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

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
arrays = []
a.sort()

b = []
c = []

for i in a:
    if i < 0:
        c.append(i)
    else:
        b.append(i)

if len(c) >= 1 and len(b) >= 1:
    while len(b) > 1:
        x = b.pop(0)
        array = [c[0], x]
        c[0] -= x
        arrays.append(array)
    while len(c) > 1:
        y = c.pop(0)
        array = [b[0], y]
        b[0] -= y
        arrays.append(array)

    array = [b[0], c[0]]
    arrays.append(array)

    print(b[0] - c[0])

elif len(b) == 0 and len(c) >= 1:
    mi = c.pop(-1)
    while len(c) > 1:
        x = c.pop(0)
        array = [mi, x]
        mi -= x
        arrays.append(array)
    array = [mi, c[0]]
    arrays.append(array)
    print(mi - c[0])


elif len(b) >= 1 and len(c) == 0:
    mi = b.pop(0)
    while len(b) > 1:
        x = b.pop(0)
        array = [mi, x]
        mi -= x
        arrays.append(array)
    array = [b[0], mi]
    arrays.append(array)
    print(b[0]-mi)


for x, y in arrays:
    print(x, y)

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

b = []
c = []

for i in a:
    if i < 0:
        c.append(i)
    else:
        b.append(i)

if len(c) >= 1:
    while len(b) > 1:
        x = b.pop(0)
        array = [c[0], x]
        c[0] -= x
        arrays.append(array)
    while len(c) > 1:
        y = c.pop(0)
        array = [b[0], y]
        b[0] -= y
        arrays.append(array)

    array = [b[0], c[0]]
    arrays.append(array)

    print(b[0] - c[0])

else:
    mi = b.pop(0)
    while len(b) > 1:
        x = b.pop(0)
        array = [mi, x]
        mi -= x
        arrays.append(array)
    array = [b[0], mi]
    arrays.append(array)
    print(b[0]-mi)


for x, y in arrays:
    print(x, y)

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

b = []
c = []

for i in a:
    if i < 0:
        c.append(i)
    else:
        b.append(i)

if len(c) >= 1:
    while len(b) > 1:
        x = b.pop(0)
        array = [c[0], x]
        c[0] -= x
        arrays.append(array)

    array = [b[0], c[0]]
    arrays.append(array)

    print(b[0] - c[0])

else:
    mi = b.pop(0)
    while len(b) > 1:
        x = b.pop(0)
        array = [mi, x]
        mi -= x
        arrays.append(array)
    array = [b[0], mi]
    arrays.append(array)
    print(b[0]-mi)


for x, y in arrays:
    print(x, y)
Problem p03032 (python)

Fixed submission:
import numpy as np

n, k = map(int, input().split())

value = np.array(list(map(int, input().split())))
r_value = value[::-1]

max_value = max(value[0], r_value[0])
for i in range(1, k):
    total_value = 0
    if i > n:
        s = value
        s.sort()
        s = list(s)
        for j in range(k-n):
            if s[0] < 0:
                s.pop(0)
        total_value = sum(s)
    else:
        for j in range(i+1):
            a = value[0:j]
            b = r_value[0:i-j]
            c = np.concatenate((a, b))
            c.sort()
            c = list(c)
            for l in range(k-i):
                if c[0] < 0:
                    c.pop(0)
                if c == []:
                    break
            total_value = sum(c)
            if total_value > max_value:
                max_value = total_value
print(max_value)

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

n, k = map(int, input().split())

value = np.array(list(map(int, input().split())))
r_value = value[::-1]

max_value = max(value[0], r_value[0])
for i in range(1, k):
    total_value = 0
    if i > n:
        s = value
        s.sort()
        s = list(s)
        for j in range(k-n):
            if s[0] < 0:
                s.pop(0)
        total_value = sum(s)
    else:
        for j in range(i+1):
            a = value[0:j]
            b = r_value[0:i-j]
            c = np.concatenate((a, b))
            c.sort()
            c = list(c)
            for l in range(k-i):
                if c[0] < 0:
                    c.pop(0)
                if c == []:
                    break
            total_value = sum(c)
            if total_value > max_value:
                max_value = total_value
