Harryxun/stf_run huggingface dataset:
from collections import deque
n = int(input())
a = []
for i in range(n):
    a1 = list(map(int,input().split()))
    a.append(a1)
l = [[[] for i in range(n)] for i in range(n)]
c = 0
day = 0
for i in range(n):
    ap = [i,a[i][0]-1]
    ap.sort()
    for j in range(1,n-1):
        p = [i,a[i][j]-1]
        p.sort()
        l[ap[0]][ap[1]].append(p)
        ap = p
rl = [[[0,0] for i in range(n)] for i in range(n)]
d = deque()
for i in range(n):
    for j in range(n):
        if i < j:
            if len(l[i][j]) > 0:
                for k in l[i][j]:
                    rl[k[0]][k[1]][0] += 1
#print(rl)
for i in range(n):
    for j in range(n):
        if i < j:
            if rl[i][j][0] == 0:
                d.append([[i,j],0])
al = []
key = 0
#print(l)
if len(d) == 0:
    key = 1
while len(d):
    #print(d)
    now,day = d.pop()
    day += 1
    if len(l[now[0]][now[1]]) == 0:
        al.append(day)
    else:
        for i in l[now[0]][now[1]]:
            if rl[i[0]][i[1]][0] == 1:
                rl[i[0]][i[1]][0] -= 1
                d.append([i,max(day,rl[i[0]][i[1]][1])])
            else:
                rl[i[0]][i[1]][0] -= 1
                rl[i[0]][i[1]][1] = max(day,rl[i[0]][i[1]][1])
    if day > n*(n-1)//2:
        key = 1
        break
md = 0
for i in range(n):
    md += sum(rl[i][0])
if key == 1 or md > 0:
    print(-1)
else:
    print(max(al))

### FIXED CODE ###

from collections import deque
n = int(input())
a = []
for i in range(n):
    a1 = list(map(int,input().split()))
    a.append(a1)
l = [[[] for i in range(n)] for i in range(n)]
c = 0
day = 0
for i in range(n):
    ap = [i,a[i][0]-1]
    ap.sort()
    for j in range(1,n-1):
        p = [i,a[i][j]-1]
        p.sort()
        l[ap[0]][ap[1]].append(p)
        ap = p
rl = [[0 for i in range(n)] for i in range(n)]
dl = [[0 for i in range(n)] for i in range(n)]
d = deque()
for i in range(n):
    for j in range(n):
        if i < j:
            if len(l[i][j]) > 0:
                for k in l[i][j]:
                    rl[k[0]][k[1]] += 1
#print(rl)
for i in range(n):
    for j in range(n):
        if i < j:
            if rl[i][j] == 0:
                d.append([[i,j],0])
al = []
key = 0
#print(l)
if len(d) == 0:
    key = 1
while len(d):
    #print(d)
    now,day = d.pop()
    day += 1
    if len(l[now[0]][now[1]]) == 0:
        al.append(day)
    else:
        for i in l[now[0]][now[1]]:
            if rl[i[0]][i[1]] == 1:
                rl[i[0]][i[1]] -= 1
                d.append([i,max(day,dl[i[0]][i[1]])])
            else:
                rl[i[0]][i[1]] -= 1
                dl[i[0]][i[1]] = max(day,dl[i[0]][i[1]])
    if day > n*(n-1)//2:
        key = 1
        break
md = 0
for i in range(n):
    md += sum(rl[i])
if key == 1 or md > 0:
    print(-1)
else:
    print(max(al))
N,K = map(int,input().split())
hp = list(map(int,input().split()))
hp_sort = sorted(hp,reverse = True)
if K < len(hp):
    i = 0
    for i in range(K):
        del hp_sort[i]
    print(sum(hp_sort))
else:
    print('0')


### FIXED CODE ###

N,K = map(int,input().split())
hp = list(map(int,input().split()))
hp_sort = sorted(hp)
if K < N:
    print(sum(hp_sort[0:N-K]))
else:
    print('0')
x,n=map(int,input().split())
r=[i-x for i in map(int,input())]
i=1
while True:
  if not -i in r:
    print(x-i)
    break
  elif not i in r:
    print(x+i)
  else:
    i+=1

### FIXED CODE ###

