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())
arr = sorted(list(map(int, input().split())))
divider = arr[0]
all = False
while not all:
  all = True
  new_arr = []
  for i in range(len(arr)):
    if arr[i] % divider > 0:
      all = False
      new_arr.append(arr[i] % divider)
  new_arr.append(divider)
  arr = sorted(new_arr)
  divider = new_arr[0]

print(divider)

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):
import fractions as frac
n = int(input())
a = list(map(int, input().split()))

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

print(ans)

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
import sys
from functools import reduce
import math

input = sys.stdin.readline


def main():
    n = int(input())
    a = input_list()
    print(gcd_list(a))

def get_camulative(l):
    import itertools
    
    return [0] + list(itertools.accumulate(l))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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


def input_list_str():
    return list(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)


if __name__ == "__main__":
    main()

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(*a))

Solution (Python):
def f(a,b):
    if b:
        return f(b,a%b)
    return a
n=int(input())
a=list(map(int,input().split()))
p=f(a[0],a[1])
for i in a:
    p=f(p,i)
print(p)

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

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
ans=A[0]
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)

for i in range(n-1):
    ans=gcd(ans,A[i+1])
    if ans==1:
        print(1);exit()

print(ans)

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

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

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

Solution (Python):
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
A = list(map(int,input().split()))
a = A[0]
for i in range(1,N):
    a = gcd(a,A[i])
print(a)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
A.sort()
while len(A) > 1:
  a = [A[0]]
  for i in range(1, len(A)):
    if A[i]%A[0] == 0: continue
    else: a.append(A[i]%A[0])
  A = sorted(a)
print(A[0])

Solution (Python):
import sys
input = sys.stdin.readline
from collections import *
from fractions import *

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

for Ai in A:
    G = gcd(G, Ai)

print(G)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

def main():
    N = int(input())
    A = list(map(int,input().split()))
    ans = A[0]
    for e in A[1:]:
        ans = gcd(ans,e)
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
A = list(map(int, 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)
    

g = gcd_list(A)
print(g)

Solution (Python):
import fractions
N=int(input())
a=input().split()
A=[int(b) for b in a]
A=sorted(A,reverse=True)
numbers=[]
numbers.append(fractions.gcd(A[0],A[1]))
for a in range(1,N):
    answer=fractions.gcd(numbers[-1],A[a])
    numbers.append(answer)
print(numbers[-1])

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

a.sort()

mini = a.pop(0)
ans = 10**9+1
for i in range(n-1):
  temp = fractions.gcd(mini, a[i])
  if temp < ans:
    ans = temp
  
print(ans)

Solution (Python):
import fractions
from functools import reduce
def gcd_list(l):
    return reduce(fractions.gcd, l)
n = int(input())
A = list(map(int, input().split()))
print(gcd_list(A))

Solution (Python):
import fractions

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

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

print(gcd)

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

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):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

from fractions import gcd
n = ii()
A = iil()
cd = A[0]
for item in A:
    cd = gcd(cd,item)
print(cd)

Solution (Python):
from functools import reduce
N = int(input())
*A, = map(int, input().split())
def gcd(a,b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a
ans = reduce(gcd, A)
print(ans)

Solution (Python):
import fractions
n = int(input())
a_list = sorted(list(map(int,input().split())))

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

print(a)

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

while True:
    m = min(a)
    for i in range(len(a)):
        if a[i] != m:
            a[i] = a[i] % m
    a.sort()
    z = a.count(0)
    a = a[z:]
    if min(a) == m:
        break
print(m)

Solution (Python):
import numpy as np
from functools import lru_cache
import sys
sys.setrecursionlimit(10**6)

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


@lru_cache(maxsize=None)
def gcd(a, b):
    if (b == 0):
        return a
    else:
        return gcd(b, a % b)


ans = a[0]

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

print(ans)

Solution (Python):
n=int(input()) 
lis=list(map(int,input().split()))
m=min(lis)
new=lis
num=0
while True:
  for i in range(n+num):
    new[i]%=m
  if all(nn==0 for nn in new):
    print(m)
    exit()
  new.append(m)
  sl={m}
  for i in range(n+num):
    if new[i]!=0:
      sl.add(new[i])
  m=min(sl)
  num+=1

Solution (Python):
from fractions import gcd


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 sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


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)
  return divisors


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


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1





N = I()
A = IL()
ans = A[0]
for a in A:
  ans = gcd(ans,a)
  
