Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))
ans=[]
for i in range(n):
    if(i%2==0):
        ans+=[A[i]]
    else:
        ans=[A[i]]+ans
if(i%2==0):
    print(*ans[::-1])
else:
    print(*ans)

### FIXED CODE ###

import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


n = int(input())
A = input().split()
if n%2==0:
    print(' '.join(A[1::2][::-1]),end=' ')
    print(' '.join(A[::2]))
else:
    print(' '.join(A[::2][::-1]),end=' ')
    print(' '.join(A[1::2]))
### BUGGY CODE ###

count = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
sum = 0

for i in range(len(a)-1):
  for j in range(i+1, len(a)):
    temp = a[i] * a[j]
    sum += temp

answer = sum % mod
print(answer)


  

### FIXED CODE ###

count = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
sum = sum(a)

for i in range(count):
  sum = sum - a[i]
  ans += sum * a[i]
  
answer = ans % mod
print(answer)
### BUGGY CODE ###

N,K=map(int,input().split())
td=[]
for i in range(N):
    t,d=map(int,input().split())
    td.append([t,d])
td.sort(key=lambda x:x[1],reverse=True)
A=td[:K]
B=[]
s2=set()
for i,j in td[K:]:
    if not(i in s2):
        s2.add(i)
        B.append([i,j])
s1=set()
n=0
C=[]
sum=0
for i,j in A:
    if not(i in s1):
        s1.add(i)
        n+=1
        sum+=j
    else:
        C.append([i,j])
        sum+=j
sum+=n**2
B.reverse()
D=[]
for i,j in B:
    if not(i in s1):
        D.append([i,j])
list=[sum]
while(C):
    if D:
        i,j=D.pop()
        list.append(list[-1]+2*n+1+(j-C[-1][1]))
        n+=1
        C.pop()
print(max(list))


### FIXED CODE ###

N,K=map(int,input().split())
td=[]
for i in range(N):
    t,d=map(int,input().split())
    td.append([t,d])
td.sort(key=lambda x:x[1],reverse=True)
A=td[:K]
B=[]
s2=set()
for i,j in td[K:]:
    if not(i in s2):
        s2.add(i)
        B.append([i,j])
s1=set()
n=0
C=[]
sum=0
for i,j in A:
    if not(i in s1):
        s1.add(i)
        n+=1
        sum+=j
    else:
        C.append([i,j])
        sum+=j
sum+=n**2
B.reverse()
D=[]
for i,j in B:
    if not(i in s1):
        D.append([i,j])
list=[sum]

while(C):
    if D:
        i,j=D.pop()
        list.append(list[-1]+2*n+1+(j-C[-1][1]))
        n+=1
    C.pop()
print(max(list))
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC97 C

import sys
import math
import bisect
import time
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

f = defaultdict(lambda : 0)
s = input()
k = I()
n = len(s)
for i in range(n):
    for j in range(i+1,n+1):
        f[s[i:j]] = 1
f = sorted(f.items())
print(f[k-1][0])


### FIXED CODE ###

#!usr/bin/env python3
s = input()
K = int(input())

l = {s}
for n in range(1, K+1):
    for i in range(0, len(s)-n+1):
        l.add(s[i:i+n])
l = list(l)

l.sort()

print(l[K-1])
### BUGGY CODE ###

from collections import deque
n = int(input())
s = [input() for i in range(n)]
l = deque([])
for i in s:
  if i not in l:
    l.appendleft(i)
    
print(len(l))


### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
print(len(set(s)))
### BUGGY CODE ###

import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N = int(readline().rstrip())

power = 1
for i in range(1, N+1):
    power = power * i

answer = power % MOD
print(answer)

### FIXED CODE ###

import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N = int(readline().rstrip())

answer = 1
for i in range(1, N+1):
    answer = answer * i % MOD

answer = answer % MOD
print(answer)
### BUGGY CODE ###

from copy import deepcopy as dc
n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

d=[-10**15 for _ in [0]*n]
d[0]=0
q=[[0,set()]]
flag=0
loop=set()
while q:
    item,s=q.pop()
    #print(item,s)
    s.add(item)
    #print(g[item])
    for i,dist in g[item]:
        if d[i]<d[item]+dist:
            if i in s:
                #print(i)
                loop.add(i)
                continue
            d[i]=d[item]+dist
            q.append([i,dc(s)])
    
