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

Fixed submission:
#Miccさんのコードを参考にさせていただきました
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
e = v[1::2] #偶数番号
o = v[0::2] #奇数番号
ans = 0

a = Counter(e) #Counterオブジェクトを作成(dictのサブクラスでキーに要素、値に出現回数をもつ)
b = Counter(o)

c = a.most_common(2) #出現回数が2番目に多い数までのCounterオブジェクト作成
d = b.most_common(2)

if c[0][0] != d[0][0]: #出現回数が１番多いものが違う時
    ans = n -c[0][1] -d[0][1]
else:                  #出現回数が１番多いものが同じ時
    if len(c) == 1:
        if len(d) == 1:
            ans = n//2
        else:
            ans = n -d[0][1]
    elif len(d) == 1 and len(c) != 1:
        ans = n -c[0][1]
    elif c[0][1] > d[0][1]:
        ans = n -c[0][1] -d[1][1]
    else:
        if c[0][1]==d[0][1]:
            ans = min(n-c[0][1]-d[1][1],n-c[1][1]-d[0][1])
        else:
            ans = n -c[1][1] -d[0][1]
    
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

def calculate_mode(data):
    c = Counter(data)
    # すべての要素とその出現回数を取り出します。
    freq_scores = c.most_common()
    #c.most_common内の最も多い要素[0]の最大出現回数[1]を[0][1]で指定
    max_count = freq_scores[0][1]

    modes = []
    #出現回数と最大出現回数が等しいかを確認します。
    for num in freq_scores:
        if num[1] == max_count:
            modes.append(num[0])
    return(modes)



n = int(input())
v = list(map(int, input().split()))
a = v[0::2]
b = v[1::2]
c = v[0::2]
d = v[1::2]
ans = 0

f = max(calculate_mode(a))
g = max(calculate_mode(b))
print(f,g)
if f == g :
    for i in range(len(a)):
        if f == a[i]:
            a.remove(f)
        if g == b[i]:
            b.remove(g)
    f = calculate_mode(a)
    g = calculate_mode(b)


for i in range(len(a)):
    if f != c[i]:
        ans += 1
    if g != d[i]:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import statistics

def calculate_mode(data):
    c = Counter(data)
    # すべての要素とその出現回数を取り出します。
    freq_scores = c.most_common()
    #c.most_common内の最も多い要素[0]の最大出現回数[1]を[0][1]で指定
    max_count = freq_scores[0][1]

    modes = []
    #出現回数と最大出現回数が等しいかを確認します。
    for num in freq_scores:
        if num[1] == max_count:
            modes.append(num[0])
    return(modes)

n = int(input())
v = list(map(int, input().split()))
a = []
b = []
c = []
d = []
ans = 0
for i in range(len(v)):
    if i%2 == 1:
        a.append(v[i])
        c.append(v[i])
    if i%2 == 0:
        b.append(v[i])
        d.append(v[i])
f = statistics.mode(a)
g = statistics.mode(b)

#if f == g :
    #for i in range(len(a)):
        #if f == a[i]:
            #a.remove(f)
        #if g == b[i]:
            #b.remove(g)
    #f = calculate_mode(a)
    #g = calculate_mode(b)


for i in range(len(a)):
    if f != c[i]:
        ans += 1
    if g != d[i]:
        ans += 1

print(ans)
Problem p03260 (python)

Fixed submission:
a,b = map(int, input().split())
if a%2 == 1 and b%2 == 1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def gcd(a,b):   #　ユーグリッドの互除法
    if b == 0:
        return a
    return gcd(b, a % b)


N, X = map(int, input().split())

ans = 0


x = list(map(int, input().split()))
x.append(X)
x.sort()
a = []

for i in range(N):
    a.append(abs(x[i] - x[i+1]))
    ans = gcd(ans, a[i])


print(ans)

Buggy submission (verdict: Runtime Error):
import math

N, X = map(int, input().split())

ans = 0


x = list(map(int, input().split()))
x.append(X)
x.sort()
a = []

