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

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    spot_count = int(input())
    spots = [0] + list(map(int, input().split())) + [0]

    # See:
    # https://www.youtube.com/watch?v=WFg2yJGZ2Cw
    # https://img.atcoder.jp/arc093/editorial.pdf
    total_distance = 0
    total_cost = 0

    for i in range(spot_count + 1):
        total_distance += abs(spots[i + 1] - spots[i])

    for j in range(1, spot_count + 1):
        shortcut_cost = (abs(spots[j - 1] - spots[j]) + abs(spots[j] - spots[j + 1]))
        total_cost = total_distance + abs(spots[j - 1] - spots[j + 1]) - shortcut_cost
        print(total_cost)

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

# AtCoder Beginner Contest
# Problem C


if __name__ == '__main__':
    spot_count = int(input())
    mod_spots = [0] + list(map(int, input().split())) + [0]

    # FIXME: TLE
    for i in range(spot_count):
        tmp = mod_spots[i + 1]
        # # mod_spots[i + 1] = 0
        # # min_value = min(mod_spots[1:-1])
        # # max_value = max(mod_spots[1:-1])
        # min_value = min(mod_spots[1:len(mod_spots) - 1])
        # max_value = max(mod_spots[1:len(mod_spots) - 1])
        # # cost = 0

        # # if min_value * max_value > 0:
        # if (min_value > 0 and max_value > 0) or (min_value < 0 and max_value < 0):
        #     # cost = max(abs(max_value), abs(min_value)) * 2
        #     print(max(abs(max_value), abs(min_value)) * 2)
        # # elif min_value * max_value < 0:
        # elif (min_value < 0 and max_value > 0) or (min_value > 0 and max_value < 0):
        #     # cost = abs(max_value) + abs(min_value)
        #     print((abs(max_value) + abs(min_value)) * 2)
        # elif (min_value == 0 and max_value != 0) or (max_value == 0 and min_value != 0):
        #     print(max(abs(max_value), abs(min_value)) * 2)
        # else:
        #     # cost = 0
        #     print(0)

        if mod_spots[i] <= mod_spots[i + 2]:
            mod_spots[i + 1] = mod_spots[i]
        elif (mod_spots[i] > 0) and mod_spots[i + 2] > 0:
            mod_spots[i + 1] = 0
        else:
            mod_spots[i + 1] = mod_spots[i]

        # cost = sum([abs(mod_spots[j + 1] - mod_spots[j]) for j in range(spot_count + 1)])
        # hoge = [abs(mod_spots[j + 1] - mod_spots[j]) for j in range(spot_count + 1)]
        hoge = {j: abs(mod_spots[j + 1] - mod_spots[j]) for j in range(spot_count + 1)}
        print(sum(hoge.values())
        mod_spots[i + 1] = tmp
        # print(cost)
Problem p03407 (python)

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

# AtCoder Beginner Contest
# Problem A

if __name__ == '__main__':
    A, B, C = list(map(int, input().split()))

    if (A + B) >= C:
        print('Yes')
    else:
        print('No')

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

# AtCoder Beginner Contest
# Problem A

if __name__ == '__main__':
    A, B, C = list(map(int, input().split()))

    if (A + B) >= C:
        print('Yes')
    else:
        print('No')
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem A

if __name__ == '__main__':
    A, B, C = list(map(int, input().split()))

    if (A + B) >= C:
        print('Yes')
    else:
        print('No')
Problem p03417 (python)

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    N, M = list(map(int, input().split()))

    if N == 1 and M == 1:
        print(1)
    elif N == 1:
        print(M - 2)
    elif M == 1:
        print(N - 2)
    else:
        print((N - 2) * (M - 2))

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    import numpy as np

    N, M = list(map(int, input().split()))
    s = np.zeros([N, M], dtype=int)

    for i in range(N):
        for j in range(M):
            for dx in range(-1, 2):
                for dy in range(-1, 2):
                    if (0 <= i + dy < N) and (0 <= j + dx < M):
                        if s[i][j] == 0:
                            s[i][j] = 1
                        else:
                            s[i][j] = 0

    print(np.sum(s))
Problem p03425 (python)

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

# AtCoder Beginner Contest
# Problem C


def count_initial_name(people_count: int) -> dict:
    matching_strings_count = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}

    for person in range(people_count):
        initial_name = input()[0]

        if initial_name in matching_strings_count.keys():
            matching_strings_count[initial_name] += 1

    return matching_strings_count


