Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l, r = [], []
for i in range(N):
  L,R=map(int,input().split())
  l+= [L]
  r+= [R]
  
prime = [0,0]+[1]*10**5#素数テーブル
for i in range(10**3):#エラトステネスのふるいにかける
  if prime[i]==0: continue
  for j in range(i+1,10**5+1):
    if j%i==0: prime[j]=0
  
ans = []
for i in range(10**5+1):
  if prime[i]:
    if prime[(i+1)//2]: ans+=[1]
    else: ans+=[0]
  else: ans+=[0]
ans2= [0]
for i in range(10**5):
  ans2+=[ans2[-1]+ans[i+1]]
for i in range(N): 
  print(ans2[r[i]]-ans2[l[i]-1])

Fixed submission:
N = int(input())
l, r = [], []
for i in range(N):
  L,R=map(int,input().split())
  l+= [L]
  r+= [R]
  
prime = [0,0]+[1]*10**5#素数テーブル
for i in range(10**3):#エラトステネスのふるいにかける
  if prime[i]==0: continue
  for j in range(i+1,10**5+1):
    if j%i==0: prime[j]=0
  
ans = []
for i in range(10**5+1):
  if prime[i]:
    if prime[(i+1)//2]: ans+=[1]
    else: ans+=[0]
  else: ans+=[0]
ans2= [0]
for i in range(10**5):
  ans2+=[ans2[-1]+ans[i+1]]
for i in range(N): 
  print(ans2[r[i]]-ans2[l[i]-1])
Buggy python submission (verdict: Runtime Error):
import sys
s = list(str(input().rstrip()))
s = list(map(int,s))

change = 0
cflag=[]
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    change+=1
    cflag+=[i+1]
if change==0:
  print(len(s))
  sys.exit()
elif change ==1:
  ones = s.count(1)
  zeros = s.count(0)
  print(max(ones,zeros))
  sys.exit()
elif change ==2:
  print(max(1+cflag[0],1+len(s)-cflag[1]))
  sys.exit()
  
0/0
t=[]
for i in range(len(s)):
  if s[i]==0:t+=[1]
  else: t+=[0]
while True:
  firs=s.index(1)
  last=len(s)-1-s[::-1].index(1)
  print(firs,last)
  break

Fixed submission:
s = input()

cflag=[]
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    cflag+=[i+1]
  
ans = len(s)
for flag in cflag:
  ans = min(ans,max(flag,len(s)-flag) )
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
s = list(str(input().rstrip()))
s = list(map(int,s))

change = 0
for i in range(len(s)-1):
  if s[i]!=s[i+1]: change+=1
if change==0:
  print(len(s))
  sys.exit()
elif change ==1:
  ones = s.count(1)
  zeros = s.count(0)
  print(max(ones,zeros))
  sys.exit()
  
0/0

Fixed submission:
s = input()

cflag=[]
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    cflag+=[i+1]
  
ans = len(s)
for flag in cflag:
  ans = min(ans,max(flag,len(s)-flag) )
print(ans)
Buggy python submission (verdict: Runtime Error):
def positive(n):
  for i in range(n-1):
    print(i+1,i+2)
N=int(input())
A=list(map(int,input().split()))
mina=min(A)
minin=A.index(mina)
maxa=max(A)
maxin=A.index(maxa)
if mina>=0:
  print(N-1)
  positive(N)
elif maxa<=0:
  print(N-1)
  negative(N)
elif maxa+mina>=0:
  print(2*N-1)
  for i in range(N):
    print(maxin+1, i+1)
  positive(N)
else:
  print(2*N-1)
  for i in range(N):
    print(minin+1, i+1)
  negative(N)

Fixed submission:
def positive(n):
  for i in range(n-1):
    print(i+1,i+2)
def negative(n):
  for i in range(n-1):
    print(n-i,n-i-1)
N=int(input())
A=list(map(int,input().split()))
mina=min(A)
minin=A.index(mina)
maxa=max(A)
maxin=A.index(maxa)
if mina>=0:
  print(N-1)
  positive(N)
elif maxa<=0:
  print(N-1)
  negative(N)
elif maxa+mina>=0:
  print(2*N-1)
  for i in range(N):
    print(maxin+1, i+1)
  positive(N)
else:
  print(2*N-1)
  for i in range(N):
    print(minin+1, i+1)
  negative(N)

Buggy python submission (verdict: Runtime Error):
def positive(n):
  for i in range(n-1):
    print(i+1,i+2)
N=int(input())
A=list(map(int,input().split()))
mina=min(A)
minin=A.index(mina)
maxa=max(A)
maxin=A.index(maxa)
if mina>=0:
  print(N-1)
  positive(N)
elif maxa<=0:
  print(N-1)
  negative(N)
elif maxa+mina>=0:
  print(2*N-1)
  for i in range(N):
    print(maxin, i)
  positive(N)
else:
  print(2*N-1)
  for i in range(N):
    print(minin, i)
  negative(N)

Fixed submission:
def positive(n):
  for i in range(n-1):
    print(i+1,i+2)
def negative(n):
  for i in range(n-1):
    print(n-i,n-i-1)
N=int(input())
A=list(map(int,input().split()))
mina=min(A)
minin=A.index(mina)
maxa=max(A)
maxin=A.index(maxa)
if mina>=0:
  print(N-1)
  positive(N)
elif maxa<=0:
  print(N-1)
  negative(N)
elif maxa+mina>=0:
  print(2*N-1)
  for i in range(N):
    print(maxin+1, i+1)
  positive(N)
else:
  print(2*N-1)
  for i in range(N):
    print(minin+1, i+1)
  negative(N)
Buggy python submission (verdict: Runtime Error):
N,C=map(int,input().split())
imos=[0]*(10**5+1)
for i in range(N):
  s,t,c=map(int,input().split())
  imos[s-1]+=1
  imos[t]-=1
channels=[imos[0]]*(10**5+1)
for i in range(10**5):
  channels[i+1]=channels[i]+imos[i+1]
print(max(channels))

Fixed submission:
a,b,c=map(int,input().split())
print(min(a*b,c))
Buggy python submission (verdict: Runtime Error):
N,C=map(int,input().split())
imos=[0]*(2*10**5)
for i in range(N):
  s,t,c=map(int,input().split())
  imos[2*s-1]+=1
  imos[2*t]-=1
channels=[imos[0]]*(2*10**5)
for i in range(2*10**5-1):
  channels[i+1]=channels[i]+imos[i+1]
print(max(channels))

Fixed submission:
N,C=map(int,input().split())
cha=[[0 for i in range(10**5+1)] for j in range(C)]
for i in range(N):
  s,t,c=map(int,input().split())
  cha[c-1][s-1:t]=[1]*(t-s+1)
channels=0
for i in range(10**5+1):
  chans=0
  for c in range(C):
    chans+=cha[c-1][i]
  channels=max(channels,chans)
print(channels)

Buggy python submission (verdict: Runtime Error):
N,C=map(int,input().split())
imos=[0]*(10**5)
for i in range(N):
  s,t,c=map(int,input().split())
  imos[s-1]+=1
  imos[t]-=1
channels=[imos[0]]*(10**5)
for i in range(10**5-1):
  channels[i+1]=channels[i]+imos[i+1]
print(max(channels))

Fixed submission:
N,C=map(int,input().split())
cha=[[0 for i in range(10**5+1)] for j in range(C)]
for i in range(N):
  s,t,c=map(int,input().split())
  cha[c-1][s-1:t]=[1]*(t-s+1)
channels=0
for i in range(10**5+1):
  chans=0
  for c in range(C):
    chans+=cha[c-1][i]
  channels=max(channels,chans)
print(channels)
Buggy python submission (verdict: Runtime Error):
N,Z,W=map(int,input().split())
A=list(map(int,input().split()))
ans1=abs(A[N-1]-W)
ans2=abs(A[N-1]-A[N-2])
print(A[N-1],W,A[N-2])

Fixed submission:
N,M=map(int,input().split())
t=100*N+1800*M
a=(2**M-1)/(2**M)
ans=t/((2**M)*((1-a)**2))
print(int(ans))
Buggy python submission (verdict: Runtime Error):
=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans=0
small=0
large=0
for i in range(N):
  for k in range(small,N):
    if A[k]>=B[i]:
      small=k
      break
  else: small=N
  for k in range(large,N):
    if C[k]>B[i]:
      large=k
      break
  else: large=N
  ans+=small*(N-large)
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans=0
small=0
large=0
for i in range(N):
  for k in range(small,N):
    if A[k]>=B[i]:
      small=k
      break
  else: small=N
  for k in range(large,N):
    if C[k]>B[i]:
      large=k
      break
  else: large=N
  ans+=small*(N-large)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))

