Harryxun/stf_run huggingface dataset:
# print('input >>')
N, M = map(int,(input().split()))
ABs = [map(int,(input().split())) for _ in range(M)]

INF = 10 ** 10
ds = [0] * (N+1)
marks = [0] * (N+1)

nodes = [None] * (N+1)

for AB in ABs:
    A, B = AB
    if nodes[A] is None:
        nodes[A] = []
    nodes[A].append(B)

    B, A = A, B
    if nodes[A] is None:
        nodes[A] = []
    nodes[A].append(B)

# print(nodes)

checked = [0] * (N+1) 

def dfs(cur, parent, children):
    # print(parent, children)
    if checked[parent] == 1:
        return
    checked[parent] = 1
    for child in children:
        # print(parent, cur, ds)
        if marks[child] == 0 or ds[child] < cur:
            marks[child] = parent
            ds[child] = cur
            # print(marks)
        # if not checked[child] == 0:
        dfs(cur+1, child, nodes[child])

dfs(0, 1, nodes[1])

# print('-----output-----')
print('Yes')
for mark in marks[2:]:
    print(mark)

"""
7 7
1 2
2 5
5 7
3 1
7 3
6 1
2 4
"""

### FIXED CODE ###

from collections import deque

# print('input >>')
N, M = map(int,(input().split()))
ABs = [map(int,(input().split())) for _ in range(M)]

INF = 10 ** 10
ds = [INF] * (N+1)
marks = [0] * (N+1)

nodes = [None] * (N+1)

for AB in ABs:
    A, B = AB
    if nodes[A] is None:
        nodes[A] = []
    nodes[A].append(B)

    B, A = A, B
    if nodes[A] is None:
        nodes[A] = []
    nodes[A].append(B)

# print(nodes)

queue = deque([1])
visited = [0] * (N+1)
visited[1] = 1

# d = 0
# ds = [INF] * (N+1)
marks = [0] * (N+1)
parent = 1

while len(queue) > 0:
    p = queue.popleft()
    # print(p)
    # parent, node = p[0], p[1]
    # visited[node] = 1
    # marks[node] = parent
    for n in nodes[p]:
        if visited[n] == 0:
            visited[n] = 1
            marks[n] = p
            queue.append(n)

print('Yes')
for mark in marks[2:]:
    print(mark)
#!/usr/bin/env python

dn = lambda a, b: len(str(a+b))
get = lambda : [int (x) for x in raw_input().split()]

if __name__ == "__main__":
    while True:
        print "%d\n" % dn(*get()),

### FIXED CODE ###

#!/usr/bin/env python

dn = lambda a, b: len(str(a+b))
get = lambda: [int(x) for x in raw_input().split()]

if __name__ == "__main__":
    while True:
        try:
            print "%d" % dn(*get())
        except EOFError:
            break
n = int(input())
k = int(input())
x = int(input())
y = int(input())
ans = 0
for i in range(1:n):
    if i =< k:
        ans += x
    else:
        ans += y
print(ans)

### FIXED CODE ###

n = int(input())
k = int(input())
x = int(input())
y = int(input())
ans = 0
for i in range(1,n+1):
    if i <= k:
        ans += x
    else:
        ans += y
print(ans)
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a ,b;
    b="yes";
    cin>>a;
    for (int i=0;i<a.size();i++){
        for (int j=i+1;j<a.size();j++){
            if(a.at(i)==a.at(j)){
                b="no";
                break;
            }
        }
    }
    cout<<b<<endl;
	return 0;
}


### FIXED CODE ###

a=input()
b=set(a)
c=list(a)
print(["no","yes"][len(b)==len(c)])
# 最大公約数なきがするけど。
def gcd(n, m):
    # 最大公約数
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a

N, X = map(int,input().split())
xs = [int(i) for i in input().split()]
xs.append(X)
xs = sorted(xs)
diffs = [xs[i]-xs[i-1] for i in range(1,len(xs))] #差を取る
gcd_min = gcd(diffs[0],diffs[1])
for i in range(2,len(diffs)):
    gcd_min = gcd(gcd_min, diffs[i])

