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:
from fractions import gcd
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
min_A, max_A = min(A), max(A)
g = A[0]
for i in range(1, N):
    g = gcd(g, A[i])
if max_A < K:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE" if g == 1 else "IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def ris(): return list(input())
def pli(a): return "".join(list(map(str, a)))

n, k = rli()
a = rli()
if(max(a) < k):
    print("IMPOSSIBLE")
elif(k in a):
    print("POSSIBLE")
else:
    sa = 114514810
    sorted(a)
    for i in range(n-1):
        if(abs(a[i] - a[i+1]) != 0):
            sa = min(sa, abs(a[i] - a[i+1]))
    if(sa == 114514810):
        print("IMPOSSIBLE")
    elif(sa == 1):
        print("POSSIBLE")
    else:
        flag = False
        for i in a:
            if(i % sa != 0):
                flag = True
        if(k % sa == 0):
            flag = True
        if(flag):
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N,K = LI()
    a = LI()
    if max(a) < K:
        return 'IMPOSSIBLE'
    if K in a:
        return 'POSSIBLE'
    t = 2
    #for i in range(1,N):
    #    t = math.gcd(a[i], t)
    if t <= 1:
        return 'POSSIBLE'
    for c in a:
        if (c > K) and (((c-K) % t) == 0):
            return 'POSSIBLE'

    return 'IMPOSSIBLE'


print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N,K = LI()
    a = LI()
    if max(a) < K:
        return 'IMPOSSIBLE'
    if K in a:
        return 'POSSIBLE'
    t = a[0]
    #for i in range(1,N):
    #    t = math.gcd(a[i], t)
    if t <= 1:
        return 'POSSIBLE'
    for c in a:
        if (c > K) and (((c-K) % t) == 0):
            return 'POSSIBLE'

    return 'IMPOSSIBLE'


print(main())

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
if n == 1:
    a = int(raw_input())
    if a == k:
        print "POSSIBLE"
    else:
        print "IMPOSSIBLE"
    exit()
a = map(int, raw_input().split())
a.sort()
if k in a:
    print "POSSIBLE"
    exit()
ok = False
for i in xrange(n - 1):
    if a[i + 1] - a[i] == a[0]:continue
    ok = True
print "POSSIBLE" if ok else "IMPOSSIBLE"

Submission status: Wrong Answer

Solution code:
# coding:utf-8
from itertools import combinations
N, K = map(int, raw_input().split(' '))
A = map(int, raw_input().split(' '))
setA = set(A)


def difference(data, goal):
    set_data = set(data)
    diff_data = [abs(d1 - d2) for d1, d2 in combinations(data, 2)]
    if goal in diff_data:
        return 'POSSIBLE'
    if set(diff_data) <= set_data:
        return 'INPOSSIBLE'
    else:
        new_data = data + diff_data
        return difference(new_data, goal)


if K in A:
    print 'POSSIBLE'
else:
    print difference(A, K)

Submission status: Wrong Answer

Solution code:
import sys

# sys.stdin = open('a1.in')


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


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


def read_str_list():
    return input().split()


def read_str():
    return input()


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


def solve():
    n, k = read_int_list()
    a = read_int_list()
    if k > max(a):
        return 'IMPOSSIBLE'
    g = a[0]
    for i in range(1, n):
        g = gcd(g, a[i])
        if k % g == 0:
            return 'POSSIBLE'
    return 'IMPOSSIBLE'


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
min_A, max_A = min(A), max(A)
if max_A < K:
    print("IMPOSSIBLE")
elif min_A == 1:
    print("POSSIBLE")
