Harryxun/stf_run huggingface dataset:
import collections
N, K, L = map(int, input().split())
road = [{"Connected":[],"set":0,"seen":False} for _ in range(N)]
rail = [{"Connected":[],"set":0,"seen":False} for _ in range(N)]

def dfs(graph, v, num): #深さ優先探索
    graph[v]["seen"] = True
    graph[v]["set"] = num
    for next_v in graph[v]["Connected"]:
        if graph[next_v]["seen"]:
            continue
        dfs(graph, next_v, num)

for X in ((road, K), (rail, L)): #結合を入力
    for i in range(X[1]):
        p, q = map(int, input().split())
        X[0][p-1]["Connected"].append(q-1)
        X[0][q-1]["Connected"].append(p-1)

for X in [road, rail]: #探索して連結成分に分解
    set_index = 0
    for v in range(N):
        if X[v]["seen"]:
            continue
        set_index += 1
        dfs(X, v, set_index)
        

List = [(road[i]["set"],rail[i]["set"]) for i in range(N)]
counter = collections.Counter(List)
for A in List:
    print(counter[A],end=" ")
        


### FIXED CODE ###

N, K, L = map(int, input().split())

def fp(x, parentList): #findParent
    if parentList[x] == x:
        return x
    else:
        parentList[x] = fp(parentList[x], parentList)
        return parentList[x]

#各ノードのparentをリストで表現(連結前は自身がparent)
road = [i for i in range(N)]
rail = [i for i in range(N)]

for _ in range(K):
    p, q = map(int, input().split())
    par_p, par_q = fp(p-1, road), fp(q-1, road) #p, qのparent 
    #連結する際、若い番号をparentとする
    if par_p < par_q:
        road[par_q] = par_p
    else:
        road[par_p] = par_q

#railについても同様
for _ in range(L):
    s, t = map(int, input().split())
    par_s, par_t = fp(s-1, rail), fp(t-1, rail)
    if par_s < par_t:
        rail[par_t] = par_s
    else:
        rail[par_s] = par_t

#連結成分の要素をカウント
cnt = {}
for i in range(N):
    key = (fp(i,road),fp(i,rail))
    if key in cnt:
        cnt[key] += 1
    else:
        cnt[key] = 1
#出力
for i in range(N):
    key = (fp(i,road),fp(i,rail))
    ans = cnt[key]
    print(ans, end=" ")
import numpy as np

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

s = 0

def step(a, s):
    am = np.argmax(a)
    s = s + np.max(a)*a[am+1:].shape[0] - np.sum(a[am+1:])
    
    if am == 0:
        return s
    return step(a[:am], s)

print(step(A, s))


### FIXED CODE ###

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

s = 0

for i in range(1, N):
    if A[i-1] > A[i]:
        s += A[i-1] - A[i]
        A[i] = A[i-1]

print(s)
N=int(input())
lis=[chr(i) for i in range(97, 97+26)]
ans=''
while N>0:
    N-=1
    ans+=lis[N%26]
    N=N//26
