Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import itertools
n=int(input())
s=str(input())
R=[]
B=[]
G=[]
for i in range(n):
  if s[i]=='R':
    R.append(i)
  elif s[i]=='B':
    B.append(i)
  else:
    G.append(i)
ans=len(R)*len(B)*len(G)
l=itertools.permutations([R,B,G])
for r,b,g in l:
  for i in r:
    index=bisect.bisect_left(b,i)
    for j in b[index:]:
      index2=bisect.bisect_left(g,j)
      if j+j-i in g[index2:]:
        ans-=1
print(ans)

Fixed submission:
n=int(input())
s=str(input())
R=[]
B=[]
G=[]
for i in range(n):
  if s[i]=='R':
    R.append(i)
  elif s[i]=='B':
    B.append(i)
  else:
    G.append(i)
ans=len(R)*len(B)*len(G)

for i in range(n-1):
  for j in range(i+1,n):
    char1=s[i]
    char2=s[j]
    if char1==char2:
      pass
    else:
      if n>2*j-i>j and s[2*j-i]!=char1 and s[2*j-i]!=char2:
        ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import itertools
n=int(input())
s=str(input())
R=[]
B=[]
G=[]
for i in range(n):
  if s[i]=='R':
    R.append(i)
  elif s[i]=='B':
    B.append(i)
  else:
    G.append(i)
ans=0
l=itertools.permutations([R,B,G])
for r,b,g in l:
  V=len(g)
  for i in r:
    index=bisect.bisect_left(b,i)
    for j in b[index:]:
      index2=bisect.bisect_left(g,j)
      tmp=V-index2
      if j+j-i in g[index2:]:
        tmp-=1
      ans+=tmp
print(ans)

Fixed submission:
n=int(input())
s=str(input())
R=[]
B=[]
G=[]
for i in range(n):
  if s[i]=='R':
    R.append(i)
  elif s[i]=='B':
    B.append(i)
  else:
    G.append(i)
ans=len(R)*len(B)*len(G)

for i in range(n-1):
  for j in range(i+1,n):
    char1=s[i]
    char2=s[j]
    if char1==char2:
      pass
    else:
      if n>2*j-i>j and s[2*j-i]!=char1 and s[2*j-i]!=char2:
        ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import itertools
n=int(input())
s=str(input())
R=[]
B=[]
G=[]
for i in range(n):
  if s[i]=='R':
    R.append(i)
  elif s[i]=='B':
    B.append(i)
  else:
    G.append(i)
ans=0
l=itertools.permutations([R,B,G])
for r,b,g in l:
  V=len(g)
  for i in r:
    index=bisect.bisect_left(b,i)
    for j in b[index:]:
      index2=bisect.bisect_left(g,j)
      tmp=V-index2
      if j+j-i in g[index2:]:
        tmp-=1
      ans+=tmp
print(ans)

Fixed submission:
n=int(input())
s=str(input())
R=[]
B=[]
G=[]
for i in range(n):
  if s[i]=='R':
    R.append(i)
  elif s[i]=='B':
    B.append(i)
  else:
    G.append(i)
ans=len(R)*len(B)*len(G)

for i in range(n-1):
  for j in range(i+1,n):
    char1=s[i]
    char2=s[j]
    if char1==char2:
      pass
    else:
      if n>2*j-i>j and s[2*j-i]!=char1 and s[2*j-i]!=char2:
        ans-=1
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
n=int(input())
al=[chr(ord('a') + i) for i in range(26)]
norm=defaultdict(list)
for i in range(11):
  if i==0:
    norm[1]=['a']
  else:
    for char in norm[i-1]:
      last=char[-1]
      range_digit=al.index(last)+2
      for s in al[0:range_digit]:
        norm[i].append(char+s)

for char in norm[n]:
  print(char)

Fixed submission:
from collections import defaultdict
n=int(input())
al=[chr(ord('a') + i) for i in range(26)]
norm=defaultdict(list)
def max_al(s):
  tmp=0
  for i in range(len(s)):
    tmp2=al.index(s[i])
    tmp=max(tmp,tmp2)
  return tmp

for i in range(11):
  if i==0:
    norm[1]=['a']
  else:
    for char in norm[i-1]:
      range_digit=max_al(char)+2
      for s in al[0:range_digit]:
        norm[i].append(char+s)

