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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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
    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: Wrong Answer

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


while len(A) > 1:
    A.append(gcd(A.pop(), A.pop()))
if K % A[0] == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

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


while len(A) > 1:
    A.append(gcd(A.pop(), A.pop()))
if A[0] == 1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
n,k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
a.sort()
for i in range(a[0],0,-1):
	if a[0]%i==0:
		if all(a[j]%i==0 for j in range(n)):
			num = i
			break
if k%num==0: print("POSSIBLE")
else: print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

array = [int(x) for x in input().split()]
res = sorted(array)
judge = False
tmp = res.pop(0)
for i in res:
  if i%tmp != 0:
    judge = True
    break
print("POSSIBLE" if judge else "IMPOSSIBLE")

Submission status: Wrong Answer

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


mod=functools.reduce(gcd,A)

tmp=0
if max(A)>=K and K%mod==0:
  print('POSSIBLE')
else:
  print('IMOSSIBLE')

Submission status: Wrong Answer

Solution code:
x =input()
if x=="A":
	print(1)
elif x=="B":
	print(2)
elif x=="C":
	print(3)
elif x=="D":
	print(4)
elif x=="E":
	print(5)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import itertools
N,K=map(int, raw_input().split())
A=map(int, raw_input().split())
B=list(itertools.permutations(A,2))

if K in A:
    print 'POSSIBLE'
else:
    C=[]
    for i in B:
        C.append(abs(i[0]-i[1]))
    if K in C:
        print 'POSSIBLE'
    else:
        D=list(itertools.permutations(C,2))
        E=[]
        for j in D:
            E.append(j[0]+j[1])
        if K in E:
            print 'POSSIBLE'
        else:
            print 'IMPOSSIBLE'

Submission status: Wrong Answer

Solution code:
input1 = list(map(int,input("").split(" ")))
A = list(map(int,input("").split(" ")))
N = input1[0]
K = input1[1]
A.sort()
if K in A:
	flag = True
elif K > max(A):
	flag = False
else:
	flag = False
	for i in range(N-3):
		if abs(A[i]-A[i+1])%2 | abs(A[i+2]-A[i+1])%2 != 0:
			flag = True
			break

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

Submission status: Wrong Answer

Solution code:
input1 = list(map(int,input("").split(" ")))
A = list(map(int,input("").split(" ")))
N = input1[0]
K = input1[1]
A.sort()
if K in A:
	flag = True
elif K > max(A):
	flag = False
else:
	flag = True
	for i in range(N-3):
		if abs(A[i]-A[i+1]) != abs(A[i+2]-A[i+1]):
			flag = False
			break

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

Submission status: Wrong Answer

Solution code:
input1 = list(map(int,input("").split(" ")))
A = list(map(int,input("").split(" ")))
N = input1[0]
K = input1[1]

if K in A:
	flag = True
elif K > max(A):
	flag = False
else:
	flag = True
	for i in range(N-3):
		if abs(A[i]-A[i+1]) != abs(A[i+2]-A[i+1]):
			flag = False
			break

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

Submission status: Wrong Answer

Solution code:
input1 = list(map(int,input("").split(" ")))
A = list(map(int,input("").split(" ")))
N = input1[0]
K = input1[1]

flag = True
for i in range(N-3):
	if abs(A[i]-A[i+1]) != abs(A[i+2]-A[i+1]):
		flag = False
		break

if K in A:
	flag = True

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

Submission status: Wrong Answer

Solution code:
input1 = list(map(int,input("").split(" ")))
A = list(map(int,input("").split(" ")))
N = input1[0]
K = input1[1]

flag = True
for i in range(N-3):
	if abs(A[i]-A[i+1]) != abs(A[i+2]-A[i+1]):
		flag = False
		break

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

Submission status: Wrong Answer

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: Wrong Answer

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: Wrong Answer

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:
			print(e)
			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: Wrong Answer

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:
        print i
        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()