elif all(a % min_A == 0 for a in A):
    print("POSSIBLE" if K % min_A == 0 else "IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
def main():
	N, K = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	
	max_num = max(nums)
	min_num = min(nums)

	if K > max_num:
		return("IMPOSSIBLE")

	res = [x % min_num for x in nums]
	if max(res) == min(res):
		if K % min_num == 0:
			return("POSSIBLE")
		else:
			return("IMPOSSIBLE")
	else:
		return("POSSIBLE")


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

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
if n == 1:
    a = int(raw_input())
    if a == k:
        print "POSSIBLE"
    else:
        print "IMPOSSIBLE"
    exit()
a = map(int, raw_input().split())
a.sort()
if k in a:
    print "POSSIBLE"
    exit()
d = a[1] - a[0]
ok = False
for i in xrange(n - 1):
    if a[i + 1] - a[i] == d:continue
    ok = True
print "POSSIBLE" if ok else "IMPOSSIBLE"

Submission status: Time Limit Exceeded

Solution code:
from sys import exit
from fractions import gcd

def segfunc(x, y):
    '''
    問題に応じて返り値を設定
    '''
    return gcd(x, y)


def init(a):
    '''
    配列aで初期化
    '''
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])


def query(p, q):
    '''
    [p, q)についてsegfuncを適用したものを返す
    '''
    if q <= p:
        return ide_ele
    
    p += num - 1
    q += num - 2
    res = ide_ele

    while q - p > 1:
        if p & 1 == 0:
            res = segfunc(res, seg[p])
        if q & 1 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(res, segfunc(seg[p], seg[q]))
    
    return res


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

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

num = (2 ** len(bin(n - 1)) - 2)
ide_ele = 0
seg = [ide_ele] * 2 * num

init(a)

if k % query(0, n) == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Time Limit Exceeded

Solution code:
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
lis=LI()
lis.sort(reverse=True)
ex=[0 for i in range(lis[-1])]
for i in range(1,n):
    if ex[lis[i]%lis[-1]]==0:
        ex[lis[i]%lis[-1]]+=1
    if ex[lis[-1]-lis[i]%lis[-1]-1]==0:
        ex[lis[-1]-lis[i]%lis[-1]-1]+=1
#print(ex)
for i in range(n):
    if lis[i]<k:
        break
    elif lis[i]==k:
        print("POSSIBLE")
        sys.exit()
    elif ex[(lis[i]-k)%lis[-1]]==1:
        print("POSSIBLE")
        sys.exit()
print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

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

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

while True:
  tmp = []
  for i in range(len(arr)-1):
    for k in range(i, len(arr)-1):
    	tmp.append(abs(arr[i]-arr[k+1]))
  tmp.append(abs(arr[0]-arr[-1]))
  tmp = list(set(tmp))
  
  if k in tmp:
    print("POSSIBLE")
    exit()

  if len(set(arr+tmp)) == len(arr) or len(set(arr+tmp)) == len(tmp):
    print("IMPOSSIBLE")
    exit()
    
  arr = list(set(arr+tmp))

Submission status: Time Limit Exceeded

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()
    for i in range(2,int(M**0.5)+10):
        B = set(map(lambda x:x%i,A))
        if len(B) == 1:
            print("IMPOSSIBLE")
            exit()
    print("IMPOSIBLE")
    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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()
    for i in range(2,int(M**0.5)+10):
        B = set(map(lambda x:x%i,A))
        if len(B) == 1:
            print("IMPOSSIBLE")
            exit()
    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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 a in A:
        if a-K in A:
            print("POSSIBLE")
            exit()
        elif K-a 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: Time Limit Exceeded

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 = 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: Time Limit Exceeded

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:]
    post = A[:key]
    for a in pre:
        if a-K in A:
            print("POSSIBLE")
            exit()
    B = 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: Time Limit Exceeded

Solution code:
import sys

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

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 a :
      c = 1
  if c == 1 :
    ans = 'POSSIBLE'
    break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce


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

N,K = map(int, input().split())
A = [int(i) for i in input().split()]
a = gcd_a(A)
cnt = max(A)
while cnt > K:
    cnt -= a
print('POSSIBLE' if cnt == K else 'IMPOSSIBLE')

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if a[-1] < k:
    print('IMPOSSIBLE')
elif k in a:
    print('POSSIBLE')
else:
    b = []
    while len(a) != len(b):
        b = a.copy()
        lea = a[0]
        for i in range(n-1):
            a.append(a[i+1]-a[i])
        a = list(set(a))
    if k % a[0] == 0:
        print('POSSIBLE')
    else: print('IMPOSSIBLE')

