Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque

mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

N,M = MI()
links = [[] for _ in range(N)]

for _ in range(M):
    a, b = MI()
    a -= 1
    b -= 1
    links[a].append(b)
    links[b].append(a)

ans = [-1] * N
ans[0] = 0
q = deque([(0, 0)])
while q:
  print(ans)
  room, prev = q.popleft()
  for next_ in links[room]:
    if ans[next_] < 0:
      ans[next_] = room
      q.append((next_, room))
for i in range(1,N):
  print(ans[i]+1)

Fixed submission:
from collections import deque

mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

N,M = MI()
links = [[] for _ in range(N)]

for _ in range(M):
    a, b = MI()
    a -= 1
    b -= 1
    links[a].append(b)
    links[b].append(a)

ans = [-1] * N
ans[0] = 0
q = deque([(0, 0)])
while q:
  room, prev = q.popleft()
  for next_ in links[room]:
    if ans[next_] < 0:
      ans[next_] = room+1
      q.append((next_, room))
print("Yes")
for i in range(1,N):
  print(ans[i])

Buggy python submission (verdict: Runtime Error):
from collections import deque

mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

N,M = MI()
links = [[] for _ in range(N)]

for _ in range(M):
    a, b = MI()
    a -= 1
    b -= 1
    links[a].append(b)
    links[b].append(a)

ans = [-1] * N
ans[0] = 0
q = deque([(0, 0)])
while q:
    room, prev = q.popleft()
    for next_ in links[room]:
        if ans[next_] < 0:
            ans[next_] = ans[room+1]+1
            q.append((next_, room))
for i in range(1,N):
  print(ans[i])

Fixed submission:
from collections import deque

mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

N,M = MI()
links = [[] for _ in range(N)]

for _ in range(M):
    a, b = MI()
    a -= 1
    b -= 1
    links[a].append(b)
    links[b].append(a)

ans = [-1] * N
ans[0] = 0
q = deque([(0, 0)])
while q:
  room, prev = q.popleft()
  for next_ in links[room]:
    if ans[next_] < 0:
      ans[next_] = room+1
      q.append((next_, room))
print("Yes")
for i in range(1,N):
  print(ans[i])
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
good = [0]*N

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

for j in range(M):
  a, b = map(int,input().split())
  if(H[a-1] == H[b-1]):
    good[a-1] += 1
    good[b-1] += 1
  elif(H[a-1] < H[b-1]):
    good[a-1] += 1
  elif(H[b-1] < H[a-1]:
    good[b-1] += 1
count = 0
for i in range(N):
  if(good[i] == 0):
    count += 1
print(count)

Fixed submission:
N, M = map(int,input().split())
good = [0]*N

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

for j in range(M):
  a, b = map(int,input().split())
  if(H[a-1] == H[b-1]):
    good[a-1] += 1
    good[b-1] += 1
  elif(H[a-1] < H[b-1]):
    good[a-1] += 1
  else:
    good[b-1] += 1
count = 0
for i in range(N):
  if(good[i] == 0):
    count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
a = []
b = 0
flag = True
for i in range(1,int(X**(1/5))+1):
  if(X%i== 0):
    a.append(i)
while(flag):
  for i in range(len(a)): 
    if(pow(b+a[i],5)-pow(b,5) == X):
      print("%d %d"%(b+a[i],b))
      flag = False
      break
  b -= 1
  if(-pow(b,5) > X):
    b = int(X**(1/5))

Fixed submission:
X = int(input())
a = []
b = 0
flag = True
num = 120
if(X <= 120):
  num = X
for i in range(1,num+1):
  if(X%i== 0):
    a.append(i)
while(flag):
  for i in range(len(a)): 
    if(pow(b+a[i],5)-pow(b,5) == X):
      print("%d %d"%(b+a[i],b))
      flag = False
      break
  b -= 1
  if(b < -119):
    b = 119

Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
a = []
b = 0
flag = True
for i in range(1,X+1):
  if(X%i== 0):
    a.append(i)
  
while(flag):
  for i in range(len(a)): 
    if(pow(b+a[i],5)-pow(b,5) == X):
      print("%d %d"%(b+a[i],b))
      flag = False
      break
  b -= 1
  if(-pow(b,5) > X):
    b = int(X**(1/5))

Fixed submission:
X = int(input())
a = []
b = 0
flag = True
num = 120
if(X <= 120):
  num = X
for i in range(1,num+1):
  if(X%i== 0):
    a.append(i)
while(flag):
  for i in range(len(a)): 
    if(pow(b+a[i],5)-pow(b,5) == X):
      print("%d %d"%(b+a[i],b))
      flag = False
      break
  b -= 1
  if(b < -119):
    b = 119
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int,input().split())
max = 0
x = 0
n = int(B/A)
if(n < 1):n=1
if(A == 1 or B == 1):
  print(max)
