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

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
AB = [list(map(int,readline().split())) for i in range(N-1)]

graph = [[] for _ in range(N+1)] #隣接リスト
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

#親のノードに子を入れてくdfs
stack = [1]
parent = [0]*(N+1)
order = []
while stack:
    x = stack.pop()
    order.append(x)
    for i in graph[x]:
        if i == parent[x]:
            continue
        parent[i] = x
        stack.append(i)

#各子の色を決めていく。
color = [-1]*(N+1)
for x in order:
    ng = color[x]
    c = 1
    for y in graph[x]:
        if parent[x] == y:
            continue
        if c == ng:
            c += 1
        color[y] = c
        c += 1

ans = []
for a,b in AB:
    if parent[a] == b: #子の頂点の色を入れる
        ans.append(color[a])
    else:
        ans.append(color[b])

print(max(ans))
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
count = 0
f0,f1 = -1,-1
for ans in range(1000):
  f0,f1 = -1,-1
  ans_str = "{0:03d}".format(ans)
  for i in range(n):
    if s[i] == ans_str[0]:
      f0 = i
      break
  if f0 == -1:
    continue
  for j in range(f0+1,n):
    if s[j] == ans_str[1]:
      f1 = j
      break
  if f1 == -1:
    continue
  for k in range(f1+1,n):
    if s[k] == ans_str[2]:
      count += 1
      break

print(count)
Problem p02852 (python)

Fixed submission:
import sys
#input = sys.stdin.readline
sys.setrecursionlimit(10**9)
n,m = map(int,input().split())
s = list(input())
s.reverse()
list1 = []
def maze(mass,times): #今いるマス、現状の手数
  if mass+m >= n:
    list1.append(str(n-mass))
    return
  for i in range(m,0,-1):
    if s[mass+i] == "0":
      list1.append(str(i))
      maze(mass+i,times+1)
      return
    elif i == 1:
      print("-1")
      exit()
  return

a = maze(0,0)
list1.reverse()
print(" ".join(list1))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
#sys.setrecursionlimit(10**9)
n,m = map(int,input().split())
s = list(input())
s.reverse()
list1 = []
def maze(mass,times): #今いるマス、現状の手数
  if mass+m >= n:
    list1.append(str(n-mass))
    return
  for i in range(m,0,-1):
    if s[mass+i] == "0":
      list1.append(str(i))
      maze(mass+i,times+1)
      return
    elif i == 1:
      print("-1")
      exit()
  return

a = maze(0,0)
list1.reverse()
print(" ".join(list1))
Problem p02855 (python)

Fixed submission:
h,w,k = map(int,input().split())
list1 = [list(input()) for i in range(h)]
import numpy as np
list2 = np.zeros((h,w),np.uint32) #list2に0の配列を用意
numcount = 1 #切り分けたケーキにふる番号
berrycount = 0 #1列に何回目のいちごが現れたか
flag = 0 #1列にいちごが一個も無かったときのフラグ
que = [] #その時の列をqueに入れてく
for i in range(h):
    flag = 0
    if not "#" in list1[i]: #いちごが乗ってない列
        flag = 1
        numcount -= 1
        que.append(i)
    if not flag: #いちごが乗ってる例
        for j in range(w):    
            if list1[i][j] == ".":
                list2[i][j] = numcount
            else:
                if berrycount == 0: #いちごが出現するのが1回目なら、特に気にせず番号をつける
                    berrycount += 1
                    list2[i][j] = numcount
                else: #2回目以降なら、振り分ける番号を+1する
                    berrycount += 1
                    numcount += 1
                    list2[i][j] = numcount
    berrycount = 0 #いちごリセット
    numcount += 1 #振り分け番号を+1

meme = 0 
"""
1列目から何列もいちごが現れないとき、
初めていちごが現れる列を探索し、その列の数字を1列目~にコピーする。
それ以外(普通に列の途中でいちごのない列が出現したとき)
は、一つ前の列を参照してコピーする
"""
for i in que:
    if i == 0:
        for j in range(1,h):
            if "#" in list1[j]:
                meme = j
                break
        list2[i] = list2[meme]
    else:
        list2[i] = list2[i-1]
for i in range(h):
    for j in range(w):
        list2[i][j] = int(list2[i][j])
for i in range(h):
    print(" ".join(map(str,list2[i])))

