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

Fixed submission:
class UnionFind:
    def __init__(self, size: int):
        self.__size = size
        self.__root = [-1] * size

    def root(self, x: int)->int:
        if self.__root[x] < 0:
            return x
        self.__root[x] = self.root(self.__root[x])
        return self.__root[x]

    def size(self, x: int)->int:
        root = self.root(x)
        return self.__root[root]

    def same(self, x: int, y: int)->bool:
        return self.root(x) == self.root(y)

    def unite(self, x: int, y: int):
        rx, ry = self.root(x), self.root(y)

        if rx == ry:
            return

        if ry < rx:
            rx, ry = ry, rx

        self.__root[rx] += self.__root[ry]
        self.__root[ry] = rx


def connectivity(N: int, K: int, L: int, roads: list, rails: list)->list:
    road_uf, rail_uf = UnionFind(N), UnionFind(N)

    for p, q in roads:
        road_uf.unite(p-1, q-1)

    for r, s in rails:
        rail_uf.unite(r-1, s-1)

    freq = {}
    for i in range(N):
        p = (road_uf.root(i), rail_uf.root(i))
        freq.setdefault(p, 0)
        freq[p] += 1

    return [freq[(road_uf.root(i), rail_uf.root(i))] for i in range(N)]


if __name__ == "__main__":
    K = 0
    L = 0
    N, K, L = map(int, input().split())
    roads = [tuple(int(s) for s in input().split()) for _ in range(K)]
    rails = [tuple(int(s) for s in input().split()) for _ in range(L)]
    ans = connectivity(N, K, L, roads, rails)
    print(' '.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, size: int):
        self.__size = size
        self.__root = [-1] * size

    def root(self, x: int)->int:
        if self.__root[x] < 0:
            return x
        self.__root[x] = self.root(self.__root[x])
        return self.__root[x]

    def size(self, x: int)->int:
        root = self.root(x)
        return self.__root[root]

    def same(self, x: int, y: int)->bool:
        return self.root(x) == self.root(y)

    def unite(self, x: int, y: int):
        rx, ry = self.root(x), self.root(y)

        if rx == ry:
            return

        if ry < rx:
            rx, ry = ry, rx

        self.__root[rx] += self.__root[ry]
        self.__root[ry] = rx


def connectivity(N: int, K: int, L: int, roads: list, rails: list)->list:
    road_uf, rail_uf = UnionFind(N), UnionFind(N)

    for p, q in roads:
        road_uf.unite(p-1, q-1)

    for r, s in rails:
        rail_uf.unite(r-1, s-1)

    freq = {}
    for i in range(N):
        p = (road_uf.root(i), rail_uf.root(i))
        freq.setdefault(p, 0)
        freq[p] += 1

    return [freq[(road_uf.root(i), rail_uf.root(i))] for i in range(N)]


if __name__ == "__main__":
    K = 0
    L = 0
    N, K, L = map(int, input().split())
    roads = [tuple(int(s) for s in input().split()) for _ in range(K)]
    rails = [tuple(int(s) for s in input().split()) for _ in range(K)]
    ans = connectivity(N, K, L, roads, rails)
    print(' '.join(map(str, ans)))
Problem p03945 (python)

Fixed submission:
def _1d_reversi(S: str) -> int:
    n = len(S)
    return sum(S[i] != S[i-1] for i in range(1, n))


if __name__ == "__main__":
    S = input()
    ans = _1d_reversi(S)
    print(ans)

Buggy submission (verdict: Runtime Error):
def _1d_reversi(S: str) -> int:
    n = len(S)
    return sum(s[i] != s[i-1] for i in range(1, n))


if __name__ == "__main__":
    S = input()
    ans = _1d_reversi(S)
    print(ans)
Problem p03998 (python)

Fixed submission:
def str2turn(c: str) -> int:
    if c.lower() == 'a':
        return 0
    elif c.lower() == 'b':
        return 1
    return 2


def turn2str(t: int) -> str:
    if t == 0:
        return 'a'
    elif t == 1:
        return 'b'
    return 'c'


def card_game_for_three(Sa: str, Sb: str, Sc: str) -> str:
    indexes = [0, 0, 0]
    limits = [len(Sa), len(Sb), len(Sc)]
    cards = [Sa, Sb, Sc]

    turn = 0
    while indexes[turn] < limits[turn]:
        next_turn = str2turn(cards[turn][indexes[turn]])
        indexes[turn] += 1
        turn = next_turn

    return turn2str(turn).upper()


