Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)
from math import gcd

def lcm(a, b):
    return int(a * b / gcd(a, b))

def main():
    A, B, C, D = [int(c) for c in input().split()]
    N_U = (B) - (A - 1)
    N_C = B // C - (A - 1) // C
    N_D = B // D - (A - 1) // D
    N_C_D = int(B // lcm(C, D) - (A - 1) // lcm(C, D))
    excluded_N_C_D = N_C + N_D - N_C_D
    print(int(N_U - excluded_N_C_D))


if __name__ == '__main__':
    main()

Fixed submission:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
    return int(a * b / gcd(a, b))

def main():
    A, B, C, D = [int(c) for c in input().split()]
    N_U = (B) - (A - 1)
    N_C = B // C - (A - 1) // C
    N_D = B // D - (A - 1) // D
    N_C_D = int(B // lcm(C, D) - (A - 1) // lcm(C, D))
    excluded_N_C_D = N_C + N_D - N_C_D
    print(int(N_U - excluded_N_C_D))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    N, M = map(int, input().split())
    A = [0] * (N + 1)
    for i in range(M):
        bre = int(input())
        A[bre] = -1
    a_2 = 1
    a_1 = 1 if A[1] != -1 else -1
    # print(A)
    for i in range(N):
        if (A[i] == -1) & (A[i + 1] == -1):
            print(0)
            sys.exit()
    # print(a_1, a_2)
    A[0] = 1
    A[1] = 1 if A[1] != -1 else -1
    for i in range(2, N + 1):
        if A[i] == -1:
            a_2 = a_1
            a_1 = -1
            continue
        elif a_1 == -1:
            a = a_2
        elif a_2 == -1:
            a = a_1
        else:
            a = a_1 +a_2
        a_2 = a_1
        a_1 = a
        # print(a_2, a_1)
    print(a % 1000000007)

if __name__ == '__main__':
    main()

Fixed submission:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    N, M = map(int, input().split())
    A = [0] * (N + 1)
    for i in range(M):
        bre = int(input())
        A[bre] = -1
    A[0] = 1
    A[1] = 1 if A[1] != -1 else -1
    # print(A)
    for i in range(N):
        if (A[i] == -1) & (A[i + 1] == -1):
            print(0)
            sys.exit()

    for i in range(2, N + 1):
        if A[i] == -1:
            continue
        elif A[i - 1] == -1:
            A[i] = A[i - 2]
        elif A[i - 2] == -1:
            A[i] = A[i - 1]
        else:
            A[i] = A[i - 1] + A[i - 2]
    print(A[N] % 1000000007)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import numpy as np
import math

def contrary_bit(bit):
    if (bit == 1):
        return 0
    elif (bit == 0):
        return 1
    else:
        print("error")

def dfs(adj_lists, nodes, node):
    # nodeから出発して，深さ優先探索
    neighbors = adj_lists[node]
    for neighbor in neighbors:
        if (nodes[neighbor[0]] != -1):
            #訪問済み
            continue
        else:
            if neighbor[1] %2 == 0:
                # 同じbit  
                nodes[neighbor[0]]= nodes[node]
                nodes = dfs(adj_lists, nodes, neighbor[0])
            else:
                nodes[neighbor[0]] = contrary_bit(nodes[node])
                nodes = dfs(adj_lists, nodes, neighbor[0])
    return nodes

def main():
    N = int(input())
    adj_lists = {}
    for i in range(1, N + 1):
        adj_lists[i] = []
    # adj_lists = {i: []} # u: [(v, w), []]
    nodes = [-1] * (N + 1)
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        adj_lists[u].append((v, w))
        adj_lists[v].append((u, w))
    nodes[1] = 1
    nodes = dfs(adj_lists, nodes, 1)
    ans = nodes[1:]
    for color in ans:
        print(color)

if __name__ == '__main__':
    main()

Fixed submission:
import numpy as np
import math
import sys

sys.setrecursionlimit(1000000)

def contrary_bit(bit):
    if (bit == 1):
        return 0
    elif (bit == 0):
        return 1
    else:
        print("error")

def dfs(adj_lists, nodes, node):
    # nodeから出発して，深さ優先探索
    neighbors = adj_lists[node]
    for neighbor in neighbors:
        if (nodes[neighbor[0]] != -1):
            #訪問済み
            continue
        else:
            if neighbor[1] % 2 == 0:
                # 同じbit  
                nodes[neighbor[0]] = nodes[node]
                nodes = dfs(adj_lists, nodes, neighbor[0])
            else:
                nodes[neighbor[0]] = contrary_bit(nodes[node])
                nodes = dfs(adj_lists, nodes, neighbor[0])
    return nodes

def main():
    N = int(input())
    adj_lists = {}
    for i in range(1, N + 1):
        adj_lists[i] = []
    nodes = [-1] * (N + 1)
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        adj_lists[u].append((v, w))
        adj_lists[v].append((u, w))
    nodes[1] = 1
    nodes = dfs(adj_lists, nodes, 1)
    ans = nodes[1:]
    for color in ans:
        print(color)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())
c = [0 for i in range(n+1)]
x = 0
while x <= b and x <= n:
  c[x] = (a*x)//b - a*(x//b)
  x += 1
print(max(c))

Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1,n)
print((a*x)//b - a*(x//b))

Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())
c = [0 for i in range(n+1)]
for x in range(n+1):
  c[x] = (a*x)//b - a*(x//b)
