Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())

graph = [[] for _ in range(N)]

for _ in range(N-1):
    a, b, c = map(int, input().split())
    graph[a-1].append((b-1, c))
    graph[b-1].append((a-1, c))
    
Q, K = map(int, input().split())
visited = [0 for _ in range(N)]

def DFS(a, b, c):
    for i, j in graph[b]:
        if(i != a):
            visited[i] = c+j
            DFS(b, i, c+j)
DFS(-1, K-1, 0)
             
for _ in range(Q):
    x, y = map(int, input().split())
    print(visited[x-1]+visited[y-1])

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

graph = [[] for _ in range(N)]

for _ in range(N-1):
    a, b, c = map(int, input().split())
    graph[a-1].append((b-1, c))
    graph[b-1].append((a-1, c))
    
Q, K = map(int, input().split())
visited = [0 for _ in range(N)]

def DFS(a, b, c):
    for i, j in graph[b]:
        if(i != a):
            visited[i] = c+j
            DFS(b, i, c+j)
DFS(-1, K-1, 0)
             
for _ in range(Q):
    x, y = map(int, input().split())
    print(visited[x-1]+visited[y-1])

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

graph = {i+1:[] for i in range(N)}

for i in range(N-1):
    a, b, c = map(int, input().split())
    graph[a].append((b, c))
    graph[b].append((a, c))
    
Q, K = map(int, input().split())
visited = [0 for _ in range(N+1)]

def DFS(a, b, c):
    for i, j in graph[b]:
        if(i != a):
            visited[i] = c+j
            DFS(b, i, c+j)
DFS(-1, K, 0)
             
for i in range(Q):
    x, y = map(int, input().split())
    print(visited[x]+visited[y])

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

graph = {i+1:[] for i in range(N)}

for i in range(N-1):
    a, b, c = map(int, input().split())
    graph[a].append((b, c))
    graph[b].append((a, c))
    
Q, K = map(int, input().split())
visited = [0 for _ in range(N+1)]

def DFS(a, b, c):
    for i, j in graph[b]:
        if(i != a):
            visited[i] = c+j
            DFS(b, i, c+j)
DFS(0, K, 0)
             
for i in range(Q):
    x, y = map(int, input().split())
    print(visited[x]+visited[y])
Problem p03805 (python)

Fixed submission:
N, M = map(int, input().split())
graph ={i+1:[] for i in range(N)}
for _ in range(M):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)
    
def dfs(path, n, cnt):
    if(len(path) == N):
        return cnt+1
    for j in graph[n]:
        if(j in path):
            continue
        cnt = dfs(path+[j], j, cnt)
    return cnt
print(dfs([1], 1, 0))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
dict = {i+1:[] for i in range(M)}
for _ in range(M):
    a, b = map(int, input().split())
    dict[a].append(b)
    dict[b].append(a)
    
def DFS(visited, sight, cnt):
    if(len(visited) == N):
        return cnt+1
    for num in dict[sight]:
        if num in visited:
            continue
        cnt = DFS(visited+[num], num, cnt)
    return cnt

print(DFS([1], 1, 0))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
graph ={i+1:[] for i in range(N)}
for _ in range(N):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)
    
def DFS(graph, start, end):
    stack = [start]
    visited = []
    cnt = 0
    while stack:
        label = stack.pop(0)
        if label == end:
            visited.append(label)
            cnt += 1
        if label not in visited:
            visited.append(label)
            stack = graph.get(label, [])+stack
    return cnt
print(DFS(graph, 1, N))
Problem p02623 (python)

Fixed submission:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
S = 0
ans = 0
for i in range(M):
  S += B[i]
  if S > K:
    b = i - 1
    S -= B[i]
    break
  else:
    ans += 1
    if i==M-1:
      b = M-1
if b==0:
  ans = 0
  S = 0
  for a in A:
    if S + a <= K:
      S += a
      ans += 1
    else:
      break
  if S + B[0]<=K:
    ans+=1
  print(ans)
else:
  a = 0
  max_ans = ans
  while a<N:
    if S + A[a] <= K:
      S += A[a]
      ans += 1
      a += 1
    else:
      break
  max_ans = max(max_ans, ans)
  for j in range(b, -1, -1):
    S -= B[j]
    ans -= 1
    while a<N:
      if S + A[a] <= K:
        S += A[a]
        ans += 1
        a += 1
      else:
        break
      
    max_ans = max(max_ans, ans)
  print(max_ans)

Buggy submission (verdict: Runtime Error):
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