for char in norm[n]:
  print(char)
Buggy python submission (verdict: Runtime Error):
import sys
a,b=map(int,input().split())

if a%2==0:
  lower1=int(a*100/8)
  upper1=(a+1)*100/8
  upper1=max(lower,int(upper1)-1)  
else:
  lower1=a*(100/8)
  upper1=int((a+1)*100/8)
  if (upper1)-int(lower1)<=1:
    print(-1)
    sys.exit()
  else:
    lower1=int(lower1)+1
    if lower1==upper1:
      print(-1)
      sys.exit()
    else:
      pass
  
lower2=(b)*10
upper2=(b+1)*10

lower=max(lower1,lower2)
upper=min(upper1,upper2)
if upper-lower<0:
  print(-1)
else:
  print(lower)



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

if a%2==0:
  lower1=int(a*100/8)
  upper1=(a+1)*100/8
  upper1=max(lower1,int(upper1)-1)  
else:
  lower1=a*(100/8)
  upper1=int((a+1)*100/8)
  if (upper1)-int(lower1)<=1:
    print(-1)
    sys.exit()
  else:
    lower1=int(lower1)+1
    if lower1==upper1:
      print(-1)
      sys.exit()
    else:
      pass
  
lower2=(b)*10
upper2=(b+1)*10

lower=max(lower1,lower2)
upper=min(upper1,upper2)
if upper-lower<1:
  print(-1)
else:
  print(lower)

Buggy python submission (verdict: Runtime Error):

import sys
a,b=map(int,input().split())

if a%2==0:
  lower1=int(a*100/8)
else:
  lower1=a*(100/8)
  upper1=int((a+1)*100/8)
  if (upper1)-int(lower1)<1:
    print(-1)
    sys.exit()
  else:
    lower1=int(lower1)+1
    if lower1=upper1:
      print(-1)
      sys.exit()
    else:
      pass
  
lower2=(b)*10
upper2=(b+1)*10

lower=max(lower1,lower2)
if lower=uppwer1:
  print(-1)
else:
  print(lower)

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

if a%2==0:
  lower1=int(a*100/8)
  upper1=(a+1)*100/8
  upper1=max(lower1,int(upper1)-1)  
else:
  lower1=a*(100/8)
  upper1=int((a+1)*100/8)
  if (upper1)-int(lower1)<=1:
    print(-1)
    sys.exit()
  else:
    lower1=int(lower1)+1
    if lower1==upper1:
      print(-1)
      sys.exit()
    else:
      pass
  
lower2=(b)*10
upper2=(b+1)*10

lower=max(lower1,lower2)
upper=min(upper1,upper2)
if upper-lower<1:
  print(-1)
else:
  print(lower)
Buggy python submission (verdict: Runtime Error):
s=str(input())

N=int(input())
cnt=0
f=''
b=''
for i in range(N):
  inp=str(input())
  if len(inp)==1:
    cnt+=1
  else:
    F,c=int(inp[2]),inp[4]
    if F==1:
      if cnt%2==0:
        f=c+f
      else:
        b+=c
    else:
      if cnt%2==0:
        b+=c
      else:
        f=c+f
if cnt%2==0:
  print(f+s+b)
