Harryxun/stf_run huggingface dataset:
n,W=map(int,input().split())
wv=[list(map(int,input().split()))]
w0=wv[0][0]-1
wv[0][0]=1
# すべてのwからw0を引く
for _ in range(n-1):
  w,v=list(map(int,input().split()))
  wv.append([w-w0,v])
import numpy as np
dp=np.full((n+1,301),0,int)
# dp[k][w]:k個で重さwでの最大価値
dp[0]=0
for w,v in wv:
  for i in range(n):
    dp[n-i][w:]=np.maximum(dp[n-i][w:],dp[n-i-1][:-w]+v)
ans=0
for i in range(1,n+1):
  if W-i*w0<=0:break
  ans=max(ans,dp[i][W-i*w0])
print(ans)



### FIXED CODE ###

n,W=map(int,input().split())
wv=[list(map(int,input().split()))]
w0=wv[0][0]-1
wv[0][0]=1
# すべてのwからw0を引く
for _ in range(n-1):
  w,v=list(map(int,input().split()))
  wv.append([w-w0,v])
import numpy as np
dp=np.full((n+1,401),0,int)
# dp[k][w]:k個で重さwでの最大価値
dp[0]=0
for w,v in wv:
  for i in range(n):
    dp[n-i][w:]=np.maximum(dp[n-i][w:],dp[n-i-1][:-w]+v)
ans=0
for i in range(1,n+1):
  if W-i*w0<=0:break
  ans=max(ans,dp[i][min(W-i*w0,400)])
print(ans)
n,q = map(int, input().split())

#=====================================
class Tree():
  def __init__(self, n):
    self.children = []
    self.counter = 0

  def add_child(self, child):
    self.children += [child]
  
  def reconstruct(self, root=None):
    if root in self.children:
      self.children.remove(root)
    for child in self.children:
      child.reconstruct(self)
  
  def add_count(self, x):
    self.counter += x
    for child in self.children:
      child.add_count(x)

#=====================================
      
trees = [Tree(i) for i in range(n)]

ab = [map(int,input().split()) for i in range(n-1)]
for a,b in ab:
  trees[a-1].add_child(trees[b-1])
  trees[b-1].add_child(trees[a-1])

trees[0].reconstruct()

for i in range(q):
  p,x = map(int,input().split())
  trees[p-1].add_count(x)

print(*[trees[i].counter for i in range(n)])

### FIXED CODE ###

N, Q = map(int, input().split())
graph = [[] for i in range(200010)]
ans = [0 for i in range(200010)]
import sys
#sys.setrecursionlimit(100000)
sys.setrecursionlimit(10**7)
#
readline = sys.stdin.readline


for _ in range(N - 1):
    #a, b = map(int, input().split())
    a, b = map(int, readline().split())
    a -= 1
    b -= 1

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    #p, x = map(int, input().split())
    p, x = map(int, readline().split())
    p -= 1

    ans[p] += x

def dfs(node, frm=-1):
    for to in graph[node]:
        if to == frm:
            continue
        ans[to] += ans[node]
        dfs(to, node)
dfs(0)

print(*ans[:N])
N, Y = [int(k) for k in input().split(' ') if k]
Y //= 1000
x = Y // 10
Y -= x * 10
y = Y // 5
Y -= y * 5
z = Y
if N < x + y + z:
	print(-1, -1, -1)
	exit()
checked = []
def find(a, b, c):
	left = 0
	right = len(checked) - 1
	while left != right:
		if checked[left]
def find(nx, ny, nz):
	if nx + ny + nz > N:
		return
	if find(nx, ny, nz):
		return
	if nx + ny + nz == N:
		print(nx, ny, nz)
		exit()
	if nx > 0:
		find(nx - 1, ny + 2, nz)
	if ny > 0:
		find(nx, ny - 1, nz + 5)
	checked.append((nx, ny, nz))
find(x, y, z)
print(-1, -1, -1)

### FIXED CODE ###

