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

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

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

Solution (Python):
import fractions
from functools import reduce

n = int(input())
a = [int(x) for x in input().split()]
ans = reduce(fractions.gcd,a)

print(ans)

Solution (Python):
def main():
    n = int(input())
    A = [int(e) for e in input().split()]

    while True:
        mi = min(A)
        A = [a % mi for a in A if a % mi != 0]
        A.append(mi)

        if len(A) == 1:
            print(mi)
            exit()

if __name__ == "__main__":
    main()

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

res = a[0]

while True:
    base = res
    total = 0
    for i in a:
        if  i % base > 0:
            res = min( res, i % base)
        total +=  i % base
    if total == 0:
        break

print(base)

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

res = a[0]

while True:
    base = res
    total = 0
    for i in a:
        if  i % base > 0:
            res = min( res, i % base)
        total +=  i % base
    if total == 0:
        break

print(base)

Solution (Python):
import fractions
N=int(input())
A=list(map(int,input().split()))
A.sort()
minhp=0
mi=float("inf")
for i in range(N-1):
    minhp=fractions.gcd(A[0],A[i+1])
    if mi>minhp:
        mi=minhp
print(mi)

Solution (Python):
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

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


def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n = int(input())
  a = input_list()
  g = gcd_list(a)
  print(g)
  
import math
import fractions
import collections
from functools import reduce
main()

Solution (Python):
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)

Solution (Python):
import fractions
from functools import reduce

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

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


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

print(gcd_list(a))

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

Solution (Python):
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)

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

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

Solution (Python):
import functools

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

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

def gcd(nums):
    return functools.reduce(euclid, nums)

print(gcd(A))

Solution (Python):








import sys
sys.setrecursionlimit(10 ** 5 + 10)


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



resolve()

Solution (Python):
def gcd(a, b):
    while b != 0:
        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)

Solution (Python):
import fractions

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

print(ans)

Solution (Python):
def GCD(a, b):
    if b == 0:
        return a
    else:
        return GCD(b, a % b)

def LCM(a, b):
    return a // GCD(a, b) * b

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

    ans = 0
    for a in A:
        ans = GCD(ans, a)
    print(ans)

    return 0


if __name__ == '__main__':
    main()

Solution (Python):


N = int(input())
A_list = [int(e) for e in input().split()]




import fractions
from functools import reduce

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

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


print(gcd(*A_list))

Solution (Python):
from functools import reduce
import fractions 
N = int(input())
L = [i for i in map(int,input().split())]
def gcd_list(numbers):
  return reduce(fractions.gcd,numbers)
print(gcd_list(L))

Solution (Python):
n=int(input())

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


import fractions


gcd=al[0]
for i in range(1,n):
    gcd=fractions.gcd(gcd,al[i])

print(gcd)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
while len(A)>1:
  A.sort()
  tmp = [A[0]]
  for i in range(1,len(A)):
    if A[i]-A[0]>0 and A[i]%A[0]!=0:
      tmp.append(A[i]%A[0])
  A = tmp
print(A[0])

Solution (Python):
import fractions

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

base=A[0]

for i in range(N-1):
    base=fractions.gcd(base,A[i+1])

print(base)

Solution (Python):
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):
        c = x % y
        x = y
        y = c
    y = x
    if(y == 1):
        break
print(y)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
nums = n
nin = a[0]
next_nin = a[0]
while nums != 1:
    for i in range(n - nums + 1,n):
        a[i] %= nin
        if a[i] != 0:
            next_nin = min(next_nin, a[i])
        else:
            nums -= 1
    a.sort()
    nin = next_nin
print(nin)

Solution (Python):
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)

Solution (Python):
import heapq
N = int(input())
h = list(map(int, input().split()))
heapq.heapify(h)

while len(h) > 1:
  monster = heapq.heappop(h)
  tmp = [monster]
  heapq.heapify(tmp)
  while len(h) > 0:
    num = heapq.heappop(h) % monster
    if num != 0:
      heapq.heappush(tmp, num) 
  h = tmp
print(heapq.heappop(h))