print(gcd_min)

### FIXED CODE ###

# 最大公約数なきがするけど。
def gcd(n, m):
    # 最大公約数
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a

N, X = map(int,input().split())
xs = [int(i) for i in input().split()]

xs.append(X)
xs = sorted(xs)
if len(xs) == 2:
    print(abs(xs[0]-xs[1]))
else:
    diffs = [xs[i]-xs[i-1] for i in range(1,len(xs))] #差を取る
    gcd_min = gcd(diffs[0],diffs[1])
    for i in range(2,len(diffs)):
        gcd_min = gcd(gcd_min, diffs[i])

    print(gcd_min)
import numpy

H,W = map(int,input().split())
INF = H * W
S = numpy.array([[INF if i == '.' else 0 for i in input().strip()] for _ in range(H)])

for h in range(1, H):
    S[h, :] = numpy.minimum(S[h,:],S[h-1,:] + 1)
for h in range(H - 2, -1, -1):
    S[h, :] = numpy.minimum(S[h,:],S[h+1,:] + 1)
for w in range(1, W):
    S[:, w] = numpy.minimum(S[:,w],S[:,w-1] + 1)
for w in range(w - 2, -1, -1):
    S[:, w] = numpy.minimum(S[:,w],S[:,w+1] + 1)

print(numpy.max(S))

### FIXED CODE ###

import numpy
import sys
input = sys.stdin.readline
H,W = map(int,input().split())
INF = H * W
S = numpy.array([[INF if i == '.' else 0 for i in input().strip()] for _ in range(H)])

for h in range(1, H):
    S[h, :] = numpy.minimum(S[h,:],S[h-1,:] + 1)
for h in range(H - 2, -1, -1):
    S[h, :] = numpy.minimum(S[h,:],S[h+1,:] + 1)
for w in range(1, W):
    S[:, w] = numpy.minimum(S[:,w],S[:,w-1] + 1)
for w in range(W - 2, -1, -1):
    S[:, w] = numpy.minimum(S[:,w],S[:,w+1] + 1)

print(numpy.max(S))
summer_vacation, amount_of_homework = map(int, input().split())
a = map(int, input().split())
homework_list = list[a]

total_days = 0

for i in homework_list:
    total_days += i

if summer_vacation >= total_days:
    print(summer_vacation - total_days)
else:
    print(-1)


### FIXED CODE ###

summer_vacation, amount_of_homework = map(int, input().split())
a = map(int, input().split())
homework_list = list(a)

total_days = 0

for i in homework_list:
    total_days += i

if summer_vacation >= total_days:
    print(summer_vacation - total_days)
else:
    print(-1)
N = int(input())

xy = [map(int,input().split()) for _ in range(N)]
x,y = [list(i) for i in zip(*xy)]

ans = 0

for i in range(N):
    if x[i] == y[i]:
        ans +=1
    elif ans >= 3:
        flag = True
    else:
        ans = 0
        
if ans >= 3 or flag ==True:
    print("Yes")
    
else:
    print("No")

### FIXED CODE ###

N = int(input())

xy = [map(int,input().split()) for _ in range(N)]
x,y = [list(i) for i in zip(*xy)]

ans = 0
flag = False

for i in range(N):
    if x[i] == y[i]:
        ans +=1
    elif ans >= 3:
        flag = True
        ans = 0
    else:
        ans = 0
        
if ans >= 3  or flag ==True:
    print("Yes")
    
else:
    print("No")
import math

a, b = map(int, input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(a, b))

### FIXED CODE ###

import fractions

a, b = map(int, input().split())
def lcm(x, y):
    return (x * y) / fractions.gcd(x, y)

print(int(lcm(a, b)))
def calc0toN(a):
  bina = int(bin(a)[2:]) 
  if a % 2 == 0:
    if a % 4 == 0:
      return bina
    else:
      return 1 ^ bina
  else:
    if (a + 1) % 4 == 0:
      return 0
    else:
      return 1