def check(x):
    q=[x]
    c=[False for _ in [0]*n]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
    return c[n-1]
for i in loop:
    if check(i)==True:
        print("inf")
        break
else:
    print(d[n-1])

### FIXED CODE ###

n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15

for _ in range(n):
    for p in range(n):
        for i,j in g[p]:
            dist[i]=max(dist[i],dist[p]+j)
    a,b=b,dist[n-1]

if a==b:
    print(a)
else:
    print("inf")
### BUGGY CODE ###

from array import *

h, w, a, b = map(int, input().split(' '))
MOD = 10**9 + 7
MAX = 2*10**5

def modpow(a, b):
    res = 1
    while b:
        if (b & 1):
            res = (res * a) % MOD
        a = (a * a) % MOD
        b >>= 1
    return res


def nCr(n, r):
    if r == 0 or n == r:
        return 1
    return (((f[n] * ivf[n-r]) % MOD) * ivf[r]) % MOD


f = [1] * MAX
f = array('q', f)
ivf = [0] * MAX
ivf = array('q', ivf)
for i in range(1, MAX):
    f[i] = (f[i-1] * i) % MOD
    ivf[i] = modpow(f[i], MOD-2)
r = 0
for i in range(b, w):
    y1 = h - a - 1
    x1 = i
    y2 = a - 1
    x2 = w - i - 1
    p = (nCr(x1 + y1, x1) * nCr(x2 + y2, x2)) % MOD
    r = (r + p) % MOD
print(int(r))

### FIXED CODE ###

from array import *
import time
h, w, a, b = map(int, input().split(' '))
MOD = 10**9 + 7
MAX = max(h+w-a-1, a+w)


def modpow(a, b):
    res = 1
    while b:
        if (b & 1):
            res = (res * a) % MOD
        a = (a * a) % MOD
        b >>= 1
    return res


def nCr(n, r):
    if r == 0 or n == r:
        return 1
    return (((f[n] * ivf[n-r]) % MOD) * ivf[r]) % MOD


f = [1] * MAX
f = array('q', f)
ivf = [0] * MAX
ivf = array('q', ivf)
for i in range(1, MAX):
    f[i] = (f[i-1] * i) % MOD
    ivf[i] = modpow(f[i], MOD-2)
r = 0
for i in range(b, w):
    y1 = h - a - 1
    x1 = i
    y2 = a - 1
    x2 = w - i - 1
    p = (nCr(x1 + y1, x1) * nCr(x2 + y2, x2)) % MOD
    r = (r + p) % MOD
print(int(r))
### BUGGY CODE ###

import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# from fractions import gcd
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

s = input()
q = int(input())
ql = [input().split() for i in range(q)]

isrev=False
for i in range(q):
  if ql[i][0] == '1':
    isrev = not isrev
    continue
  if (ql[i][1] == '2') == isrev:
    s=''.join([ql[i][2],s])
  else:
    s=''.join([s,ql[i][2]])
if isrev:
  s = s[::-1]

print(s)


### FIXED CODE ###

import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# from fractions import gcd
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

s = input()
q = int(input())
ql = [input().split() for i in range(q)]

ans = deque(s)
isrev=False
for i in range(q):
  if ql[i][0] == '1':
    isrev = not isrev
    continue
  if (ql[i][1] == '2') == isrev:
    ans.appendleft(ql[i][2])
  else:
    ans.append(ql[i][2])

if isrev:
  ans.reverse()

s = ''.join(ans)

print(s)
### BUGGY CODE ###

def main():
    import heapq
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    h = []
    h2 = []
    heapq.heapify(h)
    for i in range(n):
        heapq.heappush(h, (-b[i], i))
    cnt = 0
    while h:
        i, j = heapq.heappop(h)
        i=-i
        temp = i-a[j]
        sho=temp//(b[j-1]+b[(j+1)%n])
        if  sho==0:
            h2.append((i, j))
            continue
        cnt += sho
        b[j] -= (b[j-1]+b[(j+1)%n])*sho
        heapq.heappush(h, (-b[j], j))
    h2.sort(key=lambda x: x[1])
    for i in range(n):
        if a[i] != h2[i][0]:
            print(-1)
            return 0
    print(cnt)


