Conditions

시간 제한1초메모리 제한2048 MB

요약
주어진 리스트에 x가 있는지, k로 나누어지지 않는지, 십진수에 7이 있는지 세 조건 중 정확히 하나만 성립하는 ℓ 이상의 가장 작은 x를 구한다.
난이도

보통10점 중 5점

유형
수학, 구현, 완전 탐색, 정수론
정답자
아직 제출이 없습니다

문제

You are given a list aa that contains nn different positive integers, a positive integer kk, and a positive integer~ℓ\ell. Find the smallest integer xx that is greater than or equal to ℓ\ell and satisfies exactly one condition among the following ones:

  • xx is in the list aa;
  • xx is not divisible by kk;
  • xx contains 77 in its decimal representation.

입력

The first line contains two integers nn and kk (1≤n≤1051 \le n \le 10^5, 2≤k≤1052 \le k \le 10^5).

The second line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (1≤a_i≤10181 \le a\_i \le 10^{18}).

The third line contains a single integer ℓ\ell (1≤ℓ≤10181 \le \ell \le 10^{18}).

출력

Output a single integer, the answer to the problem.

힌트

In the sample, the integers 173,174,175,176,177,179,181,182173,174,175,176,177,179,181,182 satisfy two conditions. The integer 178178 satisfies three conditions. The integer 180180 does not fulfill any conditions. Finally, the integer 183183 satisfies exactly one condition: it is not divisible by 99.

예제2

  1. 예제 1

    입력
    5 9
    181 182 184 178 81
    173
    
    예상 출력
    183
    
  2. 예제 2

    입력
    1 888
    888
    888
    
    예상 출력
    888