else:
  while(x <= N):
    f = (A*x)//B - A*(x//B)
    #x += n
    x += 1
    #print(f)
    if(max <= f):
      max = f
    if(max != 0 and f == 0):
      break
  print(max)

Fixed submission:
A,B,N = map(int,input().split())
def f(x):
  f = int((A*x)/B)-A*int(x/B)
  return f
if(B-1 < N):
  print(f(B-1))
else:
  print(f(N))

Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int,input().split())
max = 0

for x in range(N+1):
  f = int(A*x/B) - A*int(x/B)
  if(max <= f):
    max = f
  if(max != 0 and f == 0):
    break
print(max)

Fixed submission:
A,B,N = map(int,input().split())
def f(x):
  f = int((A*x)/B)-A*int(x/B)
  return f
if(B-1 < N):
  print(f(B-1))
else:
  print(f(N))
Buggy python submission (verdict: Runtime Error):
S, W = int(input().split())

if(S > W):
  print("safe")
else:
  print("unsafe")

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

if(S > W):
  print("safe")
else:
  print("unsafe")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s=[]
for i in range(N):
  flag = 0
  a = input()
  for i in range(len(s)):
    if(s[i] == a):
      flag += 1
      break
  if(flag == 0):
    s.append(a)
print(len(s))

Fixed submission:
import collections
N = int(input())
s=[]
for i in range(N):
  s.append(input())
c = collections.Counter(s)
 
print(len(c))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s=[]
for i in range(N):
  flag = 0
  a = input()
  for i in range(len(s)):
    if(s[i] == a):
      flag += 1
  if(flag == 0):
    s.append(a)
print(len(s))

Fixed submission:
import collections
N = int(input())
s=[]
for i in range(N):
  s.append(input())
c = collections.Counter(s)
 
print(len(c))

Buggy python submission (verdict: Runtime Error):
N = int(input())
s=[]
for i in range(N):
  s.append(input())
num = 0

while(len(s) != 0):
  flag = 0
  a = s[0]
  num += 1
  for i in range(len(s)):
    if(s[0] == s[i]):
      s.remove(a)
    
print(num)

Fixed submission:
import collections
N = int(input())
s=[]
for i in range(N):
  s.append(input())
c = collections.Counter(s)
 
print(len(c))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s=[]
for i in range(N):
  s.append(input())
num = 0

while(len(s) != 0):
  flag = 0
  a = s[0]
  num += 1
  for i in range(len(s)):
    if(s[0] == s[i]):
      flag += 1
  for i in range(flag):
    s.remove(a)
    
print(num)

Fixed submission:
import collections
N = int(input())
s=[]
for i in range(N):
  s.append(input())
c = collections.Counter(s)
 
print(len(c))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s=[]
for i in range(N):
  s.append(input())
num = 0

while(len(s) != 0):
  flag = 0
  a = s[0]
  num += 1
  for i in range(len(s)):
    if(s[0] == s[i]):
      flag += 1
  for i in range(flag):
    s.remove(a)
    
print(num)

Fixed submission:
import collections
N = int(input())
s=[]
for i in range(N):
  s.append(input())
c = collections.Counter(s)
 
print(len(c))

Buggy python submission (verdict: Runtime Error):
N = int(input())

s=[]
flag = 0
for i in range(N):
  s.append(input())
num = 0

