Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from functools import lru_cache

@lru_cache(maxsize=None)
def g(N, K):
    if N == K == 0:
        return tuple()
    if K < 0 or N <= 0:
        return None
    # ノードの周りにi個のノードを生やす
    t = 0
    for i in range(1, N+1):
        # ノードをi個足すとcomb(i,2)個の最短距離2の頂点対ができる
        t += i
        # 足したノードの内の1つから更にノードを生やす
        res = g(N-i, K-t)
        if res is not None:
            return res + (i,)
    return None

def f(N, K):
    '''
    >>> f(5, 3)
    (1, 1, 1, 0)
    >>> f(5, 8) # return None
    >>> f(3, 1)
    (1, 0)
    >>> f(4, 2)
    (1, 1, 0)
    >>> f(4, 3)
    (2, 0)
    >>> f(5, 4)
    (2, 1, 0)
    >>> f(5, 6)
    (3, 0)
    '''
    # 始め、ノードは1つあった
    n = N - 1
    t = 0
    for i in range(1, N):
        # ノードをi個生やすとcomb(i-1,2)個の最短距離2の頂点対ができる
        t += i - 1
        # 足したノードの内の1つから更にノードを生やす
        res = g(n-i, K-t)
        if res is not None:
            return res + (i-1,)
    return res

def solve(N: int, K: int):
    from itertools import count
    edges = []
    res = f(N, K)
    if res is None:
        print(-1)
        return
    edges = []
    for i in range(len(res)):
        edges.append((i+1, i+2))
    c = count(len(res)+1)
    for p, n in enumerate(res, 1):
        for _ in range(n-1):
            edges((p, next(c)))
    print(len(edges))
    for u, v in edges:
        print(u, v)




# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main()


Fixed submission:
#!/usr/bin/env python3
import sys

def solve(N: int, K: int):
    k = (N - 1) * (N - 2) // 2
    if k < K:
        return None
    edges = [(1, i) for i in range(2, N+1)]
    def f():
        for i in range(2, N+1):
            for j in range(i+1, N+1):
                yield i, j
    it = f()
    while k > K:
        edges.append(next(it))
        k -= 1
    return edges

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    edges = solve(N, K)
    if edges:
        print(len(edges))
        for e in edges:
            print(*e)
    else:
        print(-1)

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main()
Buggy python submission (verdict: Runtime Error):
def f(y, m):
	if y in range(1, 13) and m in range(1, 13):
      return "AMBIGUOUS"
    if m in range(1, 13):
      return "YYMM"
    if y in range(1, 13):
      return "MMYY"
    return "NA"
  
S = input()
y, m = int(S[:2]), int(S[2:])
print(f(y, m))
  

Fixed submission:
def f(y, m):
	if y in range(1, 13) and m in range(1, 13):
		return "AMBIGUOUS"
	if m in range(1, 13):
		return "YYMM"
	if y in range(1, 13):
		return "MMYY"
	return "NA"
  
S = input()
y, m = int(S[:2]), int(S[2:])
print(f(y, m))
Buggy python submission (verdict: Runtime Error):
a = [int(input()) for _ in range(6)]
print('Yay!' if a[-2]-a[0]=<a[-1] else ':(') 

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(a: int, b: int, c: int, d: int, e: int, k: int):
    X = (a, b, c, d, e)
    for i, x in enumerate(X):
        for xx in X[i+1:]:
            if abs(x - xx) > k:
                return ':('
    return 'Yay!'

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    e = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    print(solve(a, b, c, d, e, k))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind(object):
 
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]
 
    def find(self, x):
        if self.table[x] < 0:
            return x
        self.table[x] = self.find(self.table[x])
        return self.table[x]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 == s2:
            return False
        if self.table[s1] > self.table[s2]:
            s1, s2 = s2, s1
        self.table[s1] += self.table[s2]
        self.table[s2] = s1
        return True

H, W = list(map(int, input().split()))
S = list(input() for _ in range(H))
uf = UnionFind(H*W)

def get(h, w):
    return h * W + w

for h in range(H):
    for w in range(W):        
        for dh, dw in zip((0, 1), (1, 0)):
            if (h + dh) >= H or (w + dw) >= W:
                continue
            if S[h][w] != S[h+dh][w+dw]:
                uf.union(get(h, w), get(h+dh, w+dw))


