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

Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import fractions

a,b,c,d = mi()

g = c*d // fractions.gcd(c,d)

# cの倍数の個数
ac = (a-1)//c
bc = b//c
nc = bc-ac

# dの倍数の個数
ad = (a-1)//d
bd = b//d
nd = bd-ad

# cdのgcdの倍数の個数
ag = (a-1)//g
bg = b//g
ng = bg-ag

ans = b-(a-1)-nc - nd + ng

# print(g,nc,nd,ng)
print(ans)

Buggy submission (verdict: Runtime Error):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import math 

a,b,c,d = mi()

g = int(c*d / math.gcd(c,d))

# cの倍数の個数
ac = int((a-1)/c)
bc = int(b/c)
nc = bc-ac

# dの倍数の個数
ad = int((a-1)/d)
bd = int(b/d)
nd = bd-ad

# cdのgcdの倍数の個数
ag = int((a-1)/g)
bg = int(b/g)
ng = bg-ag

ans = b-(a-1)-nc - nd + ng

# print(g,nc,nd,ng)
print(ans)

Buggy submission (verdict: Runtime Error):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import math 

a,b,c,d = mi()

g = int(c*d / math.gcd(c,d))

# cの倍数の個数
ac = (a-1)//c
bc = b//c
nc = bc-ac

# dの倍数の個数
ad = (a-1)//d
bd = b//d 
nd = bd-ad

# cdのgcdの倍数の個数
ag = (a-1)//g
bg = b//g
ng = bg-ag

ans = b-(a-1)-nc - nd + ng

# print(g,nc,nd,ng)
print(ans)

Buggy submission (verdict: Runtime Error):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import math 

a,b,c,d = mi()

g = c*d//math.gcd(c,d)

# cの倍数の個数
ac = (a-1)//c
bc = b//c
nc = bc-ac

# dの倍数の個数
ad = (a-1)//d
bd = b//d 
nd = bd-ad

# cdのgcdの倍数の個数
ag = (a-1)//g
bg = b//g
ng = bg-ag

ans = b-(a-1)-nc - nd + ng

# print(g,nc,nd,ng)
print(ans)

Buggy submission (verdict: Runtime Error):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import math 

a,b,c,d = mi()

g = c*d//math.gcd(c,d)

# cの倍数の個数
ac = (a-1)//c
bc = b//c
nc = bc-ac

# dの倍数の個数
ad = (a-1)//d
bd = b//d 
nd = bd-ad

# cdのgcdの倍数の個数
ag = (a-1)//g
bg = b//g
ng = bg-ag

ans = b-(a-1)-nc - nd + ng

# print(g,nc,nd,ng)
print(int(ans))
Problem p03163 (python)

Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
import numpy as np
n,W = mi()
a = [tuple(int(i) for i in input().split()) for _ in range(n)]
dp = np.array([0]*(W+1))
for w,v in a:
    ed = W+1-w
    dp[w:W+1] = np.maximum(dp[w:W+1], dp[0:W+1-w] + v)
print(dp[W])

Buggy submission (verdict: Runtime Error):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
import numpy as np
n,W = mi()
a = [tuple(int(i) for i in input().split()) for _ in range(n)]
dp = np.array([0]*(W+1))
for w,v in a:
    ed = W+1-w
    dp[w:W+1] = np.maximum(dp[w:ed], dp[0:ed] + v)
print(dp[W])
Problem p02553 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
print(max([a *c, a*d, b* c, b* d]))

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input.split())
print(max([a *c, a*d, b* c, b* d]))
Problem p02576 (python)

Fixed submission:
want, max, time = map(int, input().split())
if want % max == 0:
  required = int(want / max)
else:
  required = int(want / max + 1)
print(required * time)

Buggy submission (verdict: Runtime Error):
answer = 0
n = int(input())
a = list(map(int, input().split(" ")))
for i in range(n - 1):
    a = sorted(a[:5], key=a[:5].count, reverse=True) + a[5:]
    if a[0] == a[1] == a[2]:
        answer += 1
    	del a[:3]

if a[0] == a[1] == a[2]:
    answer += 1

print(answer)

Buggy submission (verdict: Runtime Error):
x,n,t = map(str,input().split(" "))
cnt =0
while (x > 0):
    x -= n
    cnt += 1
print(cnt * t)

Buggy submission (verdict: Runtime Error):
x,n,t = map(str,input().split())
cnt =0
while x > 0:
    x -= n
    cnt += 2
