Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
ans = 1

limit = pow(10,18)

f = 0
for i in range(N):
    if A[i] != 0:
        ans *= A[i]
    else:
        print(0)
        exit()

    if ans > limit:
        f = 1

if f == 1:
    print(-1)
else:
    print(ans)


Fixed submission:
import math

A,B=input().split()

A = int(A)
N,F = B.split('.')
ans = (A * 100 * int(N) + A * int(F)) //100

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
K = int(input())

count = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for q in range(1, K+1):
            count += math.gcd(math.gcd(i,j),q)
print(count)

Fixed submission:
import math

K = int(input())

count = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            count += math.gcd(math.gcd(i,j), k)
print(count)

Buggy python submission (verdict: Runtime Error):
import math
K = int(input())

count = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for q in range(1, K+1):
            count += math.gcd(math.gcd(i,j),q)
print(count)

Fixed submission:
import math

K = int(input())

count = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            count += math.gcd(math.gcd(i,j), k)
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
dic = {}


def Warshall_Floyd(N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


d = [[float("inf")] * N for i in range(N)]

for i in range(N-1):
    d[i][i + 1] = 1
    d[i + 1][i] = 1

for i in range(N):
    d[i][i] = 0

d[X-1][Y-1] = 1
d[Y-1][X-1] = 1

d = Warshall_Floyd(N)


for i in range(N):
    for j in range(N):
        if dic.get(d[i][j]) is None:
            dic[d[i][j]] = 1
        else:
            dic[d[i][j]] += 1

for i in range(1, N):
    if dic.get(i) is None:
        print(0)
    else:
        print(dic[i]//2)

Fixed submission:
N, X, Y = map(int, input().split())
d = {}


for i in range(1, N):
    for j in range(i+1, N+1):
        m = min(j-i, abs(X-i) + 1 + abs(Y-j))
        if d.get(m) is None:
            d[m] = 1
        else:
            d[m] += 1

for i in range(1, N):
    if d.get(i) is None:
        print(0)
    else:
        print(d[i])
Buggy python submission (verdict: Runtime Error):
S = list(input())
Q = int(input())

count = 0
for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        count += 1
    elif a[0] == '2':
        if count % 2 == 0 and a[1] == '1':
            S.insert(0, a[2])
        elif a[1] == '1':
            S.append(a[2])
        elif count % 2 == 0:
            S.append(a[2])
        else:
            S.insert(0, a[2])

print(''.join(S) if count % 2 == 0 else ''.join(S[::-1]))

Fixed submission:
from collections import deque
S = deque(list(input()))
Q = int(input())

count = 0
for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        count += 1
    elif a[0] == '2':
        if count % 2 == 0 and a[1] == '1':
            S.appendleft(a[2])
        elif a[1] == '1':
            S.append(a[2])
        elif count % 2 == 0:
            S.append(a[2])
        else:
            S.appendleft(a[2])


if count % 2 == 0:
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())

count = 0
for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        count += 1
    elif a[0] == '2':
        if count % 2 == 0 and a[1] == '1':
            S.insert(0, a[2])
        elif a[1] == '1':
            S.append(a[2])
        elif count % 2 == 0:
            S.append(a[2])
        else:
            S.insert(0, a[2])

print(''.join(S) if count % 2 == 0 else ''.join(S[::-1]))

Fixed submission:
from collections import deque
S = deque(list(input()))
Q = int(input())

count = 0
for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        count += 1
    elif a[0] == '2':
        if count % 2 == 0 and a[1] == '1':
            S.appendleft(a[2])
        elif a[1] == '1':
            S.append(a[2])
        elif count % 2 == 0:
            S.append(a[2])
        else:
            S.appendleft(a[2])


if count % 2 == 0:
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        S = S[::-1]
    elif a[0] == '2':
        if a[1] == '1':
            S.insert(0, a[2])
        else:
            S.append(a[2])

print(''.join(S))

Fixed submission:
from collections import deque
S = deque(list(input()))
Q = int(input())

count = 0
for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        count += 1
    elif a[0] == '2':
        if count % 2 == 0 and a[1] == '1':
            S.appendleft(a[2])
        elif a[1] == '1':
            S.append(a[2])
        elif count % 2 == 0:
            S.append(a[2])
        else:
            S.appendleft(a[2])


if count % 2 == 0:
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))

total = 0

for i in range(len(P)-K+1):
    c = sum(P[i:i+K])
    if c > total:
        total = c


print((total+K)/2)


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