print(max(c))

Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1,n)
print((a*x)//b - a*(x//b))

Buggy python submission (verdict: Runtime Error):
a, b, n = map(int, input().split())
c = [0]*(n+1)
for x in range(n+2):
  c[x] = (a*x)//b - a*(x//b)
print(max(c))
  

Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1,n)
print((a*x)//b - a*(x//b))

Buggy python submission (verdict: Runtime Error):
a, b, n = map(int, input().split())
c = [0]*(n+1)
for x in range(n+1):
  c[x] = (a*x)//b - a*(x//b)
print(max(c))
  

Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1,n)
print((a*x)//b - a*(x//b))

Buggy python submission (verdict: Runtime Error):
a, b, n = map(int, input().split())
current = 0
c = [0]*(n+1)
for x in range(n+1):
  c[x] = (a*x)//b - a*(x//b)
print(max(c))

Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1,n)
print((a*x)//b - a*(x//b))

Buggy python submission (verdict: Runtime Error):
a, b, n = map(int, input().split())
current = 0
c = [0]*(n+1)
for x in range(1,n+1):
  c[x]= (a*x)//b - a*(x//b)
print(max(c))

Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1,n)
print((a*x)//b - a*(x//b))

Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())
current = 0
for x in range(1,n+1):
  current = max(current, (a*x)//b - a*(x//b))
print(current)
  

Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1,n)
print((a*x)//b - a*(x//b))

Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())
current = 0
for x in range(n+1):
  temp = (a*x)//b - a*(x//b)
  current = max(current, temp)
print(current)
  

Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1,n)
print((a*x)//b - a*(x//b))
Buggy python submission (verdict: Runtime Error):
n=int(input())
m = int(sqrt(m))
for i in reversed(range(1, m)):
  if N % i == 0:
    j =  N // i
    print(i+j-2)
    break

Fixed submission:
import math
n = int(input())
m = int(math.sqrt(n))
for i in reversed(range(1, m+1)):
  if n % i == 0:
    j =  n // i
    print(i+j-2)
    break

Buggy python submission (verdict: Runtime Error):
n=int(input())
m = int(sqrt(m))
for i in reversed(range(1, m)):
  if N%i==0:
    j = N//i
    print(i+j-2)

Fixed submission:
import math
n = int(input())
m = int(math.sqrt(n))
for i in reversed(range(1, m+1)):
  if n % i == 0:
    j =  n // i
    print(i+j-2)
    break
Buggy python submission (verdict: Runtime Error):
import math
a, b, x =map(int, input().split())
if x >= a*a*b/2:
   print( math.degrees(math.tanh(2/a*(b-x/(a*a))))
else:
   print(math.degrees(math.tanh(a*b*b/(2*x))))

Fixed submission:
import math
a, b, x = map(int, input().split())
if x >= a*a*b/2:
   print(math.degrees(math.atan(2/a*(b-x/(a*a)))))
else:
   print(math.degrees(math.atan((a*b*b)/(2*x))))
Buggy python submission (verdict: Runtime Error):
s = input()
if s=='Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else s == 'Rainy':
    print('Sunny')

Fixed submission:
s = input()
if s == "Sunny":
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
else:
    print("Sunny")
Buggy python submission (verdict: Runtime Error):
n=int(input())  
h=list(map(int, input().split()))
count = 0
max_count = 0
for i in range(n-1):
    if h[i+1] <= h[i]:
        count = count + 1
    else:
        max_count = max(max_count,count)
        count = 0
print(max(max_count,count))


Fixed submission:
s = input()
t = input()
count = 0
for i in range(3):  
  if s[i] == t[i]:
       count = count+ 1
print(count)

Buggy python submission (verdict: Runtime Error):
n=int(input())  
h=list(map(int, input().split()))
count = 0
max_count = 0
for i in range(n-1):
    if h[i+1] < h[i]:
        count = count + 1
    else:
        max_count = max(max_count,count)
        count = 0
print(max(max_count,count))


Fixed submission:
s = input()
t = input()
count = 0
for i in range(3):  
  if s[i] == t[i]:
       count = count+ 1
print(count)

Buggy python submission (verdict: Runtime Error):
n=int(input())  
h=list(map(int, input().split()))
count = 0
max_count = 0
for i in range(n-1):
    if h[i+1] <= h[i]:
        count = count + 1
    elif max_count < count:
        max_count = count
        count = 0
    else:
        count = 0
      
print(max(max_count,count))

Fixed submission:
s = input()
t = input()
count = 0
for i in range(3):  
  if s[i] == t[i]:
       count = count+ 1
print(count)

Buggy python submission (verdict: Runtime Error):
n=int(input())  
h=list(map(int, input().split()))
count = 0
max_count = 0
for i in range(n-1):
    if h[i+1] <= h[i]:
        count = count + 1
    else:
        max_count = max(max_count,count)
        count = 0
print(max(max_count,count))

Fixed submission:
s = input()
t = input()
count = 0
for i in range(3):  
  if s[i] == t[i]:
       count = count+ 1
print(count)
Buggy python submission (verdict: Runtime Error):
n, y = map(int, input().split())
for i in range(n):
    for j in range(n-i):
        if 10000*i+5000*j+1000*(n-i-j) == y:
            print(i,j,n-i-j)
            break()
print(-1,-1,-1)

Fixed submission:
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j) == y:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)
Buggy python submission (verdict: Runtime Error):
k, s = map(int, input().split())
count = 0
for x in range(k+1):
  for y in range(k+1):
    z = s-x-y
      if 0 <= z <=k:
        count = count +1
