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

Fixed submission:
s = input()

core = []

for c in s:
    if c != 'x':
        core.append(c)
if core == []:
    print(0)
    exit()
l = 0
r = len(core) - 1

while l <= r:
    if core[l] != core[r]:
        print(-1)
        exit()
    l += 1
    r -= 1

ans = 0
l = 0
r = len(s) - 1

while l <= r:
    lx = 0
    rx = 0
    while s[l] == 'x':
        l += 1
        lx += 1
    while s[r] == 'x':
        r -= 1
        rx += 1
    ans += abs(lx - rx)
    l += 1
    r -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()

core = []

for c in s:
    if c != 'x':
        core.append(c)
l = 0
r = -1 if core == [] else len(core) - 1
while l <= r:
    if core[l] != core[r]:
        print(-1)
        exit()
    l += 1
    r -= 1

ans = 0
l = 0
r = len(s) - 1
while l <= r:
    lx = 0
    rx = 0
    while s[l] == 'x':
        l += 1
        lx += 1
    while s[r] == 'x':
        r -= 1
        rx += 1
    ans += abs(lx - rx)
    l += 1
    r -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()

core = []

for c in s:
    if c != 'x':
        core.append(c)
l = 0
r = 0 if core == [] else len(core) - 1
while l <= r:
    if core[l] != core[r]:
        print(-1)
        exit()
    l += 1
    r -= 1

ans = 0
l = 0
r = len(s) - 1
while l <= r:
    lx = 0
    rx = 0
    while s[l] == 'x':
        l += 1
        lx += 1
    while s[r] == 'x':
        r -= 1
        rx += 1
    ans += abs(lx - rx)
    l += 1
    r -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()

core = []

for c in s:
    if c != 'x':
        core.append(c)
l = 0
r = len(core) - 1
while l <= r:
    if core[l] != core[r]:
        print(-1)
        exit()
    l += 1
    r -= 1

ans = 0
l = 0
r = len(s) - 1
while l <= r:
    lx = 0
    rx = 0
    while s[l] == 'x':
        l += 1
        lx += 1
    while s[r] == 'x':
        r -= 1
        rx += 1
    ans += abs(lx - rx)
    l += 1
    r -= 1
print(ans)
Problem p03818 (python)

Fixed submission:
N = int(input())
fq = [0] * int(10**5 + 10)
A = list(map(int, input().split()))
for a in A:
    fq[a] += 1
fq = [f if f % 1 == 0 else 1 for f in fq]
cnt_even = 0
cnt_odd = 0
for f in fq:
    if f & 1 == 0 and f != 0:
        cnt_even += 1
    if f & 1 == 1:
        cnt_odd += 1
if cnt_even & 1 == 0:
    print(cnt_even + cnt_odd)
else:
    print(cnt_even - 1 + cnt_odd)

Buggy submission (verdict: Runtime Error):
N = int(input())
fq = [0] * (N + 10)
A = list(map(int, input().split()))
for a in A:
    fq[a] += 1
fq = [f if f % 1 == 0 else 1 for f in fq]
cnt_even = 0
cnt_odd = 0
for f in fq:
    if f & 1 == 0 and f != 0:
        cnt_even += 1
    if f & 1 == 1:
        cnt_odd += 1
if cnt_even & 1 == 0:
    print(cnt_even + cnt_odd)
else:
    print(cnt_even - 1 + cnt_odd)
Problem p03964 (python)

Fixed submission:
def ceil(a, b):
    return (a + b - 1) // b

N = int(input())
T = []
A = []
for _ in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)
curT = T[0]
curA = A[0]
for i in range(1, N):
    m1 = ceil(curT, T[i])
    m2 = ceil(curA, A[i])
    m = max(m1, m2)
    curT = m * T[i]
    curA = m * A[i]
print(curT+curA)

Buggy submission (verdict: Runtime Error):
A = []
for _ in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)
curT = T[0]
curA = A[0]
for i in range(1, N):
    if curT > curA:
        if curT % T[i] != 0:
            curT += T[i] - curT % T[i]
        curA = curT // T[i] * A[i]
    else:
        if curA % A[i] != 0:
            curA += A[i] - curA % A[i]
        curT = curA // A[i] * T[i]