print(max_value)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
edges = [[] for _ in range(n+1)]
colors = [None] * (n+1)

for i in range(n-1):
    u, v, w = [int(x) for x in input().split()]
    if w & 1 == 0:
        edges[u].append((v, 0))
        edges[v].append((u, 0))
    else:
        edges[u].append((v, 1))
        edges[v].append((u, 1))

colors[1] = 0


def color(node, c):
    colors[node] = c
    for i, j in edges[node]:
        if colors[i] is None:
            new_color = (c + j)%2
            color(i, new_color)

color(1,1)

for i in colors[1:]:
    print(i)

Buggy submission (verdict: Runtime Error):
n = int(input())
edges = [[] for _ in range(n+1)]
colors = [None] * (n+1)

for i in range(n-1):
    u, v, w = [int(x) for x in input().split()]
    if w & 1 == 0:
        edges[u].append((v, 0))
        edges[v].append((u, 0))
    else:
        edges[u].append((v, 1))
        edges[v].append((u, 1))

colors[1] = 0


def color(node, c):
    colors[node] = c
    for i, j in edges[node]:
        if colors[i] is None:
            new_color = (c + j)%2
            color(i, new_color)

color(1,1)

for i in colors[1:]:
    print(i)
Problem p03061 (python)

Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split()))
b = a[::-1]

left = [0, a[0]]
right = [0, b[0]]
l = a[0]
r = b[0]
for i in range(1, n):
    l = fractions.gcd(l, a[i])
    r = fractions.gcd(r, b[i])
    left.append(l)
    right.append(r)

gcd_max = 0
for i in range(n+1):
    gcd_tmp = fractions.gcd(left[i], right[n-i-1])
    if gcd_tmp > gcd_max:
        gcd_max = gcd_tmp

print(gcd_max)

Buggy submission (verdict: Runtime Error):
import fractions

n = int(input())
a = list(map(int, input().split()))
b = a[::-1]

left = [0, a[0]]
right = [0, b[0]]
l = a[0]
r = b[0]
for i in range(1, n):
    l = fractions.gcd(l, a[i])
    r = fractions.gcd(r, b[i])
    left.append(l)
    right.append(r)

gcd_max = 0
for i in range(n+1):
    gcd_tmp = gcd(left[i], right[n-i-1])
    if gcd_tmp > gcd_max:
        gcd_max = gcd_tmp

print(gcd_max)

Buggy submission (verdict: Runtime Error):
from math import gcd

n = int(input())
a = list(map(int, input().split()))
b = a[::-1]

left = [0, a[0]]
right = [0, b[0]]
l = a[0]
r = b[0]
for i in range(1, n):
    l = gcd(l, a[i])
    r = gcd(r, b[i])
    left.append(l)
    right.append(r)

gcd_max = 0
for i in range(n+1):
    gcd_tmp = gcd(left[i], right[n-i-1])
    if gcd_tmp > gcd_max:
        gcd_max = gcd_tmp

print(gcd_max)
Problem p03076 (python)

Fixed submission:
a = []
b = []
min = 10
minutes = 0
min_index = 0

for i in range(5):
    a.append(int(input()))
    if 0 < a[i] % 10 < min:
        min = a[i] % 10
        min_index = i

a[4], a[min_index] = a[min_index], a[4]