Solution (Python):




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

    while len(A) > 1:
        A.sort()
        for i in range(1, len(A)):
            A[i] %= A[0]
        A = [a for a in A if a != 0]

    print(A[0])


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
from fractions import gcd
def main():
    
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

    for i in range(N-1):
        if i==0:
            g=gcd(A[i],A[i+1])
        else:
            g=gcd(g,A[i+1])
        if g==1:
            print(1)
            break
    else:
        print(g)

if __name__=="__main__":
    main()

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

Solution (Python):
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))
        heapq.heappush(A, Amax2 * (-1))

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

Solution (Python):
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)

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

Solution (Python):

import fractions
from functools import reduce
N=int(input())
monster=list(map(int,input().split()))
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
print(gcd_list(monster))

Solution (Python):

import numpy as np


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


def submit():
    n = int(input())
    alist = list(map(int, input().split()))

    g = alist[0]
    for a in alist[1:]:
        g = gcd(g, a)

    print(g)
    

if __name__ == "__main__":
    submit()

Solution (Python):

import numpy as np


def submit():
    n = int(input())
    alist = list(map(int, input().split()))

    while True:
        curr_idx = np.argmin(alist)
        curr_min = alist[curr_idx]

        surplus_sum = 0
        for i in range(len(alist)):
            if i == curr_idx:
                continue
            alist[i] %= curr_min
            surplus_sum += alist[i]

        if surplus_sum == 0:
            print(curr_min)
            break

        alist = [a for a in alist if a]
    

if __name__ == "__main__":
    submit()

Solution (Python):
from functools import reduce

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

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

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

Solution (Python):
from fractions import gcd
from functools import reduce

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

    print(gcd_list(num_list))

if __name__ == '__main__':
    main()

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

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

Solution (Python):
from fractions import gcd
 
n = int(input())
aaa = list(map(int, input().split()))
ans = aaa[0]
for a in aaa[1:]:
    ans = gcd(ans, a)
print(ans)
'''
最大公約数。
2匹の状態を考える。A1=22,A2=14とする。
常にHPの低い方を、高い方に攻撃させる。
phase  A1  A2
    1  22←14
    2   8→14
    3   8← 6
    4   2→ 6
    5   2→ 4
    6   2→ 2
    7   2   0    Ans:2
このプロセスは、2数の最大公約数を求めるユークリッドの互除法と
同じ操作になる。残る1匹のモンスターのHPは2数の最大公約数となる。
逆に、この2数同士の引き算だけで、最大公約数以下の値は作れない。
（最大公約数gの倍数同士の引き算では、gの倍数しか作れない）
最大公約数は必ず作れる＆最大公約数未満は作れない→答えは最大公約数。
3匹以上の場合も同じことが言える。 
N個の数の最大公約数は、3匹目は1匹目と2匹目で生き残った方、
4匹目はさらにそこで生き残った方…と闘わせれば作れる。
逆にこれらの数の引き算では最大公約数の倍数しか作れない。
'''

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

Solution (Python):
from fractions import gcd

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

while len(a) > 1:
    a.append(gcd(a.pop(), a.pop()))

print(a.pop())

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

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

Solution (Python):
import fractions
INF = 100000000000

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

min_gcd = INF

for a in range(len(lists) - 1):
  min_gcd = min(min_gcd, fractions.gcd(lists[a], lists[a+1]))

print(min_gcd)

Solution (Python):
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]


from functools import reduce
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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


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

if __name__ == "__main__":
    main()

Solution (Python):


N = int(input().strip())
a_list = [int(i) for i in input().rstrip().split()]


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

ans = a_list[0]
for i in a_list[1:]:
    ans = gcd(ans, i)

print(ans)

Solution (Python):


N = int(input().strip())
a_list = [int(i) for i in input().rstrip().split()]


def gcd(a,b):
    x = max(a,b)
    y = min(a,b)

    while y != 0:
        r = x % y
        
        x = y
        y = r
    
    return x

ans = a_list[0]
for i in a_list[1:]:
    ans = gcd(ans, i)

print(ans)

Solution (Python):
from fractions import gcd

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

num = a[0]

for i in range(1,n):
    num = gcd(num, a[i])

