Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))



char v[]="AKIHABARA@";

char s[100];

int main(void){
	scanf("%s",s);
	int ls=strlen(s);
	int t=0;
	
	rep(i,ls){
		if(v[t]==s[i])t++;
		else if(v[t]=='A' && s[i]==v[t+1]){
			t+=2;
		}
		else{
			puts("NO");
			return 0;
		}
	}
	
	//printf("%c\n",v[t]);
	puts((v[t]=='@' || t==8)?"YES":"NO");
	return 0;
}






Fixed submission:
import re

s = raw_input()


x = re.compile('A?KIHA?BA?RA?$')


#print x.match(s)

if x.match(s):
	print 'YES'
else:
	print 'NO'
Buggy python submission (verdict: Time Limit Exceeded):
n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  if n-1:
    while v!=w:
      if v>w:v,w=w,v
      w=(w+n-2)//n
  print(v)

Fixed submission:
n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  if n<2:
    print(min(v,w))
    continue
  s,t=set(),set()
  while v:
    s|={v}
    v=(v+n-2)//n
  while w:
    t|={w}
    w=(w+n-2)//n
  print(max(s&t))

Buggy python submission (verdict: Time Limit Exceeded):
n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  while n>1and v!=w:
    v,w=sorted((v,w))
    w=(w+n-2)//n
  print(v)

Fixed submission:
n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  if n<2:
    print(min(v,w))
    continue
  s,t=set(),set()
  while v:
    s|={v}
    v=(v+n-2)//n
  while w:
    t|={w}
    w=(w+n-2)//n
  print(max(s&t))

Buggy python submission (verdict: Time Limit Exceeded):
n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  while n>1and v!=w:
    if v>w:v,w=w,v
    w=(w+n-2)//n
  print(v)

Fixed submission:
n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  if n<2:
    print(min(v,w))
    continue
  s,t=set(),set()
  while v:
    s|={v}
    v=(v+n-2)//n
  while w:
    t|={w}
    w=(w+n-2)//n
  print(max(s&t))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,q,*t=map(int,open(0).read().split())
  for v,w in zip(t[::2],t[1::2]):
    if n<2:
      print(min(v,w))
      continue
    s,t,v,w=[],[],[v],[w]
    for i in v:
      s.append(i)
      a=(i+n-2)//n
      if a:v.append(a)
    for j in w:
      t.append(j)
      b=(j+n-2)//n
      if b:w.append(b)
    print(max(set(s)&set(t)))
if __name__=='__main__':
  main()

Fixed submission:
n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  if n<2:
    print(min(v,w))
    continue
  s,t=set(),set()
  while v:
    s|={v}
    v=(v+n-2)//n
  while w:
    t|={w}
    w=(w+n-2)//n
  print(max(s&t))

Buggy python submission (verdict: Time Limit Exceeded):
n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  if n<2:
    print(min(v,w))
    continue
  s,t=set(),set()
  while v:
    s|={v}
    v=(v+n-2)//n
  while w:
    t|={w}
    w=(w+n-2)//n
  print(max(s&t))

