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

Fixed submission:
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
ans = ["UNRESTORABLE"]

if "?" not in set(s):
    print("".join(s))
    exit()

for i in range(ls-lt+1):
    f = True
    for j in range(lt):
        f &= (s[i + j] == "?" or s[i + j] == t[j])

    if f:
        ans = s.copy()
        for j in range(lt):
            ans[i+j] = t[j]


print("".join(ans).replace("?", "a"))

Buggy submission (verdict: Runtime Error):
s = list(input())
t = list(input())
ans = ["UNRESTORABLE"]
for i in range(len(s)):
    if s[i] != "?":
        for j in reversed(range(len(t))):
            if t[j] == s[i]:
                f = True
                for k in range(len(t)):
                    if not 0 <= i - j + k < len(t):
                        f = False
                        break
                    f %= (s[i - j + k] == "?" or s[i - j + k] == t[k])
                if f:
                    ans = s.copy()
                    for l in range(len(t)):
                        ans[i - j + l] = t[l]


print("".join(ans).replace("?", "a"))

Buggy submission (verdict: Runtime Error):
s = list(input())
t = list(input())
ans = ["UNRESTORABLE"]
for i in range(len(s)):
    if s[i] != "?":
        for j in reversed(range(len(t))):
            if t[j] == s[i]:
                f = True
                for k in range(len(t)):
                    if not 0 <= i - j + k < len(t):
                        break
                    f %= (s[i - j + k] == "?" or s[i - j + k] == t[k])
                if f:
                    ans = s.copy()
                    for l in range(len(t)):
                        ans[i - j + l] = t[l]


print("".join(ans).replace("?", "a"))

Buggy submission (verdict: Runtime Error):
s = list(input())
t = list(input())
ans = ["UNRESTORABLE"]
for i in range(len(s)):
    if s[i] != "?":
        for j in reversed(range(len(t))):
            if t[j] == s[i]:
                f = True
                for k in range(len(t)):
                    f &= (s[i - j + k] == "?" or s[i - j + k] == t[k])
                if f:
                    ans = s.copy()
                    for l in range(len(t)):
                        ans[i - j + l] = t[l]


print("".join(ans).replace("?", "a"))
Problem p03569 (python)

Fixed submission:
s = list(input())
l, r = 0, len(s) - 1
ans = 0
while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        if s[l] == "x":
            l += 1
            ans += 1
        elif s[r] == "x":
            r -= 1
            ans += 1
        else:
            ans = -1
            break

print(ans)

Buggy submission (verdict: Runtime Error):
s = list(input())
l, r = 0, len(s) - 1
ans = 0
while l != r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        if s[l] == "x":
            l += 1
            ans += 1
        elif s[r] == "x":
            r -= 1
            ans += 1
        else:
            ans = -1
            break

print(ans)
Problem p02692 (python)

Fixed submission:
n,a,b,c = map(int,input().split())

ss = []
for i in range(n):
    ss.append(input())

ans = []
tower = [a,b,c]
s2num = {"AB":[0,1],"BC":[1,2],"AC":[0,2]}
num2s = {0:"A",1:"B",2:"C"}
flag =True

def check_large(l,r,t):
    if t[l]>t[r]:
        return l,r,False
    elif t[l]<t[r]:
        return r,l,False
    else:
        return l,r,True

for i in range(n):
    s = ss[i]
    l,r = s2num[s]
    big,small,f = check_large(l,r,tower)
    if f:
        if i+1 < n:
            nex = s2num[ss[i+1]]
            if big in nex:
                small,big = big,small

    if tower[big] <= 0:
        flag = False
        break
    else:
        tower[big]-=1
        tower[small]+=1
        ans.append(num2s[small])

if flag:
    print("Yes")
    for i in range(n):
        print(ans[i])
else:
    print("No")

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

ss = []
for i in range(n):
    ss.append(input())

ans = []
tower = [a,b,c]
s2num = {"AB":[0,1],"BC":[1,2],"AC":[0,2]}
num2s = {0:"A",1:"B",2:"C"}
flag =True

def check_large(l,r,t):
    if t[l]>t[r]:
        return l,r,False
    elif t[l]<t[r]:
        return r,l,False
    else:
        return l,r,True

for i in range(n):
    s = ss[i]
    l,r = s2num[s]
    big,small,f = check_large(l,r,tower)
    if f:
        if i+1 < n:
            nex = s2num[ss[i+1]]
            if big in nex:
                small,big = big,small
            else:
                continue

    if tower[big] <= 0:
        flag = False
        break
    else:
        tower[big]-=1
        tower[small]+=1
        ans.append(num2s[small])