main()

### FIXED CODE ###

def main():
    from heapq import heappop as hpop
    from heapq import heappush as hpush
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    h = []
    for i in range(n):
        hpush(h, (-b[i], i))
    cnt = 0
    while h:
        i, j = hpop(h)
        i = -i
        jj = (j+1) % n
        temp = i-a[j]
        temp2 = b[j-1]+b[jj]
        sho = temp//temp2
        if sho == 0:
            if temp:
                print(-1)
                return 0
            continue
        cnt += sho
        b[j] -= temp2*sho
        hpush(h, (-b[j], j))
    print(cnt)
main()
### BUGGY CODE ###

def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


def main():
    num_nodes, num_regions = tuple(input_ints())
    regions = [tuple(input_ints()) for _ in range(num_regions)]

    nodes = set()
    for r in regions:
        nodes.add(r[0])
        nodes.add(r[1])

    regions.sort(key=lambda x: (x[1] - x[0], x[0]))

    def solve(rs, steps):
        min_steps = 99999999999

        for i in [i for i in range(rs[0][0], rs[0][1]) if i in nodes]:
            rs2 = [r for r in rs if not r[0] <= i < r[1]]
            if rs2:
                min_steps = min(solve(rs2, steps + 1), min_steps)
            else:
                return steps

        return min_steps

    print(solve(regions, 1))


main()


### FIXED CODE ###

def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


def main():
    num_nodes, num_regions = tuple(input_ints())
    regions = [tuple(input_ints()) for _ in range(num_regions)]
    regions.sort(key=lambda r: r[1])

    edges = []
    for r in regions:
        if not edges or edges[-1] < r[0]:
            edges.append(r[1] - 1)

    print(len(edges))


main()
### BUGGY CODE ###

import math
import sys
import queue
import copy
import bisect#2分探索

def input():
    return sys.stdin.readline()[:-1]
def inputi():
    return int(input())
def inputl():
    return list(map(int, input().split()))
def printl(li):
    print(*li, sep="\n")
def argsort(s):
    return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

#N = inputi()
#N, K = inputl()
#L = [int(input()) for i in range(N)]
#A = inputl()
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=lambda x:x[1],reverse=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)


#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入

K=inputi()
vals=[float('inf')]*K
visit=[]
vals[1]=0
q=[1]
flag=False
while len(q)>0:
    s=q.pop(0)
    vs=vals[s]
    if s==0:
        print(vs+1) 
        flag=True
        break
    #visit.append(s)
    s0=(10*s)%K

    if vs<vals[s0]:
        vals[s0]=vs
        q.insert(0,s0)
    s1=(s+1)%K

    if vs+1<vals[s1]:
        vals[s1]=vs+1
        q.append(s1)
    #print(q,s,s0,s1,vals)

#if flag==False:
#    print(vals[0]+1)


### FIXED CODE ###

import sys
# import math
# import queue
# import copy
# import bisect#2分探索
from collections import deque


def input():
    return sys.stdin.readline()[:-1]
def inputi():
    return int(input())

K=inputi()
vals=[10**5+1]*K
visit=[]
vals[1]=0
q = deque([1])
flag=False
while len(q)>0:
    s=q.popleft()
    vs=vals[s]
    if s==0:
        print(vs+1) 
        flag=True
        break
    #visit.append(s)
    s0=(10*s)%K

    if vs<vals[s0]:
        vals[s0]=vs
        q.appendleft(s0)
    s1=(s+1)%K

    if vs+1<vals[s1]:
        vals[s1]=vs+1
        q.append(s1)
    #print(q,s,s0,s1,vals)

#if flag==False:
#    print(vals[0]+1)
### BUGGY CODE ###

N = input()[::-1]
iv = 1
MOD = 10**9+7
pdp = [0 for i in range(13)]
pdp[0]=1
dp = [0 for i in range(13)]
for i in range(len(N)):
  x = N[i]
  if x=='?':
    for j in range(13):
      for h in range(10):
        dp[(h*iv+j)%13] += pdp[j]
    for j in range(13):
      pdp[j] = (dp[j]%MOD)
      dp[j] = 0
  else:
    x = int(x)
    for j in range(13):
      dp[(j+x*iv)%13]+=pdp[j]
    for j in range(13):
      pdp[j] = (dp[j]%MOD)
      dp[j]=0
  iv *= 10
  iv %= 13
print(pdp[5])

### FIXED CODE ###

S = input()
con = 10**9 + 7

T = [s if s != "?" else "0" for s in S]
T = int(''.join(T))
SS = T % 13

def get_mod(S):
    c = {}
    iii = 1
    for i in range(len(S)):
        if S[len(S) - i - 1] != "?":
            iii *= 10
            iii %= 13
            continue
        c[i] = {(j * iii) % 13: 1 for j in range(0, 10)}
        iii *= 10
        iii %= 13
    return c
c = get_mod(S)

def get_tdp(pdp):
    tdp = {i: 0 for i in range(13)}
    for r in v.keys():
        for _r, _v in pdp.items():
            i = (_r + r) % 13
            tdp[i] += _v
    for i in range(13):
        tdp[i] %= con
    return tdp

pdp = {i: 0 for i in range(13)}
pdp[SS] += 1
for k, v in c.items():
    pdp = get_tdp(pdp)

ans = pdp[5]
print(ans)
### BUGGY CODE ###

from collections import Counter
N = int(input())
A_list = list(map(int, input().split()))
Q = int(input())
BC_list = [list(map(int, input().split())) for i in range(Q)]

count_list = [0 for i in range(10**5 + 1)]
for a, i in Counter(A_list).items():
    count_list[a] = i

for b, c in BC_list:
    count_list[c] += count_list[b]
    count_list[b] = 0
    _sum = 0
    for i, a in enumerate(count_list):
        _sum += i * a
    print(_sum)

### FIXED CODE ###

from collections import Counter
N = int(input())
A_list = list(map(int, input().split()))
Q = int(input())
BC_list = [list(map(int, input().split())) for i in range(Q)]

count_dict = dict(Counter(A_list))
_sum = 0
for i, a in count_dict.items():
    _sum += i * a

for b, c in BC_list:
    if b in count_dict:
        count_b = count_dict[b]
        if c in count_dict:
            count_dict[c] += count_dict[b]
        else:
            count_dict[c] = count_dict[b]
        count_dict.pop(b)
        _sum -= b * count_b
        _sum += c * count_b
    print(_sum)
### BUGGY CODE ###

N = int(input())
s = [input() for _ in range(N)]
os = [ "" for _ in range(N) ]

for i in range(N):
    os[i] = "".join(sorted(s[i]))
#print(os)
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        #print(dicts[i], dicts[j])
        if os[i] == os[j]:
            cnt += 1
print(cnt)

### FIXED CODE ###

from collections import defaultdict
N = int(input())
s = [input() for _ in range(N)]
dic = defaultdict(int)

for i in range(N):
    os = "".join(sorted(s[i]))
    dic[os] += 1
#print(os)
cnt = 0
for s, c in dic.items():
    #print(s, c)
    cnt += c * (c-1) // 2
    #print(c* (c - 1) // 2)
print(cnt)
### BUGGY CODE ###

l,r = map(int,input().split())
ans = 500000000000000000000000000000000000000000000000000
for j in range(l+1,r+1):
    for i in range(l,j):
        ans = min(ans,(i*j)%2019)
print(ans)


### FIXED CODE ###

l,r = map(int,input().split())
ans = 10**10
for i in range(l,r+1):
    for j in range(i+1,r+1):
        x = (i*j)%2019
        if x==0:
            ans = 0
            break
        else:
            ans=min(ans,x)
    else:
        continue
    break
print(ans)
### BUGGY CODE ###

n = int(input())

a = list(map(int, input().split()))
set_a = set(a)
nums = {}
cnt = 0
for i in set_a:
    nums[i] = a.count(i)
    if a.count(i) % 2 == 0:
        cnt += 1
    elif a.count(i) != 1:
        cnt += 2

print(len(set_a) - cnt%2)

### FIXED CODE ###

n = int(input())

a = list(map(int, input().split()))
set_a = set(a)
nums = {}
cnt = 0