print(cnt * t)
Problem p02621 (python)

Fixed submission:
a = int(input())
print(a + a**2 + a**3)

Buggy submission (verdict: Runtime Error):
a = input()
print(1+ a**2 + a**3)
Problem p02573 (python)

Fixed submission:
from collections import defaultdict
from collections import deque

d = defaultdict(set) #初期中身は空のset

N, M = map(int, input().split())
for i in range(M):
  A, B = map(int, input().split())
  d[A-1].add(B-1)
  d[B-1].add(A-1)
        
check = [0]*N
mans = 0

for i in range(N):
    ans = 0
    if check[i] == 0:
        check[i] = 1
        ans += 1
        sl = deque(list(d[i]))
        while sl:
            s = sl.pop()
            if check[s] == 0:
                check[s] = 1
                ans += 1
                sl.extend(list(d[s]))
    if mans < ans:
        mans = ans

print(mans)

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import connected_components
import collections

def main():
    N, M = map(int, input().split())
    ab = []
    for i in range(M):
        ab.append(list(map(int,input().split())))

    l = np.zeros((N, N), dtype = np.int64)

    for i in range(M):
        l[ab[i][0]-1,ab[i][1]-1] = 1
        #[ab[i][1]-1][ab[i][0]-1] = 1

    a = np.array(l)
    n, labels = connected_components(a)

    print(collections.Counter(labels).most_common()[0][1])
    
if __name__ == "__main__":
    main()
Problem p02727 (python)