if flag:
    print("Yes")
    for i in range(n):
        print(ans[i])
else:
    print("No")

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

ss = []
for i in range(n):
    ss.append(input())

ans = []
tower = [a,b,c]
s2num = {"AB":[0,1],"BC":[1,2],"AC":[0,2]}
num2s = {0:"A",1:"B",2:"C"}
flag =True

def check_large(l,r,t):
    if t[l]>t[r]:
        return l,r,False
    elif t[l]<t[r]:
        return r,l,False
    else:
        return l,r,True

for i in range(n):
    s = ss[i]
    l,r = s2num[s]
    big,small,f = check_large(l,r,tower)
    if f:
        if i == n-1:
            pass
        else:
            nex = s2num[ss[i+1]]
            if big in nex:
                small,big = big,small
            else:
                continue
            
    if tower[big] <= 0:
        flag = False
        break
    else:
        tower[big]-=1
        tower[small]+=1
        ans.append(num2s[small])

if flag:
    print("Yes")
    for i in range(n):
        print(ans[i])
else:
    print("No")
Problem p02727 (python)

Fixed submission:
import heapq

x,y,a,b,c = map(int,input().split())
r = list(map(int,input().split()))
g = list(map(int,input().split()))
w = list(map(int,input().split()))

r.sort(key = lambda x:-x)
g.sort(key = lambda x:-x)
w.sort(key = lambda x:-x)


rg = []
for i in range(x):
    rg.append(r[i])

for i in range(y):
    rg.append(g[i])

rg.sort(key = lambda x:x)


ind = 0
ans = 0
for i in range(x+y):
    if ind <= c-1 and w[ind] > rg[i]:
        ans += w[ind]
        ind += 1
    else:
        ans += rg[i]

print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

x,y,a,b,c = map(int,input().split())
r = list(map(int,input().split()))
g = list(map(int,input().split()))
w = list(map(int,input().split()))

r.sort(key = lambda x:-x)
g.sort(key = lambda x:-x)
w.sort(key = lambda x:-x)


rg = []
for i in range(x):
    rg.append(r[i])

for i in range(y):
    rg.append(g[i])

rg.sort(key = lambda x:-x)

ind = 0
ans = 0
for i in range(x+y):
    if w[ind] > rg[i]:
        ans += w[ind]
        ind += 1
    else:
        ans += rg[i]

print(ans)
Problem p02748 (python)

Fixed submission:
a,b,m = map(int,input().split())

ref = list(map(int,input().split()))
mic = list(map(int,input().split()))

ans = min(ref)+min(mic)


for i in range(m):
    x,y,c = map(int,input().split())
    x-=1
    y-=1

    if ref[x]+mic[y]-c < ans:
        ans = ref[x]+mic[y]-c

print(ans)

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

ref = list(map(int,input().split()))
mic = list(map(int,input().split()))

ans = min(ref)+min(mic)


for i in range(m):
    x,y,c = map(int,input().split())
    x-=1
    y-=1

    if ref[x]+ref[y]-c < ans:
        ans = ref[x]+ref[y]-c

print(ans)
Problem p02852 (python)

Fixed submission:
n,m = map(int, input().split())
s = input()
now = 0
MIN = 0
ans = []
while now < n:
  for i in range(min(n-now,m),0,-1):
    nex = now + i
    if s[nex] == "0":
      now = nex
      MIN += 1
      break
  else:
    print(-1)
    exit()
now = 0
while now < n:
  for i in range(min(n-now,m),0,-1):
    nex = now + i
    if s[n-nex] == "0":
      now = nex
      ans.append(i)
      break
print(*reversed(ans))

Buggy submission (verdict: Runtime Error):


n,m = map(int,input().split())
s = input()