for i in range(N):
    a.append(abs(x[i] - x[i+1]))
    ans = math.gcd(ans, a[i])


print(ans)
Problem p03262 (python)

Fixed submission:
def gcd(a,b):   #　ユーグリッドの互除法
    if b == 0:
        return a
    return gcd(b, a % b)


N, X = map(int, input().split())

ans = 0


x = list(map(int, input().split()))
x.append(X)
x.sort()
a = []

for i in range(N):
    a.append(abs(x[i] - x[i+1]))
    ans = gcd(ans, a[i])


print(ans)

Buggy submission (verdict: Runtime Error):
import math

N, X = map(int, input().split())

ans = 0


x = list(map(int, input().split()))
x.append(X)
x.sort()
a = []

for i in range(N):
    a.append(abs(x[i] - x[i+1]))
    ans = math.gcd(ans, a[i])


print(ans)

Buggy submission (verdict: Runtime Error):
import math

N, X = map(int, input().split())

ans = 0


x = list(map(int, input().split()))
x.append(X)
x.sort()
a = []

for i in range(N):
    a.append(abs(x[i] - x[i+1]))
    ans = math.gcd(ans, a[i])


print(ans)
Problem p02658 (python)

Fixed submission:
def func():
    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for item in A:
        prod *= item
        if prod > 1e18:
            print(-1)
            return
    print(prod)

func()

Buggy submission (verdict: Runtime Error):
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author apurba_debnath
 */

#include <bits/stdc++.h>

#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl

using namespace std;

class BMultiplication2 {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        ll a[101010];
        ll zero = 0;
        for (int i = 0; i < n; ++i) {
            in >> a[i];
            if (a[i] == 0)
                zero++;
        }
        if (zero)
            out << 0;
        else {
            ll p = 1;
            for (int i = 0; i < n; ++i) {
                if (a[i] <= 1e18 / p)
                    p *= a[i];
                else {
                    out << "-1";
                    return;
                }
            }
            out << p;
        }
    }
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    BMultiplication2 solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);

    return 0;
}
Problem p02576 (python)

Fixed submission:
N, X, T = map(int, input().split())
if N % X > 0:
  a = (N // X + 1) * T
else:
  a = (N // X) * T

print(a)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = list(map(int, input().split()))
if N == 1:
  print(0)
else:
  x = 0
  for i in range(0,len(L)-1):
    if L[i] > L[i + 1]:
      x = x + (L[i] - L[i + 1])
      L[i + 1] = L[i + 1] + (L[i] - L[i + 1])
  print(x)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))
if N == 1:
  print(0)
else:
  x = 0
  for i in range(0,len(L)-1):
    if L[i] > L[i + 1]:
      x = x + (L[i] - L[i + 1])
      L[i + 1] = L[i + 1] + (L[i] - L[i + 1])
  print(x)
Problem p02582 (python)

Fixed submission:
L = [s for s in input()]
if not 'R' in L:
  print(0)
elif not 'S' in L:
  print(3)
elif L[1] == 'S':
  if 'R' in L :
    print(1)
elif L[0] == 'S':
  if L[2] =='S':
    print(1)
  else:
    print(2)
else:
  print(2)

Buggy submission (verdict: Runtime Error):
L = [s for s in input()]
if not 'R' in L:
  print(0)
elif not 'S' in L:
  print(3)
elif L[1] == 'S':
  if 'R' in L :
    print(1)
elif L[0] == 'S'
  print(1)
else:
  print(2)
Problem p02681 (python)

Fixed submission:
S = input()
T = input()

if(S==T[0:len(S)]):
  print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
A, B, C, K = map(int, input().split())
if((K-A)>0):
    Y = K-A
else:
    Y = 0
    print(K)
    exit()
if((Y-B)>0):
    Z = Y-B
else:
    Z = 0

X = A + 0 * Y + (-1) * Z
print(X)

Buggy submission (verdict: Runtime Error):
A, B, C, K = map(int, input().split())
if((K-A)>0):
    Y = K-A
else:
    Y = 0
if((Y-B)>0):
    Z = Y-B
else:
    Z = 0