Fixed submission:
X,Y,A,B,C = map(int, input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p = sorted(p)[::-1]
q = sorted(q)[::-1]
r = sorted(r)[::-1]

Ca = 0
Cb = 0
Cc = 0

ans = 0

while Ca + Cb + Cc != X + Y:
    if Cc == C:
        if q[Cb] > p[Ca]:
            ans = ans + q[Cb]
            Cb = Cb + 1
        else:
            ans = ans + p[Ca]
            Ca = Ca + 1
    else:
        if Ca == X:
            if q[Cb] > r[Cc]:
                ans = ans + q[Cb]
                Cb = Cb + 1
            else:
                ans = ans + r[Cc]
                Cc = Cc + 1
        else:
            if Cb == Y:
                if p[Ca] > r[Cc]:
                    ans = ans + p[Ca]
                    Ca = Ca + 1
                else:
                    ans = ans + r[Cc]
                    Cc = Cc + 1
            else:
                if p[Ca] >= q[Cb] and p[Ca] > r[Cc]:
                    ans = ans + p[Ca]
                    Ca = Ca + 1
                elif q[Cb] > p[Ca] and q[Cb] > r[Cc]:
                    ans = ans + q[Cb]
                    Cb = Cb + 1
                else:
                    ans = ans + r[Cc]
                    Cc = Cc + 1
print(ans)

Buggy submission (verdict: Runtime Error):
X,Y,A,B,C = map(int, input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p = sorted(p)[::-1]
q = sorted(q)[::-1]
r = sorted(r)[::-1]

Ca = 0
Cb = 0
Cc = 0

ans = 0

while Ca + Cb + Cc != X + Y:
    if Ca == X:
        if q[Cb] > r[Cc]:
            ans = ans + q[Cb]
            Cb = Cb + 1
        else:
            ans = ans + r[Cc]
            Cc = Cc + 1
    else:
        if Cb == Y:
            if p[Ca] > r[Cc]:
                ans = ans + p[Ca]
                Ca = Ca + 1
            else:
                ans = ans + r[Cc]
                Cc = Cc + 1
        else:
            if p[Ca] >= q[Cb] and p[Ca] > r[Cc]:
                ans = ans + p[Ca]
                Ca = Ca + 1
            elif q[Cb] > p[Ca] and q[Cb] > r[Cc]:
                ans = ans + q[Cb]
                Cb = Cb + 1
            else:
                ans = ans + r[Cc]
                Cc = Cc + 1
print(ans)
Problem p02641 (python)

Fixed submission:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 9999999999
lists = []
if n == 0:
    print(x)
    exit()
for i in range(-1000, 1000):
    if not i in p:
        lists.append(i)
for i in lists:
    if ans > abs(x - i):
        ans = abs(x-i)
        m = i
print(m)

Buggy submission (verdict: Runtime Error):
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 9999999999
    lists = []
    if n == 0:
        print(x)
        exit()
    for i in range(-1000, 1000):
        if not i in p:
            lists.append(i)
    for i in lists:
        if ans > abs(x - i):
            ans = abs(x-i)
            m = i
     
    print(m)
Problem p02576 (python)

Fixed submission:
#A問題

import math
N, X, T = map(int, input().split())
ans = T * math.ceil(N/X)
print(ans)

Buggy submission (verdict: Runtime Error):
#B問題
n = int(input())

# ある整数に対し、各桁の和を与える

sum = 0
while n > 0:
    sum += n % 10
    n = int(n / 10)
    
ans = sum % 9
    
if ans == 0:
    print("Yes")
else:
    print("No")
Problem p02717 (python)

Fixed submission:
box = []
box = input().split()
box[0], box[1] = box[1], box[0]
box[0], box[2] = box[2], box[0]
print(box[0],  box[1],  box[2])

Buggy submission (verdict: Runtime Error):
box = []
box = input().split()
box[0], box[1] = box[1], box[0]
box[0], box[2] = box[2], box[0]
print(box[0] box[1] box[2])

Buggy submission (verdict: Runtime Error):
box = []
box = input().rstrip()
print(box[2] box[0] box[1])
Problem p02718 (python)

Fixed submission:
N, M = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
if a[M-1] >= sum(a) / (4*M):
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
N, M = input().split()
a = list.split()
a.sort(reverse=True)
if (a[M-1] >= sum(a) / 4*M)==True
	print("Yes")
else print("No")

Buggy submission (verdict: Runtime Error):
N, M = input.split()
a = list.split()
a.sort(reverse=True)
if a[M-1] >= sum(a) / 4*M:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N, M = input.split()
a = list.split()
a.sort(reverse=True)
if (a[M-1] >= sum(a) / 4*M)==True
	print("Yes")
else print("No")
Problem p02576 (python)

Fixed submission:
A, B, C = map(int, input().split())

if A%B == 0:
	Z = A//B
else :
    Z = A//B + 1
time = Z*C

print(time)

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().split())

Z = N/X-N%X
time = Z*T

print(time)

Buggy submission (verdict: Runtime Error):
var N = 20;
var X = 12;
var T = 6;
var Z = N/X-N%T;
var time = Z*T;
print(time);

Buggy submission (verdict: Runtime Error):
var Takoyaki = [N,X,T]
N = 20 
X = 12
T = 6
N / X -- N % X = Z
Z*T = time
print(time)
Problem p02613 (python)

Fixed submission:
n,*s=open(0).read().split()
for t in['AC','WA','TLE','RE']:print(f'{t} x {s.count(t)}')

Buggy submission (verdict: Runtime Error):
n,*s=open(0);for t in['AC','WA','TLE','RE']:print(t,'x',s.count(t+'\n'))
Problem p02658 (python)

Fixed submission:
n,*a=map(int,open(0).read().split());z=1
for i in a:
 if i>1e18//z:z=-1;break
 z*=i
print(0 if 0in a else z)

Buggy submission (verdict: Runtime Error):
input();a=sorted(map(int,input().split()));z=1
for i in a:
 if i>1e18//z:z=-1;break
 z*=i
print(z)

Buggy submission (verdict: Runtime Error):
input();a=eval(input().replace(' ','*'));print((a,-1)[a>1e18])

Buggy submission (verdict: Runtime Error):
input();a=eval(input().replace(' ','*'));print((a,-1)[a>10**18])
Problem p03101 (python)

Fixed submission:
H,W=map(int,input().split())
h,w=map(int,input().split())
print((H-h)*(W-w))

Buggy submission (verdict: Runtime Error):
H,W,h,w=map(int,open(0));print((H-h)*(W-w))
Problem p03129 (python)

Fixed submission:
n,k=map(int,input().split())
print(["NO","YES"][n+n%2>=k*2])

Buggy submission (verdict: Runtime Error):
from math import factorial
n,k=map(int,input().split())
print(["NO","YES"][factorial(n)/factorial(k)-(n-1)*factorial(n-2)/factorial(k-2)>1])
Problem p03273 (python)

Fixed submission:
h,w=map(int,input().split());print(*["".join(e)for e in zip(*["".join(e)for e in zip(*[e for e in[input()for _ in[0]*h]if"#"in e])if"#"in e])],sep="\n")

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int h, w; cin >> h >> w;
  vector<string> board(h);
  for (auto& e: board) cin >> e;

  vector<bool> rowIncludeSharp(h), colIncludeSharp(w);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (board[i][j] == '#') {
        rowIncludeSharp[i] = true;
        colIncludeSharp[j] = true;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    if (rowIncludeSharp[i]) {
      for (int j = 0; j < w; j++) {
        if (colIncludeSharp[j]) {
          cout << board[i][j];
        }
      }
      cout << endl;;
    }
  }
}
Problem p02576 (python)

