Problem:


Score : 300 points

Problem Statement

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

Initially, the health of Monster i is A_i.

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

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

A random alive monster attacks another random alive monster.

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

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

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

4
2 10 8 40

Sample Output 1

2

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

Sample Input 2

4
5 13 8 1000000000

Sample Output 2

1

Sample Input 3

3
1000000000 1000000000 1000000000

Sample Output 3

1000000000



Sample input:
4
2 10 8 40


Sample output:
2

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    dummy = [0 for i in range(N)]

    m = 10**9 + 1
    idx = 0
    for i in range(N):
        dummy[i] = A[i]
        if m > A[i]:
            m = A[i]
            idx = i

    for i in range(N):
        if i == idx :
            continue
        dummy[i] = dummy[i] % m

    ma = 0
    for i in range(N):
        if i == idx:
            continue
        if ma < dummy[i]:
            ma = dummy[i]

    if ma == 0:
        print(m)
    else:
        if m % ma == 0:
            print(ma)
        else:
            print(1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    dummy = [0 for i in range(N)]

    m = 10**9 + 1
    idx = 0
    for i in range(N):
        dummy[i] = A[i]
        if m > A[i]:
            m = A[i]
            idx = i

    for i in range(N):
        if i == idx :
            continue
        dummy[i] = dummy[i] % m

    ma = 0
    for i in range(N):
        if i == idx:
            continue
        if ma < dummy[i]:
            ma = dummy[i]

    if ma == 0:
        print(m)
    else:
        print(1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


S.sort()
while len(S)!=1:
    
    
    
    if S[1]%S[0]==0:
        S.pop(1)
    
    else:
        S[1]=S[1]%S[0]
        tmp=S[1]
        S[1]=S[0]
        S[0]=S[1]
    if S[0]==1:
        print(1)
        exit()
print(S[0])

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def main():
    n = int(input())
    As = list(map(int, input().split()))
    print(n)
    print(As)
    ans = gcd(As[0], As[1])
    for i in range(2, n):
        ans = gcd(ans, As[i])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

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

a.sort()

min_num = a[0]

for i in range(N):
    if a[i] % min_num:
       print(1)
       exit()

print(min_num)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
sf = [a[0]] * n
for i in range(1, n):
    sf[i] = gcd(sf[i - 1], a[i])
sb = [a[n - 1]] * n
for i in range(n - 2, -1, -1):
    sb[i] = gcd(sb[i + 1], a[i])
ans = 1001001001
for i in range(n):
    if i == 0:
        ans = min(ans, sb[1])
    elif i == n - 1:
        ans = min(ans, sf[n - 2])
    else:
        ans = min(ans, gcd(sf[i - 1], sb[i + 1]))
print(ans)

Submission status: Wrong Answer

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

ans = a[0]
for i in range(1,n):
  x = a[i] % ans
  if x == 0 :
    continue
  else :
    ans = min( x , ans )

print(ans)

Submission status: Wrong Answer

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

A.sort()
stack = A[1:]
m = A[0]

while stack:
  stack = list(stack)
  l = []
  for x in stack:
    if x % m == 0:
      continue
    l.append(x % m)
  
  if not l:
    break
  m = min(l)
  stack = set(l)

print(m)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
ls = list(map(int,input().split()))
mn = min(ls)
a = []
for j in range(n):
    a.append(ls[j]%mn)
if a == [0]*n:
    print(mn)
    sys.exit()
ls = list(set(ls))
for i in range(len(ls)):
    ls[i] = ls[i]%2
if ls == [0]*len(ls):
    print(2)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
ls = list(map(int,input().split()))
ls = list(set(ls))
if len(ls) == 1:
    print(ls[0])
    sys.exit()
for i in range(len(ls)):
    ls[i] = ls[i]%2
if ls == [0]*len(ls):
    print(2)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

def main():
    n = int(input())
    a = list(map(int, input().split()))
    m = min(a)
    count = 0
    while count != n:
        count = 0
        for i in range(n):
            a[i] %= m
            if a[i] != 0:
                m = a[i]
            else:
                count += 1
    print(m)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

amin = A[0]
multi = True
even = True
for i in range(N):
    if A[i] % amin != 0:
        multi = False
    if A[i] % 2 != 0:
        even = False

if multi: print(amin)
elif even: print(2)
else: print(1)

Submission status: Wrong Answer

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

same = True
for i in range(N):
    a = A[i]
    if i > 0 and a != A[i-1]:
        same = False
    if a % 2 == 1:
        print(1)
        break
else:
    if same:
        print(A[0])
    else:
        print(2)

Submission status: Wrong Answer

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

same = True
for i in range(N):
    a = A[i]
    if i > 0 and a != A[i-1]:
        same = False
    if a % 2 == 1:
        print(1)
else:
    if same:
        print(A[0])
    else:
        print(2)

Submission status: Wrong Answer

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

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


count = 0

for i in range(len(a)):
    if a[i] % 2 == 0:
        count += 1

if count != len(a):
    print(1)
else:
    print(min(a))

Submission status: Wrong Answer

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

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

a = set(a)


def func(set_):
    list_ = list(set_)
    set_new = set()
    for i in range(0, len(list_)-1):
        for j in range(1, len(list_)):
            if list_[i] % list_[j] != 0:
                set_new.add(list_[i] % list_[j])

    return set_new


ans = min(a)
while(1):
    a_new = func(a)
    # print(a_new)

    if a_new == set():
        break
    ans = min(ans, min(a_new))
    a = a_new

print(ans)

Submission status: Wrong Answer

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

    A.sort()
    mons_A = A[0]
    mons_B = A[1]
    while True:
        if mons_A <= 0:
            print(mons_B)
            break
        elif mons_B <= 0:
            print(mons_A)
            break
        if mons_A > mons_B:
            mons_A -= mons_B
        else:
            mons_B -= mons_A


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd


N = int(input())
A = sorted(map(int, input().split()))
print(gcd(A[0], A[1]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def gdc(p, q):
    if q == 0:
        return p
    return gdc(q, p%q)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    if N == 1:
        print(A[0])
        return
    A_sorted = sorted(A)
    print(gdc(A[1], A[0]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

while min(nums) > 1:
    monster_index = nums.index(min(nums))
    monster = nums.pop(monster_index)
    nums = [n-monster for n in nums]
    nums.append(monster)

nums = [n for n in nums if n != 0]
print(min(monster,min(nums)))

Submission status: Wrong Answer

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

while min(nums) > 1:
    monster_index = nums.index(min(nums))
    monster = nums.pop(monster_index)
    nums = [n-monster for n in nums]
    nums.append(monster)

nums = [n for n in nums if n != 0]
print(min(nums))

Submission status: Wrong Answer

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

state = True
for i in s:
    if i%2 != 0:
        break
else:
    state = False

s.sort()
m = s[0]
for i in range(1,n):
    if s[i]%m != 0:
        if state:
            print(1)
        else:
            print(2)
        break
else:
    print(m)

Submission status: Wrong Answer

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

s.sort()
m = s[0]
for i in range(1,n):
    if s[i]%m != 0:
        print(1)
        break
else:
    print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ln = []
for i in a:
    for j in a:
        ln.append(min((max(i, j) % min(i, j)), min(i, j) - (max(i, j) % min(i, j))))
ln = [x for x in ln if x != 0]
if ln == []:
    print(min(a))
else:
    print(min(ln))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
dif_min = a[1]-a[0]
ind = 1
for i in range(n-1):
    dif = a[i+1]-a[i]
    if dif_min>dif and dif!=0:
        dif_min = dif
        ind = i+1
a[ind] = dif_min
a.sort()
dif_min = a[1]-a[0]
ind = 1
for i in range(n-1):
    dif = a[i+1]-a[i]
    if dif_min>dif and dif!=0:
        dif_min = dif
        ind = i+1
a[ind] = dif_min 
a.sort()

ans = a[1]-a[0]
if ans==0:
    ans = a[0]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
monster=list(map(int, input().split()))
monster.sort()
m = monster[0]
M = 0 
for i in range(1,n):
    tmp = monster[i]%m
    M = max(M,tmp)
if M==0:
    print(m)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ma=min(a)
ans=min(a)
for i in range(len(a)):
  if a[i]%ma!=0:
    if ma%2==0 and a[i]%2==0 and ans>2:
      ans=2
    else:
      ans=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ma=min(a)
ans=min(a)
for i in range(len(a)):
  if a[i]%ma!=0:
    if ma%2==0 and a[i]%2==0 and ans>2:
      ans=2
    elif ma%2==0 and a[i]%2==1 and ans>1:
      ans=1
    elif ma%2==1 and a[i]%2==0 and ans>1:
      ans=1
    elif ma%2==1 and a[i]%2==1 and ans>1:
      ans=1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
A=sorted(A,reverse=True)
numbers=[]
for a in range(N-1):
    b=A[a]-A[a+1]
    numbers.append(b)
numbers.append(A[-1])
suuji=0
for a in numbers:
    if a==0:
        numbers[suuji]=pow(10,9)
    suuji+=1
minimum=min(numbers)
place=numbers.index(minimum)
del(A[place])
answers=[]
for number in A:
    answer=number%minimum
    if answer!=0:
        answers.append(answer)
answers.append(minimum)
print(min(answers))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = As[0]
for a_i in As[1:]:
    tmp = a_i % ans
    if tmp != 0 and tmp < ans:
        ans = tmp
    if ans == 1:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

# input
N = int(input())
A = list(map(int, input().split()))
min_hp = min(
    [
        i % j
        for i, j in list(combinations(A, 2))
    ]
)
print(min_hp)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
a_input = list(map(lambda x:-int(x),input().split()))

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

Submission status: Wrong Answer

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 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 = deque(getList())

opt1 = A[0]

while len(A) > 0:
    i = A.popleft()
    if i == 1:
        opt1 = 1
        break
    if i % opt1 != 0:
        A.append(i % opt1)
        opt1 = i % opt1
print(opt1)

Submission status: Wrong Answer

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 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 = deque(getList())

opt1 = A[0]

while len(A) > 0:
    i = A.popleft()
    if i == 1:
        opt1 = 1
        break
    if i % opt1 != 0:
        A.append(i % opt1)
        opt1 = i
print(opt1)

Submission status: Wrong Answer

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 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 = deque(getList())

opt1 = A[0]

while len(A) > 0:
    i = A.popleft()
    if i % opt1 != 0:
        A.append(i % opt1)
        opt1 = i
        print(A)
print(opt1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
if all([i % a[0] == 0 for i in a]):
    print(a[0])
else:
    print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in A[1:]:
    if i % ans == 0 or ans % i == 0:
        ans = min(ans,i)
    else:
        print(1)
        break
else:
    print(ans)

Submission status: Wrong Answer

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_
  print(a)

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

Submission status: Wrong Answer

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()
  min_i = np.where(not_0_a == min_)
  a = a % min_

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

Submission status: Wrong Answer

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()
  min_i = np.where(not_0_a == min_)
  a = a % min_
  
  if len(min_i[0]) == 1:
    a[min_i] = min_

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

Submission status: Wrong Answer

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()
  a = a % min_
  
print(min_)

Submission status: Wrong Answer

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:
  min_ = max(a.min(), 1)
  a = a % min_
  
print(min_)

Submission status: Wrong Answer

Solution code:
import sys
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()
        if a % pre != 0:
            pre -= a % pre
    print(pre)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
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()
        if a % pre != 0: pre = a % pre
    print(pre)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


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):
        if A[i] % a == 0:
            continue
        else:
            B.add(A[i] % a)
    if len(B) == 0:
        print(a)
    else:
        B = list(B) + [a]
        B.sort()
        b = B[0]
        if b == 1:
            print(1)
            return
        cnt = 0
        for i in range(1, len(B)):
            if not B[i] % b == 0:
                break
            else:
                cnt += 1
        if cnt == len(B) - 1:
            print(b)
        else:
            print(1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


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):
        if A[i] % a == 0:
            continue
        else:
            B.add(A[i] % a)
    if len(B) == 0:
        print(a)
    else:
        B = list(B) + [a]
        B.sort()
        b = B[0]
        cnt = 0
        for i in range(1, len(B)):
            if not B[i] % b == 0:
                break
            else:
                cnt += 1
        if cnt == len(B) - 1:
            print(b)
        else:
            print(1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


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):
        if A[i] % a == 0:
            continue
        else:
            B.add(A[i] % a)
    if len(B) == 0:
        print(a)
    else:
        B = list(B)
        B.sort()
        b = B[0]
        cnt = 0
        for i in range(1, len(B)):
            if not B[i] % b == 0:
                break
        if cnt == len(B) - 1:
            print(b)
        else:
            print(1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


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):
        if A[i] % a == 0:
            continue
        else:
            B.add(A[i] % a)
    if len(B) == 0:
        print(a)
    else:
        B = list(B)
        B.sort()
        b = B[0]
        cnt = 0
        for i in range(1, len(B)):
            if not B[i] % b == 0:
                break
        if cnt == len(B) - 1:
            print(b)
        else:
            print(B[0])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import heapq


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


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


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

    divisors.sort()
    return divisors


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
l = len(a)
min = a[0]
for i in range(l - 1):
    x = a[i + 1] - a[i]
    if min > x:
        min = x
ans = 10e9 + 1
for i in range(l):
    a[i] = a[i] % min
    if a[i] == 0:
        a[i] += min
    if ans > a[i]:
        ans = a[i]
min = ans
for i in range(l):
    a[i] = a[i] % min
    if a[i] == 0:
        a[i] += min
    if ans > a[i]:
        ans = a[i]
print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
l = len(a)
min = a[0]
for i in range(l - 1):
    x = a[i + 1] - a[i]
    if min > x:
        min = x
ans = 10e9 + 1
for i in range(l):
    a[i] = a[i] % min
    if a[i] == 0:
        a[i] += min
    if ans > a[i]:
        ans = a[i]
for i in range(l):
    a[i] = a[i] % ans
    if a[i] == 0:
        a[i] += ans
    if ans > a[i]:
        ans = a[i]
print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
l = len(a)
min = a[0]
for i in range(l - 1):
    x = a[i + 1] - a[i]
    if min > x:
        min = x
ans = 10e9 + 1
for i in range(l):
    a[i] = a[i] % min
    if a[i] == 0:
        a[i] += min
    if ans > a[i]:
        ans = a[i]
print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
l = len(a)
min = float("INF")
for i in range(l - 1):
    x = a[i + 1] - a[i]
    if min > x:
        min = x
ans = float("INF")
for i in range(l):
    a[i] = a[i] % min
    if a[i] == 0:
        a[i] += min
    if ans > a[i]:
        ans = a[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
l = len(a)
min = float("INF")
for i in range(l - 1):
    x = a[i + 1] - a[i]
    if min > x:
        min = x
ans = float("INF")
for i in range(l):
    a[i] = a[i] % min
    if a[i] == 0:
        a[i] += min
    if ans > a[i]:
        ans = a[i]
print(int(ans))

Submission status: Wrong Answer

Solution code:
import fractions
def myAnswer(N:int,A:list) -> int:
   A.sort()
   target = A.pop(0)
   for a in A:
      if(fractions.gcd(target,a)==1):
         return 1
   return target

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

Submission status: Wrong Answer

Solution code:
import fractions
def myAnswer(N:int,A:list) -> int:
   A.sort()
   return fractions.gcd(A[0],A[1])

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

Submission status: Wrong Answer

Solution code:
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-1):
    d = gcd(d,a[i])
print(d)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
mi=abs(a[1]-a[0])
for i in range(2,n):
    k=abs(a[i]-a[i-1])
    mi=min(mi,k)
print(mi)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

lisA.sort()
targetnum = lisA[1]
for num in lisA:
    if num == lisA[0]:
        continue
    else:
        targetnum = num
        break

ans = gcd(lisA[0],targetnum)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

lisA.sort()

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

print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    if a[i] % min_mod != 0:
        flag = False
        break

if flag:
    print(min_mod)
else:
    print(1)

Submission status: Wrong Answer

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

if flag:
    print(min_mod)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
min_mod = min(a)
flag = True
for i in range(n):
    if a[i] % min_mod != 0:
        flag = False
        break

if flag:
    print(min_mod)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.sort()
ap = 10**9+7
for a in A:
    r = a%ap
    if r>0:ap = r
print(ap)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
ap = 10**9+7
for a in A:
    r = a%ap
    if r>0:ap = r
print(ap)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

a.sort()

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

if sum(a) - a[0] == 0:
	print(a[0])
else:
	a.sort()
	a = deque(a)
	while True:
		A = a.popleft()
		if A != 0:
			a.appendleft(A)
			break
	for i in range(1,len(a)):
		a[i] %= a[0]
	if sum(a) - a[0] == 0:
		print(a[0])
	else:
		print(1)

Submission status: Wrong Answer

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

a.sort()

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

if sum(a) - a[0] == 0:
	print(a[0])
else:
	print(1)

Submission status: Wrong Answer

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


n = int(input())
li = list(map(int, input().split()))
li.sort()
r = 10000000000
for i in range(n - 2):
    if r > gcd(li[i], li[i + 1]):
        r = gcd(li[i], li[i + 1])
print(r)

Submission status: Wrong Answer

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


n = int(input())
li = list(map(int, input().split()))
li.sort()
print(gcd(li[n - 1], li[n - 2]))

Submission status: Wrong Answer

Solution code:
n = int(input())
#n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
#abc = [int(input()) for i in range(5)]
a.sort()
for i in range(1, n):
    a[i] %= a[0]
a.sort(reverse=True)
# print(a)
ans = a[-1]
if ans == 0:
    for i in range(n-1, -1, -1):
        if a[i] != 0:
            print(a[i])
            exit()
else:
    for i in range(n-1, -1, -1):
        if a[i] % ans != 0:
            if a[i] % ans < ans:
                ans = a[i] % ans
print(ans)

Submission status: Wrong Answer

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

a.sort()
for i in range(1, n):
    a[i] %= a[0]
a.sort(reverse=True)
# print(a)
ans = a[-1]
if ans == 0:
    for i in range(n-1, -1, -1):
        if a[i] != 0:
            print(a[i])
            exit()

print(ans)

Submission status: Wrong Answer

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

a.sort()
for i in range(1, n):
    a[i] %= a[0]
a.sort(reverse=True)
# print(a)
ans = a[-1]
if ans == 0:
    for i in range(n-1, -1, -1):
        if a[i] != 0:
            print(a[i])
            exit()
else:
    for i in range(n-1, -1, -1):
        if a[i] % ans != 0:
            if a[i] % ans < ans:
                ans = a[i] % ans
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
#n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
#abc = [int(input()) for i in range(5)]
a.sort()
for i in range(1, n):
    a[i] %= a[0]
a.sort(reverse=True)
ans = a[-1]
if ans == 0:
    for i in range(n-1, -1, -1):
        if a[i] != 0:
            print(a[i])
            exit()
print(ans)

Submission status: Wrong Answer

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

a.sort()
for i in range(1, n):
    a[i] %= a[0]
ans = a[-1]
if ans == 0:
    for i in range(n-1, -1, -1):
        if a[i] != 0:
            print(a[i])
            exit()
print(ans)

Submission status: Wrong Answer

Solution code:
# C - Monsters Battle Royale

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

ans = A[0]
for i in range(1, N):
    tmp = A[i]%ans
    if tmp != 0:
        ans = tmp
    else:
        continue
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
min_num=min(a)
for i in a:
    if i==min_num:
        continue
    else:
        if i%min_num!=0:
            print(1)
            exit()
print(min_num)

Submission status: Wrong Answer

Solution code:
n = int(input())
al = list(map(int, input().split()))
al.sort()
t = al[0]
ans = t
for a in al:
    if a % t == 0:
        continue
    else:
        ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
allsame=True
alleven=True
for a in A:
    if allsame:
        if a!=A[0]:
            allsame=False
    if a%2==1:
        alleven=False

if allsame:
    print(A[0])
elif alleven:
    print(2)
else:
    print(1)