Submission status: Time Limit Exceeded

Solution code:
n,k,*a=map(int,open(0).read().split())

from fractions import gcd


G=a[0]
for i in a:
    G=gcd(G,i)
    
A=max(a)
if k>A:
    print("IMPOSSIBLE")
    exit()
    
while A>0:
    if k==A:
        print("POSSIBLE")
        exit()
    A-=G
print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
n,k,*a=map(int,open(0).read().split())

from fractions import gcd


G=a[0]
for i in a:
    G=gcd(G,i)
    
A=max(a)

while A>0:
    if k==A:
        print("POSSIBLE")
        exit()
    A-=G
print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

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


N, K = map(int, input().split())
A = list(map(int, input().split()))
if K in A:
    print("POSSIBLE")
    exit()

max_val = max(A)
if max_val < K:
    print("IMPOSSIBLE")
    exit()

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

ans = max_val
while K <= ans:
    if K == ans:
        print("POSSIBLE")
        exit()
    else:
        ans -= gcd_val
print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

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 not divide:
        print("POSSIBLE")
    else:
        if target % 2 == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

flag = 0
A_len = len(A)
while K not in A:
    for i in itertools.permutations(A, 2):
        A.add(abs(i[0] - i[1]))
    if A_len == len(A):
        flag = 1
        break
    if 1 in A:
        break

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

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

flag = 0
A_len = len(A)
while K not in A:
    for i in itertools.permutations(A, 2):
        A.add(abs(i[0] - i[1]))
    if A_len == len(A):
        flag = 1
        break

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

Submission status: Time Limit Exceeded

Solution code:
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def swap(a,b):
    c=a
    a=b
    b=c
    return a,b
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n,k = map(int,input().split()) 
    a = list(map(int,input().split()))
    x=a[0]
    for i in range(n-1):
        x=gcd(x,a[i+1])
    if k in a:
        print("POSSIBLE")
        return
    while k<=max(a):
        k+=x
        if k in a:
            print("POSSIBLE")
            return
    print("IMPOSSIBLE")
main()

Submission status: Time Limit Exceeded

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:
        for w in w_list:
            if w + K in w_list:
                return True, w_list

        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: Time Limit Exceeded

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

if max(A) < K:
    print('IMPOSSIBLE')
    exit()

if K in A:
    print('POSSIBLE')
    exit()

arr = []
for i in range(N):
    for j in range(len(A)):
        for k in range(len(A)):
            if j != k:
                arr.append(abs(A[j] - A[k]))
        arr = list(set(arr))
        A += arr
        A = list(set(A))
        if K in A:
            print('POSSIBLE')
            exit()
    arr = []

print('IMPOSSIBLE')

Submission status: Time Limit Exceeded

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

if max(A) < K:
    print('IMPOSSIBLE')
    exit()

if K in A:
    print('POSSIBLE')
    exit()

for i in range(len(A)):
    for j in range(i+1, len(A)):
        if i != j:
            A.append(abs(A[i] - A[j]))

set_A = list(set(A))

for i in range(len(set_A)):
    for j in range(i+1, len(set_A)):
        if abs(set_A[i] - set_A[j]) == K:
            print('POSSIBLE')
            exit()

print('IMPOSSIBLE')

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
l=list(map(int,input().split()))

if max(l)<K:
    print("IMPOSSIBLE")
    exit()

temp=[]
prev_l=[-1]

while prev_l!=l: #temp <=> l
    temp.clear()
    prev_l.clear()
    prev_l=prev_l+l
    for i in range(len(l)-1):
        for j in range(i+1,len(l)):
            temp.append(abs(l[i]-l[j]))
    l=l+temp
    l=list((set(l)))
    for i in range(len(l))[::-1]:
        if l[i]>K:
            for j in range(i)[::-1]:
                if (l[i]-K)%l[j]==0:
                    print("POSSIBLE")
                    exit()
        elif l[i]==K:
            print("POSSIBLE")
            exit()
        else:
            break
    
