Problem: 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.

Submission attempts (in order):
def gcd(a, b):
    if (b == 0):
        return a
    return gcd(b, a % b)

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:
	temp = A[0]
	for i in range(1,N):
		temp = gcd(temp,A[i])
	if K % G == 0:
		flag = True
	else:
		flag = False
			
if flag==True:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')

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)

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

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

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

if K <= max(A) and K % G == 0:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')

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:
	print(POSSIBLE)
else:
	print(IMPOSSIBLE)

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

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

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

 def gcd()

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:
	temp = A[0]
	for i in range(1,N):
		temp = gcd(temp,A[i])
	if K % G == 0:
		flag = True
	else:
		flag = False
			
if flag==True:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')

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

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

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

if K <= max(A) and K % temp == 0:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted