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

Fixed submission:
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

xs = 0
for i in range(N):
    xs += i  * X[i]
    xs -= (N - i - 1) * X[i]
    xs %= MOD
ys = 0
for i in range(M):
    ys += i  * Y[i]
    ys -= (M - i - 1) * Y[i]
    ys %= MOD
print(xs * ys % MOD)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

xs = 0
for i in range(N):
    xs += i  * X[i]
    xs -= (N - i - 1) * X[i]
    xs %= MOD
ys = 0
for i in range(M):
    ys += i  * Y[i]
    ys -= (M - i - 1) * Y[i]
    ys %= MOD
print(xs * ys % MOD)
Problem p03829 (python)

Fixed submission:
N, A, B = map(int, input().split())
X = list(map(int, input().split()))

ans = 0
for i in range(1, N):
    d = X[i] - X[i - 1]
    if d * A > B:
        ans += B
    else:
        ans += d * A
print(ans)

Buggy submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
X = list(map(int, input().split()))

ans = 0
for i in range(1, N):
    d = X[i] - X[i - 1]
    if d * A > B:
        ans += B
    else:
        ans += d * A
print(ans
Problem p03958 (python)

Fixed submission:

K, T = map(int, input().split())
A = list(map(int, input().split()))

A = sorted(A, reverse=True)

print(max(0, A[0] - 1 - sum(A[1:])))

Buggy submission (verdict: Runtime Error):
K, T = map(int, input().split())
A = list(map(int, input().split()))

A = sorted(A, reverse=True)

print(max(0, A[0] - 1 - sum(A[1:]))
Problem p03963 (python)

Fixed submission:
N, K = map(int, input().split())
print(K * ((K - 1) ** (N - 1)))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
print(K * ((K - 1) ** (N - 1))
Problem p03994 (python)

Fixed submission:
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
K = int(input())

ans = []
for i, c in enumerate(S):
    if c == 'a':
        ans.append(c)
        continue
    num = ord('z') - ord(c) + 1
    if K >= num:
        K -= num
        ans.append('a')
    else:
        ans.append(c)
if K > 0:
    ans[-1] = chr((ord(ans[-1]) - ord('a') + K % 26) % 26 + ord('a'))
print("".join(ans))

Buggy submission (verdict: Runtime Error):
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
K = int(input())

ans = []
for i, c in enumerate(S):
    num = ord('z') - ord(c) + 1
    if K >= num:
        K -= num
        ans.append('a')
    else:
        ans.append(c)
if K > 0:
    ans[-1] = chr((ord(S[-1]) - ord('a') + K) % 26 + ord('a'))
print("".join(an))
Problem p04031 (python)

Fixed submission:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())
A = list(map(int, input().split()))

ans = INF
for i in range(-100, 101):
    val = 0
    for a in A:
        val += (a - i) ** 2
    ans = min(ans, val)
print(ans)

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

ans = INF
for i in range(-100, 101):
    val = 0
    for a in A:
        val += (a - i) ** 2
    ans = min(ans, val)
print(ans)
Problem p02743 (python)

Fixed submission:
A=list(map(int, input().split()))
a=A[0]
b=A[1]
c=A[2]
print('No') if c<a+b or 4*a*b+2*c*(a+b)>=c*c+(a+b)**2 else print('Yes')

Buggy submission (verdict: Runtime Error):
#include<iostream>
main(){long a,b,c;std::cin>>a>>b>>c;std::cout<<(4*a*b+2*c*(a+b)<c*c+(a+b)*(a+b)&&c>=a+b?"Yes":"No");}
Problem p02761 (python)

Fixed submission:
N, M = list(map(int, input().split()))
s, c = [], []
mapSC = {}
for _ in range(M):
    si, ci = list(map(int, input().split()))
    s.append(si)
    c.append(ci)
    if si not in mapSC:
        mapSC[si] = ci
    else:
        if mapSC[si] != ci:
            print("-1")
            exit(0)

if len(mapSC) > N:
    print("-1")
    exit(0)

# if N > 1 and s[0] == 0:
#     print("-1")
#     exit(0)

if N == 1:
    rb, re = 0, 10
elif N == 2:
    rb, re = 10, 100
else:
    rb, re = 100, 1000

ans = -1
for v in range(rb, re):
    sv = "{}".format(v)
    lf = []
    for i in range(M):
        lf.append(int(sv[s[i] - 1]) == int(c[i]))
    if all(lf):
        ans = v
        break
    # print(sv, lf, all(lf))

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
s, c = [], []
mapSC = {}
for _ in range(M):
    si, ci = list(map(int, input().split()))
    s.append(si)
    c.append(ci)
    if si not in mapSC:
        mapSC[si] = ci
    else:
        if mapSC[si] != ci:
            print("-1")
            exit(0)

if len(mapSC) > N:
    print("-1")
    exit(0)

if N > 1 and s[0] == 0:
    print("-1")
    exit(0)

if s == 1:
    rb, re = 0, 10
elif s == 2:
    rb, re = 10, 100
else:
    rb, re = 100, 1000

ans = -1
for v in range(rb, re):
    sv = "{}".format(v)
    lf = []
    for i in range(M):
        lf.append(int(sv[s[i] - 1]) == int(c[i]))
    if all(lf):
        ans = v
        break
    # print(sv, lf, all(lf))

print(ans)
Problem p02843 (python)

Fixed submission:
X = int(input())

dp = [False for _ in range(110000)]
dp[0] = True

price = [100, 101, 102, 103, 104, 105]

for i in range(X + 1):
    if dp[i]:
        for p in price:
            dp[i + p] = True

if dp[X]:
    print(1)
else:
    print(0)

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

dp = [False for _ in range(100000)]
dp[0] = True

price = [100, 101, 102, 103, 104, 105]

for i in range(X + 1):
    if dp[i]:
        for p in price:
            dp[i + p] = True

if dp[X]:
    print(1)
else:
    print(0)
Problem p02937 (python)

Fixed submission:
# https://atcoder.jp/contests/abc138/tasks/abc138_e

from collections import defaultdict
from bisect import bisect_right

S = input()
T = input()

# Sの中での位置
iS = defaultdict(list)
for (idx, ch) in enumerate(S):
    iS[ch].append(idx)

# Tの文字はSに出ていないといけない
for v in T:
    if v not in iS:
        print(-1)
        exit()

# 探索
cnt = 0
cur = -1
for v in T:
    i = bisect_right(iS[v], cur)
    if i == len(iS[v]):
        j = iS[v][0]
    else:
        j = iS[v][i]

    if cur >= j:
        cnt += 1
    cur = j

print(cnt * len(S) + cur + 1)

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc138/tasks/abc138_e

from collections import defaultdict
from bisect import bisect_right

S = input()
T = input()

# Tの文字はSに出ていないといけない
for ch in T:
    if ch not in S:
        print("-1")
        exit()

# Sの中での位置
iS = defaultdict(list)
for (idx, ch) in enumerate(S):
    iS[ch].append(idx)

# 探索
cnt = 0
cur = -1
for v in T:
    i = bisect_right(iS[ch], cur)
    if i == len(iS[v]):
        j = iS[v][0]
    else:
        j = iS[v][i]

    if cur >= j:
        cnt += 1
    cur = j

print(cnt * len(S) + cur + 1)

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc138/tasks/abc138_e

from collections import defaultdict
from bisect import bisect_right

S = input()
T = input()

# Tの文字はSに出ていないといけない
for ch in T:
    if ch not in S:
        print("-1")
        exit()

# Sの中での位置
iS = defaultdict(list)
for (idx, ch) in enumerate(S):
    iS[ch].append(idx)

# 探索
cnt = 0
cur = -1
for v in T:
    i = bisect_right(iS[ch], cur)
    if i == len(iS[v]):
        j = iS[v][0]
    else:
        j = iS[v][i]

    if cur >= j:
        cnt += 1
    cur = j

print(cnt * len(S) + cur + 1)
Problem p03079 (python)

Fixed submission:
a, b, c = map(int, input().split())
if a == b and b == c:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a, b, c == map(int, input().split())
if a == b and b == c:
  print("Yes")
else:
  print("No")
Problem p03096 (python)

Fixed submission:
# 解説 https://betrue12.hateblo.jp/entry/2019/03/17/011847
# from collections import defaultdict

mod = 10 ** 9 + 7

N = int(input())
C = [int(input()) for _ in range(N)]
# L = [-1] * (N + 10)  # 出たところ
# dp = [-1] * (N + 10)
# dp[0] = 1
L  = [-1] * (2*10**5 + 10)
dp = [-1] * (2*10**5 + 10)
dp[0] = 1
 

for i in range(N):
    if L[C[i]] == -1:
        dp[i + 1] = dp[i]
    elif C[i] == C[i - 1]:
        dp[i + 1] = dp[i]
    else:
        dp[i + 1] = dp[i] + dp[L[C[i]]]
    
    dp[i + 1] %= mod
    L[C[i]] = i + 1

print(dp[N])

Buggy submission (verdict: Runtime Error):
# 解説 https://betrue12.hateblo.jp/entry/2019/03/17/011847

from collections import defaultdict

mod = 10 ** 9 + 7

N = int(input())
C = [int(input()) for _ in range(N)]
L = [-1] * (N + 10)  # 出たところ
dp = [-1] * (N + 10)
dp[0] = 1

for i in range(N):
    if L[C[i]] == -1:
        dp[i + 1] = dp[i]
    elif C[i] == C[i - 1]:
        dp[i + 1] = dp[i]
    else:
        dp[i + 1] = dp[i] + dp[L[C[i]]]
    
    dp[i + 1] %= mod
    L[C[i]] = i + 1

print(dp[N])

Buggy submission (verdict: Runtime Error):
# 解説 https://betrue12.hateblo.jp/entry/2019/03/17/011847

from collections import defaultdict

mod = 10 ** 9 + 7

N = int(input())
C = [int(input()) for _ in range(N)]
L = [-1] * (N + 1)  # 出たところ
dp = [-1] * (N + 1)
dp[0] = 1

for i in range(N):
    if L[C[i]] == -1:
        dp[i + 1] = dp[i]
    elif C[i] == C[i - 1]:
        dp[i + 1] = dp[i]
    else:
        dp[i + 1] = dp[i] + dp[L[C[i]]]
    
    dp[i + 1] %= mod
    L[C[i]] = i + 1

print(dp[N])

Buggy submission (verdict: Runtime Error):
# 解説 https://betrue12.hateblo.jp/entry/2019/03/17/011847

from collections import defaultdict

mod = 10 ** 9 + 7

N = int(input())
C = [int(input()) for _ in range(N)]
dp = [0] * (N + 1)
dp[0] = 1

for i in range(1, N):
    if C[i] == C[i - 1]:
        dp[i] = dp[i - 1]
    else:
        max_k = -1
        for k in range(i - 1):
            if C[k] == C[i]:
                max_k = max(max_k, k)
        if max_k == -1:
            dp[i] = dp[i - 1]
        else:
            dp[i] = dp[i - 1] + dp[max_k]

print(dp[N - 1])y
Problem p03155 (python)

Fixed submission:
from math import ceil
n = int(input())
a = int(input())
b = int(input())
print((n - a + 1) * (n - b + 1))

Buggy submission (verdict: Runtime Error):
from math import floor
n = int(input())
a = int(input())
b = int(input())

print(ceil(n / a) * ceil(n / b))
Problem p03157 (python)

Fixed submission:
# https://atcoder.jp/contests/aising2019/tasks/aising2019_c

import sys
sys.setrecursionlimit(10 ** 7)

H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]
seen = [[False for _ in range(W)] for _ in range(H)]


def dfs(h, w, ph, pw):
    if M[h][w] == '.':
        bc, wc = 0, 1
    else:
        bc, wc = 1, 0
    for (dh, dw) in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        nh, nw = h + dh, w + dw
        if nh < 0 or H <= nh or nw < 0 or W <= nw:
            continue
        if nh == ph and nw == pw:
            continue
        if seen[nh][nw]:
            continue
        if M[nh][nw] == M[h][w]:
            continue
        seen[nh][nw] = True
        b_add, w_add = dfs(nh, nw, h, w)
        bc += b_add
        wc += w_add
    return bc, wc

ans = 0
for h in range(H):
    for w in range(W):
        if seen[h][w] == False:
            seen[h][w] = True
            b, w = dfs(h, w, -1, -1)
            ans += b * w
print(ans)

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/aising2019/tasks/aising2019_c

H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]
seen = [[False for _ in range(W)] for _ in range(H)]