x,n=map(int,input().split())
r=[i-x for i in map(int,input().split())]
for i in range(n+1):
  if not -(i) in r:
    print(x-i)
    break
  elif not i in r:
    print(x+i)
    break
from fractions import gcd
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

n=int(input())
aa=[]*n
aa=list(map(int,input().split()))

bb=lcm(aa)
mod=10**9+7
ans=0
for i in range(n):
    ans=(bb/aa[i]+ans)%mod
print(int(ans))

### FIXED CODE ###

import sys
sys.setrecursionlimit(2000000)

from fractions import gcd
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x


mod = 1000000007


def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))



n=int(input())
aa=[]
aa=list(map(int,input().split()))
# for i in range(n):
#     aa.append(randint(1,10**6))

bb=lcm(aa)
mod=10**9+7
ans=0
for i in range(n):
    ccc=div(bb,aa[i])
    ans=int((ccc%mod+ans%mod)%mod)
print(int(ans))
import sys

args = sys.argv
a = int(args[1])
b = int(args[2])
c = int(args[3])

ret = int(b/a)
if ret >= c:
    ret =c

print(ret)


### FIXED CODE ###

import sys

l = raw_input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])

ret = int(b/a)
if ret >= c:
    ret =c

print(ret)
import math

N=int(raw_input())

n=math.floor(math.sqrt(N))

while(N%n!=0): n-=1

m=N/n
n=int(n)
m=int(m)

if n>=m:
    print len(str(n))
else:
    print len(str(m))


### FIXED CODE ###

a,b=raw_input().split(' ')
a=int(a)
b=int(b)

print (a+b)%24
# coding:utf-8

# 解答みながらの復習

S = str(input())
T = str(input())

Sdic = [0 for _ in range(26)]
Tdic = [0 for _ in range(26)]

alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l' \
    'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

Able = True

for i in range(len(S)):
    si = S[i]
    ti = T[i]
    if Sdic[alphabet.index(si)] == 0:
        Sdic[alphabet.index(si)] = ti
    elif Sdic[alphabet.index(si)] != 0:
        if Sdic[alphabet.index(si)] == ti:
            pass
        else:
            Able = False
            break
    elif Tdic[alphabet.index(ti)] == 0:
        Tdic[alphabet.index(ti)] = si
    elif Tdic[alphabet.index(ti)] != 0:
        if Tdic[alphabet.index(ti)] == si:
            pass
        else:
            Able = False
            break

print("Yes" if Able else "No")



### FIXED CODE ###

# coding:utf-8

# 解答みながらの復習

S = str(input())
T = str(input())

Sdic = [0 for _ in range(26)]
Tdic = [0 for _ in range(26)]

alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",\
    "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

Able = True

for i in range(len(S)):
    si = S[i]
    ti = T[i]
    if Sdic[alphabet.index(si)] == 0:
        Sdic[alphabet.index(si)] = ti
    elif Sdic[alphabet.index(si)] != ti:
        Able = False
        break
    if Tdic[alphabet.index(ti)] == 0:
        Tdic[alphabet.index(ti)] = si
    elif Tdic[alphabet.index(ti)] != si:
        Able = False
        break
        
print("Yes" if Able else "No")
# 整数列A 
# abs(A1-(b+1))+abs(A2-(b+2))+...+abs(An-(b+N))の最小値
# bは任意
# すなわち、その時のbを求めれば良い問題

# 結局、bを、Ai-iの中央値にすれば最適解。

def calcVal(b):
	val = 0
	for n in range(N):
		val += abs(A[n]-(b+n+1))
		# print(A[n])
		# print(n)
		# print(val)
		# print(abs(A[n]-(b+n+1)))
		# print("")
	return val

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

M=[]

for i,a in enumerate(A):
	M.append( a - (i+1) )

M.sort()

if N%2==0:
	med1=N//2
	med2=N//2+1
	if N <= med2:
		med2 = med1
	ans=min(calcVal(M[med1]),calcVal(M[med2]),calcVal(0))

else:
	med=(N+1)//2
	print(M[med])
	ans = min(calcVal(M[med]),calcVal(0))


print(ans)



### FIXED CODE ###

# 整数列A 
# abs(A1-(b+1))+abs(A2-(b+2))+...+abs(An-(b+N))の最小値
# bは任意
# すなわち、その時のbを求めれば良い問題

# 結局、bを、Ai-iの中央値にすれば最適解。

