Problem:


Score : 300 points

Problem Statement

There are N monsters, numbered 1, 2, ..., N.

Initially, the health of Monster i is A_i.

Below, a monster with at least 1 health is called alive.

Until there is only one alive monster, the following is repeated:

A random alive monster attacks another random alive monster.

As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking.

Find the minimum possible final health of the last monster alive.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible final health of the last monster alive.

Sample Input 1

4
2 10 8 40

Sample Output 1

2

When only the first monster keeps on attacking, the final health of the last monster will be 2, which is minimum.

Sample Input 2

4
5 13 8 1000000000

Sample Output 2

1

Sample Input 3

3
1000000000 1000000000 1000000000

Sample Output 3

1000000000



Sample input:
4
2 10 8 40


Sample output:
2

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
flag = True
for i in range(1,n):
    if a[i]%a[0]!=0:
        flag = False
print(a[0] if flag else 1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,=pin()
    A=tupin()
    
    from fractions import gcd

    temp=A[0]
    for i in range(N-1):
          temp=gcd(temp,A[i])
    print(temp)
#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
lis=list(map(int,input().split()))
i=0
while len(lis)<i:
  lis+=math.gcd(lis[i],lis[i+1])
print(lis[-1])

Submission status: Wrong Answer

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

mod = A[-1] % A[-2]

print(A[-2] - mod)

Submission status: Wrong Answer

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

mod = A[-1] % A[-2]

print(A[0] - mod)

Submission status: Wrong Answer

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

if len(list(set(li))) == 1:
    print(li[0])
else:
    flag = False
    for l in li:
        if l%2 == 1:
            flag = True
    if flag:
        print(1)
    else:
        print(2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
last_hp = A[0]
is_even = A[0]%2 == 0
for i in range(1, N):
    if A[-i] % A[0] != 0:
        if A[-i] % 2 == 0 and is_even:
            last_hp = 2
        else:
            last_hp = 1
            break
print(last_hp)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    n=int(input())
    A=np.array([int(_) for _ in input().split()])
    while A.size>1:
        min_A=np.min(A)
        A=np.fmod(A,min_A)
        A=A[A>0]
        A=np.append(A,min_A)
        print(A)
    print(A[0])
    

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ais = list(map(int, input().split()))
for i in range(n-1):
  a = ais[i]
  b = ais[i+1]
  if a < b:
    a, b = b, a
  while a > 1 and b > 1:
    a = a % b
    a,b = b,a
  ais[i+1] = a
  ais[i] = b
print(max(ais))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())),reverse = True)
for i in range(n-1):
    a[i+1] = a[i+1]-a[0]%a[i+1]
print(min(a[1:]))

Submission status: Wrong Answer

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

min_A = min(A)

answer = min_A
for Ai in A:
    remainder = Ai % min_A
    if remainder == 0: continue

    answer = min(remainder, min_A)

print(answer)

Submission status: Wrong Answer

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

ifContinue = True
while ifContinue:
    ifContinue = False
    counter = 0
    for i in range(N):
        if not A[i] == 0:
            counter += 1
            if counter == 2:
                ifContinue = True
                break
    min = 10**5+1
    index = -1
    for i in range(N):
        if A[i] < min and not A[i] == 0:
            min = A[i]
            index = i
    if index == -1:
        print(A[0])
        exit()

    for i in range(N):
        if i == index or A[i] == 0:
            continue
        else:
            A[i] = A[i] % min