print(num)

Solution (Python):
from functools import reduce
def gcd_list(n):
    return reduce(gcd, n)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

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

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

def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)


def lcm(a: int, b: int) -> int:
    """a, bの最小公倍数(least common multiple: LCM)を求める
    計算量: O(log(min(a, b)))
    """
    return (a * b) // gcd(a, b)


def multi_gcd(array: list) -> int:
    """arrayのGCDを求める"""
    n = len(array)
    ans = array[0]
    for i in range(1, n):
        ans = gcd(ans, array[i])
    return ans


print(multi_gcd(a))

Solution (Python):
from fractions import gcd

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

Solution (Python):
import fractions
import functools

def gcd_list(nums):
    return functools.reduce(fractions.gcd, nums)


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

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

import fractions

ans = A[0]
for i in A :
    ans = fractions.gcd(ans, i)

print(ans)

Solution (Python):



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

def main():
  n = int(input())
  As = list(map(int, input().split()))
  As.sort()
  min = 10**9 + 1
  num = As[0]
  for A in As[1:]:
    num = gcd(num, A)
  print(num)
  
if __name__=='__main__':
  main()

Solution (Python):
def main():
  import sys
  import fractions
  input = sys.stdin.readline
  n=int(input())
  a=list(map(int,input().split()))
  ans=a[0]
  for i in range(n):
    ans=fractions.gcd(a[i],ans)
  print(ans)
if __name__=='__main__':
  main()

Solution (Python):

import fractions

n = int(input())

monsters = list(map(int, input().rstrip().split(" ")))

ans = monsters[0]
for i in range(1, n):
    ans = fractions.gcd(ans, monsters[i])

print(ans)

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

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

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

Solution (Python):
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)

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

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

Solution (Python):
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)

Solution (Python):




from fractions import gcd




import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int,ipti().split()))

    ans = a[0]

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

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
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)

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

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

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

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
def gcd(m,n):
  if m > n: m,n = n,m
  while m != 1:
    if n%m == 0: return m
    m,n = n%m , m
  return m
ans = a[0]
for i in range(n-1):
  ans = gcd(ans,a[i+1])
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = A[N-1]

update = True
while update == True:
    update = False
    n = len(A)
    for i in range(1,n):
        A[i] %= A[0]
    C = []
    for a in A:
        if 1 <= a:
            C.append(a)
    C.sort()
    A = C
    if A[0] < ans:
        ans = A[0]
        update = True

print(ans)

Solution (Python):


n = int(input().rstrip())

monster = [int(i) for i in input().rstrip().split(" ")]

def get_dev(num1:int, num2:int):
    if num1 % num2 == 0:
        return num2
    return get_dev(num2, num1 % num2)

cur = monster[0]
for i in range(1,n):
    cur = get_dev(cur, monster[i])

print(cur)

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

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

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

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

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

answer = gcd(A)
print(answer)

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

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

import fractions
from functools import reduce

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

print(gcd_list(A))

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

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

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

print(ans)

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

B = [A[0]]
for i in range(N):
    if A[i]%A[0] != 0:
        B.append(A[i]%A[0])
B = set(B)



import fractions
from functools import reduce

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

print(gcd_list(B))

Solution (Python):
from functools import reduce


def gcd(a, b):
    if b > a:
        a, b = b, a
    dp = [a, b]
    for i, v in enumerate(dp, start=2):
        dp.append(dp[i - 2] % dp[i - 1])
        if dp[i] == 0:
            break
    return dp[i - 1]


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

Solution (Python):
def gcd(x,y):
  return y if x%y==0 else gcd(y,x%y)
N=input();A=list(map(int,input().split()));
g=A[0];
for a in A:
  g=gcd(g,a)
print(g)

Solution (Python):
from functools import reduce
n = int(input())
a = list(map(int, input().split()))

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

def gcd2(number):
    return reduce(gcd, number)

print(gcd2(a))

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

Solution (Python):
n=int(input())

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

Solution (Python):
import fractions
from functools import reduce

N = int(input())
a = list(map(int, input().split()))
ans = reduce(fractions.gcd, a)
  