A, B = map(int, input().split())
print(int("0b" + str(calc0toN(A - 1) ^ calc0toN(B)), 2))

### FIXED CODE ###

def calc0toN(a):
  if a % 2 == 0:
    if a % 4 == 0:
      return a
    else:
      return 1 ^ a
  else:
    if (a + 1) % 4 == 0:
      return 0
    else:
      return 1
A, B = map(int, input().split())
print(calc0toN(A - 1) ^ calc0toN(B))
import math

inp = str(input())

N, M = map(int, input().split())
count = 0
for _ in range(M):
    
    for i in inp:
        x, y = map(int, input().split())

        xx = int(x) ** 2
        yy = int(y) ** 2

        ans = math.sqrt(xx + yy)

        if ans >= M:
            count += 1
        j += 1
    print(count)

### FIXED CODE ###

import math

N, D = map(int, input().split())
count = 0
for _ in range(N):
    x, y = map(int, input().split())
    xx = x ** 2
    yy = y ** 2

    ans = math.sqrt(xx + yy)
    if ans <= D:
        count += 1

print(count)
N,K=map(int, input().strip().split())
X=list(map(int, input().strip().split()))
X.sort(reverse=True)
print(X)
Y=[]
for i in range(len(X)-1):
    Y.append(X[i]-X[i+1])
Y.sort(reverse=True)
del Y[:K-1]
print(Y)
a=0
for i in range(len(Y)):
    a=a+Y[i]
print(a)


### FIXED CODE ###

#カントリーロード
t=int(input())
for i in range(t):
    N,K=map(int, input().split())
    X=list(map(int,input().strip().split()))
    a=[0]
    for j in range(N-1):
        a.append(X[j+1]-X[j])
    b=sorted(a, reverse=True)
    if K>1:
        del b[0:K-1]

    print(sum(b))
a=input()
b=input()

d=""
for i in range(len(a)):
  d+=(a[i])
  d+=(b[i])
print(d)


### FIXED CODE ###

a=input()
b=input()

d=""
for i in range(len(b)):
  d+=(a[i])
  d+=(b[i])

if len(a)!=len(b):
  d+=a[-1]
  
print(d)
from math import sqrt
prime = [1 for _ in xrange(10**6+1)]
prime[1] = 1
prime[0] = 0
for i in xrange(2, int(sqrt(10**6+1))+1):
    if prime[i] == 1:
        for j in xrange(i+i, 10**6+1, i):
            prime[j] = 0
while True:
    N, X = map(int, raw_input().split())
    if (N, X) == (0, 0): break
    price = [input() for _ in xrange(N)]
    dp = [0] * (X+1)
    dp[0] = 1
    for i in xrange(X+1):
        if dp[i] == 0: continue
        for p in price:
            if i + p <= X:
                dp[i+p] = 1
    for i in xrange(X, -1, -1):
        if i > 0 and dp[i] == 1 and prime[i] == 1:
            print(i)
            break
    else:
        print("NA")

### FIXED CODE ###

while True:
    N, M = map(int, raw_input().split())
    if (N, M) == (0, 0): break
    fert = [map(float, raw_input().split()) for _ in range(N)]
    dp = [[0]*N for _ in range(M)]
    for i in range(N): dp[0][i] = 1.0
    for i in range(M-1):
        for j in range(N):
            dp[i+1][j] = max([dp[i][k]*fert[k][j] for k in range(N)])
    print('{:.2f}'.format(max(dp[M-1])))
#128 b
n=int(input())
res=[]
for i in range(n):
    a,b=list(input().split())
    b=-1*int(b)
    res.append([a,b,i+1])
res=sorted(res)
for x in res:
    print(x[2])

### FIXED CODE ###

#128 a
a,p=map(int,input().split())
kakera=a*3+p
ans=int(kakera/2)
print(ans)
n, k = list(map(int, input().split()))
s = input()
s[k - 1] = (s[k - 1]).lower()
print(s)

