Problem:


Score : 300 points

Problem Statement

There is a box containing N balls. The i-th ball has the integer A_i written on it.
Snuke can perform the following operation any number of times:

Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.

Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

1 \leq K \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print POSSIBLE; if it is not possible, print IMPOSSIBLE.

Sample Input 1

3 7
9 3 4

Sample Output 1

POSSIBLE

First, take out the two balls 9 and 4, and return them back along with a new ball, abs(9-4)=5.
Next, take out 3 and 5, and return them back along with abs(3-5)=2.
Finally, take out 9 and 2, and return them back along with abs(9-2)=7.
Now we have 7 in the box, and the answer is therefore POSSIBLE.

Sample Input 2

3 5
6 9 3

Sample Output 2

IMPOSSIBLE

No matter what we do, it is not possible to have 5 in the box. The answer is therefore IMPOSSIBLE.

Sample Input 3

4 11
11 3 7 15

Sample Output 3

POSSIBLE

The box already contains 11 before we do anything. The answer is therefore POSSIBLE.

Sample Input 4

5 12
10 2 8 6 4

Sample Output 4

IMPOSSIBLE



Sample input:
3 7
9 3 4


Sample output:
POSSIBLE

Submission status: Wrong Answer

Solution code:
import sys
N,K=map(int,input().split())
a=list(map(int,input().split()))
flag=False
c1=0
c2=0
all_=0
for i in range(N): 
    if a[i]==K: #もともとkが入っているか
        flag=True
        break
    if c1==0 and a[i]==1: #1入っているか
        c1+=1
    if c2==0 and K<a[i]: #kより大きい数字入っているか
        c2+=1
    if c1+c2==2:
        flag=True
        break
    if i!=0 and all_==0: #全部同じ数字か
        if bef!=a[i]:
            all_=1
    bef=a[i]
def waru(num): #素数か判定
    sosu=True
    cc=num
    for i in range(2,int(num**0.5+1)):
        if num%i==0:
            sosu=False
            cc=i
            break
    return sosu,cc
    
def bunkai(num):
    global soinsu
    sosu,cc=waru(num)
    soinsu.add(cc)
    while not sosu: #素数じゃなければ続く
        num=num//cc
        sosu,cc=waru(num)
        soinsu.add(cc)
    return 

if not flag:
    if N==1:
        print("IMPOSSIBLE")
    else:
        if all_==0:
            print("IMPOSSIBLE")
        else:
            if c2==1: #kより大きい数字入っていないと、kを作れる可能性は0
                a=sorted(a)
                soinsu=set()
                bunkai(a[0])
                soinsu=list(soinsu)
                l=len(soinsu)
                nanko=0 #公倍数じゃなかったとき
                for i in range(l): #多くても１０個
                    check=0 #全部同じ倍数
                    for j in range(N):
                        if a[j]%soinsu[i]!=0:
                            check=1
                            break
                    if check==1:
                        nanko+=1
                    else:
                        if K%soinsu[i]==0:
                            print("POSSIBLE")
                            break
                if nanko==l:
                    print("POSSIBLE")
                else:
                    print("IMPOSSIBLE")
            else:
                print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Wrong Answer

