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

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
import copy
Z = copy.deepcopy(A)
for i in range(1, N):
    Z.append(abs(A[i] - A[i - 1]))
Z.sort()
i = 0

while True:
    if i >= len(Z):
        break
    if Z[i] == 0:
        del Z[i]
        i -= 1
    elif i > 0 and Z[i] == Z[i - 1]:
        del Z[i]
        i -= 1
    i += 1

ans = -1

import fractions
gcd = Z[0]
#for i in range(1, len(Z)):
 #   gcd = fractions.gcd(gcd, Z[i])

if K % gcd == 0:
    ans = 1
    
if K > max(A):
    ans = -1
       
for i in A:
    if K == i:
        ans = 1
        break

if ans == -1:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
import copy
Z = copy.deepcopy(A)
for i in range(1, N):
    Z.append(abs(A[i] - A[i - 1]))
Z.sort()
i = 0

while True:
    if i >= len(Z):
        break
    if Z[i] == 0:
        del Z[i]
        i -= 1
    if i > 0 and Z[i] == Z[i - 1]:
        del Z[i]
        i -= 1
    i += 1

ans = -1

import fractions
gcd = Z[0]
for i in range(1, len(Z)):
    gcd = fractions.gcd(gcd, Z[i])

if K % gcd == 0:
    ans = 1
    
if K > max(A):
    ans = -1
       
for i in A:
    if K == i:
        ans = 1
        break

if ans == -1:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))
new_A = set([abs(ai-aj) for aj in A for ai in A]) - {0}
max_a = max(A)
set_A = set(A)
if k in A:
    print("POSSIBLE")
elif max_a >= k:
    if new_A - set_A == set():
        print("IMPOSSIBLE")
    else:
        print("POSSIBLE")
elif max_a < k:
    print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

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

flg = 1

def calc():
    global flg
    flg = 0
    for i in range(len(a)):
        for j in range(i+1,len(a)):
            if i == j:
                continue
            else:
                if (abs(a[i] - a[j]) not in a):
                    a.append(abs(a[i]-a[j]))
                    flg = 1
    #else:
        #print(a)
while(flg == 1):
    calc()

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()))


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


if max(A) < K:
    print("IMPOSSIBLE")
    exit()
elif K in A:
    print("POSSIBLE")
    exit()

while len(A) > 1:
    A.append(gcd(A.pop(0), A.pop(0)))

if K % A[0] == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    if A[-1] < K:
        return "IMPOSSIBLE"
    if K in A:
        return "POSSIBLE"

    sa = []
    Ak = [0 for _ in range(N)]
    Ak[0] = A[0]-K
    for i in range(N-1):
        s = A[i+1]-A[i]
        if s != 0:
            sa.append(A[i+1] - A[i])
        Ak[i+1] = A[i+1] - K
    for i in sa:
        for ak in Ak:
            if ak%i == 0:
                return "POSSIBLE"
    return "IMPOSSIBLE"

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    if A[-1] < K:
        return "IMPOSSIBLE"
    if K in A:
        return "POSSIBLE"

    sa = [0 for _ in range(N-1)]
    Ak = [0 for _ in range(N)]
    Ak[0] = A[0]-K
    for i in range(N-1):
        sa[i] = A[i+1] - A[i]
        Ak[i+1] = A[i+1] - K
    for i in sa:
        if i == 0:
            continue
        for ak in Ak:
            if ak%i == 0:
                return "POSSIBLE"
    return "IMPOSSIBLE"

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

result="POSSIBLE"
flag=True
if k > max(a):
    flag=False
    result="IMPOSSIBLE"
if k % 2 == 1:
    flag=False
    result="IMPOSSIBLE"
    for i in range(len(a)):
        if a[i]%2==1:
            flag=True
            result="POSSIBLE"
            break


while flag:
    if k in a:
        break
    a.sort()
    b=[]
    i=0
    while i < len(a):
        b.append(a[i])
        j = i+1
        while j < len(a):
            num = a[j]%a[i]
            if num == 0:
                a.pop(j)
            else:
                if not num in b:
                    b.append(num)
                j = j + 1
        i=i+1
    if len(a) == len(b):
        result="IMPOSSIBLE"
        break
    a=b
    a.sort()
    if k in a:
        break
    if 1 in a:
        break
    if len(a) == 0:
        result="IMPOSSIBLE"
        break
print(result)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

result="POSSIBLE"
flag=True
if k > max(a):
    flag=False
    result="IMPOSSIBLE"