### FIXED CODE ###

n, k = list(map(int, input().split()))
s = list(input())
s[k - 1] = s[k - 1].lower()
print(*s, sep = "")
H, W, A, B = list(map(int, input().split()))
for _ in range(B):
    print('1'*  A+ '0' * (W - A) )
for _ in range(H - B):
    print('0' * A + '1'* (W - A) )

### FIXED CODE ###

H, W, A, B = list(map(int, input().split()))
for _ in range(B):
    print('0' * A + '1' * (W - A))
for _ in range(H - B):
    print('1' * A + '0' * (W - A))
k, s = list(map(int, input().split()))
count = 0
for i in range(2,k+1):
    for j in range(2,k+1):
        if (s-i-j <= k) and (0 <= s-i-j):
            count += 1
print(count)

### FIXED CODE ###

k, s = map(int,input().split())
count = 0
for i in range(k+1):
    for j in range(k+1):
            if 0<=(s-i-j)<=k:
                count += 1
print(count)
import sys

A = [[0] * 3 for i in range(3)]

A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))

N = int(input())
for _ in range(N):
    b = int(input())
    if b in A1:
        for a in [i for i, x in enumerate(A1) if x == b]:
            A[0][a] = 1
    if b in A2:
        for a in [i for i, x in enumerate(A2) if x == b]:
            A[1][a] = 1
    if b in A3:
        for a in [i for i, x in enumerate(A3) if x == b]:
            A[2][a] = 1

for i in range(3):
    if sum(A[i][:]) == 3:
        print('Yes')
        sys.exit()
    if sum(A[:][i]) == 3:
        print('Yes')
        sys.exit()

if A[0][0] == 1 and A[1][1] == 1 and A[2][2] == 1:
    print('Yes')
    sys.exit()

if A[0][2] == 1 and A[1][1] == 1 and A[3][0] == 1:
    print('Yes')
    sys.exit()

print('No')

### FIXED CODE ###

import sys

A = [[0] * 3 for i in range(3)]

A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))

N = int(input())
for _ in range(N):
    b = int(input())
    if b in A1:
        for a in [i for i, x in enumerate(A1) if x == b]:
            A[0][a] = 1
    if b in A2:
        for a in [i for i, x in enumerate(A2) if x == b]:
            A[1][a] = 1
    if b in A3:
        for a in [i for i, x in enumerate(A3) if x == b]:
            A[2][a] = 1

for i in range(3):
    if sum(A[i][:]) == 3:
        print('Yes')
        sys.exit()

if A[0][0] == 1 and A[1][0] == 1 and A[2][0] == 1:
    print('Yes')
    sys.exit()
if A[0][1] == 1 and A[1][1] == 1 and A[2][1] == 1:
    print('Yes')
    sys.exit()
if A[0][2] == 1 and A[1][2] == 1 and A[2][2] == 1:
    print('Yes')
    sys.exit()

if A[0][0] == 1 and A[1][1] == 1 and A[2][2] == 1:
    print('Yes')
    sys.exit()

if A[0][2] == 1 and A[1][1] == 1 and A[2][0] == 1:
    print('Yes')
    sys.exit()

print('No')
# coding: utf-8
# Your code here!
def dfs(l,d):
    loc[l]=d
    for n_l,n_d in way[l]:
        if loc[n_l]==10**9:
            dfs(n_l,d+n_d)
        elif loc[n_l]!=d+n_d:
            print("No")
            exit()

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

way=[[] for i in range(N)]
loc=[10**9]*N

for _ in range(M):
    L,R,D=map(int,input().split())
    way[L-1].append([R-1,D])
    way[R-1].append([L-1,-D])

for i in range(N):
    if loc[i]==10**9:
        dfs(i,0)

print("Yes")

### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys

sys.setrecursionlimit(10**9)

def dfs(l,d):
    loc[l]=d
    for n_l,n_d in way[l]:
        if loc[n_l]==10**9:
            dfs(n_l,d+n_d)
        elif loc[n_l]!=d+n_d:
            print("No")
            exit()

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

