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:
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:
n = int(input())
a = sorted(list(map(int,input().split())))
from fractions import gcd
g = a[0]
for i in a[1:]:
    g = gcd(g,i)
print(g)

Submission status: Accepted

Solution code:
import fractions
N = int(input())
al = list(map(int,input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

from fractions import gcd

ans =0
for i in range(n-1):
    if i==0:
        ans = gcd(a[i],a[i+1])
    else:
        ans = gcd(ans,a[i+1])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

import fractions
#import math
from functools import reduce

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

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

g = gcd_list(A)
print(g)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
from fractions import gcd

# input
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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
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)]

######OUTPUT######
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()

#####Shorten#####
def DD(arg): return defaultdict(arg)


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

######Combination######
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

######Factorization######
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

#####MakeDivisors######
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

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

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

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

#####ChangeBase#####
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))))

#####IntLog#####
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

#############
# Main Code #
#############

N = I()
A = IL()
ans = A[0]
for a in A:
  ans = gcd(ans,a)
  
P(ans)

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:
import fractions

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

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

print(a)

Submission status: Accepted

Solution code:
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)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
from fractions import gcd
#import numpy as np

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()))
    #A, B, C = map(int, stdin.readline().rstrip().split())
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    big = gcd(A[0],A[1])
    for i in range(2,N):
        big = gcd(big,A[i])
    print(big)

main()

Submission status: Accepted

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

m_ = min(A)

flag = True

#m_ = m
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_)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()#0じゃない最小値
  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_)

Submission status: Accepted

Solution code:
### ----------------
### ここから
### ----------------

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

### ----------------
### ここまで 
### ----------------

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

Submission status: Accepted

Solution code:
#dpでできないかな？
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)
#print(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)
print(lis[-1])
#print(lis[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

'''
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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