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: Accepted

Solution code:
from fractions import gcd
from functools import reduce
n=int(input())
a=sorted(list(map(int,input().split())))
ans=reduce(gcd,a)  
print(ans)

Submission status: Accepted

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

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

ans=A[0]
for i in range(1,len(A)):
  ans=gcd(ans,A[i])
  
print(ans)

Submission status: Accepted

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

def gcd(a,b):
    if a == 0:
        return b
    if b == 0:
        return a
    r = 1
    while r > 0:
        r = a % b
        a = b
        b = r
    return a

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

print(l[-1])

Submission status: Accepted

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

def gcd(a,b):
    if a == 0:
        return b
    if b == 0:
        return a
    r = 1
    while r > 0:
        r = a % b
        a = b
        b = r
    return a

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

print(l[-1])

Submission status: Accepted

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

def gcd(a,b):
    if a == 0:
        return b
    if b == 0:
        return a
    r = 1
    while r > 0:
        r = a % b
        a = b
        b = r
    return a

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

print(l[n])

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
    
n = int(input())
a = list(map(int, input().split()))

print(gcd_list(a))

Submission status: Accepted

Solution code:
import fractions

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

ans = min(A)
for a in A:
    ans = fractions.gcd(ans, a)

print(ans)

Submission status: Accepted

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

n=int(input())
a=list(map(int,input().split()))
res=a[0]
for i in range(1,n):
    res=gcd(res,a[i])
print(res)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

def main():
    n = int(input())
    A = list(map(int, input().split()))
    print(reduce(fractions.gcd,A))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

a.sort()
prev = gcd(a[0], a[1])
#print(prev)
for i in range(2, n):
    g = gcd(a[i], prev)
    if g < prev:
        prev = g

print(prev)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
import fractions as f
mini=float('inf')
for i in range(n-1):
    x=f.gcd(a[i],a[i+1])
    mini=min(mini,x)