way=[[] for i in range(N)]
loc=[10**9]*N

for _ in range(M):
    L,R,D=map(int,input().split())
    way[L-1].append([R-1,D])
    way[R-1].append([L-1,-D])

for i in range(N):
    if loc[i]==10**9:
        dfs(i,0)

print("Yes")
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
	a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

### FIXED CODE ###

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

a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)
N, R = int(input().split())
 
if N < 10:
  N = R + 100 * (10 - N) 
  print(N)
  
else:
  N = R
  print(N)

### FIXED CODE ###

N, R = (int(x) for x in input().split())
 
if N < 10:
  N = R + 100 * (10 - N) 
  print(N)
  
else:
  N = R
  print(N)
# -*- coding: utf-8 -*-
# 整数の入力
# from functools import reduce
from collections import defaultdict


def main():
    # n, q
    n, q = map(int, input().split())

    trees = [[] for i in range(n+1)]
    # a, b
    for _ in range(0, n - 1):
        a, b = map(int, input().split())
        trees[a].append(b)
        trees[b].append(a)

    values = [0 for i in range(n+1)]
    # p, x
    for _ in range(0, q):
        p, x = map(int, input().split())
        values[p] += x
    print(trees)
    process(1, -1, trees, values)
    print(*values[1:])


def process(i, parent, trees, values):
    for j in trees[i]:
        if j == parent:
            continue
        values[j] += values[i]
        process(j, i, trees, values)


if __name__ == "__main__":
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
# 整数の入力
# from functools import reduce
import sys
from collections import defaultdict

sys.setrecursionlimit(1000000)


def main():
    # n, q
    n, q = map(int, input().split())

    trees = [[] for i in range(n+1)]
    # a, b
    for _ in range(0, n - 1):
        a, b = map(int, input().split())
        trees[a].append(b)
        trees[b].append(a)

    values = [0 for i in range(n+1)]
    # p, x
    for _ in range(0, q):
        p, x = map(int, input().split())
        values[p] += x
    process(1, -1, trees, values)
    print(*values[1:])


def process(i, parent, trees, values):
    for j in trees[i]:
        if j == parent:
            continue
        values[j] += values[i]
        process(j, i, trees, values)


if __name__ == "__main__":
    main()
N = int(input())
X = str(input())
F = [0] * N

def calc_f(n:int)->int:
    global F
    x = n
    res = 0
    while 0 < x:
        if F[x] != 0:
            res += F[x]
            break
        pop = bin(n).count('1')
        x %= pop
        res += 1
    F[n] = res

# 前処理 N以下のF値テーブル
for i in range(1, N):
    calc_f(i)

# ビット反転すると初期の1の個数に対して+1または-1どちらか
pop_ini = X.count('1')
pp = pop_ini + 1  # pop_plus
pm = pop_ini - 1  # pop_minus

# 2進の各桁をppとpmで割った値のテーブル
ap = [0] * N  # arr_plus
am = [0] * N  # arr_minus
for i in range(N):
    ap[i] = pow(2, N-1-i, pp)
    am[i] = pow(2, N-1-i, pm)

# 所与のXで計算、ベースになる値
fp = 0  # f_plus
fm = 0  # f_minus
for i in range(N):
    if X[i] == '1':
        fp = (fp + ap[i]) % pp
        fm = (fm + am[i]) % pm

# 各桁を反転した場合では差分更新のみ
for i in range(N):
    ans = 1
    if X[i] == '1':
        v = (fm + pm - am[i]) % pm
    else:
        v = (fp + ap[i]) % pp
    if 0 < v:
        ans += F[v]
    print(ans)

### FIXED CODE ###

N = int(input())
X = str(input())
F = [0] * N

def calc_f(n:int)->int:
    global F
    x = n
    res = 0
    while 0 < x:
        if F[x] != 0:
            res += F[x]
            break
        pop = bin(n).count('1')
        x %= pop
        res += 1
    F[n] = res