X = 1 * K + 0 * Y + (-1) * Z
print(X)

Buggy submission (verdict: Runtime Error):
A, B, C, K = map(int, input().split())
if((K-A)>0):
    Y = K-A
else:
    Y = 0
if((Y-B)>0):
    Z = Y-B
else:
    Z = 0

X = A * K + 0 * Y + (-1) * Z
print(X)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

if(S==T[0:len(S)]):
  print(Yes)
else:
    print(No)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

if(S==T[0:len(S)]):
  print(True)
 else:
    print(False)
Problem p02646 (python)

Fixed submission:
A,V = map(int,input().split())
B,W = map(int,input().split())
T=int(input())

ans = "NO"

if(A<B):
    if(A+V*T >= B+W*T):
        ans = "YES"
elif(A>B):
    if(A+(-1)*V*T <= B+(-1)*W*T):
        ans = "YES"
print(ans)

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

ans = "NO"

if(A<B):
    if(A+V*T >= B+W*T):
        ans = "YES"
elif(A>B):
    if(A+(-1)*V*T =< B+(-1)*W*T):
        ans = "YES"
print(ans)

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

ans = "NO"

if(A<B):
    if(A+V*T >= B+W*T):
        ans = "YES"
elif(A>B):
    if(A+(-1)*V*T =< B+(-1)*W*T):
        ans = "YES"
print(ans)
Problem p02626 (python)

Fixed submission:
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
l=L()
sx=0
for i in l[2:]:
    sx^=i
if sx>l[0]+l[1]:
    print(-1)
    quit()
if (l[0]+l[1]-sx)%2==1:
    print(-1)
    quit()
if sx^l[0]^l[1]==0:
    print(0)
    quit()
x=(l[0]+l[1]-sx)//2
y=x
if x&sx>0:
    print(-1)
    quit()
if x>l[0]:
    print(-1)
    quit()
for i in range(45,-1,-1):
    if sx>>i&1:
        if l[0]>=(x+(1<<i)):
            x+=(1<<i)
if x==0:
    print(-1)
    quit()
print(l[0]-x)

Buggy submission (verdict: Runtime Error):
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
l=L()
sx=0
for i in l[2:]:
    sx^=i
if sx>l[0]+l[1]:
    print(-1)
    quit()
if (l[0]+l[1]-sx)%2==1:
    print(-1)
    quit()
if sx^l[0]^l[1]==0:
    print(0)
    quit()
x=(l[0]+l[1]-sx)//2
y=x
if x&sx>0:
    print(-1)
    quit()
if x>l[0]:
    print(-1)
    quit()
for i in range(45,-1,-1):
    if sx>>i&1:
        if l[0]>=(x+(1<<i)):
            x+=(1<<i)
if x==0:
    print(-1)
    quit()
if 
print(l[0]-x)
Problem p02670 (python)

Fixed submission:
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
import sys
sys.setrecursionlimit(10**6)
n=N()
p=L()
size=(n+1)**2+1
ans=[0]*size
for i in range(1,n+1):
    for j in range(1,n+1):
        k=i*(n+1)+j
        ans[k]=min(i-1,j-1,n-i,n-j)
c=[1]*size
di=[-1,1,n+1,-n-1]
def f(k,i):
    if k+i>=size:
        return
    if ans[k]+c[k]<ans[k+i]:
        ans[k+i]-=1
        q.append(k+i)
t=0
for i in p:
    y=i%n
    if y==0:
        y=n
    x=(i+n-1)//n
    k=x*(n+1)+y
    c[k]=0
    t+=ans[k]
    q=[k]
    while q:
        k=q.pop()
        f(k,1)
        f(k,-1)
        f(k,n+1)
        f(k,-n-1)
print(t)