Buggy submission (verdict: Runtime Error):
h,w,k = map(int,input().split())
list1 = [list(input()) for i in range(h)]
import numpy as np
list2 = np.zeros((h,w),np.uint8)
numcount = 1
berrycount = 0
flag = 0
for i in range(h):
    flag = 0
    if not "#" in list1[i]:
        if numcount == 1:
            for j in range(w):
                list2[i][j] = numcount
            numcount -= 1
        else:
            numcount -= 1
            for j in range(w):
                list2[i][j] = numcount
        flag = 1

    if not flag:        
        for j in range(w):
            
            if list1[i][j] == ".":
                list2[i][j] = numcount
            else:
                if berrycount == 0:
                    berrycount += 1
                    list2[i][j] = numcount
                else:
                    berrycount += 1
                    numcount += 1
                    list2[i][j] = numcount
    berrycount = 0
    numcount += 1

for i in range(h):
    print(" ".join(map(str,list2[i])))
Problem p02885 (python)

Fixed submission:
a,b = map(int,input().split())
if a <= b*2:
    print(0)
else:
    print(a-b*2)

Buggy submission (verdict: Runtime Error):
import bisect
#input
n = int(input())
list1 = list(map(int,input().split()))
list1.sort()

cout = 0 #最終的な三角形の個数

for i in range(n-2): #リストから三角形が作れなくなるまでループ
	o = list1[i] #1辺を確定、そのままリストから消去
	for j in range(i+1,n-1): #残りの二辺のループ(iで使っている次の値から)
		p = list1[j] #２辺目を確定

		b = o+p -1 #昇順にソートしてあるので、c<a+b条件のみ計算

		d = bisect.bisect_right(list1[j+1:],b) #３辺目を確定
		
		cout += d

print(cout)
Problem p02917 (python)

Fixed submission:
n = int(input())
list1 = list(map(int,input().split()))
cout = list1[-1]
min_int = list1[-1]
for i in range(n-3,-1,-1):
    cout += min(list1[i:i+2])

cout += list1[0]

print(cout)

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

list2 = []
list2.append(list1[0])
for i in range(n):
    list2.append(min(list1[(n-1)-i:]))
print(sum(list2))
Problem p02927 (python)

Fixed submission:
m,d = map(int,input().split())
f = []
d1,d10,cout = 0,0,0
for i in range(m):
  for j in range(d):
    if j+1 >= 10:
      f = list(str(j+1))
      d10 = int(f[0])
      d1 = int(f[1])
    if d1 >=2 and d10 >= 2:
      if d1*d10 == i+1:
        cout += 1
  d10,d1 = 0,0
print(cout)

Buggy submission (verdict: Runtime Error):
m,d = int(input().split())
f = []
d1,d10,cout = 0,0,0
for i in range(m):
  for j in range(d):
    if d+1 >= 10:
      f = list(str(d+1))
      d10 = int(f[0])
      d1 = int(f[1])
    if d1*d10 == i+1:
      cout += 1
print(cout)
Problem p02937 (python)

Fixed submission:
#ABC138-E Strings of Impurity
"""
sの好きなだけのループに対する部分文字列tを求める
tにあってsにない文字がある時点でno
そうでないならば必ず達成可能で、
tに対してループを回し(i)、
sのj文字目に関して、それより後に初めて出てくるt[i+1]の場所をindexで返し,i+=1,j=そのindex
にする。
そのようなindexがないならば、j=0とし、またはじめから回す。
"""
import sys
import bisect
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

s = readline().rstrip().decode('utf-8')
t = readline().rstrip().decode('utf-8')
s_s = set(list(s))
t_s = set(list(t))
flag = 1 if s_s & t_s == t_s else 0

if not flag:
    print(-1)
    exit()

#2進数で、
lst1 = [[] for _ in range(26)]
kijun = ord("a")
for idx,i in enumerate(s):
    lst1[ord(i)-kijun].append(idx)

i = 0
roop = 0
count = 0
while True:
    if i >= len(t):
        print(roop*len(s)+count) #countは0-indexedの為
        break
    now = ord(t[i])-kijun
    res = bisect.bisect_left(lst1[now],count)
    if res == len(lst1[now]):
        roop += 1
        count = 0
        res = bisect.bisect_left(lst1[now],count)
        count = lst1[now][res]+1 #その次の文字から
    else:
        count = lst1[now][res]+1
    i += 1

Buggy submission (verdict: Runtime Error):

    #ABC138-E Strings of Impurity