def count_patterns(matching_strings_count):
    import itertools

    patterns = itertools.combinations(matching_strings_count.keys(), 3)
    pattern_count = 0

    for a_pattern in patterns:
        pattern_count += matching_strings_count[a_pattern[0]] * \
            matching_strings_count[a_pattern[1]] * \
            matching_strings_count[a_pattern[2]]
    return pattern_count


if __name__ == '__main__':
    matching_strings_count = count_initial_name(people_count=int(input()))

    if sum(matching_strings_count.values()) >= 3:
        print(count_patterns(matching_strings_count))
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    people_count = int(input())

    person_name = list()

    for person in range(people_count):
        person_name.append(str(input()))

    initial_strings = list()

    for name in person_name:
        initial_strings.append(name[0])

    mod_initial_strings = set(initial_strings)

    count = 0

    matching_strings = ['M', 'A', 'R', 'C', 'H']
    matching_strings_count = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}

    for string in matching_strings:
        if string in mod_initial_strings:
            count += initial_strings.count(string)

    for string in initial_strings:
        matching_strings_count[string] += 1

    if count >= 3:
        print(matching_strings_count)
    else:
        print(0)
Problem p03436 (python)

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


def main():
    from collections import deque

    h, w = map(int, input().split())
    s = [list(input()) for _ in range(h)]
    dist = [[float('inf') for _ in range(w)] for _ in range(h)]
    is_visited = [[False for _ in range(w)] for _ in range(h)]
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    white_count = 0

    for i in range(h):
        for j in range(w):
            if s[i][j] == '.':
                white_count += 1

    # スコアの最大化：全ての白マス－最短距離で(H, W)まで移動するのに必要なマスの数
    # BFS
    # Initialize
    d = deque()
    d.append(tuple((0, 0)))
    dist[0][0] = 1
    is_visited[0][0] = True

    while d:
        di = d.popleft()

        for dy, dx in dxy:
            nx = dx + di[1]
            ny = dy + di[0]

            if (nx < 0 or w <= nx or ny < 0 or h <= ny):
                continue
            elif s[ny][nx] == '#':
                continue
            elif is_visited[ny][nx]:
                continue
            else:
                dist[ny][nx] = dist[di[0]][di[1]] + 1
                is_visited[ny][nx] = True
                d.append((ny, nx))

    if dist[h - 1][w - 1] == float('inf'):
        print(-1)
    else:
        print(white_count - dist[h - 1][w - 1])


if __name__ == '__main__':
    main()

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

# AtCoder Beginner Contest
# Problem D

if __name__ == '__main__':
    height, width = map(int, input().split(" "))
    s = [map(str, input().split(",")) for i in range(width)]

    total_count = height * width
    white_count_min = (height - 1) + width
    current_black_count = s.count("#")

    result = total_count - current_black_count - white_count_min

    if result > 0:
        print(result)
    else:
        print(-1)
Problem p03533 (python)

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


def main():
    from re import search

    s = input()
    removed_a = s.replace('A', '')

    if (len(s) < 5 or len(s) < 10) and removed_a != 'KIHBR':
        print('NO')
    else:
        pattern = r'^A?KIHA?BA?RA?$'
        is_match = search(pattern, s)

        if is_match:
            print('YES')
        else:
            print('NO')


if __name__ == '__main__':
    main()

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


def main():
    s = input()
    removed_a = s.replace('A', '')

    if 4 < len(s) < 10 and removed_a != 'KIHBR':
        print('NO')
    else:
        if s.index('K') <= 1 and (s.index('B') - s.index('H')) <= 1 and (len(s) - 1 - s.index('R')) <= 1:
            print('YES')
        else:
            print('NO')


if __name__ == '__main__':
    main()

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