print(ans[::-1]

### FIXED CODE ###

N=int(input())
lis=[chr(i) for i in range(97, 97+26)]
ans=''
while N>0:
    N-=1
    ans+=lis[N%26]
    N=N//26
print(ans[::-1])
A, B, C, K = list(map(int, input().split()))

if A >= K:
  print(A)
elif A + B >= K:
  print(A)
else:
  print(A - (K - (A + B)))

### FIXED CODE ###

s = input()
t = input()

if len(s) != len(t) - 1:
  print("No")
elif s != t[:-1]:
  print("No")
else:
  print("Yes")
mod = 10**9 + 7
h, w, a, b = map(int, input().split())

fact = [1] * (h + w + 1)
invf = [1] * (h + w + 1)
invn = [1] * (h + w + 1)
for i in range(1, h + w + 1):
  fact[i] = fact[i-1] * i % mod
  invn[i] = -invn[mod % i] * (p // i) % mod
  invf[i] = invf[i-1] * invn[i] % mod

count = 0
for i in range(min(h-a, w-b)):
  count += fact[h+b-a-1] * invf[h-a-i-1] * invf[b+i] * fact[w+a-b-1] * invf[a+i] * invf[w-b-i-1]
  count %= mod
print(count)

### FIXED CODE ###

mod = 10**9 + 7
h, w, a, b = map(int, input().split())

fact = [1] * (h + w + 1)
invf = [1] * (h + w + 1)
invn = [1] * (h + w + 1)
for i in range(2, h + w + 1):
  fact[i] = fact[i-1] * i % mod
  invn[i] = (-invn[mod % i]) * (mod // i) % mod
  invf[i] = invf[i-1] * invn[i] % mod

count = 0
for i in range(min(h-a, w-b)):
  count += fact[h+b-a-1] * invf[h-a-i-1] * invf[b+i] * fact[w+a-b-1] * invf[a+i] * invf[w-b-i-1]
  count %= mod
print(count)
def solve(N,W,wv):
    dp=[-1]*(W+1)
    dp[0]=0
    for i in range(N):
        cur_w=wv[i][0]
        cur_v=wv[i][1]
        for j in range(W-cur_w,-1,-1):
            if dp[j]>=0:
                dp[j+cur_w]=max(dp[j+cur_w],dp[j]+cur_v)
    return max(dp)


N,W=map(int,input().split())
wv=tuple(tuple(map(int,input().split())) for _ in range(N))
print(solve(N,W,wv))

### FIXED CODE ###

def solve(N,h):
    dp=[0]*N
    dp[1]=abs(h[1]-h[0])
    for i in range(2,N):
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
    return dp[N-1]

N=int(input())
h=list(map(int,input().split()))
print(solve(N,h))
import sys
import numpy as np
from collections import defaultdict
from numba import njit
def input(): return sys.stdin.readline().rstrip()

@njit
def koushin(dp,item):
    dptmp1 = np.copy(dp)
    dptmp2 = np.copy(dp)
    dptmp3 = np.copy(dp)
    for i in range(len(item)):
        dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1])
        dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1])
        dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1])
    return dptmp3

def main():
    R, C, K = map(int, input().split())
    items = defaultdict(list)
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r-1].append([c-1, v])
    dp = np.zeros(C, dtype=int)
    for RR in range(R):
        items[RR].sort(key=lambda x: x[0])
        dp=koushin(dp,np.array(items[RR],dtype=int))
    print(dp[-1])


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
import numpy as np
from collections import defaultdict
from numba import njit
def input(): return sys.stdin.readline().rstrip()

@njit
def koushin(dp,item):
    dptmp1 = np.copy(dp)
    dptmp2 = np.copy(dp)
    dptmp3 = np.copy(dp)
    for i in range(len(item)):
        dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1])
        dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1])
        dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1])
    return dptmp3

def main():
    R, C, K = map(int, input().split())
    items = defaultdict(list)
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r-1].append([c-1, v])
    dp = np.zeros(C, dtype=int)
    for RR in range(R):
        if items[RR]==[]:
          continue
        items[RR].sort(key=lambda x: x[0])
        dp=koushin(dp,np.array(items[RR],dtype=int))
    print(dp[-1])


if __name__ == '__main__':
    main()
n, k = map(int, input().split())
s = input()
temp = ""
ans = []
c = 0
for s_ in s:
    if temp != s_:
        if s_ == "0":
            ans.append(c)
            temp = "0"
            c = -1
        else:
            ans.append(c)
            temp = "1"
            c = 1
    else:
        if s_ == "0":
            c -= 1
        else:
            c += 1
ans.append(c)
ans = ans[1:]
c = []
t = [i for i in range(len(ans)) if ans[i] < 0]
aaa = []
for v in itertools.combinations(t, k):
    anst = ans.copy()
    for v_ in v:
        anst[v_] *= -1
    c_ = 0
    for s_ in anst:
        if s_ > 0:
            c_ += s_
        else:
            aaa.append(c_)
            c_ = 0
    aaa.append(c_)