# 前処理 N以下のF値テーブル
for i in range(1, N):
    calc_f(i)

# ビット反転すると初期の1の個数に対して+1または-1どちらか
pop_ini = X.count('1')
pp = pop_ini + 1  # pop_plus
pm = pop_ini - 1  # pop_minus

# 2進の各桁をppとpmで割った値のテーブル
ap = [0] * N  # arr_plus
am = [0] * N  # arr_minus
for i in range(N):
    ap[i] = pow(2, N-1-i, pp)
    if 0 < pm:
        am[i] = pow(2, N-1-i, pm)

# 所与のXで計算、ベースになる値
fp = 0  # f_plus
fm = 0  # f_minus
for i in range(N):
    if X[i] == '1':
        fp = (fp + ap[i]) % pp
        if 0 < pm:
            fm = (fm + am[i]) % pm

# 各桁を反転した場合では差分更新のみ
for i in range(N):
    ans = 1
    if X[i] == '1':
        if 0 < pm:
            v = (fm + pm - am[i]) % pm
        else:
            ans = 0
            v = 0
    else:
        v = (fp + ap[i]) % pp
    if 0 < v:
        ans += F[v]
    print(ans)
import sys
def check(S):
    stop = True
    if len(S) < 2:
        print(base_S_length - len(S))
        sys.exit()
    for i in range(len(S) - 1):
        if (S[i] + S[i + 1]) == 1:
            S[i] = S[i + 1] = 2
            stop = False    
    if stop:
        print(base_S_length - len(S))
        sys.exit()
    S = [i for i in S if i != 2]
    check(S)

S = list(map(int, list(sys.stdin.readline())))
base_S_length = len(S)
check(S)

### FIXED CODE ###

def main():
    S = list(map(int, list(input())))

    cnt1 = sum(S)
    cnt0 = len(S) - cnt1
    print(2 * min(cnt0, cnt1))


if __name__ == "__main__":
    main()
import numpy as np
N,C=map(int, input().split())

#s~tでc
L=np.zeros((C, 10**5+2),dtype="int")

for i in range(N):
    s,t,c=map(int, input().split())
    L[c-1,s-1]+=1
    L[c-1,t]-=1