def calcVal(b):
	# print(b)
	val = 0
	for n in range(N):
		val += abs(A[n]-(b+n+1))
		# print(A[n])
		# print(n)
		# print(val)
		# print(abs(A[n]-(b+n+1)))
		# print("")
	return val

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

M=[]

for i,a in enumerate(A):
	#if a - (i+1) not in M:
	M.append( a - (i+1) )

M.sort()
lenM=len(M)

if lenM==1:
	ans=calcVal(M[0])

elif lenM==2:
	ans=min(calcVal(M[0]),calcVal(M[1]))


else:
	med1=lenM//2-1
	med2=lenM//2
	#print(M)
	ans=min(calcVal(M[med1]),calcVal(M[med2]),calcVal(0))



print(ans)
n = int(input())
sum = 0
for i in range(1, n + 1):
  if i !% 3 or i !% 5:
    sum = sum + i
print(sum)

### FIXED CODE ###

a = int(input())
sum = 0
list_number = []
for i in range(a):
    list_number.append(i + 1)
for i in list_number:
    if i % 3 == 0 and i % 5 == 0:
        pass
    elif i % 3 == 0:
        pass
    elif i % 5 == 0:
        pass
    else:
        sum = sum + i
print(sum)
s = str(input())
l = len(s)
x,y = map(int,input().split())
Fs = []
count = 0
for i in range(l):
    if s[i] == "T":
        Fs.append(count)
        count = 0
    else:
        count+=1
if s[-1] == "F":
    Fs.append(count)
xFs = [Fs[j] for j in range(len(Fs)) if j%2 == 0 and j!=0]
yFs = [Fs[k] for k in range(len(Fs)) if k%2 == 1]
x-=Fs[0]

def part_sum(a,A):
    n = len(a)
    dp = [[0 for i in range(A+1)] for j in range(n+1)]
    dp[0][0]=1
    
    for i in range(n):
        for j in range(A+1):
            if a[i]<=j:
                dp[i+1][j]=dp[i][j-a[i]] or dp[i][j]
            else:
                dp[i+1][j]=dp[i][j]
    return dp[n][A]


if sum(xFs) < abs(x) or sum(yFs) < abs(y):
    print("No")
else:
    if sax%2 == 0 and say%2 == 0:
        sax = int((sum(xFs)-x)/2)
        say = int((sum(yFs)-y)/2)
        if part_sum(xFs,sax) == 1 and part_sum(yFs,say) == 1:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

### FIXED CODE ###

s = str(input())
l = len(s)
x,y = map(int,input().split())
Fs = []
count = 0
for i in range(l):
    if s[i] == "T":
        Fs.append(count)
        count = 0
    else:
        count+=1
if s[-1] == "F":
    Fs.append(count)
xFs = [Fs[j] for j in range(len(Fs)) if j%2 == 0 and j!=0]
yFs = [Fs[k] for k in range(len(Fs)) if k%2 == 1]
x-=Fs[0]

def part_sum(a,A):
    n = len(a)
    dp = [[0 for i in range(A+1)] for j in range(n+1)]
    dp[0][0]=1
    
    for i in range(n):
        for j in range(A+1):
            if a[i]<=j:
                dp[i+1][j]=dp[i][j-a[i]] or dp[i][j]
            else:
                dp[i+1][j]=dp[i][j]
    return dp[n][A]


if sum(xFs) < abs(x) or sum(yFs) < abs(y):
    print("No")
else:
    sax = (sum(xFs)-abs(x))
    say = (sum(yFs)-abs(y))
    if sax%2 == 0 and say%2 == 0:
        sax = int(sax/2)
        say = int(say/2)
        if part_sum(xFs,sax) == 1 and part_sum(yFs,say) == 1:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
# 入力N:3桁の整数
N = input()
print("Yes" if str(N).index("7") != -1 else "No")

### FIXED CODE ###

# 入力N:3桁の整数
N = input()
print("Yes" if str(N).count("7") != 0 else "No")
import math

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

mini = min(A)
ans = min(A)
for a in A:
    amari = a%mini
    if amari != 0:
        if amari < mini:
            ans = amari            
if mini - ans == 0:
    print(ans)
else:
    print(math.gcd(mini, ans))

### FIXED CODE ###

from fractions import gcd

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