print(max(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = sorted (list(map(int,input().split())))

while True:
    for i in range(len(A)):
        a = A[i]%A[0]
        if a != 0 and a < A[0]:
            A[i] = a
            A = sorted(A)
            continue
    break
print (A[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
A = sorted (list(map(int,input().split())))
x = A[0]

while True:
    for v in A:
        a = v%x
        if a != 0 and a < x:
            x = a
            continue
    break
print (x)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = sorted (list(map(int,input().split())))
x = A[0]

for v in A:
    a = v%x
    if a != 0 and a < x:
        x = a
print (x)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = sorted (list(map(int,input().split())))
a = A[0]

while True:
    for v in A:
        x = v%a
        if (x != 0) and x < a:
            a = x
            continue
    print (a)
    exit ()

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
ary1  = map(int,input().split())
def f(n1,n2):
  bunsi = max([n1,n2])
  bunbo = min([n1,n2])
  amari = bunsi % bunbo
  if amari < (-amari+bunbo) % bunbo:
    return(amari)
  else:
    return(-amari+bunbo)

print(min([f(x[0],x[1]) for x in itertools.combinations(ary1,2) ]) )

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
import itertools

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    bit = 0
    for i in range(n):
        if a[i] % 2 != 0:
            bit = 1
            break
    if bit == 0:
        print(min(a))
    else:
        print(1)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    minA = min(A)
    while any(a % minA for a in A):
        for i in range(N):
            A[i] %= minA
            if A[i] != 0 and A[i] < minA:
                minA = A[i]
    print(minA)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
if len(set(A))==1:
  print(A[0])
  exit()
  
#A=sorted(A, reverse=True)
alleven=True

for i in range(N):
  if A[i]%2==1:
    alleven=False

if alleven:
  print(2)
else:
  print(1)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n=int(input())
a=list(map(int,input().split()))
ans=10**18
t=0
for i in range(1,n):
  if i==1:
    t=gcd(a[i-1],a[i])
    continue
  t=gcd(t,a[i])
  ans=min(t,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    if len(set(A)) == 1:
        print(A[0])
    elif all(A[0] % 2 == a % 2 == 0 for a in A):
        print(2)
    else:
        print(1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = A[0]
for i in range(N):
  for j in range(i+1,N):
    if 0 < A[j]%A[i] < ans :
      ans = A[j]%A[i]
    if ans == 1:
      break


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = []
def gcd(a,b):
    if b%a == 0:
        return(a)
    else:
        return(gcd(b%a,b))
for i in range(len(A)-1):
    ans.append(gcd(A[i],A[i+1]))
    A[i+1]=ans[i]
ans.append(gcd(A[1],A[-1]))
if min(ans) % 2 == 0:
    print(min(ans))
else:
    print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = []
def gcd(a,b):
    if b%a == 0:
        return(a)
    else:
        return(gcd(b%a,b))
for i in range(len(A)-1):
    ans.append(gcd(A[i],A[i+1]))
    A[i+1]=ans[i]
ans.append(gcd(A[1],A[-1]))
print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = []
def gcd(a,b):
    if b%a == 0:
        return(a)
    else:
        return(gcd(b%a,b))
for i in range(len(A)-1):
    ans.append(gcd(A[i],A[i+1]))
    A[i+1]=ans[i]
print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = []
def gcd(a,b):
    if b%a == 0:
        return(a)
    else:
        return(gcd(b%a,b))
for i in range(len(A)-1):
    ans.append(gcd(A[i],A[i+1]))
print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = 0
countb = 0
countc = 0
A.sort()
Ab = A
for i in A:
    if i % 2 == 0:
        count += 1

    if i % A[0] == 0:
        countb += 1
for i in range(len(Ab)):
    fr = 0
    while fr == 0:
        if Ab[i] % 2 == 0:
            Ab[i] /= 2
        else:
            fr += 1
for i in range(len(Ab)):
    if Ab[i] == 1:
        countc += 1

if countc == len(Ab):
    print(A[1]-A[0])
elif countb == N:
    print(A[0])
elif count == N:
    print(2)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = 0
countb = 0
min = min(A)
for i in A:
    if i % 2 == 0:
        count += 1

    if i % min == 0:
        countb += 1

if countb == N:
    print(min)
elif count == N:
    print(2)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = 0
countb = 0
min = min(A)
for i in A:
    if i % 2 == 0:
        count += 1

    if i % min == 0:
        countb += 1

if countb == N:
    print(A[0])
elif count == N:
    print(2)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
INF = 10**9


def main():
  n = int(readline())
  A = list(map(int, readline().split()))
  A.sort()
  if A[1]%A[0] == 0:
    print(A[0])
  else:
    print(0)
  
  
  
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))
work = sum(A[1:])
temp = work % A[0]
result = temp if temp!=0 else A[0]
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))
result = min(A)
temp = result
for i in range(10**6):
    for i in range(n-1):
        work = A[i+1] - A[i]
        result = result if result < work or work==0 else work
    A = sorted(list(map(lambda x:x%result, A)))
    if temp == result:
        break
    else:
        temp = result
print(result)

Submission status: Wrong Answer

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

A.sort()
m1 = A[0]
m2 = A[1]

ans = gcd(m1, m2)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
cnt = [a[1],a[0]]
for i in range(1,n):
  a[i] %= cnt[-1]
  if (a[i] != 0) and (a[i] < cnt[-1]):
    cnt.append(a[i])
    cnt.pop(0)
if a[1] == 0:
  print(a[0])
else:
  if cnt[0] % cnt[1] == 0:
    print(cnt[1])
  else:
    print(cnt[0] % cnt[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 0
ans = min(a)
while count < n:
    for i in a:
        if i%ans == 0:
            count += 1
        else:
            ans = min(ans, i%ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 0
ans = min(a)
while count < n-1:
    for i in a:
        if i%ans == 0:
            count += 1
        else:
            ans = min(ans, i%ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=sorted(list(map(int,input().split(' '))))
l_tmp=A[1:]
tmp = A[0]
ans = A[0]
while True:
    l_tmp_tmp=[]
    for i in l_tmp:
        if i%tmp:
            l_tmp_tmp.append(i%tmp)
            ans = min(ans,i%tmp)
    if len(l_tmp_tmp):
        tmp = ans
        l_tmp=l_tmp_tmp
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=sorted(list(map(int,input().split(' '))))
ans = A[0]
for i in A[1:]:
    if i%ans>0:
        ans = i%ans
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=sorted(list(map(int,input().split(' '))))
ans = A[0]
for i in A[1:]:
    if i%ans>0:
        ans = i%ans
    else:
        print(ans)
        break

Submission status: Wrong Answer

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

if all([n%2==0 for n in A]):
    print(min(A))
elif any([n%2==1 for n in A]):
    print(1)
elif all([n%2==1 for n in A]):
    print(min(A))
elif all([n == A[0] for n in A]):
    print(A[0])

Submission status: Wrong Answer

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

if all([n%2==0 for n in A]):
    print(min(A))
elif any([n%2==1 for n in A]):
    print(1)
elif all([n == A[0] for n in A]):
    print(A[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
buf = sum(a)
mn = min(a)

if (buf-mn) % mn == 0:
    print(mn)
else:
    print((buf-mn)%mn)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,(input().split())))
f = 0
while f == 0 or len(set(A)) >= 3:
    nim = sorted(set(A))[0]
    if nim == 0:
        nim = sorted(set(A))[1]
    for i in range(N):
        if A[i] != nim:
            A[i] %= nim
    if len(set(A)) == 1:
        print(nim)
        break
    f = 1
else:
    print(nim)

Submission status: Wrong Answer

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
a = min(list_A)
ans = a
for s in list_A:
    if s % a != 0:
        ans = 1
        break

print(ans)

Submission status: Wrong Answer

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

ans = 0
min_value = max(list_A)
for s in list_A:
    if s % 2 == 1:
        ans = 1
        break
    if s <= min_value:
        min_value = s
        ans = s
if max(list_A) == min(list_A):
    ans = list_A[0]
print(ans)

Submission status: Wrong Answer

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

ans = 0
min_value = max(list_A)
for s in list_A:
    if s % 2 == 1:
        ans = 1
        break
    if s <= min_value:
        min_value = s
        ans = s

print(ans)

Submission status: Wrong Answer

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

mini = a[0]

for i in range(1,n):
    mod = a[i] % mini
    if mod != 0:
        mini = mod

print(mini)

Submission status: Wrong Answer

Solution code:
n = int(input()) 
a = list(map(int, input().split()))
y = a[0]
for i in range(1,n):
    x = a[i]
    if(x < y):
        c = x
        x = y
        y = c
    while(y != 0):
        print(x,y)
        c = x % y
        x = y
        y = c
    y = x
    if(y == 1):
        break
print(y)

Submission status: Wrong Answer

Solution code:

n = int(input())

a = list(map(int, input().split()))
ans = min(a)
for i in range(n):
    for j in range(n):
        if i != j and a[i] % a[j] != 0:
            ans = min(ans, a[i] % a[j])
        

print(ans)

Submission status: Wrong Answer

Solution code:

n = int(input())

a = list(map(int, input().split()))
judge = 0
for i in range(n):
    if a[i] % 2 == 1:
        judge = 1
        break

print(1 if judge == 1 else min(a))

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
A = list(map(lambda x: int(x) * (-1), input().split()))

heapq.heapify(A)

while len(A) > 1:
    Amax1 = heapq.heappop(A) * (-1)
    Amax2 = heapq.heappop(A) * (-1)
    pushA = Amax1 % Amax2
    if pushA == 0:
        heapq.heappush(A, Amax2 * (-1))
    else:
        heapq.heappush(A, pushA * (-1))

print(A[0] * (-1))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
a = l[0]
for i in range(1,n):
    if l[i]%a != 0:
        a = l[i]%a
        if a == 1:
            print(1)
            exit()
print(a)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int , input().split()))
aa = A[0]
for i in range(len(A)-1):
    aa = gcd(aa, A[i]+1)
print(aa)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int , input().split()))
max_ = max(A)
A = list(set(A))
A_ = []
for i in A:
    A_.append(i-(int(max_-(i*int(max_/i)))))
A_ = list(set(A_))
A_ = sorted(A_)
if A_[0] == 0:
    ans = min(A)
else:
    ans = A_[0]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int , input().split()))