print(count)

Fixed submission:
k, s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if 0 <= z <=k:
            count = count +1
print(count)
Buggy python submission (verdict: Runtime Error):
def rec(c, a, x, n, m, start, states, best, price):

    for i in range(start, n):
        price += c[i]
        states[0] += a[i][0]
        states[1] += a[i][1]
        states[2] += a[i][2]

        if states[0] >= x and states[1] >= x and states[2] >= x and price < best:
            best = price

        if i != n - 1:
            best = rec(c, a, x, n, m, i + 1, states, best, price)

        states[0] -= a[i][0]
        states[1] -= a[i][1]
        states[2] -= a[i][2]
        price -= c[i]

    return best


def task(n, m, x, c, a):
    mx = [0] * n
    for i in range(0, n):
        for j in range(0, m):
            mx[j] += a[i][j]

    for j in range(0, m):
        if mx[j] < x:
            print(-1)
            return

    best = rec(c, a, x, n, m, 0, [0, 0, 0], 1000000, 0)

    print(best)


n, m, x = map(int, input().split())
c = []
a = []
for i in range(0, n):
    values = list(map(int, input().split()))
    c.append(values[0])
    a.append(values[1:])

task(n, m, x, c, a)


Fixed submission:
def task(s, t):
    for i in range(0, len(s)):
        if s[i] != t[i]:
            print("No")
            return

    print("Yes")


s = input()
t = input()
task(s, t)
Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())

mod = 998244353

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for i in range(k+1):
    col = m * pow(m-1,n-i-1,mod)
    match = cmb(n-1,i,mod)
    ans += col * match

print(ans % mod)

Fixed submission:
n, m, k = map(int, input().split())
 
mod = 998244353
 
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
 
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
 
ans = 0
for i in range(k+1):
    col = m * pow(m-1,n-i-1,mod)
    match = cmb(n-1,i,mod)
    ans += col * match
 
print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())

heights = list(map(int, input().split()))

total = 0
for i,height_a in enumerate(heights):
    if height_a <= (N-i-2):
        for j in range(i+height_a+1,N):
            if abs(i-j) == height_a + heights[j]:
                total += 1

print(total)

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

N = int(input())

heights = list(map(int, input().split()))


cnt_height_plus_ind = {}
cnt_height_minus_ind = {}
cnt_ind_minus_height = {}
cnt_minus_height_minus_ind = {}