ans = 0
for i in range(len(P)-K+1):
    if i == 0:
        c = sum(P[:K])
    else:
        c = c + P[i+K-1] - P[i-1]
    if c > ans:
        ans = c


print((ans+K)/2)

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

total = 0
target = 0

for i in range(len(P)-K+1):
    c = sum(P[i:i+K])
    if c > total:
        total = c
        target = i

ans = 0
for i in range(target, target+K):
    e = (P[i]+1)/2
    ans += e

print(ans)

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


ans = 0
for i in range(len(P)-K+1):
    if i == 0:
        c = sum(P[:K])
    else:
        c = c + P[i+K-1] - P[i-1]
    if c > ans:
        ans = c


print((ans+K)/2)

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

ans = 0

for i in range(len(P)-K+1):
    c = 0
    for j in range(i, i+K):
        e = (P[j] + 1)/2
        c += e

    if c > ans:
        ans = c

print(ans)

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


ans = 0
for i in range(len(P)-K+1):
    if i == 0:
        c = sum(P[:K])
    else:
        c = c + P[i+K-1] - P[i-1]
    if c > ans:
        ans = c


print((ans+K)/2)

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

ans = 0

for i in range(len(P)-K+1):
    c = 0
    for j in range(i, i+K):
        e = (P[j] + 1)/2
        c += e

    if c > ans:
        ans = c

print(ans)

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


ans = 0
for i in range(len(P)-K+1):
    if i == 0:
        c = sum(P[:K])
    else:
        c = c + P[i+K-1] - P[i-1]
    if c > ans:
        ans = c


print((ans+K)/2)
Buggy python submission (verdict: Runtime Error):
N, K, S = map(int, input().split())

if S == 1:
    A = [2]*N
    for i in range(K):
        A[i] = 1
elif S == 10e9:
    A = [2]*N
    for i in range(K+1):
        if i % 2 == 0:
            A[i] = S - 1
        else:
            A[i] = 1
else:
    A = [10**10]*N
    for i in range(K+1):
        if i % 2 == 0:
            A[i] = S - 1
        else:
            A[i] = 1


A = [str(i) for i in A]
print(' '.join(A))


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

A = []
A += [S]*K
if S == pow(10, 9):
    A += [1]*(N-K)
else:
    A += [S+1]*(N-K)


A = [str(i) for i in A]
print(' '.join(A))

Buggy python submission (verdict: Runtime Error):
N, K, S = map(int, input().split())

if S != 10e9:
    A = [S+1]*N
else:
    A = [2]*N


for i in range(K+1):
    if i % 2 == 0:
        A[i] = S - 1
    else:
        A[i] = 1
A = [str(i) for i in A]
print(' '.join(A))


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

A = []
A += [S]*K
if S == pow(10, 9):
    A += [1]*(N-K)
else:
    A += [S+1]*(N-K)


A = [str(i) for i in A]
print(' '.join(A))

Buggy python submission (verdict: Runtime Error):
N, K, S = map(int, input().split())
A = [S+1]*N

for i in range(K+1):
    if i % 2 == 0:
        A[i] = S - 1
    else:
        A[i] = 1
A = [str(i) for i in A]
print(' '.join(A))


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

A = []
A += [S]*K
if S == pow(10, 9):
    A += [1]*(N-K)
else:
    A += [S+1]*(N-K)


A = [str(i) for i in A]
print(' '.join(A))

Buggy python submission (verdict: Runtime Error):
N, K, S = map(int, input().split())
A = [10**10]*N

for i in range(K+1):
    if i % 2 == 0:
        A[i] = S - 1
    else:
        A[i] = 1
A = [str(i) for i in A]
print(' '.join(A))


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

A = []
A += [S]*K
if S == pow(10, 9):
    A += [1]*(N-K)
else:
    A += [S+1]*(N-K)


A = [str(i) for i in A]
print(' '.join(A))
Buggy python submission (verdict: Runtime Error):
N = R - L + 1
l = L % 2019

if N >= 2019:
    print(0)
    exit()

m = 2018
for i in range(N):
    a = (l + i) % 2019
    if a < m:
        m = a

print(m * (m + 1))

Fixed submission:
L, R = map(int, input().split())

m1 = 2018
for i in range(L, R):
    for j in range(L+1, R+1):
        a = (i*j) % 2019
        if a == 0:
            print(0)
            exit()
        if a < m1:
            m1 = a
