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

Fixed submission:
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]


def to_bin(n):
    return bin(n)[2:]


cnt = [0] * 40
for a in A:
    b = to_bin(a)
    b = b[::-1]
    for i in range(len(b)):
        if b[i] == '1':
            cnt[i] += 1

ans = 0
cnt.reverse()
k_str = to_bin(K)
while len(k_str) < 40:
    k_str = '0' + k_str

for j in range(len(cnt)):
    if k_str[j] == '1':
        tmp_ans = 0
        for k in range(len(cnt)):
            power = 39 - k
            if k <= j - 1:
                if k_str[k] == '0':
                    tmp_ans += cnt[k] * (2 ** power)
                else:
                    tmp_ans += (N - cnt[k]) * (2 ** power)
            elif k == j:
                tmp_ans += cnt[k] * (2 ** power)
            else:
                tmp_ans += max(cnt[k], N - cnt[k]) * (2 ** power)
        ans = max(ans, tmp_ans)
tmp_ans = 0
for k in range(len(cnt)):
    power = 39 - k
    if k_str[k] == '0':
        tmp_ans += cnt[k] * (2 ** power)
    else:
        tmp_ans += (N - cnt[k]) * (2 ** power)
ans = max(ans, tmp_ans)
print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]


def to_bin(n):
    return bin(n)[2:]


if K == 0:
    ans = 0
    for a in A:
        ans += K ^ a
    print(ans)
    exit()

cnt = [0] * len(to_bin(K))
for a in A:
    b = to_bin(a)
    while len(b) < len(cnt):
        b = '0' + b
    b = b[::-1]
    for i in range(len(b)):
        if b[i] == '1':
            cnt[i] += 1

ans = 0
for j in range(len(cnt)):
    ans += max(cnt[j], N - cnt[j]) * (2 ** j)

print(ans)
Problem p03147 (python)

Fixed submission:
from sys import stdin
import sys
sys.setrecursionlimit(10000)

n = int(stdin.readline().rstrip())
flowers = [int(x) for x in stdin.readline().rstrip().split()]


def watering(s, count):
    index_fwd = 10 ** 9
    index_back = 0
    for k in range(len(s)):
        if s[k] > 0:
            index_fwd = k
            break
    if index_fwd == 10 ** 9:
        return count
    for l in range(index_fwd, len(s)):
        if s[l] == 0:
            break
        index_back = l
    for m in range(index_fwd, index_back + 1):
        s[m] -= 1
    count += 1
    return watering(s, count)


print(watering(flowers, 0))

Buggy submission (verdict: Runtime Error):
from sys import stdin

n = int(stdin.readline().rstrip())
flowers = [int(x) for x in stdin.readline().rstrip().split()]


def watering(s, count):
    index_fwd = 10 ** 9
    index_back = 0
    for k in range(len(s)):
        if s[k] > 0:
            index_fwd = k
            break
    if index_fwd == 10 ** 9:
        return count
    for l in range(index_fwd, len(s)):
        if s[l] == 0:
            break
        index_back = l
    for m in range(index_fwd, index_back + 1):
        s[m] -= 1
    count += 1
    return watering(s, count)


print(watering(flowers, 0))

Buggy submission (verdict: Runtime Error):
from sys import stdin

n = int(stdin.readline().rstrip())
flowers = [int(x) for x in stdin.readline().rstrip().split()]

cnt = 0


def watering(s, count):
    index_fwd = 10 ** 9
    index_back = 0
    for k in range(len(s)):
        if s[k] > 0:
            index_fwd = k
            break
    for l in range(index_fwd, len(s)):
        if s[l] == 0:
            break
        index_back = l
    if index_fwd == 10 ** 9:
        return count
    for m in range(index_fwd, index_back + 1):
        s[m] -= 1
    count += 1
    return watering(s, count)


print(watering(flowers, 0))
Problem p03262 (python)

Fixed submission:
from sys import stdin
import fractions

N, X = [int(k) for k in stdin.readline().rstrip().split()]
x = [int(k) for k in stdin.readline().rstrip().split()]
y = [abs(k - X) for k in x]
C = y[0]
for l in range(N):
    C = fractions.gcd(C, y[l])