if len(aaa) > 0:
    print(max(aaa))
else:
    print(len(s))

### FIXED CODE ###

n, k = map(int, input().split())
s = input()
hand_list = []
for i in range(n):
    if i == 0:
        hand_list.append(i)
    else:
        if s[i] != s[i - 1]:
            hand_list.append(i)
hand_list.append(n)

ans_list = []
if len(hand_list) > 2 * k:
    for i in range(len(hand_list) - 2 * k):
        if s[hand_list[i]] == '1':
            ans = hand_list[min(i + 2 * k + 1, len(hand_list)-1)] - hand_list[i]
        else:
            ans = hand_list[i + 2 * k] - hand_list[i]
        ans_list.append(ans)
else:
    ans_list.append(n)
print(max(ans_list))
a, b, c, d = map(int, input())
print('Left' if a+b>c+d else 'Balanced' if a+b==c+d else 'Right')

### FIXED CODE ###

a, b, c, d = map(int, input().split())
print('Left' if a+b>c+d else 'Balanced' if a+b==c+d else 'Right')
n = int(raw_input())
ls = []
for i in range(n):
    cmd = raw_input()
    if cmd[0] == "i":
        ls.insert(0,cmd[7])
    elif cmd[6] == " ":
        ls.remove(cmd[7])
    elif cmd[6] == "F":
        ls.pop(0)
    else:
        ls.pop(-1)

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

### FIXED CODE ###

n = int(raw_input())
ls = []
bp = 0
for i in range(n):
	cmd = raw_input()
	if cmd[0] == "i":
		ls.append(cmd[7:])
	elif cmd[6] == " ":
		try:
			x = ls[::-1].index(cmd[7:])
			if x!=-1:
				del ls[-x-1]
		except:
			pass
	elif cmd[6] == "F":
		ls.pop()
	else:
		bp += 1

print " ".join(map(str, ls[bp:][::-1]))
from Dice import Dice

dice = Dice(input().split())
count = int(input())
result = []

for i in range(count):
    (top, front) = [i for i in input().split()]
    dice.moveTopTo(top)
    dice.moveFrontTo(front)
    result.append(dice.getRight())

for s in result:
    print(s)

### FIXED CODE ###

class Dice:
    def __init__(self, data):
        self.data = data

    def move(self, direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3],self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[1],self.data[0],self.data[4],self.data[5]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4],self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
             self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2],self.data[5],self.data[3],self.data[0]
        elif direction == 'LEFT':
            self.data[2],self.data[4],self.data[3],self.data[1] = \
                    self.data[1], self.data[2],self.data[4],self.data[3]


    def getTop(self):
        return self.data[0]

    def getRight(self):
        return self.data[2]

    def moveTopTo(self, target):
        for i in range(4):
            if self.data[0] == target:
                break
            self.move('W')

            if self.data[1] == target:
                self.move('S')
            elif self.data[4] == target:
                self.move('N')

    def moveFrontTo(self, target):
        for i in range(4):
            if self.data[1] == target:
                break
            self.move('LEFT')

dice = Dice(input().split())
count = int(input())
result = []

for i in range(count):
    (top, front) = [i for i in input().split()]
    dice.moveTopTo(top)
    dice.moveFrontTo(front)
    result.append(dice.getRight())

[print(i) for i in result]
num = int(input())
li = list(input())
i = int(num/2)]
ans = 0
for i in range(num):
  fi = set(li[:i])
  se = set(li[i:])
  hoge = len(list(fi & se))
  if hoge > ans:
    hoge = ans
 
print(hoge)

### FIXED CODE ###

num = int(input())
li = list(input())
ans = 0
for i in range(num):
  fi = set(li[:i])
  se = set(li[i:])
  hoge = len(list(fi & se))
  if hoge > ans:
    ans = hoge
 
print(ans)
s = input()
a = 0
for x in s:
    if x == '+'
        a += 1
    else:
        a -= 1

print(a)            


### FIXED CODE ###