"""
sの好きなだけのループに対する部分文字列tを求める
tにあってsにない文字がある時点でno
そうでないならば必ず達成可能で、
tに対してループを回し(i)、
sのj文字目に関して、それより後に初めて出てくるt[i+1]の場所をindexで返し,i+=1,j=そのindex
にする。
そのようなindexがないならば、j=0とし、またはじめから回す。
"""
import sys
import bisect
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

s = readline().rstrip().decode('utf-8')
t = readline().rstrip().decode('utf-8')
s_s = set(list(s))
t_s = set(list(t))
flag = 1 if s_s & t_s == t_s else 0

if not flag:
    raise Exception
"""    print(-1)
    exit()
"""
#2進数で、
lst1 = [[] for _ in range(26)]
kijun = ord("a")
for idx,i in enumerate(s):
    lst1[ord(i)-kijun].append(idx)

i = 0
roop = 0
count = 0
while True:
    if i >= len(t):
        print(roop*len(s)+count+1) #countは0-indexedの為
        break
    now = ord(t[i])-kijun
    res = bisect.bisect_left(lst1[now],count)
    if res == len(lst1[now]):
        roop += 1
        count = 0
        res = bisect.bisect_left(lst1[now],count)
        count = lst1[now][res]
    else:
        count = lst1[now][res]
    i += 1
Problem p02945 (python)

Fixed submission:
a,b = map(int,input().split())
list1 = []
list1.append(a+b)
list1.append(a-b)
list1.append(a*b)
print(max(list1))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

n = int(input())
list1 = [''.join(sorted(input())) for i in range(n)]
dict1 = dict()
cout = 0
@lru_cache(maxsize = None)
def func(s):
	if s == 2:
		return 1 #2個の場合は1パターン
	return s-1 + func(s-1)

for i in range(n):
	if list1[i] in dict1:
		dict1[list1[i]] += 1
	else:
		dict1[list1[i]] = 1

for i in dict1:
	if dict1[i] != 1:
		cout += func(dict1[i])

print(cout)
Problem p02947 (python)

Fixed submission:
from functools import lru_cache
import sys
sys.setrecursionlimit(1000000)
n = int(input())
list1 = [''.join(sorted(input())) for i in range(n)]
dict1 = dict()
cout = 0
@lru_cache(maxsize = None)
def func(s):
	if s == 2:
		return 1 #2個の場合は1パターン
	return s-1 + func(s-1)

for i in range(n):
	if list1[i] in dict1:
		dict1[list1[i]] += 1
	else:
		dict1[list1[i]] = 1

for i in dict1:
	if dict1[i] != 1:
		cout += func(dict1[i])

print(cout)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

n = int(input())
list1 = [''.join(sorted(input())) for i in range(n)]
dict1 = dict()
cout = 0
@lru_cache(maxsize = None)
def func(s):
	if s == 2:
		return 1 #2個の場合は1パターン
	return s-1 + func(s-1)

for i in range(n):
	if list1[i] in dict1:
		dict1[list1[i]] += 1
	else:
		dict1[list1[i]] = 1

for i in dict1:
	if dict1[i] != 1:
		cout += func(dict1[i])

print(cout)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

n = int(input())
list1 = [''.join(sorted(input())) for i in range(n)]
dict1 = dict()
cout = 0
@lru_cache(maxsize = None)
def func(s):
	if s == 2:
		return 1 #2個の場合は1パターン
	return s-1 + func(s-1)

for i in range(n):
	if list1[i] in dict1:
		dict1[list1[i]] += 1
	else:
		dict1[list1[i]] = 1

for i in dict1:
	if dict1[i] != 1:
		cout += func(dict1[i])

print(cout)
Problem p02958 (python)

Fixed submission:
import sys
N = int(input())
p = input()
list1 = list(map(int,p.split()))

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("YES")
    sys.exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("YES")
            sys.exit()
        else:
            print("NO")
            sys.exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
p = input()
list1 = list(map(int,p.split()))

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("YES")
    sys.exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("YES")
            sys.exit()
        else:
            print("NO")
            sys.exit()
Problem p02971 (python)

Fixed submission:
N = int(input())
A = []
m = 0
for i in range(N):
    A.append(int(input()))
task = 0
m = max(A)
m2 = sorted(A)[-2]
maxindex = []
for i in range(N):
    if A[i] == m:
        print(m2)
    else:
        print(m)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = []
for i in range(N):
    A += input()
    A[i] = int(A[i])
task = 0
m = 0
for i in range(N):
    task = A.pop(i)
    m = max(A)
    print(m)
    A.insert(i,task)