class segtree:

    def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_leaves = 2**(len(nb)-1)
        else:
            self.num_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_leaves * 2)]
        self.identity = identity
        self.operator =operator
        self.n = n

    def build(self,init_arr):
        for i in range(self.n):
            self.array[i+self.num_leaves] = init_arr[i]
        for i in range(self.num_leaves):
            pt = self.num_leaves-1-i
            self.array[pt] = self.operator(self.array[pt*2],self.array[pt*2+1])


    def update(self,x,val):
        actual_x = x+self.num_leaves
        # self.array[actual_x] = self.operator(self.array[actual_x],val)
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r)

    def find(self, l, r):
        #findの方が高速?
        l += self.num_leaves
        r += self.num_leaves+1
        ret = self.identity
        while l < r:
            if l & 1:
                ret = self.operator(ret, self.array[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.operator(ret, self.array[r])
            l //= 2
            r //= 2
        return ret

st = segtree(n+1,min,1e10)

arr = [1e9 for i in range(n+1)]
arr[0] = 0

st.build(arr)

for i in range(1,n+1):
    if s[i] == "1":
        continue
    else:
        left = max(i-m,0)
        right = i-1
        tm = st.find(left,right)
        arr[i] = tm+1
        st.update(i,tm+1)


nowm = arr[-1]
ans = []
for i in range(2,n+2):
    if nowm > arr[-i]:
        nowm = arr[-i]
        ans.append(-i)
    elif nowm == arr[-i]:
        ans[-1] = -i

# print(arr)
# print(ans)

bef = -1
anss = ""
for a in ans:
    anss += str(bef-a)+" "
    bef = a
anss = anss[:-1]
print(anss[::-1])
Problem p02937 (python)

Fixed submission:

from bisect import bisect_left
s= input()
t = input()

d = {}
n = len(s)
ans = 0
for i in range(len(s)):
    if s[i] not in d:
        d[s[i]] = [i+1]
    else:
        d[s[i]].append(i+1)

flag = True
bef = 0
befchar = ""
for c in t:
    if c not in d:
        flag = False
        break
    else:
        if c == befchar:
            temp = bisect_left(d[c],bef)
            # print(temp)
            if temp == len(d[c]):
                temp = d[c][0]
                ans += temp + (n-bef)
                bef = temp
            else:
                if temp +1 < len(d[c]):
                    temp = d[c][temp+1]
                    ans += temp-bef
                    bef = temp
                else:
                    temp = d[c][0]
                    ans += temp + (n - bef)
                    bef = temp
        else:
            temp = bisect_left(d[c],bef)
            if temp == len(d[c]):
                temp = d[c][0]
                ans += temp + (n-bef)
                bef = temp
            else:
                temp = d[c][temp]
                ans += temp-bef
                bef = temp
    # print(temp)
    befchar=c
    # print(ans)
# print(d)
if flag:
    print(ans)
else:
    print(-1)




# arr = [0,2,4]
# print(bisect_left(arr,2))
# print(bisect_left(arr,4))
# print(bisect_left(arr,5))

Buggy submission (verdict: Runtime Error):

from bisect import bisect_left
s= input()
t = input()

d = {}
n = len(s)
ans = 0
for i in range(len(s)):
    if s[i] not in d:
        d[s[i]] = [i+1]
    else:
        d[s[i]].append(i+1)

flag = True
bef = 0
befchar = ""
for c in t:
    if c not in d:
        flag = False
        break
    else:
        if c == befchar:
            temp = bisect_left(d[c],bef)
            if temp == len(d[c]):
                temp = d[c][0]
                ans += temp + (n-bef)
                bef = temp
            else:
                temp = d[c][temp+1]
                ans += temp-bef
                bef = temp
        else:
            temp = bisect_left(d[c],bef)
            if temp == len(d[c]):
                temp = d[c][0]
                ans += temp + (n-bef)
                bef = temp
            else:
                temp = d[c][temp]
                ans += temp-bef
                bef = temp
    befchar=c
    # print(ans)
if flag:
    print(ans)
else:
    print(-1)




# arr = [0,2,4]
# print(bisect_left(arr,1))
# print(bisect_left(arr,5))
# print(bisect_left(arr,3))
Problem p02947 (python)

Fixed submission:
n = int(input())

d = {}


class mod_comb_perm:
    def __init__(self,n,mod):
        self.mod = mod
        self.fact = [1 for i in range(n)]
        for i in range(2,n+1):
            self.fact[i-1] = (self.fact[i-2]*i)%mod

    def expo(self,x,n):
        if n == 2:
            return (x * x) % self.mod
        elif n % 2 == 1:
            return (self.expo(x, n - 1) * x) % self.mod
        else:
            temp = self.expo(x, n // 2) % self.mod
            return (temp * temp) % self.mod
    def comb(self,n,k):
        a = (self.fact[n]*self.expo(self.fact[k],self.mod-2))%self.mod
        return (a*self.expo(self.fact[n-k],self.mod-2))%self.mod
    def invm(self,x):
        return (self.expo(self.fact[x],self.mod-2))%self.mod
    def perm(self,n,k):
        return (self.fact[n]*self.expo(self.fact[n-k],self.mod-2))%self.mod


# com = mod_comb_perm(10**5,10**18+3)
d = {}
for i in range(n):
    temp = [0 for i in range(26)]
    s = input()
    for c in s:
        t = ord(c)-97
        temp[t]+=1
    for i in range(26):
        temp[i] = str(temp[i])
    txt = ",".join(temp)
    if txt not in d:
        d[txt] = 1
    else:
        d[txt] += 1
ans = 0
# print(d)
for k in d:
    if d[k] != 1:
        ans += d[k]*(d[k]-1)/2
print(int(ans))

Buggy submission (verdict: Runtime Error):
d = {}
for i in range(n):
    temp = [0 for i in range(26)]
    s = input()
    for c in s:
        t = ord(c)-97
        temp[t]+=1
    for i in range(26):
        temp[i] = str(temp[i])
    txt = ",".join(temp)
    if txt not in d:
        d[txt] = 1
    else:
        d[txt] += 1
ans = 0
for k in d:
    if d[k] != 1:
        ans += d[k]*(d[k]-1)/2
print(int(ans))
Problem p02960 (python)

Fixed submission:


s = input()
buf = [0 for i in range(13)]
s = s[::-1]
n = len(s)
# print(s)

base = 10

if s[0] == "?":
    buf = [1,1,1,1,1,1,1,1,1,1,0,0,0]
else:
    buf[int(s[0])] = 1
# print(buf)
# print("############")
for i in range(1,n):
    base = base%13
    nbuf = [0 for j in range(13)]
    if s[i] == "?":
        ooo = [0 for j in range(13)]
        for j in range(10):
            temp = (base*j)%13
            ooo[temp] += 1
        # print(ooo)
        for j in range(13):
            for k in range(13):
                temp = (j+k)%13
                nbuf[temp]+= buf[k]*ooo[j]
                nbuf[temp] %= (10**9+7)
    else:
        for j in range(13):
            temp = j+int(s[i])*base
            temp %= 13
            nbuf[temp] += buf[j]
            nbuf[temp] %= (10 ** 9 + 7)
    base *= 10
    buf = nbuf
    # print(buf)
    # print("*********************")

# print(buf)
print(buf[5])

Buggy submission (verdict: Runtime Error):
import numpy as np

s = input()
buf = [0 for i in range(13)]
s = s[::-1]
n = len(s)
# print(s)

base = 10

if s[0] == "?":
    buf = [1,1,1,1,1,1,1,1,1,1,0,0,0]
else:
    buf[int(s[0])] = 1
# print(buf)
# print("############")
for i in range(1,n):
    base = base%13
    nbuf = [0 for j in range(13)]
    if s[i] == "?":
        ooo = [0 for j in range(13)]
        for j in range(10):
            temp = (base*j)%13
            ooo[temp] += 1
        # print(ooo)
        for j in range(13):
            for k in range(13):
                temp = (j+k)%13
                nbuf[temp]+= buf[k]*ooo[j]
                nbuf[temp] %= (10**9+7)
    else:
        for j in range(13):
            temp = j+int(s[i])*base
            temp %= 13
            nbuf[temp] += buf[j]
            nbuf[temp] %= (10 ** 9 + 7)
    base *= 10
    buf = nbuf
    # print(buf)
    # print("*********************")

# print(buf)
print(buf[5])
Problem p03032 (python)

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

arr = list(map(int,input().split()))
s = [0 for i in range(n)]
temp = 0
ans = 0

for i in range(1,k+1):
    upper = min(n,i)
    for j in range(upper+1):
        v = 0
        a = []
        for l in range(j):
            v += arr[l]
            a.append(arr[l])
        for l in range(1,upper+1-j):
            v+= arr[-l]
            a.append(arr[-l])
        a.sort()
        # print(a,v)
        up = min(k-upper,i)
        for l in range(up):
            if a[l] < 0:
                v -= a[l]
            else:
                break
        if v > ans:
            ans = v

print(ans)

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

arr = list(map(int,input().split()))
s = [0 for i in range(n)]
temp = 0

ans = 0
for i in range(n):
    temp += arr[i]
    s[i] = temp

for i in range(1,k+1):
    upper = min(n,i)
    for j in range(upper+1):
        v = 0
        a = []
        for l in range(j):
            v += arr[l]
            a.append(arr[l])
        for l in range(1,i+1-j):
            v+= arr[-l]
            a.append(arr[-l])
        a.sort()
        # print(a,v)
        if k-i > 0:
            up = min(k-i,i)
            for l in range(up):
                if a[l] < 0:
                    v -= a[l]
                else:
                    break
        if v > ans:
            ans = v

print(ans)

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

arr = list(map(int,input().split()))
s = [0 for i in range(n)]
temp = 0

ans = 0
for i in range(n):
    temp += arr[i]
    s[i] = temp

for i in range(1,k+1):
    upper = min(n,i)
    for j in range(upper+1):
        v = 0
        a = []
        for l in range(j):
            v += arr[l]
            a.append(arr[l])
        for l in range(1,i+1-j):
            v+= arr[-l]
            a.append(arr[-l])
        a.sort()
        # print(a,v)
        if k-i > 0:
            up = min(k-i-1,i)
            for l in range(up):
                if a[l] < 0:
                    v -= a[l]
                else:
                    break
        if v > ans:
            ans = v

print(ans)

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

arr = list(map(int,input().split()))
s = [0 for i in range(n)]
temp = 0

ans = 0
for i in range(n):
    temp += arr[i]
    s[i] = temp

for i in range(1,k+1):
    upper = min(n,i)
    for j in range(upper+1):
        v = 0
        a = []
        for l in range(j):
            v += arr[l]
            a.append(arr[l])
        for l in range(1,i+1-j):
            v+= arr[-l]
            a.append(arr[-l])
        a.sort()
        # print(a,v)
        if k-i > 0:
            up = min(k-i,i)
            for l in range(up):
                if a[l] < 0:
                    v -= a[l]
                else:
                    break
        if v > ans:
            ans = v

print(ans)
Problem p03062 (python)

Fixed submission:
import numpy as np
n = int(input())
arr = list(map(int,input().split()))

odd = 0

for a in arr:
    if a < 0:
        odd += 1

if odd %2 == 0:
    print(np.sum(np.abs(arr)))
else:
    # print(np.sum(np.abs(arr)))
    # print(np.min(np.abs(arr)))
    print(np.sum(np.abs(arr))-2*np.min(np.abs(arr)))

Buggy submission (verdict: Runtime Error):
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g








def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

n = int(input())

a = list(map(int,input().split()))
b = a[1:-1]
m = max(b)
base = 0

for i in range(n):
    base += abs(a[i])

kouho1 = base
if a[0] > 0:
    kouho1 -=a[0]*2
kouho2 = base

if a[-1] > 0:
    kouho2 -= a[-1]*2

kouho3 = base
if m < 0:
    kouho3 += m*2


l = [kouho1,kouho2,kouho3]
print(max(l))
Problem p03210 (python)

Fixed submission:
x = int(input())
if x in [3,5,7]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
x = int(input())
if x in [3,5,7]
    print("YES")
else:
    print("NO")
Problem p03229 (python)

Fixed submission:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

A.sort()

arr = []
arr.append(A[0])
arr.append(A[-1])
Atop = 1
Abtm = len(A) - 2
ans = arr[-1]-arr[0]
for i in range(len(A)-2):
    (Ai, ai) = (Atop, 0)
    if abs(A[Atop]-arr[-1]) > abs(A[Ai]-arr[ai]):
        (Ai, ai) = (Atop, -1)
    if abs(A[Abtm]-arr[0]) > abs(A[Ai]-arr[ai]):
        (Ai, ai) = (Abtm, 0)
    if abs(A[Abtm]-arr[-1]) > abs(A[Ai]-arr[ai]):
        (Ai, ai) = (Abtm, -1)

    #print('A[Ai]: ', A[Ai])
    #print(arr)
    ans += abs(A[Ai]-arr[ai])
    if ai == -1:
        arr[-1] = A[Ai]
    else:
        arr[0] = A[Ai]

    if Ai == Atop:
        Atop += 1
    else:
        Abtm -= 1


print(ans)

Buggy submission (verdict: Runtime Error):
print(list(map(int,input().split()))[0]%list(map(int,input().split()))[1])
Problem p03241 (python)

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

max = m//n
lis = []


for i in range(int(m**0.5)):
    if i != 0 and m%i == 0:
        lis.append(i)
l = len(lis)
for i in range(l):
    if m/lis[i] != lis[i]:
        lis.append(m//lis[i])

lis.sort()
lis = lis[::-1]

if m%n == 0:
    print(max)
else:
    for line in lis:
        if line > max:
            continue
        else:
            if m/line > n:
                print(line)
                break

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

max = m//n
lis = []


for i in range(int(m**0.5)):
    if m%i == 0:
        lis.append(i)

lis = lis[::-1]

if m%n == 0:
    print(max)
else:
    for line in lis:
        if line > max:
            continue
        else:
            if lis%n == 0:
                print(lis)
                break