s = input()
a = 0
for x in s:
    if x == '+':
        a += 1
    else:
        a -= 1

print(a)
s = input()

if s[1]==s[2]==s[3]:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

s = input()

if s[1]==s[2]==s[0]:
  print('No')
else:
  print('Yes')
a=int(input())
ans=0
for i in range(1,n+1):
  num=n//1
  ans+=((num+1)//2)*i
print(ans)

### FIXED CODE ###

a=int(input())
ans=0
for i in range(1,a+1):
  num=a//i
  ans+=(((num+1)*num)//2)*i
print(ans)
temp_arr = input().split(' ')
n = temp_arr[0]
m = temp_arr[1]

print(str((n-1) * (m-1)))

### FIXED CODE ###

temp_arr = input().split(' ')
n = int(temp_arr[0])
m = int(temp_arr[1])

print(str((n-1) * (m-1)))
##Prime Numbers
##16D8101008G Kojima Masayoshi 小嶋真義　2018.4.18

import numpy as np
import math
n=int(input())
A=np.empty((n))
B=np.zeros((n))
count=0

##print(B)検査

for i in range(n):
    A[i]=int(input())


for i in range(n):
    if A[i]==1:
        B[i]=1
    elif A[i]==2:
        B[i]=0
    elif A[i]==3:
        B[i]=0
    elif A[i]==5:
        B[i]=0
    elif A[i]%2==0 :
        B[i]=1
    elif A[i]%3==0:
        B[i]=1
    elif A[i]%5==0:
        B[i]=1
    else:
        for j in range(2,int(math.sqrt(A[i]))):
            if A[i]%j==0:
                B[i]=1 ##素数でないなら1を入力
                break

##print(B)

for i in range(n):
    if B[i]==0:
        count=count+1

print(count)




### FIXED CODE ###

from math import sqrt

n=int(input())

count=0

for i in range(n):
    x=int(input())
    if x==1:
        count=count+1
    elif x!=2 and x%2==0:
        count=count+1
    elif x==2 or x==3 or x==5:
        count=count
    else:
        for j in range(2,int(sqrt(x))+1): 
            if x%j==0:
                count=count+1
                break


print(n-count)
s=input()
t=input()
u=input()
a,b=map(int,input().split())
if u==s:
    print(a-1,b)
if u==t:
    print(a,b-1)

### FIXED CODE ###

s,t=map(str,input().split())
a,b=map(int,input().split())
u=input()
if u==s:
    print(a-1,b)
if u==t:
    print(a,b-1)
N = int(input())
D = list(map(int,input().split()))

a = [0 for _ in range(N-1)]

for d in D:
  a[d] += 1


ans = 0
for i in range(N-1):
  if i == 0:
    ans += a[i]
  else:
    if a[i] == 0:
      pass
    else:
      ans = (ans * a[i]) % 998244353

print(ans)






### FIXED CODE ###

N = int(input())
D = list(map(int,input().split()))
_mod = 998244353

a = [0 for _ in range(N)]

for d in D:
  a[d] += 1

ans = 0

if a[0] != 1 or D[0] != 0:
  print(ans)
  exit()

cnt = 0
for i in range(N):
  cnt += a[i]
  if i == 0:
    ans = 1
  else:
    if a[i] == 0:
      if cnt == N:
        break
      else:
        ans = 0
    else:
      temp = a[i-1] ** a[i]
      ans = (ans * temp ) % _mod

print(ans)
N = int(input())
k = 0
for i in range(1, N+1):
    if 1 =< i < 10:
        k += 1
    elif 100 =< i < 1000:
        k += 1
    elif 10000 =< i < 100000:
        k += 1
print(k)

### FIXED CODE ###

N = int(input())
k = 0
for i in range(1, N+1):
    if 1 <= i <= 9:
        k += 1
    elif 100 <= i <= 999:
        k += 1
    elif 10000 <= i <= 99999:
        k += 1
print(k)
n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]

T = [[] for i in range(n+1)]
RT = [[] for i in range(n+1)]

for a, b in A:
    T[a].append(b)
    RT[b].append(a)

D = [0] * (n+1)
P = [0] * (n+1)

def dfs(p, i, depth):
    if depth > D[i]:
        D[i] = depth
        P[i] = p
    for t in T[i]:
        dfs(i, t, depth+1)

def root(i):
    if not RT[i]:
        return i
    return root(RT[i][0])

dfs(0, root(1), 1)
for p in P[1:]:
    print(p)

### FIXED CODE ###

from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]