L=np.cumsum(L, axis=1)
print(max(np.sum(L,axis=0))


### FIXED CODE ###

import numpy as np
N,C=map(int, input().split())

#s~tでc
L=np.zeros((C, 10**5+1))

for i in range(N):
    s,t,c=map(int, input().split())
    L[c-1,s-1]+=1
    L[c-1,t]-=1

L=np.cumsum(L, axis=1)
print(int((L>0).sum(axis=0).max()))
n, l = map(int, input().split())
list = []
for i in range(n):
  list[i] = input()
list.sort()
print("".join(list))

### FIXED CODE ###

n, l = map(int, input().split())
list = []
for i in range(n):
  list.append(input())
list.sort()
print("".join(list))
def dd():
    a=int(input("a="));
    b=int(input("b="));
    if(a+b>a-b):
        if(a+b>a*b):
            print(a+b);
        
        else:
            print(a*b);
    else:
        if(a-b>a+b):
            if(a-b>a*b):
              print(a-b);
            else:
                print(a*b);
def main():
    dd();
main();


### FIXED CODE ###

a,b=map(int,input().split())
print(max(a+b,max(a-b,a*b)))
import math

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

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

#aの最小公倍数を求める
lcm_t = a[0]

for j in range(1,N):
    lcm_t = lcm(lcm_t,a[j])

lcm_t = max(1,lcm_t-1)

ans = 0

for k in a:
    ans += lcm_t % k

print(ans)

### FIXED CODE ###

import fractions

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

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

#aの最小公倍数を求める
lcm_t = a[0]

for j in range(1,N):
    lcm_t = lcm(lcm_t,a[j])

lcm_t = max(1,lcm_t-1)

ans = 0

for k in a:
    ans += lcm_t % k

print(ans)
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


# Imperative solution
# res = 0
# rem = 0

# for i in range(N):
#     mobs_rem = min(A[i], rem)
#     A[i] -= mobs_rem
#     mobs = min(A[i], B[i])
#     rem = B[i] - mobs
#     res += (mobs+mobs_rem)

# res += min(A[N], rem)
# print(res)

# Functional
def rec(idx, res, rem):
    if idx == N:
        res += min(A[idx], rem)
        return res
    mobs_rem = min(A[idx], rem)
    mobs = min(A[idx] - mobs_rem, B[idx])
    rem = B[idx] - mobs
    res += (mobs + mobs_rem)
    return rec(idx+1, res, rem)


print(rec(0, 0, 0))


### FIXED CODE ###

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

res = 0
rem = 0

for i in range(N):
    mobs_rem = min(A[i], rem)
    A[i] -= mobs_rem
    mobs = min(A[i], B[i])
    rem = B[i] - mobs
    res += (mobs+mobs_rem)

res += min(A[N], rem)
print(res)
n, m, x = map(int, input().split())
numlist = []
minimum = -1
for i in range(n):
    numlist.append(list(map(int, input().split())))
for i in range(1<<n):
    result = [0] * (m+1)
    for j in range(n):
        if(i>>j & 1 == 1):
            for k in range(m+1):
                result[k] += numlist[j][k]
    for k in range(m):
        if(result[k+1] < x): break
    else:
        if(min > result[0] or minimum == -1): minimum = result[0]
print(minimum)

### FIXED CODE ###

n, m, x = map(int, input().split())
numlist = []
minimum = -1
for i in range(n):
    numlist.append(list(map(int, input().split())))
for i in range(1<<n):
    result = [0] * (m+1)
    for j in range(n):
        if(i>>j & 1 == 1):
            for k in range(m+1):
                result[k] += numlist[j][k]
    for k in range(m):
        if(result[k+1] < x): break
    else:
        if(minimum > result[0] or minimum == -1): minimum = result[0]
print(minimum)
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def product_many(N):
    if 0 in N: return 0
    ans = 1
    for x in N:
        if (10 ^ 18 / ans) < x: return -1  
        ans *= x
        if ans > 10 ^ 18: return -1
    return ans

def main():
    _ = input()
    N = list(map(int, input().split()))
    print(product_many(N))

if __name__ == "__main__":
    main()


### FIXED CODE ###

#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def product_many(N):
    if 0 in N: return 0
    ans = 1
    for x in N:
        if (10 ** 18 / ans) < x: return -1
        ans *= x
        if ans > 10 ** 18: return -1
    return ans

def main():
    _ = input()
    N = list(map(int, input().split()))
    print(product_many(N))

if __name__ == "__main__":
    main()
n = int(input())
a = list(map(int, input().split()))

if len(a) % 2 == 0:
    print(*reversed(a[1::2]), *a[0::2])
else:
    print(*reversed(a[0::2]), *a[1::2])


### FIXED CODE ###

from collections import deque

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

d = deque()
for i in range(n):
    if i % 2 != 0:
        d.append(a[i])
    else:
        d.appendleft(a[i])

if n % 2 == 0:
    print(*list(reversed(d)))
else:
    print(*d)
import math

N = int(input())

sum  =0


for i in range(1,N):
    sum += i
    if sum>=N:
        break

for j in range(1,i+1):
    if j == sum-N:
        continue
    print(j)

### FIXED CODE ###

N = int(input())

sum = 0

if N <= 2:
    print(N)
else:

    for i in range(1, N):
        sum += i
        if sum >= N:
            break

    for j in range(1, i + 1):
        if j == sum - N:
            continue
        print(j)
S = int(input())

s = S % 60
m = S // 60 % 60
h = S // 60 // 60

print("{a}:{b}:{c}".format(h,m,s))

### FIXED CODE ###

S = int(input())

s = S % 60
m = S // 60 % 60
h = S // 60 // 60
print(h,':',m,":",s , sep ="")
#print("{a}:{b}:{c}".format(h,m,s))