from itertools import product

C1 = [(h, w) for h, w in product(range(H), range(W)) if S[h][w] == "."]
C2 = [(h, w) for h, w in product(range(H), range(W)) if S[h][w] == "#"]

ans = 0
for h1, w1 in C1:
    for h2, w2 in C2:
        if uf.same(get(h1, w1), get(h2, w2)):
            ans += 1
print(ans)


Fixed submission:
class UnionFind(object):
 
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]
 
    def find(self, x):
        if self.table[x] < 0:
            return x
        self.table[x] = self.find(self.table[x])
        return self.table[x]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 == s2:
            return False
        if self.table[s1] > self.table[s2]:
            s1, s2 = s2, s1
        self.table[s1] += self.table[s2]
        self.table[s2] = s1
        return True

H, W = list(map(int, input().split()))
S = list(input() for _ in range(H))
uf = UnionFind(H*W)

def get(h, w):
    return h * W + w

for h in range(H):
    for w in range(W):        
        for dh, dw in zip((0, 1), (1, 0)):
            if (h + dh) >= H or (w + dw) >= W:
                continue
            if S[h][w] != S[h+dh][w+dw]:
                uf.union(get(h, w), get(h+dh, w+dw))


from itertools import product

C1 = []
C2 = []

for h in range(H):
    for w in range(W):
        if S[h][w] == ".":
            C1.append((h, w))
        else:
            C2.append((h, w))

white = [0] * (H * W)
black = [0] * (H * W)

for h in range(H):
    for w in range(W):
        n = get(h, w)
        par = uf.find(n)
        # print(h, w, n, par)
        if par < 0:
            par = n
        if S[h][w] == ".":
            white[par] += 1
        else:
            black[par] += 1
            
ans = 0
# print(white)
# print(black)
for h in range(H):
    for w in range(W):
        n = get(h, w)
        ans += white[n] * black[n]
print(ans)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(S: int, K: int):
    for i, s in enumerate(str(S)):
        if s != '1':
            return s
        if K == i:
            return s
    raise

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(solve(S, K))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(S: int, K: int):
    for i, s in enumerate(str(S)[:K]):
        if s != '1':
            return s
    return 1

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(solve(S, K))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
MOD = 1000000007

def solve(N: int, A: "List[int]"):
    l, r = 0, 1
    sux, su, ans = A[0], A[0], 0
    while l < len(A):
        while r < len(A) and (sux ^ A[r]) == (su + A[r]):
            sux ^= A[r]
            su += A[r]
            r += 1
        ans += r - l
        sux ^= A[l]
        su -= A[l]
        l += 1
    return ans

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, A))

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
MOD = 1000000007

def solve(N: int, A: "List[int]"):
    l, r = 0, 1
    sux, su, ans = A[0], A[0], 0
    while l < len(A):
        while r < len(A) and (sux ^ A[r]) == (su + A[r]):
            sux ^= A[r]
            su += A[r]
            r += 1
        ans += r - l
        sux ^= A[l]
        su -= A[l]
        l += 1
    return ans

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, A))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, A: "List[List[int]]", B: "List[List[int]]"):
    from itertools import chain
    dp = [[set() for _ in range(W+1)] for _ in range(H+1)]
    dp[0][0].add(0)
    for h in range(H):
        for w in range(W):
            d = A[h][w] - B[h][w]
            for v in dp[h][w]:
                dp[h+1][w].add(v+d)
                dp[h+1][w].add(v-d)
                dp[h][w+1].add(v+d)                                            
                dp[h][w+1].add(v-d)
    return min(map(abs, chain(dp[H-1][W], dp[H][W-1])))

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  # type: "List[List[int]]"
    B = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  # type: "List[List[int]]"
    print(solve(H, W, A, B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Fixed submission:
S = sorted(input())
T = sorted(input(), reverse=True)
print("Yes" if T > S else "No")
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]", Q: int, K: int, x: "List[int]", y: "List[int]"):
    edges = [[] for _ in range(N+1)]
    for aa, bb, cc in zip(a, b, c):
        edges[aa].append((bb, cc))
        edges[bb].append((aa, cc))
    costs = [None] * (N + 1)
    def dfs(n, c):
        if costs[n] is not None:
            return
        costs[n] = c
        for nn, cc in edges[n]:
            dfs(nn, c+cc)
    dfs(K, 0)
    for xx, yy in zip(x, y):
        print(costs[xx]+costs[yy])
    return

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    c = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    Q = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (Q)  # type: "List[int]"
    y = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, a, b, c, Q, K, x, y)

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(200000)