for ind in range(N):
    height = heights[ind]

    if ind - height not in cnt_ind_minus_height:
        cnt_ind_minus_height[ind - height] = 0
    cnt_ind_minus_height[ind - height] += 1

    if ind + height not in cnt_height_plus_ind:
        cnt_height_plus_ind[ind + height] = 0
    cnt_height_plus_ind[ind + height] += 1

    if height - ind not in cnt_height_minus_ind:
        cnt_height_minus_ind[height - ind] = 0
    cnt_height_minus_ind[height - ind] += 1

    if - ind - height not in cnt_minus_height_minus_ind:
        cnt_minus_height_minus_ind[-ind-height] = 0
    cnt_minus_height_minus_ind[-ind-height] += 1
    

ans = 0
for val in cnt_height_minus_ind:
    if val in cnt_minus_height_minus_ind:
        ans += cnt_height_minus_ind[val] * cnt_minus_height_minus_ind[val]

for val in cnt_height_plus_ind:
    if val in cnt_ind_minus_height:
        ans += cnt_height_plus_ind[val] * cnt_ind_minus_height[val]

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

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

ans = 0
if N >= B-1:
    for i in range(B-1,N,B):
        ans = max(ans, ((A*i)//B) - A * (i//B))

ans = max(ans, ((A*N)//B) - A * (N//B))


print(ans)

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

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

ans = 0
if N >= B-1:
    ans = max(ans, ((A*(B-1))//B) - A * ((B-1)//B))
else:
    ans = max(ans, ((A*N)//B) - A * (N//B))


print(ans)

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

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

ans = 0
for i in range(N+1):
    ans = max(ans, ((A*i)//B) - A * (i//B))

print(ans)

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

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

ans = 0
if N >= B-1:
    ans = max(ans, ((A*(B-1))//B) - A * ((B-1)//B))
else:
    ans = max(ans, ((A*N)//B) - A * (N//B))


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():

    N = int(input())

    a_l = [0] * N

    nums = list(map(int, input().split()))

    for i in nums:
        a_l[i-1] += 1

    for i in nums:
        a_l[i-1] -= 1
        total = 0
        for j in a_l:
            if j > 1:
                total += cmb(j,2)
        print(total)
        a_l[i-1] += 1




if __name__ == '__main__':
    main()

Fixed submission:
def cmb(n):
    return int(n * (n-1) / 2)

def main():

    N = int(input())

    a_l = [0] * N

    nums = list(map(int, input().split()))
    for i in nums:
        a_l[i-1] += 1

    total = 0
    for j in a_l:
        if j > 1:
            total += cmb(j)

    for k in nums:
        if a_l[k-1] > 1:
            print(total - cmb(a_l[k-1]) + cmb(a_l[k-1] - 1))
        else:
            print(total)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from collections import deque

n, m, k = map(int, input().split())

friends = [[0] * n for _ in range(n)]

blocks = [[0] * n for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    friends[a-1][b-1] = 1
    friends[b-1][a-1] = 1

for i in range(k):
    c, d = map(int, input().split())
    blocks[c-1][d-1] = 1
    blocks[d-1][c-1] = 1

for i in range(n):
    q = deque()
    q.append(i)
    cnt = [-1] * n
    cnt[i] = 0
    total = 0
    while q:
        k = q.popleft()
        for j in range(n):
            if friends[k][j] and cnt[j] == -1:
                q.append(j)
                cnt[j] = cnt[k] + 1
                if cnt[j] > 1 and not blocks[i][j]:
                    total += 1
    print(total)

Fixed submission:
a = int(input())

if a % 2 == 0:
    b = a/2

else:
    b = (a+1)/2

print(int(b))
Buggy python submission (verdict: Runtime Error):

N,M = map(int, input().split())

a_list = [0] * N

uncorrect = 0
changezero = True

for i in range(M):
    s,c = map(int, input().split())
    if s == 1:
        zero == False 
    if a_list[s-1] == 0:
        a_list[s-1] += c
    else:
        if a_list[s-1] != c:
            uncorrect += 1

if changezero and N >= 2:
    a_list[0] += 1

if uncorrect >= 1:
    print(-1)
elif a_list[0] == 0 and N >= 2:
    print(-1)
else:
    ans = 0
    for i in range(N):
        ans += a_list[i] * (10 ** (N-i-1))

    print(ans)

Fixed submission:

N,M = map(int, input().split())

a_list = [0] * N

uncorrect = 0
changezero = True

for i in range(M):
    s,c = map(int, input().split())
    if s == 1:
        changezero = False 
    if a_list[s-1] == 0:
        a_list[s-1] += c
    else:
        if a_list[s-1] != c:
            uncorrect += 1

if changezero and N >= 2:
    a_list[0] += 1

if uncorrect >= 1:
    print(-1)
elif a_list[0] == 0 and N >= 2:
    print(-1)
else:
    ans = 0
    for i in range(N):
        ans += a_list[i] * (10 ** (N-i-1))

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

INF = 1e100

dp = [[INF] * (10 ** 4 + 1) for i in range(10 ** 3 + 1)]

dp[0][0] = 0

for i in range(n):
    a, b = map(int, input().split())
    for j in range(h+1):
        dp[i+1][j] = min(dp[i+1][j] , dp[i][j])
        dp[i+1][min(h, (j+a))] = min(dp[i+1][min(h, (j+a))], dp[i+1][j] + b)

print(dp[n][h])

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

INF = 1e100

dp = [[INF] * (10 ** 4 + 1) for i in range(10 ** 3 + 1)]

dp[0][0] = 0

for i in range(n):
    a, b = map(int, input().split())
    for j in range(h+1):
        dp[i+1][j] = min(dp[i+1][j] , dp[i][j])
        dp[i+1][min(h, (j+a))] = min(dp[i+1][min(h, (j+a))], dp[i+1][j] + b)

print(dp[n][h])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())


ans = 0
for i in range(n):
    for j in range(n):
        if str(i+1)[0] == str(j+1)[-1] and str(i+1)[-1] == str(j+1)[0]:
            ans += 1

print(ans)

Fixed submission:
n = int(input())

array = [0] * 100

for i in range(1,n+1):
    array[int(str(i)[0])*10+int(str(i)[-1])] += 1


ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += array[i*10+j] * array[j*10+i]

print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,k = map(int, input().split())


if a >= k:
    print('{} {}'.format(a-k,b))

elif (a + b) > k:
    print('0 {}'.format(a+b-k))

elif (a + b) < k:
    print('0 0')

Fixed submission:
s,t =input().split()

ans =''

print(ans + t + s)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int, input().split())

for i in range(k):
    if a > 0:
        a -= 1
    elif b > 0:
        b -= 1 
    else:
        print('0 0')
        exit()

print('{} {}'.format(a,b))

Fixed submission:
a,b,k = map(int, input().split())


if a >= k:
    print('{} {}'.format(a-k,b))

elif (a + b) > k:
    print('0 {}'.format(a+b-k))

elif (a + b) <= k:
    print('0 0')
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n = int(input())

s = input()

numlist = [0] * 1000

for i in range(1000):
    top = i // 100
    mid = (i - top * 100) // 10
    bot = (i - top * 100 - mid * 10)


    found = False
    for j in range(n):
        if s[j] == str(top):
            for k in range(j+1, n):
                if s[k] == str(mid):
                    for l in range(k+1, n):
                        if s[l] == str(bot):
                            numlist[i] += 1
                            found = True
                            break 
                if found:
                    break
        if found:
            break

ans = numlist.count(1)

print(ans)

Fixed submission:
 
n = int(input())
s = input()
ans = 0
 
pin = [str(i).zfill(3) for i in range(1000)]
 
for i in pin:
    idx = -1
    for j in i:
        idx = s.find(j,idx+1)
        if idx < 0:
            break
    else:
        ans += 1
 
print(ans)

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

n = int(input())

s = input()

numlist = []

for v in itertools.combinations(range(n), 3):
    numlist.append(s[v[0]] + s[v[1]] + s[v[2]])

numlist = set(numlist)
ans = len(numlist)

print(ans)

Fixed submission:
 
n = int(input())
s = input()
ans = 0
 
pin = [str(i).zfill(3) for i in range(1000)]
 
for i in pin:
    idx = -1
    for j in i:
        idx = s.find(j,idx+1)
        if idx < 0:
            break
    else:
        ans += 1
 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

label = []
num = {}

for i in range(n):
    seq = input()
    seq = ''.join(sorted(seq))
    if seq in label:
        num[seq] += 1
    else:
        label.append(seq)
        num[seq] = 1

ans = 0
for s in num:
    k = num[s]
    if k > 1:
        ans += k * (k-1) // 2

print(ans)

Fixed submission:
n = int(input())

num = {}

for i in range(n):
    seq = input()
    seq = ''.join(sorted(seq))
    if seq in num:
        num[seq] += 1
    else:
        num[seq] = 1

ans = 0
for s in num:
    k = num[s]
    if k > 1:
        ans += k * (k-1) // 2

print(ans)