Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import fractions

N = int(input())
if N % 2 == 1:
  print(0)
else:
  ans = 0
  log = int(fractions.math.log(N//2,5))
  for l in range(1,log+1):
    power = 5**l
    ans += (N//2) // power
  print(ans)

Fixed submission:
import fractions


N = int(input())
if N == 0:
  print(0)
elif N % 2 == 1:
  print(0)
else:
  ans = 0
  log = int(fractions.math.log(N//2,5))
  for l in range(1,log+1):
    power = 5**l
    ans += (N//2) // power
  print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
import math

a,b = map(int,input().split())
def cf(x1,x2):
    cf = []
    for i in range(1,int(np.sqrt(max(x1,x2))+2)):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def prime(num):
  for p in range(2, int(np.sqrt(num)+2)):
    if num % p == 0:
      return False
  return True

lis = cf(a,b)
for k,l in enumerate(lis):
  if prime(l) == False:
    lis[k] = -1
s = set(lis) - set([-1])
s.add(math.gcd(a,b))
print(len(s))

Fixed submission:
import numpy as np


a,b = map(int,input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

lisa = prime_factorize(a)
lisb = prime_factorize(b)
lis = set(lisa) & set(lisb)
lis.add(1)
lis = sorted(list(lis))
devil = (max(a,b)/lis[-1])
if len(prime_factorize(devil)) == 1:
  if min(a,b) % devil == 0:
    lis.append(devil)
print(len(set(lis)))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
a,b = map(int,input().split())
def cf(x1,x2):
    cf = []
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def prime(num):
  for p in range(2, int(np.sqrt(num)+1)):
    if num % p == 0:
      return False
  return True

lis = cf(a,b)
for k,l in enumerate(lis):
  if prime(l) == False:
    lis[k] = -1
s = set(lis) - set([-1])
print(len(s))

Fixed submission:
import numpy as np


a,b = map(int,input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

lisa = prime_factorize(a)
lisb = prime_factorize(b)
lis = set(lisa) & set(lisb)
lis.add(1)
lis = sorted(list(lis))
devil = (max(a,b)/lis[-1])
if len(prime_factorize(devil)) == 1:
  if min(a,b) % devil == 0:
    lis.append(devil)
print(len(set(lis)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int, input().split()))
maxL = max(L)
L.pop(maxL)
if maxL > sum(L):
  print('Yes')
else:
  print('No')

Fixed submission:
import numpy as np


N = int(input())
L = list(map(int, input().split()))
maxL = max(L)
argmaxL = np.argmax(L)
L.pop(argmaxL)
if maxL < sum(L):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    S = sum(A)
    l = A[0]
    I = 0
    for i in range(1, N):
        if l + A[i] < S / 2:
            l += A[i]
            I = i
    if l == S / 2:
        print(0)
        exit()
    c = A[I + 1]
    r = S - l - c
    ans1 = abs(r - (l + c))
    ans2 = abs(l - (r + c))
    print(min(ans1, ans2))

if __name__ == "__main__":
    solve()


Fixed submission:
import math

def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    S = sum(A)
    l = A[0]
    I = 0
    m = math.ceil(S / 2)
    for i in range(1, N):
        if (l + A[i]) <= m:
            l += A[i]
        else:
            I = i - 1
            break
    if l == S / 2:
        print(0)
        exit()
    c = A[I + 1]
    r = S - l - c
    ans1 = abs(r - (l + c))
    ans2 = abs(l - (r + c))
    print(min(ans1, ans2))

if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Runtime Error):
def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    S = sum(A)
    l = A[0]
    I = 0
    for i in range(1, N):
        if l + A[i] <= S / 2:
            l += A[i]
            I = i
    if l == S / 2:
        print(0)
        exit()
    c = A[I + 1]
    r = S - l - c
    ans1 = abs(r - (l + c))
    ans2 = abs(l - (r + c))
    print(min(ans1, ans2))

if __name__ == "__main__":
    solve()


Fixed submission:
import math

def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    S = sum(A)
    l = A[0]
    I = 0
    m = math.ceil(S / 2)
    for i in range(1, N):
        if (l + A[i]) <= m:
            l += A[i]
        else:
            I = i - 1
            break
    if l == S / 2:
        print(0)
        exit()
    c = A[I + 1]
    r = S - l - c
    ans1 = abs(r - (l + c))
    ans2 = abs(l - (r + c))
    print(min(ans1, ans2))

if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]
t = []
for i in range(N):
    t.append(str(A.index(i + 1) + 1))
print(' '.join(t))

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]
d = {v: str(k + 1) for k, v in enumerate(A)}
print(' '.join([v for _, v in sorted(d.items())]))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter 

n = int(input())
a = list(map(int, input().split()))
co = Counter(a)
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    if b in co.keys():
        co[c] += co[b]
        co[b] = 0
    ans = 0
    for i in co.items():
        ans += i[0] * i[1]
    print(ans)

Fixed submission:
from collections import Counter 

n = int(input())
a = list(map(int, input().split()))
co = Counter(a)
q = int(input())
ans = 0
for i in co.items():
    ans += i[0] * i[1]
for _ in range(q):
    b, c = map(int, input().split())
    if b in co.keys():
        ans -= b * co[b]
        co[c] += co[b]
        ans += c * co[b]
        co[b] = 0
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, *a = map(int, open(0).read().split())
ans = 1
for i in a:
    ans *= i
print(ans if ans <= 10**18 else -1)

Fixed submission:
n, *a = map(int, open(0).read().split())
ans = 1
if 0 in a:
    ans = 0
else:
    for i in a:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    ans = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
            d[j] = min(d[j],d[v]+cost[v][j])
            if d[j] >= d[v]+cost[v][j]:
                ans[j] = v+1
    return ans 


n,w = map(int,input().split()) #n:頂点数　w:辺の数

cost = [[float("inf") for i in range(n)] for i in range(n)] 
#cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
for i in range(w):
    x,y = map(int,input().split())
    cost[x-1][y-1] = 1
    cost[y-1][x-1] = 1
ans = dijkstra(0,n,w,cost)

print('Yes')
for ans in ans[1:]:
    print(ans)

Fixed submission:
from collections import deque
n, m = map(int, input().split())
c = [[] for _ in range(n)]  # 隣接してる部屋リスト
ans = [-1]*n
ans[0] = 0
for _ in range(m):
    a,b = map(int, input().split())
    c[a-1].append(b-1)
    c[b-1].append(a-1)

d = deque([0])  # 0だけ入れたdequeを作成

while d:
    cur = d.pop()
    for x in c[cur]:
        if ans[x]<0:
            ans[x] = cur
            d.appendleft(x)  # curに隣接してる部屋xを次に見ていく
            
print('Yes')
for ans in ans[1:]:
    print(ans+1)
Buggy python submission (verdict: Runtime Error):
x = int(input())

for d in range(1, int(x**0.5)+1):
    if x % d == 0:
        for a in range(1,d+1):
            b = a - d
            if a**5 - b**5 == x:
                print(a, b)
                exit()

Fixed submission:
s = input()

if s == 'ABC':
    print('ARC')
else:
    print('ABC')
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
 
for d in range(1, int(x**0.5)+1):
    if x % d == 0:
        for a in range(0,x+1):
            b = a - d
            if a**5 - b**5 == x:
                print(a, b)
                exit()
            elif a**5 - b**5 > x:
                continue

Fixed submission:
x = int(input())
for a in range(-118,120):
    for b in range(-119, 119):
        if a**5 - b**5 == x:
            print(a,b)
            exit()

Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
 
for d in range(1, int(x**0.5)+1):
    if x % d == 0:
        for a in range(0,x+1):
            b = a - d
            if a**5 - b**5 == x:
                print(a, b)
                exit()

Fixed submission:
x = int(input())
for a in range(-118,120):
    for b in range(-119, 119):
        if a**5 - b**5 == x:
            print(a,b)
            exit()

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
div = make_divisors(x)
for d in div:
    for a in range(0,d+1):
        b = a - d
        if a**4 + (a**3)*b + (a**2)*(b**2) + a*(b**3) + b**4 == x/d:
            print(a, b)
            break

Fixed submission:
x = int(input())
for a in range(-118,120):
    for b in range(-119, 119):
        if a**5 - b**5 == x:
            print(a,b)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
n, *a = map(int, open(0).read().split())

for i in range(1,n+1):
    print(a.count(i))

Fixed submission:
import collections

n, *a = map(int, open(0).read().split())

l = collections.Counter(a)

for i in range(1,n+1):
    if l[i]:
        print(l[i])
    else:
        print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

for i in range(n-2):
  for j in range(i+1, n-1):
    k = j + (j - i)
    if k > n-1:
    	break
    if len(set([s[i], s[j], s[k]])) == 3:
      ans -= 1
print(ans)

Fixed submission:
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

for i in range(n-2):
  for j in range(i+1, n-1):
    k = j + (j - i)
    if k > n-1:
    	break
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

for i in range(n):
  diff = 1
  while i + 2 * diff <= n-1:
    if len(set([s[i], s[i+diff], s[i+2*diff]])) == 3:
      ans -= 1
    diff += 1
print(ans)

Fixed submission:
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

for i in range(n-2):
  for j in range(i+1, n-1):
    k = j + (j - i)
    if k > n-1:
    	break
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

for i in range(n):
  diff = 1
  while i + 2 * diff <= n-1:
    j = i + diff
    k = j + diff
    if len(set([s[i], s[j], s[k]])) == 3:
      ans -= 1
    diff += 1
print(ans)

Fixed submission:
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

for i in range(n-2):
  for j in range(i+1, n-1):
    k = j + (j - i)
    if k > n-1:
    	break
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
cnt = 0
for i in range(n-2):
    for d1 in range(1, n-1-i):
        for d2 in range(1-d1, n-i-2*d1):
            if d2 != 0:
                j = i + d1
                k = i + 2*d1 + d2
                if len(set([s[i],s[j],s[k]]))==3:
                    cnt += 1
print(cnt)

Fixed submission:
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

for i in range(n-2):
  for j in range(i+1, n-1):
    k = j + (j - i)
    if k > n-1:
    	break
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
inversion_flag = 0
for _ in range(q):
    inp =  list(input().split())
    if inp[0] == '1':
        inversion_flag = not inversion_flag
    else:
        if inp[1] == '1':
            if not inversion_flag:
                s = inp[2] + s
            else:
                s = s + inp[2]
        else:
            if not inversion_flag:
                s = s + inp[2]
            else:
                s = inp[2] + s
if inversion_flag:
    print(s[::-1])
else:
    print(s)

Fixed submission:
from collections import deque

s = input()
q = int(input())
isInversed = False
front = deque()
back = deque()
for _ in range(q):
    inp =  list(input().split())
    if inp[0] == '1':
        isInversed = not isInversed
    else:
        if inp[1] == '1':
            if not isInversed:
                front.appendleft(inp[2])
            else:
                back.append(inp[2])
        else:
            if not isInversed:
                back.append(inp[2])
            else:
                front.appendleft(inp[2])

front_str = ''.join(front)
back_str = ''.join(back)
ans = front_str + s + back_str

if not isInversed:
    print(ans)
else:
    print(ans[::-1])
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
tmp = [10]*n

for _ in range(m):
    s,c = map(int, input().split())
    tmp[s-1] = min(tmp[s-1],c)
for i in range(n):
    if tmp[i] == 10:
        tmp[i] = 0

ans = ''.join(map(str,tmp))
if ans[0] == '0':
    print('-1')
else:
    print(num)

Fixed submission:
n, m = map(int, input().split())
tmp = [10]*n

for _ in range(m):
    s,c = map(int, input().split())
    if tmp[s-1] == 10 or tmp[s-1]==c:
        tmp[s-1] = c
    else:
        print('-1')
        exit()

for i in range(n):
    if tmp[i] == 10:
        if i == 0 and n != 1:
            tmp[i] = 1
        else:
            tmp[i] = 0

ans = ''.join(map(str,tmp))

if n != 1 and ans[0] == '0':
    print('-1')
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,a,b = map(int, input().split())

mod = 1000000007

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

mod = 10**9+7 #出力の制限
N = n
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 )

print(pow(2,n,mod)-1-(cmb(n,a,mod)+cmb(n,b,mod)))

Fixed submission:
n, a, b = map(int, input().split())
mod = 7+10**9
def comb(n,c,mod):
  x = 1
  y = 1
  for i in range(n-c+1,n+1):
    x = x*i%mod
  for j in range(1,c+1):
    y = y*j%mod
  return (x * pow(y, mod-2, mod)) % mod
c_a = comb(n,a,mod)
c_b = comb(n,b,mod)
print((pow(2,n,mod)-1 -(c_a+c_b))%mod)

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

mod = 1000000007

def cmb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
  
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

print(pow(2,n,mod)-1-(cmb(n,a,mod)+cmb(n,b,mod)))

Fixed submission:
n, a, b = map(int, input().split())
mod = 7+10**9
def comb(n,c,mod):
  x = 1
  y = 1
  for i in range(n-c+1,n+1):
    x = x*i%mod
  for j in range(1,c+1):
    y = y*j%mod
  return (x * pow(y, mod-2, mod)) % mod
c_a = comb(n,a,mod)
c_b = comb(n,b,mod)
print((pow(2,n,mod)-1 -(c_a+c_b))%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
ps = list(map(int, input().split()))

ps_k = [sum(ps[i:i+k]) for i in range(n)]

start = ps_k.index(max(ps_k))

print(sum([(i*(i+1))/ (2*i) for i in ps[start:start+k]]))

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

tmp = sum(ps[:k])
max_ps = tmp
start = 0

for i in range(1,n-k+1):
    tmp = tmp-ps[i-1]+ps[i+k-1]
    if tmp >= max_ps:
        max_ps = tmp
        start = i

print(sum([(i*(i+1))/ (2*i) for i in ps[start:start+k]]))

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
ps = list(map(int, input().split()))
ans = 0
max_ps = 0
start = 0

ps_k = [sum(ps[i:i+k]) for i in range(n)]

start = ps_k.index(max(ps_k))

print(sum([sum(range(i+1))/i for i in ps[start:start+k]]))

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

tmp = sum(ps[:k])
max_ps = tmp
start = 0

for i in range(1,n-k+1):
    tmp = tmp-ps[i-1]+ps[i+k-1]
    if tmp >= max_ps:
        max_ps = tmp
        start = i

print(sum([(i*(i+1))/ (2*i) for i in ps[start:start+k]]))

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
ps = list(map(int, input().split()))
ans = 0
max_ps = 0
start = 0

for i in range(n):
    if max_ps <= sum(ps[i:i+k]):
        start = i
        max_ps = sum(ps[i:i+k])

print(sum([sum(range(i+1))/i for i in ps[start:start+k]]))

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

tmp = sum(ps[:k])
max_ps = tmp
start = 0

for i in range(1,n-k+1):
    tmp = tmp-ps[i-1]+ps[i+k-1]
    if tmp >= max_ps:
        max_ps = tmp
        start = i

print(sum([(i*(i+1))/ (2*i) for i in ps[start:start+k]]))

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
ps = list(map(int, input().split()))
ans = 0
max_ps = 0
start = 0

for i in range(n):
    if max_ps <= sum(ps[i:i+k]):
        start = i
        max_ps = sum(ps[i:i+k])

for i in ps[start:start+k]:
    ans+=sum(range(i+1))/i

print(ans)

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

tmp = sum(ps[:k])
max_ps = tmp
start = 0

for i in range(1,n-k+1):
    tmp = tmp-ps[i-1]+ps[i+k-1]
    if tmp >= max_ps:
        max_ps = tmp
        start = i

print(sum([(i*(i+1))/ (2*i) for i in ps[start:start+k]]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(n):
  sorted_p = sorted(p[:i+1])
  if sorted_p[0] == p[i]:
    cnt += 1
print(cnt)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
cnt = 0
p_min = n+1
for i in range(n):
  if p_min > p[i]:
    cnt += 1
    p_min = p[i]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(n):
  if min(p[:i+1]) == p[i]:
    cnt += 1
print(cnt)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
cnt = 0
p_min = n+1
for i in range(n):
  if p_min > p[i]:
    cnt += 1
    p_min = p[i]
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ps = [input().split() for _ in range(m)]
all_ac = set(int(p) for p,s in ps if s=='AC')
ac = []
pena_cnt = 0
ac_cnt = 0
for p,s in ps:
  p = int(p)
  if p in all_ac:
    if p not in ac:
      if s == 'WA':
        pena_cnt += 1
      else:
        ac_cnt += 1
        ac.append(p)
print(ac_cnt, pena_cnt)

Fixed submission:
n, m = map(int, input().split())
ps = [input().split() for _ in range(m)]
all_ac = set(int(p) for p,s in ps if s=='AC')
ac = set()
pena_cnt = 0
ac_cnt = 0
for p,s in ps:
  p = int(p)
  if p in all_ac:
    if p not in ac:
      if s == 'WA':
        pena_cnt += 1
      else:
        ac_cnt += 1
        ac.add(p)
print(ac_cnt, pena_cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import re

n = int(input())
s = input()
cnt = 0

for i in range(1000):
    tgt = str(i).zfill(3)
    j = 0
    for i in range(n):
        if tgt[j] == s[i]:
            j += 1
        if j == 3:
            cnt += 1
            break
print(cnt)

Fixed submission:
n = int(input())
s = input()
cnt = 0

for N in range(1000):
    tgt = str(N).zfill(3)
    if tgt[0] in s:
        i = s.index(tgt[0])
        if tgt[1] in s[i+1:]:
            j = s[i+1:].index(tgt[1]) + i
            if tgt[2] in s[j+2:]:
                cnt += 1
print(cnt)

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

n = int(input())
s = input()
cnt = 0

for i in range(1000):
    tgt = str(i).zfill(3)
    pattern = '.*' + tgt[0] + '.*' + tgt[1] + '.*' + tgt[2] + '.*'
    if re.match(pattern, s):
        cnt += 1
print(cnt)

Fixed submission:
n = int(input())
s = input()
cnt = 0

for N in range(1000):
    tgt = str(N).zfill(3)
    if tgt[0] in s:
        i = s.index(tgt[0])
        if tgt[1] in s[i+1:]:
            j = s[i+1:].index(tgt[1]) + i
            if tgt[2] in s[j+2:]:
                cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = [str(a.index(i)+1) for i in range(1,n+1) ]
print(' '.join(ans))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = [0 for _ in range(n)]
for i, A in enumerate(a):
  ans[A-1] = str(i+1)
print(' '.join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
for i in range(1,n+1):
  print(a.index(i)+1, end = " ")

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = [0 for _ in range(n)]
for i, A in enumerate(a):
  ans[A-1] = str(i+1)
print(' '.join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
print(sum([i for i in range(n)]))

Fixed submission:
n = int(input())
print(n*(n-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n = int(input())
s = [input() for _ in range(n)]
cnt = 0

for i in range(n):
    for j in range(i+1,n):
        if Counter(s[i]) == Counter(s[j]):
            cnt+=1
print(cnt)

Fixed submission:
from collections import Counter

n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
c = Counter(s)

cnt = 0

for key in c:
    val = c[key]
    cnt += val*(val-1)//2

print(cnt)
Buggy python submission (verdict: Runtime Error):
s = input()
s_sorted = ''.join(sorted(s))
if s_sorted[0]==s_sorted[1] and s_sorted[2]==s_sorted[3] and S[1]!=S[2]:
  print('Yes')
else:
  print('No')

Fixed submission:
s = input()
s_sorted = ''.join(sorted(s))
if (s_sorted[0]==s_sorted[1]) and (s_sorted[2]==s_sorted[3]) and (s_sorted[1]!=s_sorted[2]):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
S = input()
f,e = int(S[:2]),int(S[2:])
if f==0 of e==0 or (f>12 and e>12):
  print('NA')
  exit()
if 1<=f<=12:
  if e>12:
    print('MMYY')
  elif 1<=e<=12
    print('AMBIGUOUS')
elif f>12:
  if 1<=e<=12:
    print('YYMM')

Fixed submission:
S = input()
f,e = int(S[:2]),int(S[2:])
if (f > 12 or f == 0) and 0 < e <= 12:
   print('YYMM')
elif 0 < f <= 12 and (e > 12 or e == 0):
   print('MMYY')
elif 0 < f <= 12 and 0 < e <= 12:
   print('AMBIGUOUS')
else:
    print('NA')

Buggy python submission (verdict: Runtime Error):
S = input()
f,e = int(S[:2]),int(S[2:])
if f==0 or e==0 or (f>12 and e>12):
  print('NA')
else:
  if 1<=f<=12 and e>12:
    print('MMYY')
  elif f>12 and 1<=e<=12:
    print('YYMM')
  elif 1<=f<=12, 1<=e<=12
    print('AMBIGUOUS')

Fixed submission:
S = input()
f,e = int(S[:2]),int(S[2:])
if (f > 12 or f == 0) and 0 < e <= 12:
   print('YYMM')
elif 0 < f <= 12 and (e > 12 or e == 0):
   print('MMYY')
elif 0 < f <= 12 and 0 < e <= 12:
   print('AMBIGUOUS')
else:
    print('NA')