def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]", Q: int, K: int, x: "List[int]", y: "List[int]"):
    edges = [[] for _ in range(N+1)]
    for aa, bb, cc in zip(a, b, c):
        edges[aa].append((bb, cc))
        edges[bb].append((aa, cc))
    costs = [None] * (N + 1)
    def dfs(n, cost):
        if costs[n] is not None:
            return
        costs[n] = cost
        for nn, cc in edges[n]:
            dfs(nn, cost+cc)
    dfs(K, 0)
    for xx, yy in zip(x, y):
        print(costs[xx]+costs[yy])
    return

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    c = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    Q = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (Q)  # type: "List[int]"
    y = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, a, b, c, Q, K, x, y)

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(max(i if 2 ** i <= N else 0 for i in range(10))

Fixed submission:
N = int(input())
print(max(2 ** i if 2 ** i <= N else 0 for i in range(10)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [int(input()) for _ in range(N)]
table = [False] * (100 * 100 + 1)
table[0] = True
ma = 0
for s in S:
    ma += s
    for i in range(ma, -1, -1):
        table[i+s] |= table[i]
for i in range(ma, -1, -1):
    if i % 10 != 0 and table[i]:
        print(i)
        break
else:
    print(0)



Fixed submission:
N = int(input())
S = [int(input()) for _ in range(N)]
table = [False] * (200 * 200 + 1)
table[0] = True
ma = 0
for s in S:
    ma += s
    for i in range(ma, -1, -1):
        table[i+s] |= table[i]
for i in range(ma, -1, -1):
    if i % 10 != 0 and table[i]:
        print(i)
        break
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [int(input()) for _ in range(N)]
table = [False] * (100 * 100 + 1)
table[0] = True
ma = 0
for s in S:
    ma += s
    for i in range(ma, -1, -1):
        table[i+s] |= table[i]
for i in range(ma, -1, -1):
    if i % 10 != 0 and table[i]:
        print(i)
        break



Fixed submission:
N = int(input())
S = [int(input()) for _ in range(N)]
table = [False] * (200 * 200 + 1)
table[0] = True
ma = 0
for s in S:
    ma += s
    for i in range(ma, -1, -1):
        table[i+s] |= table[i]
for i in range(ma, -1, -1):
    if i % 10 != 0 and table[i]:
        print(i)
        break
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
G = [set([1,3,5,7,8,10,12]), set([4,6,9,11]), set([2])]
def check(x, y):
  for g in G:
    if x in g and y in g:
      return True
  return False
print("Yes" if check(x, y) else "No")

Fixed submission:
G = [set([1,3,5,7,8,10,12]), set([4,6,9,11]), set([2])]
def check(x, y):
  for g in G:
    if x in g and y in g:
      return True
  return False
x, y = map(int, input().split())
print("Yes" if check(x, y) else "No")
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def f(H, W):
    mh = H // 2
    mw = W // 2
    return (mh*W, (H-mh)*W), (H*mw, H*(W-mw))

def solve_iter(H: int, W: int):
    for h in range(1, H):
        for s in ((h*W,*s) for s in f(H-h, W)):
            yield max(s) - min(s)
    for w in range(1, W):
        for s in ((H*w,*s) for s in f(H, W-w)):
            yield max(s) - min(s)

def solve(H: int, W: int):
    return min(solve_iter(H, W))


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    print(solve(H, W))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def f(H, W):
    mh = H // 2
    if mh != 0:
        yield mh*W, (H-mh)*W
    mw = W // 2
    if mw != 0:
        yield H*mw, H*(W-mw)

def solve_iter(H: int, W: int):
    for h in range(1, H):
        for s in (tuple([h*W])+s for s in f(H-h, W)):
            yield max(s) - min(s)
    for w in range(1, W):
        for s in (tuple([H*w])+s for s in f(H, W-w)):
            yield max(s) - min(s)

def solve(H: int, W: int):
    return min(solve_iter(H, W))


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    print(solve(H, W))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()
Buggy python submission (verdict: Runtime Error):
A, B = input().split()
N = max(len(A), len(B))
A, B = A.zfill(N), B.zfill(N)
if A == B:
  print("EQUAL")
if A > B:
  print("GREATER")
if A < B:
  print("LESS")


Fixed submission:
A = int(input())
B = int(input())
if A == B:
  print("EQUAL")
if A > B:
  print("GREATER")
if A < B:
  print("LESS")

Buggy python submission (verdict: Runtime Error):
A, B = input().split()
N = max(len(A), len(B))
A, B = A.zfill(N), B.zfill(B)
if A == B:
  print("EQUAL")
if A > B:
  print("GREATER")
if A < B:
  print("LESS")


Fixed submission:
A = int(input())
B = int(input())
if A == B:
  print("EQUAL")
if A > B:
  print("GREATER")
if A < B:
  print("LESS")

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A == B:
  print("EQUAL")
if A > B:
  print("GREATER")
if A < B:
  print("LESS")

Fixed submission:
A = int(input())
B = int(input())
if A == B:
  print("EQUAL")
if A > B:
  print("GREATER")
if A < B:
  print("LESS")
Buggy python submission (verdict: Runtime Error):
from functools import reduce
MOD = 1_000_000_007
print(reduce(lambda a,b: a*b%MOD, range(1, int(input()))))


Fixed submission:
from functools import reduce
MOD = 1_000_000_007
print(reduce(lambda a,b: a*b%MOD, range(1, int(input())+1), 1))

Buggy python submission (verdict: Runtime Error):
from functools import reduce
MOD = 1_000_000_007
print(reduce(lambda a,b: a*b%MOD, range(1, int(input()))))

Fixed submission:
from functools import reduce
MOD = 1_000_000_007
print(reduce(lambda a,b: a*b%MOD, range(1, int(input())+1), 1))
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    import numpy as np    
    from scipy.sparse import csr_matrix    
    from scipy.sparse.csgraph import floyd_warshall
    omat = csr_matrix((c, (a, b)), shape=(N+1, N+1), dtype=np.int32, directed=False)
    smat = floyd_warshall(omat)
    return ((omat-smat) > 0).sum() // 2


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    print(solve(N, M, a, b, c))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Fixed submission:
#!/usr/bin/env python3
import sys

def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    import numpy as np    
    from scipy.sparse import csr_matrix    
    from scipy.sparse.csgraph import floyd_warshall
    omat = csr_matrix((c+c, (a+b, b+a)), shape=(N+1, N+1), dtype=np.int32)
    smat = floyd_warshall(omat)
    return ((omat-smat) > 0).sum() // 2


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    print(solve(N, M, a, b, c))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()
Buggy python submission (verdict: Runtime Error):
"""難しいすぎるよぅ..."""

def solve():
    R, C = list(map(int, input().split()))
    N = int(input())
    row = [[] for _ in range(R)]
    field = {}
    for _ in range(N):
        r, c, a = list(map(int, input().split()))
        r, c = r - 1, c - 1
        row[r].append((c, a))
        field[(r, c)] = a
    row = [sorted(r) for r in row]
    for rn, r in enumerate(row):
        for i, e1 in enumerate(r):
            for e2 in r[i+1:]:
                n = e2[0] - e1[0]
                print(r, e1, e2, n)
                if n > C:
                    break
                a = field.get((rn+n, e1[0]), None)
                b = field.get((rn+n, e2[0]), None)
                if a is None and b is None:
                    continue
                if a is None:
                    if e1[1] + b - e2[1] < 0:
                        return False
                elif b is None:
                    if e2[1] + a - e1[1] < 0:
                        return False
                else:
                    if e1[1] + b == e2[1] + a:
                        return False
    return True

print("Yes" if solve() else "No")


Fixed submission:
s = input()
print(s[:4]+" "+s[4:])