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

Fixed submission:
a = []
for i in range(3):
         a.append( list(map(int,input().split())))
n = int(input())
b = [int(input()) for j in range(n)]
for k in range(3):
         for l in range(3):
                  for m in range(n):
                           if a[k][l] == b[m]:
                                    a[k][l] = -1
if a[0][0] == a[0][1] == a[0][2] == -1 or  a[1][0] == a[1][1] == a[1][2] == -1 or  a[2][0] == a[2][1] == a[2][2] == -1 or  a[0][0] == a[1][0] == a[2][0] == -1 or  a[0][1] == a[1][1] == a[2][1] == -1 or  a[0][2] == a[1][2] == a[2][2] == -1 or  a[0][0] == a[1][1] == a[2][2] == -1 or  a[0][2] == a[1][1] == a[2][0] == -1 :
         print("Yes")
else:
         print("No")

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
tmp = [-1]*n
for j in range(m):
         if tmp[(sc[j][0]-1)] != sc[j][1]:
                  if tmp[(sc[j][0]-1)] != -1:
                           print(-1)
                           exit()
         tmp[(sc[j][0]-1)] = sc[j][1]
if tmp[0] == -1 and len(tmp) >= 2:
         print(-1)
         exit()
elif tmp[0] == -1 and len(tmp) == 1:
         print(0)
         exit()
else:
         for k in range(n):
                  if tmp[k] == -1:
                           tmp[k] = 0
                  print("{}".format(tmp[k]), end = "")
Problem p02900 (python)

Fixed submission:
aa,bb = map(int,input().split())
n = min(aa,bb)
b = max(aa,bb)
ans = 1
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)

if temp!=1:
         arr.append(temp)

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

for j in range(len(arr)):
         if b % arr[j] == 0:
                  ans += 1
print (ans)

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
yakusuu = []
ans = 1
for i in range (2,min(a,b)+1):
         if a % i == 0 and b% i == 0:
                  yakusuu.append(i)
for j in range(len(yakusuu)):
         for k in range(2,yakusuu[j]**(1/2)):
                  if yakusuu[j] % k == 0:
                           break
         else:
                  ans += 1
print(ans)
Problem p02995 (python)