Fixed submission:
n, x, t = map(int, input().split())
tm = (n // x) * t 
if (n % x) != 0:
    tm += t
print(tm)

Buggy submission (verdict: Runtime Error):
n,x,t = map(int, input().split())
Y = X
ans = 0
cnt = 1

while X < N:
    X = X + Y
    cnt = cnt + 1
	ans = T * cnt
	print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
X = int(input())
T = int(input())
N = int(input())
Y = X
ans = 0
cnt = 1

while X < N:
    X = X + Y
    cnt = cnt + 1

ans = T * cnt
print(ans)

Buggy submission (verdict: Runtime Error):
X = int(input())
T = int(input())
N = int(input())
Y = X
ans = 0
cnt = 1

while X < N:
    X = X + Y
    cnt = cnt + 1

ans = T * cnt
print(ans)

Buggy submission (verdict: Runtime Error):
X = int(input())
T = int(input())
N = int(input())
Y = X
ans = 0
cnt = 1

while X < N:
    X = X + Y
    cnt = cnt + 1

ans = T * cnt
print(ans)
Problem p02630 (python)

Fixed submission:
def ad(a,bank):
	if a not in bank:
		bank[a] = 1
	else:
		bank[a] += 1

def rp(a,b,bank):
	ans = 0
	if a in bank:
		t = bank[a]
		ans = t
		bank[a] = 0
		if b not in bank:
			bank[b] = t
		else:
			bank[b] += t
		
	return ans
# your code goes here
n = int(input())
arr = list(map(int, input().split()))

bank = dict()
su = 0

for a in arr:
	ad(a,bank)
	su += a

q = int(input())
for i in range(q):
	b,c = map(int, input().split())
	t = rp(b,c,bank)
	if b in bank:
		su = su - (t*b) + (t*c)
	
	print(su)

Buggy submission (verdict: Runtime Error):
n = int(input())
arr = list(map(int, input().split()))

su = sum(arr)

q = int(input())
for i in range(q):
	b,c = map(int, input().split())
    si = su -b + c
    print(si)
Problem p02717 (python)

Fixed submission:
arr = list(map(int, input().split()))
print(arr[2], arr[0], arr[1])

Buggy submission (verdict: Runtime Error):
arr = map(int, input().split())
print(arr[2], arr[0], arr[1])

Buggy submission (verdict: Runtime Error):
arr = map(int, input().split())
print(arr[2], arr[0], arr[1])
Problem p02719 (python)

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

if k == 0:
	ans = n
else:
	rem = n % k
	a = rem - k
	ans = min(abs(a), rem)

print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())