else:
  ans=f+s+b
  L=len(ans)
  if L==1:
    print(ans)
  else:
    if L%2==1:
      f=ans[0:L//2]
      s=ans[L//2]
      b=ans[L//2+1:L]
      print(''.join(list(reversed(b))))+s+''.join(list(reversed(f)))
    else:
      f=ans[0:L//2]
      b=ans[L//2:L]
      f_=''.join(list(reversed(b)))
      b_=''.join(list(reversed(f)))
      print(f_+b_)

Fixed submission:
s=str(input())

N=int(input())
cnt=0
f=''
b=''
for i in range(N):
  inp=str(input())
  if len(inp)==1:
    cnt+=1
  else:
    F,c=int(inp[2]),inp[4]
    if F==1:
      if cnt%2==0:
        f=c+f
      else:
        b+=c
    else:
      if cnt%2==0:
        b+=c
      else:
        f=c+f
if cnt%2==0:
  print(f+s+b)
else:
  ans=f+s+b
  L=len(ans)
  if L==1:
    print(ans)
  else:
    if L%2==1:
      f=ans[0:L//2]
      s=ans[L//2]
      b=ans[L//2+1:L]
      f_=''.join(list(reversed(b)))
      b_=''.join(list(reversed(f)))
      print(f_+s+b_)
    else:
      f=ans[0:L//2]
      b=ans[L//2:L]
      f_=''.join(list(reversed(b)))
      b_=''.join(list(reversed(f)))
      print(f_+b_)

Buggy python submission (verdict: Runtime Error):
s=str(input())

N=int(input())
cnt=0
f=''
b=''
for i in range(N):
  inp=str(input())
  if len(inp)==1:
    cnt+=1
  else:
    F,c=int(inp[2]),inp[4]
    if F==1:
      if cnt%2==0:
        f=c+f
      else:
        b+=c
    else:
      if cnt%2==0:
        b+=c
      else:
        f=c+f
if cnt%2==0:
  print(f+s+b)
else:
  ans=f+s+b
  L=len(ans)
  if L%2==1:
    f=ans[0:L//2]
    s=ans[L//2]
    b=ans[L//2+1:L]
    print(''.join(list(reversed(b))))+s+''.join(list(reversed(f)))
  else:
    f=ans[0:L//2]
    b=ans[L//2:L]
    f_=''.join(list(reversed(b)))
    b_=''.join(list(reversed(f)))
    print(f_+b_)

Fixed submission:
s=str(input())

N=int(input())
cnt=0
f=''
b=''
for i in range(N):
  inp=str(input())
  if len(inp)==1:
    cnt+=1
  else:
    F,c=int(inp[2]),inp[4]
    if F==1:
      if cnt%2==0:
        f=c+f
      else:
        b+=c
    else:
      if cnt%2==0:
        b+=c
      else:
        f=c+f
if cnt%2==0:
  print(f+s+b)
else:
  ans=f+s+b
  L=len(ans)
  if L==1:
    print(ans)
  else:
    if L%2==1:
      f=ans[0:L//2]
      s=ans[L//2]
      b=ans[L//2+1:L]
      f_=''.join(list(reversed(b)))
      b_=''.join(list(reversed(f)))
      print(f_+s+b_)
    else:
      f=ans[0:L//2]
      b=ans[L//2:L]
      f_=''.join(list(reversed(b)))
      b_=''.join(list(reversed(f)))
      print(f_+b_)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
a=list(map(int,input().split()))
Tmp=0
for i in range(N-K+1):
  s=sum(a[i:i+K])
  if s>Tmp:
    Tmp=s
ans=(Tmp+K)/2
print(ans)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
s=[0]
for i in range(n):
  s.append(a[i]+s[-1])
for i in range(n-k+1):
  tot=s[i+k]-s[i]
  ans=max((tot+k)/2,ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

N,K=map(int,input().split())
a=list(map(int,input().split()))
tmp=10**-10
l=[]
for i in range(N-K+1):
  s=sum(a[i:i+K])
  if s>tmp:
    l=a[i:i+K]
    tmp=s

ans=(tmp+K)/2
print(ans)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
s=[0]
for i in range(n):
  s.append(a[i]+s[-1])
for i in range(n-k+1):
  tot=s[i+k]-s[i]
  ans=max((tot+k)/2,ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
a=list(map(int,input().split()))
tmp=10**-10
l=[]
for i in range(N-K+1):
  s=sum(a[i:i+K])
  if s>tmp:
    l=a[i:i+K]
    tmp=s
ans=0
for i in range(K):
  v=l[i]
  ans+=((v+1)/2)
print(ans)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
s=[0]
for i in range(n):
  s.append(a[i]+s[-1])
for i in range(n-k+1):
  tot=s[i+k]-s[i]
  ans=max((tot+k)/2,ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H,N=map(int,input().split())
dp=[10**12 for _ in range(H+1)]
dp[0]=0
for i in range(N):
  h,n=map(int,input().split())
  for j in range(H+1):
    dp[j]=min(dp[j],dp[max(0,j-h)]+n)
print(dp[H])

Fixed submission:
H,N=map(int,input().split())
a=[]
max_x=-10**10
for i in range(N):
  x,y=map(int,input().split())
  if x>max_x:
    max_x=x
  a.append([x,y])
  
dp = [0] * (H+max_x)
for i in range(0,H+max_x):
    if i==0:
        dp[i]=0
    else:
        dp[i]=min(dp[i-l[0]]+l[1] for l in a )
print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
H,N=map(int,input().split())
hn=[]
for i in range(N):
  hn.append(list(map(int,input().split())))
dp=[[10**17]*(H+1) for _ in range(N+1)]
dp[0][0]=0
for i in range(1,N+1):
  for j in range(H+1):
    h,n=hn[i-1][0],hn[i-1][1]
    dp[i][j]=min(dp[i-1][j],dp[i][max(0,j-h)]+n)
print(dp[N][H])

Fixed submission:
H,N=map(int,input().split())
a=[]
max_x=-10**10
for i in range(N):
  x,y=map(int,input().split())
  if x>max_x:
    max_x=x
  a.append([x,y])
  
dp = [0] * (H+max_x)
for i in range(0,H+max_x):
    if i==0:
        dp[i]=0
    else:
        dp[i]=min(dp[i-l[0]]+l[1] for l in a )
print(dp[H])
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=list(map(int,input().split()))

def gcd(a,b):
  if a==b:
    return a
  a,b=max(a,b),min(a,b)
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
  
def lcm(a,b):
  return a*b//gcd(a,b)
  
for i in range(N-1):
  if i==0:
    tmp=lcm(a[i]//2,a[i+1]//2)
  else:
    tmp=lcm(tmp,a[i+1]//2)
v=M//tmp
if v%2==1:
  print(v//2+1)
else:
  print(v//2)

Fixed submission:
import sys
N,M=map(int,input().split())
a=list(map(int,input().split()))

def gcd(a,b):
  if a==b:
    return a
  a,b=max(a,b),min(a,b)
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
  
def lcm(a,b):
  return a*b//gcd(a,b)

if N==1:
  v=M//int(a[0]*0.5)
  if v%2==0:
    print(v//2)
  else:
    print(v//2+1)
  sys.exit()
  
for i in range(N-1):
  if i==0:
    tmp=lcm(a[i]//2,a[i+1]//2)
    devider=min(a[i]//2,a[i+1]//2)
    if (tmp//devider)%2==0:
      print(0)
      sys.exit()
  else:
    tmp=lcm(tmp,a[i+1]//2)
    devider=min(tmp,a[i+1]//2)
    if (tmp//devider)%2==0:
      print(0)
      sys.exit()

v=M//tmp
if v%2==1:
  print(v//2+1)
else:
  print(v//2)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=str(input())
ans=0
for i in range(0,1000):
  if i<10:
    n='0'+'0'+str(i)
  elif i<100:
    n='0'+str(i)
  else:
    n=str(i)
  v1,v2,v3=n[0],n[1],n[2]
  j=0
  while j+1<=N-2 and a[j]!=v1:
    j+=1
  if j>N-2:
    break
  k=j+1
  while k+1<=N-1 and a[k]!=v2:
    k+=1
  if k>N-1:
    break
  l=k+1
  while l+1<=N and a[l]!=v3:
    l+=1
  if l<=N-1:
    ans+=1
print(ans)

Fixed submission:
import bisect
n=int(input())
s=list(str(input()))
cnt=0
index={}
for i in range(n):
  v=s[i]
  if v not in index.keys():
    index[v]=[]
  index[v].append(i)
for i in range(1000):
  i_str='0'*(3-len(str(i)))+str(i)
  x,y,z=i_str[0],i_str[1],i_str[2]
  if x in index.keys() and y in index.keys() and z in index.keys():
    a=index[x][0]
    v=bisect.bisect_left(index[y],a+1)
    if v<len(index[y]):
      b=index[y][v]
      if b<=a or b>=n:
        pass
      else:
        v=bisect.bisect_left(index[z],b+1)
        if v<len(index[z]):
          c=index[z][v]
          if c<=b or c>=n:
            pass
          else:
            cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
ans=1
l=[0,0,0]
mod=10**9+7
for i in range(N):
  ans*=(l.count(a[i]))
  index=l.index(a[i])
  l[index]+=1
print(ans%mod)

Fixed submission:
import sys
N=int(input())
a=list(map(int,input().split()))
ans=1
l=[0,0,0]
mod=10**9+7
for i in range(N):
  ans*=(l.count(a[i]))
  if a[i] not in l:
    print(0)
    sys.exit()
  index=l.index(a[i])
  l[index]+=1
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from collections import defaultdict
N=int(input())
G=defaultdict(list)
Edges=defaultdict(int)
edges=[]
for i in range(N-1):
  a,b=map(int,input().split())
  G[a].append(b)
  Edges[(a,b)]=0
  edges.append([a,b])
def dfs(G,s):
  stack=deque()
  seen=[]
  stack.append(s)
  seen.append(s)
  prev=defaultdict(int)
  prev[s]=s
  k=1
  while len(stack)!=0:
    u=stack.pop()
    if u!=s:
      k=max(k,len(G[u])+1)
    else:
      k=max(k,len(G[u]))
    lst=[i for i in range(1,k+1)]
    if u!=s:
      lst.remove(Edges[(prev[u],u)]) 
    else:
      pass
    for v in G[u]:
      if v not in seen:
        num=lst.pop(0)
        Edges[(u,v)]=num
        seen.append(v)
        stack.append(v)
        prev[v]=u
  return k

K=dfs(G,1)
print(K)
for e in edges:
  a,b=e[0],e[1]
  print(Edges[(a,b)])

Fixed submission:
from collections import deque
from collections import defaultdict
n=int(input())
E=[[] for _ in range(n)]
col=defaultdict(list)
l=[]
for i in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  E[a].append(b)
  E[b].append(a)
  col[(a,b)]=-1
  col[(b,a)]=-1
  l.append((a,b))
s=-1
k=-1
for i in range(n):
  if len(E[i])>k:
    k=len(E[i])
    s=i
par=[-1]*n
stack=deque([s])
seen=[-1]*n
seen[s]=1
while stack:
  u=stack.pop()
  if u==s:
    cnt=1
  else:
    cnt=col[(par[u],u)]+1
  for v in E[u]:
    if seen[v]!=1:
      par[v]=u
      seen[v]=1
      if cnt<=k:
        col[(u,v)]=cnt
        cnt+=1
      else:
        col[(u,v)]=1
        cnt=2
      stack.append(v)
print(k)
for a,b in l:
  if col[(a,b)]==-1:
    print(col[(b,a)])
  else:
    print(col[(a,b)])
Buggy python submission (verdict: Runtime Error):
 def sq(a, b, mod):  # aのb乗を剰余
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod
  
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def nCk(n,k,mod):
  prev=1
  for i in range(1,min(k,n-k)+1):
    v=(prev * (n+1-i) % mod * modinv(i, mod) % mod)
    prev=v
  return prev

x,y=map(int,input().split())
mod=10**9+7

if (x+y)%3!=0:
  print(0)
else:
  n=int((x+y)/3)
  k=int((2*x-y)/3)
  print(nCk(n,k,mod))

Fixed submission:
def sq(a, b, mod):  # aのb乗を剰余
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod
  
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def nCk(n,k,mod):
  prev=1
  for i in range(1,min(k,n-k)+1):
    v=(prev * (n+1-i) % mod * modinv(i, mod) % mod)
    prev=v
  return prev

x,y=map(int,input().split())
mod=10**9+7

if (x+y)%3!=0:
  print(0)
else:
  n=(x+y)//3
  k=(2*x-y)//3
  if k<0 or k>n:
    print(0)
  else:
    print(nCk(n,k,mod))

Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
if (a+b)%3!=0:
  print(0)
else:
  n=(a+b)//3
  r=(2*b-a)//3
  def nCr(n,r):
    mod=10**9+7
    def exgcd(a,b):
      u0,u1,v0,v1=1,0,0,1
      while b!=0:
        q,a,b=a//b,b,a%b
        u0,u1=u1,u0-q*u1
        v0,v1=v1,v0-q*v1
      return u0
    def inv_mod(a,n):
      return exgcd(a,n)%n
    ans=((math.factorial(n))*(inv_mod(math.factorial(n-r),mod))*(inv_mod(math.factorial(r),mod)))%mod
    return ans
  print(nCr(n,r))

Fixed submission:
def sq(a, b, mod):  # aのb乗を剰余
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod
  
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def nCk(n,k,mod):
  prev=1
  for i in range(1,min(k,n-k)+1):
    v=(prev * (n+1-i) % mod * modinv(i, mod) % mod)
    prev=v
  return prev

x,y=map(int,input().split())
mod=10**9+7

if (x+y)%3!=0:
  print(0)
else:
  n=(x+y)//3
  k=(2*x-y)//3
  if k<0 or k>n:
    print(0)
  else:
    print(nCk(n,k,mod))
Buggy python submission (verdict: Runtime Error):
N=int(input())
s=list(str(input()))

def dp(i,ans):
  if i==N-1:
    return ans+1
  if s[i]!=s[i+1]:
    ans+=1
    return dp(i+1,ans)
  else:
    count=2
    ans+=1
    while i+count<=N-1 and s[i]==s[i+count]:
      count+=1
    if i+count==N:
      return ans
    if i+count==N-1 and s[N-2]!=s[N-1]:
      ans+=1
      return ans
    return dp(i+count,ans)
  
ans=0
print(dp(0,ans))

Fixed submission:
import sys
N=int(input())
s=list(str(input()))
i=0
ans=0
if N==1:
  print(1)
  sys.exit()
while i!=N-1:
  count=1
  ans+=1
  while i+count<=N-1 and s[i]==s[i+count]:
    count+=1
  i+=count
  if i==N:
    print(ans)
    sys.exit()
  elif i==N-1:
    if s[N-2]!=s[N-1]:
      ans+=1
    print(ans)
    sys.exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
d=sorted(list(map(int,input().split())))
ans=0
while len(d)>=3:
  c=d.pop(-1)
  tmp=[]
  for i in range(len(d)-1):
    for j in range(i+1,len(d)):
      if d[i]+d[j]>c:
        ans+=1
print(ans)

Fixed submission:
import sys
import bisect
N=int(input())
d=sorted(list(map(int,input().split())))
ans=0
for i in range(1,len(d)-1):
  for j in range(i+1,len(d)):
    v=(N-j)-(bisect.bisect_left(d,d[-i]-d[-j]+1))
    if v<=0:
      pass
    else:
      ans+=v
print(ans)
Buggy python submission (verdict: Runtime Error):
S=list(str(input()))
s=set(S)
K=int(input())
num=0
i=0
lst=[]
def dp(i,lst):
  if i==len(S)-1:
    return lst
  if S[i]!=S[i+1]:
    return dp(i+1,lst)
  j=i+1
  while j<=len(S)-1  and S[i]==S[j]:
    j+=1
  lst.append(list(S[i:j]))
  return dp(j-1,lst)
if len(s)>=2:
  L=dp(i,lst)
  for i in range(len(L)):
    num+=(len(L[i])//2)
  if L[-1][-1]==S[0] and len(L[-1])%2==1:
    print(num+(K-1)*(num+1))
  else:
    print(num*K)
else:
  print((len(S)*K)//2)

Fixed submission:
S=list(str(input()))
s=set(S)
K=int(input())
num=0
i=0
lst=[]
def dp(i,lst):
  if i==len(S)-1:
    return lst
  if S[i]!=S[i+1]:
    return dp(i+1,lst)
  j=i+1
  while j<=len(S)-1  and S[i]==S[j]:
    j+=1
  lst.append(list(S[i:j]))
  return dp(j-1,lst)

if 2<=len(s):
  L=dp(i,lst)
  for i in range(len(L)):
    num+=(len(L[i])//2)
  if num==0:
    if S[0]!=S[-1]:
      print(0)
    else:
      print(K-1)
  elif L[-1][-1]==S[0] and len(L[-1])%2==len(L[0])%2==1:
    print(num+(K-1)*(num+1))
  else:
    print(num*K)
else:
  print((len(S)*K)//2)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
lst=[]
for i in range(1,N+1):
  index=A.index(i)+1
  lst.append(str(index))
print(' '.join(lst))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
lst=[0]*N
for i in range(N):
  lst[A[i]-1]=str(i+1)
print(' '.join(lst))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
A=list(map(int,input().split()))
ans=0
while M!=0:
  val=max(A)
  index=A.index(val)
  A[index]//=2
  M-=1
print(sum(A))

Fixed submission:
import heapq
N,M=map(int,input().split())
lst=list(map(int,input().split()))
A=[]
for i in range(N):
  heapq.heappush(A,-1*lst[i])
while M!=0:
  val=heapq.heappop(A)
  M-=1
  new_val=val/2
  heapq.heappush(A,new_val)

ans=0
for i in range(N):
  ans+=-1*int(A[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
H=list(map(int,input().split()))
val1,val2=H[-1],H[-2]
for i in range(N-1):
  if H[i]<H[i+1]:
    H[i]=0
  else:
    H[i]=1
if val1<=val2:
  H[-1]=1
else:
  H[-1]=0
zero=[]
for i in range(N):
  if H[i]==0:
    zero.append(i)
if len(zero)==N:
  print(0)
elif len(zero)==0:
  print(N)
elif len(zero)==1:
  print(max(zero[0],N-zero[0]-2))
else:
  ans=0
  for i in range(len(zero)-1):
    ans=max(ans,zero[i+1]-zero[i]-1)
  ans=max(ans,zero[-1]-zero[-2]-1)
  if H[-1]==1:
    ans=max(ans,N-zero[-1]-2)
  else:
    pass
  print(ans) 

Fixed submission:
N=int(input())                                       
H=list(map(int,input().split()))
for i in range(N-1):
  if H[i]<H[i+1]:
    H[i]=0
  else:
    H[i]=1
H[-1]=0
zero=[]
for i in range(N):
  if H[i]==0:
    zero.append(i)
if len(zero)==N:
  print(0)
elif len(zero)==1:
  print(N-1)
else:
  ans=0
  for i in range(len(zero)-1):
    ans=max(ans,zero[i+1]-zero[i]-1)
  ans=max(ans,zero[-1]-zero[-2]-1) 
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
l=[]
val=[]
for i in range(N):
  s=list(str(input()))
  s.sort()
  if s not in l:
    l.append(s)
    val.append(1)
  else:
    num=l.index(s)
    val[num]+=1
ans=0
for i in range(len(val)):
  ans+=val[i]*(val[i]-1)//2
print(ans)

Fixed submission:
N=int(input())
l=[]
d={}
ans=0
for i in range(N):
  s=list(str(input()))
  s.sort()
  l.append(s) 
for s in l:
  s=''.join(s)
  if s in d:
    ans+=d[s]
    d[s]+=1
  else:
    d[s]=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
l=[]
val=[]
for i in range(N):
  s=list(str(input()))
  s.sort()
  if s not in l:
    l.append(s)
    val.append(1)
  else:
    num=l.index(s)
    val[num]+=1
ans=0
for i in range(len(val)):
  ans+=val[i]*(val[i]-1)//2
print(ans)

Fixed submission:
N=int(input())
l=[]
d={}
ans=0
for i in range(N):
  s=list(str(input()))
  s.sort()
  l.append(s) 
for s in l:
  s=''.join(s)
  if s in d:
    ans+=d[s]
    d[s]+=1
  else:
    d[s]=1
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B,C,D=map(int,input().split())
c_dividable=B//C-(A-1)//C
d_dividable=B//D-(A-1)//D
def gcd(a,b):
  if a==b:
    return q
  else:
    if a%b==0:
      return b
    while a%b!=0:
      return gcd(b,a%b)
v=C*D//gcd(C,D)
cd_dividable=B//v-(A-1)//v
print(B-A+1-(c_dividable+d_dividable-cd_dividable))

Fixed submission:
A,B,C,D=map(int,input().split())
c_dividable=B//C-(A-1)//C
d_dividable=B//D-(A-1)//D
def gcd(a,b):
  if a==b:
    return a
  else:
    if a%b==0:
      return b
    while a%b!=0:
      return gcd(b,a%b)
v=C*D//gcd(C,D)
cd_dividable=B//v-(A-1)//v
print(B-A+1-(c_dividable+d_dividable-cd_dividable))