def main():
    s = input()
    removed_a = s.replace('A', '')

    if 5 < len(s) < 10 and removed_a != 'KIHBR':
        print('NO')
    else:
        if s.index('K') <= 1 and (s.index('B') - s.index('H')) <= 1 and (len(s) - 1 - s.index('R')) <= 1:
            print('YES')
        else:
            print('NO')


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

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from itertools import accumulate

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

    # See:
    # https://atcoder.jp/img/arc078/editorial.pdf
    # total_a = sum(a)
    summed_a = [0] + list(accumulate(a))
    total_a = sum(a)
    diff = float('inf')

    for i in range(1, n):
        diff = min(diff, abs(total_a - 2 * summed_a[i]))

    print(diff)

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from itertools import accumulate
    from bisect import bisect_left

    n = int(input())
    a = sorted(list(map(int, input().split())))
    summed_a = list(accumulate(a))
    x = bisect_left(summed_a, max(summed_a) // 2)

    if x == n - 1:
        x -= 1
    elif x == 0:
        x += 1

    print(abs(max(summed_a) - 2 * summed_a[x]))
Problem p04044 (python)

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    n, length = list(map(int, input().split()))
    s = sorted([input() for _ in range(n)])

    print(''.join(s))

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    n, length = list(map(int, input().split()))
    s = sorted([input() for _ in range(length)])

    print(''.join(s))
Problem p02885 (python)

Fixed submission:
A,B=map(int,input().split())
print(max(A-2*B,0))

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split()
print(max(A-2*B,0))
Problem p02612 (python)

Fixed submission:
N = int(input())
m = N % 1000
if m != 0:
  m = 1000 - m
print(m)

Buggy submission (verdict: Runtime Error):
import numpy as np
H,W,K = map(int,input().split())
ll = []
for h in range(H):
    l = []
    for s in input():
        if s == ".":
            l.append(0)
        else:
            l.append(1)
    ll.append(l)
cnt = 0
for bh in range(2 ** H):
    for bw in range(2 ** W):
        nn = np.asarray(ll)
        k = 0
        for h in range(H):
            if (bh & 2 ** h) >> h == 0:
                continue
            nn[h] = np.array([0] * W)
        for w in range(W):
            if (bw & 2 ** w) >> w == 0:
                continue
            nn[:,w] = np.array([0] * W)
        for h in range(H):
            for w in range(W):
                k += nn[h][w]
        if k == K:
            cnt += 1
print(cnt)
Problem p02614 (python)

Fixed submission:
import numpy as np
H,W,K = map(int,input().split())
ll = []
for h in range(H):
    l = []
    for s in input():
        if s == ".":
            l.append(0)
        else:
            l.append(1)
    ll.append(l)
cnt = 0
for bh in range(2 ** H):
    for bw in range(2 ** W):
        nn = np.asarray(ll)
        k = 0
        for h in range(H):
            if (bh & 2 ** h) >> h == 0:
                continue
            nn[h] = np.array([0] * W)
        for w in range(W):
            if (bw & 2 ** w) >> w == 0:
                continue
            nn[:,w] = np.array([0] * H)
        for h in range(H):
            for w in range(W):
                k += nn[h][w]
        if k == K:
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
import numpy as np
H,W,K = map(int,input().split())
ll = []
for h in range(H):
    l = []
    for s in input():
        if s == ".":
            l.append(0)
        else:
            l.append(1)
    ll.append(l)
cnt = 0
for bh in range(2 ** H):
    for bw in range(2 ** W):
        nn = np.asarray(ll)
        k = 0
        for h in range(H):
            if (bh & 2 ** h) >> h == 0:
                continue
            nn[h] = np.array([0] * W)
        for w in range(W):
            if (bw & 2 ** w) >> w == 0:
                continue
            nn[:,w] = np.array([0] * W)
        for h in range(H):
            for w in range(W):
                k += nn[h][w]
        if k == K:
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
import numpy as np
H,W,K = map(int,input().split())
ll = []
for h in range(H):
    l = []
    for s in input():
        if s == ".":
            l.append(0)
        else:
            l.append(1)
    ll.append(l)
cnt = 0
for bh in range(2 ** H):
    for bw in range(2 ** W):
        nn = np.asarray(ll)
        k = 0
        for h in range(H):
            if (bh & 2 ** h) >> h == 0:
                continue
            nn[h] = np.array([0] * W)
        for w in range(W):
            if (bw & 2 ** w) >> w == 0:
                continue
            nn[:,w] = np.array([0] * W)
        for h in range(H):
            for w in range(W):
                k += nn[h][w]
        if k == K:
            cnt += 1
print(cnt)
Problem p02642 (python)

Fixed submission:
N = int(input())
c=[0]*8**7
for a in input().split():
    c[int(a)] += 1
i=r=0
for t in c:
    if t:
        c[::i]=[0]*-(-8**7//i)
    i+=1
    r+=t==1
print(r)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = {}
for n in input().split():
  i = int(n)
  A[i] = 0
A.sort()
Problem p02658 (python)

Fixed submission:
N = int(input())
m = 1
for n in input().split():
  i = int(n)
  m = m * i
  if m > 10 ** 18 or m < 0:
    m = -1
print(m)

Buggy submission (verdict: Runtime Error):
N = int(input())
m = 1
for n in range(n):
  i = int(input())
  m = m * i
  if m > 10 ** 18:
    m = -1
    break
print(m)

Buggy submission (verdict: Runtime Error):
N = int(input())
m = 1
for n in range(n):
  m = m * n
  if m > 10 ** 18:
    m = -1
    break
print(m)
Problem p02681 (python)

Fixed submission:
s = input()
s2 = input()
if s == s2[0:len(s)] and len(s2) == len(s) + 1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n,m,x = map(int,input().split())
cm = []
llm = []
lf = []
for i in range(n):
    lm = [int(k) for k in input().split()]
    c = lm.pop(0)
    llm.append(lm)
    cm.append(c)
    lf.append(False)
mc = 10000000
fc = False
while True:
    #calc
    c = 0
    lx = [0 for j in range(m)]
    for i in range(n):
        if lf[i]:
            for j in range(m):
                lx[j] += llm[i][j]
            c += cm[i]
    fx = True
    for j in range(m):
        if lx[j] < x:
            fx = False
            break
    if fx:
        if mc > c:
            mc = c
            fc = True
    #next
    f = False
    for i in range(n):
        if f:
            break
        lf[i] = not lf[i]
        f = lf[i]
    if not f:
        break
if fc:
    print(mc)
else:
    print(-1)
Problem p02684 (python)

Fixed submission:
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
sr = set([])
for i in range(n):
    r.append(nx)
    sr.add(nx)
    if k < i:
        print(r[k] + 1)
        break
    tnx = a[nx]
    if tnx in sr:
        m = r.index(a[nx])
        d = i - m + 1
        k = k - m
        k = k % d
        print(r[k + m] + 1)
        break  
    nx = tnx

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
for i in range(n):
    r.append(nx)
    if k < i:
        print(r[k] + 1)
        break
    if a[nx] in r:
        m = r.index(a[nx])
        d = i - m
        k = k - m
        k = k % d
        print(r[k + 1] + 1)
        break  
    nx = a[nx]

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
for i in range(n):
    r.append(nx)
    if k < i:
        print(r[k] + 1)
        break
    if a[nx] in r:
        if k >= len(r):
            m = r.index(a[nx])
            d = i - m
            k = k - m
            k = k % d
            print(r[k + 1] + 1)
            break  
    nx = a[nx]

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = [int(i) - 1 for i in input().split()]
r = []
nx = 0
for i in range(n):
    r.append(nx)
    if a[nx] in r:
        m = r.index(a[nx])
        d = i - m
        k = k - m
        k = k % d
        print(r[k + 1] + 1)
        break
    nx = a[nx]
Problem p02536 (python)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N,M = map(int,input().split())
    uf = UnionFind(N+1)
    for i in range(M):
        a, b = map(int,input().split())
        uf.union(a,b)
    print(uf.group_count()-2)
main()

Buggy submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N,M = map(int,input().split())
    uf = UnionFind(N)
    for i in range(M):
        a, b = map(int,input().split())
        uf.union(a,b)
    print(uf.group_count()-1)
main()
Problem p02722 (python)

Fixed submission:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    def divisors(x):
        r1 = deque()
        r2 = deque()
        for i in range(1,ceil(x**0.5)):
            if x % i == 0:
                r1.append(i)
                r2.appendleft(x//i)
        if int(x**0.5) == x**0.5:
            r1.append(int(x**0.5))
        return list(r1)+list(r2)
    #N-1の約数
    ans = len(divisors(N-1))-1
    # print(ans)
    # print(divisors(N))
    for d in divisors(N)[1:]:
        tmpN = N
        while tmpN % d == 0:
            tmpN //= d
        if tmpN % d == 1:
            ans += 1

            
            
    print(ans)


    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    def divisors(x):
        r1 = deque()
        r2 = deque()
        for i in range(1,int(x**0.5)):
            if x % i == 0:
                r1.append(i)
                r2.appendleft(x//i)
        if int(x**0.5) == x**0.5:
            r1.append(int(x**0.5))
        return list(r1+r2)
    #N-1の約数
    ans = len(divisors(N-1))-1
    

    for d in divisors(N)[1:]:
        tmpN = N
        while tmpN % d == 0:
            tmpN //= d
        if tmpN % d == 1:
            ans += 1

            
            
    print(ans)


    

if __name__ == '__main__':
    main()