S_A = [0] * (N + 1)
S_B = [0] * (N + 1)
for i in range(N):
  S_A[i+1] = S_A[i] + A[i]

for i in range(M):
  S_B[i+1] = S_B[i] + B[i]
  
ans = 0
a = 0
for i in range(M, -1, -1):
  s = S_B[i]
  while a<N:
    if s + S_A[a + 1]<=K:
      a += 1
    else:
      break
  ans = max(ans, i + a)
print(ans)
Problem p02624 (python)

Fixed submission:
N = int(input())
ans = 0
for i in range(1, N + 1):
  x = N//i
  ans += i * x * (x + 1) // 2
  
print(ans)

Buggy submission (verdict: Runtime Error):
def main():
  N = int(input())
  def count(n):
    ret = 0
    i = 1
    while i*i <= n:
      if n % i == 0:
        ret += 1
        if i != n // i:
          ret += 1
      i += 1
    return ret


  ans = 1
  l[0] = True
  l[1] = True
  if N==1:
    print(ans)
  else:
    for i in range(2,N+1):
      x = count(i)
      ans += x * i

    print(ans)
    
main()
Problem p02679 (python)

Fixed submission:
def main():
  from math import gcd
  from collections import defaultdict
  import sys
  input = sys.stdin.readline
  N = int(input())
  AB = [list(map(int,input().split())) for _ in range(N)]

  MOD = 10**9 + 7

  zero_zero_count = 0
  zero_one_count = 0
  one_zero_count = 0
  dd_ba = defaultdict(int, {})
  for a,b in AB:
    if (a==0)and(b==0):
      zero_zero_count += 1
    elif (a==0):
      zero_one_count += 1
    elif (b==0):
      one_zero_count += 1
    else:
      if a * b < 0:
        a = abs(a)
        b = abs(b)
        g = gcd(a, b)
        dd_ba[(b//g, a//g)] += 1
      else:
        a = abs(a)
        b = abs(b)
        g = gcd(a, b)
        dd_ba[(-b//g, a//g)] += 1

  ans = (2**zero_one_count + 2**one_zero_count -1)
  dd_flag = defaultdict(bool, {})

  for key,value in tuple(dd_ba.items()):
    if dd_flag[key]:
      continue
    
    key_0 = key[0]
    key_1 = key[1]
    if key_0<0:
      x = (key_1, -key_0)
    else:
      x = (-key_1, key_0)
    y = dd_ba[x]
    ans *= (2**y + 2**value - 1) % MOD
    ans %= MOD
    dd_flag[x] = True

  ans += zero_zero_count - 1
  print(ans%MOD) 

if __name__=='__main__':
  main()

Buggy submission (verdict: Runtime Error):
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]

MOD = 1000000007
from collections import defaultdict
dd = defaultdict(int,{})
for a,b in AB:
  dd[-b/a] += 1
  
ans = 0
N -= 1
for a,b in AB:
  if N - dd[a/b]>=0:
    ans += pow(2,(N - dd[a/b]),MOD)
    ans %= MOD
  dd[-b/a] -= 1
  N -= 1
  
print(ans%MOD)

Buggy submission (verdict: Runtime Error):
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]

MOD = 1000000007
from collections import defaultdict
dd = defaultdict(int,{})
for a,b in AB:
  dd[-b/a] += 1
  
ans = 0
N -= 1
for a,b in AB:
  if N - dd[a/b]>=0:
    print(N-dd[a/b])
    ans += pow(2,(N - dd[a/b]),MOD)
    ans %= MOD
  dd[-b/a] -= 1
  N -= 1
  
print(ans%MOD)
Problem p02757 (python)

Fixed submission:
def main():
  N,P = map(int,input().split())
  S = list(map(int,list(input())))
  S=S[::-1]
  ans = 0
  if P==2:
    l = [0,2,4,6,8]
    for i,s in enumerate(S):
      if s in l:
        ans+=N-i
  elif P==5:
    l=[0,5]
    for i,s in enumerate(S):
      if s in l:
        ans+=N-i

  else:
    l = [0]*P
    a=0
    for i in range(N):
      b = pow(10,i,P)
      b *= S[i]
      b %= P
      a+=b
      a%=P
      l[a]+=1
    ans+=l[0]
    for i in l:
      ans+=i*(i-1)//2

  print(ans)
  
main()

Buggy submission (verdict: Runtime Error):
N,P = map(int,input().split())
S = list(map(int,list(input())))
S=S[::-1]
ans = 0
from collections import Counter
if P==2:
  l = [0,2,4,6,8]
  for i,s in enumerate(S):
    if s in l:
      ans+=N-i
elif P==5:
  l=[0,5]
  for i,s in enumerate(S):
    if s in l:
      ans+=N-i

else:
  l = [0]*(N+2)
  for i in range(N):
    l[i+1]=l[i]
    l[i+1]+=(S[i]*10**i)%P
    l[i+1]%=P
    
  c = Counter(l)
  l = list(c.values())
  l = sorted(l)
  for i in l:
    if l==1:
      continue
    else:
      ans+=c*(c-1)//2
      
print(ans)
Problem p02792 (python)

Fixed submission:
N = int(input())
ans = 0
l=[[0]*10 for _ in range(10)]
for i in range(1,N+1):
  s = str(i)
  l[int(s[0])][int(s[-1])]+=1
  
for i in range(10):
  for j in range(10):
    ans+=l[i][j]*l[j][i]
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
from fractions import gcd
mod = 10**9+7
g = A[0]
for a in A[1::]:
  g = g*a//gcd(g,a)

ans = 0
b = g%mod
for a in A:
  ans += b*pow(a,mod-2,mod)
  ans %= mod
  
print(ans%mod)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
from fractions import gcd
mod = 10**9+7
g = A[0]
for a in A[1::]:
  g = g*a//gcd(g,a)

ans = 0
b = g%mod
for a in A:
  ans += b*pow(a,mod-2,mod)
  ans %= mod
  
print(ans%mod)
Problem p02793 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
from fractions import gcd
mod = 10**9+7
g = A[0]
for a in A[1::]:
  g = g*a//gcd(g,a)
  
ans = 0
b = g%mod
for a in A:
  ans += g%mod*pow(a,mod-2,mod)
  ans %= mod
  
print(ans%mod)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
l = [0]*(max(A)+1)
for a in A:
  x=0
  while a%2==0:
    a//=2
    x+=1
    
  l[2]=max(l[2],x)
  
  f = 3
  while f**2<=a:
    x = 0
    while a%f==0:
      a//=f
      x+=1
    l[f]=max(l[f],x)
    f+=2
    
  if a!=1:
    l[a]=max(l[a],1)
    
b = 1
for i,x in enumerate(l):
  b*=pow(i,x,mod)
  b%=mod
  
ans = 0
for a in A:
  ans+=(b*pow(a,mod-2,mod))%mod
  ans%=mod
  
print(ans%mod)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
l = [0]*(max(A)+1)
for a in A:
  x=0
  while a%2==0:
    a//=2
    x+=1
    
  l[2]=max(l[2],x)
  
  f = 3
  while f**2<=a:
    x = 0
    while a%f==0:
      a//=f
      x+=1
    l[f]=max(l[f],x)
    f+=2
    
  if a!=1:
    l[a]=max(l[a],1)
    
b = 1
for i,x in enumerate(l):
  b*=pow(i,x,mod)
  b%=mod
  
ans = 0
for a in A:
  ans+=(b*pow(a,mod-2,mod))%mod
  ans%=mod
  
print(ans%mod)
Problem p02829 (python)

Fixed submission:
A = int(input())
B = int(input())
l = [1,2,3]
l.remove(A)
l.remove(B)
print(l[0])

Buggy submission (verdict: Runtime Error):
N,u,v = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
    
x = [[] for _ in range(N)]
for ab in AB:
  a = ab[0]
  b = ab[1]
  x[a-1].append(b-1)
  x[b-1].append(a-1)
  
flag1 = [False]*N
flag2 = [False]*N
length1 = [0]*N
length2 = [0]*N
go = [v-1]
while go!=[]:
  a = go.pop()
  if flag1[a]:
    continue
  else:
    flag1[a]=True
    for i in x[a]:
      if flag1[i]:
        continue
      else:
        length1[i]=length1[a]+1
        go.append(i)

go = [u-1]
while go!=[]:
  a = go.pop()
  if flag2[a]:
    continue
  else:
    flag2[a]=True
    for i in x[a]:
      if flag2[i]:
        continue
      else:
        length2[i]=length2[a]+1
        go.append(i)
        
print(max(length1))
Problem p02859 (python)

Fixed submission:
r = int(input())

print(r**2)

Buggy submission (verdict: Runtime Error):
import numpy as np
import math
X,Y = map(int,input().split())
 
 
c1 = (2*Y-X)
if c1%3!=0:
  print(0)
 
else:
  def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
  
  c1 = c1//3
  c2 = Y-2*c1
  c3 = c1+c2+1
  mod = 10**9+7
  c4 = min(c1,c2)
  x = 1
  y = 1
  for i in range(1,c4+1):
    x = (x * (c3-i)) % mod
    y = (y * i) % mod
    
  result = (x * pow(y,mod-2,mod)) % mod
 
  print(result)
Problem p02863 (python)

Fixed submission:
N,T = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

dp1 = [[0]*T for _ in range(N+1)]
rev_AB = AB[::-1]
dp2 = [[0]*T for _ in range(N+1)]
for i,(ab,rev_ab) in enumerate(zip(AB,rev_AB),1):
  a = ab[0]
  rev_a = rev_ab[0]
  b = ab[1]
  rev_b = rev_ab[1]
  l_1 = dp1[i-1]
  l_2 = dp2[i-1]
  for t in range(1,T):
    if a>t:
      dp1[i][t]=l_1[t]
      
    else:
      dp1[i][t] = max(l_1[t],l_1[t-a]+b)
      
    if rev_a>t:
      dp2[i][t]=l_2[t]
    
    else:
      dp2[i][t] = max(l_2[t],l_2[t-rev_a]+rev_b)
      
      
    

      
lis = [0]*N
for i in range(1,N+1):
  l_1 = dp1[i-1]
  l_2 = dp2[N-i]
  b = AB[i-1][1]
  for t in range(T):
    lis[i-1] = max(l_1[t]+l_2[T-1-t]+b,lis[i-1])

    
print(max(lis))

Buggy submission (verdict: Runtime Error):
N,T = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
import numpy as np
 
dp1 = np.array([[0]*T for _ in range(N+1)])
rev_AB = AB[::-1]
dp2 = np.array([[0]*T for _ in range(N+1)])


for i,(ab,rev_ab) in enumerate(zip(AB,rev_AB),1):
  a = ab[0]
  rev_a = rev_ab[0]
  b = ab[1]
  rev_b = rev_ab[1]
  
  dp1[i,:a] = dp1[i-1,:a]
  dp2[i,:rev_a] = dp2[i-1,:rev_a]
  dp1[i,a:] = np.fmax(dp1[i-1,a:],dp1[i-1,:-a]+b)
  dp2[i,rev_a:] = np.fmax(dp2[i-1,rev_a:],dp2[i-1,:-rev_a]+rev_b)

      
lis = [0]*N
for i in range(1,N+1):
  l_1 = dp1[i-1]
  l_2 = dp2[N-i]
  b = AB[i-1][1]
  for t in range(T):
    lis[i-1] = max(l_1[t]+l_2[T-1-t]+b,lis[i-1])
 
    
print(max(lis))
Problem p02873 (python)

Fixed submission:
S = input()
from itertools import groupby
S_length = len(S)
k = 1
s_l=[k*len(list(g)) for k, g in groupby(S)]
  
        
        
def n_sum(n):
  return n*(n+1)//2
        

s_l_length = len(s_l)
answer=0
if s_l[0][0]=='<':
  if s_l_length%2==0:
    for i in range(0,s_l_length,2):
      s_1=s_l[i]
      s_2=s_l[i+1]
      s_1_l=len(s_1)
      s_2_l=len(s_2)
      if s_1_l<=s_2_l:
        answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
      else:
        answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  else:
    for i in range(0,s_l_length,2):
      if i==s_l_length-1:
        answer+=n_sum(len(s_l[i]))
      else:
        s_1=s_l[i]
        s_2=s_l[i+1]
        s_1_l=len(s_1)
        s_2_l=len(s_2)
        if s_1_l<=s_2_l:
          answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
        else:
          answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
          
else:
  answer+=n_sum(len(s_l.pop(0)))
  s_l_length-=1
  if s_l_length%2==0:
    for i in range(0,s_l_length,2):
      s_1=s_l[i]
      s_2=s_l[i+1]
      s_1_l=len(s_1)
      s_2_l=len(s_2)
      if s_1_l<=s_2_l:
        answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
      else:
        answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  else:
    for i in range(0,s_l_length,2):
      if i==s_l_length-1:
        answer+=n_sum(len(s_l[i]))
      else:
        s_1=s_l[i]
        s_2=s_l[i+1]
        s_1_l=len(s_1)
        s_2_l=len(s_2)
        if s_1_l<=s_2_l:
          answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
        else:
          answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  
      
print(answer)

Buggy submission (verdict: Runtime Error):
S = input()
S_length = len(S)
k = 1
s_l=[]
for i in range(S_length-1):
  s_x=S[i]
  if S[i+1]==s_x:
    k+=1
  else:
    s_l.append(s_x*k)
    k=1

if s_l[-1][0]!=S[-1]:
  s_l.append(S[-1])
  
        
        
def n_sum(n):
  return n*(n+1)//2
        

s_l_length = len(s_l)
answer=0
if s_l[0][0]=='<':
  if s_l_length%2==0:
    for i in range(0,s_l_length,2):
      s_1=s_l[i]
      s_2=s_l[i+1]
      s_1_l=len(s_1)
      s_2_l=len(s_2)
      if s_1_l<=s_2_l:
        answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
      else:
        answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  else:
    for i in range(0,s_l_length,2):
      if i==s_l_length-1:
        answer+=n_sum(len(s_l[i]))
      else:
        s_1=s_l[i]
        s_2=s_l[i+1]
        s_1_l=len(s_1)
        s_2_l=len(s_2)
        if s_1_l<=s_2_l:
          answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
        else:
          answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
          
else:
  answer+=n_sum(len(s_l.pop(0)))
  s_l_length-=1
  if s_l_length%2==0:
    for i in range(0,s_l_length,2):
      s_1=s_l[i]
      s_2=s_l[i+1]
      s_1_l=len(s_1)
      s_2_l=len(s_2)
      if s_1_l<=s_2_l:
        answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
      else:
        answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  else:
    for i in range(0,s_l_length,2):
      if i==s_l_length-1:
        answer+=n_sum(len(s_l[i]))
      else:
        s_1=s_l[i]
        s_2=s_l[i+1]
        s_1_l=len(s_1)
        s_2_l=len(s_2)
        if s_1_l<=s_2_l:
          answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
        else:
          answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  
      
print(answer)
Problem p02891 (python)

Fixed submission:
S = input()
K = int(input())

import re

def nchars(s, n):
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

if len(S)==1:
  print(K//2)
  
elif S[0]!=S[-1]:
  S_l = list(nchars(S,2))
  answer = 0
  for s in S_l:
    answer += len(s)//2
  print(answer*K)

else:
  if (S[0]!=S[1])&(S[-1]!=S[-2]):
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2

    answer = S_lr + (1+S_lr)*(K-1)
    print(answer)
  
  elif (S[0]!=S[1])&(S[-1]==S[-2]):
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2
    
    a=len(S_l[-1])
    answer = S_lr + ((a+1)//2 + (S_lr-a//2))*(K-1)
    print(answer)
  
  elif (S[0]==S[1])&(S[-1]!=S[-2]):
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2
    
    a=len(S_l[0])
    answer = S_lr + ((a+1)//2 + (S_lr-a//2))*(K-1)
    print(answer)
    
  else:
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    if len(S_l)==1:
      print(len(S)*K//2)
    else:
      for s in S_l:
        S_lr += len(s)//2

      a=len(S_l[0])
      b=len(S_l[-1])
      answer = S_lr + ((a+b)//2 + (S_lr-a//2-b//2))*(K-1)
      print(answer)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

import re

def nchars(s, n):
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

if S[0]!=S[-1]:
  S_l = list(nchars(S,2))
  answer = 0
  for s in S_l:
    answer += len(s)//2
  print(answer*K)

else:
  if (S[0]!=S[1])&(S[-1]!=S[-2]):
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2

    answer = S_lr + (1+S_lr)*(K-1)
    print(answer)
  
  elif (S[0]!=S[1])&(S[-1]==S[-2]):
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2
    
    a=len(S_l[-1])
    answer = S_lr + ((a+1)//2 + (S_lr-a//2))*(K-1)
    print(answer)
  
  elif (S[0]==S[1])&(S[-1]!=S[-2]):
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2
    
    a=len(S_l[0])
    answer = S_lr + ((a+1)//2 + (S_lr-a//2))*(K-1)
    print(answer)
    
  else:
    answer = 0
    S_lr=0
    S_l = list(nchars(S,2))
    for s in S_l:
      S_lr += len(s)//2
    
    a=len(S_l[0])
    b=len(S_l[-1])
    answer = S_lr + ((a+b)//2 + (S_lr-a//2-b//2))*(K-1)
    print(answer)
Problem p02912 (python)

Fixed submission:
N,M = map(int, input().split())
A = list(map(int, input().split()))

l = len(A)

if N>=2:
  while M>=1:
    A.sort(reverse=True)
    div = A[0]//2
    
    for i in range(l):
      if A[i]>=div:
        if M>=1:
          A[i] = A[i]//2
          M -= 1
        else:
          break
      else:
        break
 
  print(sum(A))
else:
    i=1
    while 2**(i+1)<=A[0]:
      i+=1
    if M>=i:
      print(0)
    else:
      print(A[0]//2**M)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
A = list(map(int, input().split()))

A = A.sort(reverse=True)
l = len(A)

if N>=2:
  while M>=1:
    div = A[0]//2
    
    for i in range(l):
      if A[i]>=div:
        if M>=1:
          A[i] = A[i]//2
        else:
          break
      else:
        break
 
  print(sum(A))
else:
    i=1
    while 2**(i+1)<=A[0]:
      i+=1
    if M>=i:
      print(0)
    else:
      print(A[0]//2**M)
Problem p02915 (python)

Fixed submission:
N = int(input())
print(N**3)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
Ss = input()
 
num = Ss.count('RL')*2
if list(Ss)[-1]=='L':
  num += 1
if list(Ss)[0]=='L':
  num += 1
ans = N - max(1, num-2*K)
print(ans)
Problem p03038 (python)

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]
count=0
D=[]
BC.sort(key=lambda x:x[1],reverse=True)
A.sort()
for B,C in BC:
  D+=[C]*B
  count+=B
  if count>=N:
    break

D=D[:N]
for i in range(len(D)):
  d=D[i]
  if A[i]<d:
    A[i]=d
  else:
    break
  
print(sum(A))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]
count=0
D=[]
BC.sort(key=lambda x:x[1],reverse=True)
A.sort()
for B,C in BC:
  D+=[C]*B
  count+=B
  if count>=N:
    break

if D!=[]:
  D=D[:N]
  for i in range(N):
    d=D[i]
    if A[i]<d:
      A[i]=d
    else:
      break
  
print(sum(A))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]
count=0
D=[]
BC.sort(key=lambda x:x[1],reverse=True)
A.sort()
for B,C in BC:
  D+=[C]*B
  count+=B
  if count>=N:
    break

if D:
  D=D[:N]
  for i in range(N):
    d=D[i]
    if A[i]<d:
      A[i]=d
    else:
      break
  
print(sum(A))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]
count=0
D=[]
BC.sort(key=lambda x:x[1],reverse=True)
A.sort()
for B,C in BC:
  D+=[C]*B
  count+=B
  if count>=N:
    break
  
D=D[:N]
for i in range(N):
  d=D[i]
  if A[i]<d:
    A[i]=d
  else:
    break
  
print(sum(A))
Problem p02547 (python)

Fixed submission:
n = int(input())
cur = 0
best = 0
for _ in range(n):
        a, b = input().split()
        if a == b:
                cur += 1
                best = max(best, cur)
        else:
                cur = 0
if best >= 3:
        print("Yes")
else:
        print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
cur = 0
best = 0
for _ in range(n):
  	a, b = input().split()
    if a == b:
        cur += 1
        best = max(best, cur)
    else:
      	cur = 0
if best >= 3:
  	print("Yes")
else:
  	print("No")
Problem p02771 (python)

Fixed submission:
from sys import setrecursionlimit as srl; srl(10**7)
rr = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())
 
A,B,C = rrm()
if A==B!=C or A==C!=B or B==C!=A:
    print "Yes"
else:
    print "No"

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit as srl; srl(10**7)
rr = lambda: int(raw_input())
rrm = lambda: map(raw_input().split())



A,B,C = rrm()
if A==B!=C or A==C!=B or B==C!=A:
    print "Yes"
else:
    print "No"
Problem p02773 (python)

Fixed submission:
from sys import setrecursionlimit as srl; srl(10**7)
rr = raw_input
rrm = lambda: map(int, raw_input().split())

N =int(rr())
from collections import Counter
count = Counter()
for _ in xrange(N):
    count[rr()] += 1
M = max(count.values())
ans = []
for k in count:
    if count[k] == M:
        ans.append(k)
ans.sort()
for x in ans:
    print x

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit as srl; srl(10**7)
rr = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())

N =int(rr())
from collections import Counter
count = Counter()
for _ in xrange(N):
    count[rr()] += 1
M = max(count.values())
ans = []
for k in count:
    if count[k] == M:
        ans.append(k)
ans.sort()
for x in ans:
    print x