time = 0
sum_t = sum(t)
velo_cap =[float("inf")]*(2*sum_t+1)
for i in range(N):
  start_t = time
  goal_t = time + 2*t[i]
  for s in range(0,2*sum_t+1):
    if s < start_t:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(start_t-s))
    elif s<goal_t:
      velo_cap[s] = min(velo_cap[s],2*v[i])
    else:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(s-goal_t))
  time += 2*t[i]
for s in range(2*sum_t+1):
  velo_cap[s] = min(velo_cap[s],2*sum_t-s,s)


print(sum(velo_cap)/4-(velo_cap[0]+velo_cap[-1])/8)

Fixed submission:
R=int(input())
G=int(input())
print(2*G-R)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))

time = 0
sum_t = sum(t)
velo_cap =[float("inf")]*(2*sum_t+1)
for i in range(N):
  start_t = time
  goal_t = time + 2*t[i]
  for s in range(0,2*sum_t+1):
    if s < start_t:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(start_t-s))
    elif s<goal_t:
      velo_cap[s] = min(velo_cap[s],2*v[i])
    else:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(s-goal_t))
  time += 2*t[i]
for s in range(2*sum_t+1):
  velo_cap[s] = min(velo_cap[s],2*sum_t-s,s)


print(sum(velo_cap)/4-(velo_cap[0]+velo_cap[-1])/8)

