Harryxun/testdata huggingface dataset:
Buggy python 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))

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 python 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))

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 python submission (verdict: Time Limit Exceeded):
from sys import stdin
n = int(stdin.readline().rstrip())
V = [int(x) for x in stdin.readline().rstrip().split()]
V_odd = [V[2 * k] for k in range(int(n / 2))]
V_even = [V[2 * k + 1] for k in range(int(n / 2))]
V_odd_major = [0]
V_even_major = [0]
X = 0
Y = 0
for l in range(len(V_odd)):
    V_odd_sub = [x for x in V_odd if x == V_odd[l]]
    V_even_sub = [x for x in V_even if x == V_even[l]]
    if len(V_odd_sub) > V_odd_major[len(V_odd_major) - 1]:
        V_odd_major.append(len(V_odd_sub))
        X = V_odd[l]
    if len(V_even_sub) > V_even_major[len(V_even_major) - 1]:
        V_even_major.append(len(V_even_sub))
        Y = V_even[l]
V_odd_major.sort(reverse=True)
V_even_major.sort(reverse=True)
if X != Y:
    print(n - V_odd_major[0] - V_even_major[0])
else:
    print(n - (max(V_odd_major[1] + V_even_major[0], V_odd_major[0] + V_even_major[1])))

Fixed submission:
from sys import stdin
import collections
n = int(stdin.readline().rstrip())
V = [int(x) for x in stdin.readline().rstrip().split()]
V_odd = [V[2 * k] for k in range(int(n / 2))]
V_even = [V[2 * k + 1] for k in range(int(n / 2))]
co = collections.Counter(V_odd)
ce = collections.Counter(V_even)
if co.most_common()[0][0] != ce.most_common()[0][0]:
    print(n - co.most_common()[0][1] - ce.most_common()[0][1])
elif len(co.most_common()) == 1 and len(ce.most_common()) == 1:
    print(co.most_common()[0][1])
else:
    print(n - (max(co.most_common()[1][1] + ce.most_common()[0][1], co.most_common()[0][1] + ce.most_common()[1][1])))
Buggy python 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)

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 python submission (verdict: Runtime Error):
from sys import stdin

H, W = [int(x) for x in stdin.readline().rstrip().split()]

A = [list(stdin.readline().rstrip()) for _ in range(H)]
result = A

delete_column = []
delete_row = []

for k in range(W):
    cnt = 0
    for l in A[k]:
        if l == '.':
            cnt += 1
    if cnt == len(A[k]):
        delete_row.append(k)

for k in range(W):
    cnt = 0
    for l in range(H):
        if A[l][k] == '.':
            cnt += 1
    if cnt == H:
        delete_column.append(k)

for x in delete_row:
    del result[x]

for x in delete_column:
    for y in range(len(A)):
        del result[y][x]

for x in result:
    print(''.join(x))

Fixed submission:
from sys import stdin
 
N, i = [int(x) for x in stdin.readline().rstrip().split()]
 
print(N + 1 - i)

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

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

print(N + 1 - i)


Fixed submission:
from sys import stdin
 
N, i = [int(x) for x in stdin.readline().rstrip().split()]
 
print(N + 1 - i)
Buggy python 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


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 python 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')


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 python 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)

Fixed submission:
from sys import stdin

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

A.sort()

print(A[2] - A[0])
Buggy python submission (verdict: Runtime Error):
from sys import stdin

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

for k in range(N):
    A[k] -= k

A.sort()


def get_pity_sum(x):
    pity_sum = 0
    for l in A:
        if A[x] - l >= 0:
            pity_sum += A[x] - l
        else:
            pity_sum += l - A[x]
    return pity_sum


if N % 2 == 1:
    print(min(get_pity_sum(int((N - 1) / 2)), get_pity_sum(int((N - 1) / 2 - 1)), get_pity_sum(int((N - 1) / 2 + 1))))
else:
    print(min(get_pity_sum(int(N / 2)), get_pity_sum(int(N / 2 - 1))))


Fixed submission:
from sys import stdin

N = int(stdin.readline().rstrip())

if N % 2 == 0:
    print(N)
else:
    print(2 * N)
Buggy python 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')


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 python 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')


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 python 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')


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 python submission (verdict: Time Limit Exceeded):
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

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

L = [x for x in range(10) if x not in D]
ans = 10 ** 7


def dfs(n):
    if len(n) >= len(str(N)):
        if int(n) >= N and n[0] != '0':
            return int(n)
    output = 10 ** 7
    for l in L:
        output = min(dfs(n + str(l)), output)
    return output