P(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 fractions

N = int(input())
a, *A = map(int, input().split())

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

print(a)

Solution (Python):
import fractions
n=int(input())
n=list(map(int,input().split()))
p=n[0]
for x in n:
    p=fractions.gcd(p,x)
print(p)

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

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

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)

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

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

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

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

x = a_input.pop(0)
for i in range(len(a_input)):
    x = gcd(x,a_input[i])
print(x)

Solution (Python):
import sys

def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

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

ans = gcd(a[0], a[1])
for x in a[2:]:
    tmp = gcd(ans, x)
    if tmp < ans:
        ans = tmp
print(ans)

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()

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

Solution (Python):
N=int(input())
l=list(map(int,input().split()))
S_max=max(l[0],l[1])
S_min=min(l[0],l[1])
while S_max % S_min != 0:
   S_min,S_max=S_max % S_min,S_min
for i in range(1,N-1):
   S_max=max(S_min,l[i+1])
   S_min=min(S_min,l[i+1])
   while S_max % S_min != 0:
      S_min,S_max=S_max % S_min,S_min
print(S_min)

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

Solution (Python):
import sys








from fractions import gcd


stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18



def main():
    N = int(stdin.readline().rstrip())
    A = list(map(int, stdin.readline().rstrip().split()))
    
    
    
    
    
    big = gcd(A[0],A[1])
    for i in range(2,N):
        big = gcd(big,A[i])
    print(big)

main()

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

m_ = min(A)

flag = True


while True:
    m = m_
    flag = True
    for a in A:
        n = a % m
        if n > 0:
            flag = False
            m_ = min(m_, n)
    if m_ == m:
        break
    if flag:
        break

print(m_)

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

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

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

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

print(gcd_list(a))

Solution (Python):
import numpy as np
import fractions
import sys
readline = sys.stdin.readline
read = sys.stdin.read

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

N = II()
A = LII()

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

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

Solution (Python):
from fractions 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:
        print(1)
        break
else:
    print(ans)

Solution (Python):
import numpy as np

n = int(input())

a = input().split(' ')

a = np.array(a).astype(int)


while a[a>0].shape[0] > 1:
  not_0_a = a[a!=0]
  min_ = not_0_a.min()
  min_i = np.where(a == min_)
  a = a % min_
  a[min_i[0][0]] = min_

  """
  if a[a>0].shape[0] == 1:
    not_0_a = a[a!=0]
    min_ = not_0_a.min()
  """
  
print(min_)

Solution (Python):




import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    while len(arr)>1:
        x=min(arr)
        arr=[a%x for a in arr]
        arr.append(x)
        arr=[a for a in arr if a!=0]
    print(arr[0])

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Solution (Python):
import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()


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

    pre = A.pop()
    while A:
        a = A.pop()
        pre = gcd(a, pre)
    print(pre)

if __name__ == "__main__":
    main()

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

input()
monsters = set(map(int, input().split(' ')))
print(reduce(gcd, monsters))

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
lis=sorted(lis)


for i in range(1,n):
    lis[i]=lis[i]%lis[0]
lis.append(0)
lis=sorted(list(set(lis)))
    
while len(lis)>2:
    for i in range(2,len(lis)):
        lis[i]=lis[i]%lis[1]
    lis.append(0)
    lis=sorted(list(set(lis)))

print(lis[-1])

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
b = a
while(1):
    c = [b[0]]
    for i in range(1,len(b)):
        if b[i] % b[0]:
            c.append(b[i]%b[0])
    b = sorted(c)
    if len(b) == 1:
        print(b[0])
        exit()

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


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


print(gcd(An))

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


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


res = lis[-1]
for x in lis:
    res = gcd(res, x)

print(res)

Solution (Python):
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

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

Solution (Python):
from math import gcd

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

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

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

print(g)

Solution (Python):
import math
input()
a,*b=map(int,input().split())
for i in b:a=math.gcd(a,i)
print(a)

Solution (Python):


import sys



















from fractions import gcd                    


def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    A = lmi()
    g = A[0]
    for i in range(1, n):
        g = gcd(g, A[i])
    print(g)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from fractions import gcd


def input():
    return sys.stdin.readline().strip()


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    a = A[0]
    B = set()
    for i in range(1, N):
        g = gcd(A[i], a)
        if g == 1:
            B.add(1)
        elif g == a:
            continue
        else:
            B.add(g)
    if len(B) == 0:
        print(a)
    else:
        print(min(B))