T = [[] for i in range(n+1)]
RT = [set() for i in range(n+1)]

for a, b in A:
    T[a].append(b)
    RT[b].add(a)

D = [0] * (n+1)
P = [0] * (n+1)
used = [0] * (n+1)

def dfs(p, i, depth):
    if used[i]:
        return None
    D[i] = depth
    P[i] = p
    used[i] = True
    for t in tuple(T[i]):
        RT[t].remove(i)
    for t in tuple(T[i]):
        if not RT[t]:
            dfs(i, t, depth+1)

def root(i):
    if not RT[i]:
        return i
    return root(tuple(RT[i])[0])

dfs(0, root(1), 1)
for p in P[1:]:
    print(p)
import math
A, B, C, D = map(int,input().split())

def lcm(x, y): #最小公倍数
    return (x * y) // math.gcd(x, y)

n_C = B//C - (A-1)//C # Cで割り切れる数の数
n_D = B//D - (A-1)//D
CandD = lcm(C,D)
n_CandD = B//CandD - (A-1)//CandD

# CでもDでも割けれない数 = 全体 - CでもDでも割り切れる数
ans = B-A+1 - (n_C + n_D - n_CandD)
print(ans)



### FIXED CODE ###

import fractions
A, B, C, D = map(int,input().split())

def lcm(x, y): #最小公倍数
    return (x * y) // fractions.gcd(x, y)

n_C = B//C - (A-1)//C # Cで割り切れる数の数
n_D = B//D - (A-1)//D
CandD = lcm(C,D)
n_CandD = B//CandD - (A-1)//CandD

# CでもDでも割けれない数 = 全体 - CでもDでも割り切れる数
ans = B-A+1 - (n_C + n_D - n_CandD)
print(ans)
N = int(input())
num = list(map(int, input().split(" ")))
oparation = 10 ^ 8

for i in range(N):
    temp = 0
    while(1):
        if(num[i] % 2 or num[i] == 0):
            break
        else:
            num[i] /= 2
            temp += 1
    if(oparation > temp):
        oparation = temp

print(oparation)


### FIXED CODE ###

a=input().split('1')
b=len(a)-1
print(b)
n = int(input())
s = 0

if int(n/100) == 1:
    s += 1
if n%100 => 10:
    s += 1
if n%10 == 1:
    s += 1

print(s)

### FIXED CODE ###

n = int(input())
s = 0

if int(n/100) == 1:
    s += 1
if n%100 >= 10:
    s += 1
if n%10 == 1:
    s += 1

print(s)
K = input()
S = input()

if len(S) <= K:
  print(S)
else:
  print(S[:K] + '...')

### FIXED CODE ###

K = int(input())
S = input()

if len(S) <= K:
  print(S)
else:
  print(S[:K] + '...')
n=int(input())
cnt=0
for i in range(2,int(n**0.5)+2):
    if n%i==0:
        expo=0
    while n%i==0:
        n//=i
        expo+=1
    j=1
    while expo-j>=0:
        cnt+=1
        expo-=j
        j+=1
if n>1:
    cnt+=1
print(cnt)


### FIXED CODE ###

n=int(input())
cnt=0
for i in range(2,int(n**0.5)+2):
    if n%i==0:
        expo=0
        while n%i==0:
            n//=i
            expo+=1
        j=1
        while expo-j>=0:
            cnt+=1
            expo-=j
            j+=1
if n>1:
    cnt+=1