Problem p02993 (python)

Fixed submission:
S = input()
list1 = list(map(int,S))
#例えば4つ
a = list1[0]
b = list1[1]
c = list1[2]
d = list1[3]

if a == b:
    print("Bad")
elif b == c:
    print("Bad")
elif c == d:
    print("Bad")
else:
   print("Good")

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

if a == b:
    print("Bad")
elif b == c:
    print("Bad")
elif c == d:
    print("Bad")
else:
    print("Good")
Problem p03006 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
lst1 = [list(map(int,readline().split())) for i in range(n)]
lst1.sort()
cost = 1
if n == 1:
    print(cost)
    exit()
#同じベクトルでつなげる要素を最大化する。全点対象にベクトルを求め、多数決。
dic1 = dict()

for i in range(n-1):
    for j in range(i+1,n):
        x,y = lst1[i][0] - lst1[j][0] , lst1[i][1] - lst1[j][1]
        """
        if x < 0 and y < 0:
            x,y = -x,-y
        elif x < 0 and y >= 0:
            x,y = -x,-y"""
        if (x,y) in dic1:
            dic1[(x,y)] += 1
        else:
            dic1[(x,y)] = 1

#線分は頂点-1個。そのうち同ベクトル数が免除される。
cost += n-1
cost -= max(dic1.values())

print(cost)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
lst1 = [list(map(int,readline().split())) for i in range(n)]

cost = 1

#同じベクトルでつなげる要素を最大化する。全点対象にベクトルを求め、多数決。
dic1 = dict()

for i in range(n-1):
    for j in range(i+1,n):
        x,y = lst1[i][0] - lst1[j][0] , lst1[i][1] - lst1[j][1]
        if (x,y) in dic1:
            dic1[(x,y)] += 1
        else:
            dic1[(x,y)] = 1

#線分は頂点-1個。そのうち同ベクトル数が免除される。
cost += n-1
cost -= max(dic1.values())

print(cost)
Problem p03059 (python)

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