max_ = max(A)
A = list(set(A))
A_ = []
for i in A:
    A_.append(i-(int(max_-(i*int(max_/i)))))
A_ = list(set(A_))
A_ = sorted(A_)
print(A_[0])

Submission status: Wrong Answer

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

cnt = 0
for i in range(N):
    if A[i] % 2 != 0:
        cnt = 1
if cnt == 0 :
    print('2')
else:
    print('1')

Submission status: Wrong Answer

Solution code:
s=int(input())
t=list(map(int,input().split()))
a=min(t)
b=0
for i in range(s):
  if t[i]%a!=0:
    b=min(a,t[i]%a)
if b==0:
  print(a)
else:
  print(1)

Submission status: Wrong Answer

Solution code:
s=int(input())
t=list(map(int,input().split()))
a=min(t)
b=0
for i in range(s):
  if t[i]%a!=0:
    b=min(a,t[i]%a)
if b==0:
  print(a)
else:
  print(a%abs(b-a))

Submission status: Wrong Answer

Solution code:
s=int(input())
t=list(map(int,input().split()))
a=min(t)
b=0
for i in range(s):
  if t[i]%a!=0:
    b=min(a,t[i]%a)
if b==a or b==0:
  print(a)
else:
  print(a%abs(b-a))

Submission status: Wrong Answer

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