print(curT+curA)
Problem p02613 (python)

Fixed submission:
N=int(input())
data=[input() for _ in range(N)]
for d in ["AC","WA","TLE","RE"]:
  print("{} x {}".format(d,data.count(d)))

Buggy submission (verdict: Runtime Error):
N=int(input())
mydict={"AC":0,"WA":0,"TLE":0,"RE":0}
for i in range(N):
  mydict[input()]+=1
printlist=["AC","WA","TLE","RE"]
for p in printlist:
  print("{} x {}".format(p,mydict[p])
Problem p02660 (python)

Fixed submission:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N=one_int()

temp = factorization(N)
temp = sorted(temp, key= lambda x: x[0])

# temp = [[2,9]]



output_set = []
output = [ output_set + [t[0]]*t[1] for t in temp ]

count = 0
for i in output:
    temp = len(i)
    sums = 0
    for t in range(1,temp+1):
        sums += t
        if temp >= sums:
            count += 1

if N==1:
    print(0)
else:
    print(count)

Buggy submission (verdict: Runtime Error):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N=one_int()

temp = factorization(N)
temp = sorted(temp, key= lambda x: x[0])

output_set = []
output = [ output_set + [t[0]]*t[1] for t in temp ]


count = 0
for i in output:
    temp = len(i)
    sums = 0
    for t in range(1,temp+1):
        sums += t
        if temp >= sums:
            count += 1

print(count)
Problem p02732 (python)

Fixed submission:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from math import factorial
from operator import mul
from functools import reduce

def comb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

dicts = {}

N=one_int()

A = many_int()

# 辞書作成
for a in A:
    if a in dicts:
        dicts[a] += 1
    else:
        dicts[a] = 1

# 2個選ぶ組み合わせ計算
dicts_less ={}
sums = 0
for k, v in dicts.items():
    if v>=2:
        sums += comb(v,2)
    if v<2:
        dicts_less[k]=0
    elif v==2:
        dicts_less[k]=comb(v,2) - 0
    else:
        dicts_less[k]=comb(v,2) - comb(v-1,2)

for a in A:
    print(int(sums - dicts_less[a]))

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from math import factorial
def comb(n,r):
    return factorial(n) / factorial(r) / factorial(n - r)

dicts = {}

N=one_int()

A = many_int()

# 辞書作成
for a in A:
    if a in dicts:
        dicts[a] += 1
    else:
        dicts[a] = 1

# 2個選ぶ組み合わせ計算
dicts_less ={}
sums = 0
for k, v in dicts.items():
    if v>=2:
        sums += comb(v,2)
    if v<2:
        dicts_less[k]=0
    elif v<=2:
        dicts_less[k]=comb(v,2) - 0
    else:
        dicts_less[k]=comb(v,2) - comb(v-1,2)

for a in A:
    print(int(sums - dicts_less[a]))
Problem p02743 (python)

Fixed submission:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from decimal import *

getcontext().prec = 28      # デフォルト28桁のところを20桁にする


A, B, C = input_int()

A = Decimal(A).sqrt()
B = Decimal(B).sqrt()
C = Decimal(C).sqrt()



if (A+B) < C:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import fractions

import math

A, B, C = input_int()

max_num = int(math.sqrt(max(a))+1)

a=[A,B,C]
ans = A
for i in range(1, len(a)):
    ans = fractions.gcd(ans, a[i])

A //= ans
B //= ans
C //= ans

if ( A**(1/2) + B**(1/2) ) < C**(1/2):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


import math

A, B, C = input_int()

migi = math.sqrt(C)

migi -=  math.sqrt(A)
migi -=  math.sqrt(B)



if 0 < migi:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


import math

A, B, C = input_int()

migi = math.sqrt(C)

hidari = math.sqrt(A) + math.sqrt(B)

if hidari < migi:
    print("Yes")
else:
    print("No")
Problem p02761 (python)

Fixed submission:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = input_int()

data = []
for i in range(M):
    s,c = input_int()
    data.append([s,c])

def solve(N, data):
    mins = 100000000000
    for i in range(10**N):

        temp = str(i)
        flg = True
        if len(temp)==N:
            for d in data:
                if temp[d[0]-1] != str(d[1]):
                    flg = False
                    break
            if flg==True:
                return temp
    return -1

output = solve(N,data)
print(output)

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = input_int()

data = []
for i in range(M):
    s,c = input_int()
    data.append([s,c])

output = [0 for i  in range(N)]

def solve(N, data):
    mins = 100000000000
    for i in range(10**N):

        temp = str(i)
        flg = True
        for d in data:
            if temp[d[0]-1] != str(d[1]) and len(temp)==N:
                flg = False
                break
        if flg==True:
            return temp
    return -1

output = solve(N,data)
print(output)

Buggy submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = input_int()

dicts = {}

data = []
for i in range(M):
    s,c = input_int()
    data.append([s,c])

data = sorted(data, key=lambda x: x[0],reverse=True)

data

output = [0 for i  in range(data[0][0])]

def solve(data):
    for d in data:
        if d[1]==0:
            continue
        elif output[d[0]-1]!=0:
            if (output[d[0]-1] != d[1]):
                return -1
            
        output[d[0]-1] = d[1]
    return int("".join(list(map(str, output))))

output = solve(data)
if output==0:
    print(-1)
else:
    print(output)
Problem p02783 (python)

Fixed submission:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = two_int()

temp = N/M

if temp.is_integer():
    print(int(temp))
else:
    print(int(temp)+1)

Buggy submission (verdict: Runtime Error):
def hoge(n, cnt=0):
    if n == 0:
        return cnt
    else:
        return hoge(int(n/2), 2 * cnt + 1)
      
def one_int():
    return int(input())
  
  
print(hoge(one_int()))
Problem p02866 (python)

Fixed submission:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
D=many_int()

num=998244353


dicts={i:0 for i in range(N)}
for d in D:
    if d in dicts:
        dicts[d] += 1
    else:
        dicts[d] = 1

sums = 1
keys = sorted(list(dicts.keys()))

test = [i for i in range(len(keys))]
flg=False
for t,k in zip(test,keys):
    if t!=k:
        flg=True

if keys[0]!=0 or D[0]!=0:
    flg=True
else:
    if dicts[0]!=1:
        flg=True
        
if flg:
    sums=0

for i in range(len(keys)-1):
    if i >= 1:
        for j in range(dicts[keys[i+1]]):
            sums *= (dicts[keys[i]])
            sums = sums%num
print(sums)

Buggy submission (verdict: Runtime Error):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
D=many_int()

num=998244353


dicts={}
for d in D:
    if d in dicts:
        dicts[d] += 1
    else:
        dicts[d] = 1

sums = 1
keys = sorted(list(dicts.keys()))

test = [i for i in range(len(keys))]
flg=False
for t,k in zip(test,keys):
    if t!=k:
        flg=True

if dicts[0]!=1:
    flg=True
        
if flg:
    sums=0

for i in range(len(keys)-1):
    if i >= 1:
        for j in range(dicts[keys[i+1]]):
            sums *= (dicts[keys[i]])
            sums = sums%num
print(sums)
Problem p02903 (python)

Fixed submission:
import numpy as np
H,W,A,B = map(int, input().split())

mat = np.zeros((H,W))

for y in range(B):
    for x in range(A,W):
        mat[y][x]=1

for y in range(B,H):
    for x in range(A):
        mat[y][x]=1

for row in mat:
    row=list(map(int, row))
    print("".join(list(map(str, row))))

Buggy submission (verdict: Runtime Error):
import numpy as np
H,W,A,B = map(int, input().split())

mat = np.zeros((H,W))

for y in range(B):
    for x in range(A,W-A):
        mat[y][x]=1

for y in range(B,H-B+1):
    for x in range(A):
        mat[y][x]=1

for row in mat:
    row=list(map(int, row))
    print("".join(list(map(str, row))))

Buggy submission (verdict: Runtime Error):
flg=True

if H==1 and W!=1:
    if B!=0:
        flg=False
    else:
        for i in range(A):
            mat[0][i]=1

    
elif H!=1 and W==1: 
    if A!=0:
        flg=False
    else:
        for i in range(B):
            mat[i][0]=1
else:
    for y in range(H):
        xs=0
        for x in range(W):

            if y_weight[x] < A and xs < B:
                mat[y][x] = 1
                y_weight[x]+=1
                xs += 1
        if xs!=B:
            flg=False
        
            
    for i in y_weight:
        if i!=A:
            flg=False
    
if flg:
    for row in mat:
        row=list(map(int, row))
        print("".join(list(map(str, row))))
else:
    print("No")

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

mat = [[0 for i in range(W)] for j in range(H)]

if H==1 and W!=1:
    for i in range(A):
        mat[0][i]=1
    
    
elif H!=1 and W==1: 
    for i in range(B):
        mat[i][0]=1
else:
    for y in range(H):
        for x in range(W):

            if sum(mat[:,x]) < A and sum(mat[y]) < B:
                mat[y][x] = 1
                    
for row in mat:
    row=list(map(int, row))
    print("".join(list(map(str, row))))

Buggy submission (verdict: Runtime Error):
import numpy as np
H,W,A,B = map(int, input().split())

mat = np.zeros((H,W))

if H==1 and W!=1:
    for i in range(A):
        mat[0][i]=1
    
elif H!=1 and W!=1: 
    for i in range(B):
        mat[i][0]=1
else:
    for y in range(H):
        for x in range(W):

            if sum(mat[:,x]) < A:
                mat[y][x] = 1

            if sum(mat[y]) == B:
                break
Problem p02913 (python)

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

# Zアルゴリズムで解く

def z_algorithm(S):
    N=len(S)
    A = [N] + [0]*(N-1)
    
    left=1
    length=0
    
    while left < N:
        
        # prefixが同じ間length加算
        while left + length < N and S[length] == S[left+length]:
            length += 1
        
        # prefixの一致数保存
        A[left] = length
        
        # 一文字一致していなければ戻る
        if length == 0:
            left+=1
            continue
        
        # lengthの分だけleftとindexの間を埋めていく(はみ出ていないとこまで)
        k=1
        while k+left < N and k+A[k]<length:
            A[left+k] = A[k]
            k += 1
            
        left += k
        length -= k
    return A

c=0
max_num=0
for sub in range(len(S)):
    subS = S[sub:]
    A=z_algorithm(subS)
    for i,a in enumerate(A):
        if i>=a and max_num<a:
            max_num=a
print(max_num)

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

A=[0 for i in range(length-max_num)]
length=len(S)
max_num=0
for c in range(len(S)):

    for i in range(1,length-max_num):
        if i+ A[i] < c+A[c]:
            A[i] = A[i-c]
        else:
            j=max(0,c+A[c]-i)
            while i+j<length and S[j]==S[i+j]:
                j+=1
            A[i]=j
            if max_num<A[i] and i>=A[i]:
                max_num = A[i]
print(max_num)

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

A=[0 for i in range(length-max_num)]

for c in range(len(S)):

    for i in range(1,length-max_num):
        if i+ A[i] < c+A[c]:
            A[i] = A[i-c]
        else:
            j=max(0,c+A[c]-i)
            while i+j<length and subS[j]==subS[i+j]:
                j+=1
            A[i]=j
            if max_num<A[i] and i>=A[i]:
                max_num = A[i]
print(max_num)

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

# Zアルゴリズムで解く

c=0
max_num=0
A=[0 for i in range(length-max_num)]

for sub in range(len(S)):
    subS = S[sub:]
    length = len(subS)
    if length <= max_num:
        break

    for i in range(1,length-max_num):
        if i+ A[i-c] < c+A[c]:
            A[i] = A[i-c]
        else:
            j=max(0,c+A[c]-i)
            while i+j<length and subS[j]==subS[i+j]:
                j+=1
            A[i]=j
            if max_num<A[i] and i>=A[i]:
                max_num = A[i]
print(max_num)
Problem p02918 (python)

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

count=0
for i in range(N-1):
    if S[i]==S[i+1]:
        count+=1
print(min(N-1, count+2*K))

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()

now=S[0]
smartS=now
for subs in S:
    if now != subs:
        smartS+=subs
        now=subs

smartS = list(smartS)

if len(smartS)>=2:
    now=smartS[1]
    for i in range(K):
        smartS[2*i]=now
    
    count=0
    
    for i,subs in enumerate(smartS):
        if subs=="L":
            if i==0 :
                count+=1
            else:
                if smartS[i-1] != "L":
                    count+=1
        if subs=="R":
            if i==len(smartS)-1:
                count += 1
            else:
                if smartS[i+1] != "R":
                    count+=1
    print(N-count+1)
else:
    print(N-1)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()

RLcount=0
for i in range(1,len(S)):
    if S[i-1:i+1]=="RL":
        RLcount+=1


if RLcount > K:
    temp = (RLcount-K)
    NN = N-2*temp
if S[0]=="L":
    NN -= 1
if S[-1]=="R":
    NN -= 1
if RLcount < K:
    NN = N-1

print(int(NN))
Problem p02921 (python)

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

count=0
for s,t in zip(S,T):
    if s==t:
        count+=1
print(count)

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

count=0
for s,t in zip(S,T):
    if s==t:
        count+=1
print(count)
Problem p02927 (python)

Fixed submission:
M,D=map(int,input().split())

count=0
for i in range(1,M+1):
    for j in range(22,D+1):
        temp=str(j)
        if temp[0] >="2" and temp[1]>="2":
            if int(temp[1]) * int(temp[0])==i:
                count+=1

print(count)

Buggy submission (verdict: Runtime Error):
M,D = map(int,input().split())
​
count = 0
if M < 4 or D < 22:
    print(count)
else :
    for m in range(4,M+1):
        for da in range(2,10):
            if da > m:
                break
            db = int(m/da)
#             if m == M and da == int(D/10) and db > D%10:
#                 break
#             if db < 2:
#                 continue
            if da*10+db <= D and da*db == m:
                count += 1
​
print(count)
Problem p02936 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10000000)