print(m1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

Y = [0] * N

pattern = A[0] + 1

for i in range(pattern):
    Y[0] = i * 2
    # print("pattern", Y[0])
    for k in range(1, N):
        # print("k", k)
        Y[k] = 2 * A[k - 1] - Y[k - 1]
        # print("Y:", Y[k])
        if Y[k] < 0:
            break
        if k == N - 1 and (Y[k] + Y[0]) / 2 == A[k]:
            ans = ' '.join([str(n) for n in Y])
            print(ans)
            exit()

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

Y = [0] * N
s = 0
for i in range(N):
    if i % 2 == 0:
        s += A[i]
    else:
        s -= A[i]

Y[0] = s
for i in range(1, N):
    Y[i] = 2 * A[i - 1] - Y[i - 1]

ans = ' '.join([str(n) for n in Y])
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

A = [0]*N
B = [0]*N

for i in range(N):
    A[i], B[i] = map(int, input().split())


indexes = [*range(N)]
sorted_indexes = sorted(indexes, key=lambda i: B[i])

sorted_A = [A[i] for i in sorted_indexes]
sorted_B = [B[i] for i in sorted_indexes]

total = 0
for i in range(N):
    total += sorted_A[i]
    if total <= sorted_B[i]:
        continue
    else:
        print('No')
        exit()
print('Yes')


Fixed submission:
N = int(input())

A = [0]*N
B = [0]*N

for i in range(N):
    A[i], B[i] = map(int, input().split())


indexes = [i for i in range(N)]
sorted_indexes = sorted(indexes, key=lambda i: B[i])

sorted_A = [A[i] for i in sorted_indexes]
sorted_B = [B[i] for i in sorted_indexes]

total = 0
for i in range(N):
    total += sorted_A[i]
    if total <= sorted_B[i]:
        continue
    else:
        print('No')
        exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())


def tell_power_number(number):
    i = 0
    while number * (2 ** i) < K:
        i += 1
    return i


ans = 0
if N <= K - 1:
    for k in range(1, N + 1):
        ans += 1 / N * (1 / 2) ** tell_power_number(k)
else:
    for k in range(1, K):
        ans += 1 / N * (1 / 2) ** tell_power_number(k)
    ans += (N - K + 1) / N

print(ans)

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


def tell_power_number(number):
    i = 0
    while number * (2 ** i) < K:
        i += 1
    return i


ans = 0
if N <= K - 1:
    for k in range(1, N + 1):
        ans += 1 / N * (1 / 2) ** tell_power_number(k)
else:
    for k in range(1, K):
        ans += 1 / N * (1 / 2) ** tell_power_number(k)
    ans += (N - K + 1) / N

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

ans = 0
X = N // R
Y = N // G
Z = N // B

for i in range(X + 1):
    for j in range(Y + 1):
        if (N - i * R - j * G) >= 0 and (N - i * R - j * G) % B == 0:
            ans += 1

print(ans)

Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0
X = N // R
Y = N // G
Z = N // B

for i in range(X + 1):
    for j in range(Y + 1):
        if (N - i * R - j * G) >= 0 and (N - i * R - j * G) % B == 0:
            ans += 1

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

MOD = pow(10, 9) + 7

dp = [[0 for i in range(K+1)] for j in range(N+1)]
dp[0][0] = 1

for i in range(N):
    S = [0] * (K+1)
    S[0] = dp[i][0]
    # 累積和
    for j in range(1, K+1):
        S[j] = (dp[i][j] + S[j - 1]) % MOD

    for j in range(K+1):
        if j-1 >= A[i]:
            dp[i+1][j] = (S[j] - S[j-1-A[i]]) % MOD
        else:
            dp[i+1][j] = S[j]

print(dp[N][K])


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

MOD = pow(10, 9) + 7

dp = [[0 for i in range(K+1)] for j in range(N+1)]
dp[0][0] = 1

for i in range(N):
    S = [0] * (K+1)
    S[0] = dp[i][0]
    # 累積和
    for j in range(1, K+1):
        S[j] = (dp[i][j] + S[j - 1]) % MOD

    for j in range(K+1):
        if j-1 >= A[i]:
            dp[i+1][j] = (S[j] - S[j-1-A[i]]) % MOD
        else:
            dp[i+1][j] = S[j]

print(dp[N][K])
Buggy python submission (verdict: Runtime Error):
import fractions

N, X = map(int, input().split())
x = list(map(int, input().split()))

y = []

x.sort()
for i in range(1, N):
    x1 = x[i] - x[i-1]
    y.append(x1)

d = x[0] - X if X == 1 else y[0]

