Conditions
시간 제한1초메모리 제한2048 MB
주어진 리스트에 x가 있는지, k로 나누어지지 않는지, 십진수에 7이 있는지 세 조건 중 정확히 하나만 성립하는 ℓ 이상의 가장 작은 x를 구한다.
문제
You are given a list that contains different positive integers, a positive integer , and a positive integer~. Find the smallest integer that is greater than or equal to and satisfies exactly one condition among the following ones:
- is in the list ;
- is not divisible by ;
- contains in its decimal representation.
입력
The first line contains two integers and (, ).
The second line contains integers ().
The third line contains a single integer ().
출력
Output a single integer, the answer to the problem.
힌트
In the sample, the integers satisfy two conditions. The integer satisfies three conditions. The integer does not fulfill any conditions. Finally, the integer satisfies exactly one condition: it is not divisible by .