Fixed submission:
n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  if n<2:
    print(min(v,w))
    continue
  s,t=set(),set()
  while v:
    s|={v}
    v=(v+n-2)//n
  while w:
    t|={w}
    w=(w+n-2)//n
  print(max(s&t))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,k,*t=map(int,open(0).read().split())
  *z,=zip(*[iter(t)]*2)
  ok=10**19
  ng=-1
  while ok-ng>1:
    mid=(ok+ng)//2
    if sum(max(0,0--(mid-w)//d)for w,d in z)<k:ng=mid
    else:ok=mid
  print(ng)
main()

Fixed submission:
n,k,*t=map(int,open(0).read().split())
*z,=zip(*[iter(t)]*2)
ok=10**20
ng=-1
while ok-ng>1:
  mid=(ok+ng)//2
  if sum(max(0,0--(mid-w)//d)for w,d in z)<k:ng=mid
  else:ok=mid
print(ng)

Buggy python submission (verdict: Time Limit Exceeded):
n,k,*t=map(int,open(0).read().split())
*z,=zip(*[iter(t)]*2)
ok=10**20
ng=-1
while ok-ng>1:
  mid=(ok+ng)//2
  if sum(max(0,0--(mid-w)//d)for w,d in z)<k:ng=mid
  else:ok=mid
print(ng)

Fixed submission:
n,k,*t=map(int,open(0).read().split())
*z,=zip(*[iter(t)]*2)
ok=10**20
ng=-1
while ok-ng>1:
  mid=(ok+ng)//2
  if sum(max(0,0--(mid-w)//d)for w,d in z)<k:ng=mid
  else:ok=mid
print(ng)

Buggy python submission (verdict: Time Limit Exceeded):
n,k,*t=map(int,open(0).read().split())
*z,=zip(*[iter(t)]*2)
ok=10**30
ng=-1
while ok-ng>1:
  mid=(ok+ng)//2
  if sum(max(0,0--(mid-w)//d)for w,d in z)<k:ng=mid
  else:ok=mid
print(ng)

Fixed submission:
n,k,*t=map(int,open(0).read().split())
*z,=zip(*[iter(t)]*2)
ok=10**20
ng=-1
while ok-ng>1:
  mid=(ok+ng)//2
  if sum(max(0,0--(mid-w)//d)for w,d in z)<k:ng=mid
  else:ok=mid
print(ng)

Buggy python submission (verdict: Time Limit Exceeded):
n,k,*t=map(int,open(0).read().split())
ok=10**30
ng=-1
while ok-ng>1:
  mid=(ok+ng)//2
  if sum(max(0,0--(mid-w)//d)for w,d in zip(*[iter(t)]*2))<k:ng=mid
  else:ok=mid
print(ng)

Fixed submission:
n,k,*t=map(int,open(0).read().split())
*z,=zip(*[iter(t)]*2)
ok=10**20
ng=-1
while ok-ng>1:
  mid=(ok+ng)//2
  if sum(max(0,0--(mid-w)//d)for w,d in z)<k:ng=mid
  else:ok=mid
print(ng)
Buggy python submission (verdict: Runtime Error):
from scipy.sparse import*
(n,m),*t=[map(int,t.split())for t in open(0)]
*b,a=zip(*[(i,j+n,1)for i,(_,*t)in enumerate(t)for j in t])
print('YNEOS'[1in csgraph.connected_components(csr_matrix((a,b),[n*m]*2))[1][:n]::2])

Fixed submission:
from scipy.sparse import*
(n,m),*p=[map(int,t.split())for t in open(0)]
a,b,c=zip(*[(i,j+n-1,1)for i,q in enumerate(p)for j in list(q)[1:]])
print('YNEOS'[1in csgraph.connected_components(csr_matrix(((c,(a,b))),[n+m]*2))[1][:n]::2])

Buggy python submission (verdict: Runtime Error):
from scipy.sparse import*
(n,m),*t=[map(int,t.split())for t in open(0)]
*b,a=zip(*[(i,j+n,1)for i,(_,*t)in enumerate(t)for j in t])
print('YNEOS'[1in csgraph.connected_components(csr_matrix((a,b),[n*9]*2))[1][:n]::2])

Fixed submission:
from scipy.sparse import*
(n,m),*p=[map(int,t.split())for t in open(0)]
a,b,c=zip(*[(i,j+n-1,1)for i,q in enumerate(p)for j in list(q)[1:]])
print('YNEOS'[1in csgraph.connected_components(csr_matrix(((c,(a,b))),[n+m]*2))[1][:n]::2])

Buggy python submission (verdict: Runtime Error):
from scipy.sparse import*
(n,m),*t=[map(int,t.split())for t in open(0)]
*b,a=zip(*[(i,j+n,1)for i,(_,*t)in enumerate(t)for j in t])
print('YNEOS'[1in csgraph.connected_components(csr_matrix((a,b),[m*9]*2))[1][:n]::2])

Fixed submission:
from scipy.sparse import*
(n,m),*p=[map(int,t.split())for t in open(0)]
a,b,c=zip(*[(i,j+n-1,1)for i,q in enumerate(p)for j in list(q)[1:]])
print('YNEOS'[1in csgraph.connected_components(csr_matrix(((c,(a,b))),[n+m]*2))[1][:n]::2])

Buggy python submission (verdict: Runtime Error):
from scipy.sparse import*
(n,m),*t=[map(int,t.split())for t in open(0)]
*b,a=zip(*[(i,j+n,1)for i,(_,*t)in enumerate(t)for j in t])
print('YNEOS'[1in csgraph.connected_components(csr_matrix((a,b),[m*3]*2))[1][:n]::2])

Fixed submission:
from scipy.sparse import*
(n,m),*p=[map(int,t.split())for t in open(0)]
a,b,c=zip(*[(i,j+n-1,1)for i,q in enumerate(p)for j in list(q)[1:]])
print('YNEOS'[1in csgraph.connected_components(csr_matrix(((c,(a,b))),[n+m]*2))[1][:n]::2])

Buggy python submission (verdict: Runtime Error):
from scipy.sparse import*
(n,m),*t=[map(int,t.split())for t in open(0)]
*b,a=zip(*[(i,j+n,1)for i,(_,*t)in enumerate(t)for j in t])
print('YNEOS'[1in csgraph.connected_components(csr_matrix((a,b),[n*3]*2))[1][:n]::2])

Fixed submission:
from scipy.sparse import*
(n,m),*p=[map(int,t.split())for t in open(0)]
a,b,c=zip(*[(i,j+n-1,1)for i,q in enumerate(p)for j in list(q)[1:]])
print('YNEOS'[1in csgraph.connected_components(csr_matrix(((c,(a,b))),[n+m]*2))[1][:n]::2])

Buggy python submission (verdict: Runtime Error):
from scipy.sparse import*;(n,m),*t=[map(int,t.split())for t in open(0)];*b,a=zip(*[(i,j+n-1,1)for i,(_,*t)in enumerate(t)for j in t]);print("YNEOS"[1in csgraph.connected_components(csr_matrix(((a,t)),[n+m]*2))[1][:n]::2])

Fixed submission:
from scipy.sparse import*
(n,m),*p=[map(int,t.split())for t in open(0)]
a,b,c=zip(*[(i,j+n-1,1)for i,q in enumerate(p)for j in list(q)[1:]])
print('YNEOS'[1in csgraph.connected_components(csr_matrix(((c,(a,b))),[n+m]*2))[1][:n]::2])
Buggy python submission (verdict: Runtime Error):
import numpy as np

H, W = map(int, raw_input().split())
S_list = list()
for i in range(H):
    S_list.append(raw_input())


X_mat = np.zeros((H, W), dtype='int')
S_mat_extend = np.zeros((H+2, W+2), dtype='int')
# input
for h in range(H):
    for w in range(W):
        if S_list[h][w] == 'X':
            X_mat[h, w] += 1

# make graph
G = dict()
def add_node(s, Graph=G):
    Graph[s] = {'edges':dict()}
    
def add_edge(s, t, weight=1, Graph=G):
    Graph[s]['edges'][t] = weight

def max_flow(s, t, Graph=G):
    G_ = Graph
    flow = 0
    
    while True:
        # initialize
        for v in G_.keys():
            G_[v]['reach'] = -1
            G_[v]['path'] = ''
        G_[s]['reach'] = 1
        # bfs
        ques = [s]
        while len(ques) > 0:
            v = ques.pop()
            for d in G_[v]['edges'].keys():
                if G_[v]['edges'][d] > 0 and G_[d]['reach'] == -1:
                    # update
                    G_[d]['reach'] = 1
                    G_[d]['path'] = v
                    ques.append(d)
                    if d == t:
                        flow += 1
                        break

        if G_[t]['path'] != '':
            y = t
            while True:
                x = G_[y]['path']
                G_[x]['edges'][y] -= 1
                if x not in Graph[y]['edges'].keys():
                    add_edge(y, x, weight=0, Graph=G_)
                G_[y]['edges'][x] += 1
                if x == s:
                    break
                else:
                    y = x
        else:
            break
    
    return flow


# src:sheeps
# dst:outer
add_node('src')
add_node('dst')

# grid
for i in range(H):
    for j in range(W):
        add_node(str([i, j]) + '-src')
        add_node(str([i, j]) + '-dst')
        add_edge(str([i, j]) + '-dst', str([i, j]) + '-src')
        if X_mat[i, j] == 1:
            add_edge('src', str([i, j]) + '-dst', 100000)
            add_edge(str([i, j]) + '-dst', str([i, j]) + '-src', 100000)
        if i > 0:
            add_edge(str([i, j]) + '-src', str([i-1, j]) + '-dst')
        if i < H-1:
            add_edge(str([i, j]) + '-src', str([i+1, j]) + '-dst')
        if j > 0:
            add_edge(str([i, j]) + '-src', str([i, j-1]) + '-dst')
        if j < W-1:
            add_edge(str([i, j]) + '-src', str([i, j+1]) + '-dst')
        if i == 0 or j == 0 or i == H-1 or j == W-1:
            add_edge(str([i, j]) + '-src', 'dst', 100000)

res = 0
# find -1
if X_mat[0,:].sum() + X_mat[H-1,:].sum() + X_mat[:,0].sum() + X_mat[:,W-1].sum() > 0:
    res = -1
else:
    res = max_flow('src', 'dst')


print res

Fixed submission:
N, A, B = map(int, raw_input().split())
t_list = list()
for i in range(N):
    t_list.append(int(raw_input()))

res = len(t_list) - len([t for t in t_list if t >= A and t < B])

print res
Buggy python submission (verdict: Time Limit Exceeded):
T = int(input())
for _ in range(T):
    N,D = map(int,input().split())
    cookie = [D]
    while len(cookie)<N:
        cookie.sort()
        cookie = cookie[1:] + [127-cookie[0],127]
    print(sum(cookie))

Fixed submission:
T = int(input())
for _ in range(T):
    N,D = map(int,input().split())
    if N%2==0:
        print(N*127-D)
    else:
        print((N-1)*127+D)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
flush = sys.stdout.flush
write = sys.stdout.write

N = int(input())

bb_1,bb_2 = "..##",".#.#"
res_1,res_2 = "",""

def ask(s1,s2):
    write(res_1)
    write(res_2)
    result = input()
    flush()
    if result=="end":
        exit()
    return result=="T"

# 右側に伸ばしていく
while 1:
    for i in range(4):
        if ask(res_1+bb_1[i],res_2+bb_2[i]):
            res_1 += bb_1[i]
            res_2 += bb_2[i]
            break
    else:
        break

# 左側に伸ばしていく
while 1:
    for i in range(4):
        if ask(bb_1[i]+res_1,bb_2[i]+res_2):
            res_1 = bb_1[i] + res_1
            res_2 = bb_2[i] + res_2
            break
    else:
        break


Fixed submission:
import sys
flush = sys.stdout.flush
write = sys.stdout.write

N = int(input())

bb_1,bb_2 = "..##",".#.#"
res_1,res_2 = "",""

def ask(s1,s2):
    write(s1+'\n'+s2+'\n')
    result = input()
    flush()
    if result=="end":
        exit()
    return result=="T"

# 右側に伸ばしていく
while 1:
    for i in range(4):
        if ask(res_1+bb_1[i],res_2+bb_2[i]):
            res_1 += bb_1[i]
            res_2 += bb_2[i]
            break
    else:
        break

# 左側に伸ばしていく
while 1:
    for i in range(4):
        if ask(bb_1[i]+res_1,bb_2[i]+res_2):
            res_1 = bb_1[i] + res_1
            res_2 = bb_2[i] + res_2
            break
    else:
        break
Buggy python submission (verdict: Runtime Error):
i=0
while i<len(s):
  k=0
  while s[i]=='<' if i<len(s) else False:
    k+=1
    i+=1
  if k>0:
    l.append(k)
  k=0
  while s[i]=='>' if i<len(s) else False:
    k+=1
    i+=1
sm=0
for i in l:
  sm+=(i*(i+1))//2
  
print(sm)

Fixed submission:
s=input()
l=[]
i=0
while i<len(s):
  k=0
  while s[i]=='<' if i<len(s) else False:
    k+=1
    i+=1
  if k>0:
    l.append(k)
  k=0
  while s[i]=='>' if i<len(s) else False:
    k+=1
    i+=1
  if k>0:
    l.append(k)
sm=0
for i in l:
  sm+=(i*(i+1))//2
for i in range(0 if s[0]=='<' else 1,len(l)-1,2):
  sm-=min(l[i],l[i+1])
 
  
print(sm)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input())
print(A + B if B % A == 0 else B - A)

Fixed submission:
A, B = map(int, input().split())
print(A + B if B % A == 0 else B - A)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

all_set = set.intersection(*map(set, (
  list(map(int, input().split()))[1:]
  for i in range(N)
))

print(len(all_set))

Fixed submission:
N, M = map(int, input().split())
 
all_set = set.intersection(*map(set, (
  list(map(int, input().split()))[1:]
  for i in range(N)
)))
 
print(len(all_set))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
numbers = set(map(int, input().split()))
costs = [2,5,5,4,5,6,3,7,6] # <- 1,2,3,4,5,6,7,8,9
costmap = {}
for num in numbers:
  cost = costs[num-1]
  if cost in costmap and num < costmap[cost]:
    continue
  costmap[cost] = num

from functools import lru_cache
@lru_cache(None)
def recursive(remain=N):
  maxval = costmap[remain] if remain in costmap else 0
  for cost, num in costmap.items():
    if remain > cost:
      val = recursive(remain-cost)
      if val is None:
        continue
      val = val * 10 + num
      if val > maxval:
        maxval = val
  if maxval == 0:
    return None
  return maxval

print(recursive(N))

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N, M = map(int, input().split())
numbers = list(map(int, input().split()))
costs = [2,5,5,4,5,6,3,7,6] # <- 1,2,3,4,5,6,7,8,9
costmap = {}
for num in numbers:
  cost = costs[num-1]
  if cost in costmap and num < costmap[cost]:
    continue
  costmap[cost] = num

from functools import lru_cache
@lru_cache(None)
def recursive(remain=N):
  maxval = costmap[remain] if remain in costmap else 0
  for cost, num in costmap.items():
    if remain > cost:
      val = recursive(remain-cost)
      if val == 0:
        continue
      val = val * 10 + num
      if val > maxval:
        maxval = val
  return maxval
 
print(recursive(N))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
numbers = set(map(int, input().split()))
costs = [2,5,5,4,5,6,3,7,6] # <- 1,2,3,4,5,6,7,8,9
costmap = {}
for num in numbers:
  cost = costs[num-1]
  if cost in costmap and num < costmap[cost]:
    continue
  costmap[cost] = num

def recursive(remain=N):
  maxval = costmap[remain] if remain in costmap else 0
  for cost, num in costmap.items():
    if remain > cost:
      val = recursive(remain-cost)
      if val is None:
        continue
      val = val * 10 + num
      if val > maxval:
        maxval = val
  if maxval == 0:
    return None
  return maxval

print(recursive(N))

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N, M = map(int, input().split())
numbers = list(map(int, input().split()))
costs = [2,5,5,4,5,6,3,7,6] # <- 1,2,3,4,5,6,7,8,9
costmap = {}
for num in numbers:
  cost = costs[num-1]
  if cost in costmap and num < costmap[cost]:
    continue
  costmap[cost] = num

from functools import lru_cache
@lru_cache(None)
def recursive(remain=N):
  maxval = costmap[remain] if remain in costmap else 0
  for cost, num in costmap.items():
    if remain > cost:
      val = recursive(remain-cost)
      if val == 0:
        continue
      val = val * 10 + num
      if val > maxval:
        maxval = val
  return maxval
 
print(recursive(N))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools

readInt = lambda : [int(i) for i in input().split()];
n = readInt()[0]
A = readInt()

B = list(itertools.accumulate(A))

cand = []
for i in range(2, len(A)-1):
  B0 = B[0:i]
  B1 = [x - B[i-1] for x in B[i:len(A)]]
  s = B0[-1] // 2
  for j in range(1, len(B0)):
    if (B0[j] > s):
      c0 = abs(2 * B0[j-1] - B0[-1])
      c1 = abs(2 * B0[j] - B0[-1])
      j0 = j-1 if c0 < c1 else j
      break

  s = B1[-1] // 2
  for j in range(1, len(B1)):
    if (B1[j] > s):
      c0 = abs(2 * B1[j-1] - B1[-1])
      c1 = abs(2 * B1[j] - B1[-1])
      j1 = j-1 if c0 < c1 else j
      break

  c = [B0[j0], B0[-1] - B0[j0], B1[j1], B1[-1] - B1[j1]]
  cand.append(max(c) - min(c))

ans = min(cand)
print(ans)

Fixed submission:
import sys
import itertools
import bisect

readInt = lambda : [int(i) for i in input().split()];
n = readInt()[0]
A = readInt()

B = list(itertools.accumulate(A))

cand = 2 * pow(10, 14)
for i in range(2, len(A)-1):
  z = B[i-1]
  s = z // 2
  j = bisect.bisect_right(B, s)
  if (j == 0):
    j0 = j
  else:
    c0 = abs(2 * B[j-1] - z)
    c1 = abs(2 * B[j] - z)
    j0 = j-1 if c0 < c1 else j

  z = B[-1]
  s = B[i-1] + (B[-1] - B[i-1]) // 2
  j = bisect.bisect_right(B, s)
  if (j == i):
    j1 = j
  else:
    c0 = abs(B[j-1] - B[i-1] - (B[-1] - B[j-1]))
    c1 = abs(B[j]   - B[i-1] - (B[-1] - B[j]  ))
    j1 = j-1 if c0 < c1 else j

  c = [B[j0], B[i-1] - B[j0], B[j1] - B[i-1], B[-1] - B[j1]]
  cand = min(cand, max(c) - min(c))

ans = cand
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools

readInt = lambda : [int(i) for i in input().split()];
n = readInt()[0]
A = readInt()

B = list(itertools.accumulate(A))

cand = []
for i in range(2, len(A)-1):
  B0 = B[0:i]
  B1 = [x - B[i-1] for x in B[i:len(A)]]
  D0 = [abs(2 * x - B0[-1]) for x in B0]
  D1 = [abs(2 * x - B1[-1]) for x in B1]
  j0 = D0.index(min(D0))
  j1 = D1.index(min(D1))
  c = [B0[j0], B0[-1] - B0[j0], B1[j1], B1[-1] - B1[j1]]
  cand.append(max(c) - min(c))

ans = min(cand)
print(ans)

Fixed submission:
import sys
import itertools
import bisect

readInt = lambda : [int(i) for i in input().split()];
n = readInt()[0]
A = readInt()

B = list(itertools.accumulate(A))

cand = 2 * pow(10, 14)
for i in range(2, len(A)-1):
  z = B[i-1]
  s = z // 2
  j = bisect.bisect_right(B, s)
  if (j == 0):
    j0 = j
  else:
    c0 = abs(2 * B[j-1] - z)
    c1 = abs(2 * B[j] - z)
    j0 = j-1 if c0 < c1 else j

  z = B[-1]
  s = B[i-1] + (B[-1] - B[i-1]) // 2
  j = bisect.bisect_right(B, s)
  if (j == i):
    j1 = j
  else:
    c0 = abs(B[j-1] - B[i-1] - (B[-1] - B[j-1]))
    c1 = abs(B[j]   - B[i-1] - (B[-1] - B[j]  ))
    j1 = j-1 if c0 < c1 else j

  c = [B[j0], B[i-1] - B[j0], B[j1] - B[i-1], B[-1] - B[j1]]
  cand = min(cand, max(c) - min(c))

ans = cand
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()

list=[0 for _ in range(len(s) + 1)]

def inc(n):
    if n < 0 or len(s) < n + 1:
        return

    if '<' == s[n]:
        if list[n] >= list[n + 1]:
            list[n + 1] += list[n] - list[n + 1] + 1
            inc(n + 1)

    elif '>' == s[n]:
        if list[n] <= list[n + 1]:
            list[n] += list[n + 1] - list[n] + 1
            inc(n - 1)

for i in range(len(s)):
    inc(i)

print(sum(list))


Fixed submission:
s=input()

list=[0 for _ in range(len(s) + 1)]

def inc(n):
    if n < 0 or len(s) < n + 1:
        return
    if '<' == s[n]:
        if list[n] >= list[n + 1]:
            list[n + 1] += list[n] - list[n + 1] + 1
    elif '>' == s[n]:
        if list[n] <= list[n + 1]:
            list[n] += list[n + 1] - list[n] + 1

for i in range(0, len(s), 1):
    inc(i)

for i in range(len(s) - 1, -1, -1):
    inc(i)

print(sum(list))
Buggy python submission (verdict: Runtime Error):
import sys
S = input().strip()
keyence = "keyence"

for i in range(len(keyence)):
    if keyence[:i] in S:
        s = S.find(keyence[:i]) + i
        S2 = S[s:]
        if keyence[i:] in S2:
            print("YES")
            sys.exit()

print("NO")
~           

Fixed submission:
import sys
S = input().strip()
keyence = "keyence"
n = len(keyence)

if keyence in S:
    k = S.find(keyence)
    if k == 0:
        print("YES")
        sys.exit()
    elif k + n == len(S):
        print("YES")
        sys.exit()

for i in range(n):
    if S[:i] == keyence[:i] and S[-(n-i):] == keyence[-(n-i):]:
        print("YES")
        sys.exit()

print("NO")
Buggy python submission (verdict: Runtime Error):
S = input()
n = len(S)
ans = [0]*(n+1)
for i in range(n):
    if S[i]=='<':
        ans[i]=ans[i-1]+1
for i in range(n-1,-1,-1):
    if S[i]==">":
        ans[i]=ans[i+1]+1
res = 0
for i in range(n+1):
    res+=ans[i]
return res


Fixed submission:
S = input()
n = len(S)
ans = [0]*(n+1)
for i in range(n):
    if S[i]=='<':

        ans[i+1]=ans[i]+1
    # print(ans)
# print(ans)
for i in range(n-1,-1,-1):
    if S[i]==">":
        if ans[i]>ans[i+1]:
            continue
        else:
            ans[i]=ans[i+1]+1
    # print(ans)
res = 0
for i in range(n+1):
    res+=ans[i]
# print(ans)
print(res)
Buggy python submission (verdict: Runtime Error):
import math

a,b,x = map(int,input().split())

if a**2 * b < 2*x:
    print(90-math.degrees(math.atan((1/2*a**3)/(a**2*b-x))))
else:
    print(math.degrees(math.atan((1/2*a*b**2)/(x))))

Fixed submission:
import math

a,b,x = map(int,input().split())

if a**2*b == x:
    print(0)
elif a**2 * b < 2*x:
    print(90-math.degrees(math.atan((1/2*a**3)/(a**2*b-x))))
else:
    print(math.degrees(math.atan((1/2*a*b**2)/(x))))
Buggy python submission (verdict: Runtime Error):
N = int(input())
l = map(int,input().split())
l = sorted(l)
l_dict = dict()
max_l  = max(l)
min_l = min(l)
t_list = [one for one in l if one+min_l < max_l]
for i,one in enumerate(t_list):
    l_dict[one] = i
    
    
big_dict = dict()
for one in t_list:
    big_dict[one] = bisect.bisect_left(l,2*one)

counter = 0

for a,b in combinations(t_list,2):
    tmp = a + b
    counter += bisect.bisect_left(l[l_dict[b]+1:big_dict[b]],tmp)
    
print(counter)

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