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: Accepted

Solution code:
#!/usr/bin/env python3
import copy

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

a_list = sorted(a_list)


def judge(w_list, k):
    w_list = sorted(w_list)

    for i in range(len(w_list) - 1):
        w_list += [abs(w_list[i] - w_list[i + 1])]

    w_list = sorted(list(set(w_list)))

    if k in w_list:
        return True, w_list
    elif 1 in w_list:
        return True, w_list
    elif abs(w_list[0] - w_list[-1]) < K:
        return False, w_list
    elif k % 2 == 0 and 2 in w_list:
        return True, w_list
    else:
        ww_list = set([w + K for w in w_list])
        if ww_list & set(w_list):
            return True, w_list
        else:
            return False, w_list


w_list = a_list

while True:
    org_w_list = copy.copy(w_list)
    is_ok, w_list = judge(w_list, K)
    if is_ok:
        break
    else:
        if abs(w_list[0] - w_list[-1]) < K:
            break
        if w_list == org_w_list:
            break

ans = "POSSIBLE" if is_ok else "IMPOSSIBLE"

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

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

G = gcd(*A)
M = max(A)

if K % G == 0 and M >= K:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd
n,k=map(int,input().split())
A=list(map(int,input().split()))
ans=""
if max(A)<k:
  ans="IMPOSSIBLE"
elif k in A:
  ans="POSSIBLE"
else:
  g=gcd(A[0], A[1])
  for i in range(2,n):
    g=gcd(g,A[i])
  if g!=0 and k%g==0:
    ans="POSSIBLE"
  else:
    ans="IMPOSSIBLE"
print(ans)

Submission status: Accepted

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

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

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

if k%check==0 and k<=a[-1]:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd

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

if K > max(A):
  print('IMPOSSIBLE')
  exit()
g = A[0]
for i in range(1,N):
  g = gcd(g,A[i])