a = sorted(A)
B = [a[0]]
C = []
for i in range(1,N):
    x = a[i]%a[0]
    if x != 0:
        B.append(x)
b =sorted(B)
for i in range(len(b)-1):
    y = gcd(b[i],b[-1])
    C.append(y)
    
if len(b) == 1:
    print(b[0])
else:
    print(min(C))
K, S = map(int,input().split())
ans = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if z >= 0 and Z <= K:
            ans += 1
print(ans)

### FIXED CODE ###

K, S = map(int,input().split())
ans = 0
for x in range(K+1):
    for y in range(K+1):
        if S - x - y >= 0 and S - x - y <= K:
            ans += 1
print(ans)
def ans():
  N = int(input())
  V = list(map(int,input().split()))
  even = [0]*10001
  odd = [0]*10001
  for v in V[1::2]:
    even[v] += 1
  for v in V[::2]:
    odd[v] += 1
  me = max(even)
  mo = max(odd)
  if(even.index(me) != odd.index(mo)):
    print(N - me - mo)
  else:
    even.sort()
    odd.sort()
    print(min(N-even[-1]-odd[-2], N-even[2]-odd[-1]))
ans()

### FIXED CODE ###

N = int(input())
V = list(map(int,input().split()))
even = [0] * (10 ** 5 + 10)
odd = [0] * (10 ** 5 + 10)
for v in V[1::2]:
  even[v] += 1
for v in V[::2]:
  odd[v] += 1
max_even = max(even)
max_odd = max(odd)
if(even.index(max_even) != odd.index(max_odd)):
  print(N - max_even - max_odd)
else:
  even.sort(reverse = True)
  odd.sort(reverse = True)
  print(min(N - even[0] - odd[1], N - even[1] - odd[0]))
n = int(input())
b = list(map(int, input().split()))
a = [b[0]]*2

for i in range(1, n-1):
    if b[i] >= b[i-1]:
        a.append(b[i])
    else:
        a[i] = b[i]
        a[i-1] = b[i]

print(sum(a))


### FIXED CODE ###

n = int(input())
b = list(map(int, input().split()))
a = [b[0]]*2

for i in range(1, n-1):
    a.append(b[i])
    if b[i] < b[i-1]:
        a[i] = b[i]

print(sum(a))
#グラフ構造DFSを使う
N = int(input())
ans = [-1] * (N-1)
g = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    g[a-1].append((b-1, i))
    g[b-1].append((a-1, i))

def bfs(v, c, p):
    n_c = 1
    for i in range(len(g[v])):
        to = g[v][i][0]
        ID = g[v][i][1]
        if to == p:
            continue
        if n_c == c:
            n_c += 1
        ans[ID] = n_c
        bfs(to, n_c, v)
        n_c += 1

bfs(0, 0, -1)
print(max(ans))
for i in range(N-1):
    print(ans[i])

### FIXED CODE ###

#グラフ構造DFSを使う
import sys
sys.setrecursionlimit(500000)
N = int(input())
ans = [-1] * (N-1)
g = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    g[a-1].append((b-1, i))
    g[b-1].append((a-1, i))

def bfs(v, c, p):
    n_c = 1
    for i in range(len(g[v])):
        to = g[v][i][0]
        ID = g[v][i][1]
        if to == p:
            continue
        if n_c == c:
            n_c += 1
        ans[ID] = n_c
        bfs(to, n_c, v)
        n_c += 1

bfs(0, 0, -1)
print(max(ans))
for i in range(N-1):
    print(ans[i])
import sys
#from collections import deque
input = sys.stdin.buffer.readline

x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int,input().split())),reverse=True)
q = sorted(list(map(int,input().split())),reverse=True)
r = sorted(list(map(int,input().split())),reverse=True)
ans = p[:x]
ans[x:x] = q[:y]
ans=sorted(ans)
#print(ans)
i = 0
result = 0
for A in ans:
    if A < r[i]:
        result += r[i]
        if i < c:
            i += 1
        continue
    result += A
print(result)

### FIXED CODE ###

import sys
#from collections import deque
input = sys.stdin.buffer.readline

x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int,input().split())),reverse=True)
q = sorted(list(map(int,input().split())),reverse=True)
r = sorted(list(map(int,input().split())),reverse=True)
ans = p[:x]
ans[x:x] = q[:y]
ans += r
ans = sorted(ans,reverse=True)
print(sum(ans[:x+y]))
n, k = [int(i) for i in input().split()]

