Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03491 (python)

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

class Node:
    def __init__(self, sigma, depth):
        self.end = False
        self.child = [None] * sigma
        self.depth = depth
    def __setitem__(self, i, x):
        self.child[i] = x
    def __getitem__(self, i):
        return self.child[i]

sigma = 2
root = Node(sigma, 0)
def add_trie(S):
    vn = root
    for cs in S:
        if vn[cs] is None:
            vn[cs] = Node(sigma, vn.depth + 1)
        vn = vn[cs]
    vn.end = True

ans = 0

N, L = map(int, readline().split())

for _ in range(N):
    S = list(map(int, readline().strip()))
    add_trie(S)

cnt = 0
stack = [root]
while stack:
    vn = stack.pop()
    for i in range(2):
        if vn[i] is None:
            r = L - vn.depth
            cnt ^= -r&r
        else:
            stack.append(vn[i])

print('Alice' if cnt else 'Bob')

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

class Node:
    def __init__(self, sigma, depth):
        self.end = False
        self.child = [None] * sigma
        self.depth = depth
    def __setitem__(self, i, x):
        self.child[i] = x
    def __getitem__(self, i):
        return self.child[i]

class Trie():
    def __init__(self, sigma):
        self.sigma = sigma
        self.root = Node(sigma, 0)
    
    def add(self, S):
        vn = self.root
        for cs in S:
            if vn[cs] is None:
                vn[cs] = Node(sigma, vn.depth + 1)
            vn = vn[cs]
        vn.end = True

ans = 0

N, L = map(int, readline().split())

Tr = Trie(2)

for _ in range(N):
    S = list(map(int, readline().strip()))
    Tr.add(S)

cnt = 0
stack = [Tr.root]
while stack:
    vn = stack.pop()
    for i in range(2):
        if vn[i] is None:
            r = L - vn.depth
            cnt ^= -r&r
        else:
            stack.append(vn[i])

print('Alice' if cnt else 'Bob')

Buggy submission (verdict: Runtime Error):
        import sys
        readline = sys.stdin.readline
        
        N, L = map(int, readline().split())
        node = set([1])
        for _ in range(N):
            S = list(map(int, readline().strip()))
            ls = len(S)
            pre = 1
            for s in S:
                vn = 2*pre + s
                if vn not in node:
                    node.add(vn)
                pre = vn
        cnt = 0
        for d in node:
            h = 0
            if 2*d in node:
                h += 1
            if 2*d+1 in node:
                h += 1
            if h == 1:
                depth = L-d.bit_length()+1
                cnt ^= (-depth&depth)
        
        print('Alice' if cnt else 'Bob')
Problem p03504 (python)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
N, C = inpl()
channel = [[] for _ in range(C)]
for i in range(N):
    s, t, c = inpl()
    channel[c-1].append([s,t])
H = [0 for i in range(10**5+3)]
for i in range(C):
    channel[i].sort(key = lambda x: x[0])
    for j in range(len(channel[i])-1):
        if channel[i][j][1] == channel[i][j+1][0]:
            channel[i][j+1] = [channel[i][j][0],channel[i][j+1][1]]
            channel[i][j] = []
    channel[i] = [k for k in channel[i] if k != []]

for i in range(C):
    for st, en in channel[i]:
        H[st] += 1
        H[en+1] -= 1
ans = H[0]
for i in range(10**5+1):
    H[i+1] += H[i]
    ans = max(ans,H[i+1])
        
print(ans)

Buggy submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]
N, C = inpl()
channel = [[] for _ in range(C)]
for i in range(N):
    s, t, c = inpl()
    channel[c-1].append([s,t])
H = [0 for i in range(10**5+3)]
for i in range(C):
    channel[i].sort(key = lambda x: x[0])
    for j in range(len(channel[i])-1):
        if channel[i][j][1] == channel[i][j+1][0]:
            channel[i][j+1] = [channel[i][j][0],channel[i][j+1][1]]
            channel[i][j] = []
        channel[i] = [k for k in channel[i] if k != []]

for i in range(C):
    for st, en in channel[i]:
        H[st] += 1
        H[en+1] -= 1
ans = H[0]
for i in range(10**5+1):
    H[i+1] += H[i]
    ans = max(ans,H[i+1])
        