for i in range(1, N-1):
    d = fractions.gcd(y[i], d)

print(d)


Fixed submission:
import fractions

N, X = map(int, input().split())
x = list(map(int, input().split()))
y = []
x.insert(0, X)
x.sort()
for i in range(1, N+1):
    x1 = x[i] - x[i-1]
    y.append(x1)

d = y[0]

for i in range(1, len(y)):
    d = fractions.gcd(y[i], d)

print(d)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().spllit()))
print(max(A) - min(A))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
print(max(A) - min(A))
Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int A, B;
  cin >> A >> B;
  if (A > 8 || B > 8)
    cout << ":(" << endl;
  else
    cout << "Yay!" << endl;
}

Fixed submission:
A, B = map(int, input().split())

if A <= 8 and B <= 8:
    print("Yay!")
else:
    print(":(")
Buggy python submission (verdict: Runtime Error):
A, B, C, D = (int(x) for x in input().split())
ans = min(B, D) - max(A - C)
if ans < 0:
    ans = 0
print(ans)

Fixed submission:
A, B, C, D = (int(x) for x in input().split())
ans = min(B, D) - max(A, C)
if ans < 0:
    ans = 0
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

if len(a) == 2:
    x = a[0]
    y = a[-1]
    print(abs(x-y))
    exit()


total = sum(a)
mid = total//2

for i in range(1, N):
    x += a[i]
    if x <= mid:
        continue
    else:
        print(min(abs(x-a[i]-(total - (x-a[i]))), abs(x-(total - x))))
        exit()

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
x = a[0]
total = sum(a)
y = total - x
ans = abs(x - y)
for i in range(1, N-1):
    x += a[i]
    y -= a[i]
    m = abs(x-y)
    if ans > m:
        ans = m
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

if len(a) == 2:
    x = a[0]
    y = a[-1]
    print(abs(x-y))
    exit()


total = sum(a)
mid = total//2

print(mid)
for i in range(1, N):
    x += a[i]
    if x <= mid:
        continue
    else:
        print(x-(total - x))
        print(min(abs(x-a[i]-(total - (x-a[i]))), abs(x-(total - x))))
        exit()

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
x = a[0]
total = sum(a)
y = total - x
ans = abs(x - y)
for i in range(1, N-1):
    x += a[i]
    y -= a[i]
    m = abs(x-y)
    if ans > m:
        ans = m
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
A, B, C = map(int, input().split())
q = math.gcd(A, B)

if A == 1:
    print("YES")
    exit()
if A % 2 == 0 and B % 2 == 0 and C % 2 == 1:
    print("NO")
    exit()
if math.gcd(q, C) == 1 and C != 1:
    print("NO")
else:
    print("YES")

Fixed submission:
A, B, C = map(int, input().split())

for i in range(1, B + 1):
    if A * i % B == C:
        print("YES")
        exit()

print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())
key = 0
count = 0

if a == b:
    if a % x == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()

for i in range(a, b + 1, 1):
    if i % x == 0:
        key = i
        count += 1
        ans = count + (b - key) // x
        print(ans)
        exit()

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

big = b // x + 1
small = (a - 1) // x + 1

ans = big - small
if ans < 0:
    ans = 0

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())
key = 0
count = 0
if a == b:
    if a % x == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()

for i in range(a, b + 1, 1):
    if i % x == 0:
        key = i
        count += 1
        break
ans = count + (b - key) // x
print(ans)

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

big = b // x + 1
small = (a - 1) // x + 1

ans = big - small
if ans < 0:
    ans = 0

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
*A, = map(int, input().split())

mul = 1
for a in A:
    mul *= a
    if mul == 0:
        break
    elif mul > 10 ** 18:
        mul = -1

print(mul)

Fixed submission:
N = int(input())
*A, = map(int, input().split())

list.sort(A, reverse=True)
mx = 10 ** 18
mul = 1

if 0 in A:
    print(0)
    exit(0)
    
for a in A:
    mul *= a
    if mul > mx:
        mul = -1
        break

print(mul)
Buggy python submission (verdict: Runtime Error):
T = input()

if T[0] == '?':
    T[0] = 'D'

for i, v in enumerate(T):
    if v == '?':
        if T[i - 1] == 'D':
            print('P', end='')
        else:
            print('D', end='')
    else:
        print(v, end='')

print('\n')

Fixed submission:
T = input()

for i, v in enumerate(T):
    if v == '?':
        print('D', end='')
    else:
        print(v, end='')