def dfs(h, w, ph, pw):
    if M[h][w] == '.':
        bc, wc = 0, 1
    else:
        bc, wc = 1, 0
    for (dh, dw) in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        nh, nw = h + dh, w + dw
        if nh < 0 or H <= nh or nw < 0 or W <= nw:
            continue
        if nh == ph and nw == pw:
            continue
        if seen[nh][nw]:
            continue
        if M[nh][nw] == M[h][w]:
            continue
        seen[nh][nw] = True
        b_add, w_add = dfs(nh, nw, h, w)
        bc += b_add
        wc += w_add
    return bc, wc

ans = 0
for h in range(H):
    for w in range(W):
        if seen[h][w] == False:
            seen[h][w] = True
            b, w = dfs(h, w, -1, -1)
            ans += b * w
print(ans)

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/aising2019/tasks/aising2019_c

H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]
seen = [[False] * W for _ in range(H)]


def dfs(h, w, ph, pw, color):
    nc = "." if color == "#" else "#"
    bc, bw = 0, 0
    if color == '#':
        bc += 1
    if color == '.':
        bw += 1
    
    path = []
    for (dh, dw) in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        nh, nw = h + dh, w + dw
        if nh < 0 or H <= nh or nw < 0 or W <= nw:
            continue
        if nh == ph and nw == pw:
            continue
        if seen[nh][nw]:
            continue
        if M[nh][nw] != nc:
            continue

        seen[nh][nw] = True
        b_add, w_add = dfs(nh, nw, h, w, nc)
        bc += b_add
        bw += w_add
    return bc, bw