Fixed submission:
N = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))

time = 0
sum_t = sum(t)
velo_cap =[float("inf")]*(2*sum_t+1)
for i in range(N):
  start_t = time
  goal_t = time + 2*t[i]
  for s in range(0,2*sum_t+1):
    if s < start_t:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(start_t-s))
    elif s<goal_t:
      velo_cap[s] = min(velo_cap[s],2*v[i])
    else:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(s-goal_t))
  time += 2*t[i]
for s in range(2*sum_t+1):
  velo_cap[s] = min(velo_cap[s],2*sum_t-s,s)


print(sum(velo_cap)/4-(velo_cap[0]+velo_cap[-1])/8)

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

time = 0
velo_cap =[float("inf")]*(2*sum(t)+1)
for i in range(N):
  start_t = time
  goal_t = time + 2*t[i]
  for s in range(0,2*sum(t)+1):
    if s < start_t:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(start_t-s))
    elif s<goal_t:
      velo_cap[s] = min(velo_cap[s],2*v[i])
    else:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(s-goal_t))
  time += 2*t[i]
for s in range(2*sum(t)+1):
  velo_cap[s] = min(velo_cap[s],2*sum(t)-s,s)

#print(velo_cap)
print(sum(velo_cap)/4-(velo_cap[0]+velo_cap[-1])/8)

Fixed submission:
N = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))

time = 0
sum_t = sum(t)
velo_cap =[float("inf")]*(2*sum_t+1)
for i in range(N):
  start_t = time
  goal_t = time + 2*t[i]
  for s in range(0,2*sum_t+1):
    if s < start_t:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(start_t-s))
    elif s<goal_t:
      velo_cap[s] = min(velo_cap[s],2*v[i])
    else:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(s-goal_t))
  time += 2*t[i]
for s in range(2*sum_t+1):
  velo_cap[s] = min(velo_cap[s],2*sum_t-s,s)


print(sum(velo_cap)/4-(velo_cap[0]+velo_cap[-1])/8)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
even=0
for i in range(N):
  if A[i]%2==0: even+=1

print(3**N-2**even)

Fixed submission:
S=str(input())
for i in range(len(S)-1):
  if S[i]=="A" and S[i+1]=="C":
    print("Yes")
    break
else: print("No")
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
edges=[[] for i in range(N)]
for i in range(M):
  a,b = map(int,input().split())
  edges[a-1]+=[b-1]
  edges[b-1]+=[a-1]