print(mini)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#priority_queueで管理
#普通にソートすればいいじゃん
n=int(input())
a=sorted([int(i) for i in input().split()])
#print(a)
while len(a)!=1:
    b=a[0]
    for i in range(1,n):
        a[i]-=b*(a[i]//b)
    a=sorted([i for i in a if i!=0])
    n=len(a)
    #print(a)

print(a[0])

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
array = []
if N == 1:
    print(A[0])
else:
    t = gcd(A[0],A[1])
    if N ==2:
        print(t)
    else:
        for i in range(2,N):
            t = gcd(t,A[i])
        print(t)

Submission status: Accepted

Solution code:
import fractions
N = int(input())
A = list(map(int, input().split()))
ans = 1000000000000000000
for i in range(N-1):
  ans = min(ans, fractions.gcd(A[i], A[i+1]))
  if ans == 1:
    break
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

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

A.sort()

a = make_divisors(A[0])

a.sort(reverse = True)

for i in a:
    for j in range(N):
        if A[j] % i != 0:
            break
        if j == N - 1:
            print(i)
            sys.exit()

Submission status: Accepted

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

def gcd(a,b):#最大公約数
  return a if b == 0 else gcd(b,a%b)
P=A[0]
for i in range(N):
  P=gcd(P,A[i])
print(P)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
print(reduce(fractions.gcd, a))

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
print(reduce(gcd, a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
N=int(input())
A=list(map(int,input().split()))
def gcd(*num):
    return reduce(fractions.gcd, num)
print(gcd(*A))

Submission status: Accepted

Solution code:
import os, sys, re, math

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

while True:
    min_a = min(A)
    for i in range(len(A)):
        if A[i] % min_a > 0:
            A[i] = A[i] % min_a
        else:
            A[i] = min_a

    if len(set(A)) == 1:
        break

print(min_a)

Submission status: Accepted

Solution code:
from functools import reduce

n = int(input())
lst = [int(i) for i in input().split()]


def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


print(reduce(gcd, lst))

Submission status: Accepted

Solution code:
import os, sys, re, math

N = int(input())
A = [int(n) for n in input().split()]

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

result = A[0]
for a in A[1:]:
    result = gcd(result, a)

print (result)

Submission status: Accepted

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


n = int(input())
a = list(map(int, input().split()))
v = a[0]
for aa in a[1:]:
    v = gcd(v, aa)
print(v)

Submission status: Accepted

Solution code:
from functools import reduce

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

input()
print(reduce(gcd, map(int, input().split())))

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split(' ')))
def gcd(a, b):
    return b if a % b == 0 else gcd(b, a%b)
r = l[0]
for a in l[1:]:
  r = gcd(a, r)
print (r)

Submission status: Accepted

Solution code:
from fractions import gcd

n=int(input())
*A,=map(int,input().split())

a=A[0]
for i in range(1,n):
    a=gcd(a,A[i])
print(a)

Submission status: Accepted

Solution code:
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(1,n):
    ans=gcd(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import fractions as f
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(n):
    ans=f.gcd(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
while len(a)>1:
  m=min(a)
  b=[m]
  for i in range(len(a)):
    x=a[i]%m
    if x!=0:
      b.append(x)
  a=list(set(b))
print(*a)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
input()
a = list(map(int,input().split()))
print(reduce(gcd,a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd


def solve(n, ax):
    g = ax[0]
    for ai in ax[1:]:
        g = gcd(g, ai)

    return g


if __name__ == '__main__':
    n = int(input())
    ax = list(map(int, input().split()))
    print(solve(n, ax))

Submission status: Accepted

Solution code:
import fractions

# N個の最大公約数
# ユークリッド互除法


def good(A, N):
    # A = sorted(A)
    ans = A[0]
    for i in range(1, N):
        ans = fractions.gcd(A[i], ans)
    print(ans)


def my(A, N):
    A = sorted(A)

    while True:
        v = A[0]
        tmp = [v]
        for i in range(len(A)):
            if A[i] % v == 1:
                print(1)
                return
            if A[i] % v == 0:
                pass
            else:
                tmp.append(A[i] % v)

        if len(A) == 1:
            print(A[0])
            return

        A = sorted(tmp)
        # print(A)


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

    good(A, N)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

print(gcd_list(list_aaa))

Submission status: Accepted

Solution code:
import fractions

n = int(input())
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    ans = fractions.gcd(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
import fractions
N = int(input())
A = list(map(int,input().split()))
gcd = 10**9
for i in range(N-1):
    tmp = fractions.gcd(A[i],A[i+1])
    if tmp < gcd:
        gcd = tmp
print(gcd)

Submission status: Accepted

Solution code:
import fractions
N = int(input())
A = sorted(list(map(int,input().split())),reverse = 1)
gcd = 10**9
for i in range(N-1):
    tmp = fractions.gcd(A[i],A[i+1])
    if tmp < gcd:
        gcd = tmp
print(gcd)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

n = int(input())
A = [int(i) for i in input().split()]

print(reduce(gcd, A))

Submission status: Accepted

Solution code:
n = int(input())
list1 = list(map(int,input().split()))
import fractions as math
gcd = 10**9
for i in range(n-1):
    gcd = min(gcd,math.gcd(list1[i],list1[i+1]))
print(gcd)

Submission status: Accepted

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

N = int(input())
A = list(map(int, input().split()))
g = A[0]
for a in A:
   g = gcd(g, a)
print(g)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = list(sorted(set(a)))
if len(a) == 1:
    print(a[0])
    exit()

flag = True
while flag:
    if a[0] != 0:
        for i in range(1, len(a)):
            a[i] = (a[i] % a[0])
    else:
        for i in range(2, len(a)):
            a[i] = (a[i] % a[1])
    a = list(sorted(set(a)))
    if len(a) == 2 and a[0] == 0:
        break
print(a[1])

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.buffer.readline


def sss(A, N):
    A.sort()
    while A[0] == 0:
        A.remove(0)
    for i in range(1, len(A)):
        A[i] = A[i] % A[0]
    if A[0] == sum(A):
        print(sum(A))
    else:
        return sss(A, N)


def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    sss(A, N)


main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)
  
b=a[0]
  
for i in range(1,n):
  b=gcd(b,a[i])
  
print(b)

Submission status: Accepted

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

while len(a)>=2:
  for i in range(1,len(a)):
    a[i]=a[i]%a[0]
  if 0 in a:
    for j in range(a.count(0)):
      a.remove(0)
  a.sort()
    

print(a[0])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
def gcd(a, b):
  if a < b:
    c = a
    a = b
    b = c
  while a % b != 0:
    c = a % b
    a = b
    b = c
  return b
for i in range(N-1):
  A[i+1] = gcd(A[i] , A[i+1])
print(A[N-1])

Submission status: Accepted

Solution code:
from functools import reduce
def gcd(a, b):
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
input()
Ai = list(map(int, input().split()))
print(reduce(gcd, Ai))

Submission status: Accepted

Solution code:
import math
import functools
from fractions import gcd
from functools import reduce
import numpy as np

n = int(input())

a=list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = gcd(ans, a[i])

print(ans)

Submission status: Accepted

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

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


ans = A[0]
for a in A:
    ans = gcd(ans,a)
print(ans)

Submission status: Accepted

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


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

ans = L[0]
for i in range(1, N):
    ans = gcd(ans, L[i])

print(ans)

Submission status: Accepted

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

    while True:
        v = A[0]
        tmp = [v]
        for i in range(len(A)):
            if A[i] % v == 1:
                print(1)
                return
            if A[i] % v == 0:
                pass
            else:
                tmp.append(A[i] % v)

        if len(A) == 1:
            print(A[0])
            return

        A = sorted(tmp)
        # print(A)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def gcd(n,m):
  a=min(n,m)
  b=max(n,m)
  while a!=0:
    b,a=a,b%a
  return b
n=int(input())
l=list(map(int,input().split()))
ans=l[0]
for i in range(1,n):
  ans=gcd(ans,l[i])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
while len(A) > 1: #条件を満たす間動く
    for j in range(1,len(A)):
        A[j] = A[j] % A[0]
    A = [k for k in A if k != 0]
    A.sort()

print(A[0])

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
while len(A) > 1:
    for j in range(1,len(A)):
        A[j] = A[j] % A[0]
    A = [k for k in A if k != 0]
    A.sort()

print(A[0])

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
x=min(A)
noend=True
while noend:
  a=x
  for i in range(n):
    if A[i]%x!=0 and A[i]%x<x:
      x=A[i]%x
      break
  if x==a:
    noend=False
print(x)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
n = int(input())
A = list(map(int, input().split()))
print(reduce(gcd, A))

Submission status: Accepted

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
v = fractions.gcd(a[0], a[1])
for i in range(2, n):
    v = fractions.gcd(v, a[i])
print(v)

Submission status: Accepted

Solution code:
import fractions
n = int(input())

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


ans = al[0]
for a in al:
    ans = fractions.gcd(a,ans)
    
print(ans)

Submission status: Accepted

Solution code:
# 2019-11-12 15:53:47(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

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

def main():
    n, *a = (int(x) for x in sys.stdin.read().split())
    
    ans = reduce(gcd, a)
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
from functools import reduce

def gcd(v1, v2):
    if v1 == 0 or v2 == 0:
        return max(v1, v2)
    if v1 % v2 == 0:
        return v2
    return gcd(v2, v1%v2)

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

print(reduce(gcd, A))

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
def gcd(a,b):
    if b==0:
        return a 
    return gcd(b,a%b)
g=0 
for i in l:
    g=gcd(g,i)
print(g)

Submission status: Accepted

Solution code:
# Hariom_Pandey
# 11.11.2019
from functools import reduce
from fractions import gcd
import sys
n = int(sys.stdin.readline())
H = list(map(int,sys.stdin.readline().split()))
print(reduce(gcd,H))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = fractions.gcd(ans, a[i])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
n=int(input())
A=list(map(int,input().split()))
r=gcd(0,A[0])
for i in range(1,n):
    r=gcd(r,A[i])
print(r)

Submission status: Accepted

Solution code:
from fractions import gcd  #python 3.5より前
#from math import gcd  #python 3.5以降
n = int(input())
a = sorted([int(i) for i in input().split()])
ans = gcd(a[0],a[1])
for i in range(2,len(a)):
    ans = min(ans,gcd(ans,a[i]))
print(ans)

Submission status: Accepted

Solution code:
import fractions

n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(1,n):
    ans=fractions.gcd(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
ans = li[0]

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

for i in range(1,n):
    ans = gcd(ans,li[i])

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


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

print(gcd_list(A))

Submission status: Accepted

Solution code:
import fractions
n,*a=map(int,open(0).read().split())
b=list(set(a))
c=b[0]
for i in b:
    c=fractions.gcd(i,c)
print(c)

Submission status: Accepted

Solution code:
import fractions
n = int(input())
a = list(map(int,input().split()))
gcd_a = fractions.gcd(a[0],a[1])
for i in range(2,n):
  gcd_a = fractions.gcd(gcd_a,a[i])
  if gcd_a == 1:
    break
print(gcd_a)

Submission status: Accepted

Solution code:
from fractions import gcd

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

ans = 0
for i in range(n):
    ans = gcd(ans, a[i])

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
b = a[0]
for i in range(n):
	b = gcd(b, a[i])
print (b)

Submission status: Accepted

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

ans = a[0]

for i in range(n-1):
    ans = fractions.gcd(ans,a[i+1])
    
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import bisect

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

while True:
    if len(li) < 2:
        break
    for i in range(1,len(li)):
        li[i] %= li[0]
    li.sort()
    li = li[bisect.bisect_right(li,0):]
print(li[0])

Submission status: Accepted

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

def gcd(a, b) :
    while b != 0 :
        a, b = b, a % b
    return a
    
ret = gcd(A[0], A[1])
for i in range(2, N) :
    ret = gcd(ret, A[i])
print(ret)

Submission status: Accepted

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

a.sort()
while 1:
	lst = []
	lst.append(a[0])
	for i in range(1, len(a)):
		if a[i] % a[0] != 0:
			lst.append(a[i]%a[0])
	if len(lst) == 1:
		break
	a = []
	a = lst
	a.sort()
print(lst[0])

Submission status: Accepted

Solution code:
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x):#約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x):#素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # print("Yes")  print("No")  x=[[0 for _ in range(n)] for _ in range(n)]
    n=int(input())
    a = list(map(int,input().split()))
    ans=gcd(a[0],a[1])
    for i in range(n-2):
        ans=gcd(ans,a[i+2])
        if ans==1:
            break
    print(ans)
main()

Submission status: Accepted

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

while len(A) > 1:
    min_A = min(A)
    A = [x % min_A for x in A]
    A = [x for x in A if x != 0]
    A.append(min_A)

print(A[0])

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
score = reduce(gcd, a)
print(score)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

def gcd(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())

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

print(gcd(A))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
from fractions import gcd
ans = A[0]
for a in A:
    ans = gcd(ans, a)
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
n = int(input())
A = list(map(int,input().split()))
print(reduce(gcd,A))

Submission status: Accepted

Solution code:
def GCD(x,y):
    x,y=max(x,y),min(x,y)
    if x%y==0:
        return y
    else:
        return GCD(y,x%y)

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

ans=A[0]
for i in range(1,N):
    ans=GCD(ans,A[i])
print(ans)

Submission status: Accepted

Solution code:
def vs(A):
    A = sorted(A)
    pA = list(map(lambda x: x % A[0], A))
    pA[0] = A[0]
    return list(filter(lambda x: x != 0, pA))


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


spA = -1
sA = -2
while spA != sA:
    sA = sum(A)
    pA = vs(A)
    spA = sum(pA)
    A = pA

print(sum(A))

Submission status: Accepted

Solution code:
def solve():
    n = input()
    l = list(map(int, input().split()))
    a = l.pop()
    for b in l:
        a = gcd(a,int(b))
    return a

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

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

Submission status: Accepted

Solution code:
def solve():
    n = input()
    l = input().split()
    a = int(l.pop())
    for b in l:
        a = gcd(a,int(b))
    return a

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

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

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()


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


n = int(input())
arr = lmi()
for i in range(1, n):
    arr[i] = gcd(arr[i], arr[i-1])
print(arr[n-1])

Submission status: Accepted

Solution code:
from sys import stdin

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

N = int(stdin.readline())
A = list(map(int,stdin.readline().strip().split()))

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
#import math as math
import fractions as math


N = int(stdin.readline())
A = list(map(int,stdin.readline().strip().split()))

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

print(ans)

Submission status: Accepted

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

if __name__ == '__main__':
    N = int(input())
    nums = [int(n) for n in input().split()]
    if len(nums) == 1:
        print(nums[0])
        exit()

    ret = gcd(nums[0], nums[1])
    for n in nums[1:]:
        ret = gcd(ret, n)
    print(ret)

Submission status: Accepted

Solution code:
# ABC118C - Monsters Battle Royale
from functools import reduce
from fractions import gcd


def main():
    N, *A = map(int, open(0).read().split())
    ans = reduce(gcd, A)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
n=int(input())
A=list(map(int,input().split()))
print(reduce(gcd, A))

Submission status: Accepted

Solution code:
def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    else:
        return gcd(y,x%y)       
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(1,n):
    ans=gcd(a[i],a[i-1])
    a[i]=ans
print(ans)

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    A = [int(s) for s in input().split()]
    ans = A[0]
    for i in range(1,n):
        ans = gcd(A[i], ans)
    return ans

def gcd(a,b):
    a,b = max(a,b), min(a,b)
    while b > 0:
        a,b = b,a%b
    return a
    
if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  
print(gcd_list(a))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = max(A)
def gcd(x, y):
  if y == 0:
    return x
  else:
    return gcd(y, x % y) 

for i in range (0,N-1):
  x = gcd(A[i],A[i+1])
  ans = min(ans,x)
print(ans)

Submission status: Accepted

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

n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, len(a)):
    ans = gcd(ans, a[i])
    
print(ans)

Submission status: Accepted

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


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


def gcd_for_arr(l):
    tmp = gcd(l[0], l[1])
    for i in range(2, len(l)):
        tmp = gcd(tmp, l[i])
    return tmp


print(gcd_for_arr(a))

Submission status: Accepted

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

n = int(input())
A = list(map(int, input().split()))
g = gcd(A[0], A[1])
for i in range(2,n):
    g = gcd(A[i],g)
print(g)

Submission status: Accepted

Solution code:
from functools import reduce
def gcd(a, b):
    if b==0:
        return a
    while b>0:
        a, b = b, a%b
    return a

N = int(input())
A = map(int, input().split())
ans = reduce(gcd, A)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
n = int(input())
li = list(map(int,input().split()))
print(reduce(gcd,li))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

a = list(map(int,input().split()))
back=0
back2=1
while back != back2:
  while 0 in a:a.remove(0)
  x=min(a)  
  t=a.index(x)
  for i in range(len(a)):
    a[i] = a[i] % x
  a[t]=x
  back2=back
  back=x

print(x)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

print(reduce(gcd, A))

Submission status: Accepted

Solution code:
from heapq import heapify, heappop, heappush
N = int(input())
A = [int(i) for i in input().split()]
heapify(A)
while len(A) > 1:
    curr_attacker, curr_attacked = heappop(A), heappop(A)
    if curr_attacked % curr_attacker != 0:
        heappush(A, curr_attacked % curr_attacker)
    heappush(A, curr_attacker)
print(A[0])

Submission status: Accepted

Solution code:
from fractions import gcd
#from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in A[1:]:
    ans = gcd(ans,i)
    if ans ==1:
        break
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
print(reduce(gcd,a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
input()
a=list(map(int,input().split()))
print(reduce(gcd,a))

Submission status: Accepted

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

def gcd(i,j):
  if i > j:
    i,j = j,i
  j = j % i
  if j != 0:
    return gcd(j,i)
  else:
    return i

g = a[0]
for k in a:
  g = gcd(g,k)
print(g)