Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
for _ in range(M):
    B, C = map(int, input().split(' '))
    A.extend([C]*B)
    A = sorted(A)[-N:]
print(sum(A))

Fixed submission:
N, M = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
BC_list = []
for _ in range(M):
    B, C = map(int, input().split(' '))
    BC_list.append((B, C))
BC_list = sorted(BC_list, key= lambda x: x[1], reverse=True)

for b, c in BC_list:
    A.extend([c]*b)
    if len(A) > 2*N:
        break
print(sum(sorted(A)[-N:]))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
for _ in range(M):
    B, C = map(int, input().split(' '))
    A.extend([C]*B)
print(sum(sorted(A)[-N:]))

Fixed submission:
N, M = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
BC_list = []
for _ in range(M):
    B, C = map(int, input().split(' '))
    BC_list.append((B, C))
BC_list = sorted(BC_list, key= lambda x: x[1], reverse=True)

for b, c in BC_list:
    A.extend([c]*b)
    if len(A) > 2*N:
        break
print(sum(sorted(A)[-N:]))
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split(' '))
S = input()

for _ in range(Q):
    cnt = 0
    l, r = map(int, input().split(' '))
    p_S = S[l-1:r]
    for i in range(len(p_S)-1):
        if p_S[i:i+2] == 'AC':
            cnt += 1
    print(cnt)

Fixed submission:
N, Q = map(int, input().split()) 
S = input()
tmp = [0] * (N+1)

for i in range(N):
    which = (1 if S[i : i + 2] == 'AC' else 0)
    tmp[i + 1] = tmp[i] + which