#print(edges)
ans=0
#奇数へいろを検出する0から(N//2)*2+1ステップ進んだ時, 0に戻れたらアウト
m=(N//2)*2+1
plist=[[] for i in range(m+1)]
plist[0]=[0]
for i in range(m):#iはステップ数
  for label in plist[i]:
    plist[i+1]+=edges[label]
  plist[i+1]=list(set(plist[i+1]))
print(plist,plist[m])
if 0 in plist[m]:
  print((N*(N-1))//2-M)#奇数要素の閉路があった場合は全ての頂点を結べる. 
else:
  if N%2==0:
    n=N//2
    print(n,n*(n-1)-M)
  else:
    n1=N//2
    n2=N//2+1
    print(n1,n2)
    print((n1*(n1-1))//2+(n2*(n2-1))//2-M)

Fixed submission:
s=str(input())
N=len(s)
print(s[:N-8])
Buggy python submission (verdict: Runtime Error):
import sys
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))
D.sort()
T.sort()
for i in range(M-1,-1,-1):
  while True:
    q=D.pop()
    if T[i]==q:
      #print(i)
      break
    elif T[i]>q:
      #print(i,"NO")
      sys.exit()
print("YES")

Fixed submission:
import sys
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))
D.sort()
T.sort()
for i in range(M-1,-1,-1):
  while D:
    q=D.pop()
    if T[i]==q:
      #print(i)
      break
    elif T[i]>q:
      print("NO")
      sys.exit()
  else:
    print("NO")
    sys.exit()
