input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
# -*- coding: utf-8 -*-
import copy
import queue
N = int(eval(input()))
a_list = list(map(int, input().split()))
gain = sum([a for a in a_list if a > 0])
# Flow network
S = 0
T = N + 1
c = [{} for i in range(N + 2)]
for i, a in enumerate(a_list):
index = i + 1
if a <= 0:
c[S][index]... | import copy
import collections
N = int(eval(input()))
A = list(map(int, input().split()))
gain = sum([max(a, 0) for a in A])
# Flow network
S, T = 0, N + 1
c = [{} for i in range(N + 2)]
for i in range(N):
ix = i + 1
if A[i] <= 0:
c[S][ix] = -A[i]
else:
c[ix][T] = A[i]
... | p03553 |
from collections import *
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
class Dinic():
def __init__(self, n, s, t):
s... | from collections import *
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
class Dinic():
def __init__(self, n, s, t):
s... | p03553 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, ... | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, ... | p03553 |
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline()... | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline()... | p03553 |
class Dinic:
def __init__(self, v, inf=float("inf")):
self.V = v
self.inf = inf
self.G = [[] for _ in range(v)]
self.level = [0 for _ in range(v)]
self.iter = [0 for _ in range(v)]
def addEdge(self, fm, to, cap):
'''
to:行き先
cap:容量
rev:反対側の辺
'''
self.G[fm].append({'to':to, 'cap':... | class Ford_Fulkerson:
def __init__(self, v, inf=float("inf")):
self.V = v
self.inf = inf
self.G = [[] for _ in range(v)]
self.used = [False for _ in range(v)]
def addEdge(self, fm, to, cap):
'''
to:行き先
cap:容量
rev:反対側の辺
'''
self.G[fm].append({'to':to, 'cap':cap, 'rev':len(self.G[to]... | p03553 |
# Dinic's algorithm
from collections import deque
class Dinic:
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
def add_edge(self, fr, to, cap):
forward = [to, cap, None]
forward[2] = backward = [fr, 0, forward]
self.G[fr].append(forward)
... | from collections import deque
class Dinic:
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
def add_edge(self, fr, to, cap):
forward = [to, cap, None]
forward[2] = backward = [fr, 0, forward]
self.G[fr].append(forward)
self.G[to].append... | p03553 |
import sys
def generate_next_hexes(x, y):
hexes = list()
hexes.append((x, y - 1))
hexes.append((x, y + 1))
hexes.append((x - 1, y))
hexes.append((x + 1, y))
if y % 2:
hexes.append((x - 1, y - 1))
hexes.append((x - 1, y + 1))
else:
hexes.append((x + 1, y -... | import sys
def generate_next_hexes(x, y):
hexes = [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)]
if y % 2:
hexes += [(x - 1, y - 1), (x - 1, y + 1)]
else:
hexes += [(x + 1, y - 1), (x + 1, y + 1)]
return hexes
def update_map(hex_map, hexes):
num_updated_hexes = 0
... | p00193 |
Q, H, S, D = list(map(int, input().split()))
N = int(eval(input()))
ans1 = 4 * Q * N
ans2 = 2 * H * N
ans3 = S * N
if N < 2:
ans4 = float('INF')
elif N % 2 == 0:
ans4 = (N // 2) * D
else:
t = (N // 2) * D
ans4 = t + min(4 * Q, 2 * H, 1 * S)
# print(ans1, ans2, ans3, ans4)
ans = min(an... | Q, H, S, D = list(map(int, input().split()))
N = int(eval(input()))
t = min(4*Q, 2*H, S)
if D < 2 * t:
if N % 2 == 0:
ans = (N // 2) * D
else:
ans = (N // 2) * D + t
else:
ans = N * t
print(ans)
| p03617 |
q, h, s, d = [int(i) for i in input().split()]
n = int(eval(input()))
d = min(min(d, s*2), min(h*4, q*8))
s = min(s, min(h*2, q*4))
h = min(h, q*2)
ans = (n // 2) * d
n %= 2
while n > 0:
if n >= 1:
n -= 1
ans += s
elif n >= 0.5:
n -= 0.5
ans += h
else:
... | q, h, s, d = [int(i) for i in input().split()]
n = int(eval(input()))
d = min(min(d, s*2), min(h*4, q*8))
s = min(s, min(h*2, q*4))
print(((n // 2) * d + (n % 2) * s)) | p03617 |
Q,H,S,D = (int(i) for i in input().split())
N = int(eval(input()))
q = Q*4
h = H*2
s = S
d = D/2
if min(q,h,s,d)==d:
if N%2 == 0:
money = D*(N//2)
else:
money = (N//2)*D + min(q,h,s)
else:
money = min(q,h,s)*N
print((int(money))) | Q,H,S,D = (int(i) for i in input().split())
N = int(eval(input()))
Qper025L = Q
Hper025L = H / 2
Sper025L = S / 4
Dper025L = D / 8
teainfo = [["Q",Qper025L,Q,0.25],["H",Hper025L,H,0.50],["S",Sper025L,S,1],["D",Dper025L,D,2]]
sortedtea = sorted(teainfo, key = lambda x:(x[1],x[2]), reverse = False)
price ... | p03617 |
q,h,s,d = list(map(int,input().split()))
n = int(eval(input()))
twoL = min(q*8,4*h,2*s,d)
oneL = min(q*4,2*h,s)
p = (n//2)*twoL + (n%2)*oneL
print(p)
| Q,H,S,D=list(map(int,input().split()))
N=int(eval(input()))
ans=0
#each 2L
ans+=(N//2)*min([8*Q,4*H,2*S,D])
#1L
ans+=(N%2)*min([4*Q,2*H,S])
print(ans) | p03617 |
q, h, s, d = list(map(int, input().split()))
n = int(eval(input()))
l = [4 * q, 2 * h, s, d / 2]
ans = 0
if n >= 2:
a = l.index(min(l))
if a == 0:
ans = 4 * q * n
elif a == 1:
ans = 2 * h * n
elif a == 2:
ans = s * n
elif a == 3:
if n % 2 == 0:
ans = n // 2 * d
elif n ... | #-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
def main():
quota,half,single,double = list(map(int,input().split()))
want_icetea=int(eval(input()))
cost_list = [4 * quota, 2 * half, single, double / 2]
ans=0
if want_icetea >= 2:
idx1 = cost_list.index(min(cost_list))
... | p03617 |
cost = list(map(int, input().split()))
size = [1, 2, 4, 8]
N = int(eval(input())) * 4
ans = 0
while N > 0:
min_ = (N // size[0]) * cost[0]
q = 0
for i in range(1,4):
tmp = (N//size[i]) * cost[i]
if tmp < min_ and tmp != 0:
min_ = tmp
q = i
ans += min... | import sys
input = sys.stdin.readline
def main():
Q, H, S, D = list(map(int, input().split()))
N = int(eval(input()))
c1 = min(Q*4, H*2, S)
c2 = min(c1*2, D)
ans = 0
ans += c2 * (N//2)
rest = int(N%2)
ans += c1 * rest
print(ans)
if __name__ == "__main__":
main(... | p03617 |
Q,H,S,D=list(map(int,input().split()))
N=int(eval(input()))
Min1=min(4*Q,2*H,S)
Min2=min(2*Min1,D)
Even=N//2
Odd=N%2
ans=Even*Min2+Odd*Min1
print(ans) | Q,H,S,D=list(map(int,input().split()))
N=int(eval(input()))
N2,N1=divmod(N,2)
tmp2=min(8*Q,4*H,2*S,D)
tmp1=min(4*Q,2*H,S)
ans2=N2*tmp2
ans1=N1*tmp1
ans=ans1+ans2
print(ans)
| p03617 |
q,h,s,d = list(map(int,input().split()))
n = int(eval(input()))
m = min(8*q,4*h,2*s,d)*(n//2) + min(4*q,2*h,s)*(n%2)
print(m) | q,h,s,d=list(map(int,input().split()))
n=int(eval(input()))
m=n//2*min(8*q,4*h,2*s,d)+n%2*min(4*q,2*h,s)
print(m) | p03617 |
Q, H, S, D = list(map(int,input().split()))
N = int(eval(input()))
print((min(D,2*S,4*H,8*Q)*(N//2)+min(S,2*H,4*Q)*(N%2)))
| import sys
def input():
return sys.stdin.readline()[:-1]
def main():
Q, H, S, D = list(map(int,input().split()))
N = int(eval(input()))
print(((N//2)*min(Q*8,H*4,S*2,D)+(N%2)*min(Q*4,H*2,S)))
if __name__ == '__main__':
main()
| p03617 |
# -*- coding: utf-8 -*-
q,h,s,d = list(map(int,input().split()))
n = int(eval(input()))
q = 4*q
h = 2*h
if n%2==0:
t = q*n
t = min(t, h*n)
t = min(t, s*n)
t = min(t, d*n//2)
else:
t = q*n
t = min(t, h*n)
t = min(t, s*n)
t = min(t, (n//2)*d + min(q,h,s))
print(t)
| q,h,s,d = list(map(int, input().split()))
n = int(eval(input()))
q = 4*q
h = 2*h
x = min(q,h,s)
print(((n//2)*min(2*x,d)+(n%2)*x)) | p03617 |
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b... | import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b... | p03617 |
Q,H,S,D = list(map(int,input().split()))
N = int(eval(input()))
a2 = min(Q*8,H*4,S*2,D)
ans = (N//2)*a2
a1 = min(Q*4,H*2,S)
ans += (N%2)*a1
print(ans) | Q,H,S,D = list(map(int,input().split()))
N = int(eval(input()))
x2 = min(D,2*S,4*H,8*Q)
cnt = (N//2)*x2
N = N%2
x1 = min(S,2*H,4*Q)
cnt += N*x1
print(cnt) | p03617 |
# AtCoder Grand Contest 019
# A - Ice Tea Store
def f(Q,H,S,D,N,M):
QQ=Q
QH=H/2
QS=S/4
QD=D/8
if N==0:
return M
if N==1:
if QQ==min(QQ,QH,QS):
return M+(4*Q)
if QH==min(QQ,QH,QS):
return M+(2*H)
if QS==min(QQ... | Q,H,S,D=list(map(int,input().split()))
N=int(eval(input()))
one=min (4*Q,2*H,S)
if N==1:
print(one)
else :
if 2*one<=D:
print((N*one))
else:
if N%2==0:
print(((N//2)*D))
else:
print(((N//2)*D+one)) | p03617 |
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
q, h, s, d = list(map(int, readline().split()))
n = int(readline())
h = min(h, q * 2)
s = min(s, h * 2, q * 4)
d = min(d, s * 2, h * 4, q * 8)
cnt = 0
cnt += n // 2 * d
n -= n // 2 * 2
... | import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
ls = list(map(int, readline().split()))
n = int(readline())
ls[1] = min(ls[1], ls[0] * 2)
ls[2] = min(ls[2], ls[1] * 2)
ls[3] = min(ls[3], ls[2] * 2)
t = 0
for i in range(3, -1, -1):
... | p03617 |
Q,H,S,D = list(map(int, input().split()))
N = int(eval(input()))
h = min(Q*2, H)
s = min(h*2, S)
d = min(s*2, D)
ans = (N // 2)*d + (0 if N%2 == 0 else s)
print(ans)
| Q,H,S,D = list(map(int,input().split()))
N = int(eval(input()))
half = min(Q*2,H)
one = min(half*2,S)
doub = min(one*2,D)
ans = (N//2)*doub + (N%2)*one
print(ans) | p03617 |
Q, H, S, D = list(map(int, input().split()))
N = int(eval(input()))
PS = [[Q * 8, 0.25], [H * 4, 0.5], [S * 2, 1], [D, 2]]
PS.sort(key=lambda x: x[0])
R = N
ans = 0
for i in range (4):
if R == 0:
break
elif R >= PS[i][1]:
ans += int(PS[i][0] * PS[i][1] // 2 * (R // PS[i][1]))
... | Q, H, S, D = list(map(int, input().split()))
N = int(eval(input()))
ans = (N//2) * min(8 * Q, 4 * H, S * 2, D) + (N % 2) * min(4 * Q, 2 * H, S)
print(ans) | p03617 |
A="".join(["11000000",
"11"])
B="".join(["10000000",
"10000000",
"10000000",
"1"])
C="".join(["1111"])
D="".join(["01000000",
"11000000",
"1"])
E="".join(["11000000",
"011"])
F="".join(["10000000",
"11000000",... | A="".join(["11000000",
"11"])
B="".join(["10000000",
"10000000",
"10000000",
"1"])
C="".join(["1111"])
D="".join(["01000000",
"11000000",
"1"])
E="".join(["11000000",
"011"])
F="".join(["10000000",
"11000000",... | p00036 |
import re
while True:
try:
s = ''.join([input() for s in range(8)])
print(' C GAE D F B'[len(re.findall('1.*1', s)[0])])
input()
except EOFError:
break | import sys;import re
for s in sys.stdin.read().split('\n\n'):print(' C GAE D F B'[len(re.findall('1.*1', s.replace('\n',''))[0])]) | p00036 |
from functools import reduce
def gcd(v1, v2):
v3 = v1 % v2
if v3 == 0:
return v2
return gcd(v2, v3)
def main():
N = int(eval(input()))
A = [int(v) for v in input().split()]
max_gcd = max(reduce(gcd, A[1:]), reduce(gcd, A[:N-1]))
for i in range(1, N - 1):
... | from functools import reduce
def gcd(v1, v2):
v3 = v1 % v2
if v3 == 0:
return v2
return gcd(v2, v3)
def main():
N = int(eval(input()))
A = [int(v) for v in input().split()]
max_gcd = max(reduce(gcd, A[1:]), reduce(gcd, A[:N-1]))
left = [1] * N
left[0] = A[0... | p03061 |
import sys
from functools import reduce
import sys
input = sys.stdin.readline
n = int(eval(input()))
A = list(map(int, input().split()))
def gcd(a, b):
while (b):
a, b = b, a % b
return a
def gcd_list(numbers):
return reduce(gcd, numbers)
ans = 0
for i in range(n):
ans = max(ans, gcd_lis... | # -*- coding: utf-8 -*-
import sys
from functools import reduce
import sys
input = sys.stdin.readline
n = int(eval(input()))
A = list(map(int, input().split()))
def gcd(a, b):
while (b):
a, b = b, a % b
return a
L = [0] + [None] * (n - 1)
R = [0] + [None] * (n - 1)
for i in range(1, n):
L[i] = ... | p03061 |
n = int(eval(input()))
a = list(map(int, input().split()))
end = sorted(a)[1]
for i in range(end+1, 0, -1):
x = 0
for j in a:
if j % i != 0:
x += 1
if x <= 1:
print(i)
break | n = int(eval(input()))
a = list(map(int, input().split()))
end = sorted(a)[1]
for i in range(end+1, 0, -1):
x = 0
for j in a:
if j % i != 0:
x += 1
if x >= 2:
break
if x <= 1:
print(i)
break | p03061 |
def gcd(m, n):
r = m % n
return n if r == 0 else gcd(n, r)
n = int(eval(input()))
A = list(map(int, input().split()))
if n == 2:
print((max(A)))
exit()
GCD = []
for i in range(n):
A2 = A[:i] + A[i + 1:]
g = gcd(A2[0], A2[1])
for j in range(2, n - 1):
g = gcd(g, A... | def gcd(m, n):
r = m % n
return n if r == 0 else gcd(n, r)
n = int(eval(input()))
A = list(map(int, input().split()))
GCD_left = A[:]
for i in range(1, n):
GCD_left[i] = gcd(GCD_left[i - 1], GCD_left[i])
GCD_right = A[:]
for i in range(n - 2, -1, -1):
GCD_right[i] = gcd(GCD_right[i], GCD... | p03061 |
def gcd(x, y):
while y!=0:
x, y = y, x % y # x,yの大小が逆でも、入れ替わるので、OK
return x
n = int(eval(input()))
a = list(map(int, input().split()))
if n == 2:
print((max(a)))
elif n>=3:
l = [-1] * n
r = [-1] * n
l[0] = a[0] #一番左を左に挿入
r[-1] = a[-1] #一番右を右に挿入
# print(l)
# print... | def gcd(x, y):
while y!=0:
x, y = y, x % y # x,yの大小が逆でも、入れ替わるので、OK
return x
n = int(eval(input()))
a = list(map(int, input().split()))
if n == 2:
print((max(a)))
elif n>=3:
l = [-1] * n
r = [-1] * n
l[0] = a[0] #一番左を左に挿入
r[-1] = a[-1] #一番右を右に挿入
# print(l)
# print... | p03061 |
import math
from functools import reduce
def gcd(list):
return reduce(math.gcd, list)
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n):
ans = max(ans, gcd(a[:i]+a[i+1:]))
print(ans) | from math import *
n = int(eval(input()))
a = list(map(int, input().split()))
l = [a[0]]
for i in range(1, n-1):
l.append(gcd(a[i], l[i-1]))
ans = l[n-2]
r = a[n-1]
for i in range(n-2,0,-1):
r = gcd(r, a[i+1])
ans = max(ans, gcd(l[i-1], r))
ans = max(ans, gcd(r,a[1]))
print(ans) | p03061 |
from functools import reduce
def gcd(a,b):
x = max([a,b])
y = min([a,b])
while y:
x, y = y, x % y
return x
def gcd_list(nums):
return reduce(gcd, nums)
n = int(eval(input()))
a = list(map(int,input().split()))
ans = 0
for i in range(n):
tmp_list = a[:i] + (a[i+1:])
... | N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(a,b):
x = max([a,b])
y = min([a,b])
while y:
x, y = y, x % y
return x
L = [0]
R = [0]
for i in range(N):
L.append(gcd(L[-1], A[i]))
for i in reversed(list(range(N))):
R.append(gcd(R[-1], A[i]))
R = list(... | p03061 |
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
if N == 2:
print((max(A)))
exit()
result = []
num = 0
for a in A[1:]:
if a % A[0] != 0:
num += 1
if num == 2:
break
else:
result.append(A[0])
for n in range(A[0], 0, -1):
if A[0] % n != 0:
... | import math
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
if N == 2:
print((max(A)))
exit()
result = []
num = 0
for a in A[1:]:
if a % A[0] != 0:
num += 1
if num == 2:
break
else:
result.append(A[0])
for n in range(2, int(math.sqrt(A[0])) +... | p03061 |
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
# from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
import math
# from ite... | # coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
# from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
import math
# from ite... | p03061 |
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 27 20:57:32 2019
@author: Yamazaki Kenichi
"""
N = int(eval(input()))
A = list(map(int,input().split()))
def eg(x,y):
if y == 0:
return x
x, y = y, x%y
return eg(x,y)
T = [[1,1,1] for i in range(N)]
T[0][0],T[0][1],T[0][2] = A[0], 0... | # -*- coding: utf-8 -*-
"""
Created on Sun Apr 28 15:46:33 2019
@author: Yamazaki Kenichi
"""
N = int(eval(input()))
A = list(map(int,input().split()))
def eg(x,y):
if y == 0:
return x
x, y = y, x%y
return eg(x,y)
L, R = [0 for i in range(N)],[0 for i in range(N)]
L[0], R[N-1] ... | p03061 |
n = int(eval(input()))
a = []
for x in input().split():
a.append(int(x))
ans = []
def gcd(a, b):
while b:
a, b = b, a % b
return a
def gcd_list(numbers):
element = gcd(numbers[0], numbers[1])
if len(numbers)==2:
return element
else:
for i in range(2, l... | def gcd(x,y):
if x<y:
x,y=y,x
#x>y
if y==0:
return x
if x%y==0:
return y
else:
return gcd(y,x%y)
N=int(eval(input()))
A=[int(i) for i in input().split()]
X=[0 for i in range(N)]
Y=[0 for i in range(N)]
for i in range(1,N):
X[i]=gcd(X[i-1],A[i-1])
... | p03061 |
def gcd(a,b):
if b == 0:
return 0
elif a%b == 0:
return b
else:
return gcd(b,a%b)
N = int(eval(input()))
A = list(map(int, input().split()))
GCDs = []
for n in range(N):
B = A + []
trash = B.pop(n)
GCD = B[0]
for b in B:
GCD = gcd(GCD, b)
... | def gcd(a,b):
if b == 0:
return a
else:
return gcd(b, a%b)
N = int(eval(input()))
A = list(map(int, input().split()))
L = [0]
R = [0]
for n in range(N-1):
L.append(gcd(L[-1],A[n]))
R.append(gcd(R[-1],A[N-n-1]))
GCDs = []
for n in range(N):
GCDs.append(gcd(L[n]... | p03061 |
from typing import Callable, List, Optional, Union
T = Union[int, str]
class SegmentTree:
"""Segment Tree"""
__slots__ = ["e", "op", "modifying_op", "_n", "_size", "tree"]
def __init__(
self,
a: List[T],
e: T,
op: Callable[[T, T], T],
modifying_op:... | from typing import Callable, Iterator, Optional, TypeVar
S = TypeVar("S")
class SegmentTree:
"""Segment Tree
References:
https://github.com/atcoder/ac-library/blob/master/atcoder/segtree.hpp
"""
__slots__ = ["_e", "_op", "_n", "_size", "_tree"]
def __init__(
self,
... | p03061 |
from functools import reduce
def gcd(a, b):
l = max(a, b)
s = min(a, b)
if s == 0:
return l
else:
return gcd(s, l%s)
n = int(eval(input()))
As = list(map(int, input().split(" ")))
largest = 0
for i in range(n):
largest = max(largest, gcd(reduce(gcd, As[:i], 0), reduce(gcd, As[i+1:], 0)))... | def gcd(a, b):
l = max(a, b)
s = min(a, b)
if s == 0:
return l
else:
return gcd(s, l%s)
n = int(eval(input()))
A = [0] + list(map(int, input().split())) + [0]
largest = 0
L = [0 for _ in range(n+2)]
R = [0 for _ in range(n+2)]
for i in range(1, n+2):
L[i] = gcd(A[i], L[i-1])
R[n-i+1]... | p03061 |
import sys
sys.setrecursionlimit(10 ** 6)
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def xgcd(a):
size = len(a)
if size == 1:
return a[0]
if size == 2:
return gcd(a[0], a[1])
la = a[:size // 2]
ra = a[size // 2:]
return gcd(x... | def gcd(a, b):
if a == 0:
return b
if b == 0:
return a
return gcd(b % a, a)
n = int(eval(input()))
a = list(map(int, input().split()))
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(n):
b[i + 1] = gcd(b[i], a[i])
c[i + 1] = gcd(c[i], a[-i - 1])
ans = 0
for i... | p03061 |
from functools import reduce
def gcdd(x, y):
x, y = max(x, y), min(x, y)
while y > 0:
r = x % y
x = y
y = r
return x
def gcd(numbers):
return reduce(gcdd, numbers)
n = int(eval(input()))
a = [int(i) for i in input().split()]
b = []
for i in range(n):
d =... | def gcd(x, y):
if x * y == 0:
return (x+y)
x, y = max(x, y), min(x, y)
while y > 0:
r = x % y
x, y = y, r
return x
n = int(eval(input()))
a = [int(i) for i in input().split()]
l_list = [0]
r_list = [0]
for i in range(n):
l = gcd(l_list[i], a[i])
l_list.app... | p03061 |
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
if __name__ == '__main__':
n = int(eval(input()))
a = lis... |
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
if __name__ == '__main__':
n = int(eval(input()))
a = l... | p03061 |
n = int(eval(input()))
a = list(map(int,input().split()))
ans1 = a[1]
for i in range(1,n):
big,sml = a[i],ans1
while sml != 0:
big,sml = sml,big%sml
ans1 = big
ans2 = a[-2]
for i in range(n-1):
big,sml = a[i],ans2
while sml != 0:
big,sml = sml,big%sml
ans2 = big
l1 = [-1]
now = a[0]
... | #14:10
n = int(eval(input()))
a = list(map(int,input().split()))
b = []
for i in range(n):
if i == 0:
b.append(a[i])
else:
big = b[-1]
sml = a[i]
while sml != 0:
big,sml = sml,big%sml
b.append(big)
c = []
for j in range(n)[::-1]:
if j == n-1:
c.append(a[j])
else:
... | p03061 |
n=int(eval(input()))
a=list(map(int,input().split()))
def gcd(a,b):
if a==b:
return a
else:
a,b=max(a,b),min(a,b)
if a%b==0:
return b
else:
return gcd(b,a%b)
def gcd_for_list(L):
if len(L)==1:
return L[0]
for i in range(len(L)):
if i==0:... | n=int(eval(input()))
a=list(map(int,input().split()))
def gcd(a,b):
if a==b:
return a
else:
a,b=max(a,b),min(a,b)
if a%b==0:
return b
else:
return gcd(b,a%b)
R=[]
L=[]
for i in range(n):
if i==0:
L.append(a[i])
R.append(a[-i-1])
else:
vl,... | p03061 |
def gcd(a, b):
if a < b:
a, b = b, a
if b == 0:
return a
c = a % b
return gcd(b, c)
def list_gcd(a):
a_gcd = a[0]
for i in range(n-1):
a_gcd = gcd(a_gcd, a[i+1])
return a_gcd
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
an... | def gcd(a, b):
if a < b:
a, b = b, a
if b == 0:
return a
c = a % b
return gcd(b, c)
n = int(eval(input()))
a = list(map(int, input().split()))
a = [0]+a[:]+[0]
l = [0]*len(a)
r = [0]*len(a)
for i in range(len(a)-1):
m = len(a)-1
l[i+1] = gcd(l[i], a[i+1])
... | p03061 |
#math
def gcd(a, b): #最大公約数
while b:
a, b = b, a % b
return int(a)
def gcd3(lis): #最大公約数(3over)
ans = lis[0]
for li in lis:
ans = gcd(ans,li)
return ans
n = int(eval(input()))
a = list(map(int, input().split()))
maxgcd = 0
for i in range(n):
nums = [a[j] for j in range(n)... |
import sys
def gcd(a, b): #最大公約数
while b:
a, b = b, a % b
return int(a)
n = int(eval(input()))
a = list(map(int, input().split()))
if n==2:
print((max(a)))
sys.exit(0)
elif n==3:
lis = [gcd(a[0], a[1]), gcd(a[1], a[2]), gcd(a[2], a[0])]
print((max(lis)))
sys.exit(0)
tmp... | p03061 |
n = int(eval(input()))
l = list(map(int, input().split()))
def gcd(x,y):
while y:
x, y = y, x%y
return x
ans = 0
for i in range(n):
g = l[0] if i > 0 else l[1]
for j in range(1,n):
if j != i:
g = gcd(g, l[j])
ans = max(ans, g)
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
def gcd(x,y):
while y:
x, y = y, x%y
return x
ll, lr = [0]*n, [0]*n
ll[0], lr[n-1] = a[0], a[n-1]
for i in range(1,n):
ll[i] = gcd(ll[i-1], a[i])
lr[n-i-1] = gcd(lr[n-i], a[n-i-1])
print((max(ll[n-2], lr[1], *[gcd(l,r) for l,r in zi... | p03061 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int, input().split()))
def gcd(x,y):
while y:
x, y = y, x%y
return x
ll, lr = [0]*n, [0]*n
ll[0], lr[n-1] = a[0], a[n-1]
for i in range(1,n):
ll[i] = gcd(ll[i-1], a[i])
lr[n-i-1] = gcd(lr[n-i], a[n-i-1])
print((ma... | n=int(eval(input()))
a=[*list(map(int,input().split()))]
from math import *
l=a.copy()
r=a.copy()
for i in range(n-1):
l[i+1]=gcd(l[i],l[i+1])
r[-i-2]=gcd(r[-i-1],r[-i-2])
a=max(l[-2],r[1])
for i in range(1,n-1):
a=max(a,gcd(l[i-1],r[i+1]))
print(a) | p03061 |
n=int(eval(input()))
a=[*list(map(int,input().split()))]
from math import *
l=a.copy()
r=a.copy()
for i in range(n-1):
l[i+1]=gcd(l[i],l[i+1])
r[-i-2]=gcd(r[-i-1],r[-i-2])
a=max(l[-2],r[1])
for i in range(1,n-1):
a=max(a,gcd(l[i-1],r[i+1]))
print(a) | n=int(eval(input()))
a=[*list(map(int,input().split()))]
from math import *
l,r=[0]*n,[0]*n
for i in range(1,n):
l[i]=gcd(l[i-1],a[i-1])
r[~i]=gcd(r[-i],a[-i])
m=0
for i in range(n):
m=max(m,gcd(l[i],r[i]))
print(m) | p03061 |
n=int(eval(input()))
A=list(map(int,input().split()))
L=[0]*(n+1)
R=[0]*(n+1)
def gcd(a,b):
while b!=0:
a,b=b,a%b
return a
for i in range(n):
L[i+1]=gcd(L[i],A[i])
for i in range(n,0,-1):
R[i-1]=gcd(R[i],A[i-1])
ans=[]
for k in range(n):
ans.append(gcd(L[k],R[k+1]))
print((max... | n=int(eval(input()))
A=list(map(int,input().split()))
def gcd(a,b):
while b!=0:
a,b=b,a%b
return a
L=[0]
R=[0]
for i in range(n):
L.append(gcd(L[i],A[i]))
R.append(gcd(R[i],A[-(i+1)]))
R=R[::-1]
ans=[]
for i in range(n):
ans.append(gcd(L[i],R[i+1]))
print((max(ans)))
| p03061 |
import functools
n = int(eval(input()))
a_list = list(map(int,input().split()))
def gcd(m,n):
x = max(m,n)
y = min(m,n)
if x%y==0:
return y
else:
while x%y!=0:
x,y = y,x%y
return y
res = []
tmp = []
for i in range(n):
if a_list[i] in tmp:
... | n = int(eval(input()))
a_list = list(map(int,input().split()))
def gcd(m,n):
x = max(m,n)
y = min(m,n)
if y==0:
return x
else:
while x%y!=0:
x,y = y,x%y
return y
res = []
l_gcd = [0]*(n+2)
r_gcd = [0]*(n+2)
for i in range(n+1):
if i ==0:
... | p03061 |
n = int(eval(input()))
alist = [int(i) for i in input().split()]
alist.sort()
def calc_gcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
def get_custum(xlist):
prev = None
gcm_list = []
for a in xlist:
if prev is None:
gcm_list.ap... | n = int(eval(input()))
alist = [int(i) for i in input().split()]
def calc_gcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
def listup_gcm(xlist):
list_gcm = []
prev = None
for a in xlist:
if prev is None:
list_gcm.append(a)
... | p03061 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, N, func, I):
self.func = func
self.I = I
self.sz = 2**(N-1).bit_length()
self.seg = [I] * (self.sz * 2)
def assign(self, k, x):
self.seg[k + s... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, N, func, I):
self.func = func
self.I = I
self.sz = 2**(N-1).bit_length()
self.seg = [I] * (self.sz * 2)
def assign(self, k, x):
self.seg[k + s... | p03061 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, N, func, I):
self.func = func
self.I = I
self.N = N
self.sz = 2**(N-1).bit_length()
self.seg = [I] * (self.sz * 2)
def assign(self, k, x):
... | import sys
readline = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, N, func, I):
self.N = N
self.sz = 2**(N-1).bit_length()
self.func = func
self.I = I
self.seg = [I] * (self.sz * 2)
def assign(self, k, x):
self.seg[k + self.sz] =... | p03061 |
import sys
readline = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, N, func, I):
self.N = N
self.sz = 2**(N-1).bit_length()
self.func = func
self.I = I
self.seg = [I] * (self.sz * 2)
def assign(self, k, x):
self.seg[k + self.sz] =... | # test
import sys
readline = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, N, func, I):
self.N = N
self.sz = 2**(N-1).bit_length()
self.func = func
self.I = I
self.seg = [I] * (self.sz * 2)
def assign(self, k, x):
self.seg[k + se... | p03061 |
import sys
readline = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, N, func, I):
self.N = N
self.sz = 2**(N-1).bit_length()
self.func = func
self.I = I
self.seg = [I] * (self.sz * 2)
def assign(self, k, x):
self.seg[k + self.sz] =... | import sys
readline = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, N, func, I):
self.N = N
self.sz = 2**(N-1).bit_length()
self.func = func
self.I = I
self.seg = [I] * (self.sz * 2)
def assign(self, k, x):
self.seg[k + self.sz] =... | p03061 |
# test
import sys
readline = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, N, func, I):
self.N = N
self.sz = 2**(N-1).bit_length()
self.func = func
self.I = I
self.seg = [I] * (self.sz * 2)
def assign(self, k, x):
self.seg[k + ... | import sys
readline = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, N, func, I):
self.N = N
self.sz = 2**(N-1).bit_length()
self.func = func
self.I = I
self.seg = [I] * (self.sz * 2)
def assign(self, k, x):
self.seg[k + self.sz] =... | p03061 |
import sys
readline = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, N, func, I):
self.N = N
self.sz = 2**(N-1).bit_length()
self.func = func
self.I = I
self.seg = [I] * (self.sz * 2)
def assign(self, k, x):
self.seg[k + self.sz] =... | import sys
readline = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, N, func, I):
self.N = N
self.sz = 2**(N-1).bit_length()
self.func = func
self.I = I
self.seg = [I] * (self.sz * 2)
def assign(self, k, x):
self.seg[k + self.sz] =... | p03061 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int,input().split()))
def gcd(a,b):
if b == 0:
return a
return gcd(b,a%b)
ans = 0
B = []
for i in range(N):
b = [A[i],A[i-1]]
B.append(gcd(max(b),min(b)))
for i in range(-1,-N-1,-1):
if N == 2:
... | N = int(eval(input()))
A = list(map(int,input().split()))
def gcd(a,b):
if b == 0:
return a
return gcd(b,a%b)
L,R = [A[0]],[A[-1]]
Lg = A[0]
Rg = A[-1]
for i in range(N-1):
Lg = gcd(Lg,A[i+1])
L.append(Lg)
for i in range(N-1,0,-1):
Rg = gcd(Rg,A[i-1])
R.append(Rg)
L.ap... | p03061 |
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
from math import gcd
class SegTree:
def __init__(self, N, ele):
self.num = 2**(N-1).bit_length()
self.el = ele
self.data = [ele]*(2*self.num)
def calc(self, x, y):
return gcd(x, y)
def update(... | from math import gcd
n = int(eval(input()))
A = [0] + list(map(int, input().split())) + [0]
n += 2
L, R = [0]*n, [0]*n
gl, gr = 0, 0
for i in range(n):
gl = gcd(gl, A[i])
gr = gcd(gr, A[n-i-1])
L[i] = gl
R[n-i-1] = gr
ans = L[-1]
for i in range(n-2):
ans = max(ans, gcd(L[i], R[i+2])... | p03061 |
import functools
import copy
N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
n = 0
if N == 2:
n = max(A)
else:
for i in range(N):
l = copy.copy(A)
l.pop(i)
res = functools.reduce(lambda ... | import functools
import copy
N = int(eval(input()))
A = list(map(int, input().split()))
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
l = [0] * N #L_i, i = 0, 1, 2, ..., N-1
for i in range(N):
if i == 0:
continue
else:
l[i] = gcd(l[i-1], A[i-1])
r =... | p03061 |
import functools
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a%b)
n = int(eval(input()))
a = list(map(int,input().split()))
ans = 1
def f(a,an):
an = max(functools.reduce(gcd, a),an)
return an
for i in range(n):
ans = f(a[:i]+a[i+1:],ans)
print(... | def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a%b)
n = int(eval(input()))
a = list(map(int,input().split()))
b = [a[0]]
c = [a[-1]]
for i in range(1,n):
j = n-1-i
b.append(gcd(b[-1],a[i]))
c.append(gcd(c[-1],a[j]))
ans = max(b[-2],c[-2])
for i i... | p03061 |
N = int(eval(input()))
As = list(map(int,input().split()))
As.sort(reverse=True)
first_d = As[0]
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)
# diviso... | N = int(eval(input()))
As = list(map(int,input().split()))
As.sort(reverse=True)
first_d = As[0]
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)
# diviso... | p03061 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def euclid(a, b):
if b == 0:
return a
else:
return euclid(b, a%b)
def list_euclid(int_list):
ans = int_list[0]
for i in range(1,len(int_list)):
ans = euclid(ans, int_list[i])
if ans == 1:
return ans
r... | #!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def gcd(a, b): #最大公約数
while b:
a, b = b, a % b
return int(a)
n = int(eval(input()))
a = list(map(int, input().split()))
if n==2:
print((max(a)))
sys.exit(0)
elif n==3:
lis = [gcd(a[0], a[1]), gcd(a[1], a[2]), gcd(a[2], a[0])]
prin... | p03061 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def euclid(a, b):
if b == 0:
return a
else:
return euclid(b, a % b)
def list_euclid(int_list):
ans = int_list[0]
if len(int_list) == 1:
return ans
for i in range(1,len(int_list)):
ans = euclid(ans, int_list[i])
... | #!/usr/bin/python3
# -*- coding: utf-8 -*-
def euclid(a, b):
if b == 0:
return a
else:
return euclid(b, a % b)
def list_euclid(int_list):
ans = int_list[0]
if len(int_list) == 1:
return ans
kako_hash = {}
kako_hash[ans] = ans
for i in range(1,len(int_li... | p03061 |
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from... | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from... | p03061 |
def egcd(a, b):
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return a
N=int(eval(input()))
a=list(map(int,input().split()))
l=[0]*N
l[0]=a[0]
for i i... | def gcd(a, b):
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return a
N=int(eval(input()))
a=list(map(int,input().split()))
l=[0]*N
l[0]=a[0]
for i in r... | p03061 |
def gcd(a, b):
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return a
N=int(eval(input()))
a=list(map(int,input().split()))
l=[0]*N
l[0]=a[0]
for i in r... | def gcd(x, y):
if y > x:
x, y = y, x
while y:
x, y = y, x % y
return x
N=int(eval(input()))
a=list(map(int,input().split()))
l=[0]*N
l[0]=a[0]
for i in range(1,N):
l[i]=gcd(l[i-1],a[i])
r=[0]*N
r[N-1]=a[N-1]
for i in range(N-2,-1,-1):
r[i]=gcd(r[i+1],a[i])
ans... | p03061 |
def gcd(x, y):
if y > x:
x, y = y, x
while y:
x, y = y, x % y
return x
N=int(eval(input()))
a=list(map(int,input().split()))
l=[0]*N
l[0]=a[0]
for i in range(1,N):
l[i]=gcd(l[i-1],a[i])
r=[0]*N
r[N-1]=a[N-1]
for i in range(N-2,-1,-1):
r[i]=gcd(r[i+1],a[i])
ans... | def gcd(x, y):
if y > x:
x, y = y, x
while y:
x, y = y, x % y
return x
N=int(eval(input()))
a=list(map(int,input().split()))
l=[0]*N
l[0]=a[0]
for i in range(1,N):
l[i]=gcd(l[i-1],a[i])
r=[0]*N
r[N-1]=a[N-1]
for i in range(N-2,-1,-1):
r[i]=gcd(r[i+1],a[i])
ans... | p03061 |
def gcd(a,b):
if b>a:
a,b=b,a
while b:
a,b=b, a%b
return a
def cul(n,x):
l=len(x)
b=[x[i] for i in range(l)]
b.pop(n)
tmp=b[0]
for i in range(1,l-1):
tmp=gcd(tmp,b[i])
return tmp
import sys
import math
p=100
N=int(eval(input()))
a=list(... | def gcd(a,b):
if b>a:
a,b=b,a
while b:
a,b=b, a%b
return a
def cul(n,x):
l=len(x)
b=[x[i] for i in range(l)]
b.pop(n)
tmp=b[0]
for i in range(1,l-1):
tmp=gcd(tmp,b[i])
return tmp
import sys
import math
p=100
N=int(eval(input()))
a=list(... | p03061 |
def gcd(a,b):
if b>a:
a,b=b,a
while b:
a,b=b, a%b
return a
def cul(n,x):
l=len(x)
b=[x[i] for i in range(l)]
b.pop(n)
tmp=b[0]
for i in range(1,l-1):
tmp=gcd(tmp,b[i])
return tmp
import sys
p=100
N=int(eval(input()))
a=list(map(int,input()... | def gcd(a,b):
if b>a:
a,b=b,a
while b:
a,b=b, a%b
return a
def cul(n,x):
l=len(x)
b=[x[i] for i in range(l)]
b.pop(n)
tmp=b[0]
for i in range(1,l-1):
tmp=gcd(tmp,b[i])
return tmp
import sys
p=50
N=int(eval(input()))
a=list(map(int,input().... | p03061 |
N = int(eval(input()))
nums = [int(i) for i in input().split()]
from functools import reduce
def gcd(a,b):
while b!=0:
a, b = b, a%b
return a
def compute_gcd(numbers):
return reduce(gcd, numbers)
from copy import copy
gcds = []
for i in range(len(nums)):
n = copy(nums)
n.pop(i)
gcd... | N = int(eval(input()))
nums = [int(i) for i in input().split()]
nums_sorted = sorted(list((set(nums))), reverse=True)
def compute_divs(n):
divs = []
if n == 1: return [1]
for i in range(2,int(n**0.5)+1):
if n % i == 0:
divs.append(i)
if i != n // i:
... | p03061 |
def gcd(a, b):
while b > 0:
a, b = b, a % b
return a
N = int(eval(input()))
A = list(map(int, input().split()))
if N == 2:
print((max(A)))
else:
m = -1
for i in range(N):
G = 0
for j in range(0, i):
G = gcd(G, A[j])
for j in range(i+1, N):
G = gcd(G, A[j])
... |
def gcd(a, b):
while b > 0:
a, b = b, a % b
return a
N = int(eval(input()))
A = list(map(int, input().split()))
if N == 2:
print((max(A)))
else:
L = [0 for j in range(N+1)]
R = [0 for j in range(N+1)]
for j in range(N):
L[j+1] = gcd(L[j], A[j])
for j in reversed(list(range(N... | p03061 |
def gcd(m,n):
x = max(m,n)
y = min(m,n)
tmp = x%y
while not tmp == 0:
x = y
y = tmp
tmp = x%y
return y
N = int(eval(input()))
A = list(map(int,input().split()))
gcd_max = 0
for i in range(N):
tmp = A[0]
if i == 0:
tmp = A[1]
for j in rang... | N = int(eval(input()))
A = list(map(int,input().split()))
def GCD(x,y):
while y != 0:
x,y = y,x%y
return x
l,r = [0],[0]
for i in range(N-1):
l.append(GCD(l[-1],A[i]))
r.append(GCD(r[-1],A[N-i-1]))
ans = 0
for i in range(N):
ans = max(ans,GCD(l[i],r[N-i-1]))
print(ans)
| p03061 |
from functools import reduce
result = 0
def gcd(a,b):
if b==0:return a
return gcd(b,a%b)
n = int(eval(input()))
A = list(map(int, input().split()))
for i in range(n):
result = max(result, reduce(gcd, A[:i]+A[i+1:]))
print(result) | from functools import reduce
result = 0
def gcd(a,b):
if b==0:return a
return gcd(b,a%b)
n = int(eval(input()))
A = list(map(int, input().split()))
X = [0 for i in range(n)]
Y = [0 for i in range(n)]
for i in range(1, n):
X[i] = gcd(X[i-1], A[i-1])
for i in range(n-1)[::-1]:
Y[i] = gcd... | p03061 |
N = int(eval(input()))
A = list(map(int, input().split()))
def factorize(x):
"""xの素因数分解を表す辞書 {素因数: 指数}"""
f = {}
d = 2
while x > 1:
c = 0
while x % d == 0:
c += 1
x //= d
f[d] = c
d += 1
if d * d > x > d:
d = x
... | # math.gcd is introduced in python 3.5
def gcd(a, b):
while b > 0:
a, b = b, a % b
return a
N = int(eval(input()))
A = [int(a) for a in input().split()]
# L[i] = gcd(A[:i + 1])
# R[i] = gcd(A[i:])
L = [0] * N
L[0] = A[0]
for i in range(1, N):
L[i] = gcd(L[i-1], A[i])
R = [0] * N
R[... | p03061 |
def gcd(a,b):
while b:a,b=b,a%b
return a
n=int(eval(input()))
a=list(map(int,input().split()))
if n==2:print((max(a[0],a[1])));exit()
left=[a[0]]
for i in range(1,n):left.append(gcd(left[-1],a[i]))
right=[a[n-1]]
for i in range(n-2,-1,-1):right.append(gcd(right[-1],a[i]))
right.reverse()
ans=max(right[1]... | def gcd(a,b):
while b:a,b=b,a%b
return a
n,a=int(eval(input())),list(map(int,input().split()))
if n==2:print((max(a)));exit()
if n==3:print((max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2]))));exit()
ans=ans2=a[0]
for i in range(1,n):
g=gcd(ans,a[i])
if g!=ans:
ans=max(g,ans2)
ans2=gcd(g,ans2... | p03061 |
def GCD(a, b):
""" Euclidean algorithm"""
if a < b: (a, b) = (b, a)
if b == 0: return a
m = a % b
while m != 0:
a = b
b = m
m = a % b
return b
N = int(input())
A = [ int(v) for v in input().split() ]
if N < 2 and 1e5 < N: raise()
for v in A:
if v < 1... | def GCD(a, b):
""" Euclidean algorithm"""
if a < b: (a, b) = (b, a)
if b == 0: return a
m = a % b
while m != 0:
a = b
b = m
m = a % b
return b
N = int(input())
A = [ int(v) for v in input().split() ]
if N < 2 and 1e5 < N: raise()
for v in A:
if v < 1... | p03061 |
def GCD(a, b):
""" Euclidean algorithm"""
if a < b: (a, b) = (b, a)
if b == 0: return a
m = a % b
while m != 0:
a = b
b = m
m = a % b
return b
N = int(input())
A = [ int(v) for v in input().split() ]
if N < 2 and 1e5 < N: raise()
for v in A:
if v < 1... | def GCD(a, b):
""" Euclidean algorithm"""
if a < b: (a, b) = (b, a)
if b == 0: return a
m = a % b
while m != 0:
a = b
b = m
m = a % b
return b
N = int(input())
A = [ int(v) for v in input().split() ]
AR = list(reversed(A))
if N < 2 and 1e5 < N: raise()
f... | p03061 |
def GCD(a, b):
""" Euclidean algorithm"""
if a < b: (a, b) = (b, a)
if b == 0: return a
m = a % b
while m != 0:
a = b
b = m
m = a % b
return b
N = int(input())
A = [ int(v) for v in input().split() ]
AR = list(reversed(A))
if N < 2 and 1e5 < N: raise()
f... | def GCD(a, b):
""" Euclidean algorithm"""
if a < b: (a, b) = (b, a)
if b == 0: return a
m = a % b
while m != 0:
a = b
b = m
m = a % b
return b
N = int(input())
A = [ int(v) for v in input().split() ]
AR = list(reversed(A))
if N < 2 and 1e5 < N: raise()
f... | p03061 |
def GCD(a, b):
""" Euclidean algorithm"""
if a < b: (a, b) = (b, a)
if b == 0: return a
m = a % b
while m != 0:
a = b
b = m
m = a % b
return b
N = int(input())
A = [ int(v) for v in input().split() ]
AR = list(reversed(A))
if N < 2 and 1e5 < N: raise()
f... | def GCD(a, b):
""" Euclidean algorithm"""
if a < b: (a, b) = (b, a)
if b == 0: return a
m = a % b
while m != 0:
a = b
b = m
m = a % b
return b
N = int(input())
A = [ int(v) for v in input().split() ]
AR = list(reversed(A))
if N < 2 and 1e5 < N: raise()
f... | p03061 |
def GCD(a, b):
""" Euclidean algorithm"""
if a < b: (a, b) = (b, a)
if b == 0: return a
m = a % b
while m != 0:
a = b
b = m
m = a % b
return b
N = int(input())
A = [ int(v) for v in input().split() ]
if N < 2 and 1e5 < N: raise()
for v in A:
if v < 1... | def GCD(a, b):
""" Euclidean algorithm"""
if a < b: (a, b) = (b, a)
if b == 0: return a
m = a % b
while m != 0:
a = b
b = m
m = a % b
return b
N = int(input())
A = [ int(v) for v in input().split() ]
if N < 2 and 1e5 < N: raise()
for v in A:
... | p03061 |
def GCD(a, b):
""" Euclidean algorithm"""
if a < b: (a, b) = (b, a)
if b == 0: return a
m = a % b
while m != 0:
a = b
b = m
m = a % b
return b
N = int(input())
A = [ int(v) for v in input().split() ]
if N < 2 and 1e5 < N: raise()
for v in A:
... | def GCD(a, b):
""" Euclidean algorithm"""
if a < b: (a, b) = (b, a)
if b == 0: return a
m = a % b
while m != 0:
a = b
b = m
m = a % b
return b
N = int(input())
A = [ int(v) for v in input().split() ]
if N < 2 and 1e5 < N: raise()
for v in A:
... | p03061 |
from collections import Counter as c
m=int(eval(input()))
a=list(map(int,input().split()))
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
arr=[... | n=int(eval(input()))
a=sorted(list(map(int,input().split())))
i=a[1]
while i > 0:
flg=0
for j in a:
if j%i!=0:
flg+=1
if flg>1:
break
if flg<=1:
print(i)
break
else:
i-=1 | p03061 |
import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {
id(v): k
for k, v in list(inspect.currentframe().f_back.f_locals.items())
}
print(... | import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {
id(v): k
for k, v in list(inspect.currentframe().f_back.f_locals.items())
}
print(... | p03061 |
n = int(eval(input()))
A = list(map(int, input().split()))
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
ans = 0
L = [0]
R = [0]
for i in range(n-1):
l = gcd(L[-1], A[i])
L.append(l)
r = gcd(R[-1], A[::-1][i])
R.append(r)
for l, r in zip(L,R[::-1]):
ans = m... | n = int(eval(input()))
A = list(map(int, input().split()))
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
ans = 0
L = [0]*(n)
R = [0]*(n+1)
for i in range(n-1):
L[i+1] = gcd(L[i], A[i])
R[i+1] = gcd(R[i], A[-i-1])
for l, r in zip(L[::-1],R):
ans = max(ans, gcd(l, r))
... | p03061 |
n = int(eval(input()))
a = [int(m) for m in input().split()]
a.sort()
m0 = a[0]
m1 = a[1]
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.s... | import sys
# import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
# from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
# from itertools import permutations, combinations, product, accumulate, groupby
# from bisect import bise... | p03061 |
n = int(eval(input()))
num_list = list(map(int, input().split()))
num_list.sort()
num_list.reverse()
answer_list = []
max_num = 0
flag = False
for i in range(num_list[0], 0, -1):
if flag and count < 2:
break
else:
flag = True
count = 0
max_num = i
for j in range... | n = int(eval(input()))
a = list(map(int, input().split()))
end = sorted(a)[1]
for i in range(end + 1, 0, -1):
x = 0
for j in a:
if j % i != 0:
x += 1
if x >= 2:
break
if x <= 1:
print(i)
break | p03061 |
n = int(eval(input()))
A = list(map(int,input().split()))
ass = set()
def div(x):
for i in range(1,int(x**0.5)+1):
if x%i == 0:
ass.add(i)
ass.add(x//i)
return ass
a0 = A[0]
a1 = A[1]
div(a0)
div(a1)
ans = []
for i in ass:
cnt = 0
for a in A:
... | import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
n = int(eval(input()))
A = list(map(int,input().split()))
ass = set()
def div(x):
for i in range(1,int(x**0.5)+1):
if x%i == 0:
ass.add(i)
ass.add(x//i)
return ass
... | p03061 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
#a,bの最大公約数
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b,a%b)
#リスト l の最大公約数
def gcdlist(l):
a = l[0]
for i in range(len(l)):
a = gcd(a,l[i])
retu... | #a,bの最大公約数
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b,a%b)
n = int(eval(input()))
a = list(map(int,input().split()))
#b[i]:a[0]~a[i]までのgcd,c[i]:a[i]~a[-1]までのgcd
b = [0]*n
c = [0]*n
for i in range(n):
if i == 0:
b[0] = a[0]
c[-1] = a[-1]
co... | p03061 |
def 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(eval(input()))
A = list(map(int, input().s... | def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def main():
N = int(eval(input()))
A = list(map(int, input().split()))
L = [0]
R = [0]
for i in range(N):
L.append(gcd(L[i], A[i]))
R.append(gcd(R[i], A[N-i-1]))
R.reverse()
M = [gcd(L[i]... | p03061 |
from collections import Counter
def getDivisor(x):
ans = []
for d in range(1, int(x**0.5)+1):
if x % d == 0:
ans.append(d)
if x//d != d:
ans.append(x//d)
return sorted(ans)
N = int(eval(input()))
As = list(map(int, input().split()))
divisors =... | from itertools import accumulate
def gcd(a, b):
while b:
a, b = b, a%b
return a
N = int(eval(input()))
As = list(map(int, input().split()))
Ls = [As[-1]] + list(accumulate(As, gcd))
Rs = list(accumulate(As[::-1], gcd))[::-1] + [As[0]]
ans = 0
for i in range(N):
g = gcd(Ls[i], Rs[i... | p03061 |
def gcd(x, y):
if x > y:
tmp = x
x = y
y = tmp
if x == 0:
return y
else:
return gcd(y%x, x)
N = int(eval(input()))
A = list(map(int, input().split()))
# if N == 2:
# print(max(A[0], A[1]))
# return 0
Llist = [0]
Rlist = [0]
for i in ran... | def gcd(x, y):
if x > y:
tmp = x
x = y
y = tmp
if x == 0:
return y
else:
return gcd(y%x, x)
N = int(eval(input()))
A = list(map(int, input().split()))
Llist = [0]
Rlist = [0]
for i in range(N):
Llist.append(gcd(Llist[i], A[i]))
# Rlist.in... | p03061 |
import copy
n = int(eval(input()))
x = [int(i) for i in input().split()]
#ユークリッド互除法の関数の定義
def gcd(a,b):
if b==0:return a
return gcd(b,a%b)
def gcd_multi(n,x):
if n==1:
return x[0]
else:
element = gcd(x[0], x[1])
if n==2:
return element
else... | import copy
n = int(eval(input()))
x = [int(i) for i in input().split()]
#ユークリッド互除法の関数の定義
def gcd(a,b):
if b==0:return a
return gcd(b,a%b)
def gcd_multi(n,x):
if n==1:
return x[0]
else:
element = gcd(x[0], x[1])
if n==2:
return element
else... | p03061 |
import sys
sys.setrecursionlimit(10**6)
n = int(eval(input()))
a = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in... | """
累積GCD
"""
import sys
sys.setrecursionlimit(10**6)
n = int(eval(input()))
A = list(map(int, input().split()))
from math import gcd
L = [0] * n
R = [0] * n
for i in range(n-1):
L[i+1] = gcd(L[i], A[i])
for i in range(n-1, 0, -1):
R[i-1] = gcd(R[i], A[i])
ans = 0
for i in range(n):
... | p03061 |
def main():
N = int(eval(input()))
A = [int(i) for i in input().split()]
gcd_L = [0]*(N+1)
gcd_R = [0]*(N+1)
def gcd(x, y):
if y == 0:
return x
while y != 0:
x, y = y, x % y
return x
for i, a in enumerate(A):
gcd_L[i+1] = gc... | def main():
N = int(eval(input()))
A = [int(i) for i in input().split()]
gcd_L = [0]*(N+2)
gcd_R = [0]*(N+2)
def gcd(x, y):
if y == 0:
return x
while y != 0:
x, y = y, x % y
return x
for i, a in enumerate(A):
gcd_L[i+1] = gc... | p03061 |
from collections import Counter
N = int(eval(input()))
#約数を列挙
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
A_list = [make_divisors... | from collections import Counter
from functools import lru_cache
N = int(eval(input()))
#約数を列挙
@lru_cache(maxsize=1000)
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.a... | p03061 |
import sys
from functools import reduce
input = sys.stdin.readline
def gcd(a,b):
if b>a:
a, b = b, a
while b:
a, b = b, a%b
return a
def gcds(nums):
return reduce(gcd, nums)
n = int(eval(input()))
a = [int(i) for i in input().split()]
ans = 0
for i in range(len(a)... | import sys
from functools import reduce
input = sys.stdin.readline
def gcd(a,b):
if b>a:
a, b = b, a
while b:
a, b = b, a%b
return a
n = int(eval(input()))
a = [int(i) for i in input().split()]
ans = 0
l = [0]*(n+1)
r = [0]*(n+1)
for i in range(n):
l[i+1] = gcd(l... | p03061 |
# AtCoder Beginner Contest 125
# https://atcoder.jp/contests/abc125
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(... | # AtCoder Beginner Contest 125
# https://atcoder.jp/contests/abc125
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(... | p03061 |
def gcd(x, y):
if y == 0:
return x
else:
return gcd(y, x % y)
def gcd_array(A):
n = len(A)
s = A[0]
i = 1
while(i < n):
s = gcd(s,A[i])
i += 1
return s
if __name__ == "__main__":
N = int(eval(input()))
B = list(map(int,input().split(... | def gcd(x, y):
if y == 0:
return x
else:
return gcd(y, x % y)
def gcd_array(A):
n = len(A)
s = A[0]
i = 1
Down = [0]
while(i < n):
t = gcd(s,A[i])
if t < s:
Down.append(i)
s = t
i += 1
return s,Down
if __nam... | p03061 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.