Buggy submission (verdict: Runtime Error):
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
p=L()
ans=[[0]*(n+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,n+1):
        ans[i][j]=min(i-1,j-1,n-i,n-j)
c=[[1]*(n+1) for i in range(n+1)]
def f(x,y):
    for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
        if 1<=x+i<=n and 1<=y+j<=n:
            if ans[x][y]+c[x][y]<ans[x+i][y+j]:
                ans[x+i][y+j]-=1
                f(x+i,y+j)
t=0
for i in p:
    y=i%n
    if y==0:
        y=n
    x=(i+n-1)//n
    c[x][y]=0
    t+=ans[x][y]
    f(x,y)
print(t)
Problem p02690 (python)

Fixed submission:
n=int(input())
d=dict()
for i in range(300):
    for j in range(300):
        d[i**5-j**5]=(i,j)
        d[i**5+j**5]=(i,-j)
a,b=d[n]
print(a,b)

Buggy submission (verdict: Runtime Error):
n=int(input())
d=dict()
for i in range(200):
    for j in range(i,200):
        d[i**5-j**5]=(i,j)
        d[i**5+j**5]=(i,-j)
a,b=d[n]
print(a,b)
Problem p02733 (python)

Fixed submission:
h,w,k=map(int,input().split())
l=[[0 for i in range(w+1)]]+[[0]+[int(j) for j in input()] for i in range(h)]
a=[[0 for i in range(w+1)] for i in range(h+1)]
for i in range(1,h+1):
    for j in range(1,w+1):
        a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1]+l[i][j]
ans=h*w
def ink(h2,h1,w2,w1):
    return a[h2][w2]-a[h1][w2]-(a[h2][w1]-a[h1][w1])
for i in range(2**(h-1)):
    tl=[0]
    for j in range(h-1):
        if i>>j&1:
            tl.append(j+1)
    tl.append(h)
    t=len(tl)-2
    w1=0
    for w2 in range(1,w+1):
        for h1,h2 in zip(tl,tl[1:]):
            if ink(h2,h1,w2,w1)>k:
                if w2-1==w1:
                    t=h*w
                    break
                w1=w2-1
                t+=1
                break
    ans=min(ans,t)
print(ans)

Buggy submission (verdict: Runtime Error):
h,w,k=map(int,input().split())
import numpy as np
l=[[0 for i in range(w+1)]]+[[0]+[int(j) for j in input()] for i in range(h)]
a=np.cumsum(l,axis=1)
a=np.cumsum(a,axis=0)
ans=h*w
def ink(h2,h1,w2,w1):
    return a[h2][w2]-a[h1][w2]-(a[h2][w1]-a[h1][w1])
for i in range(2**(h-1)):
    tl=[0]
    for j in range(h-1):
        if i>>j&1:
            tl.append(j+1)
    tl.append(h)
    t=len(tl)-2
    w1=0
    for w2 in range(1,w+1):
        for h1,h2 in zip(tl,tl[1:]):
            if ink(h2,h1,w2,w1)>k:
                w1=w2-1
                t+=1
                break
    ans=min(ans,t)
print(ans)
Problem p02782 (python)

Fixed submission:
r1,c1,r2,c2=map(int,input().split())
r2+=1
c2+=1
N=2*(10**6)+2
mod=10**9+7
fac=[1]*(N+2)
inv=[1]*(N+2)
t=1
for i in range(1,N+2):
    t*=i
    t%=mod
    fac[i]=t
t=pow(fac[N+1],mod-2,mod)
for i in range(N+1,0,-1):
    inv[i]=t
    t*=i
    t%=mod
def comb(n,r):
    return fac[n]*inv[n-r]*inv[r]%mod
print((comb(r2+c2,c2)-comb(r2+c1,c1)-comb(r1+c2,c2)+comb(r1+c1,c1))%mod)

Buggy submission (verdict: Runtime Error):
r1,c1,r2,c2=map(int,input().split())
r2+=1
c2+=1
N=2*(10**6)
mod=10**9+7
fac=[1]*(N+2)
inv=[1]*(N+2)
t=1
for i in range(1,N+2):
    t*=i
    t%=mod
    fac[i]=t
t=pow(fac[N+1],mod-2,mod)
for i in range(N+1,0,-1):
    inv[i]=t
    t*=i
    t%=mod
def comb(n,r):
    return fac[n]*inv[n-r]*inv[r]%mod