N,Q=list(map(int, input().split() ))

data={i+1:0 for i in range(N)}

# for i in range(N-1):
#     a,b=list(map(int, input().split() ))
#     hoge[a].baby_list.append(b)

relate = [list(map(int, input().split() )) for i in range(N-1)]
relate.sort(key=lambda x :x[0])
    
for i in range(Q):
    root, value = list(map(int, input().split() ))
    data[root]+=value

for a,b in relate:
    data[b]+=data[a]

print(" ".join(list(map(str,list(data.values())))))

Buggy submission (verdict: Runtime Error):
import sys
  
class tree:
    def __init__(self):
        self.baby_list=[]
        self.counter=0
    
    def add_value(self):
        for i in self.baby_list:
            hoge[i].counter+=self.counter
            hoge[i].add_value()
            
N,Q=list(map(int, input().split() ))

hoge={i:tree() for i in range(1,N+1)}
    
for i in range(N-1):
    a,b=list(map(int, input().split() ))
    hoge[a].baby_list.append(b)

for i in range(Q):
    root, value = list(map(int, input().split() ))
    hoge[root].counter+=value

hoge[1].add_value()
output = []
for t in hoge:
    output.append(hoge[t].counter)

    
output = list(map(str, output))
print(" ".join(output))

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10000000)

class tree:
    def __init__(self):
        self.baby_list=[]
        self.counter=0
    
    def add_value(self):
        for i in self.baby_list:
            hoge[i].counter += self.counter
            hoge[i].add_value()

N,Q=list(map(int, input().split() ))


hoge={}

for i in range(1,N+1):
    hoge[i] = tree()
    
for i in range(N-1):
    a,b=input().split()
    hoge[a].baby_list.append(b)

for i in range(Q):
    root, value = input().split()
    hoge[root].counter+=int(value)

hoge[1].add_value()
output = ""
for t in hoge:
    output+=str(hoge[t].counter)+" "

print(output[:-1])