for _ in range(Q):
    l, r = map(int, input().split())
    print(tmp[r-1] - tmp[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
dp = np.zeros((N+1, 3), dtype=int)
for i in range(1, N+1):
    lst = np.array(list(map(int, input().split(' '))))
    dp[i][0] = np.max(dp[i-1][[1,2]] + lst[[1,2]])
    dp[i][1] = np.max(dp[i-1][[0,2]] + lst[[0,2]])
    dp[i][2] = np.max(dp[i-1][[0,1]] + lst[[0,1]])
print(np.max(dp[-1]))

Fixed submission:
import numpy as np
N = int(input())
dp = np.zeros((N+1, 3), dtype=int)
for i in range(1, N+1):
    a, b, c = list(map(int, input().split(' ')))
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c
print(np.max(dp[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
dp = np.zeros((N+1, 3), dtype=int)
for i in range(1, N+1):
    lst = np.array(list(map(int, input().split(' '))))
    dp[i][0] = max(dp[i-1][[1,2]] + lst[[1,2]])
    dp[i][1] = max(dp[i-1][[0,2]] + lst[[0,2]])
    dp[i][2] = max(dp[i-1][[0,1]] + lst[[0,1]])

print(max(dp[-1]))

Fixed submission:
import numpy as np
N = int(input())
dp = np.zeros((N+1, 3), dtype=int)
for i in range(1, N+1):
    a, b, c = list(map(int, input().split(' ')))
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c
print(np.max(dp[-1]))
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split(' '))
pair = [tuple(map(int, input().split(' '))) for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(N):
    for sum_w in range(W+1):
        if sum_w >= pair[i][0]:
            dp[i+1][sum_w] = max(dp[i][sum_w], dp[i][sum_w-pair[i][0]] + pair[i][1])
        else:
            dp[i+1][sum_w] = dp[i][sum_w]
print(dp[-1][-1])

Fixed submission:
N, W = map(int, input().split(' '))
pair = [tuple(map(int, input().split(' '))) for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(N):
    for sum_w in range(W+1):
        if sum_w >= pair[i][0]:
            dp[i+1][sum_w] = max(dp[i][sum_w], dp[i][sum_w-pair[i][0]] + pair[i][1])
        else:
            dp[i+1][sum_w] = dp[i][sum_w]
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, W = map(int, input().split(' '))
pair = [tuple(map(int, input().split(' '))) for _ in range(N)]
dp = np.zeros((N+1, W+1), dtype=int)
for i in range(N):
    for sum_w in range(W+1):
        if sum_w >= pair[i][0]:
            dp[i+1][sum_w] = max(dp[i][sum_w], dp[i][sum_w-pair[i][0]] + pair[i][1])
        else:
            dp[i+1][sum_w] = dp[i][sum_w]
print(dp[-1][-1])

Fixed submission:
N, W = map(int, input().split(' '))
pair = [tuple(map(int, input().split(' '))) for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(N):
    for sum_w in range(W+1):
        if sum_w >= pair[i][0]:
            dp[i+1][sum_w] = max(dp[i][sum_w], dp[i][sum_w-pair[i][0]] + pair[i][1])
        else:
            dp[i+1][sum_w] = dp[i][sum_w]
print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]

def backtrack(dp, s, t, i, j):
    if i == 0 or j == 0:
        return ''
    if s[i-1] == t[j-1]:
        return backtrack(dp, s, t, i-1, j-1) + s[i-1]
    if dp[i][j-1] > dp[i-1][j]:
        return backtrack(dp, s, t, i, j-1)
    return backtrack(dp, s, t, i-1, j)

for i in range(1, len(s)+1):
    for j in range(1, len(t)+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1)
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])
print(backtrack(dp, s, t, len(s), len(t)))

Fixed submission:
import sys
sys.setrecursionlimit(200000)
s = input()
t = input()
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]

def backtrack(dp, s, t, i, j):
    if i == 0 or j == 0:
        return ''
    if s[i-1] == t[j-1]:
        return backtrack(dp, s, t, i-1, j-1) + s[i-1]
    if dp[i][j-1] > dp[i-1][j]:
        return backtrack(dp, s, t, i, j-1)
    return backtrack(dp, s, t, i-1, j)

for i in range(1, len(s)+1):
    for j in range(1, len(t)+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1)
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])
print(backtrack(dp, s, t, len(s), len(t)))
Buggy python submission (verdict: Time Limit Exceeded):
#https://atcoder.jp/contests/abc051/tasks/abc051_b
K, S = map(int, input().split(' '))

cnt = 0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x + y + z == S:
                cnt += 1
print(cnt)

Fixed submission:
#https://atcoder.jp/contests/abc051/tasks/abc051_b
K, S = map(int, input().split(' '))
cnt = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - (x + y)
        if 0 <= z <= K:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
# N = int(input())
# K = list(map(int, input().split()))
# N, M = map(int, input().split())

S = list(input())

# print(int(''.join(S)) / 2019)
# print(int(''.join(S)) % 2019)

cnt = 0

# for i in range(0,len(S)-3) :
#     for j in range(i+3, len(S)) :
#         # print(int(''.join(S[i:j+1])))
#         res = int(''.join(S[i:j+1]))
#         if res % 2019 == 0 :
#             cnt += 1
#             print(S[i:j+1])

for i in range(0,len(S)-3) :
    amari = int(''.join(S[i:i+3]))
    for j in range(i+3, len(S)) :
        amari = ((amari * 10) + int(S[j])) % 2019
        if amari == 0 :
            cnt += 1

print(cnt)

Fixed submission:
S = input()
P =2019
ans = 0

count = [0] * P
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
    u = (int(s) * pow(10, i, P) + u) % P
    ans += count[u]
    count[u] += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# N = int(input())
# K = list(map(int, input().split()))
# N, M = map(int, input().split())

S = list(input())

cnt = 0

for i in range(0,len(S)-3) :
    for j in range(i+3, len(S)) :
        # print(int(''.join(S[i:j+1])))
        res = int(''.join(S[i:j+1]))
        if res % 2019 == 0 :
            cnt += 1

print(cnt)

Fixed submission:
S = input()
P =2019
ans = 0

count = [0] * P
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
    u = (int(s) * pow(10, i, P) + u) % P
    ans += count[u]
    count[u] += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)

result = 0
for i in range(N-2) :
  for j in range(i+1,N-1) :
    for k in range(j+1,N) :
      if L[i] < L[j] + L[k] :
        result += 1

print(result)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()

result = 0
for i in range(N) :
  for j in range(i+1,N) :
    result += bisect_left(L,L[i]+L[j]) - (j+1)

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

result = 0
for i in list(itertools.combinations(range(N),3)) :
  if L[i[0]] < L[i[1]] + L[i[2]] and L[i[1]] < L[i[0]] + L[i[2]] and L[i[2]] < L[i[1]] + L[i[0]] :
    result += 1

print(result)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()

result = 0
for i in range(N) :
  for j in range(i+1,N) :
    result += bisect_left(L,L[i]+L[j]) - (j+1)

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
result = []

for i in range(N) :
  for j in range(int(N/2)+1) :
    if A[j] == i+1 :
      print(j+1, end="")
      print(" ", end="")
      break
    elif A[N-1-j] == i+1 :
      print(N-j, end="")
      print(" ", end="")
      break
  

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
result = [0 for i in range(N)]
  
for i in range(N) :
  result[A[i]-1] = i+1

for i in range(N) :
  print(result[i], end="")
  print(" ", end="")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
result = []

