Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
x=input()
p=x.count("1")
Ma=[1]+[0]*(n-1)
Mb=[1]+[0]*(n-1)
for i in range(1,n):
  Ma[i]=Ma[i-1]*2%(p-1)
  Mb[i]=Mb[i-1]*2%(p+1)
Sa=Sb=0
for i in range(n):
  if x[i]=="1":
    Sa+=Ma[n-1-i]
    Sb+=Mb[n-1-i]
for i in range(n):
  a=1
  if x[i]=="1":
    s=(Sa-Ma[n-1-i])%(p-1)
  else:
    s=(Sb+Mb[n-1-i])%(p+1)
  while(s>0):
    t=0
    r=s
    while(r>0):
      t+=r&1
      r//=2
    s%=t
    a+=1
  print(a)  

Fixed submission:
n=int(input())
x=input()
p=x.count("1")
Ma=[1]+[0]*(n-1)
Mb=[1]+[0]*(n-1)
for i in range(1,n):
  if p>1:
    Ma[i]=Ma[i-1]*2%(p-1)
  else:
    Ma[i]=0
    Ma[0]=0
  Mb[i]=Mb[i-1]*2%(p+1)
Sa=Sb=0
for i in range(n):
  if x[i]=="1":
    Sa+=Ma[n-1-i]
    Sb+=Mb[n-1-i]
for i in range(n):
  a=0
  if x[i]=="1":
    if p==1:
      s=0
    else:
      s=(Sa-Ma[n-1-i])%(p-1)
      a+=1
  else:
    s=(Sb+Mb[n-1-i])%(p+1)
    a+=1
  while(s>0):
    t=0
    r=s
    while(r>0):
      t+=r&1
      r//=2
    s%=t
    a+=1
  print(a)