print("YES")
Buggy python submission (verdict: Runtime Error):
import sys
N=int(input())
if N%2==0:
  print(N//2,N,N)
else:
  for a in range(1,3501):
    for b in range(1,a):
      M=N*a*b
      L=4*a*b-N*(a+b)
      if M%L==0 and L>0:
        print(a,b,M//L)
        sys.exit()

Fixed submission:
import sys
N=int(input())
if N%2==0:
  print(N//2,N,N)
  sys.exit()
for a in range(1,3501):
  for b in range(1,a):
    M=N*a*b
    L=4*a*b-N*(a+b)
    if L>0:
      if M%L==0:
        print(a,b,M//L)
        sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
if N%2==0:
  print(N//2,N,N)
else:
  for i in range(1,3501):
    for j in range(1,i):
      for k in range(1,j):
        if 4*i*j*k==N*(i*j+ j*k+k*i):
          print(i,j,k)
          sys.exit()

Fixed submission:
import sys
N=int(input())
if N%2==0:
  print(N//2,N,N)
  sys.exit()
for a in range(1,3501):
  for b in range(1,a):
    M=N*a*b
    L=4*a*b-N*(a+b)
    if L>0:
      if M%L==0:
        print(a,b,M//L)
        sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
if N%2==0:
  print(N//2,N,N)
else:
  for i in range(1,10**5):
    for j in range(i+1):
      if 3*i*j==N*(i+j):
        print(N,i,j)
        sys.exit()

Fixed submission:
import sys
N=int(input())
if N%2==0:
  print(N//2,N,N)
  sys.exit()
for a in range(1,3501):
  for b in range(1,a):
    M=N*a*b
    L=4*a*b-N*(a+b)
    if L>0:
      if M%L==0:
        print(a,b,M//L)
        sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
if N%2==0:
  print(N//2,N,N)
else:
  for i in range(1,10**5):
    for j in range(i+1):
      if 3*i*j==N*(i+j):
        print(N,i,j)
        sys.exit()

Fixed submission:
import sys
N=int(input())
if N%2==0:
  print(N//2,N,N)
  sys.exit()
for a in range(1,3501):
  for b in range(1,a):
    M=N*a*b
    L=4*a*b-N*(a+b)
    if L>0:
      if M%L==0:
        print(a,b,M//L)
        sys.exit()
Buggy python submission (verdict: Runtime Error):
import sys
H,W,d=map(int,input().split())
if d%2==1:
  l=W//4+1
  reg=list("RYGB"*l)
  for j in range(H):
    a=reg.pop(0)
    reg+=a
    print("".join(map(str,reg))[:W])
else:
  for i in range(H):
      ans = []
      for j in range(W):
          b1 = ((i+j) // d) % 2
          b2 = ((i-j) // d) % 2
          result += c[b1 * 2 + b2]
      print("".join(result))

Fixed submission:
import sys
H,W,d=map(int,input().split())
if d%2==1:
  l=W//4+1
  reg=list("RYGB"*l)
  for j in range(H):
    a=reg.pop(0)
    reg+=a
    print("".join(map(str,reg))[:W])
else:
  for i in range(H):
      c="RYGB"
      ans = []
      for j in range(W):
          b1 = ((i-j) // d) % 2
          b2 = ((i+j) // d) % 2
          ans+= c[b1 * 2 + b2]
      print("".join(ans))
Buggy python submission (verdict: Runtime Error):
def Warshall_Floyd(edges,N):
  """頂点N個のグラフ上の隣接行列edgesが与えられたとき, 
  2点間の最短距離距離を隣接行列で返す"""
  for k in range(N):
    for i in range(N):
      for j in range(N):
        edges[i][j]=min(edges[i][j],edges[i][k]+edges[k][j])
  return edges
 
import sys
from sys import stdin
input = stdin.readline
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
B=Warshall_Floyd(A,N)
if A!=B:
  print(-1)
  sys.exit()
 
ans=0
for i in range(N):
  for j in range(i):
    need=1
    for k in range(N):
      if k!=i and k!=j:
        if A[i][j]==A[i][k]+A[k][j]:
          need=0
          break
    ans+=need*A[i][j]
print(ans)

Fixed submission:
N=int(input())
A=int(input())
print(N*N-A)
Buggy python submission (verdict: Runtime Error):
A,B,C,D,E,F=map(int,input().split())
best_water=0
best_salt=0
best_rate=0
for i in range(30//A+1):#Aの投入数
  for j in range(30//B+1):#Bの投入数
    water=(i*A+j*B)*100
    if water<=F and water:
      max_salt=(i*A+j*B)*E
      for k in range(max_salt//C+1):#Cを何個使うか
        l=(max_salt-C*k)//D#Dは何個つかえるか
        salt=k*C+l*D
        rate=100*salt/(water+salt)
        if rate>best_rate and rate<E and water+salt <=F:
          best_rate=rate
          best_salt=salt
          best_water=water
print(best_water+best_salt,best_salt)

Fixed submission:
N=int(input())
K=int(input())
x=list(map(int,input().split()))
ans=0
for i in range(N):
  ans+=min(x[i],abs(K-x[i]))
print(2*ans)
Buggy python submission (verdict: Runtime Error):
def Warshall_Floyd(edges,N):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        edges[i][j]=min(edges[i][j],edges[i][k]+edges[k][j])
  return edges

import itertools
N, M, R = map(int,input().split())
r = list(map(int,input().split()))
A=[[float("inf") for i in range(N)] for j in range(N)]
for m in range(M):
  a, b, c = map(int,input().split())
  A[a-1][b-1] = c
  A[b-1][a-1] = c

ans = float("inf")
for road in list(itertools.permutations(r)):
  length = 0
  for i in range(R-1):
    length += A[road[i]-1][road[i+1]-1]
  ans = min(ans, length)
print(ans)

Fixed submission:
N=str(input())
if N[0]=="9" or N[1]=="9":
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
ans=[]
for i in range(N):
  s=int(input())
  if s not in ans:
    ans+=[s]
  else:
    ans.remove(s)
print(len(ans))

Fixed submission:
N=int(input())
A=[int(input()) for i in range(N)]
A.sort()
i=0
ans=0
while i<N:
  p=A[i]
  count=0
  for j in range(i,N):
    if A[j]==A[i]:
      count+=1
    else:
      break
  if count%2==1: ans+=1
  i+=count
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[int(input()) for i in range(N)]
se=set(A)
ans=0
for el in se:
  if A.count(el)%2==1:
    ans+=1
print(ans)

Fixed submission:
N=int(input())
A=[int(input()) for i in range(N)]
A.sort()
i=0
ans=0
while i<N:
  p=A[i]
  count=0
  for j in range(i,N):
    if A[j]==A[i]:
      count+=1
    else:
      break
  if count%2==1: ans+=1
  i+=count
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def Warshall_Floyd(edges,N):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        edges[i][j]=min(edges[i][j],edges[i][k]+edges[k][j])
  return edges

import itertools
N, M, R = map(int,input().split())
r = list(map(int,input().split()))
A=[[float("inf") for i in range(N)] for j in range(N)]
for m in range(M):
  a, b, c = map(int,input().split())
  A[a-1][b-1] = c
  A[b-1][a-1] = c
A = Warshall_Floyd(A,N)

ans = float("inf")
for road in list(itertools.permutations(r)):
  length = 0
  for i in range(R-1):
    length += A[road[i]-1][road[i+1]-1]
  ans = min(ans, length)
print(ans)

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

import itertools
N, M, R = map(int,input().split())
r = list(map(int,input().split()))
A=[[float("inf") for i in range(N)] for j in range(N)]
for m in range(M):
  a, b, c = map(int,input().split())
  A[a-1][b-1] = c
  A[b-1][a-1] = c
A = Warshall_Floyd(A,N)

ans = float("inf")
for road in list(itertools.permutations(r)):
  length = 0
  for i in range(R-1):
    length += A[road[i]-1][road[i+1]-1]
  ans = min(ans, length)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
se=[s]
n=len(s)
num=0
total=n*(n-1)//2 +1
for i in range(n):
  for j in range(i+1,n):
    if s[i]==s[j]:
      num+=1
print(total-num)

Fixed submission:
s=str(input())
L=[0]*26
n=len(s)
for i in range(n):
  L[ord(s[i])-97]+=1
num=0
total=n*(n-1)//2 +1
for i in range(26):
  if L[i]>1:
    num+=L[i]*(L[i]-1)//2
print(total-num)

Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
se=[s]
n=len(s)
num=0
total=n*(n-1)//2+1
s_="0"+s
for i in range(n):
  for j in range(1,n-i):
    k=s_[1:i+1]+s_[i+j+1:i:-1]+s_[i+j+2:]
    if k in se: num-=1
    else: se+=[k]
print(num+total)

Fixed submission:
s=str(input())
L=[0]*26
n=len(s)
for i in range(n):
  L[ord(s[i])-97]+=1
num=0
total=n*(n-1)//2 +1
for i in range(26):
  if L[i]>1:
    num+=L[i]*(L[i]-1)//2
print(total-num)

Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
se=set()
se.add((s))
n=len(s)
s_="0"+s
for i in range(n):
  for j in range(1,n-i):
    k=(s_[1:i+1]+s_[i+j+1:i:-1]+s_[i+j+2:]) 
    se.add(k)
print(len(se))

Fixed submission:
s=str(input())
L=[0]*26
n=len(s)
for i in range(n):
  L[ord(s[i])-97]+=1
num=0
total=n*(n-1)//2 +1
for i in range(26):
  if L[i]>1:
    num+=L[i]*(L[i]-1)//2
print(total-num)

Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
se=[s]
n=len(s)
s_="0"+s
for i in range(n):
  for j in range(1,n-i):
    k=s_[1:i+1]+s_[i+j+1:i:-1]+s_[i+j+2:]
    se+=[k]
uniq = list(set(se))
print(len(uniq))

Fixed submission:
s=str(input())
L=[0]*26
n=len(s)
for i in range(n):
  L[ord(s[i])-97]+=1
num=0
total=n*(n-1)//2 +1
for i in range(26):
  if L[i]>1:
    num+=L[i]*(L[i]-1)//2
print(total-num)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
  if A[i] in B:
    C+=[A[i]]
    B.remove(A[i])
  else: 
    B+=[A[i]]
C.sort(reverse=1)
if len(C)<2:
  print(0)
else:
  print(C[0]*C[1])

Fixed submission:
import sys
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=1)
a=0
b=0
j=N-1
for i in range(N-1):
  if A[i]==A[i+1]:
    a=A[i]
    j=i
    break
for i in range(j+2,N-1):
  if A[i]==A[i+1]:
    b=A[i]
    break

print(a*b)
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
def lcm(a,b):
  return a*b//gcd(a,b)

N=int(input())
T=[int(input()) for i in range(N)]
T.sort()
G=T[1]
for i in range(N):
  G=lcm(G,T[i])
print(G)

Fixed submission:
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
def lcm(a,b):
  return a*b//gcd(a,b)

N=int(input())
T=[int(input()) for i in range(N)]
T.sort()
G=T[0]
for i in range(N):
  G=lcm(G,T[i])
print(G)

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
def lcm(a,b):
  return a*b//gcd(a,b)

N=int(input())
T=[int(input()) for i in range(N)]
G=T[1]
for i in range(N):
  G=lcm(G,T[i])
print(G)

Fixed submission:
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
def lcm(a,b):
  return a*b//gcd(a,b)

N=int(input())
T=[int(input()) for i in range(N)]
T.sort()
G=T[0]
for i in range(N):
  G=lcm(G,T[i])
print(G)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline
def BFS(K,path,N):
  """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す"""
  import queue
  dist=[-1]*N
  dist[K]=0
  que=queue.Queue()
  que.put(K)
  while que.qsize():
    label=que.get()
    for i,c in path[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        que.put(i)
  return dist
 
N=int(input())
path=[ [] for i in range(N)]
for i in range(N-1):
  a,b,c=map(int,input().split())
  path[a-1]+=[(b-1,c)]
  path[b-1]+=[(a-1,c)]
Q,K=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(Q)]
distance=BFS(K-1,path,N)
for i in range(Q):
  print(distance[xy[i][0]-1]+distance[xy[i][1]-1])

Fixed submission:
n,m=map(int,input().split())
print((n-1)*(m-1))