def l2c(x):
	c = 1 / n
    while x < k:
		x = x * 2
        c = c / 2
    return c
  
print(sum([l2c(i) for i in range(1, n+1)])

### FIXED CODE ###

n, k = [int(i) for i in input().split()]

def l2c(x):
	c = 1 / n
	while x < k:
		x = x * 2
		c = c / 2
	return c

print(sum([l2c(i) for i in range(1, n+1)]))
# B - ATCoder
s = input()
wordList = 'ACGT'
t = []
tmp = []
for i in range(len(s)):
    if s[i] in wordList:
        tmp.append(s[i])
    if not (s[i] in wordList):
        t.append(tmp)
        tmp = []
print(max(len(i) for i in t))


### FIXED CODE ###

s = input()
wordList = 'ACGT'
t = []
tmp = []
lead = 0
ans = 0
slist = list(s)
for i in range(len(slist)):
    if not slist[i] in wordList:
        ans = max(ans, (i - lead))
        lead = i + 1
ans = max(ans, (len(slist) - lead))
print(ans)
X=int(input())
if x>=30:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

x=int(input())
if x>=30:
  print("Yes")
else:
  print("No")
N = int(input())
x = list(map(int, input().split()))
a=[0]*8
b=0
for i in range(0,N):
    if x[i]>=3200:
        b +=1
for j in range(0,8):
    for i in range(0,N):
        if x[i]<400:
            a[j] +=1
            x[i] = inf
        x[i] -= 400

zerox=0
mincolar=0
 
for i in a:
    if i==0:
        zerox +=1  
    else:
        mincolar +=1

if(zerox<b):
    print(mincolar,mincolar+zerox)
else:
    print(mincolar,mincolar+b)


quit()

### FIXED CODE ###

inf=float('inf')
N = int(input())
x = list(map(int, input().split()))
a=[0]*8
b=0
for i in range(0,N):
    if x[i]>=3200:
        b +=1
        x[i]=inf
for j in range(0,8):
    for i in range(0,N):
        if x[i]<400:
            a[j] +=1
            x[i] = inf
        x[i] -= 400
 
 
mincolar=0
for i in a:
    if i!=0:
        mincolar +=1
if mincolar!=0:
    print(mincolar,mincolar+b)
else:
    print(1,b)
quit()
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
l.sort()
ans=[0]
for i in range(m-1):
    ans.append(l[i+1]-l[i])
ans.sort()
for i in range(n-1): ans.pop()
print(sum(ans))


### FIXED CODE ###

n,m=map(int,input().split())
l=[int(i) for i in input().split()]
l.sort()
ans=[0]
for i in range(m-1):
    ans.append(l[i+1]-l[i])
ans.sort()
for i in range(n-1):
    if len(ans)==1: break
    ans.pop()
print(sum(ans))
s = input()
n = s.size()
ans=""
 
half = s[0:(n-1)/2]
 
if(s==s[::-1] && half==half[::-1]){
	ans = "Yes";
}
else
	ans = "No";
  
print(ans)
}

### FIXED CODE ###

s = input()
n = len(s)
ans=""
 
half = s[:int((n-1)/2)]
 
if s==s[::-1] and half==half[::-1]:
	ans = "Yes"
else:
	ans = "No"
  
print(ans)
import sys
input = sys.stdin.readline
import numpy as np
sys.setrecursionlimit(10**6)

N = int(input())
graph = [[] for _ in range(N+1)] # parent to child
for i,p in enumerate(input().split(),2):
    graph[int(p)].append(i)
X = [None] + [int(x) for x in input().split()]

def dfs(v):
    # None または 白、黒の2つ組を返す
    child = []
    for w in graph[v]:
        c = dfs(w)
        if c is None:
            return None
        child.append(c)
    S = sum(a+b for a,b in child)
    x = X[v]
    dp = np.zeros(x+1, dtype=np.bool) # 2択の繰り返しで作れる和
    dp[0] = 1
    for a,b in child:
        prev = dp
        dp = np.zeros_like(prev)
        dp[a:] = prev[:-a]
        dp[b:] |= prev[:x+1-b]
    nz = np.nonzero(dp)[0]
    if len(nz) == 0:
        return None
    return x, S - nz[-1]