print(ans)

Buggy submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]
N, C = inpl()
channel = [[] for _ in range(C)]
for i in range(N):
    s, t, c = inpl()
    channel[c-1].append([s,t])
H = [0 for i in range(10**5+1)]
for i in range(C):
    channel[i].sort(key = lambda x: x[0])
    for j in range(len(channel[i])-1):
        if channel[i][j][1] == channel[i][j][0]:
            channel[i][j+1] = [channel[i][j][0],channel[i][j+1][1]]
            channel[i][j] = []
        channel[i][j] = [i for i in channel[i][j] if i != []]

for i in range(C):
    for st, en in channel[i]:
        H[st] += 1
        H[en+1] -= 1
ans = H[0]
for i in range(10**5):
    H[i+1] += H[i]
    ans = max(ans,H[i+1])
        
print(ans)
Problem p03560 (python)

Fixed submission:
import sys
from collections import deque
readline = sys.stdin.readline

K = int(readline())

inf = 10**9+7
dist = [inf]*(K+1)
dist[K] = 0
Q = deque([K])
used = [False]*(K+1)
while Q:
    vn = Q.pop()
    if used[vn]:
        continue
    used[vn] = True
    vf = (vn*10)%K
    if vn%K and not used[vf]:
        dist[vf] = min(dist[vf], dist[vn])
        Q.append(vf)
    vf = (vn+1)%K
    if not used[(vn+1)%K]:
        dist[vf] = min(dist[vf], 1+dist[vn])
        Q.appendleft(vf)
print(dist[0])

Buggy submission (verdict: Runtime Error):
from collections import deque
readline = sys.stdin.readline

K = int(readline())

inf = 10**9+7
dist = [inf]*(K+1)
dist[K] = 0
Q = deque([K])
used = [False]*(K+1)
while Q:
    vn = Q.pop()
    if used[vn]:
        continue
    used[vn] = True
    vf = (vn*10)%K
    if vn%K and not used[vf]:
        dist[vf] = min(dist[vf], dist[vn])
        Q.append(vf)
    vf = (vn+1)%K
    if not used[(vn+1)%K]:
        dist[vf] = min(dist[vf], 1+dist[vn])
        Q.appendleft(vf)
print(dist[0])
Problem p03608 (python)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
import heapq
from itertools import permutations

N, M, R = inpl()
r = inpl()
for i in range(R):
    r[i] -= 1
inf = float('inf')
Q = [[inf] * N for _ in range(N)]
path = [[0] * N for _ in range(N)]

for i in range(M):
    A,B,C = inpl()
    path[A-1][B-1] = path[B-1][A-1] = C

for i in r:
    decided = [False for _ in range(N)]
    H = []
    ctr = 0
    Q[i][i] = 0
    heapq.heappush(H,(0,i))
    while ctr != N:
        while True:
            k = heapq.heappop(H)
            k = k[1]
            if not decided[k]:
                decided[k] = True
                ctr += 1
                break
        for j in range(N):
            if path[k][j] == 0:
                continue
            if decided[j]:
                continue
            Q[i][j] = min(Q[i][k] + path[k][j], Q[i][j])
            heapq.heappush(H,(Q[i][j],j))

Ans = inf
for i in permutations(r):
    ans = 0
    for j in range(R-1):
        ans += Q[i[j]][i[j+1]]
    Ans = min(Ans,ans) 
        
print(Ans)

Buggy submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]
import heapq
from itertools import permutations

N, M, R = inpl()
r = inpl()
inf = 10**11
Q = [[inf] * N for _ in range(N)]
path = [[0] * N for _ in range(N)]

for i in range(M):
    A,B,C = inpl()
    path[A-1][B-1] = path[B-1][A-1] = C

for i in r:
    decided = [False for _ in range(N)]
    H = []
    ctr = 0
    Q[i][i] = 0
    heapq.heappush(H,(0,i))
    for _ in range(N):
        while True:
            k = heapq.heappop(H)
            k = k[1]
            if not decided[k]:
                decided[k] = True
                break
        for j in range(N):
            if path[k][j] == 0:
                continue
            if decided[j]:
                continue
            Q[i][j] = min(Q[i][k] + path[k][j], Q[i][j])
            heapq.heappush(H,(Q[i][j],j))

