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
import math
import itertools
import collections
import heapq
import re
import numpy as np
import fractions

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n, k = rm()
a = rl()
s = set()
b = 1
if tuple(set(a))[0] == 1:
  if k <= n:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
  exit()
for i in a:
  g = fractions.gcd(i, b)
  if g == 1:
    print('POSSIBLE')
    exit()
  s.add(g)
for i in tuple(s):
  if k % i == 0:
    print('POSSIBLE')
    break
else:
  print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
import fractions
a.sort()
#9,4,3>7
#9-(9-4-3)
print(k)
print(a[-1],a[0])
#9 ;6 3 >5
if k in a:
    print("POSSIBLE")
    exit()

if k>a[-1]:
    print("IMPOSSIBLE")
    exit()

if a[0]==1:
    print("POSSIBLE")
    exit()

flag=0
gg = fractions.gcd(a[0], a[1])

for item in a[1:]:
    if item%gg!=0:
        flag=1

if flag==1:
    print("POSSIBLE")
    exit()
else:
    if k%gg==0:
        print("POSSIBLE")
        exit()
    else:
        print("IMPOSSIBLE")
        exit()

Submission status: Wrong Answer

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

a.sort()
#9,4,3>7
#9-(9-4-3)


#9 ;6 3 >5
if k in a:
    print("POSSIBLE")
    exit()

if k>a[-1]:
    print("IMPOSSIBLE")
    exit()

if a[0]==1:
    print("POSSIBLE")
    exit()

flag=0
for item in a[1:]:
    if item%a[0]!=0:
        flag=1

if flag==1:
    print("POSSIBLE")
    exit()
else:
    if k%a[0]==0:
        print("POSSIBLE")
        exit()
    else:
        print("IMPOSSIBLE")
        exit()

Submission status: Wrong Answer

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

a.sort()
#9,4,3>7
#9-(9-4-3)


#9 ;6 3 >5
if k in a:
    print("POSSIBLE")
    exit()

if k>a[-1]:
    print("IMPOSSIBLE")
    exit()

if a[0]==1:
    print("POSSIBLE")
    exit()

flag=0
for item in a[1:]:
    if item%a[0]!=0:
        flag=1

if flag==1:
    print("POSSIBLE")
    exit()
else:
    print("IMPOSSIBLE")
    exit()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    A.sort()

    if N == 1 and A[0] != K:
        print("IMPOSSIBLE")
        return

    if A[-1] < K:
        print("IMPOSSIBLE")
        return
    if A[0] == 1:
        print("POSSIBLE")
        return

    for a in A[1:]:
        if a % A[0] != 0 or a == K:
            print("POSSIBLE")
            return
    else:
        if K % A[0] == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    A.sort()

    if A[-1] < K:
        print("IMPOSSIBLE")
        return
    if A[0] == 1:
        print("POSSIBLE")
        return

    for a in A[1:]:
        if a % A[0] != 0 or a == K:
            print("POSSIBLE")
            return
    else:
        if K % A[0] == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    A.sort()

    if A[-1] < K:
        print("IMPOSSIBLE")
        return
    if A[0] == 1:
        print("POSSIBLE")
        return

    for a in A[1:]:
        if a % A[0] != 0:
            print("POSSIBLE")
            return
    else:
        if K % A[0] == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

N, K = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))


max_a = max(A)
if K > max_a:
    print("IMPOSSIBLE")
    sys.exit()


A.sort()

diffs = set()
for i in range(N-1):
    diffs.add(A[i+1] - A[i])

if 1 in diffs:
    print("POSSIBLE")
    sys.exit()

for a_i in A:
    if a_i - K in diffs:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
import fractions
N,K=map(int,input().split())
A=list(map(int,input().split()))
g=A[0]
for i in range(N):
  g=fractions.gcd(g,A[i])
flag=False
for i in range(N):
  if((A[i]-K)>0 and (A[i]-K)%g==0):
    flag=True
if flag:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
import numpy as np

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

f = 0
if np.max(A) > K:
    for i in range(N):
        num = A[i]
        if num == 0:
            continue
        A %= A[i]
        A[i] = num
        if np.any(A == 1):
            f = 1
            break

if f:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
import numpy as np

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

f = 0
for i in range(N):
    num = A[i]
    if num == 0:
        continue
    A %= A[i]
    A[i] = num
    if np.any(A == 1):
        f = 1
        break