N, Y = [int(k) for k in input().split(' ') if k]
Y //= 1000
x = Y // 10
Y -= x * 10
y = Y // 5
Y -= y * 5
z = Y
if N < x + y + z:
	print(-1, -1, -1)
	exit()
d = N - x - y - z
for dx in range(min(d, x) + 1):
	nx = x - dx
	ny = y + 2 * dx
	nd = N - nx - ny - z
	dy = min(nd // 4, ny)
	ny = ny - dy
	nz = z + dy * 5
	if nx + ny + nz == N:
		print(nx, ny, nz)
		exit()
print(-1, -1, -1)
import math
from functools import reduce

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

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

N, X = map(int, input().split())
x = list(map(int, input().split()))
subX = []

for x_i in x:
    subX.append(abs(x_i - X))

print(gcd_list(subX))

### FIXED CODE ###

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

N, X = map(int, input().split())
x = list(map(int, input().split()))
ans = abs(x[0] - X)

for i in range(len(x)):
    ans = gcd(ans, abs(x[i] - X))

print(ans)
#Grid Repainting 2

#初期化
S = []
p = []
flag = True

#入力
H,W = map(int, input().split())
for i in range(W):
	s = input()
	s_list = list(s)
	S.append(s_list)

#計算
for i in range(0, W-1, 1):
	for j in range(1, H-1, 1):
		if S[i][j] == "#" and S[i+1][j] == "." and S[i][j+1] == "."  and S[i-1][j] == "." and S[i][j-1] == "." :
			flag = False
		

#出力
if flag == True:
	print("Yes")

else:
	print("No")

### FIXED CODE ###

#Grid Repainting 2

#初期化
S = []
p = []
flag = True

#入力
H,W = map(int, input().split())
for i in range(H):
	s = input()
	s_list = list(s)
	S.append(s_list)

#計算
for i in range(0, H-1, 1):
	for j in range(0, W-1, 1):
		if S[i][j] == "#" and S[i+1][j] == "." and S[i][j+1] == "."  and S[i-1][j] == "." and S[i][j-1] == "." :
			flag = False
		

#出力
if flag == True:
	print("Yes")

else:
	print("No")
W, H, N = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(N)]
X1, X2, Y1, Y2 = 0, W, 0, H

for x, y, a in P:
    if a == 1:
        X1 = max(X1, x)
    elif a == 2:
        X2 = min(X2, x)
    elif a == 3:
        Y1 = max(Y1, y)
    elif a == 4:
        Y2 = min(Y2, y)
else:

    if X2 <= X1 or Y2 <= Y1:
        print(0)
    else:
        print((X2 - X1) * (Y2 - Y1))


### FIXED CODE ###

[a,b,c]=list(map(int,input().split()))
if a+b==c or a+c==b or b+c==a :
    print("Yes")
else:
    print("No")
from collections import deque

INF = float('inf')

