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

Fixed submission:
n=int(input())
*h,=map(int, input().split())
import numpy as np
h=np.array(h)

def rec(hh):
    if len(hh)==0:
        return 0
    if len(hh)==1:
        return hh[0]
    i=np.argmin(hh)
    res=hh[i]
    l=rec(hh[:i]-hh[i])
    r=rec(hh[i+1:]-hh[i])
    return res+l+r
print(rec(h))

Buggy submission (verdict: Runtime Error):
#editorial参照
import sys
input = sys.stdin.read
n,*a, = map(int, input().split( ))
m = min(a)
ans = (n+m-1)//m + 4
print(ans)
Problem p03156 (python)

Fixed submission:
n=int(input())
a,b=map(int, input().split())
*p,=map(int, input().split())
mn,md,mx=0,0,0
for pi in p:
    if pi<=a:
        mn+=1
    elif pi<=b:
        md+=1
    else:
        mx+=1
print(min(mn,md,mx))

Buggy submission (verdict: Runtime Error):
n,a,b=map(int, input().split())
*p,=map(int, input().split())
mn,md,mx=0,0,0
for pi in p:
    if pi<=a:
        mn+=1
    elif pi<=b:
        md+=1
    else:
        mx+=1
print(min(mn,md,mx))
Problem p03160 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split( )))
dp =[0,0]

dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    ad0 = abs(h[i]-h[i-1])
    ad1 = abs(h[i]-h[i-2])
    dp.append(min(dp[i-1]+ad0,dp[i-2]+ad1))
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n,w_max = map(int,input().split())
w = [0]
v = [0]

for _ in range(n):
    W,V = map(int,input().split())
    w.append(W)
    v.append(V)
v_sum = sum(v)
lrg = 10**12
dp = [[lrg]*(v_sum+1) for i in range(n+1)]
for i in range(n+1):
    dp[i][0] = 0
for i in range(1,n+1):
    for u in range(v_sum+1):
        if u>=v[i]:
            dp[i][u] = min(dp[i-1][u-v[i]]+w[i],dp[i-1][u])
        else:###
            dp[i][u] = min(w[i],dp[i-1][u])

ans = []
for u in range(v_sum+1):
    if dp[n][u] <= w_max:
        ans.append(u)
#print(*dp[n])
print(max(ans))
Problem p03161 (python)

Fixed submission:
import sys
n,k = map(int,input().split( ))
if k>n:
    flag =1
else:
    flag =0
    
k = min(k,n)
h = list(map(int, input().split( )))
dp =[abs(h[i]-h[0]) for i in range(k)]
for i in range(2,k):
    tmp =[]
    for j in range(i+1):
        #tmp =[]
        #print(*dp)
        #print(dp[j])
        #print(*h)
        #print(h[i],h[j],i,j)
        tmp.append(dp[j]+abs(h[i]-h[j]))#こっちはdp[j],h[j]
    dp[i]= min(tmp)
if flag:
    print(dp[-1])
    sys.exit()
for i in range(k,n):
    tmp =[]
    for j in range(1,k+1):#+1
        tmp.append(dp[i-j]+abs(h[i]-h[i-j]))#こっちはdp[i-j],h[i-j]
    dp.append(min(tmp))
#print(*dp)
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split( ))
h = list(map(int, input().split( )))
dp =[abs(h[i]-h[0]) for i in range(k)]
for i in range(2,k):
    tmp =[]
    for j in range(i+1):
        #tmp =[]
        #print(*dp)
        #print(dp[j])
        #print(*h)
        #print(h[i],h[j],i,j)
        tmp.append(dp[j]+abs(h[i]-h[j]))#こっちはdp[j],h[j]
    dp[i]= min(tmp)
for i in range(k,n):
    tmp =[]
    for j in range(1,k+1):#+1
        tmp.append(dp[i-j]+abs(h[i]-h[i-j]))#こっちはdp[i-j],h[i-j]
    dp.append(min(tmp))
#print(*dp)
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split( ))
h = list(map(int, input().split( )))
dp =[abs(h[i]-h[0]) for i in range(k)]
for i in range(2,k):
    tmp =[]
    for j in range(i+1):
        #tmp =[]
        #print(*dp)
        #print(dp[j])
        #print(*h)
        #print(h[i],h[j],i,j)
        tmp.append(dp[j]+abs(h[i]-h[j]))#こっちはdp[j],h[j]
    dp[i]= min(tmp)