print cur_set
print target
if target in cur_set:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def get_difference():
	# get input from raw_input()
	n, k = map(int, raw_input().split(' '))
	l = [int(e) for e in raw_input().split(' ')]
	if k in l:
		print "POSSIBLE"
		return
	if k>max(l):
		print "INPOSSIBLE"
		return
	gcd_v = reduce(gcd, l)
	if k%gcd_v==0:
		print "POSSIBLE"
	else:
		print "INPOSSIBLE"
 
 
if __name__ == "__main__":
	get_difference()

Submission status: Wrong Answer

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


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

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

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

Submission status: Wrong Answer

Solution code:
n, k = input().split(' ')
a = [int(x) for x in input().split(' ')]
k = int(k)
n = int(n)
i=0
c = a[:]
counter=0

while i < len(a)-1:
  a=list(set(a))
  for j in a[i+1:]:
    c.append(abs(a[i]-j))
  a=c[:]
  if k in a:
    print('POSSIBLE')
    counter=1
    break
  i+=1
if counter!=1:
  print('IMPOSSIBLE')

Submission status: Wrong Answer

Solution code:
import sys

n,k = map(int, input().split())
a = list(map(int, input().split()))
if k > max(a) :
    print('IMPOSSIBLE')
    sys.exit()
elif k in a or 1 in a:
    print('POSSIBLE')
    sys.exit()

a.sort()
mn = min(a)
l = []
diff = [0]*(n-1)
for i in range(n-1) :
    diff[i] = a[i+1] - a[i]
else :
    diff = list(set(diff))

if min(diff) < mn :
    print('POSSIBLE')
else :
    print('IMPOSSIBLE')

Submission status: Wrong Answer

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 abs(k - a) in K or a in K:
		isPossible = True
		break
	else:
		K.append(abs(k-a))
for a in A:
	if a > k:
		break
	if abs(k - a) in K or a in K:
		isPossible = True
		break

if k > max(A):
	isPossible = False

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

Submission status: Wrong Answer

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):
		for j in range(N-1, i+1, -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: Wrong Answer

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 K or a in K:
		isPossible = True
		break
	else:
		K.append(abs(k-a))
for a in A:
	if abs(k - a) in K or a in K:
		isPossible = True
		break

if k > max(A):
	isPossible = False

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

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()
if k > a[n - 1]:
    print "IMPOSSIBLE"
    exit()

ok = False
for i in xrange(n - 1):
    if a[i + 1] % a[0] == 0:continue
    ok = True
if ok:
    if a[0] % 2 == 0:
        for i in xrange(n):
            if a[i] % 2 == 1:
                print "POSSIBLE"
                exit()
        else:
            print "IMPOSSIBLE"
    else :
        for i in xrange(n):
            if a[i] % 2 == 0:
                print "POSSIBLE"
                exit()
        else:
            print "IMPOSSIBLE"
else:
    if k % a[0] == 0:
        print "POSIIBLE"
    else :
        print "IMPOSSIBLE"

Submission status: Wrong Answer

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 K:
		isPossible = True
		break
	elif a in K:
		isPossible = True
		break
	else:
		K.append(abs(k-a))


if k > max(A):
	isPossible = False

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

Submission status: Wrong Answer

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


def difference(data_pair, data_set, goal):
    diff_data = {}

    for d1, d2 in data_pair:
        diff = abs(d1 - d2)
        if diff == goal:
            return 'POSSIBLE'
        if diff not in data_set:
            diff_data.setdefault(diff, set()).update((d1, d2))

    if len(diff_data) == 0:
        return 'IMPOSSIBLE'
    elif 1 in diff_data:
        return 'POSSIBLE'

    data_pair = []
    for d1 in data_set:
        for d2 in diff_data:
            if d1 not in diff_data[d2]:
                data_pair.append((d1, d2))
    for pair in combinations(diff_data, 2):
        data_pair.append(pair)
    data_set.update(diff_data)
    return difference(data_pair, data_set, goal)


if K >= max(A):
    print 'IMPOSSIBLE'
elif K in A or 1 in A:
    print 'POSSIBLE'
else:
    print difference(combinations(A, 2), A, K)

Submission status: Wrong Answer

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)
			if x>y:
				x,y = y,x
			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: Wrong Answer