print(t//a*b)

Buggy submission (verdict: Runtime Error):
import fractions as math
#import fractions as math
n = int(input())
list1 = list(map(int,input().split()))
a = math.gcd(list1[0],list1[-1])
b = 0
for i in range(0,n):
	if a > math.gcd(a,list1[i]):
		a = math.gcd(a,list1[i])
		b = list1.index(list1[i])
del list1[b]
a = list1[0]
for i in range(0,len(list1)):
	a = min(a,math.gcd(a,list1[i]))
print(a)
Problem p03061 (python)

Fixed submission:
from collections import deque
import fractions as math
n = int(input())
list1 = list(map(int,input().split()))
list1 = deque(list1)
L = deque([0])
R = deque([0])
M = []

for i in range(len(list1)-1):
	L.append(math.gcd(L[i],list1[i]))
	R.append(math.gcd(R[i],list1[n-i-1]))

for i in range(len(L)):
	M.append(math.gcd(L[i],R[len(R)-i-1]))
print(max(M))

Buggy submission (verdict: Runtime Error):
import math
#import fractions as math
n = int(input())
list1 = list(map(int,input().split()))
a = 0
for i in range(n):
	L,R = 0,0
	for j in range(0,i):
		L = math.gcd(L,list1[j])
	for j in range(i+1,n):
		R = math.gcd(R,list1[j])
	a = max(a,math.gcd(L,R))

print(a)

Buggy submission (verdict: Runtime Error):
import fractions as math
n = int(input())
list1 = list(map(int,input().split()))

a = list1[0]
b = 0

for i in range(n):
	if a > math.gcd(a,list1[i]):
		a = math.gcd(a,list1[i])
		b = list1.index(list1[i])
if b == 1:
	if math.gcd(list1[0],list1[2]) < math.gcd(list1[1],list1[2]):
		b = 0
del list1[b]
a = list1[0]
for i in range(len(list1)):
	a = min(a,math.gcd(a,list1[i]))
print(a)

Buggy submission (verdict: Runtime Error):
import math
#import fractions as math
n = int(input())
list1 = list(map(int,input().split()))
if math.gcd(list1[0],list1[1]) < math.gcd(list1[0],list1[-1]):
	a = math.gcd(list1[0],list1[-1])
	b = 0
else:
	a = math.gcd(list1[0],list1[1])
	b = -1

for i in range(0,n):
	if a > math.gcd(a,list1[i]):
		a = math.gcd(a,list1[i])
		b = list1.index(list1[i])
del list1[b]
a = list1[0]
for i in range(0,len(list1)):
	a = min(a,math.gcd(a,list1[i]))
print(a)

Buggy submission (verdict: Runtime Error):
import math
#import fractions as math
n = int(input())
list1 = list(map(int,input().split()))
a = math.gcd(list1[0],list1[-1])
b = 0
for i in range(0,n):
	if a > math.gcd(a,list1[i]):
		a = math.gcd(a,list1[i])
		b = list1.index(list1[i])
del list1[b]
a = list1[0]
for i in range(0,len(list1)):
	a = min(a,math.gcd(a,list1[i]))
print(a)
Problem p03069 (python)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
s = readline().rstrip().decode('utf-8')
res = s.count(".")
ans = res
for i in range(n):
    if s[i] == "#":
        res += 1
    else:
        res -= 1
    ans = min(ans,res)

print(ans)

Buggy submission (verdict: Runtime Error):
"""
#の右に.が無いようにしたい
一番左にある#.もしくは一番右にある#の部分
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
s = readline().rstrip().decode('utf-8')
ans = 10**9
res = 0
for i in range(n-1):
    if s[i] == "#":
        if s[i+1] == ".":
            res = i
            break

ans = min(ans,s[i:].count("."))

ans = min(ans,s.count("#"),s.count("."))

print(ans)
Problem p03074 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,k = map(int,readline().split())
s = readline().rstrip().decode('utf-8')

if s[0] == 0: #反転からスタート
    r = 0
else: #無操作からスタート
    r = 1

if r==0:
    lst1 = [0] #裏からに調整
else:
    lst1 = []
res = 0
cache = str(r)
for i in s:
    if i != cache:
        lst1.append(res)
        cache = "1" if cache=="0" else "0"
        res = 1
    else:
        res += 1

lst1.append(res)
lst1.append(0)

#全部1で埋められるなら
if len(lst1) <= 2*k:
    print(n)
    exit()

#累積和
for i in range(len(lst1)-1):
    lst1[i+1] += lst1[i]

def cumsumdif(a,b,lst): #求めたい差のインデックスを入れる
    if a == 0:
        return lst[b]
    else:
        return lst[b] - lst[a-1]
i = 0
ans = 0
while True:
    if i+(k*2) >= len(lst1):
        break
    ans = max(ans,cumsumdif(i,i+2*k,lst1))
    i += 2

print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
list1 = list(map(int,input()))
list2 = []
count = 1
for i in range(1,n):
	if list1[i] != list1[i-1]:
		list2.append(count)
		count = 0
	count += 1
list2.append(count) #最後の処理
length = 0
list3 = []
#以下のループはn=1のときのみうまく動作しないので、例外処理
if n ==1:
	print(1)
	exit()

if list1[0] == 0: #長さはk*2
	length1 = k*2 #初期値
	length2 = k*2 + 1
	for i in range(len(list2)):
		if length != length1:
			length = length1
		else:
			length = length2
		if i+length >= n:
			break
		list3.append(sum(list2[i:i+length]))

else: #長さはk*2+1
	length1 = k*2 +1 #初期値
	length2 = k*2
	for i in range(len(list2)):
		if length != length1:
			length = length1
		else:
			length = length2
		if i+length >= n:
			break
		list3.append(sum(list2[i:i+length]))

print(max(list3))
Problem p03076 (python)

Fixed submission:
import math
list_str = []
list1 = []
for i in range(5):
	a = input()
	list_str.append(list(a))
	list1.append(int(a))


abs_max = 10
count = 0
for i in range(5):
	if int(list_str[i][-1]) != 0 and int(list_str[i][-1]) < abs_max:
		abs_max = int(list_str[i][-1])
for i in range(5):
	count += math.ceil(list1[i]/10)

if abs_max == 10:
	print(int(count*10))
else:
	print(int(count*10)-10+abs_max)

Buggy submission (verdict: Runtime Error):
list_str = []
list1 = []
for i in range(5):
	a = input()
	list_str.append(list(a))
	list1.append(int(a))


abs_max = 10
count = 0
for i in range(5):
	if int(list_str[i][-1]) != 0 and int(list_str[i][-1]) < abs_max:
		abs_max = int(list_str[i][-1])
for i in range(5):
	count += math.ceil(list1[i]/10)

if abs_max == 10:
	print(int(count*10))
else:
	print(int(count*10)-10+abs_max)
Problem p03229 (python)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = []
for i in range(n):
    lst1.append(int(readline()))
lst1.sort(reverse=True)
if n % 2 == 1:
    minority = n//2
    majority = n - minority
    A = sum(lst1[:minority])*2 - sum(lst1[minority:])*2+sum(lst1[minority:minority+2])
    B = sum(lst1[:majority])*2 - sum(lst1[majority:])*2 - sum(lst1[majority-2:majority])
    ans = max(A, B)
else:
    C = sum(lst1[:n//2])*2 - sum(lst1[n//2:])*2 + lst1[n//2]-lst1[n//2-1]
    D = -C
    ans = max(C, D)
print(ans)

Buggy submission (verdict: Runtime Error):
#Tenka1 Programmer Beginner Contest-C Align
"""
リストを並び替えて隣り合う要素の差の最大を出力
"""
import sys
from collections import deque
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = []
for i in range(n):
    lst1.append(int(readline()))

d = deque()

lst1.sort()
lst2 = lst1[:n//2] #小さい方
lst1 = lst1[n//2:] #大きい方
large = deque(lst1)
small = deque(lst2)
#2又に分かれるまで手動
res1 = large.pop()
res2 = small.popleft()
def func(x):
    global res1,res2
    if abs(res1-x) > abs(res2-x):
        res = abs(res1-x)
        res1 = x
        return res
    else:
        res = abs(res2-x)
        res2 = x
        return res

ans = res1-res2
ans += func(small.popleft())
while True:
    if not len(large):
        pass
    else:
        ans += func(large.pop())
    if not len(large):
        pass
    else:
        ans += func(large.pop())
    if not len(small):
        pass
    else:
        ans += func(small.popleft())
    if not len(small):
        pass
    else:
        ans += func(small.popleft())
    if not (len(large) or len(small)):
        print(ans)
        exit()
Problem p03263 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
h,w = map(int,readline().split())

lst1 = [list(map(int,readline().split())) for i in range(h)]
ans = []
for i in range(h):
    for j in range(w-1):
        if lst1[i][j] %2 == 1:
            ans.append([i,j,i,j+1])
            lst1[i][j+1] += 1

for i in range(h-1):
    if lst1[i][-1] %2 == 1:
        ans.append([i,w-1,i+1,w-1])
        lst1[i+1][-1] += 1

print(len(ans))
for i in ans:
    print(i[0]+1,i[1]+1,i[2]+1,i[3]+1)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
h,w = map(int,readline().split())

lst1 = [list(map(int,readline().split())) for i in range(h)]
ans = []
for i in range(h):
    for j in range(w-1):
        if lst1[i][j] %2 == 1:
            ans.append([i,j,i,j+1])
            lst1[i][j+1] += 1

for i in range(h-1):
    if lst1[i][-1] %2 == 1:
        ans.append([i,j,i+1,j])
        lst1[i+1][-1] += 1

print(len(ans))
for i in ans:
    print(i[0]+1,i[1]+1,i[2]+1,i[3]+1)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
h,w = map(int,readline().split())

lst1 = [list(map(int,readline().split())) for i in range(h)]
ans = []
for i in range(h):
    for j in range(w-1):
        if lst1[i][j] %2 == 1:
            ans.append([i,j,i,j+1])
            lst1[i][j+1] += 1

for i in range(h-1):
    if lst1[i][-1] %2 == 1:
        ans.append([i,j,i+1,j])
        lst1[i+1][j] += 1

print(len(ans))
for i in ans:
    print(i[0]+1,i[1]+1,i[2]+1,i[3]+1)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
h,w = map(int,readline().split())

lst1 = [list(map(int,readline().split())) for i in range(h)]
lst2 = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if lst1[i][j] %2 == 1:
            lst2[i][j] = 1

mask = [(-1,-1),(-1,1),(1,-1),(1,1)]
ans = []
for i in range(h):
    for j in range(w):
        if lst2[i][j] == 1:
            for XY in mask:
                if 0 <= i + XY[0] < w and 0 <= j + XY[1] < h \
                and lst2[i + XY[0]][j + XY[1]] == 1:
                    lst2[i][j] -= 1
                    lst2[i + XY[0]][j + XY[1]] -= 1
                    ans.append([i,j,i + XY[0],j])
                    ans.append([i+ XY[0],j,i+ XY[0],j+XY[1]])



print(len(ans))
for i in ans:
    print(i[0]+1,i[1]+1,i[2]+1,i[3]+1)