answer = 'POSSIBLE' if dfs(1) is not None else 'IMPOSSIBLE'
print(answer)

### FIXED CODE ###

import sys
input = sys.stdin.readline
import numpy as np
sys.setrecursionlimit(10**6)

N = int(input())
graph = [[] for _ in range(N+1)] # parent to child
for i,p in enumerate(input().split(),2):
    graph[int(p)].append(i)
X = [None] + [int(x) for x in input().split()]

def dfs(v):
    # None または 白、黒の2つ組を返す
    child = []
    for w in graph[v]:
        c = dfs(w)
        if c is None:
            return None
        child.append(c)
    S = sum(a+b for a,b in child)
    x = X[v]
    dp = np.zeros(x+1, dtype=np.bool) # 2択の繰り返しで作れる和
    dp[0] = 1
    for a,b in child:
        prev = dp
        dp = np.zeros_like(prev)
        if a <= x:
            dp[a:] = prev[:x+1-a]
        if b <= x:
            dp[b:] |= prev[:x+1-b]
    nz = np.nonzero(dp)[0]
    if len(nz) == 0:
        return None
    return x, S - nz[-1]

answer = 'POSSIBLE' if dfs(1) is not None else 'IMPOSSIBLE'
print(answer)
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
MOD = 1000000007
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()
    A = LI()

    # color_number[i][j]: [0, i)でj番目に多い色の人数
    color_number = [[0, 0, 0] for _ in range(N)]
    for i in range(N-1):
        idx = color_number[i].index(A[i])
        for j in range(3):
            if j==idx:
                color_number[i+1][j] = color_number[i][j] + 1
            else:
                color_number[i+1][j] = color_number[i][j]

    ans = 1
    for i in range(N):
        ans *= color_number[i].count(A[i])
        ans %= MOD

    print(ans)

if __name__ == '__main__':
    resolve()

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
MOD = 1000000007
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()
    A = LI()

    # color_number[i][j]: [0, i)でj番目に多い色の人数
    color_number = [[0, 0, 0] for _ in range(N)]
    for i in range(N-1):
        if A[i] in color_number[i]:
            idx = color_number[i].index(A[i])
        else:
            idx = -1
        for j in range(3):
            if j==idx:
                color_number[i+1][j] = color_number[i][j] + 1
            else:
                color_number[i+1][j] = color_number[i][j]

    ans = 1
    for i in range(N):
        ans *= color_number[i].count(A[i])
        ans %= MOD

    print(ans)

if __name__ == '__main__':
    resolve()
# 文字列のリストとして受け取りので、高階関数mapでint関数を各要素に適用
N, K = map(int, input().split())
# 入力される文字列を、文字のリストに変換する
S = list(input())

S[K - 1] = S[K - 1].lower()

print(''.json(S))

### FIXED CODE ###

N, K = map(int, input().split())
S = list(input())
 
S[K - 1] = S[K - 1].lower()
 
print(''.join(S))
from sys import stdin, stdout
n = int(stdin.readline())
nmleaves = list(map(int, stdin.readline().strip().split()))

# pref[i]: sum of all elements in nmleaves after i, i.e. sum(nmleaves[i+1:])
full = sum(nmleaves)
tot = 0
pref = [0]*(n+1)
for i, l in enumerate(nmleaves):
    tot += l
    pref[i] = full - tot

if n==0:
    print(0)

else:
    if nmleaves[0]!=0:
        print(-1)
        exit()
    
    ## it exists
    ans = 0
    for level, leaves in enumerate(nmleaves):
        if leaves > 2**(level):
            print(-1)
            exit()

        if level == 0:
            ans += 1
            validnom = 1
        else:
            maxup = 2*validnom
            maxnom = maxup - leaves

            if level+1<len(nmleaves):
                validnom = min(maxnom, pref[level])
                ans += (leaves + validnom)
            else:
                ans += leaves
    print(ans)





### FIXED CODE ###

from sys import stdin, stdout
# t = int(input())
# for _ in range(t):
    # n = int(stdin.readline())
h1, m1, h2, m2, k = map(int, stdin.readline().strip().split())
    # nums = list(map(int, stdin.readline().strip().split()))

t = (h2*60 + m2 - (h1*60 + m1) -  k)
print(t if t>0 else 0)