while(len(s) != 0):
  for i in range(len(s)):
    if(s[0] == s[i]):
      flag += 1
  for i in range(flag):
    s.remove(s[0])
  num += 1
print(num)

Fixed submission:
import collections
N = int(input())
s=[]
for i in range(N):
  s.append(input())
c = collections.Counter(s)
 
print(len(c))
Buggy python submission (verdict: Runtime Error):
from math import factorial
a, b = map(int, input().split())
 
def count(x, y):
  a = factorial(x) / factorial(y) / factorial(x - y)
  return a
 
if(a+1== b):
  print(1)
else:
  count = 0
  for i in range(a-b+2):
    count += count(a,i+b)
  print(count)

Fixed submission:
a, b = map(int, input().split())
mod = pow(10,9) + 7

def cal(a,i):
  min = i*(i-1)/2
  max = a*(a-1)/2 - (a-i)*(a-i-1)/2
  return max - min + 1

count = 0
for i in range(a-b+2):
  count += cal(a+1,i+b)
print(int(count % mod))

Buggy python submission (verdict: Runtime Error):
from math import factorial
a = factorial(n) / factorial(r) / factorial(n - r)
a, b = map(int, input().split())

def count(x, y):
  a = factorial(x) / factorial(y) / factorial(x - y)
  return a

if(a+1== b):
  print(1)
else:
  count = 0
  for i in range(a-b+2):
    count += count(a,i+b)
  print(count)
  

Fixed submission:
a, b = map(int, input().split())
mod = pow(10,9) + 7

def cal(a,i):
  min = i*(i-1)/2
  max = a*(a-1)/2 - (a-i)*(a-i-1)/2
  return max - min + 1

count = 0
for i in range(a-b+2):
  count += cal(a+1,i+b)
print(int(count % mod))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

total = 0

while N > 0:
  total = (total + N % 10) % 9
  N = N // 10
  
if total % 9 == 0:
  print("Yes")
else:
  print("No")

Fixed submission:
if sum([int(s) for s in list(input().split())]) % 9 == 0:
  print("Yes")
else:
  print("No")

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

total = 0

while N > 0:
  total += N % 10
  N = N // 10
  
if total % 9 == 0:
  print("Yes")
else:
  print("No")

Fixed submission:
if sum([int(s) for s in list(input().split())]) % 9 == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
X, K, D = map(int, input().split())

X = abs(X)

final = -1

for n in range(K):
  X = abs(X - D)
  if X <= D / 2:
    if (K-n) % 2 == 0:
      final = abs(X-D)
      break
    else:
      final = X
      break

if final >= 0:
  print(final)
else:
  print(X)

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

X = abs(X)

final = -1

q, n = X % D, X // D

if n >= K:
  print(X - K * D)
else:
  if q <= X / 2:
    if (K - n) % 2 == 0:
      print(q)
    else:
      print(D - q)
  else:
    if (K - n) % 2 == 0:
      print(q)
    else:
      print(D - q)
Buggy python submission (verdict: Runtime Error):
aalphabets = [""] + [s for s in "abcdefghijklmnopqrstuvwxyz"]

s = int(input())

nums = []

while s > 0:
  nums.append((s - 1) % 26 + 1)
  s = (s - 1) // 26

res = ""
  
for _ in range(len(nums)):
  res = res + alphabets[nums.pop()]

print(res)

Fixed submission:
alphabets = [""] + [s for s in "abcdefghijklmnopqrstuvwxyz"]

s = int(input())

nums = []

while s > 0:
  nums.append((s - 1) % 26 + 1)
  s = (s - 1) // 26

res = ""
  
for _ in range(len(nums)):
  res = res + alphabets[nums.pop()]

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

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

dct = defaultdict(int)
for _ in range(N):
  dct[nums.pop()] += 1

for _ in range(Q):
  B, C = map(int,input().split())
  if B in dct:
    if C in dct:
      dct[C] += dct.pop(B)
    else:
      dct[C] = dct.pop(B)

  sum = 0
  for k, v in dct.items():
    sum += k * v
  
  print(sum)


Fixed submission:
from collections import defaultdict

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

res = 0