Solution code:
N = 4
K = 11
A = [3, 7, 12, 15]

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.difference(A))
    print("IMPOSSIBLE")

Submission status: Wrong Answer

Solution code:

N,K=map(int,raw_input().split())
a=map(int,raw_input().split())

a.sort()
difflist=[]
for i in range(len(a)-1):
    difflist.append(a[i+1]-a[i])

if K in a:
    ans = 'POSSIBLE'
elif K > max(a):
    ans = 'IMPOSSIBLE'
elif len(set(difflist))==0:
    ans='IMPOSSIBLE'
elif len(set(difflist))==1:
    ans='IMPOSSIBLE'
else:
    ans='POSSIBLE'

print ans

Submission status: Wrong Answer

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


def difference(data_pair, data_set, goal):
    diff_data = set()

    for d1, d2 in data_pair:
        diff = abs(d1 - d2)
        if diff == goal:
            return 'POSSIBLE'
        if diff not in data_set:
            diff_data.add(diff)

    if len(diff_data) == 0:
        return 'IMPOSSIBLE'
    elif 1 in diff_data:
        return 'POSSIBLE'

    data_pair = []
    for d1 in data_set:
        for d2 in diff_data:
            data_pair.append((d1, d2))
    for pair in combinations(diff_data, 2):
        data_pair.append(pair)
    data_set.update(diff_data)
    return difference(data_pair, data_set, goal)


if K >= max(A):
    print 'IMPOSSIBLE'
elif K in A or 1 in A:
    print 'POSSIBLE'
else:
    print difference(combinations(A, 2), A, K)