H,W=map(int,input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

## '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for i in range(H):
    for j in range(W):
        if grid[i][j]=="#":
            dist[i][j]=0
            black_cells.append((i,j))

while(black_cells):
    x,y=black_cells.popleft()#黒マスのスタート地点
    d=dist[x][y]#スタート地点からの距離
    for dx,dy in ((0,1),(1,0),(-1,0),(0,-1)):#上下左右の色を塗る
        new_x=x+dx
        new_y=y+dy
        if new_y < 0 or H <= new_y or new_x < 0 or W <= new_x:#範囲からはみ出すとき
            continue
        elif dist[new_x][new_y]==-1:
            dist[new_x][new_y]=d+1
            black_cells.append((new_x,new_y))
print(d)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

def bfs(black_cells, dist):
    """
    BFSを用いて、全マス目を黒くする回数を求める

    Args:
        black_cells: 「開始時の黒マス」の座標が入ったキュー（複数座標あり）
        dist: 「開始時の黒マス」からの距離の入ったリスト  [[-1, -1, 0], ...]
        　　　（白マスの初期値は0）

    Returns:
        g: 操作を繰り返した数
    """
    d = 0
    while black_cells:
        # キューとして使うのでpop()ではなくpopleft()
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N=int(input())
strings=[sorted(input()) for a in range(N)]
strings.sort()
sums=0
sorteds=strings
for st in list(set(sorteds)):
    n=sorteds.count(st)
    if n!=1:
       sums=sums+combinations_count(n,2)

print(sums)



### FIXED CODE ###

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

N=int(input())
strings=[str(sorted(input())) for a in range(N)]
c=collections.Counter(strings)
tp=c.most_common()
sums=0
for thing in tp:
    if thing[1]!=1:
        sums=sums+combinations_count(thing[1],2)
    else:break

print(sums)
S = input()+'T'
X,Y = map(int,input().split())

xmove = []
ymove = []

tmp = 0
flag = True
for i in range(len(S)):
    if S[i]=='F':
        tmp += 1
    elif flag and S[i]=='T':
        xmove.append(tmp*2)
        tmp = 0
        flag = False
    else:
        ymove.append(tmp*2)
        tmp = 0
        flag = True
        
if xmove:
    x0 = xmove.pop(0)//2
else:
    x0 = 0

xgoal = sum(xmove)//2+X-x0
ygoal = sum(ymove)//2+Y

def subsetsum(arr,s):
    if not arr:
        if s==0:
            return True
        else:
            return False
    dp = [[0 for j in range(s+1)] for i in range(len(arr)+1)]
    dp[0][0] = 1
    for i in range(1,len(arr)+1):
        for j in range(s+1):
            if j-arr[i-1]>=0:
                dp[i][j] = (dp[i-1][j-arr[i-1]] | dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]
    return dp[-1][s]
    
if subsetsum(xmove,xgoal) and subsetsum(ymove,ygoal):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

S = input()+'T'
X,Y = map(int,input().split())

xmove = []
ymove = []

tmp = 0
flag = True
for i in range(len(S)):
    if S[i]=='F':
        tmp += 1
    elif flag and S[i]=='T':
        xmove.append(tmp*2)
        tmp = 0
        flag = False
    else:
        ymove.append(tmp*2)
        tmp = 0
        flag = True
        
if xmove:
    x0 = xmove.pop(0)//2
else:
    x0 = 0

xgoal = sum(xmove)//2+X-x0
ygoal = sum(ymove)//2+Y

def subsetsum(arr,s):
    if not arr or s < 0:
        if s==0:
            return True
        else:
            return False
    dp = [[0 for j in range(s+1)] for i in range(len(arr)+1)]
    dp[0][0] = 1
    for i in range(1,len(arr)+1):
        for j in range(s+1):
            if j-arr[i-1]>=0:
                dp[i][j] = (dp[i-1][j-arr[i-1]] | dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]
    return dp[-1][s]
    
if subsetsum(xmove,xgoal) and subsetsum(ymove,ygoal):
    print('Yes')
else:
    print('No')
N = int(input())
a_i = []
for i in range(N):
    a_i.append(int(input()))

x = []
y = []

if N%2==0:
    for j in range(int(N/2)):
        x.append(max(a_i))
        a_i.remove(max(a_i))
        y.append(max(a_i))
        a_i.remove(max(a_i))

else:
    for j in range(int((N/2)+1)):
        x.append(max(a_i))
        a_i.remove(max(a_i))
        if a_i == []:
            break
        y.append(max(a_i))
        a_i.remove(max(a_i))

X = sum(x)
Y = sum(y)


if X >= Y:
    print(X - Y)

else:
    print(Y - X)

### FIXED CODE ###

N = int(input())
a_i = list(map(int, input().split(" ")))
 
x = []
y = []
 
if N%2==0:
    for j in range(int(N/2)):
        x.append(max(a_i))
        a_i.remove(max(a_i))
        y.append(max(a_i))
        a_i.remove(max(a_i))
 
else:
    for j in range(int((N/2)+1)):
        x.append(max(a_i))
        a_i.remove(max(a_i))
        if a_i == []:
            break
        y.append(max(a_i))
        a_i.remove(max(a_i))
 
X = sum(x)
Y = sum(y)
 
 
if X >= Y:
    print(X - Y)
 
else:
    print(Y - X)
import numpy as np

h,w = map(int,(input().split()))
s = [list(map(str,input())) for i in range(h)]
l = [[0]*(w+2) for i in range(h+2)]


def addFlag(i,j):
    for x in range(3):
        for y in range(3):
            if l[i+x][j+y] != '#':
                l[i+x][j+y] += 1
                
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i+1][j+1] = '#'
            addFlag(i,j)