if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18


n = I()
A = LI()
g = reduce(gcd, A)
print(g)

Solution (Python):
import sys
import fractions
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    g = a[0]

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

main()

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):
def main():
  N=int(input())
  A=list(set(list(map(int,input().split()))))

  if min(A)==1:
    print(1)
    exit()

  while len(A)>1:
    monster_min = A.pop(A.index(min(A)))
    for i in range(len(A)):
      A[i] %= monster_min
    A.sort()
    for i in A[:]:  
      if i == 0: A.remove(i)
      else: continue
    A.append(monster_min)

  print(A[0])

if __name__ == "__main__":
  main()

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

if min(A)==1:
  print(1)
  exit()

while len(A)>1:
  monster_min = A.pop(A.index(min(A)))
  for i in range(len(A)):
    A[i] %= monster_min
  A.sort()
  for i in A[:]:  
    if i == 0: A.remove(i)
    else: continue
  A.append(monster_min)

print(A[0])

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

if min(A)==1:
  print(1)
  exit()

while len(A)>1:
  monster_min = A.pop(A.index(min(A)))
  for i in range(len(A)):
    A[i] %= monster_min
  A.sort()
  for i in A[:]:  
    if i == 0: A.remove(i)
    else: continue
  A.append(monster_min)

print(A[0])

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

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

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()))
ans = gcd_list(A)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline




'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

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

Solution (Python):
import fractions
def myAnswer(N:int,A:list) -> int:
   A.sort()
   pre = A.pop(0)
   ans = 10**10
   for a in A:
      ans = min(fractions.gcd(pre,a),ans)
      pre = a
   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Solution (Python):
import heapq
n = int(input())
heap = list(map(int, input().split()))
heapq.heapify(heap)
m = heapq.heappop(heap)
while True:
    heap2 = []
    for i in heap:
        if i%m != 0:
            heapq.heappush(heap2, i%m)
    if len(heap2) == 0:
        print(m)
        exit()
    heapq.heappush(heap2, m)
    m = heapq.heappop(heap2)
    heap = heap2

Solution (Python):
import fractions
n = int(input())
l = list(map(int, input().split()))
ans = l[0]
for i in l[1:]:
    ans = fractions.gcd(i, ans)
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):
import sys
from fractions import gcd

input = sys.stdin.readline


def main():
    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)


if __name__ == "__main__":
    main()

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

res=fractions.gcd(A[0],A[1])
for i in range(2,N):
  res = fractions.gcd(res,A[i]);
print(res)

Solution (Python):


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

N = int(input())
A = list(int(x) for x in input().split())

ans = gcd(A[0], A[1])
for i in range(2, N):
    ans = 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):
def ngcd(lista):
    from fractions import gcd
    res = lista[0]
    for i in range(1,len(lista)):
        if res != 1:
            res = gcd(lista[i],res)
    return res

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

if __name__ == '__main__':
    main()

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

print(g)

Solution (Python):
from fractions import gcd  


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    A.sort()
    print(min([gcd(A[0], a) for a in A[1:]]))


if __name__ == '__main__':
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

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

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

print(ans)

Solution (Python):
num = (int)(input())
mons = list(map(int, input().split(" ")))
while(sum(mons) != len(mons) * min(mons)):
  wari = min([e for e in mons if e != 0])
  for i in range(len(mons)):
    if mons[i] != wari:
      mons[i] %= wari
  mons = [e for e in mons if e != 0]
print(max(mons))

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

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

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

N = int(input())
l = map(int, input().split())

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

print(gcd_list(l))

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): return k.join(list(map(str, lst)))
INF = float('inf')

from fractions import gcd
def solve():
    n = II()
    A = LI()

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


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): return k.join(list(map(str, lst)))
INF = float('inf')

def solve():
    n = II()
    A = LI()
    A = sorted(A)
    
    
    while 1:
        if len(set(A)) == 1:
            print(A[0])
            return

        a0 = A[0]
        for i in range(1, n):
            ai = A[i]
            if ai % a0 == 0:
                A[i] = a0
            else:
                A[i] = ai % a0
        A = sorted(A)
        

if __name__ == '__main__':
    solve()

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

import heapq
while len(a)>1:
    heapq.heapify(a)
    s=heapq.heappop(a)
    an=[s]
    for i in range(len(a)):
        m=a[i]%s
        if m>0:
            an.append(m)
    a.clear()
    a=an
print(s)