print('\n')
Buggy python submission (verdict: Runtime Error):
import sys

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

a = int(A // 0.08) + 1
b = int(B // 0.1) + 1

ab = []
ab.append(min(a, b))
ab.append(max(a, b))

for i in ab:
    if int(i * 0.08) == A and int(i * 0.1) == B:
        print(f'{i}')
        sys.exit(0)

print('-1')

Fixed submission:
A, B = map(int, input().split())

a = int(A // 0.08) + 1
b = int(B // 0.1) + 1

ab = []
ab.append(min(a, b))
ab.append(max(a, b))

for i in ab:
    if int(i * 0.08) == A and int(i * 0.1) == B:
        print(i)
        exit(0)

print('-1')

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

a = int(A // 0.08) + 1
b = int(B // 0.1) + 1

ab = []
ab.append(min(a, b))
ab.append(max(a, b))

for i in ab:
    if int(i * 0.08) == A and int(i * 0.1) == B:
        print(f'{i}')
        exit(0)
        
print('-1')

Fixed submission:
A, B = map(int, input().split())

a = int(A // 0.08) + 1
b = int(B // 0.1) + 1

ab = []
ab.append(min(a, b))
ab.append(max(a, b))

for i in ab:
    if int(i * 0.08) == A and int(i * 0.1) == B:
        print(i)
        exit(0)

print('-1')
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

S = input()
Q = int(input())

for i in range(Q):
    tmp = list(input().split())
    if tmp[0] == '1':
        S = S[::-1]
    if tmp[0] == '2':
        F = tmp[1]
        C = tmp[2]
        if F == '1':
            S = C + S
        else:
            S = S + C

print(S)


Fixed submission:
from collections import deque

S = input()
Q = int(input())
s = deque(S)
reverse = True

for i in range(Q):
    tmp = list(input().split())
    if tmp[0] == '1':
        reverse = not reverse
    if tmp[0] == '2':
        F = tmp[1]
        C = tmp[2]
        if F == '1':
            if reverse:
                s.appendleft(C)
            else:
                s.append(C)
        else:
            if reverse:
                s.append(C)
            else:
                s.appendleft(C)
if reverse:
    print(''.join(s))
else:
    print(''.join(list(s)[::-1]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 0

for i in range(1000):
    t = str(i).zfill(3)
    ti = 0
    for si in range(N):
        if t[ti] == S[si]:
            ti += 1
            if ti == 3:
                break
    if ti == 3:
        ans += 1

print(ans)

Fixed submission:
N = int(input())
S = input()

ans = 0

for i in range(10):
    a = S.find(str(i))
    if -1 == a:
        continue
    for j in range(10):
        b = S.find(str(j), a + 1)
        if -1 == b:
            continue
        for k in range(10):
            c = S.find(str(k), b + 1)
            if -1 == c:
                continue
            ans += 1
            # print(''.join(map(str, [i, j, k])))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

ans = set()

for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            iss = s[i : i + 1]
            js = s[j : j + 1]
            ks = s[k : k + 1]
            ans.add(iss + js + ks)

print(len(ans))

Fixed submission:
N = int(input())
S = input()

ans = 0

for i in range(10):
    a = S.find(str(i))
    if -1 == a:
        continue
    for j in range(10):
        b = S.find(str(j), a + 1)
        if -1 == b:
            continue
        for k in range(10):
            c = S.find(str(k), b + 1)
            if -1 == c:
                continue
            ans += 1
            # print(''.join(map(str, [i, j, k])))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy

N = int(input())
*abc, = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * 3 for _ in range(N)]

for i, l in enumerate(abc):
    if i == 0:
        dp[i] = copy.deepcopy(l)
    else:
        mx = 0
        ex = [0, 1, 2]
        ext = copy.deepcopy(ex)
        for j, m in enumerate(l):
            ext.remove(j)
            mx1 = max(mx, abc[i][ext[0]] + dp[i - 1][j])
            mx2 = max(mx, abc[i][ext[1]] + dp[i - 1][j])
            mx = max(mx1, mx2)
            ext = copy.deepcopy(ex)
            dp[i][j] = mx

print(max(dp[-1]))

Fixed submission:
N = int(input())
la, lb, lc = [0] * 3

for i in range(N):
    a, b, c = [int(x) for x in input().split()]
    aa = a + max(lb, lc)
    bb = b + max(lc, la)
    cc = c + max(lb, la)
    la = aa
    lb = bb
    lc = cc

print(max(la, lb, lc))