Problem p03651 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k>max(a):
  print("IMPOSSIBLE")
  exit(0)

from fractions import gcd
gcd_v=a[0]
for i in range(1,n):
  gcd_v=gcd(a[i],gcd_v)
for aa in a:
  if (aa-k)%gcd_v==0:
    print("POSSIBLE")
    exit(0)
print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
# A - Getting Difference
from fractions import gcd

n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n-1):
    if i==0:
        t=gcd(a[i],a[i+1])
        continue
    t=gcd(t,a[i+1])
if k%t!=0:
    print('IMPOSSIBLE')
    exit()

a_max=max(a)
b=a_max-k

if b<0:
    print('IMPOSSIBLE')
    exit()
elif b==0:
    print('POSSIBLE')
    exit()

even_count=0
odd_count=0

for aa in a:
    if aa%2==0:
        even_count+=1
    else:
        odd_count+=1
a.sort()
sa=[]
for i in range(n-1):
    if abs(a[i+1]-a[i])!=0:
        sa.append(abs(a[i+1]-a[i]))
sa.sort()


is_even=False
is_odd=False
for ssaa in sa:
    if ssaa%2==0:
        if ssaa<=b:
            is_even=True
    else:
        if ssaa<=b:
            is_odd=True

if is_even==True and is_odd==True:
    print('POSSIBLE')
elif is_even==True and is_odd==False:
    if odd_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
elif is_even==False and is_odd==True:
    if even_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
# A - Getting Difference
from fractions import gcd

n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n-1):
    if i==0:
        t=gcd(a[i],a[i+1])
        continue
    t=gcd(t,a[i+1])
if k%t!=0:
    print('IMPOSSIBLE')
    exit()

a_max=max(a)
b=a_max-k

if b<0:
    print('IMPOSSIBLE')
    exit()
elif b==0:
    print('POSSIBLE')
    exit()

even_count=0
odd_count=0

for aa in a:
    if aa%2==0:
        even_count+=1
    else:
        odd_count+=1
a.sort()
sa=[]
for i in range(n-1):
    sa.append(abs(a[i+1]-a[i]))
sa.sort()


is_even=False
is_odd=False
for ssaa in sa:
    if ssaa%2==0:
        if ssaa<=b:
            is_even=True
    else:
        if ssaa<=b:
            is_odd=True

if is_even==True and is_odd==True:
    print('POSSIBLE')
elif is_even==True and is_odd==False:
    if odd_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
elif is_even==False and is_odd==True:
    if even_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
# A - Getting Difference
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n-1):
    if i==0:
        t=gcd(a[i],a[i+1])
        continue
    t=gcd(t,a[i+1])
if k%t!=0:
    print('IMPOSSIBLE')
    exit()

a_max=max(a)
b=a_max-k

if b<0:
    print('IMPOSSIBLE')
    exit()

even_count=0
odd_count=0

for aa in a:
    if aa%2==0:
        even_count+=1
    else:
        odd_count+=1
a.sort()
sa=[]
for i in range(n-1):
    sa.append(abs(a[i+1]-a[i]))
sa.sort()


is_even=False
is_odd=False
for ssaa in sa:
    if ssaa%2==0:
        if ssaa<=b:
            is_even=True
    else:
        if ssaa<=b:
            is_odd=True

if is_even==True and is_odd==True:
    print('POSSIBLE')
elif is_even==True and is_odd==False:
    if odd_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
elif is_even==False and is_odd==True:
    if even_count>0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    print('IMPOSSIBLE')