Buggy python submission (verdict: Runtime Error):
print(sum((j:=i+1)(x:=n//j)*(x+1)*i//2for i in range(n:=int(input()))))

Fixed submission:
n=int(input());print(sum((x:=n//i)*(x+1)*i//2 for i in range(1,n+1)))
Buggy python submission (verdict: Time Limit Exceeded):
n,k,*A=map(int,open(0).read().split());e=enumerate
for _ in '_'*min(k,99):
  S=[0]*(n+1)
  B=[0]*(n+1)
  for i,a in e(A):S[max(0,i-a)]+=1;S[min(n,i+a+1)]-=1
  for i,s in e(S[:-1]):B[i+1]=B[i]+s
  A=B[1:]
print(*A)

Fixed submission:
n,k,*A=map(int,open(0).read().split());e=enumerate
for _ in '_'*min(k,99):
  S=[0]*(n+1)
  B=[0]*(n+1)
  for i,a in e(A):S[max(0,i-a)]+=1;S[min(n,i+a+1)]-=1
  for i,s in e(S[:-1]):B[i+1]=B[i]+s
  A=B[1:]
print(*A)
Buggy python submission (verdict: Runtime Error):
a,n=0,int(input())
for i in range(2,int(n**0.5+1)):x=0
  while(n%i==0):n//=i;x+=1
  j=1
  while(x>=j):a+=1;x-=j;j+=1
print(1 if n-1 else a)

Fixed submission:
a,n=0,int(input())
for i in range(2,int(n**0.5+1)):
  x=0
  while(n%i==0):n//=i;x+=1
  j=1
  while(x>=j):a+=1;x-=j;j+=1
print(a+(n>1))

Buggy python submission (verdict: Runtime Error):
import itertools
import copy
n=int(input())
c=0
A=[]
for i in range(2,int(n**0.5+1)):
  if n%i==0:
    a=0
    while(n%i==0):
      n//=i
      a+=1
    A.append(a)
l=len(A)
i=1
while(sum(A)>=l and l>0):
  for j in itertools.combinations_with_replacement(range(l), i):
    for k in j:
      C=deepcopy(A)
      if A[k]==0:
        A[k]=C[k]
        break
      else:
        A[k]-=1
    else:
      c+=1
  B=[]
  for a in A:
    if a!=0:
      B.append(a)
  A=B
  l=len(A)
  i+=1
print(1 if c!=1 and c==0 else c)

Fixed submission:
a,n=0,int(input())
for i in range(2,int(n**0.5+1)):
  x=0
  while(n%i==0):n//=i;x+=1
  j=1
  while(x>=j):a+=1;x-=j;j+=1
print(a+(n>1))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
L=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
A=[0]+[-1]*(n-1)
B=[[0,L[0]]]
def wfs(A,B):
    C=[]
    f=False
    for b in B:
        for l in b[1]:
            if A[l]==-1:
                A[l]=b[0]
                C.append([l,L[l]])
                f=True
    if f:
        return wfs(A,C)
    else:
        print('Yes')
        for a in A[1:]:
            print(a+1)
wfs(A,B)

Fixed submission:
import sys
sys.setrecursionlimit(9**9)
n,m=map(int,input().split())
L=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
A=[0]+[-1]*(n-1)
B=[[0,L[0]]]
def wfs(A,B):
    C=[]
    f=False
    for b in B:
        for l in b[1]:
            if A[l]==-1:
                A[l]=b[0]
                C.append([l,L[l]])
                f=True
    if f:
        return wfs(A,C)
    else:
        print('Yes')
        for a in A[1:]:
            print(a+1)
wfs(A,B)
Buggy python submission (verdict: Runtime Error):
import math
print(int(input)*2*math.pi)

Fixed submission:
import math
print(int(input())*2*math.pi)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
ans=0
r=g=b=0
R=[0 for _ in range(n)]
G=[0 for _ in range(n)]
B=[0 for _ in range(n)]
for i in range(i):
    if s[i]='R':r+=1
    elif s[i]='G':g+=1
    else:b+=1
    R[i]=r
    G[i]=g
    B[i]=b
for i in range(n):
    if s[i]='R':ans+=G[i]*(B[-1]-B[i])+B[i]*(G[-1]-G[i])
    elif s[i]='G':ans+=R[i]*(B[-1]-B[i])+B[i]*(R[-1]-R[i])
    else:ans+=R[i]*(G[-1]-G[i])+G[i]*(R[-1]-R[i])
print(ans)

Fixed submission:
from collections import Counter as C
n=int(input())
S=list(input())
a=1
L=C(S).most_common(3)
for l in L:
  a*=l[1]
for i in range(1,n):
  for j in range(n-2*i):
    if len(set((S[j],S[j+i],S[j+2*i])))==3:
      a-=1
print(a if len(L)>2 else 0)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
L=sorted(list(map(int,input().split())))
print('Yes' if all([L[i]*m*4>=sum(L) for i in range(m)] else 'No')

Fixed submission:
n,m=map(int,input().split())
L=sorted(list(map(int,input().split())),reverse=True)
print('Yes' if all([L[i]*m*4>=sum(L) for i in range(m)]) else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import*
H,W=map(int,input().split());M=[input()for _ in"_"*H];C=[[999]*W for _ in"_"*H];C[0][0]=0;q=deque([[0,0]])
while q:
  x,y=q.popleft()
  for i,j in [[1,0],[0,1]]:
    h,w=x+i,y+j
    if H>h and W>w:C[h][w]=min([C[h-1][w]+(M[h-1][w]<"."),999][0>h],[C[h][w-1]+(M[h][w-1]<"."),999][0>w]);q.append([h,w])
print(C[-1][-1]+(M[-1][-1]<"."))

Fixed submission:
H,W=map(int,input().split());M=[input()for _ in"_"*H];D=[[0]*-~W for _ in"_"*-~H]
for i in range(H):
  for j in range(W):
    a=b=999
    if i>0:a=D[i][j+1]+(M[i-1][j]>M[i][j])
    if j>0:b=D[i+1][j]+(M[i][j-1]>M[i][j])
    D[i+1][j+1]=min(a,b,999*(i+j>0))
print(D[-1][-1]+(M[0][0]<"."))
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
b=1
for i in range(int(input())):
    q=input()
    if q=='1':b^=1
    else:
        a,f,c=q.split()
        S=c+S if (int(f)-1)^b else S+c 
print(S if b else S[::-1])

Fixed submission:
S=input()
b=1
x=''
y=''
for i in range(int(input())):
    q=input()
    if q=='1':b^=1
    else:
        a,f,c=q.split()
        if (int(f)-1)^b:x=c+x
        else:y=y+c
S=x+S+y
print(S if b else S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S=list(input())
for i in range(int(input())):
    q=input()
    if q=='1':
        S.reverse()
    else:
        a,f,c=q.split()
        S=[c]+S if f=='1' else S+[c] 
print(''.join(S))

Fixed submission:
S=input()
b=1
x=''
y=''
for i in range(int(input())):
    q=input()
    if q=='1':b^=1
    else:
        a,f,c=q.split()
        if (int(f)-1)^b:x=c+x
        else:y=y+c
S=x+S+y
print(S if b else S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():return sys.stdin.readline().strip()
S=input()
Q=int(input())
for i in range(Q):
    q=input()
    if q=='1':
        S=S[::-1]
    else:
        a,f,c=q.split()
        S=''.join((c,S)) if f=='1' else ''.join((S,c)) 
print(S)

Fixed submission:
S=input()
b=1
x=''
y=''
for i in range(int(input())):
    q=input()
    if q=='1':b^=1
    else:
        a,f,c=q.split()
        if (int(f)-1)^b:x=c+x
        else:y=y+c
S=x+S+y
print(S if b else S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
for i in range(int(input())):
    q=input()
    if q=='1':
        S=S[::-1]
    else:
        a,f,c=q.split()
        S=''.join((c,S)) if f=='1' else ''.join((S,c)) 
print(S)

Fixed submission:
S=input()
b=1
x=''
y=''
for i in range(int(input())):
    q=input()
    if q=='1':b^=1
    else:
        a,f,c=q.split()
        if (int(f)-1)^b:x=c+x
        else:y=y+c
S=x+S+y
print(S if b else S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
for i in range(int(input())):
    q=input()
    if q=='1':S=S[::-1]
    else:
        a,f,c=q.split()
        S=c+S if f=='1' else S+c
print(S)        

Fixed submission:
S=input()
b=1
x=''
y=''
for i in range(int(input())):
    q=input()
    if q=='1':b^=1
    else:
        a,f,c=q.split()
        if (int(f)-1)^b:x=c+x
        else:y=y+c
S=x+S+y
print(S if b else S[::-1])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
N="a"*n
for _ in range(m):
    s,c=map(int,input().split())
    s-=1
    if (s==0 and c==0) or (N[s]!="a" and N[s]!=str(c)):
        print(-1)
        exit()        
    else:
        N=N[:s]+str(c)+N[s+1:]
if N[0]=="a":N[0]="1"
N=N.replace("a","0")
print(int(N))

Fixed submission:
n,m=map(int,input().split())
N="a"*n
for _ in range(m):
    s,c=map(int,input().split())
    s-=1
    if (s==0 and c==0 and n!=1) or (N[s]!="a" and N[s]!=str(c)):
        print(-1)
        exit()        
    else:
        N=N[:s]+str(c)+N[s+1:]
if N[0]=="a" and n!=1:N="1"+N[1:]
N=N.replace("a","0")
print(int(N))
Buggy python submission (verdict: Runtime Error):
import numpy as N
n,k=map(int,input().split())
A=N.array(list(map(int,input().split())))
A.sort()
p=A[A>0]
z=N.count_nonzero(A==0)
m=A[A<0]
r=10**19
l=-r
while r-l>1:
    b=(l+r)//2
    c=0
    if b>=0:
        c+=z*n
    c+=A.searchsorted(b//p,side='right').sum()
    c+=n*len(m)-A.searchsorted(-(-b//m),side='left').sum()
    c-=N.count_nonzero(A*A<=b)
    if c//2>=k:
        r=b
    else:
        l=b
print(r)

Fixed submission:
import numpy as N
n,k=map(int,input().split())
A=N.array(list(map(int,input().split())))
A.sort()
p=A[A>0]
z=N.count_nonzero(A==0)
m=A[A<0]
r=10**19
l=-r
while r-l>1:
    b=(l+r)//2
    c=0
    if b>=0:
        c+=z*n
    c+=A.searchsorted(b//p,side='right').sum()
    c+=n*len(m)-A.searchsorted(-(-b//m),side='left').sum()
    c-=N.count_nonzero(A*A<=b)
    if c//2>=k:
        r=b
    else:
        l=b
print(r)
Buggy python submission (verdict: Runtime Error):
h,n=map(int,input().split())
print('No' if eval(input().replace(" ","+"))<h else 'Yes')

Fixed submission:
h,n=map(int,input().split())
A=list(map(int,input().split()))
print('No' if sum(A)<h else 'Yes')
Buggy python submission (verdict: Time Limit Exceeded):
h,n=map(int,input().split())
M=[list(map(int,input().split())) for _ in range(n)]
dp = [[-(-i//M[0][0])*M[0][1] for i in range(1,h+1)] for _ in range(n)]
for i in range(1,n):
  for j in range(h):
    if j<M[i][0]:
      dp[i][j]=min(dp[i-1][j],M[i][1])
    else:
      dp[i][j]=min(dp[i-1][j],dp[i][j-M[i][0]]+M[i][1])
print(dp[n-1][h-1])

Fixed submission:
h,n=map(int,input().split())
M=[list(map(int,input().split())) for _ in range(n)]
dp = [[-(-i//M[0][0])*M[0][1] for i in range(1,h+1)] for _ in range(n)]
for i in range(1,n):
  for j in range(h):
    if j<M[i][0]:
      dp[i][j]=min(dp[i-1][j],M[i][1])
    else:
      dp[i][j]=min(dp[i-1][j],dp[i][j-M[i][0]]+M[i][1])
print(dp[n-1][h-1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
D=[[0 for _ in range(9)] for _ in range(9)]
for i in range(n):
    s=str(n)
    D[s[0]][s[-1]]+=1
a=0
for i in range(1,10):
    for j in range(1,10):
        a+=D[i][j]*D[j][i]
print(a)

Fixed submission:
n=int(input())
D=[[0 for _ in range(10)] for _ in range(10)]
for i in range(1,n+1):
    s=str(i)
    D[int(s[0])][int(s[-1])]+=1
a=0
for i in range(10):
    for j in range(10):
        a+=D[i][j]*D[j][i]
print(a)
Buggy python submission (verdict: Runtime Error):
n,k,s=map(int,input().split())
L=[s]*k+[min(s+1,10**9-1)]*(n-k)
print(''join(L))

Fixed submission:
n,k,s=map(int,input().split())
L=[s]*k+[min(s+1,10**9-1)]*(n-k)
print(' '.join(map(str,L)))
Buggy python submission (verdict: Runtime Error):
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
n,k=map(int,input().split())
A=sorted(list(map(int,input().split())))
s=0
c=int(cmb(n-1,k-1))
for i in range(n-k+1):
  s+=(A[n-1-i]-A[i])*c
  s%=10**9+7
  c=c*(n-k-i)//(n-1-i)
print(s)

Fixed submission:
n,m=map(int,input().split())
if m == 0:
  print(0,0)
  exit()
A=[[0,0] for _ in range(n)]
for i in range(m):
  p,s=input().split()
  p=int(p)-1
  if A[p][0]==1:
    continue
  elif s=='AC':
    A[p][0]=1
  else:
  	A[p][1]+=1
ac=0
wa=0
for a in A:
  ac+=a[0]
  if a[0] == 1:wa+=a[1]
print(ac,wa)
Buggy python submission (verdict: Runtime Error):
import itertools
A=list(itertools.permutations(range(1,int(input())+1)))
print(abs(A.index(map(int,input().split()))-A.index(map(int,input().split())))


Fixed submission:
import itertools
A=list(itertools.permutations(range(1,int(input())+1)))
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
print(abs(A.index(P)-A.index(Q)))

Buggy python submission (verdict: Runtime Error):
import itertool
A=itertool.permutations(range(1,int(input())+1))
print(abs(A.index(list(map(int,input().split())))-A.index(list(map(int,input().split()))))


Fixed submission:
import itertools
A=list(itertools.permutations(range(1,int(input())+1)))
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
print(abs(A.index(P)-A.index(Q)))

Buggy python submission (verdict: Runtime Error):
import itertool
A=itertool.permutation(range(1,int(input())+1))
print(abs(A.index(list(map(int,input().split())))-A.index(list(map(int,input().split()))))


Fixed submission:
import itertools
A=list(itertools.permutations(range(1,int(input())+1)))
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
print(abs(A.index(P)-A.index(Q)))
Buggy python submission (verdict: Runtime Error):
x=int(input())
while 1:
  for i in range(int(x**0.5+1)):
    if x//i==0:
      x+=1
      break
  else:
    print(X)
    break

Fixed submission:
x=int(input())
while 1:
  for i in range(2,int(x**0.5+1)):
    if x%i==0:
      x+=1
      break
  else:
    print(x)
    exit()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
a=0
c=0
m=max(A)
while(m):
    o=sum(map(lambda x:x&1,A))
    a+=(n-o)*o*2**c
    A=list(map(lambda x:x>>1,A))
    c+=1
    a%=10**9+7
    m//=2
print(a)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
a=0
c=0
m=max(A)
while(m):
    o=sum(map(lambda x:x&1,A))
    a+=(n-o)*o*2**c
    A=list(map(lambda x:x>>1,A))
    c+=1
    a%=10**9+7
    m//=2
print(a)
Buggy python submission (verdict: Runtime Error):
input()
I=list(map(int,input().split()))
L=[0,0,0]
a=1
m=10**9+7
for i in I:
  a*=L.count(i)
  L[L.index(i)]+=1
  a%=m
print(a)

Fixed submission:
input()
I=list(map(int,input().split()))
L=[0,0,0]
a=1
m=10**9+7
for i in I:
  if i in L:
  	a*=L.count(i)
  	L[L.index(i)]+=1
  	a%=m
  else:
    a=0
    break
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
c=0
for i in range(l+1):
  a=0
  b=0
  for j in range(i-1,-1,-1):
    if S[j]=='<':
      a+=1
    else:
      break
  for k in range(i,l):
    if S[k]=='>':
      b+=1
    else:
      break
  c+=max(a,b)
print(c)

Fixed submission:
S=input()
l=len(S)
A=[0]*(l+1)
B=[0]*(l+1)
for i in range(l):
  if S[i]=='<':
    A[i+1]=A[i]+1
  if S[l-i-1]=='>':
    B[l-i-1]=B[l-i]+1
print(sum([max(a,b) for a,b in zip(A,B)]))
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
a,b=map(int,input().split())
c=gcd(a,b)
if c==1:
  print(1)
  exit()
D=[]
P=[]
def E(c):
    P=[]
    E=[i+1 for i in range(1,int(c**0.5)+1)]
    while True:
        p=E[0]
        if int(c**0.5)+1<=p:
            return P+E
        P.append(p)
        E=[e for e in E if e%p!=0]
P=E(c)
f=True
for p in P:
  if c%p==0:
    f=False
    break
if f:
  print(2)
  exit()
for i in range(2, int(-(-gcd(a,b)**0.5//1))+1):
  if c%i==0:
    D.append(i)
    while c%i==0:
      c//=i
  if c==1:
    break
print(len(D)+1)

Fixed submission:
from fractions import gcd
a,b=map(int,input().split())
c=gcd(a,b)
d=1
for i in range(2, int(-(-gcd(a,b)**0.5//1))+1):
  if c%i==0:
    d+=1
    while c%i==0:
      c//=i
  if c==1:
    break
if c!=1:
  d+=1
print(d)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
for i in range(m):
    b=A.pop(n-1)//2
    bisect.insort_left(A, b)
print(sum(A))

Fixed submission:
import heapq
n,m=map(int,input().split())
A=list(map(int,input().split()))
H=[]
for a in A:
    heapq.heappush(H,-a)
for i in range(m):
    heapq.heappush(H,-(-heapq.heappop(H)//2))
print(-sum(H))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
for i in range(m):
    b=A.pop(n-1)//2
    bisect.insort_left(A, b)
print(sum(A))

Fixed submission:
import heapq
n,m=map(int,input().split())
A=list(map(int,input().split()))
H=[]
for a in A:
    heapq.heappush(H,-a)
for i in range(m):
    heapq.heappush(H,-(-heapq.heappop(H)//2))
print(-sum(H))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
for i in range(m):
  A[A.index(max(A))]//=2
print(sum(A))

Fixed submission:
import heapq
n,m=map(int,input().split())
A=list(map(int,input().split()))
H=[]
for a in A:
    heapq.heappush(H,-a)
for i in range(m):
    heapq.heappush(H,-(-heapq.heappop(H)//2))
print(-sum(H))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
S=input()
c=0
d=0
for i in range(n):
    if S[i]==S[i+1]:
        c+=1
    if S[i]!=S[i+1]:
        d+=1
print(c+2*k-1 if d<=k and S[0]==S[-1] else c+2*k)

Fixed submission:
n,k=map(int,input().split())
S=input()
c=0
d=0
for i in range(n-1):
    if S[i]==S[i+1]:
        c+=1
    if S[i]!=S[i+1]:
        d+=1
d=(d+1)//2
print(c+2*d-1 if (d<=k and S[0]!=S[-1]) else c+2*min(d,k))
Buggy python submission (verdict: Time Limit Exceeded):
print(sum(range(int(input()))))

Fixed submission:
n=int(input())
print((n-1)*n//2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [0 for i in range(N)]
S[0] = ''.join(sorted(list(input())))
ans = 0
for i in range(1, N):
    S[i] = ''.join(sorted(list(input())))
S2 = list(set(S))
for j in range(len(S2)):
    x = S.count(S2[j])
    if x != 1:
        ans += x * (x - 1) / 2
print(int(ans))

Fixed submission:
n=int(input())
S=[''.join(sorted(input())) for i in range(n)]
c=0
dict={}
for s in S:
  if s in dict:
    c+=dict[s]
    dict[s]+=1
  else:
    dict[s]=1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [0 for i in range(N)]
S[0] = ''.join(sorted(list(input())))
ans = 0
for i in range(1, N):
    S[i] = ''.join(sorted(list(input())))
S2 = list(set(S))
for j in range(len(S2)):
    x = S.count(S2[j])
    if x != 1:
        ans += x * (x - 1) / 2
print(int(ans))

Fixed submission:
n=int(input())
S=[''.join(sorted(input())) for i in range(n)]
c=0
dict={}
for s in S:
  if s in dict:
    c+=dict[s]
    dict[s]+=1
  else:
    dict[s]=1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
dp = [0 for i in range(N)]
dp[0] = ''.join(sorted(list(input())))
ans = 0
for i in range(1, N):
    dp[i] = ''.join(sorted(list(input())))
    for j in range(i):
        if dp[j] == dp[i]:
            ans += 1
print(ans)

Fixed submission:
n=int(input())
S=[''.join(sorted(input())) for i in range(n)]
c=0
dict={}
for s in S:
  if s in dict:
    c+=dict[s]
    dict[s]+=1
  else:
    dict[s]=1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
m=10**9+7
dp=[1]+[0]*12
for i in range(l):
    dp2=[0]*13
    if S[-i-1]=='?':
        for j in range(13):
            for k in range(10):
                dp2[j]+=dp[(j-k*10**i)%13]%m
    else:
        for j in range(13):
            dp2[j]=dp[(j-int(S[-i-1])*10**i)%13]
    dp=dp2
print(dp[5]%m)

Fixed submission:
S=input()[::-1]
l=len(S)
a=1
m=10**9+7
dp=[1]+[0]*12
for d in S:
    dp2=[0]*13
    if d=='?':
        for j in range(13):
            for k in range(10):
                dp2[(j+k*a)%13]+=dp[j]%m
    else:
        for j in range(13):
            dp2[(j+int(d)*a)%13]=dp[j]
    dp=dp2
    a=(a*10)%13 if a!=1 else 10
print(dp[5]%m)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
m=10**9+7
dp=[[0 for _ in range(13)] for _ in range(l)]
if S[-1]=='?':
    dp[0]=[1,1,1,1,1,1,1,1,1,1,0,0,0]
else:
    dp[0][int(S[-1])]=1
for i in range(1,l):
    if S[-i-1]=='?':
        for j in range(13):
            for k in range(10):
                dp[i][j]+=dp[i-1][(j-k*10**i)%13]%m
    else:
        for j in range(13):
            dp[i][j]=dp[i-1][(j-int(S[-i-1])*10**i)%13]
print(dp[-1][5]%m)

Fixed submission:
S=input()[::-1]
l=len(S)
a=1
m=10**9+7
dp=[1]+[0]*12
for d in S:
    dp2=[0]*13
    if d=='?':
        for j in range(13):
            for k in range(10):
                dp2[(j+k*a)%13]+=dp[j]%m
    else:
        for j in range(13):
            dp2[(j+int(d)*a)%13]=dp[j]
    dp=dp2
    a=(a*10)%13 if a!=1 else 10
print(dp[5]%m)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
m=10**9+7
dp=[[0 for _ in range(13)] for _ in range(l)]
if S[-1]=='?':
    dp[0]=[1,1,1,1,1,1,1,1,1,1,0,0,0]
else:
    dp[0][int(S[-1])]=1
for i in range(1,l):
    if S[-i-1]=='?':
        for j in range(13):
            for k in range(10):
                dp[i][j]+=dp[i-1][(j-k*10**i)%13]%m
    else:
        for j in range(13):
            dp[i][j]=dp[i-1][(j-int(S[-i-1])*10**i)%13]
print(dp[-1][5]%m)

Fixed submission:
S=input()[::-1]
l=len(S)
a=1
m=10**9+7
dp=[1]+[0]*12
for d in S:
    dp2=[0]*13
    if d=='?':
        for j in range(13):
            for k in range(10):
                dp2[(j+k*a)%13]+=dp[j]%m
    else:
        for j in range(13):
            dp2[(j+int(d)*a)%13]=dp[j]
    dp=dp2
    a=(a*10)%13 if a!=1 else 10
print(dp[5]%m)

Buggy python submission (verdict: Runtime Error):
S=list(input())
for i in range(int(input())):
    q=input()
    if q=='1':
        S.reverse()
    else:
        a,f,c=q.split()
        S=[c]+S if f=='1' else S+[c] 
print(''.join(S))

Fixed submission:
S=input()[::-1]
l=len(S)
a=1
m=10**9+7
dp=[1]+[0]*12
for d in S:
    dp2=[0]*13
    if d=='?':
        for j in range(13):
            for k in range(10):
                dp2[(j+k*a)%13]+=dp[j]%m
    else:
        for j in range(13):
            dp2[(j+int(d)*a)%13]=dp[j]
    dp=dp2
    a=(a*10)%13 if a!=1 else 10
print(dp[5]%m)