m = (K-min(A))/g
print('POSSIBLE' if m.is_integer() else 'IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd

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

if max(A)<K:
    ans="IMPOSSIBLE"
elif K in A:
    ans="POSSIBLE"

else:
    g=gcd(A[0],A[1])
    for i in range(2,N):
        g=gcd(g,A[i])
    if g!=0 and K%g==0:
        ans="POSSIBLE"
    else:
        ans="IMPOSSIBLE"

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd


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

if max(A)<K:
    ans="IMPOSSIBLE"
elif K in A:
    ans="POSSIBLE"

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

    if g==1:
        ans="POSSIBLE"

    elif g!=0 and K%g==0:
        ans="POSSIBLE"

    else:
        ans="IMPOSSIBLE"

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
kk=a[0]
import fractions
for i in range(n-1):
	kk=fractions.gcd(kk,a[i+1])
if kk==1 and max(a)>=k:
	print("POSSIBLE")
elif k%kk!=0 or max(a)<k:
	print("IMPOSSIBLE")
else:
	print("POSSIBLE")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd;from functools import reduce;N,K,*A=map(int,open(0).read().split());print("IM"*(((K-A[0])%reduce(gcd,A)>0)|(K>max(A)))+"POSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
N,K,*A=map(int,open(0).read().split())
print("IM"*(((K-A[0])%reduce(gcd,A)>0)|(min(A)>K)|(K>max(A)))+"POSSIBLE")

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
lista = [int(i) for i in input().split()]
import functools
#from functools import reduce
import fractions
#from fractions import gcd

gcda=functools.reduce(fractions.gcd, lista)

if k>max(lista):
    print("IMPOSSIBLE")
else:
    if k%gcda==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

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

def gcd(a,b):
  return a if not b else gcd(b,a%b)

if K in A:
  print("POSSIBLE")
else:
  if max(A)<K:
    print("IMPOSSIBLE")
  else:
    max_gcd=A[0]
    for i in range(N):
      max_gcd=gcd(max_gcd,A[i])
    #print(max_gcd)
    if (max(A)-K)%max_gcd==0:
      print("POSSIBLE")
    else:
      print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

print("POSSIBLE" if not k % g and k <= max(a) else "IMPOSSIBLE")

Submission status: Accepted

Solution code:
# import math
# import fractions
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)
 
 
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = sorted(a)
 
div = a[0]
for i in range(1, n):
    div = gcd(div, a[i])
 
if k % div == 0 and k <= a[-1]:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
from fractions import gcd
g=A[0]
for a in A[1:]:
    g=gcd(g,a)
print(['IMPOSSIBLE','POSSIBLE'][(g==1 or K%g==0) and max(A)>=K])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
from fractions import gcd
from functools import reduce

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

if max(l)<K:
    print("IMPOSSIBLE")
else:
    if K%reduce(gcd, l)==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd
import functools

N, K = map(int,input().split())
A = list(map(int, input().split()))
max_A = max(A)
gcd_A = functools.reduce(gcd, A)
 
ans = 'POSSIBLE' if K <= max_A and K % gcd_A == 0 else 'IMPOSSIBLE'
 
print(ans)

Submission status: Accepted

Solution code:
# li = list(map(int, input().split()))
N, K = map(int, input().split())
A_N = list(map(int, input().split()))


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


next = A_N[0]
for i in range(len(A_N)):
    next = gcd(A_N[i], next)

if K > max(A_N):
    print('IMPOSSIBLE')
elif next == 1:
    print('POSSIBLE')
elif K % next ==0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
# li = list(map(int, input().split()))
N, K = map(int, input().split())
A_N = list(map(int, input().split()))


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


next = A_N[0]
for i in range(len(A_N)):
    next = gcd(A_N[i], next)

if K > max(A_N):
    print('IMPOSSIBLE')
elif next == 1:
    print('POSSIBLE')
elif K % next ==0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
# AGC018A - Getting Difference
from fractions import gcd
from functools import reduce


def main():
    N, K, *A = map(int, open(0).read().split())
    G, M = reduce(gcd, A), max(A)  # gcd, max of A
    flg = K <= M and K % G == 0
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

def main():
    N, K = map(int, input().split())
    a = list(map(int, input().split()))

    gcd_ = a[0]
    for i in range(1, N):
        gcd_ = gcd(gcd_, a[i])
    
    if K%gcd_ == 0 and K <= max(a):
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
N,K = map(int,input().split())
A = list(map(int,input().split()))
if max(A) < K:
  print("IMPOSSIBLE")
elif N == 1:
  if A[0] == K:
    print("POSSIBLE")
  else:
    print("IMPOSSIBLE")
else:
  G = fractions.gcd(A[0],A[1])
  for g in range(2,N):
    G = fractions.gcd(G,A[g])
  if K % G != 0:
    print("IMPOSSIBLE")
  else:
    print("POSSIBLE")

Submission status: Accepted

Solution code:
from sys import stdin
from fractions import gcd
from functools import reduce

def gcd_l(l):
    return reduce(gcd, l)

N, K = [int(_) for _ in stdin.readline().rstrip().split()]
A = [int(_) for _ in stdin.readline().rstrip().split()]
ans = gcd_l(A)
if K % ans == 0 and max(A) >= K:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
import fractions

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

if k > max(a):
    print("IMPOSSIBLE")
elif n == 1:
    if a[0] == k:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
else:
    minak = min(a)

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

    for i in range(0,n):
        gcda = fractions.gcd(gcda,a[i])
        if gcda ==1:
            break

    if gcda == 1 or k % gcda == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
As = list(map(int, input().split()))
def calcgcd(a, b):
  if a > b:
    a, b = b, a
  while a > 0:
    a, b = b%a, a
  return b
gcd = 0
for A in As:
  gcd = calcgcd(gcd, A)
if K%gcd == 0 and K <= max(As):
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd
n,k = map(int, input().split())
a = list(map(int, input().split()))
g = a[0]
for i in a:
    g = gcd(g, i)
m = max(a)
if m >= k and (m-k) % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import fractions as math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
x = gcd_list(A)
if(K%x==0 and max(A)>=K):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
import collections
N, K = map(int, input().split())
A = list(map(int, input().split()))
if K in A:
    print("POSSIBLE")
    exit(0)
else:
    diff = collections.defaultdict(int)
    A.sort()
    idx = N - 1
    if K > A[-1]:
        print("IMPOSSIBLE")
        exit(0)
    else:
        for i in range(N-1):
            if A[i] > K and idx == N - 1:
                idx = i
            if A[i+1] - A[i] != 0:
                diff[A[i+1] - A[i]] += 1

        diff_list = list(diff.keys())
        if 1 in diff_list:
            print("POSSIBLE")
            exit(0)
        else:
            diff_list.sort()
            for i in range(idx, N):
                for j in range(len(diff_list)):
                    if (K - A[i]) % diff_list[j] == 0:
                        print("POSSIBLE")
                        exit(0)
            print("IMPOSSIBLE")
            exit(0)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
import fractions

def main():
    _,K = map(int, input().split())
    A = list(map(int, input().split()))
    a = A[0]
    for x in A:
        a = fractions.gcd(a,x)
    if max(A) >= K and K%a == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
import sys
input = sys.stdin.readline

def main():
    N,K =map(int,input().split())
    A = list(map(int,input().split()))
    if K > max(A):
        print("IMPOSSIBLE")
    else:
        def gcd_list(numbers):
            return reduce(fractions.gcd,numbers)
          
        gcd = gcd_list(A)
        if (max(A)-K)%gcd == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

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

    if max(a) < k:
        print("IMPOSSIBLE")
    else:
        from fractions import gcd
        gmax = a[0]
        for i in range(1, n):
            gmax = gcd(gmax, a[i])

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

    


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

    if max(a) < k:
        print("IMPOSSIBLE")
    else:
        from fractions import gcd
        gmax = a[0]
        for i in range(1, n):
            gmax = gcd(gmax, a[i])
        if gmax == 1:
            print("POSSIBLE")
        else:
            if k % gmax == 0:
                print("POSSIBLE")
            else:
                print("IMPOSSIBLE")

    


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
from functools import reduce

N, K = map(int, input().split())
A = [int(_) for _ in input().split()]

if max(A) < K:
    print('IMPOSSIBLE')
    sys.exit()
if K in A:
    print('POSSIBLE')
    sys.exit()

def gcd_list(numbers):
    return reduce(gcd, numbers)

num = gcd_list(A)
if num == 1:
    print('POSSIBLE')
else:
    if K % num == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    def gcd(a,b):
        if a == 0:
            return b
        return gcd(b%a, a)
    n,k = LI()
    a = LI()
    if max(a) < k:
        print("IMPOSSIBLE")
        return
    g = a[0]
    for i in a[1:]:
        g = gcd(g, i)
    if g == 1:
        print("POSSIBLE")
    else:
        if k%g == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")
    return

#B
def B():
    n = I()

    return

#C
def C():
    x,y,z = LI()
    n = x+y+z
    c = LIR(n)
    for i in range(n):
        c[i].append(c[i][0])
    c.sort(key = lambda x:-(x[1]-x[3]))
    for i in range(y):
        c[i][3] = c[i][1]
    c.sort(key = lambda x:-(x[2]-x[3]))
    for i in range(y):
        c[i][3] = c[i][1]

    for i in c:
        print(i)
    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Accepted

Solution code:
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    gcd = 0
    for v in a:
        gcd = fractions.gcd(gcd, v)
    mv = max(a)
    if mv < k:
        print("IMPOSSIBLE")
    else:
        if (mv - k) % gcd == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    if N == 1:
        if K == A[0]: return "POSSIBLE"
        else: return "IMPOSSIBLE"
    if max(A) < K:
        return "IMPOSSIBLE"
    if K in A:
        return "POSSIBLE"

    ref = A[0]
    for i in range(1, N):
        ref = gcd(ref, A[i])
    for i in range(N):
        if A[i] > K and (A[i]-K) % ref == 0:
            return "POSSIBLE"
    return "IMPOSSIBLE"

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

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#AGC014A
import sys
#import collections

#n= int(input())

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

tmp = input().split()
a = list(map(lambda a: int(a), tmp))

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

maxa=a[0]
tmp=a[0]
for i in range(1,n):
	maxa=max(maxa,a[i])
	tmp=gcd(tmp, a[i])

if(k<=maxa)and(k%tmp ==0):
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

#print(maxa)
#print(tmp)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
def gcd(x,y):
    if x==y:
        return x
    elif x>y:
        r=-1
        while r!=0:
            r=x%y
            x=y
            y=r
        return x
    else:
        r=-1
        while r!=0:
            r=y%x
            y=x
            x=r
        return y

if n==1:
    if k==a[0]:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    exit()
g=gcd(a[0],a[1])
for i in range(2,n):
    g=gcd(g,a[i])
if k%g==0 and k<=max(a):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
def gcd(a,b):
    if b==0:
        return a
    return gcd(b, a%b)
if N==1:
    print("POSSIBLE" if K==A[0] else "IMPOSSIBLE")
    exit()
element=gcd(A[0], A[1])
if N!=2:
    for _ in range(2, N):
        element=gcd(element, A[_])

print("POSSIBLE" if K%element==0 and max(A)>=K else "IMPOSSIBLE")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#AGC18 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


def gcd(n,m):
    if m == 0:
        return n
    else:
        return gcd(m,n%m)

n,k = LI()
a = LI()
if k in a:
    print('POSSIBLE')
    quit()
if max(a) < k:
    print('IMPOSSIBLE')
    quit()
g = a[0]
for i in range(1,n):
    g = gcd(g,a[i])
if k % g != 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Submission status: Accepted

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

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

gcd  = A[0]
max_a = A[0]
for i in range(1, N):
    a = A[i]
    if a == K:
        print("POSSIBLE")
        exit()
    if a > max_a:
        max_a = a
    gcd = get_gcd(gcd, a)

if max_a < K:
    print("IMPOSSIBLE")
    exit()
else:
    if K % gcd == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import fractions
n,k=map(int,input().split())
l=list(map(int,input().split()))
ma=max(l)
if k>ma:
  print('IMPOSSIBLE')
else:
  gcd=l[0]
  l.remove(gcd)
  for x in l:
    gcd=fractions.gcd(gcd,x)
  if gcd==1:
    print('POSSIBLE')
  else:
    if k%gcd==0:
      print('POSSIBLE')
    else:
      print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
def main():
    n, k = (int(i) for i in input().split())
    a = [int(i) for i in input().split()]
    a.sort()
    diff_min = 10**9 + 7
    for i in range(n-1):
        diff = abs(a[i] - a[i+1])
        diff_min = (min(diff_min,diff) if diff != 0 else diff_min)
    for i in range(n):
        diff_min = (a[i] % diff_min if a[i] % (diff_min) != 0 else diff_min)
    for i in range(n):
        if a[i] - k >= 0 and (a[i] - k)%diff_min == 0:
            print("POSSIBLE")
            break
    else:
        print("IMPOSSIBLE")
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq

YES = "POSSIBLE"  # type: str
NO = "IMPOSSIBLE"  # type: str

def solve(N: int, K: int, A: "List[int]"):
    if K > max(A):
        print(NO)
        return
    g = A[-1]
    for a in A[:-1]:
        g = fractions.gcd(g, a)
    if K % g == 0:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

flag = False
for i in A:
    if i >= K and (i - K) % n == 0:
        flag = True
        break
    else:
        pass

if flag:
    print ('POSSIBLE')
else:
    print ('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import gcd


n, k = map(int, input().split())
a = list(map(int, input().split()))
g = a[0]
for a_ in a[1:]:
    g = gcd(a_, g)
if max(a) >= k and k % g == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
import fractions
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = max(a)
gcd = 0
for i in a:
    gcd = fractions.gcd(gcd, i)
print("POSSIBLE" if k <= s and (k - s) % gcd == 0 else "IMPOSSIBLE")

Submission status: Accepted

Solution code:
from fractions import gcd
from bisect import bisect_right
n,k=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
if k>A[n-1]:ans=-1
elif k==A[n-1]:ans=1
else:
    a=A[0]
    for i in range(1,n):
        a=gcd(a,A[i])
    m=A[bisect_right(A,k)]
    if (m-k)%a==0:
        ans=1
    else:
        ans=-1
if ans==1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
# 2019/08/15

from fractions import gcd

n,k=map(int,input().split())
a=list(map(int,input().split()))
ans='POSSIBLE'
max_a=max(a)
if max_a==k:
    print(ans)
    exit()
elif max_a<k:
    print('IMPOSSIBLE')
    exit()

    

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

if k%g==0 or k in a:
    print(ans)
else:
    print('IMPOSSIBLE')

Submission status: Accepted

Solution code:
from fractions import*;_,k,*a=map(int,open(0).read().split());g=a[0]
for i in a:g=gcd(g,i)
print("IM"*(k>max(a)or k%g>0)+"POSSIBLE")

Submission status: Accepted

Solution code:
from fractions import*;_,k,*a=map(int,open(0).read().split());g=a[0];m=max(a)
for i in a:g=gcd(g,i)
print("IM"*(k>m or k%g!=0)+"POSSIBLE")

Submission status: Accepted

Solution code:
from fractions import*
n,k=map(int,input().split())
*a,=map(int,input().split())
g=a[0];m=max(a)
for i in a:g=gcd(g,i)
print("IM"*(k>m or k%g!=0)+"POSSIBLE")

Submission status: Accepted

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

def gcd(n, m) :
    n, m = max(n, m), min(n, m)
    if m == 0 :
        return n
    return gcd(m, n % m)

dis = A[0]
for a in A :
    dis = gcd(dis, a)

for a in A :
    if a < K :
        continue
    if (a - K) % dis == 0 :
        print('POSSIBLE')
        break
else :
    print('IMPOSSIBLE')

Submission status: Accepted

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

s = 0

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

g = gcd(*A)

if K % g == 0 and max(A)>=K:
    ans = 'POSSIBLE'
else:
    ans = 'IMPOSSIBLE'

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

import functools
N,K = map(int,input().split())
A = [int(x) for x in input().split()]
max_A = max(A)
gcd_A = functools.reduce(gcd,A)

answer = 'POSSIBLE' if K <= max_A and K % gcd_A == 0 else 'IMPOSSIBLE'

print(answer)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    return b if (a % b==0) else gcd(b, a%b)

def solve(n, k, a):
    if k in a:
        return "POSSIBLE" 
    p = a[0]
    for i in range(1, n):
        p = gcd(p, a[i])
    q = max(a) - p
    if (k <= q) and (gcd(q, k) == p):
        return "POSSIBLE"
    else:
        return "IMPOSSIBLE"

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

Submission status: Accepted

Solution code:
from functools import reduce

def gcd_list(n):
    return reduce(gcd, n)

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


n, k = map(int, input().split())
a = list(map(int, input().split()))
if k > max(a):
    print("IMPOSSIBLE")
elif k in a:
    print("POSSIBLE")
else:
    if k % gcd_list(a) == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from copy import *

N, K = map(int, input().split())
A = list(map(int, input().split()))
gcd = lambda a, b: a if b == 0 else gcd(b, a%b)
G = 0
for a in A:
    G = gcd(a, G)
M = max(A)
if K <= M and K % G == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import fractions

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

A=list(set(A))
N=len(A)
A.sort()

g=A[0]
for i in range(N-1):
    g=fractions.gcd(g,A[i+1])

if K%g==0 and K<=A[-1]:
    ans="POSSIBLE"
else:
    ans="IMPOSSIBLE"
print(ans)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    if a <= b:
        temp = a
        a = b
        b = temp
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b, r)


N, K = map(int,input().split())
A = list(map(int,input().split()))
#Aの最大公約数を作ることが出来る

A.sort()
if K > A[-1]:
    print("IMPOSSIBLE")
elif N == 1:
    if K != A[0]:
        print("IMPOSSIBLE")
    else:
        print("POSSIBLE")
else:
    g = gcd(A[0], A[1])
    for i in range(2, N):
        g = gcd(g, A[i])
    if K % g == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
from sys import stdin
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N,K = [int(x) for x in stdin.readline().rstrip().split()]
data = [int(x) for x in stdin.readline().rstrip().split()]

M = max(data)
G = gcd_list(data)

if K <= M and K % G == 0:
    print("POSSIBLE")

else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
import fractions

N,K =list(map(int,input().split(" ")))
As= list(map(int,input().split(" ")))
g = As[0]
ma = -1
for a in As:
    g = fractions.gcd(g,a)
    ma = max(ma,a)
    if K == a:
        print("POSSIBLE")
        exit()
if K % g == 0 and ma >= K:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Accepted

Solution code:
# AGC018A - Getting Difference
from fractions import gcd
from functools import reduce


def main():
    n, k = tuple(map(int, input().rstrip().split()))
    A = tuple(map(int, input().rstrip().split()))
    G, M = reduce(gcd, A), max(A)  # gcd, max of A
    flg = k <= M and k % G == 0
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# AGC018A - Getting Difference
from fractions import gcd


def main():
    n, k = tuple(map(int, input().rstrip().split()))
    A = tuple(map(int, input().rstrip().split()))
    M = max(A)
    G = A[0]
    for i in A[1:]:
        G = gcd(G, i)
    flg = k <= max(A) and k % G == 0
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


a, b = map(int, input().split())
c = list(map(int, input().split()))
d = 0
e = max(c)
if b in c:
    print("POSSIBLE")
    exit()
if e < b:
    print("IMPOSSIBLE")
    exit()
for i in c:
    d = g_c_d(d, i)
for i in c:
    if (i - b) % d == 0:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")
exit()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
from fractions import gcd
g = a[0]
for i in range(n):
  g = gcd(g, a[i])

if k % g != 0 or max(a) < k:
  print('IMPOSSIBLE')
else:
  print('POSSIBLE')

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a%b)

n,k=map(int,input().split())
l=list(map(int,input().split()))
if k>max(l):print("IMPOSSIBLE");exit()
g=l[0]
for i in l:
    g=gcd(g,i)
if k%g==0:print("POSSIBLE")
else:print("IMPOSSIBLE")