while flag:
    if k in a:
        break
    a.sort()
    b=[]
    i=0
    while i < len(a):
        b.append(a[i])
        j = i+1
        while j < len(a):
            num = a[j]%a[i]
            if num == 0:
                a.pop(j)
            else:
                if not num in b:
                    b.append(num)
                j = j + 1
        i=i+1
    if len(a) == len(b):
        result="IMPOSSIBLE"
        break
    a=b
    a.sort()
    if k in a:
        break
    if 1 in a:
        break
    if len(a) == 0:
        result="IMPOSSIBLE"
        break
print(result)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

result="POSSIBLE"


while True:
    if k in a:
        break
    a.sort()
    b=[]
    i=0
    while i < len(a):
        b.append(a[i])
        j = i+1
        while j < len(a):
            num = a[j]%a[i]
            if num == 0:
                a.pop(j)
            else:
                if not num in b:
                    b.append(num)
                j = j + 1
        i=i+1
    if len(a) == len(b):
        result="IMPOSSIBLE"
        break
    a=b
    a.sort()
    if k in a:
        break
    if 1 in a:
        break
    if len(a) == 0:
        result="IMPOSSIBLE"
        break
print(result)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

result="POSSIBLE"


while True:
    a.sort()
    b=[]
    i=0
    while i < len(a):
        b.append(a[i])
        j = i+1
        while j < len(a):
            num = a[j]%a[i]
            if num == 0:
                a.pop(j)
            else:
                j = j + 1
        i=i+1
    #print(a)
    #print(b)
    #sys.exit()
                
    a=b
    if k in a:
        break
    if 1 in a:
        break
    if len(a) == 0:
        result="IMPOSSIBLE"
        break
    a.sort()
    b=[]    
    for i in range(len(a)-1):
        b.append(a[i])
        for j in range(i+1,len(a)):
            num = a[j]%a[i]
            if not num in b:
                if num != 0:
                    b.append(num)
    a=b
print(result)

Submission status: Time Limit Exceeded

Solution code:
import functools

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


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

mod=functools.reduce(gcd,A)

tmp=0
amax=max(A)
while 1:
  if amax-mod*tmp==K:
    print('POSSIBLE')
    exit()
  elif amax-mod*tmp<0:
    break
  tmp+=1
print('IMPOSSIBLE')

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

while 1:
    Alen1 = len(A)
    c = list(set(itertools.combinations(A, 2)))

    for i, j in c:
        A.append(abs(i - j))
        
    A = list(set(A))
        
    if K in A:
        ans = "POSSIBLE"
        break
    elif Alen1 == len(A):
        ans = "IMPOSSIBLE"
        break
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, raw_input().split())
a = sorted(map(int, raw_input().split()))
b = set()
for i in range(len(a) - 1):
    b.add(abs(a[i] - a[i+1]))
while a != sorted(set(a + list(b))):
    a = sorted(set(a + list(b)))
    b = set()
    for i in range(len(a) - 1):
        b.add(abs(a[i] - a[i+1]))

for i in range(len(a)):
    for j in range(i, len(a)):
        if a[j] - a[i] == k:
            print 'POSSIBLE'
            exit()

if k in a:
    print 'POSSIBLE'
else:
    print 'IMPOSSIBLE'

Submission status: Time Limit Exceeded

Solution code:

input1s = input()
input2s = input()

input1 = [int(i) for i in input1s.split(' ')]
N = input1[0]
K = input1[1]
numbers = [int(i) for i in input2s.split(' ')]
#print (numbers)

# 出て来る可能性のある数字を配列に追加
def func(arr):
	for i in range(len(arr)):
		for k in range(i+1, len(arr)):
			num = int(arr[i]) - int(arr[k])
			if(num < 0):
				num = (-1)*num
			count = 0
			for j in range(len(arr)):
				if(num != arr[j]):
					count += 1
			if(count == len(arr)):
				arr.append(num)
	return arr

#配列を上の関数に適用して変わらなくなるまでループ
old_num = 0
new_num = -1

count = 0
while(old_num != new_num):
	count += 1
	old_num = len(numbers)
	array = func(numbers)
	new_num = len(numbers)
	if(count > 10): #無限ループ対策	
		break

#print ("+++++++++++++")
#print (numbers)

# 判定
judge = 0
for i in range(len(numbers)):
	if(K == numbers[i]):
		judge = 1

if(judge == 1):
	print ("POSSIBLE")