print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
b = min(A)
s = A.index(b)
while True:
	c = 0
	for i in range(len(A)):
		if i == s: continue
		else: 
			A[i] %= b
			if A[i] == 0:
				c += 1
			elif A[i] < b:
				b = A[i]
				s = A.index(b)
	if c == n-1:
		print(max(A))
		break

Solution (Python):
import fractions

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

for i in range(1,n):
    if i==1:
        ko = fractions.gcd(a[1],a[0])
    else:
        ko = fractions.gcd(ko,a[i])
print(ko)

Solution (Python):
import fractions

n=int(input())

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

for i in range(1,n):
    if i == 1:
        a = fractions.gcd(t[0], t[1])
    else:
        a = fractions.gcd(a, t[i])
print(a)

Solution (Python):
from fractions import gcd
_, *A = map(int, open(0).read().split())
F = A[0]
for a in A:
  F = gcd(F, a)
print(F)

Solution (Python):
from fractions import gcd
from functools import reduce
input()
print(reduce(gcd,map(int,input().split())))

Solution (Python):
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)

Solution (Python):
n = int(input())
a_lst = list(map(int,input().split()))
a_lst.sort()
b_lst = a_lst.copy()

for _ in range(10**5+1):
    new_lst = []
    min_b = b_lst[0]
    new_lst.append(min_b)

    for i in range(1, len(b_lst)):
        x = b_lst[i]
        tmp = x//min_b
        b = x- min_b*tmp
        if b!=0:
            new_lst.append(b)

    if len(new_lst)==1:
        print(new_lst[0])
        break
    else:
        b_lst = new_lst.copy()
        b_lst.sort()

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

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

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

Solution (Python):
from functools import reduce


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


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

print(reduce(gcd, A))

Solution (Python):
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])
    if ans==1:
        break
print(ans)

Solution (Python):
from fractions import gcd
from functools import reduce
def gcdl(numbers):
    return reduce(gcd, numbers)
n=int(input())
a=list(map(int,input().split()))
print(gcdl(a))

Solution (Python):
import fractions
N = int(input())
mons = tuple(map(int, input().split()))

ans = mons[0]
for m in mons:
    ans = fractions.gcd(ans, m)

print(ans)

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

Solution (Python):
from fractions import gcd
from functools import reduce
n, *A = map(int, open(0).read().split())
print(reduce(gcd, A))

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
while A.count(0)<N-1:
    A.sort()
    i=0
    while A[i]==0: i+=1
    min_A=A[i]
    A=[min_A if j==i else A[j]%min_A for j in range(N)]
print(max(A))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
miner = 0
while sum(a) != miner:
    flag = 0
    miner = min(a)
    for i in range(len(a)):
        if a[i] == miner and flag == 0:
            flag += 1
        else:
            a[i] = a[i]%miner
    a = [i for i in a if i != 0]
print(miner)

Solution (Python):
def gcd(n,m):
    n,m = max(n,m),min(n,m)
    r = n % m
    while r > 0:
        n,m = m,r
        r = n % m
    return m
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)

Solution (Python):
from fractions import gcd

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

ans = gcd(A[0], A[1])

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


print(ans)

Solution (Python):
from heapq import heapify, heappush, heappop
N = int(input())
Alist = list(map(int, input().split()))
heapify(Alist)
while len(Alist)>1:
    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])

Solution (Python):

def gcd(x,y):
    a=max(x,y)
    b=min(x,y)
    r=a%b
    if r==0:
        return b
    else:
        return gcd(b,r)

def extd_gcd(numbers):
    from functools import reduce
    return reduce(gcd,numbers)

if __name__ == '__main__':
    N=int(input())
    Monsters=list(map(int,input().split()))
    print(extd_gcd(Monsters))

Solution (Python):
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
g = a[0]

for i in a[1:]:
    g = gcd(g,i)
print(g)

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

res = A[0]

def f(n, m):
    while m != 0:
        n, m = m, n%m
    return n

for a in A:
    res = f(res, a)

print(res)

Solution (Python):
from fractions import gcd

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

Solution (Python):
import fractions
from functools import reduce

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