print(comb(r2+c2,c2)-comb(r2+c1,c1)-comb(r1+c2,c2)+comb(r1+c1,c1))
Problem p02852 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())
s=input()
ans=[]
def f(i,j):
    if i==0:
        print(" ".join(map(str,ans[::-1])))
        return
    if j>i:
        j=i
    while s[i-j]=="1":
        j-=1
    if j==0:
        print(-1)
        return
    ans.append(j)
    f(i-j,m)
f(n,m)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=input()
ans=[]
def f(i,j):
    if i==0:
        print(" ".join(map(str,ans[::-1])))
        return
    if j>i:
        j=i
    while s[i-j]=="1":
        j-=1
    if j==0:
        print(-1)
        return
    ans.append(j)
    f(i-j,m)
f(n,m)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=input()
ans=[]
def f(i,j):
    if i==0:
        return
    if j>i:
        j=i
    while s[i-j]=="1":
        j-=1
    if j==0:
        print(-1)
        quit()
    ans.append(j)
    f(i-j,m)
f(n,m)
print(" ".join(map(str,ans[::-1])))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=input()
l=[0 for i in range(n+1)]
i=0
j=0
while j<n:
    j+=1
    while s[j]=="1":
        j+=1
    while j>i:
        i+=1
        l[i]=j
ans=[[] for i in range(n+1)]
for i in range(1,m+1):
    ans[i].append(i)
for i in range(m+1,n+1):
    if s[i]=="1":
        continue
    else:
        ans[i]=ans[l[i-m]]+[i-l[i-m]]
if 0 in ans[-1]:
    print(-1)
else:
    print(" ".join(map(str,ans[-1])))
Problem p02949 (python)

Fixed submission:
n,m,p=map(int,input().split())
edge=[]
for i in range(m):
    a,b,c=map(int,input().split())
    edge.append((a,b,p-c))
INF=float('inf')
def bellmanford(s,n):
    d = [INF for i in range(n+1)]
    d[s]=0
    for i in range(n-1):
        for a,b,c in edge:
            if d[b]>d[a]+c:
                d[b]=d[a]+c
    for i in range(n-1):
         for a,b,c in edge:
            if d[b]>d[a]+c:
                d[b]=-INF
    return d
d=bellmanford(1,n)
if d[n]==-INF:
    print(-1)
elif d[n]>=0:
    print(0)
else:
    print(-d[n])

Buggy submission (verdict: Runtime Error):
n,m,p=map(int,input().split())
edge=[]
for i in range(m):
    a,b,c=map(int,input().split())
    edge.append((a,b,p-c))
INF=float('inf')
def bellmanford(s,n):
    d = [INF for i in range(n+1)]
    d[s]=0
    for i in range(n-1):
        for a,b,c in edge:
            if d[b]>d[a]+cost:
                d[b]=d[a]+cost
    for i in range(n-1):
         for a,b,c in edge:
            if d[b]>d[a]+cost:
                d[b]=-INF
    return d
d=bellmanford(1,n)
if d[n]==-INF:
    print(-1)
elif d[n]>=0:
    print(0)
else:
    print(-d[n])
Problem p03220 (python)

Fixed submission:
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
b=1
c=abs(t-h[0]*0.006-a)
for i in range(n) :
  if(abs(t-h[i]*0.006-a)<c):
    b=i+1
    c=abs(t-h[i]*0.006-a)
  else:
    continue
print(b)

Buggy submission (verdict: Runtime Error):
n=int(input())
t,a=map(int,input().suplit())
h=list(input().suplit())
b=1
c=abs(t-h[0]*0.006-a)
for i in n :
  if(abs(t-h[i]*0.006-a)<c):
    b=i+1
    c=abs(t-h[i]*0.006-a)
  else:
    continue
print(b)
Problem p03227 (python)

Fixed submission:
s=input()
if(len(s)==2):
 print(s)
else:
 print(s[-1::-1])