ans = 0
for h in range(H):
    for w in range(W):
        if seen[h][w] == False:
            seen[h][w] = True
            (b, w) = dfs(h, w, -1, -1, M[h][w])
            ans += b * w
print(ans)
Problem p03231 (python)

Fixed submission:
from fractions import gcd

N, M = map(int, input().split())
S = input()
T = input()

lcm = N * M // gcd(N, M)
n = N // gcd(N, M)
m = M // gcd(N, M)

for k in range(gcd(N, M)):
    a = k * n
    b = k * m
    if S[a] != T[b]:
        print(-1)
        exit()

print(lcm)

Buggy submission (verdict: Runtime Error):
#
# N M
# S
# T
#
# find X (length L, LはN, Mで割り切れる (最小公倍数))
#
# e.g.
# 3 2
# acp
# ae
#
# X
# - 
# - 1, L/N+1, 2L/N+1, ... はSになる
# - 1, L/M+1, 2L/M+1, ... はTになる

from fractions import gcd

N, M = map(int, input().split())
S = input()
T = input()
L = N * M // gcd(N, M)

if S[0] != T[0]:
    print(-1)
    exit()

# 仮の文字列 (中身は何でもいい)
ans = [S[0]] + ["-"] * (L - 1)

# Sを置く
for i in range(N):
    ans[i * L // N] = S[i]

# print(ans)

# Tを置く
# 既にSが入っている場合，Tと整合するか確認する
for i in range(M):
    index = i * L // M
    if ans[index] != "-":
        if ans[index] != T[i]:
            print(-1)
            exit()
        else:
            ans[index] = T[i]
    else:
        ans[index] = T[i]


print(L)
Problem p03427 (python)

Fixed submission:
N = input()
if len(N) == 1:
  # 1桁の数字
  print(N)
elif all(map(lambda x: x == '9', N[1:])):
  # 下位が全部9の場合
  print(sum(int(n) for n in N))
else:
  # 下位を全部9にする例
    print(9 * (len(N) - 1) + int(N[0]) - 1)

Buggy submission (verdict: Runtime Error):
-*- coding: utf-8 -*-
N = input()

if len(N) == 1:
  # 1桁の数字
  print(N)
elif all(map(lambda x: x == '9', N[1:])):
  # 下位が全部9の場合
  print(sum(int(n) for n in N))
else:
  # 下位を全部9にする例
    print(9 * (len(N) - 1) + int(N[0]) - 1)
Problem p03476 (python)

Fixed submission:
'''
https://atcoder.jp/contests/abc084/tasks/abc084_d
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    def primecheck(n):
        p = [True] * (n + 1)
        p[0] = False
        p[1] = False
        for i in range(2, int(n ** 0.5) + 1):
            if p[i]:
                for j in range(i * i, n + 1, i):
                    p[j] = False
        return p
    
    p = primecheck(10**5)
    cnt = 0
    res = [0]*(10**5)
    for i in range(10**5):
        if p[i]==p[(i+1)//2]==1:
            cnt += 1
        res[i] = cnt


    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        print(res[r]-res[l-1])

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# Q = int(input())

Qmax = 100_001
is_prime = [True] *  Qmax
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(Qmax ** 0.5) + 1):
    if is_prime[i]:
        for j in range(i * i, Qmax, i):
            is_prime[j] = False

# 1 ~ 10^5を先に計算する
cnt = 0
res = [0]*(10**5)
for i in range(10**5):
    if is_prime[i] and is_prime[(i+1)//2]:
        cnt += 1
    res[i] = cnt


# 計算
Q = int(input())
for q in range(Q):
    li, ri = map(int, input().split())
    print(res[ri] - res[li - 1])

Buggy submission (verdict: Runtime Error):
# Q = int(input())

def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return is_prime

prime_flag_list = primes(100_001)


# 1 ~ 10^5を先に計算する
list_flag = [False] * (100_001)
for n in range(1, 100_000 + 1, 2):
    if prime_flag_list[n] and prime_flag_list[(n + 1) // 2]:
        list_flag[n] = True

# 計算
Q = int(input())
for q in range(Q):
    li, ri = map(int, input().split())
    x = 0
    for i in range(li, ri+1, 2):
        if list_flag[i]:
            x += 1
    print(x)
Problem p03578 (python)

Fixed submission:
from collections import Counter, defaultdict

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

memo = defaultdict(int)
for d in D:
    memo[d] += 1

for i in range(M):
    ti = T[i]
    if ti not in memo:
        print("NO")
        exit()
    if memo[ti] == 0:
        print("NO")
        exit()
    memo[ti] -= 1

print("YES")

Buggy submission (verdict: Runtime Error):
from collections import Counter, defaultdict

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

memo = defaultdict(int)
for d in D:
    memo[d] += 1

for i in range(m):
    ti = T[i]
    if ti not in memo:
        print("NO")
        exit()
    if memo[ti] == 0:
        print("NO")
        exit()
    memo[ti] -= 1

print("YES")
Problem p03651 (python)

Fixed submission:
from fractions import gcd

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

M = max(A)
G = A[0]
for i in range(1, N):
    G = gcd(G, A[i])

if K <= M and K % G == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

M = max(A)
G = gcd(A[0], A[1])
for i in range(2, N):
    G = gcd(G, A[i])
# print(M, G)

if K <= M and K % G == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

if K in A:
    print("POSSIBLE")
    exit(0)

An = A.copy()
for i in range(len(A)):
    for j in range(i + 1, len(A)):
        aij = abs(A[i] - A[j])
        if aij not in An:
            An.append(aij)

if K in A:
    print("POSSIBLE")
    exit(0)

while A != An:
    A = An.copy()
    for i in range(len(A)):
        for j in range(i + 1, len(A)):
            aij = abs(A[i] - A[j])
            if aij not in An:
                An.append(aij)

    # print(A)
    # print(An)

    if K in A:
        print("POSSIBLE")
        exit(0)

if K in An:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03992 (python)

Fixed submission:
s = input()
print("{} {}".format(s[:4], s[4:]))

Buggy submission (verdict: Runtime Error):
s = input()
print("{} {}".format(s[:4], s[4:])
Problem p02586 (python)

Fixed submission:
rows, cols, k = map(int, input().split())
items = [[] for _ in range(rows+1)]
best = [0]*(cols+1)
for _ in range(k):
	r, c, v = map(int, input().split())
	items[r].append([c, v])
for i in range(rows+1):
	items[i].sort()
ans = 0
for r in range(1, rows+1):
	dp = []
	best1, best2 = 0, 0
	Row = items[r]
	for c, v in Row:
		v1 = best[c] + v
		v2 = best1 + v
		v3 = best2 + v
		V = max(v1, v2, v3)
		dp.append(V)
		if v1 > best1:
			best1 = v1
		if v2 > best2:
			best2 = v2
		if ans < V:
			ans = V
	for j in range(len(dp)):
		if best[Row[j][0]] < dp[j]:
			best[Row[j][0]] = dp[j]
	for j in range(2, cols+1):
		if best[j] < best[j-1]:
			best[j] = best[j-1]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0

rows, cols, k = inp[ii:ii+3]; ii += 3
items = [[] for _ in range(rows+1)]
best = [0]*(cols+1)
for _ in range(k):
	inp[ii:ii+3]; ii += 3
	items[r].append([c, v])
for i in range(rows+1):
	items[i].sort()
ans = 0
for r in range(1, rows+1):
	dp = []
	best1, best2 = 0, 0
	Row = items[r]
	for c, v in Row:
		v1 = best[c] + v
		v2 = best1 + v
		v3 = best2 + v
		V = v1
		if V < v2:
			V = v2
		if V < v3:
			V = v3
		dp.append(V)
		if v1 > best1:
			best1 = v1
		if v2 > best2:
			best2 = v2
		if ans < V:
			ans = V
	for j in range(len(dp)):
		if best[Row[j][0]] < dp[j]:
			best[Row[j][0]] = dp[j]
	for j in range(2, cols+1):
		if best[j] < best[j-1]:
			best[j] = best[j-1]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

inp = [int(x) for x in sys.stdin.readline()]; ii = 0

rows, cols, k = inp[ii:ii+3]; ii += 3
items = [[] for _ in range(rows+1)]
best = [0]*(cols+1)
for _ in range(k):
	inp[ii:ii+3]; ii += 3
	items[r].append([c, v])
for i in range(rows+1):
	items[i].sort()
ans = 0
for r in range(1, rows+1):
	dp = []
	best1, best2 = 0, 0
	Row = items[r]
	for c, v in Row:
		v1 = best[c] + v
		v2 = best1 + v
		v3 = best2 + v
		V = v1
		if V < v2:
			V = v2
		if V < v3:
			V = v3
		dp.append(V)
		if v1 > best1:
			best1 = v1
		if v2 > best2:
			best2 = v2
		if ans < V:
			ans = V
	for j in range(len(dp)):
		if best[Row[j][0]] < dp[j]:
			best[Row[j][0]] = dp[j]
	for j in range(2, cols+1):
		if best[j] < best[j-1]:
			best[j] = best[j-1]
print(ans)
Problem p02556 (python)

Fixed submission:
n = int(input())

p_one = input()
p_one_list = p_one.split(' ')

zmax = int(p_one_list[0]) + int(p_one_list[1])
zmin = int(p_one_list[0]) + int(p_one_list[1])
wmax = int(p_one_list[0]) - int(p_one_list[1])
wmin = int(p_one_list[0]) - int(p_one_list[1])


for i in range(1, n):
    line = input()
    tmp = line.split(' ')
    z = int(tmp[0]) + int(tmp[1])
    w = int(tmp[0]) - int(tmp[1])
    zmax = max(zmax, z)
    wmax = max(wmax, w)
    zmin = min(zmin, z)
    wmin = min(wmin, w)


z_ans = zmax - zmin
w_ans = wmax - wmin


print(f'{max(z_ans, w_ans)}')

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

z_vec = [0] * n
w_vec = [0] * n


for i in range(0, n + 1):
    line = input()
    tmp = line.split()
    z_vec[i] = int(tmp[0]) + int(tmp[1])
    w_vec[i] = int(tmp[0]) - int(tmp[1])

z_ans = max(z_vec) - min(z_vec)
w_ans = max(w_vec) - min(w_vec)


print(f'{max(z_ans, w_ans)}')

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

z_vec = [0] * n
w_vec = [0] * n


for i in range(0, n + 1):
    tmp = input().split()
    z_vec[i] = int(tmp[0]) + int(tmp[1])
    w_vec[i] = int(tmp[0]) - int(tmp[1])

z_ans = max(z_vec) - min(z_vec)
w_ans = max(w_vec) - min(w_vec)


print(f'{max(z_ans, w_ans)}')