Ans = inf
for i in permutations(r):
    ans = 0
    for j in range(R-1):
        ans += Q[i[j]-1][i[j+1]-1]
    Ans = min(Ans,ans) 
        
print(Ans)
Problem p03627 (python)

Fixed submission:
from collections import defaultdict
edge = defaultdict(lambda: 0)
def inpl(): return [int(i) for i in input().split()]
N = int(input())
A = inpl()
for i in A:
    edge[i] += 1
doubled = []
for j,k in edge.items():
    if k >= 2:
        doubled.append(j)
    if k >= 4:
        doubled.append(j)
doubled = (sorted(doubled))
if len(doubled) < 2:
    print(0)
else:
    print(doubled[-1]*doubled[-2])

Buggy submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]

H, W = inpl()
ans = max(H, W)
S = ''
for _ in range(H):
    S += input()
T = [[0]*(W-1)]
for i in range(H-1):
    t = []
    for j in range(W-1):
        r = S[i*W+j] + S[i*W+j+1] + S[(i+1)*W+j] + S[(i+1)*W+j+1]
        t.append(r.count('.')%2)
    ts = [0]*(W-1)
    for i, k in enumerate(t):
        if k:
            continue
        ts[i] = T[-1][i] + 1
    T.append(ts)
for iT in T[1:]:
    stack = []
    for i, l in enumerate(iT):
        while stack:
            w, h = stack[-1]
            if h > l:
                dw, dh = stack.pop()
                ans = max(ans, (dh+1)*(i-dw+1))
                continue
            break
        stack.append((i, l))
    while stack:
        dw, dh = stack.pop()
        ans = max(ans, (dh+1)*(i-dw+2))
print(ans)
Problem p03633 (python)

Fixed submission:
def gcd(a,b):
    if a%b == 0:
        return b
    return gcd(b,a%b)

N = int(input())
ans = 1
for _ in range(N):
    A = int(input())
    ans = ans*A//gcd(ans,A)
print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
    
    if a == 1 or b == 1:
        return 1
    if a == b:
        return a
    if a > b:
        a,b = b,a
    if b%a == 0:
        return a
    b = b%a
    return gcd(a,b)

N = int(input())
A = 1

for _ in range(N):
    B = int(input())
    ans = int(A*B/gcd(A,B))
    A = ans
print(ans)
Problem p03661 (python)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
import numpy as np
ans = float('inf')
N = int(input())
a = np.cumsum(np.array(inpl()))
suma = a[-1]
a = np.delete(a, -1)
for i in a:
    ans = min(ans, abs(suma-2*i))
print(ans)

Buggy submission (verdict: Runtime Error):
print('?', 10**10)
if input() == 'Y':
    for nod in range(10):
        print('?', 10**nod+1)
        if input() == 'Y':
            break
    ans = 10**nod
else:
    for nod in range(1, 10):
        print('?', 10**nod)
        if input() == 'Y':
            continue
            nod -= 1
        break
    ok = 10**(nod-1)
    ng = 10**nod
    while abs(ok - ng) > 1:
        med = (ok + ng)//2
        print('?', med*10+1)
        if input() == 'N':
            ok = med
        else:
            ng = med
    ans = ok+1
print('!', ans)
Problem p03722 (python)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

N, M = inpl()
inf = float('inf')
path = [0 for _ in range(M)]
score = [-inf]*N
score[0] = 0
ans = 0
for i in range(M):
    a, b, c = inpl()
    path[i] = (a-1,b-1,c)

for i in range(N-1):
    update = False
    for na, nb, nc in path:
        if score[na] != -inf and score[nb] < score[na] + nc:
            score[nb] = score[na]+nc
            update = True
    if not update:
        break
ans = score[N-1]
for na, nb, nc in path:
        if score[na] != -inf and score[nb] < score[na] + nc:
            score[nb] = score[na]+nc
print(ans if ans == score[N-1] else 'inf')

Buggy submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]