Buggy submission (verdict: Runtime Error):
a, b, c= (int(i) for i in input().split())
for i in range(c):
 if(i%2==0):
  a=a//2
  b=b+a
 else:
  b=b//2
  a=a+b
print(a,b)

Buggy submission (verdict: Runtime Error):
a, b, c= (int(i) for i in input().split())
for i in range(c):
 if(i%2==0):
  a=a//2
  b=b+a//2
 else:
  b=b//2
  a=a+b//2
print(a,b)

Buggy submission (verdict: Runtime Error):
a, b, c = (int(i) for i in input().split()) 
for i in range(c):
 if(i%2==0):
  a=a//2
  b=b+a//2
 else:
  b=b//2
  a=a+b//2
print(a,b)
Problem p03228 (python)

Fixed submission:
a, b, c= (int(i) for i in input().split())
for i in range(c):
 if(i%2==0):
  a=a//2
  b=b+a
 else:
  b=b//2
  a=a+b
print(a,b)

Buggy submission (verdict: Runtime Error):
a, b, c = (int(i) for i in input().split()) 
for i in range(c)
 if(i%2==0):
  a=a//2
  b=b+a//2
 else:
  b=b//2
  a=a+b//2
print(a,b)
Problem p03312 (python)

Fixed submission:
n=int(input())
l=[0]+list(map(int,input().split()))
from itertools import accumulate
l=list(accumulate(l))
from bisect import bisect, bisect_left, bisect_right
ans=10**15
for i in range(2,n-1):
    x=bisect_left(l,l[i]//2)
    p1=l[x]
    p2=l[x-1]
    if abs(l[i]-p1*2)>=abs(l[i]-p2*2):
        p=p2
    else:
        p=p1
    q=l[i]-p
    x=bisect_left(l,(l[n]-l[i])//2+l[i])
    r1=l[x]-l[i]
    r2=l[x-1]-l[i]
    if abs(l[n]-l[i]-r1*2)>=abs(l[n]-l[i]-r2*2):
        r=r2
    else:
        r=r1
    s=l[n]-l[i]-r
    ans=min(ans,max(p,q,r,s)-min(p,q,r,s))
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=[0]+list(map(int,input().split()))
from itertools import accumulate
l=list(accumulate(l))
from bisect import bisect, bisect_left, bisect_right
ans=10**15
for i in range(2,n-1):
  	x=bisect_left(l,l[i]//2)
    p1=l[x]
    p2=l[x-1]
    if abs(l[i]-p1*2)>=abs(l[i]-p2*2):
        p=p2
    else:
        p=p1
    q=l[i]-p
    x=bisect_left(l,(l[n]-l[i])//2+l[i])
    r1=l[x]-l[i]
    r2=l[x-1]-l[i]
    if abs(l[n]-l[i]-r1*2)>=abs(l[n]-l[i]-r2*2):
        r=r2
    else:
        r=r1
    s=l[n]-l[i]-r
    ans=min(ans,max(p,q,r,s)-min(p,q,r,s))
print(ans)
Problem p03339 (python)

Fixed submission:
n=int(input())
s=input()
w=0
e=0
ans=1
for i in s:
  if(i=="W"):
    ans=min(ans,-e+w)
    w+=1
  else:
    e+=1
    ans=min(ans,-e+w)
print(ans+e)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
w=0
e=0
ans=0
for i in s:
  if(i="W"):
    ans=min(ans,ans-e+w)
    w+=1
  else:
    e+=1
    ans=min(ans,ans-e+w)
print(ans+e)
Problem p03347 (python)

Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
l=[int(input()) for i in range(n)]
if l[0]!=0:
    print(-1)
    quit()
l.reverse()
l+=[0]
ans=0
i=0
while i<n-1:
    if l[i]>n-i-1:
        print(-1)
        quit()
    if l[i+1]+1==l[i]:
        ans+=l[i]
        while l[i+1]+1==l[i]:
            i+=1
        i+=1
    elif l[i+1]+1<l[i]:
        print(-1)
        quit()
    else:
        ans+=l[i]
        i+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n=int(input())
l=[int(input()) for i in range(n)]
if l[0]!=0:
    print(-1)
    quit()
l.reverse()
ans=0
i=0
while i<n-2:
    if l[i]>n-i-1:
        print(-1)
        quit()
    if l[i+1]+1==l[i]:
        ans+=l[i]
        while l[i+1]+1==l[i]:
            i+=1
    elif l[i+1]+1<l[i]:
        print(-1)
        quit()
    else:
        ans+=l[i]
        i+=1
print(ans)
Problem p03363 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
s=0
dic={}
for i in a:
  s+=i
  dic[s]=dic.get(s,0)+1
  ans+=dic[s]
  if s!=0:
      ans-=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=0
s=0
dic={}
for i in a:
  s+=i
  dic.get(s,0)+=1
  ans+=dic[s]-s!=0
print(ans)
Problem p03393 (python)

Fixed submission:
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    quit()
elif len(s)<26:
    d=set([i for i in range(26)])
    for i in s:
        d.remove(ord(i)-97)
    print(s+chr(min(d)+97))
else:
    d=[ord(s[-1])]
    for i in range(25):
        c=s[-2-i]
        if max(d)<ord(c):
            d.append(ord(c))
        else:
            print(s[:26-2-i]+chr(min([i for i in d if i>ord(c)])))
            break

Buggy submission (verdict: Runtime Error):
s=input()
a="abcdefghijklmnopqrstuvwxyz"
if(s==a[::-1]):
    print(-1)
else:
    if(len(s)==26):
        c=s[-1]
        i=2
        while 1:
            if(s[-i]<c):
                print(s[:26-i]+c)
                break
            else:
                i+=1
    else:
        for i in a:
            if(not i in s):
                print(s+i)
                break

Buggy submission (verdict: Runtime Error):
s=input()
a="abcdefghijklmnopqrstuvwxyz"
if(s==a[::-1]):
    print(-1)
else:
    if(len(s)==26):
        c=s[-1]
        i=2
        while 1:
            if(s[-i]<c):
                print(s[:26-i]+c)
                break
            else:
                i+=1
    else:
        for i in a:
            if(not i in s):
                print(s+i)
                break
Problem p03504 (python)

Fixed submission:
n,C=map(int,input().split())
import collections
d=collections.defaultdict(list)
for i in range(n):
    s,t,c=map(int,input().split())
    d[c].append((s,t))
T=[0 for i in range(2*10**5+3)]
for i in d.values():
    i.sort()
    T[i[0][0]*2-1]+=1
    T[i[-1][1]*2+1]-=1
    for x,y in zip(i,i[1:]):
        s1,t1=x
        s2,t2=y
        if t1!=s2:
            T[s2*2-1]+=1
            T[t1*2+1]-=1
from itertools import accumulate
T=list(accumulate(T))
print(max(T))

Buggy submission (verdict: Runtime Error):
n,C=map(int,input().split())
import collections
d=collections.defaultdict(list)
for i in range(n):
    s,t,c=map(int,input().split())
    d[c].append((s,t))
T=[0 for i in range(2*10**5+1)]
for i in d.values():
    i.sort()
    T[i[0][0]*2-1]+=1
    T[i[-1][1]*2+1]-=1
    for x,y in zip(i,i[1:]):
        s1,t1=x
        s2,t2=y
        if t1!=s2:
            T[s2*2-1]+=1
            T[t1*2+1]-=1
from itertools import accumulate
T=list(accumulate(T))
print(max(T))
Problem p03533 (python)

Fixed submission:
s=input()
if(len(s)>9):
    print("NO")
    quit()
i=0
for c in "AKIHABAR":
    if(len(s)==i):
      print("NO")
      quit()
    if(s[i]==c):
        i+=1
    else:
        if(c!="A"):
            print("NO")
            quit()
print("YES")

Buggy submission (verdict: Runtime Error):
s=input()
if(len(s)>9):
    print("NO")
    quit()
i=0
for c in "AKIHABAR":
    if(s[i]==c):
        i+=1
    else:
        if(c=="A"):
            continue
        else:
            print("NO")
            quit()
print("YES")