print(dfs(''))


Fixed submission:
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

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

L = [x for x in range(10) if x not in D]
ans = 10 ** 7


def dfs(n):
    global ans
    if n != '' and n[0] == '0':
        return
    if n != '' and int(n) >= ans:
        return
    if len(n) >= len(str(N)):
        if int(n) >= N:
            ans = int(n)
    for l in L:
        dfs(n + str(l))


dfs('')
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
v=[0]*64
ans=0
mod=1000000007
zero=0
one=0

index=n-1
while index>=0:
	for k in range(61):
		one=v[k]
		zero=n-1-index-one
		tmp=1<<k
		if((a[index]&tmp)==0):
			ans=(ans+tmp*one)%mod
		else:
			ans=(ans+tmp*zero)%mod
			v[k]=v[k]+1
	index-=1


print(ans)
print()

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
v=[0]*64
ans=0
mod=1000000007
zero=0
one=0

index=n-1
while index>=0:
	for k in range(61):
		one=v[k]
		zero=n-1-index-one
		tmp=1<<k
		if((a[index]&tmp)==0):
			ans=(ans+tmp*one)
		else:
			ans=(ans+tmp*zero)
			v[k]=v[k]+1
	index-=1

ans=ans%mod
print(ans)
print()

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
v=[0]*64
ans=0
mod=1000000007
zero=0
one=0

index=n-1
while index>=0:
	for k in range(64):
		one=v[k]
		zero=n-1-index-one
		if((a[index]&(1<<k))==0):
			ans=(ans+(1<<k)*one)%mod
		else:
			ans=(ans+(1<<k)*zero)%mod
			v[k]=v[k]+1
	index-=1


print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
v=[0]*64
ans=0
mod=1000000007
zero=0
one=0

index=n-1
while index>=0:
	for k in range(61):
		one=v[k]
		zero=n-1-index-one
		tmp=1<<k
		if((a[index]&tmp)==0):
			ans=(ans+tmp*one)
		else:
			ans=(ans+tmp*zero)
			v[k]=v[k]+1
	index-=1

ans=ans%mod
print(ans)
print()
Buggy python submission (verdict: Time Limit Exceeded):
N,S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp =[[0]*(S+1) for _ in range(N+1)]
dp[0][0]=1
for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod
        if j+A[i]<=S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= mod
print(dp[N][S])

Fixed submission:
N,S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp =[[0]*(S+1) for _ in range(N+1)]
dp[0][0]=1
for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod
        if j+A[i]<=S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= mod
print(dp[N][S])
Buggy python submission (verdict: Runtime Error):
import collections
n,m = map(int,input().split())
a = list(map(int,input().split()))
col = collections.Counter(a)
 
for i in range(m):
  b,c = map(int,input().split())
  col[c] += b
col = sorted(col.items(), key=lambda x:x[0],reverse=True)
 
ans=0
for k,v in col:
  if n <= v:
    ans += k*n
    break
  else:
    ans += k*v
    n -= v
print(ans)

Fixed submission:
import collections
n,m = map(int,input().split())
a = list(map(int,input().split()))
col = collections.Counter(a)
 
for i in range(m):
  b,c = map(int,input().split())
  col[c] += b
col = sorted(col.items(), key=lambda x:x[0],reverse=True)
 
ans=0
for k,v in col:
  if n <= v:
    ans += k*n
    break
  else:
    ans += k*v
    n -= v
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def main():
    k = int(input())
    print(getresult(k))

def getresult(k):
    res = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                res += gcd(gcd(a, b), c)
    return res

def gcd(x, y):
    if x < y:
        x, y = y, x  # x >= y
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

if __name__ == "__main__":
    main()


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

from numba import njit

def main():
    k = int(input())
    print(getresult(k))

@njit
def getresult(k):
    res = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                res += gcd(gcd(a, b), c)
    return res

@njit
def gcd(x, y):
    if x < y:
        x, y = y, x  # x >= y
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    f = list(map(int, input().split()))
    a = sorted(a)
    f = sorted(f)
    f = f[::-1]
    mi = -1  # Impossible
    ma = 10 ** 12  # Possible
    for i in range(100):
        md = mi + (ma - mi) // 2
        if can_achieve(md, a, f, k, n):
            ma = md
        else:
            mi = md
        if ma - mi <= 1:
            break
    print(ma)