MIN=min(a)


for i in range(n):
    if a[i]%MIN!=0:
        print(1)
        exit()
print(MIN)

Submission status: Wrong Answer

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

ao = list(map(lambda x:x%2, a))
if 1 in ao:
    print(1)
else:
    print(min(a))

Submission status: Wrong Answer

Solution code:
import fractions

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ko = fractions.gcd(a[1],a[0])
print(ko)

Submission status: Wrong Answer

Solution code:
import fractions

n = int(input())
a = [int(i) for i in input().split()]
mn1 = min(a)
a.remove(mn1)
mn2 = min(a)
ko = fractions.gcd(mn2,mn1)
print(ko)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mn1 = min(a)
a.remove(mn1)
mn2 = min(a)
if mn2%mn1==0:
    print(mn1)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans=2
if len(set(A))==1:
    print(A[0])
else:
    for a in A:
        if a%2==1:
            ans=1
    print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappush, heappop
N = int(input())
Alist = list(map(int, input().split()))
heapify(Alist)
while len(Alist)>2:
    Alist = [a for a in Alist if a > 0]
    min_num = heappop(Alist)
    for i in range(len(Alist)):
        Alist[i] %= min_num
    heappush(Alist, min_num)
print(Alist[0])

Submission status: Wrong Answer

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

m = min(A)

for i in range(N):
    if A[i] % m != 0:
        print(1)
        exit()
print(m)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# 基本的には結果は１になるはず。例外は全てKの倍数である時のみ
# minで割って行ってあまりが1ならそれで終了、それ以外は、あまりが異なるものをひいていって、1になったら終了
# あまりのminで更新することができるかどうか => TLE
# 新しいリストを作る
n = int(input())
a = list(map(int,input().split()))
div = min(a)
while len(a) >= 2:
    n_l = []
    for i in range(len(a)):
        if a[i] % div != 0: n_l.append(a[i] % div)
    a = n_l
    if len(n_l) <= 1: break
    div = min(a)
    a.append(div)
    #print(a,div)

print(div)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n = int(input())
l = list(map(int, input().split()))

x = 0
for i in range(n-1):
    x = gcd(x,l[i])

print(x)

Submission status: Wrong Answer

Solution code:
n=int(input())
*a,=map(int,input().split())
a.sort()
x=a[0]
for i in range(1,n):
	if a[i]%x != 0:
		x=a[i]%x
	else:
		pass