dct = defaultdict(int)
for _ in range(N):
  n = nums.pop()
  dct[n] += 1
  res += n

for _ in range(Q):
  B, C = map(int,input().split())
  if B in dct:
    n = dct.pop(B)
    res += (C - B) * n
    if C in dct:
      dct[C] += n
    else:
      dct[C] = n
  
  print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
nums = [int(s) for s in input().rstrip().split()]
Q = int(input())

dct = {}
for k in range(N):
  n = nums[k]
  if n in dct:
    dct[n] += 1
  else:
    dct[n] = 1

for _ in range(Q):
  B, C =(int(s) for s in input().rstrip().split())
  if B in dct:
    if C in dct:
      dct[C] += dct.pop(B)
    else:
      dct[C] = dct.pop(B)

  sum = 0
  for k, v in dct.items():
    sum += k * v
  
  print(sum)


Fixed submission:
from collections import defaultdict

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

res = 0

dct = defaultdict(int)
for _ in range(N):
  n = nums.pop()
  dct[n] += 1
  res += n

for _ in range(Q):
  B, C = map(int,input().split())
  if B in dct:
    n = dct.pop(B)
    res += (C - B) * n
    if C in dct:
      dct[C] += n
    else:
      dct[C] = n
  
  print(res)

Buggy python submission (verdict: Runtime Error):
N = int(input())
nums = [int(s) for s in input().rstrip().split()]
Q = int(input())

dct = {}
for k in range(N):
  n = nums[k]
  if n in dct:
    dct[n] += 1
  else:
    dct[n] = 1

for _ in range(Q):
  B, C =(int(s) for s in input().rstrip().split())
  if C in dct:
    dct[C] += dct.pop(B)
  else:
    dct[C] = dct.pop(B)

  sum = 0
  for k, v in dct.items():
    sum += k * v
  
  print(sum)

Fixed submission:
from collections import defaultdict

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

res = 0

dct = defaultdict(int)
for _ in range(N):
  n = nums.pop()
  dct[n] += 1
  res += n

for _ in range(Q):
  B, C = map(int,input().split())
  if B in dct:
    n = dct.pop(B)
    res += (C - B) * n
    if C in dct:
      dct[C] += n
    else:
      dct[C] = n
  
  print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))

from functools import reduce as r
from operator import mul

ans=r(mul,a)

if ans>10**18:
  print(-1)
else:
  print(ans)

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

if 0 in a:
  print(0)
  exit()

ans=1
for x in a[::-1]:
  ans*=x
  if ans>10**18:
    print(-1)
    exit()
print(ans)

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

ans=1
for x in a:
  ans*=x

if ans>10**18:
  print(-1)
else:
  print(ans)

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

if 0 in a:
  print(0)
  exit()

ans=1
for x in a[::-1]:
  ans*=x
  if ans>10**18:
    print(-1)
    exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
t=input()
ans=''
for c in t:
  if c=='?':
    ans+='D'
  else:
    ans+=c
print(ans)

Fixed submission:
t=input()
print(t.replace('?','D'))
Buggy python submission (verdict: Runtime Error):
x=int(input())

b=0

while 1:
  a5=x+b**5
  a=a5**0.2
  if a-int(a)==0:
    print(int(a),b)
    exit()
  
  a5=x-b**5
  a=a5**0.2
  if a-int(a)==0:
    print(int(a),-b)
    exit()
  
  b+=1

Fixed submission:
x=int(input())

def rt5(a):
  if a==0:
    return 0
  i=1
  while 1:
    s=i**5
    if a==s:
      return i
    elif a==-s:
      return -i
    elif abs(a)<s:
      return False
    i+=1

b=0

while 1:
  a5=x+b**5
  a=rt5(a5)
  if a==False:
    pass
  else:
    print(a,b)
    exit()
  
  a5=x-b**5
  a=rt5(a5)
  if a==False:
    pass
  else:
    print(a,-b)
    exit()
  b+=1
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k] and j-i!=k-j:
        cnt+=1
print(cnt)

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

r,g,b=s.count('R'),s.count('G'),s.count('B')

cnt=0