N, M = inpl()
inf = float('inf')
path = [0 for _ in range(N)]
score = [-inf]*N
score[0] = 0
ans = 0
for i in range(M):
    a, b, c = inpl()
    path[i] = (a-1,b-1,c)

for i in range(N-1):
    update = False
    for na, nb, nc in path:
        if score[na] != -inf and score[nb] < score[na] + nc:
            score[nb] = score[na]+nc
            update = True
    if not update:
        break
ans = score[N-1]
for na, nb, nc in path:
        if score[na] != -inf and score[nb] < score[na] + nc:
            score[nb] = score[na]+nc
print(ans if ans == score[N-1] else 'inf')
Problem p03766 (python)

Fixed submission:
import sys
readline = sys.stdin.readline
MOD = 10**9+7
N = int(readline())

dp1 = [0]*(N+3)
Dp1 = [0]*(N+3)
dp2 = [0]*(N+3)
Dp2 = [0]*(N+3)
dp1[0] = 1
Dp1[0] = 1
dp2[0] = N-1
Dp2[0] = N-1
dp1[1] = N-1
dp2[1] = (N-1)**2
dp1[2] = N-1
dp2[2] = (N-1)**2
Dp1[1] = Dp1[0] + dp1[1]
Dp2[1] = Dp2[0] + dp2[1]
Dp1[2] = Dp1[1] + dp1[2]
Dp2[2] = Dp2[1] + dp2[2]
for i in range(3, N+1):
    dp1[i] = (dp1[i-1] + Dp1[i-3] - 1) % MOD
    dp2[i] = (dp2[i-1] + Dp2[i-3]) % MOD
    Dp1[i] = (Dp1[i-1] + dp1[i]) % MOD
    Dp2[i] = (Dp2[i-1] + dp2[i]) % MOD
print((Dp1[N-1] + Dp2[N-1]) % MOD)

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline
MOD = 10**9+7
N = int(readline())

dp1 = [0]*(N+1)
Dp1 = [0]*(N+1)
dp2 = [0]*(N+1)
Dp2 = [0]*(N+1)
dp1[0] = 1
Dp1[0] = 1
dp2[0] = N-1
Dp2[0] = N-1
dp1[1] = N-1
dp2[1] = (N-1)**2
dp1[2] = N-1
dp2[2] = (N-1)**2
Dp1[1] = Dp1[0] + dp1[1]
Dp2[1] = Dp2[0] + dp2[1]
Dp1[2] = Dp1[1] + dp1[2]
Dp2[2] = Dp2[1] + dp2[2]
for i in range(3, N+1):
    dp1[i] = (dp1[i-1] + Dp1[i-3] - 1) % MOD
    dp2[i] = (dp2[i-1] + Dp2[i-3]) % MOD
    Dp1[i] = (Dp1[i-1] + dp1[i]) % MOD
    Dp2[i] = (Dp2[i-1] + dp2[i]) % MOD
print((Dp1[N-1] + Dp2[N-1]) % MOD)
Problem p03791 (python)