print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())

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


odd = False
even = False
if a[1:] == a[:-1]:
    print(a[0])

else:

    for i in a:
        if i%2 == 0:odd = True
        else: even = True

    if  even: print(1)
    elif odd: print(2)

Submission status: Wrong Answer

Solution code:
import fractions

N =int(input())
monster = sorted([int(i) for i in input().split()])

print(fractions.gcd(monster[0], monster[1]))

Submission status: Wrong Answer

Solution code:
import sys
import fractions
f = sys.stdin
n = int(f.readline())
a = list(map(int, f.readline().split()))
a.sort()
gcd = fractions.gcd(a[0], a[1])
print(gcd)

Submission status: Wrong Answer

Solution code:
import sys
f = sys.stdin
n = int(f.readline())
a = list(map(int, f.readline().split()))
a.sort()
ans = a[0]
for i in range(n-1):
    if a[i] == a[i+1]:
        continue
    
    if a[i]%2 == 0:
        if a[i] == 2:
            ans = 2
            break
        continue
    
    if a[i]%2 == 1:
        ans = 1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
f = sys.stdin
n = int(f.readline())
a = list(map(int, f.readline().split()))
a.sort()
ans = a[0]
for i in range(n-1):
    if a[i] == a[i+1]:
        continue
    
    if a[i]%2 == 0:
        ans = 2
        continue
    
    if a[i]%2 == 1:
        ans = 1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
a.sort()
ans = 1e10
for i in range(1, n):
    x, y = a[0], a[1]
    while y%x:
        y -= y//x*x
        x, y = y, x
    ans = min(ans, x)
print(ans)

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
a.sort()
for i in range(1, n):
    x, y = a[0], a[1]
    while y%x:
            y -= y//x*x
            x, y = y, x
print(x)

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
a.sort()
x, y = a[0], a[1]
while y%x:
        y -= y//x*x
        x, y = y, x
print(x)

Submission status: Wrong Answer

Solution code:
import fractions
def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    ans = a[0]
    for i,a_i in enumerate(a,1):
        if ans == a_i:
            continue
        elif ans % a_i == 0 or a_i % ans == 0:
            ans = min(ans, fractions.gcd(ans,a_i))
        elif ans % 2 == 0 and a_i % 2 == 0:
            ans = 2
        else:
            ans = 1
            print(ans)
            return
    print(ans)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    ans = a[0]
    for i,a_i in enumerate(a,1):
        if ans == a_i:
            continue
        elif ans % a_i == 0 or a_i % ans == 0:
            ans = min(ans, a_i)
        elif ans % 2 == 0 and a_i % 2 == 0:
            ans = 2
        else:
            ans = 1
            print(ans)
            return
    print(ans)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    ans = a[0]
    for i,a_i in enumerate(a,1):
        if ans == a_i:
            continue
        elif ans % a_i == 0 or a_i % ans == 0:
            ans = min(ans, a_i)
        elif ans % 2 == 0 and a_i % 2 == 0:
            ans = min(2,ans)
        else:
            ans = 1
            print(ans)
            return
    print(ans)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    ans = a[0]
    for i,a_i in enumerate(a,1):
        if ans == a_i:
            continue
        elif ans % a_i == 0 or a_i % ans == 0:
            ans = min(ans, a_i)
        elif ans % 2 == 0 and a_i % 2 == 0:
            ans = min(2,ans)
        else:
            ans = 1
            print(ans)
            return
    print(ans)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    evn = []
    odd = []
    flg = 1
    tmp = a[0]
    flg2 = 1
    for i,a_i in enumerate(a):
        if a_i % tmp != 0 and flg2==1:
            flg2=0
        if a_i % 2 == 0:
            evn.append(a_i)
        else:
            odd.append(a_i)
        if flg == 1 and tmp == a_i:
            flg = 1
        else:
            flg = 0
    if flg == 1:
        print(a[0])
        return
    elif flg2 == 1:
        print(a[0])
    elif len(evn) > 0 and len(odd) == 0:
        print(2)
    else:
        print(1)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    evn = []
    odd = []
    flg = 1
    tmp = a[0]
    for i,a_i in enumerate(a):
        if a_i % 2 == 0:
            evn.append(a_i)
        else:
            odd.append(a_i)
        if flg == 1 and tmp == a_i:
            flg = 1
        else:
            flg = 0
    if flg == 1:
        print(a[0])
        return
    elif len(evn) > 0 and len(odd) == 0:
        print(2)
    else:
        print(1)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