rem = n % k
a = rem - k
ans = min(abs(a)
Problem p02602 (python)

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

for i in range(K,N):
  if A[i-K] < A[i]:
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
sys.setrecursionlimit(10**5+10)

N,K = map(int,input().split())
A = list(map(int,input().split()))
ynlist = []

def checker(i):
  try:
    l1 = A[i-K+1:i:]
    b = np.prod(l1)
    i1 = A[i-K]
    i2 = A[i]
    score1 = b * i1
    score2 = b * i2
    if score1 < score2:
      ynlist.append("Yes")
    else:
      ynlist.append("No")
    checker(i + 1)
  except IndexError:
    pass

checker(K)
for i in ynlist:
  print(i)
Problem p02639 (python)

Fixed submission:
x = list(map(int,input().split()))
for i in range(len(x)):
  if x[i] == 0:
    print(i + 1)

Buggy submission (verdict: Runtime Error):
x = list(map(int,input().split()))
for i in x:
  if x[i] == 0:
    print(i+1)
Problem p03268 (python)

Fixed submission:
n,k=map(int,input().split())
ans=(n//k)**3
if(k%2==0):
    ans+=(n//(k//2)-n//k)**3
print(ans)

Buggy submission (verdict: Runtime Error):
def base3(K):
    tmp=K
    S=""
    while(True):
        S=str(tmp%3)+S
        tmp=tmp//3
        if tmp==0:
            break
    return S
L=int(input())
T=base3(L)[::-1]
N=len(T)
A=[]
for i in range(N-1):
    tmp=3**i
    for k in range(3):
        A.append((i+1,i+2,k*tmp))
bef=0
for i in range(N)[::-1]:
    tmp=3**i
    for k in range(int(T[i])):
        A.append((i+1,N+1,bef+k*tmp))
    bef+=int(T[i])*tmp
print(N+1,len(A))
for p in A:
    print(p[0],p[1],p[2])ans=(n//k)**3

Buggy submission (verdict: Runtime Error):
    def base3(K):
        tmp=K
        S=""
        while(True):
            S=str(tmp%3)+S
            tmp=tmp//3
            if tmp==0:
                break
        return S
    L=int(input())
    T=base3(L)[::-1]
    N=len(T)
    A=[]
    for i in range(N-1):
        tmp=3**i
        for k in range(3):
            A.append((i+1,i+2,k*tmp))
    bef=0
    for i in range(N)[::-1]:
        tmp=3**i
        for k in range(int(T[i])):
            A.append((i+1,N+1,bef+k*tmp))
        bef+=int(T[i])*tmp
    print(N+1,len(A))
    for p in A:
        print(p[0],p[1],p[2])
Problem p02741 (python)

Fixed submission:
t = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(t[int(input()) - 1])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
if n == 1 or m == 1:
    print(1)
else:
    r = (n * m) // 2
    if (n * m) % 2 == 0:
        print(r)
    else:
        print(r+1)
Problem p02768 (python)

Fixed submission:
mod = 10**9+7
 
def comb(n,m,p=10**9+7):
    if n < m : return 0
    if n < 0 or m < 0:return 0
    m = min(m, n-m)
    top = bot = 1
    for i in range(m):
        top = top*(n-i) % p
        bot = bot*(i+1) % p
    bot = pow(bot, p-2, p)
    return top*bot % p
 
n,a,b = map(int, input().split())
ans = pow(2, n, mod)-1 - comb(n,a) - comb(n, b)
ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 1000000007
n,a,b = map(int,input().split())

def modpow(a, n, mod):
    res = 1
    while n > 0:
        if (n & 1): res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res
    

fac = [0]*(n+1)
finv = [0]*(n+1)
inv = [0]*(n+1)

# テーブルを作る前処理
def COMinit(n, MOD):
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, n+1):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

# 二項係数計算
def COM(n, k):
    if (n < k): return 0
    if (n < 0 or k < 0): return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


COMinit(n, MOD)
answer = modpow(2, n, MOD) - 1 - COM(n, a) - COM(n, b)
print(answer)
Problem p02885 (python)

Fixed submission:
A, B = map(int, input().split())
print(A - 2 * B if A - 2 * B > 0 else 0)

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
print(A-2*b if A-2*b > 0 else 0)
Problem p02909 (python)

Fixed submission:
S = input()
if S == 'Sunny':
    print('Cloudy')
elif S == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')

Buggy submission (verdict: Runtime Error):
def z_arr(s):

    Z = [0] * len(s)
    Z[0] = len(s)

    rt = 0
    lt = 0

    for k in range(1, len(s)):
        if k > rt:
            n = 0
            while n + k < len(s) and s[n] == s[n + k] and n < k:
                n += 1
            Z[k] = n
            if n > 0:
                lt = k
                rt = k + n - 1
        else:

            p = k - lt
            right_part_len = rt - k + 1

            if Z[p] < right_part_len:
                Z[k] = Z[p]
            else:
                i = rt + 1
                while i < len(s) and s[i] == s[i - k] and i-k+1 < k:
                    i += 1
                Z[k] = i - k

                lt = k
                rt = i - 1
    return Z

N = int(input())
S = input()
answer = 0
for i in range(N-1):
    ZZ = z_arr(S[i:])
    # print(ZZ)
    temp_max = max(ZZ[1:])
    if answer < temp_max:
        answer = temp_max
print(answer)

Buggy submission (verdict: Runtime Error):
def z_arr(s):

    Z = [0] * len(s)
    Z[0] = len(s)

    rt = 0
    lt = 0

    for k in range(1, len(s)):
        if k > rt:
            n = 0
            while n + k < len(s) and s[n] == s[n + k] and n < k:
                n += 1
            Z[k] = n
            if n > 0:
                lt = k
                rt = k + n - 1
        else:

            p = k - lt
            right_part_len = rt - k + 1

            if Z[p] < right_part_len:
                Z[k] = Z[p]
            else:
                i = rt + 1
                while i < len(s) and s[i] == s[i - k] and i < k:
                    i += 1
                Z[k] = i - k

                lt = k
                rt = i - 1
    return Z

N = int(input())
S = input()
answer = 0
for i in range(N-1):
    ZZ = z_arr(S[i:])
    # print(ZZ)
    temp_max = max(ZZ[1:])
    if answer < temp_max:
        answer = temp_max
print(answer)
Problem p02918 (python)

Fixed submission:
import sys
N, K = map(int, input().split())
S = input()
S0 = S[0]
SL = S[-1]
if N == 1:
    print(0)
    sys.exit(0)
else:
    cnt = S.count('RL')
    answer = 0
    if S0 == 'L' and SL == 'L':
        answer = N - 1
        answer -= cnt*2
        answer += K*2
        answer = answer if answer < N-1 else N-1
    if S0 == 'L' and SL == 'R':
        answer = N - 1
        answer -= cnt*2+1
        answer += K*2
        answer = answer if answer < N-1 else N-1
    if S0 == 'R' and SL == 'L':
        answer = N - 1
        answer -= cnt*2-1
        answer += K*2
        answer = answer if answer < N-1 else N-1
    if S0 == 'R' and SL == 'R':
        answer = N - 1
        answer -= cnt*2
        answer += K*2
        answer = answer if answer < N-1 else N-1
        
    print(answer)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
S0 = S[0]
SL = S[-1]
if N == 1:
    print(0)
    sys.exit(0)
else:
    cnt = S.count('RL')
    answer = 0
    if S0 == 'L' and SL == 'L':
        answer = N - 1
        answer -= cnt*2
        answer += K*2
        answer = answer if answer < N-1 else N-1
    if S0 == 'L' and SL == 'R':
        answer = N - 1
        answer -= cnt*2+1
        answer += K*2
        answer = answer if answer < N-1 else N-1
    if S0 == 'R' and SL == 'L':
        answer = N - 1
        answer -= cnt*2-1
        answer += K*2
        answer = answer if answer < N-1 else N-1
    if S0 == 'R' and SL == 'R':
        answer = N - 1
        answer -= cnt*2
        answer += K*2
        answer = answer if answer < N-1 else N-1
        
    print(answer)
Problem p02958 (python)

Fixed submission:
import sys
N = int(input())
p_s = list(map(int,input().split()))
cnt = 0
for i,p in enumerate(p_s):
    if i+1 != p:
  	    cnt += 1
    if cnt > 2:
        break
else:
    print("YES")
    sys.exit(0)
print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
p_s = list(map(int,input().split()))
cnt = 0
for i,p in enumerate(p_s):
  	if i+1 != p:
      	cnt += 1
    if cnt > 2:
      	break
else:
  	print("YES")
print("NO")
Problem p02993 (python)

Fixed submission:
S = input()
for i,s in enumerate(S):
    if i == 3:
        print('Good')
        break
    if S[i] == S[i+1]:
        print('Bad')
        break

Buggy submission (verdict: Runtime Error):
import fractions
import sys

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


A,B,C,D = map(int,input().split())
if C == 1 or D == 1:
    print(0)
    sys.exit(0)

E = lcm(C,D)
c = (A-1)//C + 1 if C!=1 else A
d = (A-1)//D + 1 if D!=1 else A
e = (A-1)//E + 1 if E!=1 else A
cde = [[c,C], [d,D], [e,E]]
cnt_cde = []
for x,y in cde:
    if x*y < B:
        cnt_cde.append((B-x*y)//y+1)
    elif x*y == B:
        cnt_cde.append(1)
    else :
        cnt_cde.append(0)
answer = B-A+1-(cnt_cde[0]+cnt_cde[1]-cnt_cde[2])
print(answer)

Buggy submission (verdict: Runtime Error):
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)


A,B,C,D = map(int,input().split())
c = B//C - (A-1)//C
d = B//D - (A-1)//D
E = lcm(C,D)
e = B//E - (A-1)//E
answer = B-A+1-(c+d-e)
print(answer)