print(cnt)
S = input()
K = int(input())
counter = 0
num=0
log=0
for i in range(K + 1):
    if int(S[i]) != 1:
        log = counter
        num = int(S[i])
        break
    counter += 1

if K <= log:
    print(1)
else:
    print(num)


### FIXED CODE ###

S = input()
K = int(input())
counter = 0
num = 1
log = 0
for i in S:
    if int(i) != 1:
        log = counter
        num = int(i)
        break
    counter += 1

if K <= log:
    print(1)
else:
    print(num)
N=int(input())
S=input()
sl=list(S)
change=[0]
ans=''
for i in range(N+1):
  if (sl[i-1]==')')and(sl[i]=='('):
    change.append(i)

change.append(N)
for i in range(len(change)-1):
  A=sl[change[i]:change[i+1]]
  r=0
  l=0
  for a in A:
    if a=='(':
      l+=1
    else:
      r+=1
      
  if r==l:
    ans+=''.join(A)
  elif r>l:
    ans+='('*(r-l)+''.join(A)
  else:
    ans+=''.join(A)+')'*(l-r)
      
print(ans)

### FIXED CODE ###

N=int(input())
S=input()
sl=list(S)
change=[0]
for i in range(1,N):
  if (sl[i-1]==')')and(sl[i]=='('):
    change.append(i)

change.append(N)
r_add=0
l_add=0
for i in range(len(change)-1):
  A=sl[change[i]:change[i+1]]
  r=0
  l=0
  for a in A:
    if a=='(':
      l+=1
    else:
      r+=1
      
  if r==l:
    continue
  elif r>l:
    if r_add>0:
      if r_add>=r-l:
        r_add-=r-l
      else:
        l_add+=r-l-r_add
        r_add=0
        
    else:
      l_add+=r-l
      
  else:
    r_add+=l-r
      