A=sorted(list(map(int,input().split())))

minA=min(A)
for i in range(1,n):
    if 0<A[i]%minA<minA:
        minA=A[i]%minA

print(minA)

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
    if y > x:
        x, y = y, x
    while y != 0:
        x, y = y, x % y
    return x


N = int(input())
A = [int(i) for i in input().split()]
ans = gcd(A[0], A[1])
for i in range(2, N):
    gcd(ans, A[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = [int(i) for i in input().split()]


def solve(nums):
    if len(set(nums)) == 1:
        return nums[0]

    min_num = min(nums)
    # 最小値ですべての値を割ることができたら最小値が答え
    if all([num % min_num == 0 for num in nums]):
        return min_num

    for num in nums:
        # 最小値条件を満たさないで、奇数が含まれていたらそれが答え
        if num % 2 != 0:
            return 1
    # 最小値（偶数）
    return min_num


print(solve(nums))

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = [int(i) for i in input().split()]


def solve(nums):
    if len(set(nums)) == 1:
        return nums[0]

    has_odd = False
    for num in nums:
        if num % 2 != 0:
            has_odd = True
            break
    min_num = min(nums)
    if all([num % min_num == 0 for num in nums]):
        return min_num

    if has_odd:
        return 1
    else:
        return min_num


print(solve(nums))

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = [int(i) for i in input().split()]


def solve(nums):
    if len(set(nums)) == 1:
        return nums[0]

    has_odd = False
    for num in nums:
        if num % 2 != 0:
            has_odd = True
            break

    if has_odd:
        return 1
    else:
        return min(nums)


print(solve(nums))

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
a = list(map(int,input().split()))
a.sort()

if len(a) == 1:
    print(a[0])
    sys.exit()
elif a[0] == a[len(a)-1]:
    print(a[0])
    sys.exit()
ans_l = [a[i] for i in range(len(a)) if a[i]%a[0]!=0]

if len(ans_l) == 0:
    print(a[0])
else:
    print(1)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def list_gcd(list):
    c=list[0]
    for i in list:
        c=gcd(c,i)
    return c

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
ans = A[0]
if N == 1:
    print(ans)
    exit()
while A[0] > 0:
    ans = A[0]
    for i in range(1,N):
        A[i] -= A[0]
    A.sort()

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = A[0]
if N == 1:
    print(ans)
    exit()
while A[0] > 0:
    ans = A[0]
    for i in range(1,N):
        A[i] -= A[0]
    A.sort()

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = A[0]
while A[0] > 0:
    ans = A[0]
    for i in range(1,N):
        A[i] -= A[0]
    A.sort()

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = A[0]
while A[0] != 0:
    ans = A[0]
    for i in range(1,N):
        A[i] -= A[0]
    A.sort()

print(ans)

Submission status: Wrong Answer

Solution code:
"""TLE
N = int(input())
HPs = list(map(int,input().split()))
while True:
    min_hp = min(HPs)
    for i in range(len(HPs)):
        if i == HPs.index(min_hp):
            continue
        HPs[i] = HPs[i] % min_hp
    tmp = HPs.count(0)
    for j in range(tmp):
        if tmp==len(HPs):
            print(HPs[0])
            exit()
        HPs.remove(0)
    if len(HPs)==1:
        break
print(HPs[0])
"""

from fractions import gcd
N = int(input())
HPs = list(map(int,input().split()))
ans = 1
for i in HPs:
    ans = gcd(ans,i)
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce


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


def lcm(x, y):
    return (x * y) // gcd(x, y)


def gcd_list(*numbers):
    return reduce(gcd, numbers)


def lcm_list(*numbers):
    return reduce(lcm, numbers)


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

print(gcd_list(a))

Submission status: Wrong Answer

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

for i in range(n - 1):
    if a[i] != a[i + 1]:
        break
    if i == n - 2:
        print(a[i])
        exit()

for i in range(n):
    if a[i] % 2 != 0:
        break
    if i == n - 1:
        print("2")
        exit()

print("1")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
m1=min(a)
a.sort(reverse=True)
for i in range(n-1):
    for j in range(i,n):
        if m1==1:
            break
        else:
            count=a[i]%a[j]
            if m1>count and count!=0:
                m1=count

print(m1)

Submission status: Wrong Answer

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