if f:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
n,k = map(int,input().split())
A = list(map(int,input().split()))
if k in A:
    print("POSSIBLE")
    sys.exit()
A.sort()
mod = A[0]
for i in range(1,n):
    mod = gcd(mod,A[i])
    if mod == 1 or (k%mod==0):
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

N,K,*A = map(int,open(0).read().split())
g = reduce(fractions.gcd,A)
print("POSSIBLE" if K % g == 0 else "IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N,K=map(int,input().split())
A=list(map(int,input().split()))
maxi=max(A)

if K>maxi:
  ans="IMPOSSIBLE"
else:
  t=A[0]
  for i in range(1,N):
    t = gcd(t,A[i])
  if t==1:
    ans="POSSIBLE"
  else:
    ans="IMPOSSIBLE"
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from functools import reduce
from collections import Counter
def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort(reverse=True)
    
    if A[0]==A[-1]:
        if A[0]==k:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")
    else:
        D=[A[i]-A[i+1] for i in range(n-1)]
        Dc=list(Counter(D).items())
        if k>A[0] or (len(Dc)==1 and A[0]%Dc[0][0]==0):
            print("IMPOSSIBLE")
        else:
            print("POSSIBLE")


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd

N, K, *X = map(int, open(0).read().split())

d = reduce(gcd, X)
for i in range(N):
    if X[i] < K:
        continue
        
    if (X[i] - K) % d == 0:
        print("POSSIBLE")
        break

Submission status: Wrong Answer

Solution code:
import fractions

n , k = map(int,input().split())
a = list(map(int,input().split()))
if max(a) < k:
    print("INPOSSIBLE")
    exit()
f = a[0]
for i in range(n):
    if a[i] == k:
        print("POSSIBLE")
        exit()
    f = fractions.gcd(f,a[i])
    
if k % f != 0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
gcm = 10**9+7
for i in range(N-1):
    gcm = min(gcm, gcd(A[i], A[i+1]))
if N == 1:
    print('IMPOSSIBLE')
    exit()

print('POSSIBLE' if K % gcm == 0 and K <= A[0] else 'IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
def possible(b):
    print('POSSIBLE' if b else 'IMPOSSIIBLE')

n, k = map(int, input().split())
A = list(set(map(int, input().split())))
n = len(A)

if k in A:
    possible(True)
    exit()

if n == 1:
    possible(False)
    exit()

A.sort()
D = [A[i + 1] - A[i] for i in range(n - 1)]
from fractions import *
g = D[0]
for d in D:
    g = gcd(g, d)

print('POSSIBLE' if k % g == 0 and k <= A[-1] else 'IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))
if n == 1:
    print('IMPOSSIBLE')
    exit()
A.sort()
D = [A[i + 1] - A[i] for i in range(n - 1)]
from fractions import *
g = D[0]
for d in D:
    g = gcd(g, d)
print('POSSIBLE'if g == 1 else 'IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
A_list.sort()
sub_A_list = A_list.copy()[1:]

for i in range(N-1):
    sub_A_list[i] -= A_list[i]
    
a = []   
for i in range(N-2):
    sub_A_list[i] == sub_A_list[i+1]
    a.append(-1)

if len(a) == N-2:
    print('IMPOSSIBLE')
    
else:
    print('POSSIBLE')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

ma = max(a)

if ma < k:
    print('IMPOSSIBLE')
    exit()

mia = min(a)

flg = True
for i in range(n):
    if a[i]%mia!=0:
        flg = False
if flg == True:
    if k%mia !=0:
        print('IMPOSSIBLE')
        exit()

print('POSSIBLE')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from functools import reduce

def calc_gcd(a, b):
  if a > b:
    a, b = b, a
  while b % a:
    a, b = b % a, a
  return a

def main():
  n, k = map(int, input().split())
  la = list(map(int, input().split()))
  if max(la) > k and k % (reduce(calc_gcd, la)) == 0:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
  
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from functools import reduce

def calc_gcd(a, b):
  if a > b:
    a, b = b, a
  while b % a:
    a, b = b % a, a
  return a

def main():
  n, k = map(int, input().split())
  la = list(map(int, input().split()))
  if max(la) > k and (max(la) - k) % (reduce(calc_gcd, la)) == 0:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
  
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
import fractions
N,K=map(int,input().split())
L=list(map(int,input().split()))
tmp=0
if max(L)<K:
	print("IMPOSSIBLE")
	exit()
for i in range(1,N):
	if i==1:
		if L[0]==K or L[i]==K:
			print("POSSIBLE")
			exit()
		tmp=fractions.gcd(L[0],L[1])
		if tmp<=K and K%tmp==0:
			print("POSSIBLE")
			exit()
	else:
		if L[i]==K:
			print("POSSIBLE")
			exit()
		tmp=fractions.gcd(tmp,L[i])
		if tmp<=K and K%tmp==0:
			print("POSSIBLE")
			exit()
print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
import fractions
N,K=map(int,input().split())
L=list(map(int,input().split()))
tmp=0
if max(L)<K:
	print("IMPOSSIBLE")
	exit()
for i in range(1,N):
	if i==1:
		tmp=fractions.gcd(L[0],L[1])
		if tmp<=K and K%tmp==0:
			print("POSSIBLE")
			exit()
	else:
		tmp=fractions.gcd(tmp,L[i])
		if tmp<=K and K%tmp==0:
			print("POSSIBLE")
			exit()
print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = inpl()
g = a[0]
for i in range(1,n):
    g = fractions.gcd(g,a[i])
if max(a) >= m and g % 2 == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = inpl()
g = a[0]
for i in range(1,n):
    g = fractions.gcd(g,a[i])
if max(a) >= m and m % 2 == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
*A,=map(int, input().split())
def gcd(a,b):
    while b: a,b=b,a%b
    return a
g=0
for a in A: g=gcd(g,a)
print('POSSIBLE' if K%g==0 else 'IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    A = readInts()
    g = 1
    for i in range(n):
        g = gcd(g,A[i])

    if k <= max(A) and k % g == 0:
        print("POSSIBLE")
    else:
        print('IMPOSSIBLE')
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=list(range(1,1+n))
if k> max(a):
    print('IMPOSSIBLE')
    exit()
import fractions
b=a[0]
for i in range(1,n):
    b=fractions.gcd(b,a[i])
print('POSSIBLE' if k%b==0 else 'IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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


def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    if k in set(A):
        print("POSSIBLE")
        exit()

    if k > A[-1]:
        print("IMPOSSIBLE")
        exit()

    if n == 1:
        print("IMPOSSIBLE")
        exit()

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

    if k % g == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = sorted(list(map(int, input().split())))

    if k in set(A):
        print("POSSIBLE")
        exit()

    if n == 1:
        print("IMPOSSIBLE")
        exit()

    if k > A[-1]:
        print("IMPOSSIBLE")
        exit()

    if A[0] == 1:
        print("POSSIBLE")
        exit()

    kousa = abs(A[0] - A[1])
    if A[0] % kousa != 0:
        print("POSSIBLE")
        exit()

    for i in range(1, n):
        if abs(A[0] - A[i]) % kousa != 0:
            print("POSSIBLE")
            break
    else:
        if k % (A[0] - A[1]) == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = sorted(list(map(int, input().split())))

    if k in set(A):
        print("POSSIBLE")
        exit()

    if n == 1:
        print("IMPOSSIBLE")
        exit()

    if k > A[-1]:
        print("IMPOSSIBLE")
        exit()

    if A[0] == 1:
        print("POSSIBLE")
        exit()

    for i in range(1, n):
        if abs(A[0] - A[i]) % A[0] != 0:
            print("POSSIBLE")
            break
    else:
        if k % A[0] == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = sorted(list(map(int, input().split())))

    if k in A:
        print("POSSIBLE")
        exit()

    if n == 1:
        print("IMPOSSIBLE")
        exit()

    if k > A[-1]:
        print("IMPOSSIBLE")
        exit()

    for i in range(1, n):
        if abs(A[0] - A[i]) not in set(A):
            print("POSSIBLE")
            break
    else:
        print("IMPOSSIBLE")


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import fractions
N, K = map(int, input().split())
A = list(map(int, input().split()))
G = A[0]
for i in range(1,N):
  G = fractions.gcd(G,A[i])
if K < max(A) and K % G == 0:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
INF = 10 ** 20
MOD = 10 ** 9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  heapq import heappop,heapify,heappush
from bisect import bisect_left
from functools import reduce
from fractions import gcd

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

    if k > max(a):
        print('IMPOSSIBLE')
        return

    G = reduce(gcd,a)
    if k%G == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBEL')
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int,input().split()))
diff = [0]*N
for i in range(N-1):
  diff[i] = abs(A[i+1] - A[i])
diff[N-1] = abs(A[0] - A[N-1])
if K > max(A):
  print("IMPOSSIBLE")
elif all(diff[i] in A for i in range(N)):
  print("IMPOSSIBLE")
elif K % 2 == 1 and all(A[i] % 2 == 0 for i in range(N)):
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int,input().split()))
diff = [0]*N
for i in range(N-1):
  diff[i] = abs(A[i+1] - A[i])
diff[N-1] = abs(A[0] - A[N-1])
if K > max(A):
  print("IMPOSSIBLE")
elif all(diff[i] in A for i in range(N)):
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
if k>A[-1]:
    print('IMPOSSIBLE')
else:
    flag=True
    for i in range(n):
        if A[i]%A[0]!=0:
            flag=False
    if flag:
        if k%A[0]==0:
            print('POSSIBLE')
        else:
            print('IMPOSSIBLE')
    else:
        print('POSSIBLE')

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
if k>A[-1]:
    print('IMPOSSIBLE')
else:
    flag=True
    for i in range(n):
        if A[i]%A[0]!=0:
            flag=False
    if flag:
        print('POSSIBLE')
    else:
        if k%A[0]==0:
            print('POSSIBLE')
        else:
            print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
# 1が作れれば必ず終了できる
# 1が作れないようなやつはあるか？
# -> 6 18 26 31 40 があったとき、26と31だけで作れそう
# -> 偶奇が揃っていればいい？
# ex) ぜんぶ奇数だと奇数-奇数で偶数が作れるので結局いける？
# 21 29 45 うんいけそう(8を作れば5ができるので21%5=1)（16を作れば5がry）
# ただしサンプル曰くすべてが同じ数の倍数なら無理そう 適当に最初とそれ以外で試せばいいか
# と思ったけど[6 33 45]とかは作れないのでgcdをとって最後まで更新されなかったらアウトとする
# というか奇数だけでも偶数作れるから奇数さえあればいけるか

n, k = map(int, input().split())
arr = sorted(list(set(list(map(int, input().split())))))
n = len(arr)
if arr[0] == 1 or k in arr:
    print("POSSIBLE")
    exit()
if n < 2 or arr[-1] < k:
    print("IMPOSSIBLE")
    exit()


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


tmp = gcd(arr[0], arr[1])
# あーもうめちゃくちゃだよ
if tmp == 1:
    print("POSSIBLE")
    exit()
flag = True
for i in range(2, n):
    g = gcd(tmp, arr[i])
    if g != tmp or g == 1:
        flag = False
        break
if flag:
    print("IMPOSSIBLE")
    exit()

even_flag, odd_flag = False, False
for a in arr:
    if a % 2 == 1:
        odd_flag = True
    else:
        even_flag = True

# あーもうめちゃくちゃだよ
if odd_flag:
    if k % 2 == 0 and not even_flag:
        print("IMPOSSIBLE")
    else:
        print("POSSIBLE")
    exit()

# あーもうめちゃくちゃだよ
if k % 2 == 1:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Wrong Answer

Solution code:
# 1が作れれば必ず終了できる
# 1が作れないようなやつはあるか？
# -> 6 18 26 31 40 があったとき、26と31だけで作れそう
# -> 偶奇が揃っていればいい？
# ex) ぜんぶ奇数だと奇数-奇数で偶数が作れるので結局いける？
# 21 29 45 うんいけそう(8を作れば5ができるので21%5=1)（16を作れば5がry）
# ただしサンプル曰くすべてが同じ数の倍数なら無理そう 適当に最初とそれ以外で試せばいいか
# と思ったけど[6 33 45]とかは作れないのでgcdをとって最後まで更新されなかったらアウトとする
# というか奇数だけでも偶数作れるから奇数さえあればいけるか

n, k = map(int, input().split())
arr = sorted(list(set(list(map(int, input().split())))))
n = len(arr)
if arr[0] == 1 or k in arr:
    print("POSSIBLE")
    exit()
if n < 2 or arr[-1] < k:
    print("IMPOSSIBLE")
    exit()


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


tmp = gcd(arr[0], arr[1])
# あーもうめちゃくちゃだよ
if tmp == 1:
    print("POSSIBLE")
    exit()
flag = True
for i in range(2, n):
    g = gcd(tmp, arr[i])
    if g != tmp or g == 1:
        flag = False
        break
if flag:
    print("IMPOSSIBLE")
    exit()

even_flag, odd_flag = False, False
for a in arr:
    if a % 2 == 1:
        odd_flag = True
    else:
        even_flag = True

# あーもうめちゃくちゃだよ
if odd_flag:
    if k % 2 == 1 and not even_flag:
        print("IMPOSSIBLE")
    else:
        print("POSSIBLE")
    exit()

# あーもうめちゃくちゃだよ
if k % 2 == 1:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Wrong Answer

Solution code:
# 1が作れれば必ず終了できる
# 1が作れないようなやつはあるか？
# -> 6 18 26 31 40 があったとき、26と31だけで作れそう
# -> 偶奇が揃っていればいい？
# ex) ぜんぶ奇数だと奇数-奇数で偶数が作れるので結局いける？
# 21 29 45 うんいけそう(8を作れば5ができるので21%5=1)（16を作れば5がry）
# ただしサンプル曰くすべてが同じ数の倍数なら無理そう 適当に最初とそれ以外で試せばいいか
# と思ったけど[6 33 45]とかは作れないのでgcdをとって最後まで更新されなかったらアウトとする
# というか奇数だけでも偶数作れるから奇数さえあればいけるか

n, k = map(int, input().split())
arr = sorted(list(set(list(map(int, input().split())))))
n = len(arr)
if arr[0] == 1 or k in arr:
    print("POSSIBLE")
    exit()
if n < 2 or arr[-1] < k:
    print("IMPOSSIBLE")
    exit()


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


tmp = gcd(arr[0], arr[1])
# あーもうめちゃくちゃだよ
if tmp == 1:
    print("POSSIBLE")
    exit()
flag = True
for i in range(2, n):
    g = gcd(tmp, arr[i])
    if g != tmp or g == 1:
        flag = False
        break
if flag:
    print("IMPOSSIBLE")
    exit()
for a in arr:
    if a % 2 == 1:
        print("POSSIBLE")
        exit()
# あーもうめちゃくちゃだよ
if k % 2 == 1:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Wrong Answer

Solution code:
# 1が作れれば必ず終了できる
# 1が作れないようなやつはあるか？
# -> 6 18 26 31 40 があったとき、26と31だけで作れそう
# -> 偶奇が揃っていればいい？
# ex) ぜんぶ奇数だと奇数-奇数で偶数が作れるので結局いける？
# 21 29 45 うんいけそう(8を作れば5ができるので21%5=1)（16を作れば5がry）
# ただしサンプル曰くすべてが同じ数の倍数なら無理そう 適当に最初とそれ以外で試せばいいか
# と思ったけど[6 33 45]とかは作れないのでgcdをとって最後まで更新されなかったらアウトとする
# というか奇数だけでも偶数作れるから奇数さえあればいけるか

n, k = map(int, input().split())
arr = sorted(list(set(list(map(int, input().split())))))
n = len(arr)
if arr[0] == 1 or k in arr:
    print("POSSIBLE")
    exit()
if n < 2 or arr[-1] < k:
    print("IMPOSSIBLE")
    exit()


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


tmp = gcd(arr[0], arr[1])
flag = True
for i in range(2, n):
    g = gcd(tmp, arr[i])
    if g != tmp or g == 1:
        flag = False
        break
if flag:
    print("IMPOSSIBLE")
    exit()
odds, evens = False, False
for a in arr:
    # if a % 2 == 0:
    #     evens = True
    # else:
    #     odds = True
    if a % 2 == 1:
        print("POSSIBLE")
        exit()
# あーもうめちゃくちゃだよ
if k % 2 == 1:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

# if evens and odds:
#     print("POSSIBLE")
# else:
#     print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
# 1が作れれば必ず終了できる
# 1が作れないようなやつはあるか？
# -> 6 18 26 31 40 があったとき、26と31だけで作れそう
# -> 偶奇が揃っていればいい？
# ex) ぜんぶ奇数だと奇数-奇数で偶数が作れるので結局いける？
# 21 29 45 うんいけそう(8を作れば5ができるので21%5=1)（16を作れば5がry）
# ただしサンプル曰くすべてが同じ数の倍数なら無理そう 適当に最初とそれ以外で試せばいいか
# と思ったけど[6 33 45]とかは作れないのでgcdをとって最後まで更新されなかったらアウトとする
# というか奇数だけでも偶数作れるから奇数さえあればいけるか

n, k = map(int, input().split())
arr = sorted(list(set(list(map(int, input().split())))))
n = len(arr)
if arr[0] == 1 or k in arr:
    print("POSSIBLE")
    exit()
if n < 2 or arr[-1] < k:
    print("IMPOSSIBLE")
    exit()


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


tmp = gcd(arr[0], arr[1])
flag = True
for i in range(2, n):
    g = gcd(tmp, arr[i])
    if g != tmp or g == 1:
        flag = False
        break
if flag:
    print("IMPOSSIBLE")
    exit()
odds, evens = False, False
for a in arr:
    # if a % 2 == 0:
    #     evens = True
    # else:
    #     odds = True
    if a % 2 == 1:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

# if evens and odds:
#     print("POSSIBLE")
# else:
#     print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
# 1が作れれば必ず終了できる
# 1が作れないようなやつはあるか？
# -> 6 18 26 31 40 があったとき、26と31だけで作れそう
# -> 偶奇が揃っていればいい？
# ex) ぜんぶ奇数だと奇数-奇数で偶数が作れるので結局いける？
# 21 29 45 うんいけそう(8を作れば5ができるので21%5=1)（16を作れば5がry）
# ただしサンプル曰くすべてが同じ数の倍数なら無理そう 適当に最初とそれ以外で試せばいいか
# と思ったけど[6 33 45]とかは作れないのでgcdをとって最後まで更新されなかったらアウトとする

n, k = map(int, input().split())
arr = sorted(list(set(list(map(int, input().split())))))
n = len(arr)
if arr[0] == 1 or k in arr:
    print("POSSIBLE")
    exit()
if n < 2 or arr[-1] < k:
    print("IMPOSSIBLE")
    exit()


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


tmp = gcd(arr[0], arr[1])
flag = True
for i in range(2, n):
    g = gcd(tmp, arr[i])
    if g != tmp or g == 1:
        flag = False
        break
if flag:
    print("IMPOSSIBLE")
    exit()
odds, evens = False, False
for a in arr:
    if a % 2 == 0:
        evens = True
    else:
        odds = True
if evens and odds:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
# 1が作れれば必ず終了できる
# 1が作れないようなやつはあるか？
# -> 6 18 26 31 40 があったとき、26と31だけで作れそう
# -> 偶奇が揃っていればいい？
# ex) ぜんぶ奇数だと奇数-奇数で偶数が作れるので結局いける？
# 21 29 45 うんいけそう(8を作れば5ができるので21%5=1)（16を作れば5がry）
# ただしサンプル曰くすべてが同じ数の倍数なら無理そう 適当に最初とそれ以外で試せばいいか
# と思ったけど[6 33 45]とかは作れないのでgcdをとって最後まで更新されなかったらアウトとする

n, k = map(int, input().split())
arr = sorted(list(set(list(map(int, input().split())))))
n = len(arr)
if arr[0] == 1:
    print("POSSIBLE")
    exit()
if n < 2 or arr[-1] < k:
    print("IMPOSSIBLE")
    exit()


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


tmp = gcd(arr[0], arr[1])
flag = True
for i in range(2, n):
    g = gcd(tmp, arr[i])
    if g != tmp or g == 1:
        flag = False
        break
if flag:
    print("IMPOSSIBLE")
    exit()
odds, evens = False, False
for a in arr:
    if a % 2 == 0:
        evens = True
    else:
        odds = True
if evens and odds:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
# 1が作れれば必ず終了できる
# 1が作れないようなやつはあるか？
# -> 6 18 26 31 40 があったとき、26と31だけで作れそう
# -> 偶奇が揃っていればいい？
# ex) ぜんぶ奇数だと奇数-奇数で偶数が作れるので結局いける？
# 21 29 45 うんいけそう(8を作れば5ができるので21%5=1)（16を作れば5がry）
# ただしサンプル曰くすべてが同じ数の倍数なら無理そう 適当に最初とそれ以外で試せばいいか
# と思ったけど[6 33 45]とかは作れないのでgcdをとって最後まで更新されなかったらアウトとする

n, k = map(int, input().split())
arr = sorted(list(set(list(map(int, input().split())))))
n = len(arr)
if arr[0] == 1:
    print("POSSIBLE")
    exit()
if n < 2 or arr[-1] < k:
    print("IMPOSSIBLE")
    exit()


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


tmp = gcd(arr[0], arr[1])
flag = True
for i in range(2, n):
    g = gcd(tmp, arr[i])
    if g != tmp:
        flag = False
if flag:
    print("IMPOSSIBLE")
    exit()
odds, evens = False, False
for a in arr:
    if a % 2 == 0:
        evens = True
    else:
        odds = True
if evens and odds:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")