Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())

    for i in range(M//N, 0, -1):
        if (M - N * i) % i == 0:
            print(i)
            break
    
if __name__ == "__main__":
    main()

Fixed submission:
import math
import sys
input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return sorted(divisors, reverse=True)

def main():
    N, M = map(int, input().split())

    divisors = make_divisors(M)

    for d in divisors:
        tmp = M - d * N
        if tmp >= 0 and tmp % d == 0:
            print(d)
            break
    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def ceil(a, b):
    if a%b == 0:
        return a//b
    else:
        return a//b + 1

def main():
    D, G = map(int, input().split())
    pc = [list(map(int, input().split())) for i in range(D)]

    ans = int(1e9)
    for i in range(2**D):
        tmp = 0
        rest = []
        count = 0
        for j in range(D):
            if i&1:# コンプリートする問題
                tmp += (j+1)*100 * pc[j][0] + pc[j][1]
                count += pc[j][0]
            else:
                rest.append(((j+1)*100, pc[j][0]))
            i >>= 1
        rest = sorted(rest, reverse=True)
        rest_point = G - tmp
        if rest_point < 0:
            continue
        tmp = ceil(rest_point, rest[0][0])
        if tmp <= rest[0][1]:
            ans = min(ans, count + tmp)
            # print(rest_point, count, tmp)
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def ceil(a, b):
    if a%b == 0:
        return a//b
    else:
        return a//b + 1

def main():
    D, G = map(int, input().split())
    G //= 100
    pc = [list(map(int, input().split())) for i in range(D)]

    ans = int(1e9)
    for i in range(2**D):
        tmp = 0
        rest = []
        count = 0
        for j in range(D):
            if i&1:# コンプリートする問題
                tmp += (j+1) * pc[j][0] + pc[j][1]//100
                count += pc[j][0]
            else:
                rest.append((j+1, pc[j][0]))
            i >>= 1
        rest = sorted(rest, reverse=True)
        rest_point = G - tmp
        if rest_point <= 0:# すでに足りている
            ans = min(ans, count)
        elif len(rest) > 0:# 不足分を補う必要がある
            plus = ceil(rest_point, rest[0][0])
            if plus < rest[0][1]:# p-1問以内ですむ
                ans = min(ans, count + plus)
        else:# すべて使っても足りない
            pass
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    ab = sorted([list(map(int, input().split())) for i in range(M)], key = lambda x:x[1])
    bridge = [True] * (N-1)
    count = 0
    start = -1
    for a, b in ab:
        a -= 1; b -= 1;
        if a > start:
            ok = True
            for i in range(a, b):
                if not bridge[i]:
                    ok = False
                    break
            if ok:
                start = a
                bridge[b-1] = False
                count += 1
    print(count)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    ab = sorted([list(map(int, input().split())) for i in range(M)], key = lambda x:x[1])
    count = 0
    break_ = -1
    for a, b in ab:
        a -= 1; b -= 1;
        if a > break_:
            count += 1
            break_ = b-1
    print(count)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    ab = sorted([list(map(int, input().split())) for i in range(M)], key = lambda x:x[1])
    # print(ab)
    bridge = [True] * (N-1)
    count = 0
    for a, b in ab:
        a -= 1; b -= 1;
        ok = True
        for i in range(a, b):
            if not bridge[i]:
                ok = False
                break
        if ok:
            bridge[b-1] = False
            count += 1
    print(count)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    ab = sorted([list(map(int, input().split())) for i in range(M)], key = lambda x:x[1])
    count = 0
    break_ = -1
    for a, b in ab:
        a -= 1; b -= 1;
        if a > break_:
            count += 1
            break_ = b-1
    print(count)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    K = int(input())
    starts = sorted(list(set(list(s))))
    count = 0
    ind = {}
    for start in starts:
        for i in range(len(s)):
            if s[i] == start:
                for j in range(i+1, len(s)+1):
                    if s[i:j] not in ind:
                        count += 1
                        ind[s[i:j]] = 1
        if count >= K:
            break
    # print(ind)
    ind = sorted(list(ind))
    print(ind[K-1])

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    s = input()
    K = int(input())
    ind = []
    for i in range(len(s)):
        for j in range(i+1, min(len(s)+1, i+6)):
            ind.append(s[i:j])
    ind = sorted(list(set(list(ind))))
    # print(ind)
    print(ind[K-1])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    x = sorted([(int(input()), i) for i in range(N)])
    ans = [0] * N
    for i in range(N//2):
        ans[x[i][1]] = x[N//2][0]
    for i in range(N//2, N):
        ans[x[i][1]] = x[N//2 - 1][0]
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    N = int(input())
    x = list(map(int, input().split()))
    x = sorted([(x[i], i) for i in range(N)])
    ans = [0] * N
    for i in range(N//2):
        ans[x[i][1]] = x[N//2][0]
    for i in range(N//2, N):
        ans[x[i][1]] = x[N//2 - 1][0]
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = input().strip()
    ans = 0
    count = 0
    for i in range(len(N)):
        if N[i] != "9":
            break
        count += 1
    if count == len(N):
        print(9*count)
    elif count == len(N)-1:
        print(9*count+int(N[-2])-1)
    else:
        print(9*(len(N)-1)+int(N[count])-1)

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = input().strip()
    all_nine = True
    for i in range(1, len(N)):
        if N[i] != "9":
            all_nine = False
    ans = int(N[0]) + 9 * (len(N) - 1)
    if all_nine:
        print(ans)
    else:
        print(ans - 1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.redline

def main():
  s = input().strip()
  t = "abc"
  count = [0, 0, 0]
  for i in range(len(s)):
    for j in range(3):
      if s[i] == t[j]:
        count[j] += 1
  m = min(count)
  jud = count[0] - m
  jud = max(jud, count[1] - m)
  jud = max(jud, count[2] - m)
  
  if jud <= 1:
    print("YES")
  else:
    print("NO")
    
if __name__ == "__main__":
  main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
  s = input().strip()
  t = "abc"
  count = [0, 0, 0]
  for i in range(len(s)):
    for j in range(3):
      if s[i] == t[j]:
        count[j] += 1
  m = min(count)
  jud = count[0] - m
  jud = max(jud, count[1] - m)
  jud = max(jud, count[2] - m)
  
  if jud <= 1:
    print("YES")
  else:
    print("NO")
    
if __name__ == "__main__":
  main()
Buggy python submission (verdict: Runtime Error):
import sys
import bisect
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = sorted(list(map(int, input().split())))
    c = list(map(int, input().split()))

    sum_c = [0] * (max(max(c), b[-1]) + 2)
    for i in range(N):
        sum_c[c[i]] += 1
    
    for i in range(len(sum_c)-2, -1, -1):
        sum_c[i] += sum_c[i+1]
    
    count = [0] * N
    for i in range(N):
        count[i] = sum_c[b[i]+1]
    for i in range(N-2, -1, -1):
        count[i] += count[i+1]
    # print(count)
    ans = 0
    for i in range(N):
        a_ = a[i]
        b_i = bisect.bisect_left(b, a_+1)
        if b_i < N:
            # print("{}より大きくて最小のbは{}でcount[{}] := {}".format(a_, b[b_i], b_i, count[b_i]))
            ans += count[b_i]
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import sys
import bisect
input = sys.stdin.readline

def main():
    N = int(input())
    a = sorted(list(map(int, input().split())))
    b = sorted(list(map(int, input().split())))
    c = sorted(list(map(int, input().split())))

    ans = 0
    for i in range(N):
        tmp = bisect.bisect_right(a, b[i]-1)
        tmp *= N - bisect.bisect_left(c, b[i]+1)
        ans += tmp
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = [int(input()) for i in range(N)]

    check = [False] * (max(a) + 1)

    for i in a:
        check[i] = not(check[i])
    
    ans = 0
    for c in check:
        if c:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
import sys
import bisect
input = sys.stdin.readline

def main():
    N = int(input())
    a = [int(input()) for i in range(N)]

    nums = []

    for i in a:
        if len(nums) > 0:
            if i <= nums[-1]:
                ind = bisect.bisect_left(nums, i)
                if nums[ind] == i:
                    nums.pop(ind)
                else:
                    bisect.insort(nums, i)
            else:
                nums.append(i)
        else:
            nums.append(i)
    
    print(len(nums))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = [int(input()) for i in range(N)]

    check = [False] * (int(1e5) + 1)

    for i in a:
        check[i] = not(check[i])
    
    ans = 0
    for c in check:
        if c:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
import sys
import bisect
input = sys.stdin.readline

def main():
    N = int(input())
    a = [int(input()) for i in range(N)]

    nums = []

    for i in a:
        if len(nums) > 0:
            if i <= nums[-1]:
                ind = bisect.bisect_left(nums, i)
                if nums[ind] == i:
                    nums.pop(ind)
                else:
                    bisect.insort(nums, i)
            else:
                nums.append(i)
        else:
            nums.append(i)
    
    print(len(nums))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import itertools
import sys
input = sys.stdin.readline

MAX = 1e9

def main():
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    link = [[MAX if j != i else 0 for j in range(N+1)] for i in range(N+1)]

    for i in range(M):
        a, b, c = map(int, input().split())
        link[a][b] = c
        link[b][a] = c

    for i in range(N+1):
        for j in range(N+1):
            for k in range(N+1):
                link[j][k] = min(link[j][k], link[j][i] + link[i][k])

    ans = MAX
    for per in list(itertools.permutations(r)):
        tmp = 0
        for i in range(R-1):
            tmp += link[per[i]][per[i+1]]
        ans = min(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque
import itertools
from scipy.sparse.csgraph import floyd_warshall as wf
import sys
input = sys.stdin.readline

MAX = 1e9

def main():
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    link = [[MAX if j != i else 0 for j in range(N+1)] for i in range(N+1)]

    for i in range(M):
        a, b, c = map(int, input().split())
        link[a][b] = c
        link[b][a] = c

    link = wf(link)

    ans = MAX
    for per in list(itertools.permutations(r)):
        tmp = 0
        for i in range(R-1):
            tmp += link[per[i]][per[i+1]]
        ans = min(ans, tmp)
    print(int(ans))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# import sys
# input = sys.stdin.readline

def main():
    N = int(input())
    p = list(map(int, input().split()))

    ans = 0
    i = 0
    # while i < N:
    for i in range(N):
        if i+1 == p[i]:
            tmp = p[i]
            p[i] = p[i+1]
            p[i+1] = tmp
            ans += 1
            # i += 1
        # i += 1
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
# import sys
# input = sys.stdin.readline

def main():
    N = int(input())
    p = list(map(int, input().split())) + [N+1]

    ans = 0
    i = 1
    for i in range(N):
        if i+1 == p[i]:
            tmp = p[i]
            p[i] = p[i+1]
            p[i+1] = tmp
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    p = list(map(int, input().split()))

    ans = 0
    i = 0
    # while i < N:
    for i in range(N):
        if i+1 == p[i]:
            tmp = p[i]
            p[i] = p[i+1]
            p[i+1] = tmp
            ans += 1
            # i += 1
        # i += 1
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
# import sys
# input = sys.stdin.readline

def main():
    N = int(input())
    p = list(map(int, input().split())) + [N+1]

    ans = 0
    i = 1
    for i in range(N):
        if i+1 == p[i]:
            tmp = p[i]
            p[i] = p[i+1]
            p[i+1] = tmp
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    p = list(map(int, input().split()))

    ans = 0
    i = 0
    while i < N:
        if i+1 == p[i]:
            tmp = p[i]
            p[i] = p[i+1]
            p[i+1] = tmp
            ans += 1
            i += 1
        i += 1
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
# import sys
# input = sys.stdin.readline

def main():
    N = int(input())
    p = list(map(int, input().split())) + [N+1]

    ans = 0
    i = 1
    for i in range(N):
        if i+1 == p[i]:
            tmp = p[i]
            p[i] = p[i+1]
            p[i+1] = tmp
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#include <stdio.h>

int main(void){
    int i, a, b, N, M, count[50];

    scanf("%d %d", &N, &M);

    for(i=0; i<M; i++){
        scanf("%d %d", &a, &b);
        count[a-1] += 1;
        count[b-1] += 1;
    }

    for (i = 0; i < N; i++)
    {
        printf("%d\n", count[i]);
    }
    

    return 0;
}

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    
    count = [0] * N

    for i in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        count[a] += 1
        count[b] += 1
    
    for i in range(N):
        print(count[i])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def unite(node_a, node_b):
    root_a = node_a.root()
    root_b = node_b.root()
    if root_a == root_b:
        return False
    # if root_b.depth > root_a.depth:
    #     root_a, root_b = root_b, root_a
    root_b.is_root = False
    root_b.parent = root_a
    root_a.depth = max(root_a.depth, root_b.depth+1)
    return True

class Node:
    def __init__(self, id):
        self.id = id
        self.is_root = True
        self.parent = None
        self.depth = 1
    
    def root(self):
        if self.is_root:
            return self
        elif self.parent.is_root:
            return self.parent
        else:
            self.parent = self.parent.root()
            return self.parent

def main():
    N, K, L = map(int, input().split())
    
    trains = [Node(i) for i in range(N)]
    streets = [Node(i) for i in range(N)]

    for i in range(K):
        p, q = map(int, input().split())
        p -= 1; q -= 1
        unite(trains[p], trains[q])
    for i in range(L):
        r, s = map(int, input().split())
        r -= 1; s -= 1
        unite(streets[r], streets[s])
    dic = {}
    roots = []
    for i in range(N):
        tmp = (trains[i].root().id, streets[i].root().id)
        roots.append(tmp)
        if tmp in dic:
            dic[tmp] += 1
        else:
            dic[tmp] = 1
    
    for i in range(N-1):
        print(dic[roots[i]], end=" ")
    print(dic[roots[N-1]])

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def unite(node_a, node_b):
    root_a = node_a.root()
    root_b = node_b.root()
    if root_a == root_b:
        return False
    if root_b.depth > root_a.depth:
        root_a, root_b = root_b, root_a
    root_b.is_root = False
    root_b.parent = root_a
    root_a.depth = max(root_a.depth, root_b.depth+1)
    return True

class Node:
    def __init__(self, id):
        self.id = id
        self.is_root = True
        self.parent = None
        self.depth = 1
    
    def root(self):
        if self.is_root:
            return self
        elif self.parent.is_root:
            return self.parent
        else:
            self.parent = self.parent.root()
            return self.parent

def main():
    N, K, L = map(int, input().split())
    
    trains = [Node(i) for i in range(N)]
    streets = [Node(i) for i in range(N)]

    for i in range(K):
        p, q = map(int, input().split())
        p -= 1; q -= 1
        unite(trains[p], trains[q])
    for i in range(L):
        r, s = map(int, input().split())
        r -= 1; s -= 1
        unite(streets[r], streets[s])
    dic = {}
    roots = []
    for i in range(N):
        tmp = (trains[i].root().id, streets[i].root().id)
        roots.append(tmp)
        if tmp in dic:
            dic[tmp] += 1
        else:
            dic[tmp] = 1
    
    for i in range(N-1):
        print(dic[roots[i]], end=" ")
    print(dic[roots[N-1]])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    sa = input().strip()
    sb = input().strip()
    sc = input().strip()
    
    rest_a = 0
    rest_b = 0
    rest_c = 0
    rest_a += 1
    next_ = sa[0]
    while True:
        if next_ == "a":
            if rest_a == len(sa) - 1:
                print("A")
                break
            else:
                next_ = sa[rest_a]
                rest_a += 1
        elif next_ == "b":
            if rest_b == len(sb) - 1:
                print("B")
                break
            else:
                next_ = sb[rest_b]
                rest_b += 1
        elif next_ == "c":
            if rest_c == len(sc) - 1:
                print("C")
                break
            else:
                next_ = sc[rest_c]
                rest_c += 1

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    a = input().strip() + "w"
    b = input().strip() + "w"
    c = input().strip() + "w"

    i, j, k = 0, 0, 0
    now = "a"
    while True:
        # print(now, i, j, k)
        if now == "a":
            now = a[i]
            i += 1
            if now == "w":
                win = "a"
                break
        elif now == "b":
            now = b[j]
            j += 1
            if now == "w":
                win = "b"
                break
        else:
            now = c[k]
            k += 1
            if now == "w":
                win = "c"
                break

    if win == "a":
        print("A")
    elif win == "b":
        print("B")
    else:
        print("C")

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N, X = map(int, input().split(" "))

e_long = max(X, N-X)
e_short = N - e_long

total = N

while e_long != e_short and e_long > 0 and e_short > 0:
    total += e_short * 2
    e_long -= e_short
    if e_short > e_long:
        tmp = e_long
        e_long = e_short
        e_short = tmp

total += e_short

print(total)

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N, X = map(int, input().split())
    ans = N
    min_ = min(X, N-X)
    max_ = max(X, N-X)
    while min_ != 0:
        # print(max_, min_)
        ans += (max_ // min_) * 2 * min_
        tmp = max_ % min_
        max_ = min_
        min_ = tmp
    ans -= max_
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
int main() {
	string s,t;
	cin>>s>>t;
	for(char c='a';c<='z';c++)
		if(s+c==t) puts("Yes"),exit(0);
	puts("No"); 
	return 0;
}

Fixed submission:
S = input()
T = input()
S_len = len(S)
 
if S_len+1 == len(T) and S == T[:S_len:1]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
 N, M = map(int,input().split())
 A = list(map(int,input().split()))
 S = sum(A)
 cnt = 0
 for a in A:
    if a >= S / (4*M):
      cnt += 1
 if cnt >= M:
  print("Yes")
 else:
  print("No")

Fixed submission:
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
S = sum(A)
if A[M-1] >= S / (4*M):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [0]
for i in range(1, n):
    dp += [min([dp[-j] + abs(h[i] - h[i - j]) for j in range(1, min(i, k) + 1)])]
print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [0]
for i in range(1, n):
    dp += [min([dp[-j] + abs(h[i] - h[i - j]) for j in range(1, min(i, k) + 1)])]
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n , m = map(int , input().split())
dp = []
for i in range(n + 1):
    dp.append([])
    for j in range(m + 1):
        dp[i].append(0)
arr = []
for i in range(n):
    arr.append(input())
dp[1][1] = 1
for i in range(1,n + 1):
    for j in range(1,m + 1):
        if arr[i - 1][j - 1] == '#' or (i == 1 and j == 1):
            continue
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
print(dp[n][m] % 1000000007

Fixed submission:
n , m = map(int , input().split())
dp = []
for i in range(n + 1):
    dp.append([])
    for j in range(m + 1):
        dp[i].append(0)
arr = []
for i in range(n):
    arr.append(input())
dp[1][1] = 1
for i in range(1,n + 1):
    for j in range(1,m + 1):
        if arr[i - 1][j - 1] == '#' or (i == 1 and j == 1):
            continue
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
print(dp[n][m] % 1000000007)
Buggy python submission (verdict: Runtime Error):
s = input()
 
n = len(s)
 
ans = 0
 
cunt = 0
 
for i in range(n):
    if s[i] == "B":
        cnt += 1
    else:
        ans += cunt
print(ans)

Fixed submission:
s = input()
 
n = len(s)
 
ans = 0
 
cunt = 0
 
for i in range(n):
    if s[i] == "B":
        cunt += 1
    else:
        ans += cunt
print(ans)
Buggy python submission (verdict: Runtime Error):
q,h,re,d = map(int,input().split())
n = int(input())
re = min(q*4, h*2,result)
print(min(result*n, n//2*d + (n%2)*re))

Fixed submission:
q,h,re,d = map(int,input().split())
n = int(input())
re = min(q*4, h*2,re)
print(min(re*n, n//2*d + (n%2)*re))