Solution code:
def get_divisors(n):
    """
    引数の数字の約数を列挙し、setで返します。1および引数自身を含みます。
    計算量はO(log(n))です。
    """
    divisors = set()
    i = 1
    while i * i <= n:
        if n % i == 0:
            divisors.add(i)
            divisors.add(n // i)
        i += 1
    return divisors


n, k = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()
divs = get_divisors(A[0])
divs.remove(1)
divs = list(divs)

if k in A:
    print('POSSIBLE')
    exit()
if k > A[-1]:
    print('IMPOSSIBLE')
    exit()

for a in A:
    for div in divs:
        if a % div != 0:
            divs.remove(div)
            if len(divs) == 0:
                print('POSSIBLE')
                exit()
print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = [int(x) for x in input().split()]
if k in A:
    print('POSSIBLE')
    exit()
A.sort()
if A[-1] < k:
    print('IMPOSSIBLE')
    exit()
min_a = A[0]
for a in A[1:]:
    if a % min_a != 0:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()
if A[-1] < k:
    print('IMPOSSIBLE')
    exit()
min_a = A[0]
for a in A[1:]:
    if a % min_a != 0:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
if N==1:
    if K in A:
        print("POSSIBLE")
        exit()
    else:
        print("IMPOSSIBLE")
        exit()
def eu(n,m):
    r=n%m
    while(r!=0):
        n=m
        m=r
        r=n%m
    return m
g=eu(A[0],A[1])
flag=True
for i in range(N):
    if A[i]%g==0:
        pass
    else:
        flag=False
if not flag:
    g=1
if K<max(A):
    if K%g==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
g=A[0]
flag=True
for i in range(N):
    if A[i]%g==0:
        pass
    else:
        flag=False
if not flag:
    g=1
if K<max(A):
    if K%g==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
if K in A:
    print("POSSIBLE")
    exit()
if K>max(A):
    print("IMPOSSIBLE")
    exit()
if 1 in A:
    print("POSSIBLE")
    exit()
A.sort()
a=A[0]
flag=False
for i in range(N):
    if A[i]%a==0:
        pass
    else:
        flag=True
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
if K in A:
    print("POSSIBLE")
    exit()
if K>max(A):
    print("IMPOSSIBLE")
    exit()
A.sort()
a=A[0]
flag=False
for i in range(N):
    if A[i]%a==0:
        pass
    else:
        flag=True
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

N,K = map(int,input().split())
A = list(map(int,input().split()))

n = A[0]
for i in range(len(A)):
    n = fractions.gcd(n, A[i])

if K<max(A) and K%n==0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
l=sorted(map(int,input().split()))
def gcd(x,y):
  if y==0:return x
  return gcd(y,x%y)
ans=""
s=0
for i in l:
  s=gcd(i,s)
  if s==1:break
else:
  if k%s!=l[-1]%s:
    ans="IM"
print(ans+"POSSIBLE")

Submission status: Wrong Answer

Solution code:
def main():
    balls, target = map(int, input().split())
    numbers = [int(x) for x in input().split()]
    numbers.sort()
    is_possible = False
    if target in numbers:
        is_possible = True
    elif target < numbers[-1]:
        diff_list = [set(), set()]
        for i in range(balls - 1):
            difference = abs(numbers[i + 1] - numbers[i])
            diff_list[difference % 2].add(difference)
        difference = abs(numbers[-1] - numbers[0])
        diff_list[difference % 2].add(difference)
        for even in list(diff_list[0]):
            if is_possible:
                break
            for odd in list(diff_list[1]):
                if even % odd and odd % even:
                    is_possible = True
                    break
    print("POSSIBLE" if is_possible else "IMPOSSIBLE")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()
    for i in range(N-1):
        if A[i+1]-A[i] == 1:
            print("POSSIBLE")
            exit()
    key = bl(A,K)
    target = A[key:]
    small = A[:key]
    for t in target:
        if t-K in small:
            print("POSSIBLE")
            exit()

    print("IMPOSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()
    E = list(map(lambda x:x-K,A))
    E = set(E)
    C = [A[i+1]-A[i] for i in range(N-1)]
    C = set(C)
    D = set(A)
    if E&D:
        print("POSSIBLE")
        exit()
    print("IMPOSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()
    E = list(map(lambda x:x+K,A))
    E = set(E)
    C = [A[i+1]-A[i] for i in range(N-1)]
    C = set(C)
    D = set(A)
    if E&D:
        print("POSSIBLE")
        exit()
    print("IMPOSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()
    M = max(A)
    E = list(map(lambda x:abs(x-K),A))
    E = set(E)
    C = [A[i+1]-A[i] for i in range(N-1)]
    C = set(C)
    D = set(A)
    if E&D:
        print("POSSIBLE")
        exit()

    print("IMPOSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()
    E = list(map(lambda x:abs(x-K),A))
    E = set(E)
    B = list(map(lambda x:x%2,A))
    B = set(B)
    flag = 0
    C = [A[i+1]-A[i] for i in range(N-1)]
    C = set(C)
    D = set(A)
    if E&D:
        print("POSSIBLE")
        exit()
    if C-D:
        flag = 1
    if len(B) == 2 and flag:
        print("POSSIBLE")
        exit()
    if len(B)==1:
        if K%2 in B:
            print("POSSIBLE")
            exit()
    print("IMPOSSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()
    E = list(map(lambda x:abs(x-K),A))
    E = set(E)
    B = list(map(lambda x:x%2,A))
    B = set(B)
    flag = 0
    C = [A[i+1]-A[i] for i in range(N-1)]
    C = set(C)
    D = set(A)
    if E&D:
        print("POSSIBLE")
        exit()
    if C-D:
        flag = 1
    if len(B) == 2 and flag:
        print("POSSIBLE")
        exit()
    print("IMPOSSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()
    E = list(map(lambda x:abs(x-K),A))
    E = set(E)
    B = list(map(lambda x:x%2,A))
    B = set(B)
    flag = 0
    C = [A[i+1]-A[i] for i in range(N-1)]
    C = set(C)
    D = set(A)
    if E-D:
        print("POSSIBLE")
        exit()
    if C-D:
        flag = 1
    if len(B) == 2 and flag:
        print("POSSIBLE")
        exit()
    print("IMPOSSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()
    key = bl(A,K)
    pre = A[key:]
    for a in pre:
        if a-K in A:
            print("POSSIBLE")
            exit()
    B = list(map(lambda x:x%2,A))
    B = set(B)
    flag = 0
    C = [A[i+1]-A[i] for i in range(N-1)]
    C = set(C)
    D = set(A)
    if C-D:
        flag = 1
    if len(B) == 2 and flag:
        print("POSSIBLE")
        exit()
    print("IMPOSSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()
    B = list(map(lambda x:x%2,A))
    B = set(B)
    flag = 0
    C = [A[i+1]-A[i] for i in range(N-1)]
    C = set(C)
    D = set(A)
    if C-D:
        flag = 1
    if len(B) == 2 and flag:
        print("POSSIBLE")
        exit()
    print("IMPOSSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    if K > max(A):
        print("IMPOSSIBLE")
        exit()
    if K in A:
        print("POSSIBLE")
        exit()
    B = list(map(lambda x:x%2,A))
    B = set(B)
    flag = 0
    for i in range(N-1):
        if A[i+1] - A[i] not in A:
            flag = 1
    if len(B) == 2 and flag:
        print("POSSIBLE")
        exit()
    print("IMPOSSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

n,k = map(int,input().split())
a = list(map(int,input().split()))

ad = {}
for i in range(n) :
  ad[a[i]] = 1

if k > max(a) :
  print('IMPOSSIBLE')
  sys.exit()
if k in a :
  print('POSSIBLE')
  sys.exit()
  
ans = 'IMPOSSIBLE'
c = 0
for i in range(n-1) :
  a1 = a[i]
  for j in range(i+1,n) :
    a2 = a[j]
    if not abs(a1-a2) in ad  :
      c = 1
  if c == 1 :
    ans = 'POSSIBLE'
    break

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
#print(K)

A = list(map(int, input().split()))
A = list(set(A))
if len(A) == 1:
    if K == A[0]:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
elif K in A:
    ans = 'POSSIBLE'
elif K > max(A):
    ans = 'IMPOSSIBLE'
else:
    
    A.sort()

    #print(A)

    a = A[0]
    b = A[1]

    while True:
        c = b - a
        if c == 0:
            break
        if c < a:
            b = a
            a = c
        else:
            b = c

    if K%a == 0:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
    #print(a)

print(ans)

Submission status: Wrong Answer

Solution code:

N, K = map(int, input().split())
#print(K)

A = list(map(int, input().split()))

if len(A) == 1:
    if K == A[0]:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
elif K in A:
    ans = 'POSSIBLE'
elif K > max(A):
    ans = 'IMPOSSIBLE'
else:
    A = list(set(A))
    A.sort()

    #print(A)

    a = A[0]
    b = A[1]

    while True:
        c = b - a
        if c == 0:
            break
        if c < a:
            b = a
            a = c
        else:
            b = c

    if K%a == 0:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
    #print(a)

print(ans)

Submission status: Wrong Answer

Solution code:

N, K = map(int, input().split())
#print(K)

A = list(map(int, input().split()))

if len(A) == 1:
    if K == A[0]:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
elif K in A:
    ans = 'POSSIBLE'
elif K > max(A):
    ans = 'IMPOSSIBLE'
else:
    A.sort()

    #print(A)

    a = A[0]
    b = A[1]

    while True:
        c = b - a
        if c == 0:
            break
        if c < a:
            b = a
            a = c
        else:
            b = c

    if K%a == 0:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
    #print(a)

print(ans)

Submission status: Wrong Answer

Solution code:

N, K = map(int, input().split())
#print(K)

A = list(map(int, input().split()))

if len(A) == 1:
    if K == A:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
elif K in A:
    ans = 'POSSIBLE'
elif K > max(A):
    ans = 'IMPOSSIBLE'
else:
    A.sort()

    #print(A)

    a = A[0]
    b = A[1]

    while True:
        c = b - a
        if c == 0:
            break
        if c < a:
            b = a
            a = c
        else:
            b = c

    if K%a == 0:
        ans = 'POSSIBLE'
    else:
        ans = 'IMPOSSIBLE'
    #print(a)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import functools

def gcd_list(l):
    return functools.reduce(gcd, l)

def solve():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    d = gcd_list(A)
    ret = False
    if K > max(A):
        print('IMPOSSIBLE')
        return
    
    for a in A:
        if (a-K)%d == 0:
            ret = True
            break
            
    print('POSSIBLE' if ret else 'IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
A.sort()
if A[-1] <= K:
    print("IMPOSSIBLE")
    exit()
if K in A:
    print("POSSIBLE")
    exit()
from fractions import gcd
n = A[0]
for i in range(1,N):
    n = gcd(A[i],n)
if K % n == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
import fractions

n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))

if n == 1:
    print("POSSBLE" if arr[0] == k else "IMPOSSIBLE")
else:
    # 最大公約数
    gcd = arr[0]
    for num in arr[1:]:
        gcd = fractions.gcd(gcd, num)

    print("POSSBLE" if (k % gcd == 0 and k <= max(arr)) else "IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
from functools import reduce
n,k=map(int,input().split())
a=list(map(int,input().split()))

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

g=reduce(gcd,a)
print("POSSIBLE" if k%g==0 and k<max(a) else "IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
# A - Getting Difference
from fractions import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
    if a[0]==k:
        print('POSSIBLE')
        exit()
    else:
        print('IMPOSSIBLE')    
        exit()
for aa in a:
    if aa==k:
        print('POSSIBLE')
        exit()
for i in range(n-1):
    if i==0:
        t=gcd(a[i],a[i+1])
        continue
    t=gcd(t,a[i+1])
if k%t!=0:
    print('IMPOSSIBLE')
    exit()

a_max=max(a)
b=a_max-k

if b<0:
    print('IMPOSSIBLE')
    exit()
elif b==0:
    print('POSSIBLE')
    exit()

even_count=0
odd_count=0

for aa in a:
    if aa%2==0:
        even_count+=1
    else:
        odd_count+=1
a.sort()
sa=[]
for i in range(n-1):
    if abs(a[i+1]-a[i])!=0:
        sa.append(abs(a[i+1]-a[i]))
sa.sort()
if len(sa)==0:
    if k%a[0]==0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
is_even=False
is_odd=False
for ssaa in sa:
    if ssaa%2==0:
        if 0<ssaa<=b:
            is_even=True
    else:
        if 0<ssaa<=b:
            is_odd=True

if is_even==True and is_odd==True:
    print('POSSIBLE')
elif is_even==True and is_odd==False:
    if odd_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
elif is_even==False and is_odd==True:
    if even_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
# A - Getting Difference
from fractions import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
    if a[0]==k:
        print('POSSIBLE')
        exit()
    else:
        print('IMPOSSIBLE')    
        exit()
for i in range(n-1):
    if i==0:
        t=gcd(a[i],a[i+1])
        continue
    t=gcd(t,a[i+1])
if k%t!=0:
    print('IMPOSSIBLE')
    exit()

a_max=max(a)
b=a_max-k

if b<0:
    print('IMPOSSIBLE')
    exit()
elif b==0:
    print('POSSIBLE')
    exit()

even_count=0
odd_count=0

for aa in a:
    if aa%2==0:
        even_count+=1
    else:
        odd_count+=1
a.sort()
sa=[]
for i in range(n-1):
    if abs(a[i+1]-a[i])!=0:
        sa.append(abs(a[i+1]-a[i]))
sa.sort()
if len(sa)==0:
    if k%a[0]==0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
is_even=False
is_odd=False
for ssaa in sa:
    if ssaa%2==0:
        if 0<ssaa<=b:
            is_even=True
    else:
        if 0<ssaa<=b:
            is_odd=True

if is_even==True and is_odd==True:
    print('POSSIBLE')
elif is_even==True and is_odd==False:
    if odd_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
elif is_even==False and is_odd==True:
    if even_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
# A - Getting Difference
from fractions import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
    if a[0]==k:
        print('POSSIBLE')
        exit()
    else:
        print('IMPOSSIBLE')    
        exit()
for i in range(n-1):
    if i==0:
        t=gcd(a[i],a[i+1])
        continue
    t=gcd(t,a[i+1])
if k%t!=0:
    print('IMPOSSIBLE')
    exit()

a_max=max(a)
b=a_max-k

if b<0:
    print('IMPOSSIBLE')
    exit()
elif b==0:
    print('POSSIBLE')
    exit()

even_count=0
odd_count=0

for aa in a:
    if aa%2==0:
        even_count+=1
    else:
        odd_count+=1
a.sort()
sa=[]
for i in range(n-1):
    # if abs(a[i+1]-a[i])!=0:
    sa.append(abs(a[i+1]-a[i]))
sa.sort()


is_even=False
is_odd=False
for ssaa in sa:
    if ssaa%2==0:
        if 0<ssaa<=b:
            is_even=True
    else:
        if 0<ssaa<=b:
            is_odd=True

if is_even==True and is_odd==True:
    print('POSSIBLE')
elif is_even==True and is_odd==False:
    if odd_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
elif is_even==False and is_odd==True:
    if even_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
# A - Getting Difference
from fractions import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
    if a[0]==k:
        print('POSSIBLE')
        exit()
    else:
        print('IMPOSSIBLE')    
        exit()
for i in range(n-1):
    if i==0:
        t=gcd(a[i],a[i+1])
        continue
    t=gcd(t,a[i+1])
if k%t!=0:
    print('IMPOSSIBLE')
    exit()

a_max=max(a)
b=a_max-k

if b<0:
    print('IMPOSSIBLE')
    exit()
elif b==0:
    print('POSSIBLE')
    exit()

even_count=0
odd_count=0

for aa in a:
    if aa%2==0:
        even_count+=1
    else:
        odd_count+=1
a.sort()
sa=[]
for i in range(n-1):
    # if abs(a[i+1]-a[i])!=0:
    sa.append(abs(a[i+1]-a[i]))
sa.sort()


is_even=False
is_odd=False
for ssaa in sa:
    if ssaa%2==0:
        if ssaa<=b:
            is_even=True
    else:
        if ssaa<=b:
            is_odd=True

if is_even==True and is_odd==True:
    print('POSSIBLE')
elif is_even==True and is_odd==False:
    if odd_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
elif is_even==False and is_odd==True:
    if even_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
# A - Getting Difference
from fractions import gcd
n,k=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
    if a[0]==k:
        print('POSSIBLE')
        exit()
    else:
        print('IMPOSSIBLE')    
        exit()
for i in range(n-1):
    if i==0:
        t=gcd(a[i],a[i+1])
        continue
    t=gcd(t,a[i+1])
if k%t!=0:
    print('IMPOSSIBLE')
    exit()

a_max=max(a)
b=a_max-k

if b<0:
    print('IMPOSSIBLE')
    exit()
elif b==0:
    print('POSSIBLE')
    exit()

even_count=0
odd_count=0

for aa in a:
    if aa%2==0:
        even_count+=1
    else:
        odd_count+=1
a.sort()
sa=[]
for i in range(n-1):
    if abs(a[i+1]-a[i])!=0:
        sa.append(abs(a[i+1]-a[i]))
sa.sort()


is_even=False
is_odd=False
for ssaa in sa:
    if ssaa%2==0:
        if ssaa<=b:
            is_even=True
    else:
        if ssaa<=b:
            is_odd=True

if is_even==True and is_odd==True:
    print('POSSIBLE')
elif is_even==True and is_odd==False:
    if odd_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
elif is_even==False and is_odd==True:
    if even_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

from functools import reduce
from fractions import gcd

g = reduce(gcd, a)

print('POSSIBLE' if (k % g == 0) and (k <= sum(a)) else 'IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

def gcd(l):
    return reduce(fractions.gcd, l)
    
n, k = map(int, input().split())
a = list(map(int, input().split()))

x = gcd(a)
if k%x == 0 and k <= max(a):
    print("POSSIBLE")
else:
    print("INPOSSIBLE")

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions
n,k = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
if k > li[0]:
    print("IMPOSSIBLE")
    exit()
def gcd_all(list):
    return gcd_all([fractions.gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]
gcd = gcd_all(li)
if k%gcd != 0:
    print("IMPOSSIBLE")
    exit()
print("POSSIBLE")

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions
n,k = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
if k > li[0]:
    print("IMPOSSIBLE")
    exit()
def gcd_all(list):
    return gcd_all([fractions.gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]
gcd = gcd_all(li)
if k%gcd != 0:
    print("IMPOSSIBLE")
    exit()
print("POSSIBLE")

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
lst = sorted(list(map(int,input().split())))

if k > lst[-1]:
    print('IMPOSSIBLE')
elif k in lst:
    print('POSSIBLE')
else:
    dif = 10**5
    a = lst[0]
    b = lst[1]
    
    while True:
        dif = b-a
        if dif in lst or dif <= 0:
            break
        else:
            lst.append(dif)
            b = max(dif, a)
            a = min(dif, a)
    
    mn = min(lst)
    mx = max(lst)
    if (mx - k)%mn==0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
length, target = map(int, input().split(" "))
nums = sorted([int(n) for n in input().split(" ")])
minimum = min(nums)
odd, even, divide = 0, 0, 1
for n in nums:
    if n % 2 == 0:
        even = 1
    else:
        odd = 1
    if n % minimum != 0:
        divide = 0
if target > max(nums):
    print("IMPOSSIBLE")
elif target in nums:
    print("POSSIBLE")
else:
    if odd and not divide:
        print("POSSIBLE")
    else:
        if target % 2 == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
length, target = map(int, input().split(" "))
nums = sorted([int(n) for n in input().split(" ")])
odd, even, divide = 0, 0, 1
for n in nums:
    if n % 2 == 0:
        even = 1
    else:
        odd = 1
    if n % min(nums) != 0:
        divide = 0
if target > max(nums):
    print("IMPOSSIBLE")
elif target in nums:
    print("POSSIBLE")
else:
    if odd and divide:
        print("POSSIBLE")
    else:
        if target % 2 == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
length, target = map(int, input().split(" "))
nums = [int(n) for n in input().split(" ")]
odd, even = 0, 0
for n in nums:
    if n % 2 == 0:
        even = 1
    else:
        odd = 1
if target > max(nums):
    print("IMPOSSIBLE")
elif target in nums:
    print("POSSIBLE")
else:
    if odd:
        print("POSSIBLE")
    else:
        if target % 2 == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap

@mt
def slv(N, K, A):
    from fractions import gcd
    G = reduce(gcd, A)
    if max(A) > K or K % G != 0:
        return 'IMPOSSIBLE'
    else:
        return 'POSSIBLE'

def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
minimum = min(A)
maximum = max(A)

ans = "IMPOSSIBLE"
if K % minimum == 0:
    ans = "POSSIBLE"
for a in A:
    if a % minimum != 0:
        ans = "POSSIBLE"
        break
if K > maximum:
    ans = "IMPOSSIBLE"
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
minimum = min(A)
maximum = max(A)

ans = "IMPOSSIBLE"
if K % minimum == 0 and K <= maximum:
    ans = "POSSIBLE"
for a in A:
    if a % minimum != 0:
        ans = "POSSIBLE"
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
minimum = min(A)

ans = "IMPOSSIBLE"
for a in A:
    if a % minimum != 0:
        ans = "POSSIBLE"
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]

def gcd(x,y):
    if y == 0: return x
    else: return gcd(y,x%y)

g = a[0]
for i in range(n):
    g = gcd(g,a[i])

if k <= max(a) or k%g == 0:
    ans = "POSSIBLE"
else:
    ans = "IMPOSSIBLE"

print(ans)