ans = reduce(fractions.gcd, a)
print(ans)

Solution (Python):
import fractions
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(fractions.gcd(m, A[i]))
        exit()
print(m)

Solution (Python):
from fractions import gcd

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

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

print(ans)

Solution (Python):
from fractions import gcd

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)

Solution (Python):
import fractions

def monsters_battle_royal(n, a):
    gcd = a[0]
    for i in range(1, n):
        gcd = fractions.gcd(gcd, a[i])
    return gcd

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

ans = monsters_battle_royal(n, a)
print(ans)

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

Solution (Python):
from fractions import gcd

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

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

print(x)

Solution (Python):
from fractions import gcd
n=int(input())
*a,=map(int,input().split())
a.sort()
g=gcd(a[0],a[1])
for i in range(2,n):
	g=gcd(g,a[i])
print(g)

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

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

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

Solution (Python):
import fractions
n=int(input())
l=list(map(int,input().split()))
tmp=l[0]
for i in range(n):
  tmp=fractions.gcd(tmp,l[i])
print(tmp)

Solution (Python):
import fractions
from functools import reduce 
N,*A=map(int,open(0).read().split())
print(reduce(fractions.gcd,A))

Solution (Python):
import fractions

n = int(input())

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

ans = a[0]
for i in range(1,len(a)):
    ans = fractions.gcd(ans,a[i])


print(ans)

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

Solution (Python):
def main():
  n=int(input())
  num=[int(i) for i in input().split()] 
  from fractions import gcd
  
  def gcd2(num,n):
    if n==1:
      return num[0]
    else:
      return gcd2([gcd(num[i],num[-i-1]) for i in range((n+1)//2)],(n+1)//2)
    
  print(gcd2(num,n))

if __name__=='__main__':
  main()

Solution (Python):
n = int(input())

S = input().split(" ")

arr = [int(s) for s in S]

def calculate(m,n):
    if m == n:
        return m
    elif m > n:
        s = m % n
        if s == 0:
            return n
        else:
            return calculate(n,s)
    else:
        s = n % m
        if s == 0:
            return m
        else:
            return calculate(m,s)

v = arr[0]

for index in range(1,n):
    v = calculate(v,arr[index])

print(v)

Solution (Python):
from collections import Counter

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

if len(Counter(A)) == 1:
    print(A[0])
else:
    while sum(a > 0 for a in A) > 1:
        m = min((abs(A[i+1]-A[i]), i) for i in range(N-1) if (A[i+1] != A[i]))
        if A[m[1]+1] > A[m[1]]:
            j = m[1] + 1
            A[j] -= A[j-1]
        else:
            j = m[1]
            A[j] -= A[j+1]
        for i in range(N):
            if i != j:
                A[i] %= A[j]
    print(A[j])

Solution (Python):
from functools import reduce
import fractions


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


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

Solution (Python):
from fractions import gcd

from functools import reduce

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

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    print(gcd_list(A))
    
solve()

Solution (Python):
import fractions

N = int(input())

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

A = sorted(A)

a = A.pop(0)
for i in A:
    a = fractions.gcd(a, i)
    
print(a)

Solution (Python):
from fractions import gcd
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)

Solution (Python):
import fractions
N = int(input())
*A, = map(int, input().split())
chk = [0] * (N+1)
for i in range(N):
    chk[i+1] = fractions.gcd(chk[i], A[i])
print(chk[N])

Solution (Python):
from fractions import gcd
from functools import reduce
N = int(input())
A = [int(i) for i in input().split()]
print(reduce(gcd, A))

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

ans = a[0]

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

print(ans)

Solution (Python):
import sys
import fractions
import functools
f = sys.stdin
n = int(f.readline())
a = list(map(int, f.readline().split()))
gcd = functools.reduce(fractions.gcd, a)
print(gcd)

Solution (Python):
N = int(input())
HP = list(map(int, input().split()))

def gcd(a, b):
    mod = 1

    while (mod > 0):
        mod = a % b
        a = b
        b = mod
    
    return (a)

gc = HP[0]

for i in range(1, N):
    gc = gcd(gc, HP[i])
    

print(gc)