print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
l=list(map(int,input().split()))

if max(l)<K:
    print("IMPOSSIBLE")
    exit()

temp=[]
prev_l=[-1]
while prev_l!=l: #temp <=> l <=> prev_l
    temp.clear()
    prev_l.clear()
    prev_l=prev_l+l
    for i in range(len(l)-1):
        for j in range(i+1,len(l)):
            temp.append(abs(l[i]-l[j]))
    l=l+temp
    if 1 in l or K in l:
        print("POSSIBLE")
        exit()
    l=list((set(l)))
    #print(l)
    
print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
l=list(map(int,input().split()))

if max(l)<K:
    print("IMPOSSIBLE")
    exit()

temp=[]
prev_l=[-1]
while prev_l!=l: #temp <=> l <=> prev_l
    temp.clear()
    prev_l.clear()
    prev_l=prev_l+l
    for i in range(len(l)-1):
        for j in range(i+1,len(l)):
            temp.append(abs(l[i]-l[j]))
    l=l+temp
    if K in l:
        print("POSSIBLE")
        exit()
    l=list((set(l)))
    #print(l)
    
print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())

l=list(map(int,input().split()))
new=[]

for i in range(N):
    for j in range(i+1,N):
        if l[i]-l[j]==K:
            print("POSSIBLE")
            break
        new.append(abs(l[i]-l[j]))

Key=True

try:
    while Key:
        temp=[]
        for i in range(len(l)):
            for j in range(len(new)):
                if l[i]-new[j]==K:
                    print("POSSIBLE")
                    Key=False
                    break
                temp.append(abs(l[i]-new[j]))
        l=l+new
        new.clear()
        new+=temp
except TimeoutError:
    print("IMPOSSIBLE")
    



'''
while Key:
    print(new)
    temp=[]
    for i in range(len(l)):
        for j in range(len(new)):
            if l[i]-new[j]==K:
                print("POSSIBLE")
                Key=False
                break
            temp.append(abs(l[i]-new[j]))
    l=l+new
    new.clear()
    new+=temp
'''

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
import itertools
flag = True
while(flag):
    count = 0
    if K in A:
        flag = False
        break
    A_2 = list(itertools.combinations(A,2))
    for comb in A_2:
        diff = abs(comb[0] - comb[1])
        if diff not in A:
            A.append(diff)
        else:
            count += 1
    else:
        if (count == len(A_2)):
            flag = False
if K in A:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
import itertools
flag = True
while(flag):
    count = 0
    A_2 = list(itertools.combinations(A,2))
    for comb in A_2:
        diff = abs(comb[0] - comb[1])
        if diff not in A:
            A.append(diff)
        else:
            count += 1
    else:
        if (count == len(A_2)) or (K in A):
            flag = False
if K in A:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
import itertools
flag = True
while(flag):
    count = 0
    A_2 = list(itertools.combinations(A,2))
    for comb in A_2:
        diff = abs(comb[0] - comb[1])
        if diff not in A:
            A.append(diff)
        else:
            count += 1
    else:
        if (count == len(A_2)):
            flag = False
if K in A:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter as ct

def factoring(n):
    root = int(n ** .5) + 1
    arr = []
    for i in range(2, root):
        while(n % i == 0):
            arr.append(i)
            n //= i
    if n > 1:
        arr.append(n)
    return ct(arr)

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

kp = factoring(k)
ap = list(map(factoring, a))
ap0 = ap[0]
for a_cnt in ap[1:]:
    ap0 = ap0 & a_cnt
prod = 1
for p, x in ap0.items():
    prod *= p ** x

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

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
	while a*b>0:
		a,b = min(a,b),max(a,b)
		a,b = b-a, a
	return b

N,K=map(int,input().split())
A=sorted(list(set(map(int,input().split()))))
if len(A)>1:
	R=gcd(A[1],A[0])
	for i in range(1,len(A)-1):
		R=gcd(R,(A[i+1]-A[i]))
	if K<=A[-1] and (K-A[0])%R==0:
		print('POSSIBLE')
	else:
		print('IMPOSSIBLE')