if __name__ == "__main__":
    Sa = input()
    Sb = input()
    Sc = input()
    ans = card_game_for_three(Sa, Sb, Sc)
    print(ans)

Buggy submission (verdict: Runtime Error):
def str2turn(c: str) -> int:
    if c.lower() == 'a':
        return 0
    elif c.lower() == 'b':
        return 1
    return 2


def turn2str(t: int) -> str:
    if t == 0:
        return 'a'
    elif t == 1:
        return 'b'
    return 'c'


def card_game_for_three(Sa: str, Sb: str, Sc: str) -> str:
    indexes = [0, 0, 0]
    limits = [len(Sa), len(Sb), len(Sc)]
    cards = [Sa, Sb, Sc]

    turn = 0
    while indexes[turn] < limits[turn]:
        next_turn = cards[turn][indexes[turn]]
        indexes[turn] += 1
        turn = next_turn

    return turn2str(turn).upper()


if __name__ == "__main__":
    Sa = input()
    Sb = input()
    Sc = input()
    ans = card_game_for_three(Sa, Sb, Sc)
    print(ans)
Problem p04032 (python)

Fixed submission:
def unbalanced(s: str) -> tuple:
    for i in range(len(s) - 1):
        c1, c2 = s[i], s[i + 1]
        if c1 == c2:
            return i+1, i+2
        if i + 2 < len(s):
            c3 = s[i + 2]
            if c1 == c3:
                return i+1, i+3
    return -1, -1


if __name__ == "__main__":
    s = input()
    a, b = unbalanced(s)
    print(a, b)

Buggy submission (verdict: Runtime Error):
def unbalanced(s: str) -> tuple:
    for i in range(len(s) - 1):
        c1, c2 = s[i], s[i + 1]
        if c1 == c2:
            return i+1, i+2
        if i + 2 < len(s):
            c3 = s[i + 2]
            if c1 == c3:
                return i+1, i+3
    return False


if __name__ == "__main__":
    s = input()
    a, b = unbalanced(s)
    print(a, b)
Problem p02628 (python)

Fixed submission:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

n, k = lr()
p = lr()

p.sort()
print(sum(p[:k]))

Buggy submission (verdict: Runtime Error):
n,k = lr()
p = lr()

p.sort()
print(sum(p[:k]))
Problem p02646 (python)

Fixed submission:
inf = 10**18
mod = 10**9+7

a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
if v-w <= 0:
    print('NO')
else:
    if t >= abs(a-b)/(v-w):
        print('YES')
    else:
        print('NO')

Buggy submission (verdict: Runtime Error):

inf = 10**18
mod = 10**9+7

a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
if v-w == 0:
    print('NO')
if t >= abs(a-b)/(v-w):
    print('YES')
else:
    print('NO')
Problem p02690 (python)

Fixed submission:
import sys
inf = 10**15
mod = 10**9+7
x = int(input())
for i in range(-10**5, 10**5+1):
    tmp = i**5-x
    b = int(abs(tmp)**(1/5))
    if b**5 == abs(tmp):
        if tmp > 0:
            print('{} {}'.format(i, b))
        else:
            print('{} {}'.format(i, -b))
        sys.exit()

Buggy submission (verdict: Runtime Error):
inf = 10**15
mod = 10**9+7
x = int(input())
for i in range(-10**5, 10**5+1):
    tmp = i**5-x
    b = int(abs(tmp)**(1/5))
    if b**5 == abs(tmp):
        if tmp > 0:
            print('{} {}'.format(i, b))
        else:
            print('{} {}'.format(i, -b))
        sys.exit()
Problem p02784 (python)

Fixed submission:
h,n = map(int, input().split())
a = list(map(int, input().split()))
total = 0
for i in range(n):
    total += a[i]
if total >= h:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
h,n = map(int, input().split())
total = 0
for i in range(n):
    a = int(input())
    total += a
if h >= total:
    print('Yes')
else:
    print('No')
Problem p02789 (python)

Fixed submission:
n,m = map(int, input().split())
if n == m:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n,m = map(int, input())
if n >= m:
    print('Yes')
else:
    print('No')
Problem p02850 (python)

Fixed submission:
import sys

sys.setrecursionlimit(100000)
n = int(input())
bfs_dic = [{} for i in range(n)]
ans = [0 for i in range(n-1)]