for i in range(k,n):
    tmp =[]
    for j in range(1,k+1):#+1
        tmp.append(dp[i-j]+abs(h[i]-h[i-j]))#こっちはdp[i-j],h[i-j]
    dp.append(min(tmp))
print(*dp)
print(dp[n-1])
Problem p03169 (python)

Fixed submission:
#http://compro.tsutajiro.com/archive/180220_probability_dp.pdf
import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split( )))
cnt =[0,0,0]
for i in range(n):
    cnt[3-a[i]] += 1
dp = [[[0 for _ in range(n+1)] for __ in range(n+1)] for ___ in range(n+1)]

dp[n][n][n] = 0
divT = [1/i for i in range(1,n+1)]

for x in range(n,cnt[1]+cnt[2]-1,-1):## -2だったのを-1に
    for y in range(x,cnt[2]-1,-1):##cnt[2]
        for z in range(y,-1,-1):
            delta = n*divT[n-z-1]#2枚以下を引くまで
            if x != n:
                dp[x][y][z] += (dp[x+1][y][z] + delta) * (n-x)
            if y != x:
                dp[x][y][z] += (dp[x][y+1][z] + delta) * (x-y)#x+1,y+1ではない
            if z != y:
                dp[x][y][z] += (dp[x][y][z+1] + delta)* (y-z)#x+1,y+1,z+1ではない
            dp[x][y][z] *=divT[n-z-1]

print(dp[cnt[1]+cnt[2]][cnt[2]][0])

Buggy submission (verdict: Runtime Error):
#http://compro.tsutajiro.com/archive/180220_probability_dp.pdf
import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split( )))
cnt =[0,0,0]
for i in range(n):
    cnt[3-a[i]] += 1

divT = [1/i for i in range(1,n+1)]

from functools import lru_cache### 
@lru_cache(100100100)

def f(x,y,z):
    if x==y==z==n:
        return 0
    res = 0
    delta = n*divT[n-z-1]
    if x != n:
        res += (f(x+1,y,z) + delta) * (n-x)
    if y != x:
        res += (f(x,y+1,z) + delta) * (x-y)#x+1,y+1ではない
    if z != y:
        res += (f(x,y,z+1) + delta)* (y-z)#x+1,y+1,z+1ではない
    res *=divT[n-z-1]
    return res
    

print(f(cnt[1]+cnt[2],cnt[2],0))

Buggy submission (verdict: Runtime Error):
#http://compro.tsutajiro.com/archive/180220_probability_dp.pdf
import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split( )))
cnt =[0,0,0]
for i in range(n):
    cnt[3-a[i]] += 1

divT = [1/i for i in range(1,n+1)]

from functools import lru_cache### これの練習
@lru_cache(100000)

def f(x,y,z):
    if x==y==z==n:
        return 0
    res = 0
    delta = n*divT[n-z-1]
    if x != n:
        res += (f(x+1,y,z) + delta) * (n-x)
    if y != x:
        res += (f(x,y+1,z) + delta) * (x-y)#x+1,y+1ではない
    if z != y:
        res += (f(x,y,z+1) + delta)* (y-z)#x+1,y+1,z+1ではない
    res *=divT[n-z-1]
    return res
    

print(f(cnt[1]+cnt[2],cnt[2],0))
Problem p03170 (python)

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

a = list(map(int, input().split( )))

dp = [0]*(k+1)

for i in range(k+1):
    win = 0
    for j in a:
        if i>=j and dp[i-j] == 0:
            win = 1
            break
    dp[i] = win
#print(*dp)            
if dp[k] == 1:
    print("First")
else:
    print("Second")

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

a = list(map(int, input().split( )))

dp = [0]*(k+1)

for i in range(k+1):
    win = 0
    for j in a:
        if i>=j and dp[i-j] == 0:
            win = 1
            break
    dp[i] = win
#print(*dp)            
if dp[k] == 1:
    print("First")
else:
    print("Second")
Problem p03274 (python)

Fixed submission:
##境界の処理が場当たり的すぎるが他を見てもコードの発想が理解できない
import bisect
n,k = map(int, input().split( ))
x = list(map(int, input().split( )))
inf = 10**15
x.append(inf)
start = bisect.bisect_left(x,0)