print('('*l_add+S+')'*r_add)
s = int(input())
print(str(s//3600)+":"+str((s//3600))//str(60+":"+s%60))

### FIXED CODE ###

s = int(input())
print(str(s//3600) + ":" + str((s%3600)//60) + ":" + str(s%60))
k,s=map(int,input(),split())
#k=2
#s=2
result=0
for x in range(k+1):
    for y in range(k+1):
        z=s-x-y
        if 0<=z and z<=k:
            result+=1
            
print(result)

### FIXED CODE ###

k,s=map(int,input().split())
#k=2
#s=2
result=0
for x in range(k+1):
    for y in range(k+1):
        z=s-x-y
        if 0<=z and z<=k:
            result+=1
            
print(result)
from collections import defaultdict
    
n, m = map(int, input().split())
adj = defaultdict(list)
radj = defaultdict(list)

for i in range(m):
    s, e = map(int, input().split())
    adj[s].append(e)
    
dp = [-1]*(n+1)

def dfs(e):
    if dp[e] != -1:
        return dp[e]
    
    temp = 0
    for i in adj[e]:
        temp = max(temp, 1+dfs(i))
        
    dp[e] = temp
    return temp
    
    
for i in range(1, n+1):
    dfs(i)
    
print(max(dp))

### FIXED CODE ###

import sys
from collections import defaultdict
    
sys.setrecursionlimit(10**9)
    
n, m = map(int, input().split())
adj = defaultdict(list)
radj = defaultdict(list)

for i in range(m):
    s, e = map(int, input().split())
    adj[s].append(e)
    
dp = [-1]*(n+1)

def dfs(e):
    if dp[e] != -1:
        return dp[e]
    
    temp = 0
    for i in adj[e]:
        temp = max(temp, 1+dfs(i))
        
    dp[e] = temp
    return temp
    
    
for i in range(1, n+1):
    dfs(i)
    
print(max(dp))
a,b,c,d=map(int, input().split)
n=int(input)
oneltr=min(4*a, 2*b, c, 2*a+b)
twoltr=min(8*a, 4*b, 2*c, d, c+2*b, 4*a+2*b)

if n%2==0 :
               print(twoltr*n//2)
else :
               print(oneltr+twoltr*(n-1)//2)


### FIXED CODE ###

a,b,c,d=map(int, input().split())
n=int(input())
oneltr=min(4*a, 2*b, c, 2*a+b)
twoltr=min(8*a, 4*b, 2*c, d, c+2*b, c+b+2*a,c+4*a,4*a+2*b,b+6*a,3*b+2*a)

if n%2==0 :
               print(twoltr * (n//2))
else :
               print(oneltr+twoltr * ((n-1)//2))
n=input()
print(int(n**3))


### FIXED CODE ###

n=int(input())
print(n**3)
import math

# 入力
A,B = map(int,input().split())

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

print(int(lcm(A, B)))

### FIXED CODE ###

import fractions

# 入力
A,B = map(int,input().split())

print(int((A * B) // fractions.gcd(A, B)))
, M = map(int,input().split())
alist = list()
for _ in range(M):
    alist.append(int(input()))


li = {}
li[0] = 1

for i in range(1,N+1):
    if i in alist:
        li[i] = 0
    else:
        if i == 1:
            li[i] = 1
        else:
            li[i] = (li[i-1] + li[i-2])%(10**9+7)
print(li[N]%(10**9+7))

### FIXED CODE ###

N, M = map(int,input().split())
alist = list()
for _ in range(M):
    alist.append(int(input()))


li = {}
li[0] = 1

for i in range(1,N+1):
    if len(alist)>=1 and i ==  alist[0]:
        li[i] = 0
        alist.pop(0)
    else:
        if i == 1:
            li[i] = 1
        else:
            li[i] = ((li[i-1] + li[i-2])%(10**9+7))
print(li[N]%(10**9+7))
#python3.4
def inpul(): return list(map(int, input().split()))

N, M = inpul()
X = inpul()

if(N >= M):
    print(0)

new_list = sorted(X)
diff_list = [new_list[i+1] - new_list[i] for i in range(M-1)]
new_dif_list = sorted(diff_list, reverse = True)

if(N  >= 2):
    for i in range(N-1):
      new_dif_list.pop(0)

print(sum(new_dif_list))


### FIXED CODE ###

#python3.4
def inpul(): return list(map(int, input().split()))

N, M = inpul()
X = inpul()
new_list = sorted(X)
diff_list = [new_list[i+1] - new_list[i] for i in range(M-1)]
new_dif_list = sorted(diff_list, reverse = True)

if(N >= M):
    print(0)

else:
  if(N  >= 2):
      for i in range(N-1):
        new_dif_list.pop(0)

  print(sum(new_dif_list))
n = int(input())
t = []
for i in range(n):
    txy = list(map(int,input().split()))
    t.append(txy)
if t[0][0]<sum(t[0][1:]) or t[1][0]<sum(t[1][1:]):
    print('No')
else:
    if t[0][0]%sum(t[0][1:])==0 and t[1][0]%sum(t[1][1:])==0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

n = int(input())
for i in range(n):
  t, x, y = map(int, input().split())
  if t < (x+y) or (t+x+y)%2==1:
    print("No")
    exit()

print("Yes")
n = int(input())
s = list(str(input()))

n_s = ""

for c in s:
    add = n
    c_num = ord(c) - 64
    if(n % 26 == 0):
        n_s += c
    else:
        if(c_num + n > 26):
            add = (c_num + n) % 26
            n_s += chr(add + 64)
        else:
            n_s += chr(c_num + add + 64)

print(n_s)

### FIXED CODE ###

day = str(input())

days = ["SAT","FRI","THU","WED","TUE","MON","SUN"]

for d in days:
    if(day == d):
        print(days.index(d) + 1)
n = int(input())
ls = list(map(int,input().split()))

ls.sort()

dis = 0
for i in range(0, n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if ls[i] + ls[j] <= ls[k]: dis += 1

ans = (n*(n-1)*(n-2) // 6) - dis
print(ans)

### FIXED CODE ###

# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
import math
# mod = 10**9 + 7

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


print(a-2*b if a-2*b>=0 else 0)