def can_achieve(score, a, f, k, n):
    sumb = 0
    for i in range(n):
        b = a[i] - score // f[i]
        b = max(b, 0)
        sumb += b
    return k >= sumb

if __name__ == "__main__":
    main()


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

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    f = list(map(int, input().split()))
    a = sorted(a)
    f = sorted(f)
    f = f[::-1]
    mi = -1  # Impossible
    ma = 10 ** 12  # Possible
    for i in range(100):
        md = mi + (ma - mi) // 2
        if can_achieve(md, a, f, k, n):
            ma = md
        else:
            mi = md
        if ma - mi <= 1:
            break
    print(ma)

def can_achieve(score, a, f, k, n):
    sumb = 0
    for i in range(n):
        b = a[i] - score // f[i]
        b = max(b, 0)
        sumb += b
    return k >= sumb

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

from collections import deque

def main():
    n = int(input())
    n_prev = [[2 for j in range(n)] for i in range(n)]
    post_matches = [[[] for j in range(n)] for i in range(n)]
    q = deque()
    for i in range(n):
        ai = list(map(int, input().split()))
        for j in range(n - 1):
            x = min(i, ai[j] - 1)
            y = max(i, ai[j] - 1)
            if j == 0:
                n_prev[x][y] -= 1
                if n_prev[x][y] == 0:
                    q.append((x, y))
            else:
                xp = min(i, ai[j - 1] - 1)
                yp = max(i, ai[j - 1] - 1)
                post_matches[xp][yp].append((x, y))

    time = 0
    while q:
        time += 1
        qn = deque()
        while q:
            i, j = q.pop()
            for i2, j2 in post_matches[i][j]:
                n_prev[i2][j2] -= 1
                if n_prev[i2][j2] == 0:
                    qn.append((i2, j2))
        q = qn

    for i in range(n):
        for j in range(i + 1, n):
            if n_prev[i][j] > 0:
                print(-1)
                return
    print(time)

if __name__ == "__main__":
    main()


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

from collections import deque

def main():
    n = int(input())
    n_prev = [[2 for j in range(n)] for i in range(n)]
    post_matches = [[[] for j in range(n)] for i in range(n)]
    q = deque()
    for i in range(n):
        ai = list(map(int, input().split()))
        for j in range(n - 1):
            x = min(i, ai[j] - 1)
            y = max(i, ai[j] - 1)
            if j == 0:
                n_prev[x][y] -= 1
                if n_prev[x][y] == 0:
                    q.append((x, y))
            else:
                xp = min(i, ai[j - 1] - 1)
                yp = max(i, ai[j - 1] - 1)
                post_matches[xp][yp].append((x, y))

    time = 0
    while q:
        time += 1
        qn = deque()
        while q:
            i, j = q.pop()
            for i2, j2 in post_matches[i][j]:
                n_prev[i2][j2] -= 1
                if n_prev[i2][j2] == 0:
                    qn.append((i2, j2))
        q = qn

    for i in range(n):
        for j in range(i + 1, n):
            if n_prev[i][j] > 0:
                print(-1)
                return
    print(time)

if __name__ == "__main__":
    main()
Buggy python 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()


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 python 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()


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 python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import numpy as np

def main():
    a, b, q = map(int, input().split())
    huge = 10 ** 18
    s = np.array([-huge] + [int(input()) for i in range(a)] + [huge])
    t = np.array([-huge] + [int(input()) for i in range(b)] + [huge])
    for i in range(q):
        x = int(input())
        b = np.searchsorted(s, x, "right")
        d = np.searchsorted(t, x, "right")
        res = huge
        for sh in s[b - 1:b + 1]:
            for te in t[d - 1:d + 1]:
                d1 = abs(sh - x) + abs(sh - te)
                d2 = abs(te - x) + abs(sh - te)
                res = min(res, d1, d2)
        print(res)


if __name__ == "__main__":
    main()


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

import bisect

def main():
    a, b, q = map(int, input().split())
    huge = 10 ** 18
    s = [-huge] + [int(input()) for i in range(a)] + [huge]
    t = [-huge] + [int(input()) for i in range(b)] + [huge]
    for i in range(q):
        x = int(input())
        b = bisect.bisect_right(s, x)
        d = bisect.bisect_right(t, x)
        res = huge
        for sh in s[b - 1:b + 1]:
            for te in t[d - 1:d + 1]:
                d1 = abs(sh - x) + abs(sh - te)
                d2 = abs(te - x) + abs(sh - te)
                res = min(res, d1, d2)
        print(res)


if __name__ == "__main__":
    main()