if x[start] == 0:
    k -= 1
    n -= 1
    x = [-inf]*k + x + [inf]*k###
else:
    x = [-inf]*k + x[:start] + [0] + x[start:] + [inf]*k###
#print(x)
ans = inf
start = bisect.bisect_left(x,0)
for i in range(k+1):###
    tmp1 = -x[start-i]
    tmp2 = x[start+k-i]
    #print(tmp1,tmp2)
    ans = min(ans, tmp1*2 + tmp2, tmp1 + tmp2*2)

print(ans)

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

start = bisect.bisect_left(x,0)
inf = 10**15
if x[start] == 0:
    k -= 1
    n -= 1
    x = [-inf]*k + x + [inf]*k###
else:
    x = [-inf]*k + x[:start] + [0] + x[start:] + [inf]*k###
#print(x)
ans = inf
start = bisect.bisect_left(x,0)
for i in range(k+1):###
    tmp1 = -x[start-i]
    tmp2 = x[start+k-i]
    #print(tmp1,tmp2)
    ans = min(ans, tmp1*2 + tmp2, tmp1 + tmp2*2)

print(ans)

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

start = bisect.bisect_left(x,0)

if x[start] == 0:
    k -= 1
    n -= 1
    #x = x[:start] + [0] + x[start+1:]
else:
    x = x[:start] + [0] + x[start:]
#print(x)
ans = 10**15

for i in range(start,start + k - n ,-1):###
    tmp1 = -x[start-i]
    tmp2 = x[start+k-i]
    #print(tmp1,tmp2)
    ans = min(ans, tmp1*2 + tmp2, tmp1 + tmp2*2)

print(ans)

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

start = bisect.bisect_left(x,0)

if x[start] == 0:
    k -= 1
    n -= 1
    #x = x[:start] + [0] + x[start+1:]
else:
    x = x[:start] + [0] + x[start:]
#print(x)
ans = 10**15

for i in range(start,start + k - n - 1 ,-1):
    tmp1 = -x[start-i]
    tmp2 = x[start+k-i]
    #print(tmp1,tmp2)
    ans = min(ans, tmp1*2 + tmp2, tmp1 + tmp2*2)

print(ans)
Problem p03277 (python)