def bfs(pn, pc, node):
    c = 1
    max_c = 0
    
    if len(bfs_dic[node]) != 1 or pc == 0: #葉は見ない(葉でも最初だけは子を見る)
        for k,v in bfs_dic[node].items():
            if k == pn: continue #親と同じなら無視
            if pc == c:                 #親と色被っちゃったら色変え
                c+=1
            ans[v] = c
            maxable_c = bfs(node, c, k)
            if max_c < maxable_c:
                max_c = maxable_c
            c+=1                        #子と自分の間に色割り当てて色変える
        if max_c < c-1:
            return c-1
        else:
            return max_c
    return 1                                        #葉やったら1色しか使っとらん
            
for i in range(n-1):
    a,b = map(int, input().split())
    a-=1
    b-=1
    bfs_dic[a][b] = i
    bfs_dic[b][a] = i

print(bfs(-1, 0, 0))
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
n = int(input())
bfs_dic = [{} for i in range(n)]
ans = [0 for i in range(n-1)]

def bfs(pn, pc, node):
    c = 1
    max_c = 0
    
    if len(bfs_dic[node]) != 1 or pc == 0: #葉は見ない(葉でも最初だけは子を見る)
        for k,v in bfs_dic[node].items():
            if k == pn: continue #親と同じなら無視
            if pc == c:                 #親と色被っちゃったら色変え
                c+=1
            ans[v] = c
            maxable_c = bfs(node, c, k)
            if max_c < maxable_c:
                max_c = maxable_c
            c+=1                        #子と自分の間に色割り当てて色変える
        if max_c < c-1:
            return c-1
        else:
            return max_c
    return 1                                        #葉やったら1色しか使っとらん
            
for i in range(n-1):
    a,b = map(int, input().split())
    a-=1
    b-=1
    bfs_dic[a][b] = i
    bfs_dic[b][a] = i

print(bfs(-1, 0, 0))
for i in ans:
    print(i)
Problem p02995 (python)

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

import fractions

f=fractions.gcd(c,d)           #最大公約数
f2=c*d//f                          #最小公倍数

# a未満でcかdで割れるかず
a-=1
x = a//c
y = a//d
z = a//f2
ac = x+y-z

# b以下でcかdで割れるかず
x = b//c
y = b//d
z = b//f2
bc = x+y-z

print(b-a-(bc-ac))

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

import math

f=math.gcd(c,d)           #最大公約数
f2=c*d//f                          #最小公倍数

# a未満でcかdで割れるかず
a-=1
x = a//c
y = a//d
z = a//f2
ac = x+y-z

# b以下でcかdで割れるかず
x = b//c
y = b//d
z = b//f2
bc = x+y-z

print(b-a-(bc-ac))
Problem p03111 (python)

Fixed submission:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n,a,b,c = lr()
l = [ir() for i in range(n)]
l.sort(reverse=True)

def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)

ans = inf

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            now = [l[i],l[j],l[k]]
            ret = [0 for w in range(5-(n-3))]
            pre = 0
            for g in range(n):
                if g!=i and g!=j and g!=k:
                    ret.append(l[g])
            for h in range(4**(n-3)):
                now = [l[i], l[j], l[k]]
                pre = 0
                judge = base10to(h, 4)
                tmp = ''
                for w in range(5-len(judge)):
                    tmp = ''.join([tmp,'0'])
                judge = ''.join([tmp,judge])

                for p,t in enumerate(judge):
                    if t == '1':
                        now[0]+=ret[p]
                        pre+=10
                    elif t == '2':
                        now[1]+=ret[p]
                        pre+=10
                    elif t == '3':
                        now[2]+=ret[p]
                        pre+=10
                now.sort(reverse=True)
                ans = min(ans,pre+abs(a-now[0])+abs(b-now[1])+abs(c-now[2]))
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            f = gcd(i, j)
            ans += gcd(f, l)
print(ans)
Problem p03148 (python)

Fixed submission:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))

inf = 10**9+7
mod = 10**9+7
n, k = map(int, input().split())
g_val = [list(map(int, input().split())) for i in range(n)]
netalist = [False for i in range(n+1)]
netanum = [0 for i in range(n+1)]
g_val.sort(key=lambda x: x[1])
used_list = []
ans = [0 for i in range(k+1)] # i種類食べた時の最大値
preans = 0
for j in range(k):
    if g_val:
        g,v = g_val.pop()
        netalist[g] = True
        netanum[g]+=1
        used_list.append((v,g))
        preans+=v