for i in range(N) :
  print(A.index(i+1)+1, end="")
  print(" ", end="")

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
result = [0 for i in range(N)]
  
for i in range(N) :
  result[A[i]-1] = i+1

for i in range(N) :
  print(result[i], end="")
  print(" ", end="")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
result = []

for i in range(N) :
  print(A.index(i+1)+1, end="")
  if (i+1) != N :
    print(" ", end="")


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
result = [0 for i in range(N)]
  
for i in range(N) :
  result[A[i]-1] = i+1

for i in range(N) :
  print(result[i], end="")
  print(" ", end="")
Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())

cnt = 0
s = b - a + 1
cd = (c*d) // math.gcd(c,d)

m1 = int((a-1) / c)
m2 = int((b+1) / c)
cnt += (m2-m1)

m1 = int((a-1) / d)
m2 = int((b+1) / d)
cnt += (m2-m1)

m1 = int((a-1) / cd)
m2 = int((b+1) / cd)
cnt -= (m2-m1)

#print(cnt)
print(s - cnt)

Fixed submission:
from fractions import gcd
a, b, c, d = map(int, input().split())

cnt = 0
s = b - a + 1
cd = (c*d) // gcd(c,d)

m1 = int((a-1) // c)
m2 = int(b // c)
cnt += (m2-m1)
#print(cnt)

m1 = int((a-1) // d)
m2 = int(b // d)
cnt += (m2-m1)
#print(cnt)

m1 = int((a-1) // cd)
m2 = int(b // cd)
cnt -= (m2-m1)
#print(cnt)

#print(cnt)
print(s - cnt)
Buggy python submission (verdict: Runtime Error):
import math, itertools

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

gcdl = []
coml = list(itertools.combinations(a,2))

for x in range(len(coml)) :
    gcdl.append(math.gcd(coml[x][0], coml[x][1])) 

gcdl.sort()
min = gcdl[0]
for x in range(1, len(coml)) :
    if min != gcdl[x] :
        break

print(gcdl[x])

Fixed submission:
import fractions

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

gcdl = [0]
gcdr = [0]

for i in range(n-1) :
    gcdl.append(fractions.gcd(gcdl[i], a[i]))
    gcdr.append(fractions.gcd(gcdr[i], a[-(i+1)]))
gcdr = gcdr[::-1]

ans = []
for i in range(n) :
    ans.append(fractions.gcd(gcdl[i], gcdr[i]))

print(max(ans))

Buggy python submission (verdict: Runtime Error):
import math, itertools

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

gcdl = []
coml = list(itertools.combinations(a,2))

for x in range(len(coml)) :
    gcdl.append(math.gcd(coml[x][0], coml[x][1])) 

gcdl.sort()
min = gcdl[0]
for x in range(1, len(coml)) :
    if min != gcdl[x] :
        break

print(gcdl[x])

Fixed submission:
import fractions

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

gcdl = [0]
gcdr = [0]

for i in range(n-1) :
    gcdl.append(fractions.gcd(gcdl[i], a[i]))
    gcdr.append(fractions.gcd(gcdr[i], a[-(i+1)]))
gcdr = gcdr[::-1]

ans = []
for i in range(n) :
    ans.append(fractions.gcd(gcdl[i], gcdr[i]))

print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A=list(map(int, input().split()))

c=1
path=[]
d={}
l=0
while l<=k:
    if c in path:
        p=d[c]
        #print(p, path)
        pattern_l = l-p
        k-=((k-p)//pattern_l)*pattern_l
    path.append(c)
    l+=1
    d[c]=l-1
    c=A[c-1]
print(path[k])


Fixed submission:
n, k = map(int, input().split())
A=list(map(int, input().split()))

c=1
path=[]
d={}
l=0
while l<=k:
    if c in d:
        p=d[c]
        #print(p, path)
        pattern_l = l-p
        k-=((k-p)//pattern_l)*pattern_l
    path.append(c)
    l+=1
    d[c]=l-1
    c=A[c-1]
print(path[k])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A=list(map(int, input().split()))

c=1
path=[]
while len(path)<=k:
    if c in path:
        p=path.index(c)
        pattern_l = len(path)-p
        k-=((k-p)//pattern_l)*pattern_l
    path.append(c)
    c=A[c-1]
print(path[k])


Fixed submission:
n, k = map(int, input().split())
A=list(map(int, input().split()))

c=1
path=[]
d={}
l=0
while l<=k:
    if c in d:
        p=d[c]
        #print(p, path)
        pattern_l = l-p
        k-=((k-p)//pattern_l)*pattern_l
    path.append(c)
    l+=1
    d[c]=l-1
    c=A[c-1]
print(path[k])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A_list = list(map(int, input().split()))

place = [0]

while True:
    next_place = A_list[place[-1]] - 1
    if next_place in place:
        idx = place.index(next_place)
        loop = place[idx:]
        break
    place.append(next_place)

if K < len(place):
    print(place[K] + 1)
else:
    print(loop[(K-idx)%len(loop)] + 1)

Fixed submission:
N, K = map(int, input().split())
A_list = list(map(int, input().split()))

place = [0]
table = [0] * N
table[0] = 1

while True:
    next_place = A_list[place[-1]] - 1
    if table[next_place] == 1:
        idx = place.index(next_place)
        loop = place[idx:]
        break
    table[next_place] = 1
    place.append(next_place)

if K < len(place):
    print(place[K] + 1)
else:
    print(loop[(K-idx)%len(loop)] + 1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

mp = [0] * n
#right = [0] * n

ans = 0

for i in range(n):
    ans += mp[i-a[i]]
    if n > a[i]+i:
        mp[a[i]+i] += 1

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

mp = [0] * n

ans = 0

for i in range(n):
    if i-a[i] >= 0:
        ans += mp[i-a[i]]
    if n > a[i]+i:
        mp[a[i]+i] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

left = []
right = []

for i in range(n):
    left.append(a[i]+i)
    right.append(i-a[i])
    
ans = 0

for i in range(n):
    for j in range(i+1, n):
        #print(i,j)
        if left[i]==right[j]:
            ans += 1

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

mp = [0] * n

ans = 0

for i in range(n):
    if i-a[i] >= 0:
        ans += mp[i-a[i]]
    if n > a[i]+i:
        mp[a[i]+i] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(n):
    for j in range(i+1,n):
        if a[i]+a[j] == j-i:
            ans += 1
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

mp = [0] * n

ans = 0

for i in range(n):
    if i-a[i] >= 0:
        ans += mp[i-a[i]]
    if n > a[i]+i:
        mp[a[i]+i] += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n,m,q,*abcd=list(map(int, Input.split()))
a=[]
b=[]
c=[]
d=[]

ans = 0

for i in range(q):
    a.append(abcd.pop(0))
    b.append(abcd.pop(0))
    c.append(abcd.pop(0))
    d.append(abcd.pop(0))
    
def dfs(la):
    global ans
    if len(la)==n+1:
        sum_d=0
        #print(la)
        #print(ans)
        for i in range(q):
            if la[b[i]] - la[a[i]] == c[i]:
                sum_d += d[i]
        if sum_d > ans:
            ans = sum_d
        return
    
    la.append(la[-1])
    while(la[-1]<=m):
        dfs(la.copy())
        la[-1] += 1
        

dfs([1])
print(ans)

Fixed submission:
#提出用
n,m,q = list(map(int, input().split()))

a=[]
b=[]
c=[]
d=[]

for i in range(q):
    aa,bb,cc,dd = list(map(int, input().split()))
    a.append(aa)
    b.append(bb)
    c.append(cc)
    d.append(dd)

ans = 0

def dfs(la):
    global ans
    if len(la)==n+1:
        sum_d=0
        #print(la)
        #print(ans)
        for i in range(q):
            if la[b[i]] - la[a[i]] == c[i]:
                sum_d += d[i]
        if sum_d > ans:
            ans = sum_d
        return
    
    la.append(la[-1])
    while(la[-1]<=m):
        dfs(la.copy())
        la[-1] += 1
        

dfs([1])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
h = list(map(int, input().split()))

cost = [0 for i in range(N)]
cost[0] = 0

for i in range(1,N):
    for j in range(1,K+1):
        if i-j<0:
            break
        #print(i,j)
        if j==1:
            cost_min = abs(h[i]-h[i-j]) + cost[i-j]
        else:
            cost_min = min(cost_min, abs(h[i]-h[i-j]) + cost[i-j])
    cost[i] = cost_min

print(cost[N-1])

Fixed submission:
N, K = list(map(int, input().split()))
h = list(map(int, input().split()))

cost = [0 for i in range(N)]
cost[0] = 0

for i in range(1,N):
    for j in range(1,K+1):
        if i-j<0:
            break
        #print(i,j)
        if j==1:
            cost_min = abs(h[i]-h[i-j]) + cost[i-j]
        else:
            cost_min = min(cost_min, abs(h[i]-h[i-j]) + cost[i-j])
    cost[i] = cost_min

print(cost[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

x=INT()

for i in range(-1*int(x**(1/5))-1,int(x**(1/5))+1):
    for j in range(-1*int(x**(1/5))-1,int(x**(1/5))+1):
        if i**5-j**5==x:
            print(i,j)
            exit()
while True:
    j+=1

Fixed submission:
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

x=INT()

for i in range(-500,501):
    for j in range(-500,501):
        if i**5-j**5==x:
            print(i,j)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

a,b,x=MAP()

def f(n):
    return (a*n)//b-a*(n//b)

ans=0
pre=0
for i in range(1,x+1):
    pre=f(i)
    #print(ans,pre)
    if ans<f(i):
        ans=pre

print(ans)


Fixed submission:
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

a,b,x=MAP()

def f(n):
    return (a*n)//b-a*(n//b)

if b<=x:
    print(f(b-1))
else:
    print(f(x))
Buggy python submission (verdict: Runtime Error):
n=int(input())
s,t=input().split()
for i in range(n):
    print(f"{s[i]}{t[i]}",end="")
print()

Fixed submission:
n=int(input())
s,t=input().split()
for i in range(n):
    print(s[i],end="")
    print(t[i],end="")
print()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(input())
# n=19
# s=list(str(3141592653589793238))
a=[0]*1000
s=[int(i) for i in s]
res=[0,0,0]
#print(s)
for i in range(0,n-2):
    b=100*s[i]
    for j in range(i+1,n-1):
        b2=b+10*s[j]
        for k in range(j+1,n):
            b3=b2+s[k]-1
            if a[b3]!=1:
                a[b3]+=1
print(sum(a))

Fixed submission:
n=int(input())
s=list(input())
s=[int(i) for i in s]
res=[[0 for i in range(10)]for i in range(n)]
for i in range(n-1,0,-1):
    for j in range(10):
        res[i-1][j]=res[i][j]
    res[i-1][s[i]]+=1
cnt=0
#print(res)
a=[0]*10
for i in range(n-2):
    if a[s[i]]!=0:
        continue
    a[s[i]]+=1
    b=[0]*10
    for j in range(i+1,n-1):
        if b[s[j]]==0:
            b[s[j]]+=1
            cnt+=10-res[j].count(0)

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)

n=int(input())
s=list(input())
a=[0 for i in range(1000)]
res=[0,0,0]
#cnt=0
def abc(i,cnt):
    global s,a,res
    if i==3:
        b=100*int(res[0])+10*int(res[1])+int(res[2])
        if a[b]!=1:
            a[b]+=1
    elif cnt>=n:
        pass
    else:
        if res[0]==0:
            res[0]=s[cnt]
            abc(i+1,cnt+1)
            res[0]=0
            abc(i,cnt+1)
        elif res[1]==0:
            res[1]=s[cnt]
            abc(i+1,cnt+1)
            res[1]=0
            abc(i,cnt+1)
        else:
            res[2]=s[cnt]
            abc(i+1,cnt+1)
            res[2]=0
            abc(i,cnt+1)
abc(0,0)
print(sum(a))

Fixed submission:
n=int(input())
s=list(input())
s=[int(i) for i in s]
res=[[0 for i in range(10)]for i in range(n)]
for i in range(n-1,0,-1):
    for j in range(10):
        res[i-1][j]=res[i][j]
    res[i-1][s[i]]+=1
cnt=0
#print(res)
a=[0]*10
for i in range(n-2):
    if a[s[i]]!=0:
        continue
    a[s[i]]+=1
    b=[0]*10
    for j in range(i+1,n-1):
        if b[s[j]]==0:
            b[s[j]]+=1
            cnt+=10-res[j].count(0)

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
s=sum(a)

s2=s/2
cnt=0
for i,k in zip(a,range(len(a))):
    cnt+=i
    if cnt>s/2:
        break
my2=True
if cnt-a[k]<s-cnt:#小さいほう
    res=0
    my=True
    b=cnt
    while my:
        b-=1
        s-=1
        res+=1
        if b==s/2:
            my=False
        if b<s/2:
            my=False
            my2=False
    if my2:
        print(res)
    else:
        print(0)
else:
    res=0
    my=True
    b=s-cnt+a[k]
    while my:
        b-=1
        s-=1
        res+=1
        if b==s/2:
            my=False
        if b<s/2:
            my=False
            my2=False
    if my2:
        print(res)
    else:
        print(0)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
s=sum(a)

s2=s/2
cnt=0
for i,k in zip(a,range(len(a))):
    cnt+=i
    if cnt>s/2:
        break
my2=True
if cnt-a[k]<s-cnt:#小さいほう
    res=0
    my=True
    b=cnt
else:
    res=0
    my=True
    b=s-cnt+a[k]

c=s-b
if s-(c*2)==b-c:
    print(int(b-c))
else:
    print(0)