Fixed submission:
n=int(input())
*a,=map(int, input().split())
def invr(x):
    if len(x)<=1:
        return x,0
    m=len(x)
    x1=x[:m//2]
    x2=x[m//2:]
    x11,res1=invr(x1)
    x22,res2=invr(x2)
    rx=[];res=res1+res2
    l=0;r=0
    while l<m//2 and r<m-(m//2):
        if x11[l]<=x22[r]:
            rx.append(x11[l])
            l+=1
        else:
            rx.append(x22[r])
            r+=1
            res+=m//2-l
    rx+=x11[l:]
    rx+=x22[r:]
    return rx,res

def f(m):
    a2=[(ai>=m)*2-1 for ai in a]
    a3=[0]
    for ai in a2:
        a3.append(a3[-1]+ai)
    _,r=invr(a3)
    return n*(n+1)//2-r>=((n+1)*n//2)//2



mx=max(a)+1;mn=min(a)
while mx-mn>1:
    md=(mx+mn)//2
    r=f(md)
    if r:
        mn=md
    else:
        mx=md
print(mn)

Buggy submission (verdict: Runtime Error):
n=int(input())
*a_,=map(int, input().split())
import numpy as np
a=np.array(a_)
def invr(x):
    if len(x)<=1:
        return x,0
    m=len(x)
    x1=x[:m//2]
    x2=x[m//2:]
    x11,r1=invr(x1)
    x22,r2=invr(x2)
    x11=x11[::-1]
    x22=x22[::-1]
    rx=[];r=r1+r2
    while x11 and x22:
        if x11[-1]<=x22[-1]:
            rx.append(x11.pop())
        else:
            rx.append(x22.pop())
            r+=len(x11)
    rx+=x11[::-1]
    rx+=x22[::-1]
    return rx,r

def f(m):
    a2=(a>=m)*2-1
    ac=np.cumsum(a2).tolist()
    _,r=invr([0]+ac)
    return n*(n+1)//2-r>=((n+1)*n//2)//2+1



mx=max(a)+1;mn=min(a)
while mx-mn>1:
    md=(mx+mn)//2
    r=f(md)
    if r:
        mn=md
    else:
        mx=md
print(mn)
Problem p03296 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split( )))
###連続区間に分ける

tmp = a[0]
tmp2 = 1
ans = 0
for i in range(1,n):
    if a[i]==tmp:
        tmp2 += 1
    else:
        tmp = a[i]
        ans += tmp2//2
        tmp2 = 1
ans += tmp2//2
print(ans)

Buggy submission (verdict: Runtime Error):

Enter a title here
Main.py 
Success  
  
        
出力
入力
コメント 0
(0.03 sec)
 
4
Problem p03343 (python)

Fixed submission:
n,k,q=map(int, input().split())
if q==1:
    print(0)
    exit()
*a,=map(int, input().split())
a+=[-1]
ans=10**10
for i in range(n):
    ai=a[i]
    tmp=[10**11]##15行目でtmp[:0]になるから
    tmp2=[ai]
    for j in range(n+1):
        if i==j:
            continue
        if a[j]<ai:
            tmp.sort()
            if len(tmp)>=k+1:
                tmp2+=tmp[:-k]
            tmp=[10**11]###
        else:
            tmp.append(a[j])
            #print("test",tmp)
    tmp2.sort()
#    print(tmp,tmp2)
    if len(tmp2)>=q:    
#        print("test2")
        ans=min(ans,tmp2[q-1]-ai)
print(ans)

Buggy submission (verdict: Runtime Error):
#解説参照
n,k,q=map(int, input().split())
*a,=map(int, input().split())
a+=[0]
ans=10**10
for i in range(n):
    ai=a[i]
    tmp=[10**10]##15行目でtmp[:0]になるから
    tmp2=[]
    for j in range(n+1):
        if i==j:
            continue
        if a[j]<ai:
            tmp.sort()
            if len(tmp)>=k+1:
                tmp2+=tmp[:-k]
            tmp=[]
        else:
            tmp.append(a[j])
            #print("test",tmp)
    tmp2.sort()
#    print(tmp,tmp2)
    if len(tmp2)>=q-1:    
#        print("test2")
        ans=min(ans,tmp2[q-2]-ai)
print(ans)
Problem p03386 (python)

Fixed submission:
a,b,k=map(int, input().split())
k=min(k,b-a+1)
*al,=range(a,a+k)
*al2,=range(b-k+1,b+1)
ans=al+al2
ans=list(set(ans))
ans.sort()
for i in ans:print(i)

Buggy submission (verdict: Runtime Error):
a,b,k=map(int, input().split())
k=min(k,b-a)
*al,=range(a,b+1)
ans=al[:k]+al[-k:]
ans=list(set(ans))
ans.sort()
for i in ans:print(i)
Problem p03389 (python)

Fixed submission:
#解説参照
a = list(map(int, input().split( )))
a.sort(reverse = True)
ans = 0
ans += a[0]-a[1]
a[1]+=ans
a[2] += ans
ans += (a[0]-a[2])//2
ans += ((a[0]-a[2])%2)*2###これ
print(ans)

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

a.sort(reverese = True)

ans = 0
ans += a[0]-a[1]
a[1]+=ans
a[2] += ans
ans += (a[0]-a[2]+1)//2
print(ans)

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

a.sort()

ans = 0
ans += a[0]-b[0]
a[1]+=ans
a[2] += ans
ans += (a[0]-a[2]+1)//2
print(ans)
Problem p03404 (python)

Fixed submission:
# editorial参照
# 格子まで詰め込もうとしたのが困難
# 十分大きい黒白の塊一つに孤立した白黒の点を取る


a,b = map(int, input().split( ))
k=50
W = [["."]*(k*2) for i in range(k)] 
B = [["#"]*(k*2) for i in range(k)]
for i in range(b-1):
    h = (i//k)*2
    w = (i%k)*2
    W[h][w]="#"



for i in range(a-1):
    h = (i//k)*2+1
    w = (i%k)*2+1
    B[-h][-w]="."
    
ans = [''.join(W[i]) for i in range(k)]+ [''.join(B[i]) for i in range(k)]
print(100,100)
print('\n'.join(ans))

Buggy submission (verdict: Runtime Error):
# editorial参照
# 格子まで詰め込もうとしたのが困難
# 十分大きい黒白の塊一つに孤立した白黒の点を取る


a,b = map(int, input().split( ))
k=10
W = [["."]*(k*2) for i in range(k)] 
B = [["#"]*(k*2) for i in range(k)]

for i in range(b-1):
    h = (i//k)*2
    w = (i%k)*2
    W[h][w-(h%2)]="#"



for i in range(a-1):
    h = (i//k)*2+1
    w = (i%k)*2+1
    B[-h][-w+(h%2)]="."
    
ans = [''.join(W[i]) for i in range(k)]+ [''.join(B[i]) for i in range(k)]

print('\n'.join(ans))
Problem p03479 (python)

Fixed submission:
x,y = map(int, input().split( ))
ans = 1

while x*2<=y:
    x*=2
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import math
x,y = map(int, input().split( ))
ans = int(math.log2(y/x))+1
print(ans)
Problem p03482 (python)

Fixed submission:
#解説参照
#隣接が異なる箇所を操作する必要がある
#max(i,n-i)の最小値がkの下限
#逆に上限であることは、異なる箇所から(右か左の)端までを反転させれば隣接が異なる箇所が減る

s = input()
ans = 10**6
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        ans = min(ans,max(i+1,len(s)-i-1))
if ans ==10**6:
    print(len(s))
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
prev = s[0]
cnt = 0

now_len = 1
len_sec = []
for i in range(1,len(s)):
  if prev == s[i]:
    now_len += 1
  else:
    len_sec.append(now_len)
    now_len = 1
  prev = s[i]
if len(len_sec)%2==0:
  mx = len_sec[0]+len_sec[1]
  for i in range(1,len(len_sec)-1):
    mx = max(mx, len_sec[i]+len_sec[i+1])
else:
  mx = max(len_sec)
print(mx)
Problem p03574 (python)

Fixed submission:

h,w=map(int, input().split( ))
s=[input() for _ in range(h)]
a = [-1,0,1]
b=[-1,0,1]
n=[(i,j) for i in a for j in b]
#print(n)
ans=[["#"]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        tmp=0
        if s[i][j]=="#":
            continue
        for x,y in n:
            if 0<=i+x<h and 0<=j+y<w:
                if (x or y) and s[i+x][j+y]=="#":
                    tmp+=1
        ans[i][j]=str(tmp)
for i in range(h):
    print(''.join(ans[i]))

Buggy submission (verdict: Runtime Error):
import numpy as np
h,w=map(int, input().split( ))
s=[input() for _ in range(h)]
a = [-1,0,1]
b=[-1,0,1]
n=[(i,j) for i in a for j in b]
#print(n)
ans=[["#"]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        tmp=0
        if s[i][j]=="#":
            continue
        for x,y in n:
            if 0<=i+x<h and 0<=j+y<w:
                if (x or y) and s[i+x][j+y]=="#":
                    tmp+=1
        ans[i][j]=str(tmp)
for i in range(h):
    print(''.join(ans[i]))
Problem p03599 (python)

Fixed submission:
a, b, c, d, e, f = map(int,input().split( ))
mx = 0
ans = [0,0]
for i in range(f//(a*100)+1):
    sup_b = f-i*a*100
    
    for j in range(sup_b//(b*100)+1):
        wat = i*a*100 + j*b*100
        
        if wat > f or not wat:
            continue
        sup_sug = min(e*(wat/100), f - wat)

        
        for k in range(int(sup_sug//c)+1):
            l = (sup_sug - k*c)//d
            
            if (k*c + l*d)/wat > e/100:
                continue
                
            if mx < (k*c + l*d)/wat:
                mx = (k*c + l*d)/wat
                ans = [(k*c + l*d) + wat, k*c + l*d]
if int(ans[0])==0 and int(ans[1])==0:
    print(100*a,0)
else:
    print(int(ans[0]),int(ans[1]))

Buggy submission (verdict: Runtime Error):
a, b, c, d, e, f = map(int,input().split( ))
mx = 0
ans = []
for i in range(f//(a*100)+1):
    sup_b = f-i*a*100
    
    for j in range(sup_b//(b*100)+1):
        wat = i*a*100 + j*b*100
        
        if wat > f or not wat:
            continue
        sup_sug = min(e*(wat/100), f - wat)

        
        for k in range(int(sup_sug//c)+1):
            l = (sup_sug - k*c)//d
            
            if (k*c + l*d)/wat > e/100:
                continue
                
            if mx < (k*c + l*d)/wat:
                mx = (k*c + l*d)/wat
                ans = [(k*c + l*d) + wat, k*c + l*d]

print(int(ans[0]),int(ans[1]))
Problem p03626 (python)

Fixed submission:
n = int(input())
s = input()+"0"
s2 = input()##要らない

i = 0

d = []#0が縦、1が横
while i<n:
    try:
        if s[i]==s[i+1]:
            d.append(1)
            i+=1
        else:
            d.append(0)
        i+=1
    except:
        break

ans = 1
#print(d)
if d[0]==0:
    ans = 3
else:
    ans = 6
mod = 10**9+7
for j in range(1,len(d)):
    if d[j]==0:
        if d[j-1]==0:
            ans*=2
    else:
        if d[j-1]==1:
            ans*=3
        else:
            ans*=2####
    ans%=mod
    

    
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
s2 = input()
if len(s)==2:
    print(3)
    exit()
i = 0

d = []#0が縦、1が横
while i<n:
    try:
        if s[i]==s[i+1]:
            d.append(1)
            i+=1
        else:
            d.append(0)
        i+=1
    except:
        break

ans = 1
#print(d)
if d[0]==0:
    ans = 3
else:
    ans = 6
mod = 10**9+7
for j in range(1,len(d)):
    if d[j]==0:
        if d[j-1]==0:
            ans*=2
    else:
        if d[j-1]==1:
            ans*=3
        else:
            ans*=2####
    ans%=mod
    

    
print(ans)
Problem p03633 (python)

Fixed submission:
import numpy as np
n=int(input())
a = list( int(input()) for _ in range(n))
#print(np.lcm.reduce(a1))
ans = 1
from fractions import gcd
for ai in a:
    ans = ans*ai//gcd(ans,ai)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a = list( int(input()) for _ in range(n))
#print(np.lcm.reduce(a1))
ans = 1
from math import gcd
for ai in a:
    ans = ans*ai//gcd(ans,ai)
print(ans)
Problem p03638 (python)

Fixed submission:
h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split( )))
ans = []

for i in range(n):
    for _ in range(a[i]):
        ans.append(i+1)
for i in range(h):
    if not i%2:
        print(*ans[w*i:w*i+w])
    else:
        print(*ans[w*i+w-1:w*i-1:-1])

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split( )))
ans = []

for i in range(n):
    for _ in range(a[i]):
        ans.append(i+1)
for i in range(h):
    for j in range(w):
        if i%2:
            print(ans[h*i+j], end = " ")
        else:
            print(ans[h*i+w-j-1],end = " ")
    print()

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split( )))
ans = []

for i in range(n):
    for _ in range(a[i]):
        ans.append(i+1)
for i in range(h):
    for j in range(w):
        if i%2:
            print(ans[h*i+j], end = " ")
        else:
            print(ans[h*i+w-j-1],end = " ")
    print()
Problem p03703 (python)

Fixed submission:
n,k=map(int,input().split())
a=[0]+[int(input())-k for _ in range(n)]
sm=0
ac=[]
for ai in a:
    sm+=ai
    ac.append(sm)


def rec(l):
    ll=len(l)
    if ll<=1:
        return 0
    l1=l[:ll//2]
    l2=l[ll//2:]
    res=rec(l1)+rec(l2)
    l1.sort()
    l2.sort()
    i2=0
    for i in range(len(l1)):
        while i2<len(l2) and l2[i2]<l1[i]:
            res+=len(l1)-i
            i2+=1
    return res
print(n*(n+1)//2-rec(ac))

Buggy submission (verdict: Runtime Error):
import numpy as np
n,k=map(int,input().split())
a=[0]+[int(input())-k for _ in range(n)]
ac=np.cumsum(a)
##BITは分からない
def rec(l):
    ll=len(l)
    if ll<=1:
        return 0
    l1=l[:ll//2]
    l2=l[ll//2:]
    res=rec(l1)+rec(l2)
    l1.sort()
    l2.sort()
    i2=0
    for i in range(len(l1)):
        while i2<len(l2) and l2[i2]<l1[i]:
            res+=len(l1)-i
            i2+=1
    return res
print(n*(n+1)//2-rec(ac))
Problem p03731 (python)

Fixed submission:
n,tt = map(int, input().split( ))
t = tuple(map(int, input().split( )))
ans  = 0
ti = 0;
for i in range(n):
    if t[i] >= ti+tt:
        ans += tt 
    else:
        ans += t[i] - ti
    ti = t[i]
print(ans+tt)##最後の分

Buggy submission (verdict: Runtime Error):
n,t = map(int, input().split( ))
t = tuple(map(int, input().split( )))
ans  = 0
ti = 0;
for i in range(n):
    if t[i] >= ti+t:
        ans += t 
    else:
        ans += t[i] - ti
    ti = t[i]
print(ans)
Problem p03800 (python)

Fixed submission:
#お手上げ、挙動追えない
import sys
n = int(input())
s = input()

L = ["SS","SW","WS","WW"]
l= len(s)
##0,1に置き換えたりしない
##条件分岐注意する
##ずらす必要はない?Lが固定するのはindexで-1,0?
for t in L:
    tmp = t###
    for i in range(l):
        if (s[i]=="x") ^ (tmp[-1] == "W"):
            if tmp[-2]=="S":
                tmp+= "W"
            else:
                tmp += "S"
            
        else:
            tmp += tmp[-2]
    if tmp[:2]==tmp[-2:]:
        print(tmp[1:-1])###
        sys.exit()
print(-1)

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
s = input()

L = ["SS","SW","WS","WW"]
l= len(s)
##0,1に置き換えたりしない
##条件分岐注意する
##ずらす必要はない、Lが固定するのはindexで-2,-1
for t in L:
  　tmp = t###
    for i in range(l):
        if (s[i]=="x") ^ (tmp[-1] == "W"):
            if tmp[-2]=="S":
                tmp+= "W"
            else:
                tmp += "S"
            
        else:
            tmp += tmp[-2]
    if tmp[:2]==tmp[-2:]:
        print(tmp)
        sys.exit()
print(-1)
Problem p03808 (python)

Fixed submission:
#modN等差数列が必要...根本的に違う
n=int(input())
a=list(map(int, input().split()))
sa= sum(a)
if sa%(n*(n+1)//2):
    print("NO")
    exit()
k=sa//(n*(n+1)//2)###+
b=[a[i]-a[i-1] -k for i in range(n)]

for i in range(n):
    if b[i]%n or b[i]>0:
        print("NO")
        exit()
print("YES")

Buggy submission (verdict: Runtime Error):
#editorial参照
n=int(input())
a=list(map(int, input().split()))
sa= sum(a)
if sa%(n*(n+1)//2):
    print("NO")
    exit()
k=sa//(n*(n-1)//2)
b=[a[i]-a[i-1] -k for i in range(n)]

for i in range(n):
    if b[i]%n or b[i]>0:
        print("NO")
        exit()
print("YES")
Problem p03854 (python)

Fixed submission:
s = input()
l = len(s)
#後ろから見たら一意
"""
tryブロックでsys.exit()を呼ぶと強制終了しない。
"""
import sys
i = l-1
try:
    while i>-1:
        if s[i]=="r":
            if s[i-5:i+1]=="eraser":
                i-=6
            elif s[i-6:i+1]=="dreamer":
                i-=7
            else:
                print("NO")###
                sys.exit()
        else:
            if s[i-4:i+1]=="erase":
                i-=5
            elif s[i-4:i+1]=="dream":
                i -= 5
            else:
                print("NO")###
                sys.exit()
    print("YES")
except:
    pass

Buggy submission (verdict: Runtime Error):
s = input()
l = len(s)
#後ろから見たら一意
import sys
i = l-1
try:
    while i>0:
        if s[i]=="r":
            if s[i-5:i+1]=="eraser":
                i-=6
            elif s[i-6:i+1]=="dremer":
                i-=7
        else:
            if s[i-4:i+1]=="erase":
                i-=5
            elif s[i-4:i+1]=="dream":
                i -= 5
        	else:
            	print("NO")###
            	sys.exit()
    print("YES")
except:
    print("NO")