if(judge == 0):
	print ("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
def f(array, n):
	for a in array:
		if a == n:
			return True
	B = set(array)
	D = set()
	endFlag = False
	while not endFlag:
		endFlag = True
		C = set(itertools.combinations(B, 2)) - D
		for e in C:
			b = abs(e[0] - e[1])
			if b == n:
				return True
			if not (b in A):
				B.add(b)
				endFlag = False
		D = D | C
	return False
print("POSSIBLE" if f(A, K) else "IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
def f(array, n):
	for a in array:
		if a == n:
			return True
	B = set(array)
	D = set()
	endFlag = False
	while not endFlag:
		B_ = list(B)
		endFlag = True
		C = set(itertools.combinations(B_, 2)) - D
		for e in C:
			b = abs(e[0] - e[1])
			if b == n:
				return True
			if not (b in A):
				B_.append(b)
				endFlag = False
		B = set(B_)
		D = D | C
	return False
print("POSSIBLE" if f(A, K) else "IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
line = raw_input()
ball_num = line.split(" ")[0]
target = int(line.split(" ")[1])
line = raw_input()
balls = [int(s) for s in line.split(" ")]

pre_set = set(balls)
cur_set = set(balls)


def tryit():
    for i in pre_set:
        cur_set.add(i)
        for j in pre_set:
            cur_set.add(abs(i - j))

tryit()
while cur_set != pre_set:
    pre_set = set(cur_set)
    tryit()
if target in cur_set:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
p = lambda  x: x #print(x)
 
PO = "POSSIBLE"
IM = "IMPOSSIBLE"
ans = ""
 
# def fnc(a, ans):
# 	for i in range(N-1):
# 		if ans != "": break
# 		x = a[N-1-i]
# 		for j in range(N-1):
# 			y = a[j]
# 			if x-y == K:
# 				ans = PO
# 				break
# 			elif x-y < 0:
# 				break
# 			else:
# 				if (x-y) not in a:
# 					a.insert(0,x-y)
# 					print(a)
# 	else:
# 		ans = IM
	
 
N, K = map(int, input().split())		# 5 7
a = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
a.sort()
p(a)
 
if max(a)<K:
	ans = IM
 
if K in a:
	ans = PO
 
if ans == "":
	for i in range(N-2):
		x = a[i]
		p(x)
		for j in range(i+1, N-1):
			y = a[j]
			p(y)
			b = y%x
			p(b)
			if b!=0 and K%b == 0:
				ans = PO
				p("A")
				break
 
		if ans != "": break
	else:
		ans = IM
		p("B")
 
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import copy

from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

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

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] = [int(input_raw[0]), int(input_raw[1])]

    input_raw = list(read_func().strip().split())
    A = set([])
    for i in range(len(input_raw)):
        A.add(int(input_raw[i]))
    A_list = list(A)
    possible_flag = False
    is_all_geometric = False
    min_gcd = sys.maxint
    if len(filter(lambda x:x >=K , A)) != 0:
        for i in range(len(A_list)):
            x = A_list[i]
            if x == K:
                possible_flag = True
                break;
            for j in range(i + 1, len(A_list)):
                g = gcd(x, A_list[j])
                if g < min_gcd:
                    min_gcd = g
        if min_gcd == 1:
            possible_flag = True
        elif ((K % min_gcd != 0) and len(filter(lambda x:x%min_gcd != 0, A))== 0) == False:
            possible_flag = True


    if possible_flag == True:
        print "POSSIBLE"
    else:
        print "IMPOSSIBLE"


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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")

	decomp_min = decomp(min_num)
	for x in decomp_min:
		res = [y % x for y in nums]

		# 共通因子を持ってなかったらだめ
		if max(res) == min(res):
			if K % x > 0:
				return("IMPOSSIBLE")
	else:
		return("POSSIBLE")

def decomp(n):
	i = 2
	table = [n]

	while i <= n:
		if n % i == 0:
			table.append(int(i))
		i += 1
	return(table)

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

Submission status: Time Limit Exceeded

Solution code:
import math
import sys


def factors(n):  # generator that computes factors
    k = 1
    while k * k < n:  # while k < sqrt(n)
        if n % k == 0:
            yield k
            yield n//k
        k += 1
    if k * k == n:  # special case if n is perfect square
        yield k


N, K = map(int, input().split())
l1 = set(map(int, input().split()))
if K in l1:
    print("POSSIBLE")
    sys.exit()
s1 = set(math.fabs(K - ll) for ll in l1 if ll > K)
s2 = set([])
for i in s1:
        s2 = s2 | set(factors(i))

for i in s2:
    for j in l1:
        if (i + j) in l1:
            print("POSSIBLE")
            sys.exit()
print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

an = sorted(an,reverse=True)
if K in an:
    print('POSSIBLE')
    exit()

visited = {}
def dfs(a, b):
    d = a - b 
    if K == d:
        return 1
    if d in an:
        return 0
    visited[(a,b)]=True
    for it in combinations(an + [d], 2):
        if visited.get((it[0],it[1]), False):
            continue
        if dfs(it[0], it[1]) == 1:
            return 1
    return 0
        
comb=combinations(an, 2)
s=sum([dfs(it[0], it[1]) for it in comb])
if s == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Submission status: Time Limit Exceeded

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")

	decomp_min = decomp(min_num)

	for i, x in enumerate(decomp_min):
		res = [y % x for y in nums]

		# 共通因子を持ってなかったらだめ
		if max(res) == min(res):
			if K % x > 0:
				return("IMPOSSIBLE")
	else:
		return("POSSIBLE")

def decomp(n):
	i = 2
	table = [n]

	while i * n  <= n * n:
		if n % i == 0:
			table.append(int(i))
		i += 1
	return(table)

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

Submission status: Time Limit Exceeded

Solution code:
#Getting Difference
 
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
b = sorted(A)
flag = False
if ( K>b[-1] ):
    pass
elif ( K==b[-1] ):
    flag = True
else:
    dif = b
    while 1:
        tmp = dif
        n = len(b)-1
        l = [ [n-j for j in range(n-i) ] for i in range(n)]
        dif = sorted([b[j]-b[i]  for i in range(n) for j in l[i]] )
        b = list(set(sorted(b+dif)))
        if ( len(b)==len(tmp) ):
            break
              
        if K in b:
            flag = True
            break
    
 
 
#result
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
#p = lambda  x: x #print(x)

PO = "POSSIBLE"
IM = "IMPOSSIBLE"
ans = ""

# def fnc(a, ans):
# 	for i in range(N-1):
# 		if ans != "": break
# 		x = a[N-1-i]
# 		for j in range(N-1):
# 			y = a[j]
# 			if x-y == K:
# 				ans = PO
# 				break
# 			elif x-y < 0:
# 				break
# 			else:
# 				if (x-y) not in a:
# 					a.insert(0,x-y)
# 					print(a)
# 	else:
# 		ans = IM
	

N, K = map(int, input().split())		# 5 7
a = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
a.sort()
#p(a)

if max(a)<K:
	ans = IM

if K in a:
	ans = PO

if ans == "":
	for i in range(N-2):
		x = a[i]
		#p(x)
		for j in range(i+1, N-1):
			y = a[j]
			#p(y)
			b = y%x
			#p(b)
			if b!=0 and K%b == 0:
				ans = PO
				#p("A")
				break

		if ans != "": break
	else:
		ans = IM
		#p("B")


print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, k = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
isPossible = False

K = [k]

for a in A:
	if a > k:
		break
	if k - a in A:
		isPossible = True
		break
	elif a in K:
		isPossible = True
		break
	else:
		K.append(k-a)


if k > max(A):
	isPossible = False

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, raw_input().split(" "))
s = set(map(int, raw_input().split(" ")))

def check(ar):
  if k in s: return True
  for i in xrange(len(ar)):
    v = ar[i]
    if v < k: continue
    w = ar[i] - k
    for j in xrange(i):
      if ar[j] > w: break
      if w % ar[j] == 0: return True
  return False

if k in s:
  print "POSSIBLE"
  exit()
ar = sorted(s)
while 1:
  changed = False
  prev = None
  deltas = [0]
  for a in ar:
    if not prev:
      prev = a
      continue
    v = a - prev
    for i in xrange(len(deltas)):
      n = deltas[i] + v
      deltas[i] += v
      if n not in s:
        s.add(n)
        changed = True
    deltas.append(v)
    prev = a
  ar = sorted(s)
  if check(ar):
    print "POSSIBLE"
    exit()
  elif not changed:
    print "IMPOSSIBLE"
    exit()

Submission status: Time Limit Exceeded

Solution code:
p = lambda  x: x #print(x)

PO = "POSSIBLE"
IM = "IMPOSSIBLE"
ans = ""

# def fnc(a, ans):
# 	for i in range(N-1):
# 		if ans != "": break
# 		x = a[N-1-i]
# 		for j in range(N-1):
# 			y = a[j]
# 			if x-y == K:
# 				ans = PO
# 				break
# 			elif x-y < 0:
# 				break
# 			else:
# 				if (x-y) not in a:
# 					a.insert(0,x-y)
# 					print(a)
# 	else:
# 		ans = IM
	

N, K = map(int, input().split())		# 5 7
a = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
a.sort()
p(a)

if max(a)<K:
	ans = IM

if K in a:
	ans = PO

if ans == "":
	for i in range(N-2):
		x = a[i]
		p(x)
		for j in range(i+1, N-1):
			y = a[j]
			p(y)
			b = y%x
			p(b)
			if b!=0 and K%b == 0:
				ans = PO
				p("A")
				break

		if ans != "": break
	else:
		ans = IM
		p("B")


print(ans)

Submission status: Time Limit Exceeded

Solution code:
#Getting Difference
 
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
b = sorted(A)
flag = False
if ( K>b[-1] ):
    pass
elif ( K==b[-1] ):
    flag = True
else:
    dif = b
    while 1:
        tmp = dif
        dif = list(set([ abs(i-j) for i in b for j in b ]))[1:]
        b = list(set(sorted(b+dif)))
        if ( len(b)==len(tmp) ):
            break
              
        if K in b:
            flag = True
            break
    
 
 
#result
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

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

if K in A:
    print("POSSIBLE")
elif K > max(A):
    print("IMPOSSIBLE")
else:
    l = 0
    d2 = A[:]
    while l != len(A):
        l = len(A)
        d = {abs(A[i] - j) for i in range(l) for j in d2}
        if K in d:
            print("POSSIBLE")
            exit()
        A = list(set(A).union(d))
        d2 = list(d)
    print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

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

if K in A:
    print("POSSIBLE")
elif K > max(A):
    print("IMPOSSIBLE")
else:
    l = 0
    while l != len(A):
        l = len(A)
        d = {abs(A[i] - A[j]) for i in range(l) for j in range(i, l)}
        if K in d:
            print("POSSIBLE")
            exit()
        A = list(set(A).union(d))
    print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
def a():
    n, k = map(int, input().split())
    A = {int(a) for a in input().split()}

    if k > max(A):
        print('IMPOSSIBLE')
        return
    # combination of two nums in A
    # keep making the combination -
    # until it finds k or doesn't increase in number.
    from itertools import combinations as combi
    l = len(A)
    while True:
        A |= { abs(c[0] - c[1]) for c in combi(A, 2) }
        if k in A or 1 in A:
            print('POSSIBLE')
            return
        if len(A) == l:
            break
        l = len(A)
    print( 'POSSIBLE' if k in A else 'IMPOSSIBLE' )

    # 差が1の組みがあれば絶対可能
    # 差が2の組みがあり、kと偶奇が同じ数があれば可能

a()

Submission status: Time Limit Exceeded

Solution code:
N, k = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
isPossible = False

K = [k]

for a in A:
	if a in K:
		isPossible = True
		break
	else:
		K.append(abs(k-a))
for a in A:
	if a in K:
		isPossible = True
		break



if k in A:
	isPossible = True

if k > max(A):
	isPossible = False

# print(K)
if isPossible:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
def a():
    n, k = map(int, input().split())
    A = {int(a) for a in input().split()}

    if k > max(A):
        print('IMPOSSIBLE')
        return
    # combination of two nums in A
    # keep making the combination -
    # until it finds k or doesn't increase in number.
    from itertools import combinations as combi
    l = len(A)
    while True:
        A |= { abs(c[0] - c[1]) for c in combi(A, 2) }
        if k in A:
            print('POSSIBLE')
            return
        if len(A) == l:
            break
        l = len(A)
    print( 'POSSIBLE' if k in A else 'IMPOSSIBLE' )

    # 差が1の組みがあれば絶対可能
    # 差が2の組みがあり、kと偶奇が同じ数があれば可能

a()

Submission status: Time Limit Exceeded

Solution code:
N, k = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
isPossible = False

K = [k]

for a in A:
	if abs(k - a) in A:
		isPossible = True
		break
	elif a in K:
		isPossible = True
		break
	else:
		K.append(abs(k-a))

if k in A:
	isPossible = True

if k > max(A):
	isPossible = False

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

Submission status: Time Limit Exceeded

Solution code:
#Getting Difference

N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
b = sorted(A)
flag = False
if ( K>b[-1] ):
    pass
elif ( K==b[-1] ):
    flag = True
else:
    sabun = b
    while 1:
        tmp = sabun
        sabun = list(set([ abs(i-j) for i in b for j in b ]))[1:]
        b = list(set(sorted(b+sabun)))
        #print(b, tmp)
        if ( len(b)==len(tmp) ):
            break
              
        if K in b:
            flag = True
            break
    


#result
if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = list(map(int, input().split()))
args = list(map(int, input().split()))

if K > max(args):
    print("IMPOSSIBLE")
    exit()

rev = sorted(args, reverse=True)
m = args[0]
check = [False for i in range(0, rev[0] + 1)]
mn = min(args)
same = True
for i in range(0, len(rev)):
    check[rev[i]] = True
    if same and rev[i] % mn == 0:
        same = False
if same:
    print("POSSIBLE")
    exit()

if check[K]:
    print("POSSIBLE")
    exit()

n = rev[1]
while not n == 0:
    for j in range(rev[0], n, -1):
        if check[j]:
            if j - n == K:
                print("POSSIBLE")
                exit()
            check[j - n] = True
    old_n = n
    for j in range(n-1, 0, -1):
        if check[j]:
            n = j
            break
    if old_n == n:
        break

print("IMPOSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
#! cat input | python3 main.py

n, k = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    if a[0] == k:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    __import__("sys").exit()
a.sort()
ma = max(a)
def isfact(n):
    if n == 2: return True
    for i in (2, n**0.5 + 1):
        if n % i == 0:
            return False
    return True
def calcfacts():
    r = []
    for i in range(2, 10**5):
        if isfact(i):
            r.append(i)
    return r
allfacts = calcfacts()

def prim_fact(n):
    facts = []
    ti = 0
    t = allfacts[ti]
    nn = n ** 0.5 + 1
    while True:
        if n % t == 0:
            facts.append(t)
            n //= t
        else:
            ti += 1
            t = allfacts[ti]
        if t >= n or t > nn:
            if n != 1:
                facts.append(n)
            break
    return facts


def f(a, k, ma):
    minv = float("inf")
    for i, v in enumerate(a[1:]):
        if v - a[i] != 0:
            minv = min(minv, v - a[i])
    minv = min(minv, a[0])

    sets = []
    setn = set()
    for v in a:
        s = set(prim_fact(v))
        # sets.append(s)
        # for i in s: setn.add(i)
    # for v in setn:
    #     for s in sets:
    #         if v not in s:
    #             break
    #     else:
    #         minv = min(minv, v)
    #         break
    # else:
    #     return False

    if minv == 1:
        return False

    a = a[:]
    for i in range(0, ma + minv, minv):
        if i == k:
            return False
        if i < a[0]:
            continue
        if i == a[0]:
            del a[0]
        else:
            return False
    return True

if ma < k:
    print("IMPOSSIBLE")
elif f(a, k, ma):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Submission status: Time Limit Exceeded

Solution code:
#! cat input | python3 main.py

n, k = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    if a[0] == k:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    __import__("sys").exit()
a.sort()
ma = max(a)
def isfact(n):
    if n == 2: return True
    for i in (2, n**0.5 + 1):
        if n % i == 0:
            return False
    return True
def calcfacts():
    r = []
    for i in range(2, 10**5):
        if isfact(i):
            r.append(i)
    return r
allfacts = calcfacts()

def prim_fact(n):
    facts = []
    ti = 0
    t = allfacts[ti]
    nn = n ** 0.5 + 1
    while True:
        if n % t == 0:
            facts.append(t)
            n //= t
        else:
            ti += 1
            t = allfacts[ti]
        if t >= n or t > nn:
            if n != 1:
                facts.append(n)
            break
    return facts


def f(a, k, ma):
    minv = float("inf")
    for i, v in enumerate(a[1:]):
        if v - a[i] != 0:
            minv = min(minv, v - a[i])
    minv = min(minv, a[0])

    sets = []
    setn = set()
    for v in a:
        s = set(prim_fact(v))
        sets.append(s)
        for i in s: setn.add(i)
    # for v in setn:
    #     for s in sets:
    #         if v not in s:
    #             break
    #     else:
    #         minv = min(minv, v)
    #         break
    # else:
    #     return False

    if minv == 1:
        return False

    a = a[:]
    for i in range(0, ma + minv, minv):
        if i == k:
            return False
        if i < a[0]:
            continue
        if i == a[0]:
            del a[0]
        else:
            return False
    return True

if ma < k:
    print("IMPOSSIBLE")
elif f(a, k, ma):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")