Submission status: Wrong Answer

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 or n == 3: return True
    for i in range(2, int(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 pf(n):
    nn = int(n**0.5) + 1
    ti = 0
    t = allfacts[ti]
    r = []
    while True:
        if n % t == 0:
            r.append(t)
            n //= t
        else:
            ti += 1
            t = allfacts[ti]
        if t >= n or t >= nn:
            if n != 1:
                r.append(n)
                break
    return r


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

    # for v in allfacts:
    #     for s in a:
    #         if s%v != 0:
    #             break
    #     else:
    #         minv = min(minv, v)
    #         break

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

	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 * i <= n:
		if n % i == 0:
			table.append(int(i))
		i += 1
	return(table)

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

Submission status: Wrong Answer

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 or n == 3: return True
    for i in range(2, int(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 pf(n):
    nn = int(n**0.5) + 1
    ti = 0
    t = allfacts[ti]
    r = []
    while True:
        if n % t == 0:
            r.append(t)
            n //= t
        else:
            ti += 1
            t = allfacts[ti]
        if t >= n or t >= nn:
            if n != 1:
                r.append(n)
                break
    return r


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

    # for v in allfacts:
    #     for s in a:
    #         if s%v != 0:
    #             break
    #     else:
    #         minv = min(minv, v)
    #         break

    if minv == 1:
        return False
    print(minv)

    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: Wrong Answer

Solution code:
# coding:utf-8
from itertools import combinations
N, K = map(int, raw_input().split(' '))
A = set()
A.update(map(int, raw_input().split(' ')))
 
 
def difference(data_pair, data_set, goal, calced_pair=set()):
    diff_data = set()
 
    for d1, d2 in data_pair:
        if (d1, d2) in calced_pair:
            continue
        calced_pair.add((d1, d2))
        diff = abs(d1-d2)
        if diff == goal:
            return 'POSSIBLE'
        if diff not in data_set:
            diff_data.add(diff)
 
    if len(diff_data) == 0:
        return 'IMPOSSIBLE'
    elif 1 in diff_data:
        return 'POSSIBLE'
 
    data_pair = []
    for d1 in data_set:
        for d2 in diff_data:
            if d1 < d2:
                data_pair.append((d1, d2))
            else:
                data_pair.append((d2, d1))
    for pair in combinations(sorted(diff_data), 2):
        data_pair.append(pair)
    data_set.update(diff_data)
    return difference(data_pair, data_set, goal, calced_pair)
 
 
if K >= max(A):
    print 'IMPOSSIBLE'
elif K in A or 1 in A:
    print 'POSSIBLE'
else:
    print difference(combinations(sorted(A), 2), A, K)

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

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

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

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

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

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

Submission status: Wrong Answer

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

b = 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.extend(dif)
        b = sorted(list(set(b)))
        if ( len(b)==len(tmp) ):
            break
              
        if K in b:
            flag = True
            break
    


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

Submission status: Wrong Answer

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 or n == 3: return True
    for i in range(2, int(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 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])

    for v in allfacts:
        for s in a:
            if s%v != 0:
                break
        else:
            minv = min(minv, v)
            break

    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: Wrong Answer

Solution code:
#Getting Difference

N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
b = 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.extend(dif)
        b = list(set(b))
        if ( len(b)==len(tmp) ):
            break
              
        if K in b:
            flag = True
            break
    


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

Submission status: Wrong Answer

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 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
    if len(filter(lambda x:x >=K , A)) != 0:
        if ((K%2 == 1) and len(filter(lambda x:x%2 == 1, A))== 0) == False:

            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)):
                    diff = abs(x - A_list[j])
                    if diff not in A or diff == K:
                        possible_flag = True
                if possible_flag == True:
                    break

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/use/bin/env python

N,K=map(int,raw_input().split())
a=map(int,raw_input().split())

a.sort()
difflist=[]
for i in range(len(a)-1):
    difflist.append(a[i+1]-a[i])

if K in a:
    ans = 'POSSIBLE'
elif K > max(a):
    ans = 'IMPOSSIBLE'
elif len(set(difflist))==1:
    ans='IMPOSSIBLE'
else:
    ans='POSSIBLE'

print ans

Submission status: Wrong Answer

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

def s(n):
    ret = []
    i = 2
    while i * i <= n:
        while n % i == 0:
            n //= i
            ret.append(i)
        i += 1
    if n > 1:
        ret.append(n)
    return ret

def j(N, K, a):
    flag = 1
    if K > max(a):
        flag = 0
    else:
        minE = min(a)
        eles = s(minE)
        ce = []
        for e in eles:
            boolA = [ea % e == 0 for ea in a]
            if all(boolA):
                ce.append(e)
        for e in ce:
            if K % e != 0:
                flag = 0
                break
            else:
                K //= e
    print(('IMPOSSIBLE', 'POSSIBLE')[flag])

j(N, K, a)

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]))
    for i in range(n):
        if(abs(a[i] - sa) != 0):
            sa = min(sa, abs(a[i] - sa))
    if(sa == 114514810):
        print("IMPOSSIBLE")
    elif(sa == 1):
        print("POSSIBLE")
    else:
        sa = min(a[0],sa)
        flag = False
        mod = 0
        for i in range(n-1):
            if(abs(a[i] - a[i+1]) % sa != mod):
                if(mod != 0):
                    flag = True
                    break
                else:
                    mod = abs(a[i] - a[i+1]) % sa
        for i in range(n):
            if(k % sa == a[i] % sa):
                flag = True
                break
        if(flag):
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")

Submission status: Wrong Answer

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 gcd(a, b):
    while True:
        a, b = b, a%b
        if not b:
            return a


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

    for v in allfacts:
        for s in a:
            if s%v != 0:
                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: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
diff_list = set([])
bigger_val_list = set([])
cand_diff_list = []

biggest_in_a = 0
last_val = 0
for i in a_list:
    diff_list.add(abs(last_val - i))
    if i > k:
        bigger_val_list.add(i - k)
    if i > biggest_in_a:
        biggest_in_a = i
    last_val = i

tmp_diff_list = set([0])
sum_diff_list = set([0])
for i in range(n):
    for j in diff_list:
        for kk in tmp_diff_list:
            if j + kk > biggest_in_a:
                break
            sum_diff_list.add(j + kk)
    tmp_diff_list = tmp_diff_list.union(sum_diff_list)

ans_set = sum_diff_list&bigger_val_list
if len(ans_set) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')