Fixed submission:
import fractions
a,b,c,d = map(int,input().split())
lcm = (c*d)//fractions.gcd(c,d)
print(((b-((b//c)+(b//d)-(b//lcm)))-((a-1)-(((a-1)//c)+((a-1)//d)-((a-1)//lcm)))))

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
lcm = (c*d)//math.gcd(c,d)
print(((b-((b//c)+(b//d)-(b//lcm)))-((a-1)-(((a-1)//c)+((a-1)//d)-((a-1)//lcm)))))
Problem p03136 (python)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
sortl = sorted(l)
ans = 0
for number in sortl:
         ans += number
if ans - sortl[n-1] > sortl[n-1]:
         print("Yes")
else:
         print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
sortl = sorted(l)
ans = 0
for number in sortl:
         ans += number
if ans - sortl(n-1) >= sortl(n-1):
         print("No")
else:
         print("Yes")
Problem p03574 (python)

Fixed submission:
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
ans = [[0]*w for i in range(h)]
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           for k in range(max(0,i-1),min(h,(i+1)+1)):
                                    for l in range(max(0,j-1),min(w,(j+1)+1)):
                                             ans[k][l] += 1
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           ans [i][j] = "#"
for i in range(h):
         answer = list(map(str,ans[i]))
         answer=''.join(answer)
         print(answer)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
ans = [[0]*5 for i in range(h)]
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           for k in range(max(0,i-1),min(h,(i+1)+1)):
                                    for l in range(max(0,j-1),min(w,(j+1)+1)):
                                             ans[k][l] += 1
for i in range(h):
         for j in range(w):
                  if s[i][j] == "#":
                           ans [i][j] = "#"
for i in range(h):
         answer = list(map(str,ans[i]))
         answer=''.join(answer)
         print(answer)
Problem p02675 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    n = str(input())
    digit = n[-1]

    if digit == '3':
        print('bon')
    elif digit == '0':
        print('pon')
    elif digit == '1':
        print('pon')
    elif digit == '6':
        print('pon')
    elif digit == '8':
        print('pon')
    else:
        print('hon')


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    n = input()
    digit = int(n[-1])

    if digit == 3:
        print('bon')
    elif digit == 0:
        print('pon')
    elif digit == 1:
        print('pon')
    elif digit == 6:
        print('pon')
    elif digit == 8:
        print('pon')
    else:
        print('hon')


if __name__ == '__main__':
    main()
Problem p02761 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    n, m = map(int, input().split())
    s = list()
    c = list()

    for i in range(m):
        si, ci = map(int, input().split())
        si -= 1

        s.append(si)
        c.append(ci)

    for i in range(1000):
        digit = list(str(i))

        if len(digit) != n:
            continue

        ok = True

        for j in range(m):
            if int(digit[s[j]]) != c[j]:
                ok = False

        if ok:
            print(i)
            exit()

    print(-1)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    n, m = map(int, input().split())
    numbers = [list() for _ in range(n)]

    for i in range(m):
        si, ci = map(int, input().split())
        si -= 1

        numbers[si].append(ci)

    ans = list()

    for index, element in enumerate(numbers):
        if n >= 2 and index != 0 and len(element) == 0:
            numbers[index].append(0)

        if n >= 2 and index == 0:
            digit = sorted(set(numbers[0]))

            if len(digit) == 0:
                print(-1)
                exit()
            elif len(digit) == 1 and 0 in digit:
                print(-1)
                exit()
            elif len(digit) >= 2 and 0 in digit:
                ans.append(digit[1])
                continue

        ans.append(min(numbers[index]))

    candidate = ''.join(map(str, ans))

    if len(str(int(candidate))) == len(candidate):
        print(candidate)
    else:
        print(-1)


if __name__ == '__main__':
    main()
Problem p02882 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from math import degrees, atan

    a, b, x = map(int, input().split())
    h = x / (a ** 2)
    y = 2 * h * a / b
    z = 2 * b - 2 * h

    if x == (a ** 2) * b:
        print(0)
    elif 2 * h >= b:
        print(90 - degrees(atan(a / z)))
    else:
        print(degrees(atan(b / y)))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    from math import degrees, atan

    a, b, x = map(int, input().split())
    h = x / (a ** 2)
    y = 2 * h * a / b
    z = 2 * b - 2 * h

    if 2 * h >= b:
        print(90 - degrees(atan(a / z)))
    else:
        print(degrees(atan(b / y)))


if __name__ == '__main__':
    main()
Problem p02937 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from bisect import bisect_left

    s = input()
    t = input()
    n = len(s)
    m = len(t)
    alpha = [[] for _ in range(26)]

    # KeyInsight
    # 部分列判定：場所i以降で文字Cが最初に現れる位置を高速に求める
    # アルファベットの出現位置をリストで記録

    # sで各文字が出現する位置を2周分記録
    for index, si in enumerate(s):
        alpha[(ord(si) - ord('a'))].append(index)

    for index, si in enumerate(s):
        alpha[(ord(si) - ord('a'))].append(index + n)

    ans = 0
    p = 0

    for ti in t:
        c = ord(ti) - ord('a')

        if len(alpha[c]) == 0:
            print('-1')
            exit()

        pi = bisect_left(alpha[c], p)
        p = alpha[c][pi]
        p += 1

        if p >= n:
            p -= n
            ans += n

    ans += p

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    from bisect import bisect_right

    s = input()
    t = input()
    n = len(s)
    m = len(t)
    alpha = [[] for _ in range(26)]

    # KeyInsight
    # 部分列判定：場所i以降で文字Cが最初に現れる位置を高速に求める
    # アルファベットの出現位置をリストで記録

    # sで各文字が出現する位置を2周分記録
    for index, si in enumerate(s):
        alpha[(ord(si) - ord('a'))].append(index)

    for index, si in enumerate(s):
        alpha[(ord(si) - ord('a'))].append(index + n)

    ans = 1
    p = 0

    for ti in t:
        c = ord(ti) - ord('a')

        if len(alpha[c]) == 0:
            print('-1')
            exit()

        p = alpha[c][bisect_right(alpha[c], p)]

        if p > n:
            p -= n
            ans += n

    ans += p

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    from bisect import bisect

    s = input()
    t = input()
    n = len(s)
    m = len(t)
    alpha = [[] for _ in range(26)]

    # KeyInsight
    # 部分列判定：場所i以降で文字Cが最初に現れる位置を高速に求める
    # アルファベットの出現位置をリストで記録

    # sで各文字が出現する位置を2周分記録
    for index, si in enumerate(s):
        alpha[(ord(si) - ord('a'))].append(index)

    for index, si in enumerate(s):
        alpha[(ord(si) - ord('a'))].append(index + n)

    ans = 1
    p = 0

    for ti in t:
        c = ord(ti) - ord('a')

        if len(alpha[c]) == 0:
            print('-1')
            exit()

        p = alpha[c][bisect(alpha[c], p)]

        if p > n:
            p -= n
            ans += n

    ans += p

    print(ans)


if __name__ == '__main__':
    main()
Problem p02972 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    # 1-indexに
    a = [0] + list(map(int, input().split()))
    c = [0 for _ in range(n + 1)]

    # See
    # https://www.youtube.com/watch?v=-o4r74eJzV4
    # 全体の計算量は，O(N^2)のようにみえて，O(NlogN)
    # 箱iの番号が大きいものから見る
    for i in range(n, 0, -1):
        # ボールの個数の和を0で初期化
        ball_count = 0

        # iの倍数の箱を順番に見る
        # ループの範囲を[2 * i, n]として，i個飛ばしで
        for j in range(2 * i, n + 1, i):
            # mod2は，xor（排他的論理和）を使うと言い換えるとスマートに記述できる．
            # ただし，演算の順序に注意が必要
            ball_count ^= c[j]

        # i個ずつみた後の合計(mod2)とa[i]を比べる
        c[i] = a[i] ^ ball_count

    # 出力
    # ボールが入っている箱の個数とその番号
    ans = [index for index, ci in enumerate(c) if ci == 1]
    print(len(ans))
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    sorted_a = sorted(a)
    a_max = max(a)
    a_second = sorted_a[-2]

    for ai in a:
        if ai == a_max:
            print(a_second)
        else:
            print(a_max)


if __name__ == '__main__':
    main()
Problem p03000 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    from bisect import bisect

    n, x = map(int, input().split())
    ls = list(map(int, input().split()))
    dist = [0]

    for i in range(1, n + 1):
        dist.append(dist[i - 1] + ls[i - 1])

    print(bisect(dist, x))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    n, x = map(int, input().split())
    ls = list(map(int, input().split()))
    count = 0
    d = 0

    for i in range(1, n + 2):
        if d > x:
            print(count)
            exit()

        d = d + ls[i - 1]
        count += 1

    print(count)


if __name__ == '__main__':
    main()
Problem p03069 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    s = list(input())
    black_count = [0 for _ in range(n + 1)]
    ans = float('inf')

    for i, si in enumerate(s):
        if si == '#':
            black_count[i + 1] = black_count[i] + 1
        else:
            black_count[i + 1] = black_count[i]

    for j in range(n + 1):
        ans = min(ans, black_count[j] + (n - j) - black_count[n] + black_count[j])

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    s = list(input())

    if len(set(s)) == 1:
        print(0)
    else:
        ans = 0
        i = 0

        while i < n - 1:
            if s[i] == '#' and s[i + 1] == '.':
                ans += 1

                if i + 2 < n:
                    if s[i + 2] == '#':
                        i += 2
                    elif s[i + 2] == '.':
                        i += 3
                else:
                    print(ans)
                    exit()
            else:
                i += 1

    print(ans)


if __name__ == '__main__':
    main()
Problem p03141 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    dishes = list()
    ans = 0

    # See:
    # https://poporix.hatenablog.com/entry/2019/01/28/222905
    # https://misteer.hatenablog.com/entry/NIKKEI2019qual?_ga=2.121425408.962332021.1548821392-1201012407.1527836447
    for i in range(n):
        ai, bi = map(int, input().split())
        dishes.append(tuple([ai + bi, ai, bi]))

    for index, dish in enumerate(sorted(dishes, reverse=True)):
        if index % 2 == 0:
            ans += dish[1]
        else:
            ans -= dish[2]

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    diff_positive = dict()
    diff_negaitive = dict()
    pos_max = 0
    nega_max = 0
    a = [0 for _ in range(n)]
    b = [0 for _ in range(n)]

    for i in range(n):
        ai, bi = map(int, input().split())
        a[i] = ai
        b[i] = bi

        if ai - bi >= 0:
            diff_positive[i] = ai - bi
            pos_max = max(pos_max, ai - bi)
        else:
            diff_negaitive[i] = bi - ai
            nega_max = max(nega_max, abs(ai - bi))

    posi = sorted(diff_positive.items(), key=lambda x: x[1], reverse=True)
    nega = sorted(diff_negaitive.items(), key=lambda x: x[1], reverse=True)
    taka_point = 0
    aoki_point = 0

    if len(posi) % 2 == 0:
        taka = posi[::2] + nega[::2]
        aoki = posi[1::2] + nega[1::2]

        for t in taka:
            taka_point += a[t[0]]

        for a in aoki:
            aoki_point += b[a[0]]

        print(taka_point - aoki_point)
    else:
        taka = posi[::2] + nega[1::2]
        aoki = posi[1::2] + nega[::2]

        for t in taka:
            taka_point += a[t[0]]

        for a in aoki:
            aoki_point += b[a[0]]

        ans1 = taka_point - aoki_point

        taka = posi[1::2] + nega[::2]
        aoki = posi[::2] + nega[1::2]

        for t in taka:
            taka_point += a[t[0]]

        for a in aoki:
            aoki_point += b[a[0]]

        ans2 = taka_point - aoki_point
        print(max(ans1, ans2))


if __name__ == '__main__':
    main()
Problem p03274 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    n, k = list(map(int, input().split()))
    x = list(map(int, input().split()))
    ans = float('inf')

    for i in range(n - k + 1):
        left = x[i]
        right = x[i + k - 1]

        if left * right >= 0:
            ans = min(ans, max(abs(left), abs(right)))
        else:
            ans = min(ans, 2 * abs(left) + abs(right), abs(left) + 2 * abs(right))

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    n, k = list(map(int, input().split()))
    x = list(map(int, input().split()))

    if x[0] < 0:
        diff = abs(x[0])

        for i in range(n):
            x[i] += diff

    print(min(x[k - 1]), x[-k])


if __name__ == '__main__':
    main()
Problem p03282 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    s = input()
    k = int(input())
    one_count = 0

    for si in s:
        if si == '1':
            one_count += 1
        else:
            break

    if s[0] == '1':
        if k == 1:
            print(s[0])
        elif one_count >= k:
            print(1)
        elif one_count < k:
            print(s[one_count])
        else:
            print(s[1])
    else:
        print(s[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    s = input()
    k = int(input())
    one_count = 0

    for si in s:
        if si == '1':
            one_count += 1
        else:
            break

    if s[0] == '1':
        if k == 1:
            print(s[0])
        elif one_count >= k:
            print(1)
        elif one_count < k:
            print(s[k - 1])
        else:
            print(s[1])
    else:
        print(s[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    s = input()
    k = int(input())

    if s[0] == '1':
        print(s[1])
    else:
        print(s[0])


if __name__ == '__main__':
    main()
Problem p03379 (python)

Fixed submission:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    x = list(map(int, input().split()))
    sorted_x = sorted(x)

    low = sorted_x[(n // 2) - 1]
    high = sorted_x[(n // 2)]

    for i in range(n):
        if x[i] < high:
            print(high)
        else:
            print(low)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C


# See:
# https://qiita.com/suecharo/items/30f5d817da4c948c3be6
def count_sort(arr):
    max_num = max(arr)
    min_num = min(arr)
    count = [0] * (max_num - min_num + 1)
    for ele in arr:
        count[ele - min_num] += 1

    return [ele for ele, cnt in enumerate(count, start=min_num) for __ in range(cnt)]


if __name__ == '__main__':
    n = int(input())
    x = list(map(int, input().split()))
    order = list(x)

    for i in range(n):
        tmp = order[i]
        x.remove(tmp)
        x = count_sort(x)
        print(x[(n // 2) - 1])
        x += [tmp]
Problem p03380 (python)

Fixed submission:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem D

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a_max = max(a)
    a.remove(a_max)
    a = sorted(a)

    # See:
    # https://www.youtube.com/watch?v=RwWljbtCrPA
    # https://img.atcoder.jp/arc095/editorial.pdf
    diff = float('inf')
    center = 0

    for ai in a:
        current_diff = abs(a_max / 2 - ai)

        if current_diff < diff:
            diff = current_diff
            center = ai

    print(str(a_max) + ' ' + str(center))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem D

if __name__ == '__main__':
    from bisect import bisect_left
    from bisect import bisect_right
    from itertools import combinations

    n = int(input())
    a = list(map(int, input().split()))
    a_max = max(a)
    a.remove(a_max)
    a = sorted(a)

    if max(a) == 0:
        print(str(a_max) + ' ' + str(a[0]))
        exit()

    if (n - 1) % 2 == 0:
        left = bisect_left(a, a_max // 2)
        right = n - bisect_right(a, a_max // 2)
        a_right = combinations(range(1, a_max + 1), a[right])
        a_left = combinations(range(1, a_max + 1), a[left])

        if len(list(a_left)) > len(list(a_right)):
            print(str(a_max) + ' ' + str(a[left]))
        else:
            print(str(a_max) + ' ' + str(a[right]))
    else:
        center = bisect_left(a, a_max // 2)

        if center >= len(a):
            center -= 1

        a_center = combinations(range(1, a_max + 1), a[center])
        print(str(a_max) + ' ' + str(a[center]))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem D

if __name__ == '__main__':
    from bisect import bisect_left
    from bisect import bisect_right
    from itertools import combinations

    n = int(input())
    a = list(map(int, input().split()))
    a_max = max(a)
    a.remove(a_max)
    a = sorted(a)

    if max(a) == 0:
        print(str(a_max) + ' ' + str(a[0]))
        exit()

    left = bisect_left(a, a_max // 2)
    right = n - bisect_right(a, a_max // 2)
    a_right = combinations(range(1, a_max + 1), a[right])
    a_left = combinations(range(1, a_max + 1), a[left])

    if len(list(a_left)) > len(list(a_right)):
        print(str(a_max) + ' ' + str(a[left]))
    else:
        print(str(a_max) + ' ' + str(a[right]))
Problem p03393 (python)

Fixed submission:
# -*- coding: utf-8 -*-

# AtCoder Grand Contest
# Problem A


# See:
# https://img.atcoder.jp/agc022/editorial.pdf
# https://agc022.contest.atcoder.jp/submissions/2286541
def determine_next_word(given_word: str) -> str:
    while given_word:
        pi = ascii_lowercase.index(given_word[-1])
        given_word = given_word[:-1]

        for character in ascii_lowercase[pi + 1:]:
            if character not in given_word:
                return given_word + character


if __name__ == '__main__':
    from string import ascii_lowercase
    s = input()

    if len(s) < 26:
        result = [s + character for character in ascii_lowercase if character not in s][0]
        print(result)
    elif s == ascii_lowercase[::-1]:
        print(-1)
    else:
        print(determine_next_word(given_word=s))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

# AtCoder Grand Contest
# Problem A

if __name__ == '__main__':
    s = list(input())
    alphabets = [chr(ord('a') + i) for i in range(26)]

    if len(s) == 26:
        if s == alphabets[::-1]:
            print(-1)
        else:
            common_alphabet = ''

            for i in range(len(s)):
                if s[:i] == alphabets[:i]:
                    common_alphabet = s[:i]
            new_s = alphabets.index(''.join(common_alphabet[-2:-1]))
            print(''.join(common_alphabet[:-1]) + alphabets[new_s + 2])
    else:
        sorted_s = sorted(s)
        diff = set(alphabets) - set(sorted_s)
        candidate = sorted(diff)[0]
        print(''.join(s + [candidate]))