for i in range(n):
  d=0
  while 1:
    d+=1
    j=i+d
    k=j+d
    if not k<n:
      break
    if not (s[i]==s[j] or s[j]==s[k] or s[k]==s[i]):
      cnt+=1
print(r*g*b-cnt)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]

arr=[str(i) for i in range(10**(n-1),10**n)]

for x in arr:
  flag=[False]*n
  for i,tmp in enumerate(l):
    s,c=tmp
    if x[s-1]==str(c):
      flag[i]=True
  if all(flag):
    print(x)
    exit()
print(-1)

Fixed submission:
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]

arr=[str(i) for i in range(10**(n-1) if n>1 else 0,10**n)]

for x in arr:
  for i,tmp in enumerate(l):
    s,c=tmp
    if x[s-1]!=str(c):
      break
  else:
    print(x)
    exit()

print(-1)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=list(map(int,input().split()))

e=[0]*n

for i in range(n):
  e[i]=(1+p[i])/2
  if i!=0:
    e[i]+=e[i-1]

arr=[]

for i in range(k,n):
  s=i-k
  arr.append(e[i]-e[s])

print(max(arr))

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

e=[0]*n

for i in range(n):
  e[i]=(1+p[i])/2
  if i!=0:
    e[i]+=e[i-1]

arr=[]

if n==k:
  print(e[-1])
  exit()

for i in range(k,n):
  s=i-k
  arr.append(e[i]-e[s])

print(max(arr))

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
e=[(x+1)/2 for x in list(map(int,input().split()))]

e3=[sum(e[i:i+k]) for i in range(n-2)]

print(max(e3))

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

e=[0]*n

for i in range(n):
  e[i]=(1+p[i])/2
  if i!=0:
    e[i]+=e[i-1]

arr=[]

if n==k:
  print(e[-1])
  exit()

for i in range(k,n):
  s=i-k
  arr.append(e[i]-e[s])

print(max(arr))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[input().split() for _ in range(m)]
arr=[]
ac,wa=0,0
acl=[False for _ in range(m)]
for r in l:
  p,s=int(r[0]),r[1]
  if s=='AC' and acl[p]==False:
    arr.append([p,s])
    acl[p]=True
  elif s=='WA' and acl[p]==False:
    arr.append([p,s])
    
for r in arr:
  p,s=r
  if s=='WA' and acl[p]:
    wa+=1
  elif s=='AC':
    ac+=1
    
print(ac,wa)

Fixed submission:
n,m=map(int,input().split())
l=[input().split() for _ in range(m)]
arr=[]
ac,wa=0,0
acl=[False for _ in range(n)]
for r in l:
  p,s=int(r[0])-1,r[1]
  if s=='AC' and acl[p]==False:
    arr.append([p,s])
    acl[p]=True
  elif s=='WA' and acl[p]==False:
    arr.append([p,s])
    
for r in arr:
  p,s=r
  if s=='WA' and acl[p]:
    wa+=1
  elif s=='AC':
    ac+=1
    
print(ac,wa)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l=[input().split() for _ in range(m)]
arr=[]
ac,wa=0,0

for r in l:
  p,s=int(r[0]),r[1]
  if s=='AC' and not ([p,'AC'] in arr):
    arr.append([p,s])
  elif s=='WA' and not ([p,'AC'] in arr):
    arr.append([p,s])
for r in arr:
  p,s=r
  if s=='WA' and [p,'AC'] in arr:
    wa+=1
  if s=='AC':
    ac+=1
    
print(ac,wa)

Fixed submission:
n,m=map(int,input().split())
l=[input().split() for _ in range(m)]
arr=[]
ac,wa=0,0
acl=[False for _ in range(n)]
for r in l:
  p,s=int(r[0])-1,r[1]
  if s=='AC' and acl[p]==False:
    arr.append([p,s])
    acl[p]=True
  elif s=='WA' and acl[p]==False:
    arr.append([p,s])
    
for r in arr:
  p,s=r
  if s=='WA' and acl[p]:
    wa+=1
  elif s=='AC':
    ac+=1
    