for i in range(4):
    if a[i] % 10 != 0:
        minutes += (a[i] // 10 + 1) * 10
    else:
        minutes += a[i]

minutes += a[4]

print(minutes)

Buggy submission (verdict: Runtime Error):
a = []
b = []
min = 10
minutes = 0

for i in range(5):
    a.append(int(input()))
    amari = a[i] % 10
    if amari < min and 0 < amari:
        min = amari
        min_index = i

a[4], a[min_index] = a[min_index], a[4]

for i in range(4):
    if a[i] % 10 != 0:
        minutes += (a[i] // 10 + 1) * 10
    else:
        minutes += a[i]

minutes += a[4]

print(minutes)
Problem p03087 (python)

Fixed submission:
n, q = map(int, input().split())
s = list(input())

l = [0]
ll = []
count = 0

for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        count += 1
    l.append(count)


for i in range(q):
    array = list(map(int, input().split()))
    ll.append(array)

for i in range(q):
    print(l[ll[i][1]-1] - l[ll[i][0]-1])

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

l = [0]
ll = []
count = 0

for i in range(n):
    if s[i] == 'A' and s[i+1] == 'C':
        count += 1
    l.append(count)


for i in range(q):
    array = list(map(int, input().split()))
    ll.append(array)

for i in range(q):
    print(l[ll[i][1]-1] - l[ll[i][0]-1])

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

l = [0]
ll = []
count = 0

for i in range(n):
    if s[i] == 'A' and s[i+1] == 'C':
        count += 1
    l.append(count)


for i in range(q):
    array = list(map(int, input().split()))
    ll.append(array)

for i in range(q):
    print(l[ll[i][1]-1] - l[ll[i][0]-1])

print(l)
Problem p03239 (python)

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

routes = []
cost = 1000

for i in range(n):
    array = list(map(int, input().split()))
    if array[1] <= t:
        routes.append(array)
        cost = min(array[0], cost)

if not routes:
    print('TLE')
    exit()

print(cost)

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

routes = []

for i in range(n):
    array = list(map(int, input().split()))
    if array[1] <= t:
        routes.append(array)

if not routes:
    print('TLE')
    exit()

print(min(routes[1]))
Problem p03240 (python)

Fixed submission:
n = int(input())

lis = []

for i in range(n):
    array = list(map(int, input().split()))
    lis.append(array)

lis.sort(reverse=True, key=lambda x:x[2])
ans_list = []

for i in range(101):
    for j in range(101):
        h = abs(i-lis[0][0]) + abs(j-lis[0][1]) + lis[0][2]
        flag = True
        for k in range(1, n):
            dist = abs(i - lis[k][0]) + abs(j - lis[k][1])
            if h - dist == lis[k][2]:
                continue
            elif h - dist <= 0 and lis[k][2] == 0:
                continue
            else:
                flag = False
                break
        if flag is True:
            print(i, j, h)

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

lis = []

for i in range(n):
    array = list(map(int, input().split()))
    lis.append(array)

ans_list = []

for i in range(101):
    for j in range(101):
        h = abs(i-lis[0][0]) + abs(j-lis[0][1]) + lis[0][2]
        flag = True
        for k in range(1, n):
            dist = abs(i - lis[k][0]) + abs(j - lis[k][1])
            if h - dist == lis[k][2]:
                continue
            else:
                flag = False
                break
        if flag is True:
            ans_list.append([i, j, h])

ans_list.sort(reverse=True, key=lambda x:x[2])

for i in ans_list[0]:
    print(i, end=' ')
Problem p03262 (python)

Fixed submission:
from fractions import gcd

n, x = map(int, input().split())
l = list(map(int, input().split()))

if n == 1:
    print(abs(x-l[0]))
    exit()

diff = []
for i in range(len(l)-1):
    diff.append(abs(l[i] - l[i+1]))

for i in range(len(l)):
    diff.append(abs(l[i] - x))

gcd_1 = gcd(diff[0], diff[1])
if n == 2:
    print(gcd_1)
    exit()

for i in range(2, len(diff)-1):
    gcd_1 = gcd(gcd_1, diff[i])

print(gcd_1)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

n, x = map(int, input().split())
l = list(map(int, input().split()))

if n == 1:
    print(abs(x-l[0]))
    exit()

diff = []
for i in range(len(l)-1):
    diff.append(abs(l[i] - l[i+1]))

for i in range(len(l)):
    diff.append(abs(l[i] - x))

gcd = gcd(diff[0], diff[1])
if n == 2:
    print(gcd)
    exit()

for i in range(2, len(diff)-1):
    gcd = gcd(gcd, diff[i])

print(gcd)

Buggy submission (verdict: Runtime Error):
import math

n, x = map(int, input().split())
l = list(map(int, input().split()))

if n == 1:
    print(abs(x-l[0]))
    exit()

diff = []
for i in range(len(l)-1):
    diff.append(abs(l[i] - l[i+1]))

for i in range(len(l)):
    diff.append(abs(l[i] - x))

gcd = math.gcd(diff[0], diff[1])
if n == 2:
    print(gcd)
    exit()

for i in range(2, len(diff)-1):
    gcd = math.gcd(gcd, diff[i])

print(gcd)
Problem p03407 (python)

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

if a + b >= c:
    print('Yes')
else:
    print('No')

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

if a + b >= c:
    print('Yes')
else:
    print('No')
Problem p03455 (python)

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

if(a * b %2 == 0):
    print("Even")

else:
    print("Odd")

Buggy submission (verdict: Runtime Error):

def find(b, c, d):
    min_path = c + d
    cnt = 0

    for i in range(1000):
        act_path = min_path + 4 * i
        if(act_path == b):
            cnt += 1
        else:
            cnt += 0

    return cnt


N = int(input())
t = [0] * N
x = [0] * N
y = [0] * N
for i in range(N):
    t[i], x[i], y[i] = map(int, input().split())

count = 0

for i in range(N):
    diff_x = x[i] - x[i-1]
    diff_y = y[i] - y[i-1]
    diff_t = t[i] - t[i-1]

    count += find(diff_t, diff_x, diff_y)

if(count == N):
    print('Yes')
else:
    print('No')
Problem p03456 (python)

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

import math

c = int(a + b)
d = math.sqrt(c)
e = int(math.sqrt(c))
diff = d - e

if(diff == 0):
    print('Yes')
else:
    print('No')

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

import math

c = a + b
d = math.sqrt(c)

if(c == d**2):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import math

a, b = input().split()

c = a + b
d = math.sqrt(c)

if(c == d**2):
    print('Yes')
else:
    print('No')
Problem p03546 (python)

Fixed submission:
h, w = map(int, input().split())

WF = []
wall = []
ans = 0

for _ in range(10):
    array = list(map(int, input().split()))
    WF.append(array)

for _ in range(h):
    array = list(map(int,input().split()))
    wall.append(array)

for k in range(10):
    for i in range(10):
        for j in range(10):
            WF[i][j]=min(WF[i][j],WF[i][k]+WF[k][j])

for i in range(h):
    for j in range(w):
        num = wall[i][j]
        if num != -1:
            ans += WF[num][1]

print(ans)

Buggy submission (verdict: Runtime Error):
import math
import itertools
import collections


h, w = map(int, input().split())

route_list = []
wall = []
count = 0

for _ in range(10):
    array = list(map(int, input().split()))
    route_list.append(array)

for _ in range(h):
    array = list(map(int,input().split()))
    wall.append(array)

node_num = len(route_list) #ノードの数

route = []

for i in range(10):
    now = i
    unsearched_nodes = list(range(node_num)) # 未探索ノード
    distance = [math.inf] * node_num # ノードごとの距離のリスト
    distance[now] = 0 # 初期のノードの距離は0とする

    while len(unsearched_nodes) > 0:
        for node in range(node_num):
            if now == node:
                continue
            else:
                distance[node] = min(distance[now] + route_list[now][node], distance[node])
        unsearched_nodes.remove(now)
        if len(unsearched_nodes) > 0:
            now = unsearched_nodes[0]
    route.append(distance)

distance_to_one = []
for i in range(10):
    distance_to_one.append(route[i][1])

flattened_wall = list(itertools.chain.from_iterable(wall))

c = collections.Counter(flattened_wall)
for i, j in c.items():
    if i == -1:
        continue
    elif i == 1:
        collections
    else:
        count += distance_to_one[i] * j

print(count)
Problem p03547 (python)

Fixed submission:
a = list(input())
x = a[0]
y = a[2]

if x < y:
    print('<')
elif y < x:
    print('>')
else:
    print('=')

Buggy submission (verdict: Runtime Error):
x = input()
y = input()

if x < y:
    print('<')
elif y < x:
    print('>')
else:
    print('=')
Problem p03565 (python)

Fixed submission:
s = list(input())
t = list(input())

length_1 = len(s)
length_2 = len(t)


def check_word(num1, length):
    a = s[num1:num1+length]
    b = t[:]
    flag = True
    for i in range(length):
        if a[i] == '?':
            continue
        elif a[i] == b[i]:
            continue
        else:
            flag = False
            break
    if flag is True:
        c = s.copy()
        c[num1:num1+length] = t[:]
        c = fill_a(c)
        return c
    elif flag is False:
        return []


def fill_a(li):
    for i in range(len(li)):
        if li[i] == '?':
            li[i] = 'a'
    return li


word_list = []
for i in range(length_1 - length_2 + 1):
    x = check_word(i, length_2)
    if x != []:
        word_list.append(x)

if word_list == []:
    print('UNRESTORABLE')
else:
    word_list.sort()
    while word_list[0] == []:
        x.pop(0)
    for i in word_list[0]:
        print(i, end='')

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


def check_context(a, b):
    ss = s.copy()
    if a <= b:
        return []
    if len(s[a:]) < len(t[b:]):
        return []
    ss[a-b:a-b+len(t)] = t[:]
    return ss


x = []
count = 0
for i in range(len(s)):
    if s[i] == '?':
        continue
    for j in range(len(t)):
        if s[i] == t[j]:
            x.append(check_context(i, j))
            if x[count]:
                for k in range(len(x[count])):
                    if x[count][k] == '?':
                        x[count][k] = 'a'
                count += 1


if x:
    x.sort()
    while x[0] == []:
        x.pop(0)
    for i in x[0]:
        print(i, end='')
elif x == []:
    print('UNRESTORABLE')

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


def check_context(a, b):
    ss = s.copy()
    if a <= b:
        return []
    if len(s[a:]) < len(t[b:]):
        return []
    ss[a-b:a-b+len(t)] = t[:]
    return ss



for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            x = check_context(i, j)
            if x:
                for k in range(len(x)):
                    if x[k] == '?':
                        x[k] = 'a'

if x:
    for i in x:
        print(i, end='')
else:
    print('UNRESTORABLE')

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


def check_context(a, b):
    ss = s.copy()
    if a <= b:
        return []
    if len(s[a:]) < len(t[b:]):
        return []
    ss[a-b:a-b+len(t)] = t[:]
    return ss



for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            x = check_context(i, j)
            if x:
                for k in range(len(x)):
                    if x[k] == '?':
                        x[k] = 'a'

if x:
    print(x, sep='')
else:
    print('UNRESTORABLE')
Problem p03569 (python)

Fixed submission:
s = input()

left = 0
right = len(s) - 1
x_cnt = 0

while left < right:
    if s[left] == s[right]:
        left += 1
        right -= 1
    else:
        if s[left] == 'x':
            x_cnt += 1
            left += 1
        elif s[right] == 'x':
            x_cnt += 1
            right -= 1
        else:
            print(-1)
            exit()

print(x_cnt)

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

if s == s[::-1]:
    print(0)
    exit()

t = []

for i in range(len(s)):
    if s[i] != 'x':
        t.append(s[i])

if t != t[::-1]:
    print(-1)
    exit()

central_char = t[len(t)//2]

s = list(s)
s.insert(0, '*')
s.append('*')

central_position = 0

for i in range(len(s)):
    if s[i] == central_char:
        central_position = i

left = central_position - 1
right = central_position + 1
x_cnt = 0

while left > 0 or right < len(s)-1:
    if s[max(0, left)] == s[min(len(s), right)]:
        left -= 1
        right += 1
    else:
        x_cnt += 1
        if s[max(0, left)] == 'x':
            left -= 1
        else:
            right += 1

print(x_cnt)

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

if s == s[::-1]:
    print(0)
    exit()

t = []

for i in range(len(s)):
    if s[i] != 'x':
        t.append(s[i])

if t != t[::-1]:
    print(-1)
    exit()

central_char = t[len(t)//2]

s = list(s)
s.insert(0, '*')
s.append('*')

central_position = 0

for i in range(len(s)):
    if s[i] == central_char:
        central_position = i

left = central_position - 1
right = central_position + 1
x_cnt = 0

while left != 0 or right != len(s)-1:
    if s[max(0, left)] == s[min(len(s), right)]:
        left -= 1
        right += 1
    else:
        x_cnt += 1
        if s[max(0, left)] == 'x':
            left -= 1
        else:
            right += 1

print(x_cnt)
Problem p03574 (python)

Fixed submission:
h, w = map(int, input().split())
mine_area = []
output = [[0 for _ in range(w)] for _ in range(h)]


def check_num(i, j):
    a = i - 1
    b = i + 1
    c = j - 1
    d = j + 1
    if i == 0:
        a = i
    if i == h-1:
        b = i
    if j == 0:
        c = j
    if j == w-1:
        d = j
    count = 0
    for p in range(a, b+1):
        for q in range(c, d+1):
            if p == i and q == j:
                continue
            if mine_area[p][q] == '#':
                count += 1
    return count


for _ in range(h):
    mine_line = list(input())
    mine_area.append(mine_line)

for i in range(h):
    for j in range(w):
        if mine_area[i][j] == '#':
            mine_area[i][j] = '#'
        else:
            mine_area[i][j] = check_num(i, j)

for i in range(h):
    for j in range(w):
        print(mine_area[i][j], end='')
        if j == w-1:
            print()

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
mine_area = []
output = [[0 for _ in range(w)] for _ in range(h)]


def check_num(i, j):
    a = i - 1
    b = i + 1
    c = j - 1
    d = j + 1
    if i == 0:
        a = i
    elif i == h-1:
        b = i
    if j == 0:
        c = j
    elif j == w-1:
        d = j
    count = 0
    for p in range(a, b+1):
        for q in range(c, d+1):
            if p == i and q == j:
                continue
            if mine_area[p][q] == '#':
                count += 1
    return count


for _ in range(h):
    mine_line = list(input())
    mine_area.append(mine_line)

for i in range(h):
    for j in range(w):
        if mine_area[i][j] == '#':
            mine_area[i][j] = '#'
        else:
            mine_area[i][j] = check_num(i, j)

for i in range(h):
    for j in range(w):
        print(mine_area[i][j], end='')
        if j == w-1:
            print()
Problem p03607 (python)

Fixed submission:
n = int(input())

num_list = []
for i in range(n):
    a = int(input())
    num_list.append(a)

num_list.sort()
num_list2 = []
i = 0
while i < n:
    if i == n-1:
        num_list2.append(num_list[i])
        break
    elif num_list[i] == num_list[i+1]:
        i += 2
    else:
        num_list2.append(num_list[i])
        i += 1


print(len(num_list2))

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

num_list = []
for i in range(n):
    a = int(input())
    num_list.append(a)

num_list.sort()
num_list2 = []
i = 0
while i < n:
    if num_list[i] == num_list[i+1]:
        i += 2
    else:
        num_list2.append(num_list[i])
        i += 1

print(len(num_list2))