for i in range(n):
    nums[a[i]] = nums.get(a[i], 0) + 1


for i in set_a:
    if nums[i] % 2 == 0:
        cnt += 1
    elif nums[i] != 1:
        cnt += 2

print(len(set_a) - cnt%2)
### BUGGY CODE ###

A, B, C, D, E, F = map(int, input().split())
dens = 0
ans_water = 0
ans_sugar = 0
for i in range(31):
    for j in range(31):
        for k in range(101):
            for l in range(101):
                water = 100*A*i+100*B*j
                sugar = C*k+D*l
                if i==j==0:
                    break
                if water+sugar <= F and sugar <= E*(A*i+B*j):
                    if dens<sugar/(sugar+water):
                        dens = sugar/(sugar+water)
                        ans_water = water
                        ans_sugar = sugar
print(ans_water+ans_sugar, ans_sugar)

### FIXED CODE ###

A, B, C, D, E, F = map(int, input().split())
dens = 0
ans_water = 100*min(A, B)
ans_sugar = 0
for i in range(31):
    for j in range((F-(100*A*i))//(100*B)+1):
        for k in range((F-(100*A*i)-(100*B*j))//C+1):
            for l in range((F-(100*A*i)-(100*B*j)-(C*k))//D+1):
                water = 100*A*i+100*B*j
                sugar = C*k+D*l
                if water == 0:
                    break
                if sugar <= E*(A*i+B*j):
                    if dens<sugar/(sugar+water):
                        dens = sugar/(sugar+water)
                        ans_water = water
                        ans_sugar = sugar
print(ans_water+ans_sugar, ans_sugar)
### BUGGY CODE ###

from sys import stdin
from collections import defaultdict
readline = stdin.readline



#readline = open('???.txt').readline

def main():
    v, e = map(int, readline().split())
    g = defaultdict(list)
    residual = [[0] * v for _ in range(v)]
    source, sink = 0, v - 1

    for _ in range(e):
        s, t, c = map(int, readline().split())
        if 0 < c:
            g[s].append(t)
            residual[s][t] = c

    capacity = sum(residual[source][i] for i in g[source])

    while True:
        route, flow = search(g, residual, source, sink)
        if route is None:
            break
        for i in range(1, len(route)):
            residual[route[i - 1]][route[i]] -= flow

    print(capacity - sum(residual[source][i] for i in g[source]))

def search(g, residual, source, sink):
    dfs_stack = [(source, None, float('inf'))]
    route = [None]
    #visited = set()
    while dfs_stack:
        u, prev, flow = dfs_stack.pop()
        while route[-1] != prev:
            route.pop()
        route.append(u)
        #visited |= {u}
        if u == sink:
            return route[1:], flow
        for v in g[u]:
            #if v in visited:
            if v in route:
                continue
            next_flow = min(residual[u][v], flow)
            if 0 < next_flow:
                dfs_stack.append((v, u, next_flow))
    return None, None
main()

### FIXED CODE ###

from sys import stdin
from collections import defaultdict
readline = stdin.readline


def main():
    v, e = map(int, readline().split())
    g = defaultdict(set)
    residual = [[0] * v for _ in range(v)]
    source, sink = 0, v - 1

    for _ in range(e):
        s, t, c = map(int, readline().split())
        if 0 < c and s != sink and t != source:
            g[s] |= {t}
            g[t] |= {s}
            residual[s][t] = c

    while True:
        route, flow = search(g, residual, source, sink)
        if not route:
            break
        for s, t in zip(route, route[1:]):
            residual[s][t] -= flow
            residual[t][s] += flow

    print(sum(residual[sink][i] for i in g[sink]))


def search(g, residual, source, sink):
    dfs_stack = [(source, None, float('inf'))]
    route = [None]
    visited = set()
    while dfs_stack:
        u, prev, flow = dfs_stack.pop()
        while route[-1] != prev:
            route.pop()
        route.append(u)
        visited |= {u}
        if u == sink:
            return route[1:], flow
        for v in g[u]:
            if v not in visited and 0 < residual[u][v]:
                dfs_stack.append((v, u, min(residual[u][v], flow)))
    return [], 0
main()