else:
	if K==A[0]:
		print('POSSIBLE')
	else:
		print('IMPOSSIBLE')

Submission status: Time Limit Exceeded

Solution code:
N, X = map(int, input().split())
A = set(list(map(int, input().split())))
lenA = len(A)
prev = 0
while prev != lenA:
    if X in A:
        print("POSSIBLE")
        exit()
    cand = set()
    for i, a in enumerate(A):
        if i == 0:
            aa = a
            continue
        tmp = abs(aa - a)
        if tmp not in A:
            cand.add(tmp)
        A = set.union(A, cand)
    prev= len(A)
print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

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

li.sort()
max = li[-1]

while(len(li) > 1):
    v = li[0]
    for i in range(1, len(li)):
        li[i] = li[i]%v
    for _ in range(li.count(0)):
        li.remove(0)
    li.sort()

if K <= max:
    if K%li[0] == max%li[0]:
        print('POSSIBLE')
        exit()

print('IMPOSSIBLE')

Submission status: Time Limit Exceeded

Solution code:
def factor(N):
    ret = []
    i = 2
    while N > 1:
        if N % i == 0:
            ret.append(i)
            N //= i
        else:
            i += 1
    return ret


from collections import Counter


def solve(N, K, As):
    if K > max(As):
        return "IMPOSSIBLE"

    factors = [Counter(factor(a)) for a in As]
    iter = factors[0]
    for f in factors[1:]:
        for k, v in iter.items():
            if k not in f:
                iter[k] = 0
            else:
                iter[k] = min(v, f[k])

    if all([v == 0 for v in iter.values()]):
        return "POSSIBLE"
    else:
        d = 1
        for k, v in iter.items():
            if v != 0:
                d *= k ** v
        if K % d == 0:
            return "POSSIBLE"
    return "IMPOSSIBLE"

if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    As = list(map(int, input().split(" ")))
    print(solve(N, K, As))

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = []
for r in ar:
    if r > b:
        br.append(r-b)
    elif r == b:
        print("POSSIBLE")
        exit()
m = 0
if len(br) == 0:
    print("IMPOSSIBLE")
else:
    for i in range(max(ar),0,-1):
        count = 0
        for r in ar:
            if r % i == 0:
                count += 1
        if count == a:
            m = i
            break
    for r in br:
        if r % m == 0:
            print("POSSIBLE")
            exit()
    print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
if k>max(a):
    print("IMPOSSIBLE")
    exit()
if k in a:
    print("POSSIBLE")
    exit()
for i in range(n-1):
    for j in range(i+1,n):
        t=abs(a[i]-a[j])
        if (t): k%=abs(a[i]-a[j])
print(["IMPOSSIBLE","POSSIBLE"][k==0])

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
d=set()
if k>max(a):
    print("IMPOSSIBLE")
    exit()
if k in a:
    print("POSSIBLE")
    exit()
for i in range(n-1):
    for j in range(i+1,n):
        d.add(abs(a[i]-a[j]))
ans=chk=0
d=list(d)
d.sort()
for i in d:
    k%=i
    if i>k or k==0:break
print(["IMPOSSIBLE","POSSIBLE"][k==0])

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
d=set()
if k>max(a):
    print("IMPOSSIBLE")
    exit()
if k in a:
    print("POSSIBLE")
    exit()
for i in range(n-1):
    for j in range(i+1,n):
        d.add(abs(a[i]-a[j]))
ans=chk=0
for i in d:
    k%=i
print(["IMPOSSIBLE","POSSIBLE"][k==0])

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
L = list(map(int,input().split()))
L = sorted(L,reverse=False)

ans = "IMPOSSIBLE"
if L[-1] < K :
    ans = "IMPOSSIBLE"
elif (K in L) or (1 in L) : 
    ans = "POSSIBLE"
else :
    for i in range(1,N) :
        if L[i] % L[0] != 0 :
            ans = "POSSIBLE"
            break

for i in range(N) :
    if (K + L[i]) in L :
        ans = "POSSIBLE"

print(ans)