kind = sum(list(map(int, netalist)))
ans[kind] = preans+(kind*kind)

import heapq # 優先度付きキュー(最小値取り出し)
heapq.heapify(used_list)   # ヒープ化


while used_list:
    v,g = heapq.heappop(used_list) # 最小値の取り出し
    if netanum[g] > 1:
        while g_val:
            gnew,vnew = g_val.pop()
            if netanum[gnew] == 0:
                ans[kind+1] = ans[kind]-v-(kind*kind)+vnew+((kind+1)*(kind+1))
                kind+=1
                netanum[g] -= 1
                netanum[gnew] += 1
                break
    if not g_val:
        break
print(max(ans))

Buggy submission (verdict: Runtime Error):
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))

import numpy as np
inf = 10**9+7
mod = 10**9+7
n, k = map(int, input().split())
g_val = [list(map(int, input().split())) for i in range(n)]
netalist = [False for i in range(n+1)]
netanum = [0 for i in range(n+1)]
g_val.sort(key=lambda x: x[1])
used_list = []
ans = [0 for i in range(k+1)] # i種類食べた時の最大値
preans = 0
for j in range(k):
    if g_val:
        g,v = g_val.pop()
        netalist[g] = True
        netanum[g]+=1
        used_list.append((v,g))
        preans+=v

kind = sum(list(map(int, netalist)))
ans[kind] = preans+(kind*kind)

import heapq # 優先度付きキュー(最小値取り出し)
heapq.heapify(used_list)   # ヒープ化


while used_list:
    v,g = heapq.heappop(used_list) # 最小値の取り出し
    if netanum[g] > 1:
        while g_val:
            gnew,vnew = g_val.pop()
            if netanum[gnew] == 0:
                ans[kind+1] = ans[kind]-v-(kind*kind)+vnew+((kind+1)*(kind+1))
                kind+=1
                netanum[g] -= 1
                netanum[gnew] += 1
                break
    if not g_val:
        break
print(max(ans))
Problem p03231 (python)

Fixed submission:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import deque
import pprint

inf = 10**18
mod = 10**9+7

n,m = map(int, input().split())
s = input()
t = input()
f=fractions.gcd(n,m)           #最大公約数
f2=n*m//f                          #最小公倍数


x = f2//n
y = f2//m

for i in range(n):
    if (x*i)%y==0:
        if s[i] != t[x*i//y]:
            print(-1)
            sys.exit()
print(f2)

Buggy submission (verdict: Runtime Error):
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import deque
import pprint

inf = 10**18
mod = 10**9+7

n,m = map(int, input().split())
s = input()
t = input()
f=math.gcd(n,m)           #最大公約数
f2=n*m//f                          #最小公倍数


x = f2//n
y = f2//m

z = ['' for i in range(f2)]
for i in range(n):
    z[i*x] = s[i]
for i in range(m):
    if z[i*y] != '' and z[i*y] != t[i]:
        print(-1)
        sys.exit()
print(f2)
Problem p03244 (python)

Fixed submission:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import itertools
import math
import fractions
import functools
l = [0]*(10**5+1)
r = [0]*(10**5+1)
 
n = int(input())
v = list(map(int, input().split()))
 
for i in range(n):
    if i % 2 == 0:
        l[v[i]] += 1
    else:
        r[v[i]] += 1
 
max_l = l.index(max(l))
max_r = r.index(max(r))
count = 0
 
if max_l == max_r:
    for i in range(len(r)):
        if r[i] == r[max_r]:
            r[i] = 0
        if l[i] == l[max_l]:
            l[i] = 0
if max(l) > max(r):
    max_l = l.index(max(l))
else:
    max_r = r.index(max(r))
 
for i in range(n):
    if i % 2 == 0 and v[i] != max_l:
        count += 1
    if i % 2 != 0 and v[i] != max_r:
        count += 1
print(count)

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

inf = 10**15
mod = 10**9+7
n = int(input())
v = list(map(int, input().split()))
left = [0 for i in range(100001)]
right = [0 for i in range(100001)]
for i in range(0,n-1,2):
    left[v[i]]+=1
    right[v[i+1]]+=1
leftnp = np.array(left)
rightnp = np.array(right)
leftnpind = np.argsort(leftnp, axis=0)[::-1]
rightnpind = np.argsort(rightnp, axis=0)[::-1]
if leftnpind[0] != rightnpind[0]:
    lmax = leftnp[leftnpind[0]]
    rmax = rightnp[rightnpind[0]]
else:
    if leftnp[leftnpind[1]] > rightnp[rightnpind[1]]:
        lmax = leftnp[leftnpind[1]]
        rmax = rightnp[rightnpind[0]]
    else:
        lmax = leftnp[leftnpind[0]]
        rmax = rightnp[rightnpind[1]]
print(n - lmax - rmax)
Problem p03263 (python)

Fixed submission:
inf = 10 ** 15
mod = 10 ** 9 + 7
h,w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
ans = []
for i in range(h):
    if i%2 == 0:
        for j in range(w-1):
            if a[i][j] != 0:
                if a[i][j]%2 == 1:    # 奇数だった
                    ans.append([i,j,i,j+1])
                    a[i][j]-=1
                    a[i][j+1]+=1
        if i < h-1 and a[i][w-1]%2 == 1:
            ans.append([i, w-1, i+1, w-1])
            a[i][w-1]-=1
            a[i+1][w-1]+=1
    else:
        for j in range(w-1):
            if a[i][w-1-j]%2 == 1:
                ans.append([i,w-1-j,i,w-1-j-1])
                a[i][w-1-j]-=1
                a[i][w-1-j-1]+=1
        if i < h-1 and a[i][0]%2 == 1:
            ans.append([i,0,i+1,0])
            a[i][0]-=1
            a[i+1][0]+=1
print(len(ans))
for x,y,nx,ny in ans:
    print('{} {} {} {}'.format(x+1,y+1,nx+1,ny+1))

Buggy submission (verdict: Runtime Error):
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)