Fixed submission:
from itertools import accumulate
from bisect import bisect
N = int(input())
X = list(map(int, input().split()))
mod = 10**9+7
T = [2 + i - (1+x)//2 for i, x in enumerate(X)]
T = list(accumulate(T, max))
D = [min(1 + bisect(T, i), N) - i + 1 for i in range(1, N + 1)]
ans = 1
for d in D:
    ans = (ans * d)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from bisect import bisect
N = int(input())
X = list(map(int, input().split()))
mod = 10**9+7
T = [2 + i - (1+x)//2 for i, x in enumerate(X)]
T = list(accumulate(T, max))
D = [min(1 + bisect(T, i), N) - i + 1 for i in range(1, N + 1)]
ans = 1
for d in D:
    ans = (ans * d)%mod
print(ans)
Problem p03810 (python)

Fixed submission:
import sys
readline = sys.stdin.readline
from functools import reduce
def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

def calc(A):
    N = len(A)
    if N == 1:
        return A[0]%2 == 0

    K = sum(1 for a in A if a % 2 == 0)
    if K & 1:
        return True
    if N-K != 1:
        return False
    if min(A) == 1:
        return False
    A = [a-a%2 for a in A]
    g = reduce(gcd, A)
    A = [a//g for a in A]
    return not calc(A)


N = int(readline())
A = list(map(int, readline().split()))
print('First' if calc(A) else 'Second')

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline
from functools import reduce
def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

def calc(A):
    N = len(A)
    K = sum(1 for a in A if a % 2 == 0)
    if K & 1:
        return True
    if N-1 != K:
        return False
    A = [a-a%2 for a in A]
    g = reduce(gcd, A)
    A = [a//g for a in A]
    return not calc(A)


N = int(readline())
A = list(map(int, readline().split()))
print('First' if calc(A) else 'Second')
Problem p03848 (python)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
import sys
from collections import defaultdict
H = defaultdict(lambda: 0)
N = int(input())
A = inpl()
mod = 10**9+7
if N%2:
    H[0] = -1
    for i in range(1, 1+N//2):
        H[2*i] = -2
else:
    for i in range(1, 1+N//2):
        H[2*i-1] = -2
for i in A:
    H[i] += 1
H = list(H.values())
if any(H):
    print(0)
    sys.exit()
print(2**(N//2)%mod)

Buggy submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]
import sys
N = int(input())
A = inpl()
H = dict([])
if N%2:
    H[0] = -1
    for i in range(1, 1+N//2):
        H[2*i] = -2
else:
    for i in range(1, 1+N//2):
        H[2*i-1] = -2
for i in A:
    H[i] += 1
H = list(H.values())
if any(H):
    print(0)
    sys.exit()
print(2**(N//2))
Problem p03857 (python)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
class UnionFind():
    def __init__(self, num):
        self.par = [-1 for _ in range(num)]
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            x = self.par[x]
            return self.find(x)
    
    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            if self.par[rx] < self.par[ry]:
                self.par[ry] = rx
            if self.par[rx] > self.par[ry]:
                self.par[rx] = ry
            else:
                self.par[rx] -= 1
                self.par[ry] = rx
        return

N, K, L = inpl()
ufk = UnionFind(N)
for i in range(K):
    p, q = inpl()
    ufk.union(p-1, q-1)

ufr = UnionFind(N)
for i in range(L):
    r, s = inpl()
    ufr.union(r-1, s-1)

from collections import defaultdict
ans = defaultdict(lambda: 0)
for i in range(N):
    ans[ufk.find(i),ufr.find(i)] +=1
Ans = [0 for _ in range(N)]
for i in range(N):
    Ans[i] = ans[ufk.find(i),ufr.find(i)]
print(*Ans)

Buggy submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]

def root(x,par):
    if par[x] == x:
        return [x,[x]]
    else:
        return [root(par[x],par)[0],root(par[x],par)[1]+[x]]


N, K, L = inpl()
parK = list(range(N))
for i in range(K):
    p, q = inpl()
    rp = root(p-1,parK)
    rq = root(q-1,parK)
    if len(rp[1]) < len(rq[1]) :
        parK[rq[0]] = rp[0] 
    else:
        parK[rp[0]] = rq[0]
    print(parK)

parL = list(range(N))
for i in range(L):
    r, s = inpl()
    rr = root(r-1,parL)
    rs = root(s-1,parL)
    for i in rr[1]:
        parL[i] = rr[0]
    for j in rs[1]:
        parL[j] = rr[0]

from collections import defaultdict
ans = defaultdict(lambda: 0)
for i in range(N):
    ans[root(i,parK)[0],root(i,parL)[0]] +=1
Ans = [0 for _ in range(N)]
for i in range(N):
    Ans[i] = ans[root(i,parK)[0],root(i,parL)[0]]
print(*Ans)
Problem p03866 (python)

Fixed submission:
def flpl(): return [float(i) for i in input().split()]
def inpl(): return [int(i) for i in input().split()]
import heapq
def dijkstra(vnum, vs):
    dist = [float('inf') for _ in range(vnum)]
    dist[vs] = 0 
    remain = set(range(vnum))
    Q = []
    heapq.heappush(Q,(0,vs))
    while Q:
        c, vn = heapq.heappop(Q)
        if vn not in remain :
            continue
        remain.remove(vn)
        for j in remain:
            evnj = edge(vn, j)
            if dist[vn] + evnj < dist[j]:
                dist[j] = dist[vn] + evnj 
                heapq.heappush(Q,(dist[j],j)) 
        if not remain:
            break
    return dist
def edge(s, t):
    return max(((X[s] - X[t])**2 + (Y[s] - Y[t])**2)**(1/2) -(R[s]+R[t]), 0)

xs, ys, xt, yt = flpl()
N = int(input())
xyr = [(xs, ys, 0),(xt, yt, 0)] + [inpl() for _ in range(N)]
X, Y, R = list(map(list, zip(*xyr)))
D = dijkstra(N+2, 0)
print(D[1])

Buggy submission (verdict: Runtime Error):
def flpl(): return [float(i) for i in input().split()]
def inpl(): return [int(i) for i in input().split()]
import numpy as np
import heapq

xs, ys, xt, yt = flpl()
N = int(input())
xyr = [(xs, ys, 0),(xt, yt, 0)] + [inpl() for _ in range(N)]
X, Y, R = np.array(xyr).T
X, Y, R = np.tile(X, (N+2, 1)), np.tile(Y, (N+2, 1)), np.tile(R, (N+2, 1))
edge = np.maximum(np.zeros((N+2, N+2)), np.sqrt(np.square(X-X.T) +\
                  np.square(Y-Y.T))-(R+R.T)) +\
                  np.diag(np.ones(N+2)*np.inf)

dist = np.array([np.inf for _ in range(N+2)])
dist[0] = 0 
remain = set(range(N+2))
Q = []
heapq.heappush(Q,(0,0))
while Q:
    c, vn = heapq.heappop(Q)
    if vn not in remain or c > dist[c]:
        continue
    remain.remove(vn)
    for j in remain:
        if dist[vn] + edge[vn][j] < dist[j]:
            dist[j] = dist[vn] + edge[vn][j] 
            heapq.heappush(Q,(dist[j],j)) 
    if 1 not in remain:
        break
print(dist[1])
Problem p03987 (python)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
N = int(input())
a = inpl()
b = {a[i]: i for i in range(N)}

left = list(range(N+2))
right = list(range(N+2))

ans = 0
for i in range(N,0,-1):
    x = b[i]
    ans += i*(right[x]-x +1)*(x-left[x] +1)
    right[left[x] - 1] = right[x]
    left[right[x] + 1] = left[x]
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
def inpl(): return [int(i) for i in input().split()]
def minisum(x):
    mini = np.argmin(x)
    d = len(x)
    if d == 1:
        return x[0]
    result = 0
    if mini != 0:
        result += minisum(x[0:mini])
    if mini != d-1:
        result += minisum(x[mini+1:d])
    return result + (d-mini)*(mini+1)*x[mini]

N = input()
a = np.array(inpl())
print(minisum(a))

Buggy submission (verdict: Runtime Error):
import numpy as np
def inpl(): return [int(i) for i in input().split()]
def minisum(x):
    mini = np.argmin(x)
    d = len(x)
    if d == 0:
        return 0
    if d == 1:
        return x[0]
    result = 0
    if mini != 0:
        result += minisum(x[:mini])
    if mini != d-1:
        result += minisum(x[mini+1:])
    return result + (d-mini)*(mini+1)*x[mini]

N = input()
a = np.array(inpl())
print(minisum(a))

Buggy submission (verdict: Runtime Error):
import numpy as np
def inpl(): return [int(i) for i in input().split()]
def minisum(x):
    mini = np.argmin(x)
    d = len(x)
    result = 0
    if mini != 0:
        result += minisum(x[0:mini])
    if mini != d-1:
        result += minisum(x[mini+1:d])
    return result + (d-mini)*(mini+1)*x[mini]

N = input()
a = np.array(inpl())
print(minisum(a))

Buggy submission (verdict: Runtime Error):
import numpy as np
def inpl(): return [int(i) for i in input().split()]
def minisum(x):
    mini = np.argmin(x)
    d = len(x)
    if d == 1:
        return x[0]
    result = 0
    if mini != 0:
        result += minisum(x[0:mini])
    if mini != d-1:
        result += minisum(x[mini+1:d])
    return result + (d-mini)*(mini+1)*x[mini]

N = input()
a = np.array(inpl())
print(minisum(a))