print(C)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math

N, X = [int(k) for k in stdin.readline().rstrip().split()]
x = [int(k) for k in stdin.readline().rstrip().split()]
y = [abs(k - X) for k in x]
C = y[0]
for l in range(N):
    C = math.gcd(C, y[l])
print(C)
Problem p03282 (python)

Fixed submission:
from sys import stdin

S = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())

for x in range(len(S)):
    if int(S[x]) > 1:
        print(S[x])
        break
    if K == x + 1:
        print('1')
        break

Buggy submission (verdict: Runtime Error):
from sys import stdin

S = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())

for x in range(10 ** 2):
    if int(S[x]) > 1:
        print(S[x])
        break
Problem p03284 (python)

Fixed submission:
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]

if N % K == 0:
    print('0')
else:
    print('1')

Buggy submission (verdict: Runtime Error):
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip()]

if N % K == 0:
    print('0')
else:
    print('1')
Problem p03292 (python)

Fixed submission:
from sys import stdin

A = [int(x) for x in stdin.readline().rstrip().split()]

A.sort()

print(A[2] - A[0])

Buggy submission (verdict: Runtime Error):
from sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

lcm_a = int(A[0] * A[1] / fractions.gcd(A[0], A[1]))

if len(A) > 2:
    for k in A[2:]:
        lcm_a = int(lcm_a * k / fractions.gcd(lcm_a, k))

modulo_sum = 0

for k in A:
    modulo_sum += (lcm_a - 1) % k

print(modulo_sum)
Problem p03294 (python)

Fixed submission:
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

lcm_a = A[0] * A[1]

if len(A) > 2:
    for k in A[2:]:
        lcm_a = lcm_a * k

modulo_sum = 0

for k in A:
    modulo_sum += (lcm_a - 1) % k

print(modulo_sum)

Buggy submission (verdict: Runtime Error):
rom sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