inf = 10 ** 15
mod = 10 ** 9 + 7
h,w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
ans = []
for i in range(h):
    if i%2 == 0:
        for j in range(w-1):
            if a[i][j] != 0:
                if a[i][j]%2 == 1:    # 奇数だった
                    ans.append([i,j,i,j+1])
                    a[i][j]-=1
                    a[i][j+1]+=1
        if i < h-1 and a[i][w-1]%2 == 1:
            ans.append([i, j, i+1, j])
            a[i][w-1]-=1
            a[i+1][w-1]+=1
    else:
        for j in range(w-1):
            if a[i][w-1-j]%2 == 1:
                ans.append([i,w-1-j,i,w-1-j-1])
                a[i][w-1-j]-=1
                a[i][w-1-j-1]+=1
        if i < h-1 and a[i][0]%2 == 1:
            ans.append([i,0,i+1,0])
            a[i][0]-=1
            a[i+1][0]+=1
print(len(ans))
for x,y,nx,ny in ans:
    print('{} {} {} {}'.format(x+1,y+1,nx+1,ny+1))
Problem p03311 (python)

Fixed submission:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

n = ir()
a = lr()
total = 0
for i,num in enumerate(a):
    a[i]=(num-(i+1))
a.sort()
if n%2 == 0:
    mean = (a[n//2-1]+a[n//2])//2
else:
    mean = a[n//2]
ans = [0,0]
for i in range(mean, mean+2):
    tmp = i%2
    for num in a:
        ans[tmp]+=abs(num-i)
print(min(ans))

Buggy submission (verdict: Runtime Error):
n = ir()
a = lr()
total = 0
for i,num in enumerate(a):
    a[i]=(num-(i+1))
mean = sum(a)//n-1
ans = [0,0,0]
for i in range(mean, mean+3):
    tmp = i%3
    for num in a:
        ans[tmp]+=abs(num-i)
print(min(ans))
Problem p02645 (python)

Fixed submission:
#
print(input()[0:3])

Buggy submission (verdict: Runtime Error):
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())
def check():
  deltaD=B-A
  deltaV=V-W
  if deltaD<0:
    return 'NO'  
  if deltaD==0:
    return 'YES'
  if deltaV<=0:
    return 'NO'
  if deltaV>0:
     if T>=deltaD//deltaV:
       return 'YES'
  return 'NO'

print(check())

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

def check():
  deltaD=B-A
  deltaV=V-W
  if deltaD<0:
    return 'NO'  
  if deltaD==0:
    return 'YES'
  if deltaV<=0:
    return 'NO'
  if T>=deltaD//deltaV:
     return 'YES'
print(check())