print(ac,wa)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
temp=n+1
for i in range(1,n):
  if n%i==0 and temp>=i+n//i:
    temp=i+n//i
  elif n%i==0 and temp<i+n//i:
    break
print(temp-2)

Fixed submission:
import math
n=int(input())
temp=n+1
for i in range(int(math.sqrt(n)),0,-1):
  if n%i==0:
    print(i+n//i-2)
    exit()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
print(' '.join([str(a.index(i)+1) for i in range(1,n+1)]))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[0 for _ in range(n)]
for i in range(n):
  ans[a[i]-1]=i+1
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
ans=0
for x in set(s):
  cnt=s.count(x)
  ans+=cnt*(cnt-1)/2
print(int(ans))

Fixed submission:
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
ans=0
cnt={}
for i in range(n):
  if s[i] in cnt:
    cnt[s[i]]+=1
  else:
    cnt[s[i]]=1
print(sum(cnt[key]*(cnt[key]-1)//2 for key in cnt))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=sorted([''.join(sorted(input())) for _ in range(n)])
ans=0
for x in set(s):
  cnt=s.count(x)
  ans+=cnt*(cnt-1)//2
print(ans)


Fixed submission:
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
ans=0
cnt={}
for i in range(n):
  if s[i] in cnt:
    cnt[s[i]]+=1
  else:
    cnt[s[i]]=1
print(sum(cnt[key]*(cnt[key]-1)//2 for key in cnt))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=sorted([''.join(sorted(input())) for _ in range(n)])
cnt=0
print(sum([s.count(x)*(s.count(x)-1)//2 if s.count(x)>1 else 0 for x in set(s)]))


Fixed submission:
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
ans=0
cnt={}
for i in range(n):
  if s[i] in cnt:
    cnt[s[i]]+=1
  else:
    cnt[s[i]]=1
print(sum(cnt[key]*(cnt[key]-1)//2 for key in cnt))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[sorted(input()) for _ in range(n)]
cnt=0
for i in range(n):
  for j in range(n):
    if i>=j:
      continue
    if s[i]==s[j]:
      cnt+=1
print(cnt)

Fixed submission:
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
ans=0
cnt={}
for i in range(n):
  if s[i] in cnt:
    cnt[s[i]]+=1
  else:
    cnt[s[i]]=1
print(sum(cnt[key]*(cnt[key]-1)//2 for key in cnt))

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=[input().sort() for _ in range(n)]
cnt=0
for i in range(n):
  for j in range(n):
    if i>=j:
      continue
    if s[i]==s[j]:
      cnt+=1
print(cnt)

Fixed submission:
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
ans=0
cnt={}
for i in range(n):
  if s[i] in cnt:
    cnt[s[i]]+=1
  else:
    cnt[s[i]]=1
print(sum(cnt[key]*(cnt[key]-1)//2 for key in cnt))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[input() for _ in range(n)]
cnt=0
for i in range(n):
  for j in range(n):
    if i>=j:
      continue
    if sorted(s[i])==sorted(s[j]):
      cnt+=1
print(cnt)

Fixed submission:
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
ans=0
cnt={}
for i in range(n):
  if s[i] in cnt:
    cnt[s[i]]+=1
  else:
    cnt[s[i]]=1
print(sum(cnt[key]*(cnt[key]-1)//2 for key in cnt))
Buggy python submission (verdict: Runtime Error):
print(3*int(input())**2

Fixed submission:
print(3*int(input())**2)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for _ in range(n)]
m=max(a)
for i in range(n):
  print(max([a[j] for j in range(n) if i!=j]))

Fixed submission:
n=int(input())
a=[int(input()) for _ in range(n)]
m=max(a)
b=sorted(a)
for i in range(n):
  if a[i]==m:
    print(b[-2])
  else:
    print(m)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for _ in range(n)]
m=max(a)
for i in range(n):
  if a[i]<m:
    print(m)
  else:
    print(sorted(a)[-2])

Fixed submission:
n=int(input())
a=[int(input()) for _ in range(n)]
m=max(a)
b=sorted(a)
for i in range(n):
  if a[i]==m:
    print(b[-2])
  else:
    print(m)