l = np.delete(l,[0,h+1],0)
l = np.delete(l,[0,w+1],1)

for i in l:
    if len(i)>1:
        ans = ''.join(i)
    else:
        ans = print(*i)
    print(ans)


### FIXED CODE ###

import numpy as np

h,w = map(int,(input().split()))
s = [list(map(str,input())) for i in range(h)]
l = [[0]*(w+2) for i in range(h+2)]


def addFlag(i,j):
    for x in range(3):
        for y in range(3):
            if l[i+x][j+y] != '#':
                l[i+x][j+y] += 1
                
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i+1][j+1] = '#'
            addFlag(i,j)

l = np.delete(l,[0,h+1],0)
l = np.delete(l,[0,w+1],1)


for i in l:
    ans = ''.join(map(str,i))
    print(ans)
n=int(input())
for i in range(int(n**0.5)+3):
	if i**2+i>=2*n:
		p=i
		break
total=(p*(p+1))//2
for i in range(1,p+1):
	if total-n!=i:
		print(i)

### FIXED CODE ###

n=int(input())
for i in range(n+1):
	if i**2+i>=2*n:
		p=i
		break
total=(p*(p+1))//2
for i in range(1,p+1):
	if total-n!=i:
		print(i)
n = int(input())
a = []
ans = 0
for i in range(n):
  a.appen(int(input())
print(a)         n = int(input())
a = list(map(int,input().split()))
ans1 = 0
for i in range(n - 1):
    if a[i] >= a[i+1]:
        ans1 += 1
    else:
        ans1 = 0
print(ans1)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
temp = 0
ans = 0
for i in range(n - 1):
    if a[i] >= a[i+1]:
        temp +=1
        ans = max(ans,temp)
    else:
        temp = 0
print(ans)
"""
task statement
==============

H \times W マスの二次元グリッドがあります。この中には M 個の爆破対象があります。 i 個目の爆破対象の位置は \left(h_i, w_i \right)です。
高橋君は 1 つのマスを選び、そのマスに爆弾を設置し、起爆します。爆弾と同じ行または同じ列に存在する爆破対象が爆破されます。爆破対象が存在するマスに爆弾を設置することも出来ます。
高橋君は、爆破する爆破対象の数を最大化しようとしています。最大でいくつの爆破対象を爆破出来るか答えてください。

io_style
-------
H W M
h_1 w_1
\vdots
h_M w_M
"""
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


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


def main():
    h, w, m = [int(i) for i in input().split()]
    d_h = defaultdict(int)
    d_w = defaultdict(int)
    bom = set()
    for _ in range(m):
        h, w = [int(i) for i in input().split()]
        bom.add((h, w))
        d_h[h] += 1
        d_w[w] += 1
    H = sorted(d_h.items(), key=lambda x: -x[1])
    W = sorted(d_w.items(), key=lambda x: -x[1])
    ans = H[0][1] + W[0][1]
    if (H[0][0], W[0][0]) in bom:
        ans -= 1

    ans2 = H[1][1] + W[0][1]
    if (H[1][0], W[0][0]) in bom:
        ans2 -= 1
    ans3 = H[0][1] + W[1][1]
    if (H[0][0], W[1][0]) in bom:
        ans3 -= 1

    print(max(ans, ans2, ans3))

    return


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


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


def main():
    h, w, m = [int(i) for i in input().split()]
    d_h = defaultdict(int)
    d_w = defaultdict(int)
    bom = set()
    for _ in range(m):
        h, w = [int(i) for i in input().split()]
        bom.add((h, w))
        d_h[h] += 1
        d_w[w] += 1
    H = sorted(d_h.items(), key=lambda x: -x[1])
    W = sorted(d_w.items(), key=lambda x: -x[1])
    ans = 0
    for k_h, v_h in H:
        for k_w, v_w in W:
            tmp = v_h + v_w
            if (k_h, k_w) in bom:
                tmp -= 1
                ans = max(tmp, ans)
            else:
                ans = max(tmp, ans)
                break
        else:
            continue
        break

    for k_w, v_w in W:
        for k_h, v_h in H:
            tmp = v_h + v_w
            if (k_h, k_w) in bom:
                tmp -= 1
                ans = max(tmp, ans)
            else:
                ans = max(tmp, ans)
                break
        else:
            continue
        break
    print(ans)


if __name__ == "__main__":
    main()
N,X,D=map(int,input().split())
M=10**8
D+=(D==0)*M**3
f,c,r={},[0]*M,0
for x,y,z in sorted((((N-k)*j+~-k)*k//2+k*X//D,j,k*X%D)for k in range(N+1)for j in[0,2]):
 x=x*(D<M**3)
 if c[z]+y<1:
  f[z]=x
 r+=(x-f[z]+1)*(c[z]<y)
 c[z]-=y-1
print(r)

### FIXED CODE ###

N, X, D = map(int, input().split())
if D == 0:
    r = N+1
    if X == 0:
        r = 1
    print(r)
else:
    if D < 0:
        X, D = -X, -D
    d = dict()
    for k in range(N+1):
        M = (k*X) % D
        F = (k*X)//D + ((k-1)*k)//2 #(1..k-1)
        L = (k*X)//D + (2*N-k-1)*k//2# (N-k..N-1)
        if M not in d:
            d[M] = list()
        d[M].append((F, 0))
        d[M].append((L, 1))
    r = 0
    for m in d:
        d[m] = sorted(d[m])
        fc = 0
        f = 0
        for x in d[m]:
            if not x[1]:
                fc += 1
                if fc == 1:
                    f = x[0]
            if x[1]:
                fc -= 1
                if fc == 0:
                    r += x[0] - f + 1
    print(r)
import math
while True:
	x = map(int,raw_input().split(' '))
	a =int( math.log10(x[0] + x[1]) + 1)
	if a <=1000000 :
		print a
		continue
	else:
		break

### FIXED CODE ###

while True:
	try:
		a,b = map(int,raw_input().split(' '))
		print len(str(a+b))
	except: break
n=int(input())
l=sorted(list(map(int,input().split())))
import bisect
count=0
for i in range(n-1):
  for j in range(1,n):
    if i==j:
      pass
    else:
      left=bisect.bisect_left(abs(l[i]-l[j]))
      right=bisect.bisect_right(l[i]+l[j])
      count+=right-left
print(count)                             

### FIXED CODE ###

import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
count=0
for i in range(n-2):
  for j in range(i+1,n-1):
    index=bisect.bisect_left(l,l[i]+l[j])
    count+=index-j-1
print(count)
N, K = map(int, input().split())
A = list(map(int, input().split()))

visited = {1: 0}
index = 0
last = 1

for i in range(K):
    t = A[last - 1]
    index += 1
    if t in visited:
        z = K - i - 1
        l = index - visited[t]
        print([k for k, v in visited.items() if v == visited[t] + (z % l)][0])
        exit()
    else:
        visited[t] = index
        last = t

print(visited[-1])



### FIXED CODE ###

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

visited = {1: 0}
index = 0
last = 1

for i in range(K):
    t = A[last - 1]
    index += 1
    if t in visited:
        z = K - i - 1
        l = index - visited[t]
        print([k for k, v in visited.items() if v == visited[t] + (z % l)][0])
        exit()
    else:
        visited[t] = index
        last = t

print(last)
n = int(input())
s = input().split()
s_i = [int(d) for d in s]
cnt = [0]
cn = 0
r = 1
d = n-1
for a in range(1,n-1):
    while s_i[d-1] >= s_i[d]:
        cn = cn + 1
        d = d-1
    if cn != 0:
        cnt.extend([cn])
        r = r + 1
    cn = 0
    d = d -1

max = cnt[0]
while cn < r:
    if max < cnt[cn]:
        max = cnt[cn]
    cn = cn + 1

print(max)

### FIXED CODE ###

### INPUT
N = int(input())
A = list(map(int,input().split()))
cont = 0
b = N-1
MAX = 0
### MAIN
for i in range(b):
    if A[i]>=A[i+1] :
        cont = cont + 1
    else:
        cont = 0

    if cont > MAX:
        MAX = cont
### OUT
print(MAX)
'''input
3
1 2 2
2 3 1
'''
import sys
sys.setrecursionlimit(100100)
N = int(input())

edges = [[] for i in range(N)]

for i in range(N-1):
	a, b, w = [int(x) for x in input().split()]
	a -= 1
	b -= 1
	edges[a].append((b, w))
	edges[b].append((a, w))


color = [None]*N

color[0] = 0

def dfs(curr, prev):
	for i in edges[curr]:
		if i[0] == prev: continue

		if i[1] % 2 == 0: color[i[0]] = color[curr]
		else: color[i[0]] = 1 - color[curr]

		dfs(i[0], curr)

dfs(0, -1)

for i in color:
	print(i)

### FIXED CODE ###

'''input
3
1 2 2
2 3 1
'''
import sys
sys.setrecursionlimit(100100)
N = int(input())

edges = [[] for i in range(N)]

for i in range(N-1):
	a, b, w = [int(x) for x in input().split()]
	a -= 1
	b -= 1
	edges[a].append((b, w))
	edges[b].append((a, w))


color = [None]*N

color[0] = 0

def dfs(curr, prev):
	for i in edges[curr]:
		if i[0] == prev: continue

		if i[1] % 2 == 0: color[i[0]] = color[curr]
		else: color[i[0]] = 1 - color[curr]

		dfs(i[0], curr)

dfs(0, -1)

for i in color:
	print(i)
import sys
     
data = []
     
for l in sys.stdin:
    data.append(str(l))
       
last = int(data[0][-1])
     
if last in [2,4,5,7,9]:
  print('hon')
elif last in [0,1,6,8]:
  print('pon')
else:
  print('hon')

### FIXED CODE ###

last = int(input()[-1])
     
if last in [2,4,5,7,9]:
  print('hon')
elif last in [0,1,6,8]:
  print('pon')
else:
  print('bon')
import math
import copy
from functools import reduce
from fractions import gcd

N = int(input())
nums = [int(i) for i in input().split()]
nums2 = copy.copy(nums)
ans = []

def gcds(numlist):
    return reduce(math.gcd, numlist)


for i in range(N):
   nums.pop(i)
   ans.append(gcds(nums))
   nums = copy.copy(nums2)

print(max(ans))


### FIXED CODE ###

from fractions import gcd

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

fort = [nums[0], gcd(nums[0], nums[1])]
back = [nums[N-1], gcd(nums[N-1], nums[N-2])]
ans = []

for i in range(N-2):
    fort.append(gcd(fort[i+1], nums[i+2]))
                
for i in range(N-2):
    back.append(gcd(back[i+1], nums[N-(i+3)]))
    
for i in range(1, N-1):
    ans.append(gcd(fort[i-1], back[N-2-i]))

ans.append(fort[N-2])
ans.append(back[N-2])

print(max(ans))
r, g, b, n = map(int, input().split())
ans = 0
for r_num in range(math.floor(n/r)+1):
    for g_num in range(math.floor(math.floor(n - r*r_num)/g)+1):
        if ((n - (r_num * r) - (g_num * g)) % b == 0):
            ans += 1
print(ans)

### FIXED CODE ###

import math
r, g, b, n = map(int, input().split())
ans = 0
for r_num in range(math.floor(n/r)+1):
    for g_num in range(math.floor(math.floor(n - r*r_num)/g)+1):
        if ((n - (r_num * r) - (g_num * g)) % b == 0):
            ans += 1
print(ans)
N,Q=map(int,input().split())
a=[0 for i in range(N-1)]
b=[0 for i in range(N-1)]
p=[0 for i in range(N-1)]
q=[0 for i in range(N-1)]
for i in range(N-1):
  a[i],b[i]=map(int,input().split())
for i in range(Q):
  p[i],q[i]=map(int,input().split())
#print(N,Q)
#print(a)
#print(b)
#print(p)
#print(q)

c=list(zip(a,b))
c.sort()
a,b=list(zip(*c))

K=[0 for i in range(N)]
for i in range(N-1):
  K[p[i]-1]+=q[i]
#print(K)

#for i in range(N-1):
#  K[b[i]-1]+=K[a[i]-1]
#print(K)

print(" ".join(map(str,K)))

### FIXED CODE ###

import collections

N,Q=map(int,input().split())
M=[[] for i in range(N+1)]
P=[0 for i in range(N+1)]
for i in range(N-1):
  a,b=map(int,input().split())
  M[a].append(b)
  M[b].append(a)
#print("M:",M)

S=[0 for i in range(N+1)]
for i in range(Q):
  p,x=map(int,input().split())
  S[p]+=x
#print(S)
  
d=collections.deque([1])

while len(d):
  dd=d.popleft()
  if P[dd]==0:
    P[dd]=1
    for i in M[dd]:
      if P[i]==0:
        S[i]+=S[dd]
      d.append(i)
  #print(d,S)
print(*S[1:])
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
bag = set()

spot = 1
road = []
for _ in range(K):
    if not spot in bag:
        road.append(spot)
        bag.add(spot)
        spot = A[spot-1]
    else:
        break

# print(road)
till_loop = road.index(spot)
# print(till_loop)
loop = road[till_loop:]
# print(loop)
cycle_len = len(road) - road.index(spot)
# print(cycle_len)
answer = loop[(K-till_loop) % cycle_len]

print(answer)


### FIXED CODE ###

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
tmp = [0 for _ in range(N)]
# bagに入る要素が多すぎてエラーが出ている

spot = 1
road = [1]
tmp[0] = 1
for _ in range(K):
    n_s = A[spot-1]
    if not tmp[n_s-1] == 1:
        road.append(n_s)
        tmp[n_s-1] = 1
        spot = n_s
    else:
        spot = n_s
        break

till_loop = road.index(spot)
# print(till_loop)
loop = road[till_loop:]
# print(loop)
cycle_len = len(road) - road.index(spot)
# print(cycle_len)
answer = loop[(K-till_loop) % cycle_len]

print(answer)
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a, b, c, d = map(int, input().split())
cd = lcm(c, d)
num = b - a + 1

if a <= cd <= b:
    cd_count = (b // cd) - (a // cd)
else:
    cd_count = 0

if a % c == 0:
    c_count = (b // c) - (a // c) + 1
else:
    c_count = (b // c) - (a // c)
if a % d == 0:
    d_count = (b // d) - (a // d) + 1
else:
    d_count = (b // d) - (a // d)

ans = num - c_count - d_count + cd_count

print(ans)

### FIXED CODE ###

import fractions

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

a, b, c, d = map(int, input().split())
a -= 1
cd = lcm(c, d)

upper = b - b//c - b//d + b//cd
lower = a - a//c - a//d + a//cd
ans = upper - lower

print(ans)