lcm_a = int(A[0] * A[1] // fractions.gcd(A[0], A[1]))

if len(A) > 2:
    for k in A[2:]:
        lcm_a = int(lcm_a * k // fractions.gcd(lcm_a, k))

modulo_sum = 0

for k in A:
    modulo_sum += (lcm_a - 1) % k

print(modulo_sum)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

lcm_a = int(A[0] * A[1] / fractions.gcd(A[0], A[1]))

if len(A) > 2:
    for k in A[2:]:
        lcm_a = int(lcm_a * k / fractions.gcd(lcm_a, k))

modulo_sum = 0

for k in A:
    modulo_sum += (lcm_a - 1) % k

print(modulo_sum)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

lcm_a = int(A[0] * A[1] / fractions.gcd(A[0], A[1]))

if len(A) > 2:
    for k in A[2:]:
        lcm_a = int(lcm_a * k / fractions.gcd(lcm_a, k))

modulo_sum = 0

for k in A:
    modulo_sum += (lcm_a - 1) % k

print(modulo_sum)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

lcm_a = int(A[0] * A[1] / fractions.gcd(A[0], A[1]))

for k in A[2:]:
    lcm_a = int(lcm_a * k / fractions.gcd(lcm_a, k))

modulo_sum = 0

for k in A:
    modulo_sum += (lcm_a - 1) % k

print(modulo_sum)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

lcm_a = int(A[0] * A[1] / math.gcd(A[0], A[1]))

for k in A[2:]:
    lcm_a = int(lcm_a * k / math.gcd(lcm_a, k))

modulo_sum = 0

for k in A:
    modulo_sum += (lcm_a - 1) % k

print(modulo_sum)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

lcm_a = int(A[0] * A[1] / math.gcd(A[0], A[1]))

for k in A[2:]:
    lcm_a = int(lcm_a * k / math.gcd(lcm_a, k))

modulo_sum = 0

for k in A:
    modulo_sum += (lcm_a - 1) % k

print(modulo_sum)
Problem p03701 (python)

Fixed submission:
from sys import stdin, exit

N = int(stdin.readline().rstrip())
s = [int(stdin.readline().rstrip()) for _ in range(N)]
dp = [0] * (100 * N)
dp[0] = 1
for n in range(N):
    for p in range(len(dp) - 1, 0, -1):
        if p - s[n] >= 0:
            if dp[p - s[n]] == 1 and 0 <= p:
                dp[p] = 1
for k in range(len(dp)):
    if dp[len(dp) - k - 1] == 1 and (len(dp) - k - 1) % 10 != 0:
        print(len(dp) - k - 1)
        exit()
print('0')

Buggy submission (verdict: Runtime Error):
from sys import stdin, exit

N = int(stdin.readline().rstrip())
s = [int(stdin.readline().rstrip()) for _ in range(N)]
dp = [0] * (100 * N)
dp[0] = 1
for n in range(N):
    for p in range(len(dp), 0, -1):
        if p - s[n] >= 0:
            if dp[p - s[n]] == 1:
                dp[p] = 1
for k in range(len(dp)):
    if dp[len(dp) - k - 1] == 1 and (len(dp) - k - 1) % 10 != 0:
        print(len(dp) - k - 1)
        exit()
print('0')

Buggy submission (verdict: Runtime Error):
from sys import stdin, exit

N = int(stdin.readline().rstrip())
s = [int(stdin.readline().rstrip()) for _ in range(N)]
dp = [0] * (100 * N)
dp[0] = 1
for n in range(N):
    for p in range(len(dp), 0, -1):
        if p - s[n] >= 0
            if dp[p - s[n]] == 1:
                dp[p] = 1
for k in range(len(dp)):
    if dp[len(dp) - k - 1] == 1 and (len(dp) - k - 1) % 10 != 0:
        print(len(dp) - k - 1)
        exit()
print('0')

Buggy submission (verdict: Runtime Error):
from sys import stdin, exit

N = int(stdin.readline().rstrip())
s = [int(stdin.readline().rstrip()) for _ in range(N)]
dp = [0] * (100 * N)
dp[0] = 1
for n in range(N):
    for p in range(len(dp), 0, -1):
        if dp[p - s[n]] == 1:
            dp[p] = 1
for k in range(len(dp)):
    if dp[len(dp) - k - 1] == 1 and (len(dp) - k - 1) % 10 != 0:
        print(len(dp) - k - 1)
        exit()
print('0')
Problem p02850 (python)

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

import sys
import random

def main():
    sys.setrecursionlimit(10 ** 6)
    n = int(input())
    ranks = [0 for i in range(n)]
    adjs = [[] for i in range(n)]
    edges = []
    for i in range(n - 1):
        a, b = map(int, input().split())
        edges.append((a - 1, b - 1))
        ranks[a - 1] += 1
        ranks[b - 1] += 1
        adjs[a - 1].append(b - 1)
        adjs[b - 1].append(a - 1)

    for i in range(n):
        random.shuffle(adjs[i])
    visited = [False for i in range(n)]
    colors = {}  # (mi, ma) |-> color
    dfs(0, adjs, visited, -1, colors)

    print(max(ranks))
    for i in range(n - 1):
        a, b = edges[i]
        mi = min(a, b)
        ma = max(a, b)
        print(colors[(mi, ma)])

def dfs(i, adjs, visited, color_used, colors):
    visited[i] = True
    c = 1
    for j in adjs[i]:
        if visited[j]:
            continue
        if c == color_used:
            c += 1
        mi = min(i, j)
        ma = max(i, j)
        colors[(mi, ma)] = c
        dfs(j, adjs, visited, c, colors)
        c += 1

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

def main():
    n = int(input())
    ranks = [0 for i in range(n)]
    adjs = [[] for i in range(n)]
    edges = []
    for i in range(n - 1):
        a, b = map(int, input().split())
        edges.append((a - 1, b - 1))
        ranks[a - 1] += 1
        ranks[b - 1] += 1
        adjs[a - 1].append(b - 1)
        adjs[b - 1].append(a - 1)

    visited = [False for i in range(n)]
    color_used = [set() for i in range(n)]
    colors = {}  # (mi, ma) |-> color
    dfs(0, adjs, visited, color_used, colors)

    print(max(ranks))
    for i in range(n - 1):
        a, b = edges[i]
        mi = min(a, b)
        ma = max(a, b)
        print(colors[(mi, ma)])

def dfs(i, adjs, visited, color_used, colors):
    visited[i] = True
    for j in adjs[i]:
        if visited[j]:
            continue
        for c in range(1, 100005):
            if c in color_used[i]:
                continue
            if c in color_used[j]:
                continue
            color_used[i].add(c)
            color_used[j].add(c)
            mi = min(i, j)
            ma = max(i, j)
            colors[(mi, ma)] = c
            break
        dfs(j, adjs, visited, color_used, colors)

if __name__ == "__main__":
    main()
Problem p02936 (python)

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

import sys

def dfs(i, p, add):
    add += add_node[i]
    counter[i] += add
    for j in adj[i]:
        if j != p:
            dfs(j, i, add)

sys.setrecursionlimit(10 ** 6)
n, q = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, sys.stdin.readline().split())
    adj[a - 1].append(b - 1)
    adj[b - 1].append(a - 1)
add_node = [0 for i in range(n)]
for i in range(q):
    p, x = map(int, sys.stdin.readline().split())
    add_node[p - 1] += x
counter = [0 for i in range(n)]
dfs(0, -1, 0)
print(" ".join(str(x) for x in counter))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

def main():
    n, q = map(int, input().split())
    adj = [[] for i in range(n)]
    for i in range(n - 1):
        a, b = map(int, input().split())
        adj[a - 1].append(b - 1)
        adj[b - 1].append(a - 1)
    add_node = [0 for i in range(n)]
    for i in range(q):
        p, x = map(int, input().split())
        add_node[p - 1] += x
    counter = [0 for i in range(n)]
    visited = [False for i in range(n)]
    dfs(0, adj, visited, counter, 0, add_node)
    print(" ".join(str(x) for x in counter))

def dfs(i, adj, visited, counter, add, add_node):
    visited[i] = True
    add += add_node[i]
    counter[i] += add
    for j in adj[i]:
        if not visited[j]:
            dfs(j, adj, visited, counter, add, add_node)

if __name__ == "__main__":
    main()
Problem p02997 (python)

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

def main():
    n, k = map(int, input().split())
    kmax = ((n - 1) * (n - 2)) // 2
    if k > kmax:
        print(-1)
        return

    edges = getedges(n, k, kmax)
    print(len(edges))
    for i, j in edges:
        print(i, j)

def getedges(n, k, kmax):
    edges = []
    for i in range(1, n):
        edges.append((i, n))
    if kmax == k:
        return edges
    c = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            edges.append((i, j))
            c += 1
            if c == kmax - k:
                return edges
    assert False

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

def main():
    n, k = map(int, input().split())
    kmax = ((n - 1) * (n - 2)) // 2
    if k > kmax:
        print(-1)
        return

    edges = getedges(n, k, kmax)
    print(len(edges))
    for i, j in edges:
        print(i, j)

def getedges(n, k, kmax):
    edges = []
    for i in range(1, n):
        edges.append((i, n))
    c = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            edges.append((i, j))
            c += 1
            if c == kmax - k:
                return edges
    assert False


if __name__ == "__main__":
    main()
Problem p03044 (python)

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

import sys

def main():
    sys.setrecursionlimit(10 ** 6)
    n = int(input())
    adjs = [[] for i in range(n)]
    for i in range(n - 1):
        u, v, w = map(int, input().split())
        adjs[u - 1].append((v - 1, w))
        adjs[v - 1].append((u - 1, w))
    colors = [None for i in range(n)]
    visited = [False for i in range(n)]
    dfs(0, 0, adjs, visited, colors)
    for i in range(n):
        print(colors[i])

def dfs(i, color, adjs, visited, colors):
    visited[i] = True
    colors[i] = color
    for v, w in adjs[i]:
        if visited[v]:
            continue
        dfs(v, (color + w) % 2, adjs, visited, colors)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

def main():
    n = int(input())
    adjs = [[] for i in range(n)]
    for i in range(n - 1):
        u, v, w = map(int, input().split())
        adjs[u - 1].append((v - 1, w))
        adjs[v - 1].append((u - 1, w))
    colors = [None for i in range(n)]
    visited = [False for i in range(n)]
    dfs(0, 0, adjs, visited, colors)
    for i in range(n):
        print(colors[i])

def dfs(i, color, adjs, visited, colors):
    visited[i] = True
    colors[i] = color
    for v, w in adjs[i]:
        if visited[v]:
            continue
        dfs(v, (color + w) % 2, adjs, visited, colors)

if __name__ == "__main__":
    main()
Problem p03382 (python)

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

def dist(x, y):
    assert 0 <= y <= x
    return min(y, x - y)

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    ai = sorted(ai)

    x = ai[-1]
    y = ai[0]
    for i in range(n - 1):
        if dist(x, ai[i]) > dist(x, y):
            y = ai[i]

    print("%d %d" % (x, y))

main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

def dist(x, y):
    assert 0 <= y <= x
    return min(y, x - y)

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    ai = sorted(ai)

    x = ai[-1]
    y = ai[0]
    for i in range(n - 1):
        if dist(x, ai[i]) > dist(x, y):
            y = ai[i]

    print(f"{x} {y}")

main()
Problem p03415 (python)

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

l1 = input()
l2 = input()
l3 = input()

s = l1[0] + l2[1] + l3[2]
print(s)

Buggy submission (verdict: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector < vector <int> > vvi;
const int HUGEI = 2147483647;  // (1 << 31) - 1
const ll HUGEL = 9223372036854775807;  // (1 << 63) - 1
const string ABC = "abcdefghijklmnopqrstuvwxyz";

int main(void) {
    return 0;
}
Problem p03452 (python)

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

import sys
sys.setrecursionlimit(10 ** 6)

class Impossible(ValueError):
    pass

def main():
    n, m = map(int, input().split())
    lrds = []
    for i in range(m):
        l, r, d = map(int, input().split())
        lrds.append((l - 1, r - 1, d))

    adj = [[] for i in range(n)]
    parents = [i for i in range(n)]
    for i in range(m):
        l, r, d = lrds[i]
        union(parents, l, r)
        adj[l].append((r, d))
        adj[r].append((l, -d))

    ds = set()
    for i in range(n):
        ds.add(find(parents, i))

    pos = [None for i in range(n)]
    try:
        for i in ds:
            pos[i] = 0
            dfs(adj, pos, i)
        print("Yes")
    except Impossible:
        print("No")

def dfs(adj, pos, x):
    for y, d in adj[x]:
        if pos[y] is None:
            pos[y] = pos[x] + d
            dfs(adj, pos, y)
        elif pos[y] != pos[x] + d:
            raise Impossible

def find(p, x):
    if p[x] != x:
        p[x] = find(p, p[x])
    return p[x]

def union(p, x, y):
    p[find(p, y)] = find(p, x)


main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

class Impossible(ValueError):
    pass

def main():
    n, m = map(int, input().split())
    lrds = []
    for i in range(m):
        l, r, d = map(int, input().split())
        lrds.append((l - 1, r - 1, d))

    adj = [[] for i in range(n)]
    parents = [i for i in range(n)]
    for i in range(m):
        l, r, d = lrds[i]
        union(parents, l, r)
        adj[l].append((r, d))
        adj[r].append((l, -d))

    ds = set()
    for i in range(n):
        ds.add(find(parents, i))

    pos = [None for i in range(n)]
    try:
        for i in ds:
            pos[i] = 0
            dfs(adj, pos, i)
        print("Yes")
    except Impossible:
        print("No")

def dfs(adj, pos, x):
    for y, d in adj[x]:
        if pos[y] is None:
            pos[y] = pos[x] + d
            dfs(adj, pos, y)
        elif pos[y] != pos[x] + d:
            raise Impossible

def find(p, x):
    if p[x] != x:
        p[x] = find(p, p[x])
    return p[x]

def union(p, x, y):
    p[find(p, y)] = find(p, x)


main()
Problem p03494 (python)

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

def fact_of_two(i):
    for j in range(10000):
        if i % (2 ** j) != 0:
            break
    assert j >= 1
    return j - 1

n = int(input())
ai = list(map(int, input().split()))
assert len(ai) == n

mi = 999999
for a in ai:
    mi = min(mi, fact_of_two(a))

print(mi)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys

def main():
    n = int(input())
    imax = None
    dmax = 0
    for i in range(2, n + 1):
        print("? {} {}".format(1, i))
        sys.stdout.flush()
        dist = int(input())
        if dist > dmax:
            dmax = dist
            imax = i
    imax2 = None
    dmax2 = 0
    for i in range(1, n + 1):
        if i == imax2:
            continue
        print("? {} {}".format(imax, i))
        sys.stdout.flush()
        dist = int(input())
        if dist > dmax2:
            dmax2 = dist
            imax2 = i
    print("! {} {}".format(imax, imax2))

if __name__ == "__main__":
    main()
Problem p03545 (python)

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

from itertools import product

def main():
    a, b, c, d = map(int, input())
    for x, y, z in product(("+", "-"), repeat=3):
        eq = "a{x}b{y}c{z}d".format(x=x, y=y, z=z)
        val = eval(eq)
        if val == 7:
            print("{a}{x}{b}{y}{c}{z}{d}=7".format(x=x, y=y, z=z, a=a, b=b, c=c, d=d))
            return

main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

from itertools import product

def main():
    a, b, c, d = map(int, input())
    for x, y, z in product(("+", "-"), repeat=3):
        eq = f"a{x}b{y}c{z}d"
        val = eval(eq)
        if val == 7:
            print(f"{a}{x}{b}{y}{c}{z}{d}=7")
            return

main()
Problem p03608 (python)

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

from itertools import permutations
import numpy as np

HUGE = 10 ** 18

def main():
    n, m, r = map(int, input().split())
    togo = list(map(int, input().split()))
    adj_mat = [[HUGE for j in range(n)] for i in range(n)]
    for i in range(n):
        adj_mat[i][i] = HUGE
    for i in range(m):
        a, b, c = map(int, input().split())
        a0 = a - 1
        b0 = b - 1
        adj_mat[a0][b0] = c
        adj_mat[b0][a0] = c
    adj_mat = np.array(adj_mat)

    wf(adj_mat, n)

    res = HUGE
    for way in permutations(togo):
        assert len(way) > 1
        x = 0
        for i in range(len(way) - 1):
            x += adj_mat[way[i] - 1][way[i + 1] - 1]
        res = min(res, x)

    print(res)

def wf(adj_mat, n):
    for k in range(n):
        for i in range(n):
            adj_mat[i, :] = np.minimum(adj_mat[i, :], adj_mat[i][k] + adj_mat[k, :])

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

from itertools import permutations
from numba import jit
import numpy as np

HUGE = 10 ** 18

def main():
    n, m, r = map(int, input().split())
    togo = list(map(int, input().split()))
    adj_mat = [[HUGE for j in range(n)] for i in range(n)]
    for i in range(n):
        adj_mat[i][i] = HUGE
    for i in range(m):
        a, b, c = map(int, input().split())
        a0 = a - 1
        b0 = b - 1
        adj_mat[a0][b0] = c
        adj_mat[b0][a0] = c
    adj_mat = np.array(adj_mat)

    wf(adj_mat, n)

    res = HUGE
    for way in permutations(togo):
        assert len(way) > 1
        x = 0
        for i in range(len(way) - 1):
            x += adj_mat[way[i] - 1][way[i + 1] - 1]
        res = min(res, x)

    print(res)

@jit(nopython=True)
def wf(adj_mat, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                adj_mat[i][j] = min(adj_mat[i][j], adj_mat[i][k] + adj_mat[k][j])

if __name__ == "__main__":
    main()