Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, C = map(int, input().split())
r = [[0] * C for _ in range(10 * 5)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s - 1, t):
        r[i][c - 1] = 1
ans = 0
for t in r:
    sum_t = sum(t)
    if sum_t > ans:
        ans = sum_t

print(ans)

Fixed submission:
N, A, B = map(int, input().split())
print(min(A * N, B))
Buggy python submission (verdict: Runtime Error):
N, C = map(int, input().split())
r = [[0 for _ in range(C)] for _ in range(10 * 5)]

for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s - 1, t):
        r[i][c - 1] = 1
ans = 0
for t in r:
    sum_t = sum(t)
    if sum_t > ans:
        ans = sum_t

print(ans)

Fixed submission:
n, c = map(int, input().split())

r = [[0 for i in range(c)] for j in range(100000)]  # テレビ局の番組表
for dummy in range(n):  # 入力
    s, t, c = map(int, input().split())
    for j in range(s - 1, t):
        r[j][c - 1] = 1  # 放送中なら1

ans = 0
for i in range(100000):
    if sum(r[i]) > ans:
        ans = sum(r[i])  # 同時に放送されている番組の最大数

print(ans)

Buggy python submission (verdict: Runtime Error):
N, C = map(int, input().split())
r = [[0] * C for _ in range(10 * 5)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s - 1, t):
        r[i][c - 1] = 1
ans = 0
for t in r:
    sum_t = sum(t)
    if sum_t > ans:
        ans = sum_t

print(ans)

Fixed submission:
n, c = map(int, input().split())

r = [[0 for i in range(c)] for j in range(100000)]  # テレビ局の番組表
for dummy in range(n):  # 入力
    s, t, c = map(int, input().split())
    for j in range(s - 1, t):
        r[j][c - 1] = 1  # 放送中なら1

ans = 0
for i in range(100000):
    if sum(r[i]) > ans:
        ans = sum(r[i])  # 同時に放送されている番組の最大数

print(ans)

Buggy python submission (verdict: Runtime Error):
N, C = map(int, input().split())
r = [[0] * C for _ in range(10 * 5)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s - 1, t):
        r[j][c - 1] = 1
ans = 0
for t in r:
    sum_t = sum(t)
    if sum_t > ans:
        ans = sum_t

print(ans)

Fixed submission:
n, c = map(int, input().split())

r = [[0 for i in range(c)] for j in range(100000)]  # テレビ局の番組表
for dummy in range(n):  # 入力
    s, t, c = map(int, input().split())
    for j in range(s - 1, t):
        r[j][c - 1] = 1  # 放送中なら1

ans = 0
for i in range(100000):
    if sum(r[i]) > ans:
        ans = sum(r[i])  # 同時に放送されている番組の最大数

print(ans)
Buggy python submission (verdict: Runtime Error):
import re
s = input()
pa = s.replace('x', '')
if pa != pa[::-1]:
    print(-1)
else:
    ans = 0
    sp = s.split(pa[len(pa) // 2])
    for r, l in zip(re.split(r'[a-wyz]', sp[0]),
                    re.split(r'[a-wyz]', sp[-1])[::-1]):
        ans += abs(len(r) - len(l))
    print(ans)

Fixed submission:
import re
s = input()
pa = s.replace('x', '')
if pa != pa[::-1]:
    print(-1)
else:
    ans = 0
    sp = re.split(r'[a-wyz]', s)
    for r, l in zip(sp, sp[::-1]):
        ans += abs(len(r) - len(l))
    print(ans // 2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(N):
            if i == k or j == k:
                continue
            if A[i][j] == A[i][k] + A[k][j]:
                break
            elif A[i][k] > A[i][j] + A[j][k]:
                print(-1)
                exit()
        else:
            ans += A[i][j]

print(ans)

Fixed submission:
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(N):
            if i == k or j == k:
                continue
            if A[i][j] == A[i][k] + A[k][j]:
                break
            elif A[i][k] > A[i][j] + A[j][k]:
                print(-1)
                exit()
        else:
            ans += A[i][j]

print(ans)
Buggy python submission (verdict: Runtime Error):
g1, g2, g3 = {1, 3, 5, 7, 8, 10, 12}, {4, 6, 9, 11}, {2}
print('Yes' if {a, b} in g1 or {a, b} in g2 else 'No')

Fixed submission:
a, b = map(int, input().split())
g1, g2, g3 = {1, 3, 5, 7, 8, 10, 12}, {4, 6, 9, 11}, {2}
print('Yes' if not ({a, b} - g1) or not ({a, b} - g2) else 'No')
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a == 'H':
    print(b)
else:
    if b == 'H':
        print('D')
    else:
        print('H')

Fixed submission:
a, b = input().split()
if a == 'H':
    print(b)
else:
    if b == 'H':
        print('D')
    else:
        print('H')
Buggy python submission (verdict: Runtime Error):
# https://beta.atcoder.jp/contests/arc070/submissions/2980516
from bisect import bisect_left

N, K = map(int, input().split())
A = sorted(map(int, input().split()))
A = A[:bisect_left(A, K)]
dp = [False] * K
dp[0] = True
curr_max = 0
ans = len(A)
for i, a in reversed(enumerate(A)):
    # a[i - 1]を使ってa[i]が必要ならa[i - 1]も必要
    # a[i]より大きな値を使って判定すればいい
    if curr_max + a >= K:
        ans = i

    f = True
    for j in range(min(curr_max, K - a - 1), -1, -1):
        if dp[j]:
            dp[j + a] = True
            if f:
                curr_max = max(curr_max, j + a)
                f = False
print(ans)

Fixed submission:
# https://beta.atcoder.jp/contests/arc070/submissions/2980516
from bisect import bisect_left

N, K = map(int, input().split())
A = sorted(map(int, input().split()))
A = A[:bisect_left(A, K)]
dp = [False] * K
dp[0] = True
curr_max = 0
ans = len(A)
for i, a in reversed(list(enumerate(A))):
    # a[i - 1]を使ってa[i]が必要ならa[i - 1]も必要
    # a[i]より大きな値を使って判定すればいい
    if curr_max + a >= K:
        ans = i

    f = True
    for j in range(min(curr_max, K - a - 1), -1, -1):
        if dp[j]:
            dp[j + a] = True
            if f:
                curr_max = max(curr_max, j + a)
                f = False
print(ans)
Buggy python submission (verdict: Runtime Error):
from heapq import heappop, heappush

INF = 10 ** 20

xs, ys, xt, yt = map(int, input().split())
N = int(input())
circle = [list(map(int, input().split())) for _ in range(N)]
circle = [[xs, ys, 0]] + circle + [[xt, yt, 0]]
edges_lst = [[] for _ in range(N + 2)]
for i, (x1, y1, r1) in enumerate(circle):
    for j, (x2, y2, r2) in enumerate(circle[i + 1:]):
        j += i + 1
        d = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** .5
        dist = max(0, d - r1 - r2)
        edges_lst[i].append((j, dist))
        edges_lst[j].append((i, dist))

def dijkstra():
    que = []
    heappush(que, (0, 0))
    dist_lst = [INF] * (N + 2)
    dist_lst[0] = 0
    while que:
        dist, node = heappop(que)
        for to, cost in edges_lst[node]:
            if dist_lst[to] > cost + dist:
                dist_lst[to] = cost + dist
                heappush(que, (cost + dist, to))
    return dist_lst[-1]

print('{:.10f}'.format(dijkstra()))

Fixed submission:
n, x = map(int, input().split())
a = list(map(int, input().split()))
b = [v if v < x else x for v in a]
for i in range(1, n):
    if b[i - 1] + b[i] > x:
        b[i] = x - b[i - 1]
print(sum(i - j for i, j in zip(a, b)))
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush

INF = 10 ** 20

xs, ys, xt, yt = map(int, input().split())
N = int(input())
circle = [list(map(int, input().split())) for _ in range(N)]
circle = [[xs, ys, 0]] + circle + [[xt, yt, 0]]
edges_lst = [[] for _ in range(N + 2)]
dist_lst = [INF] * (N + 2)
for i, (x1, y1, r1) in enumerate(circle):
    for j, (x2, y2, r2) in enumerate(circle[i + 1:]):
        j += i + 1
        d = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** .5
        dist = d - r1 - r2
        if d - r1 - r2 > 0:
            edges_lst[i].append((j, dist))
            edges_lst[j].append((i, dist))
        else:
            edges_lst[i].append((j, 0))
            edges_lst[j].append((i, 0))


que = []
heappush(que, (0, 0))
dist_lst[0] = 0
while que:
    dist, node = heappop(que)
    for to, cost in edges_lst[node]:
        if dist_lst[to] > cost + dist:
            dist_lst[to] = cost + dist
            heappush(que, (cost + dist, to))

print('{:.10f}'.format(dist_lst[-1]))

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra

INF = 10 ** 20

xs, ys, xt, yt = map(int, input().split())
N = int(input())
X = np.zeros((1, N + 2), dtype=np.float64)
Y = np.zeros((1, N + 2), dtype=np.float64)
R = np.zeros((1, N + 2), dtype=np.float64)

X[0][0] = xs
Y[0][0] = ys
X[0][N + 1] = xt
Y[0][N + 1] = yt

for i in range(N):
    X[0][i + 1], Y[0][i + 1], R[0][i + 1] = map(int, input().split())

# G[i][j]: iからjまでの距離
G = np.maximum(np.sqrt(np.square(X - X.T) + np.square(Y - Y.T)) - (R + R.T),
               np.zeros((N + 2, N + 2), dtype=np.float64))
# 対角行列をinfで塗りつぶす
G += np.diag(np.ones(N + 2, dtype=np.float64) * np.inf)
# 自己ループを消す
G = csgraph_from_dense(G, null_value=np.inf)
print(dijkstra(G, indices=0)[-1])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
parent = [i for i in range(N + M)]
def find(x):
    if x == parent[x]:
        return x
    parent[x] = find(parent[x])
    return parent[x]

def unite(x, y):
    x, y = find(x), find(y)
    if x == y:
        return
    parent[y] = x
for i in range(N):
    for l in list(map(int, input().split()))[1:]:
        # 言語はparentの後半
        unite(i, N + l - 1)
if all(find(0) == find(i) for i in range(N)):
    print('YES')
else:
    print('NO')

Fixed submission:
N, M = map(int, input().split())
parent = [i for i in range(N + M)]
rank = [1] * (N + M)
def find(x):
    if x == parent[x]:
        return x
    parent[x] = find(parent[x])
    return parent[x]

def unite(x, y):
    x, y = find(x), find(y)
    if x == y:
        return
    if rank[x] == rank[y]:
        rank[x] += 1
    elif rank[x] < rank[y]:
        x, y = y, x
    parent[y] = x
for i in range(N):
    for l in list(map(int, input().split()))[1:]:
        # 言語はparentの後半
        unite(i, N + l - 1)
if all(find(0) == find(i) for i in range(N)):
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
s = input()
if s.index('C') < s.rindex('F'):
    print('Yes')
else:
    print('No')

Fixed submission:
s = input()
if 'C' in s and 'F' in s and s.index('C') < s.rindex('F'):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())
print(sum(a != b for a, b in zip(input(), 'CODEFESTIVAL2016')))

Fixed submission:
print(sum(a != b for a, b in zip(input(), 'CODEFESTIVAL2016')))
Buggy python submission (verdict: Runtime Error):
N, L = map(int, input().split())
a = list(map(int, input().split()))
end = 0
for i in range(N - 1):
    if a[i] + a[i + 1] >= L:
        end = i + 1
        break
else:
    print('Impossible')
    exit()

print('Possible')
print(*range(1, end), *reversed(range(end, N)), sep='\n')

Fixed submission:
N, L = map(int, input().split())
a = list(map(int, input().split()))
end = 0
for i in range(N - 1):
    if a[i] + a[i + 1] >= L:
        end = i + 1
        break
else:
    print('Impossible')
    exit()

ans = list(range(1, end)) + list(range(end, N))[::-1]
print('Possible')
print(*ans, sep='\n')
Buggy python submission (verdict: Runtime Error):
for t in range(int(input())):
	s=input()
	freq=[0]*(26)
	ct=0
	for i in range(len(s)):
		freq[ord(s[i])-ord('a')]+=1
		if freq[ord(s[i])-ord('a')]==1:
			ct+=1
	ans=1
	for i in range(26):
		if freq[i]>0:
			ans=(ans*(freq[i]+1))
	print((ans-1)%1000000007)



Fixed submission:
for t in range(1):
	n=input()
	s=input()
	freq=[0]*(26)
	ct=0
	for i in range(len(s)):
		freq[ord(s[i])-ord('a')]+=1
		if freq[ord(s[i])-ord('a')]==1:
			ct+=1
	ans=1
	for i in range(26):
		if freq[i]>0:
			ans=(ans*(freq[i]+1))
	print((ans-1)%1000000007)
Buggy python submission (verdict: Runtime Error):
import math
n,m,k=map(int,input().split())
print(math.gcd(n,m))

Fixed submission:
n,m,k=map(int,input().split())
for i in range(min(n,m),0,-1):
	if n%i==0 and m%i==0:
		k-=1
		if k==0:
			print(i)
			exit()

Buggy python submission (verdict: Runtime Error):
import math
n,m,k=map(int,input().split())
g=math.gcd(n,m)
for i in range(1,101):
	if g%i==0:
		k-=1
		if k==0:
			print(i)
			exit() 

Fixed submission:
n,m,k=map(int,input().split())
for i in range(min(n,m),0,-1):
	if n%i==0 and m%i==0:
		k-=1
		if k==0:
			print(i)
			exit()

Buggy python submission (verdict: Runtime Error):
import math
n,m,k=map(int,input().split())
g=math.gcd(n,m)
for i in range(1,101):
	if g%i==0:
		k-=1
		if k==0:
			print(i)
			exit() 

Fixed submission:
n,m,k=map(int,input().split())
for i in range(min(n,m),0,-1):
	if n%i==0 and m%i==0:
		k-=1
		if k==0:
			print(i)
			exit()

Buggy python submission (verdict: Runtime Error):
import math
n,m,k=map(int,input().split())
g=math.gcd(n,m)
for i in range(1,101):
	if g%i==0:
		k-=1
		if k==0:
			print(i)
			exit() 

Fixed submission:
n,m,k=map(int,input().split())
for i in range(min(n,m),0,-1):
	if n%i==0 and m%i==0:
		k-=1
		if k==0:
			print(i)
			exit()
Buggy python submission (verdict: Runtime Error):
    s=input()
  	z,o=0,0
    for i in range(len(s)):
      if s[i]=="0":
        z+=1
      else:
        o+=1
    print(2*min(z,o))

Fixed submission:
s=input()
z,o=0,0
for i in range(len(s)):
  if s[i]=="0":
    z+=1
  else:
    o+=1
print(2*min(z,o))

Buggy python submission (verdict: Runtime Error):
s=input()
for i in range(len(s)):
  if s[i]=="0":
    z+=1
  else:
    o+=1
print(2*min(0,1))

Fixed submission:
s=input()
z,o=0,0
for i in range(len(s)):
  if s[i]=="0":
    z+=1
  else:
    o+=1
print(2*min(z,o))
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
dp=[0]*(n)
for i in range(n):
	s=input()
	dp[i]=[-1]*m
	for j in range(m):
		if s[j]=="#":
			dp[i][j]=0
fill=1
for i in range(m):
	if dp[0][i]<0:
		dp[0][i]=fill
	else:
		fill=0
fill=1
for i in range(1,n):
	if dp[i][0]<0:
		dp[i][0]=fill
	else:
		fill=0
for i in range(1,n):
	for j in range(1,m):
		if dp[i][j]<0:
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007
print(dp[n-1][m-1])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
dp=[0]*(n)
dp[1]=abs(arr[1]-arr[0])
for i in range(2,n):
	dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]))
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
arr=list(map(int,input().split()))
dp=[0]*(n)
dp[1]=abs(arr[1]-arr[0])
for i in range(2,n):
	mn=99999999999999
	for j in range(1,k+1):
		if i-j>=0 and mn>dp[i-j]+abs(arr[i]-arr[i-j]):
			mn=dp[i-j]+abs(arr[i]-arr[i-j])
	dp[i]=mn
# print(dp)
print(dp[n-1])


Fixed submission:
n,k=map(int,input().split())
arr=list(map(int,input().split()))
dp=[0]*(n)
dp[1]=abs(arr[1]-arr[0])
for i in range(2,n):
	mn=99999999999999
	for j in range(1,k+1):
		if i-j>=0 and mn>dp[i-j]+abs(arr[i]-arr[i-j]):
			mn=dp[i-j]+abs(arr[i]-arr[i-j])
	dp[i]=mn
# print(dp)
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
dp=[0]*(n+1)
dp[0]=1
pbl=list(map(float,input().split()))
for i in range(n):
	for j in range(i+1,-1,-1):
		dp[j]=dp[j-1]*pbl[i]+dp[j]*(1-pbl[i])
	# print(dp)
ans=0
for i in range((n+1)//2,n+1):
	ans+=dp[i]
print(ans)

Fixed submission:
n=int(input())
dp=[0]*(n+1)
dp[0]=1
pbl=list(map(float,input().split()))
for i in range(n):
	for j in range(i+1,-1,-1):
		dp[j]=dp[j-1]*pbl[i]+dp[j]*(1-pbl[i])
	# print(dp)
ans=0
for i in range((n+1)//2,n+1):
	ans+=dp[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
n = input()
total = 0
for candy in range(1, n+1):
  total += candy
 
print(candy)

Fixed submission:
n = input()
n = int(n)
total = 0
for candy in range(1, n + 1):
    total += candy

print(total)
Buggy python submission (verdict: Runtime Error):
S = list(input())
ACGT_filter = ['A', 'C', 'G', 'T']

str_length = 0
str_lengths = []
for s in S:
    if s in ACGT_filter:
        str_length += 1
    else:
        str_lengths.append(str_length)
        str_length = 0

print(max(str_lengths))

Fixed submission:
ACGT_filter = ['A', 'C', 'G', 'T']

ans = 0
now = 0
for s in input():
    if s in ACGT_filter:
        now += 1
    else:
        now = 0
    ans = max(now, ans)

print(ans)

Buggy python submission (verdict: Runtime Error):
S = list(input())
ACGT_filter = ['A', 'C', 'G', 'T']

str_length = 0
str_lengths = []
for s in S:
    if s in ACGT_filter:
        str_length += 1
    else:
        str_lengths.append(str_length)
        str_length = 0

print(max(str_lengths))

Fixed submission:
ACGT_filter = ['A', 'C', 'G', 'T']

ans = 0
now = 0
for s in input():
    if s in ACGT_filter:
        now += 1
    else:
        now = 0
    ans = max(now, ans)

print(ans)

Buggy python submission (verdict: Runtime Error):
S = list(input())
ACGT_filter = ['A', 'C', 'G', 'T']

str_length = 0
str_lengths = []
for s in S:
    if s in ACGT_filter:
        print(s)
        str_length += 1
    else:
        str_lengths.append(str_length)
        str_length = 0

print(max(str_lengths))

Fixed submission:
ACGT_filter = ['A', 'C', 'G', 'T']

ans = 0
now = 0
for s in input():
    if s in ACGT_filter:
        now += 1
    else:
        now = 0
    ans = max(now, ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
b = input()

c = {A:T,T:A,C:G,G:C}

print(c[b])

Fixed submission:
b = input()
 
c = {"A":"T","T":"A","C":"G","G":"C"}
 
print(c[b])
Buggy python submission (verdict: Runtime Error):
N, M = [int(e) for e in input().split(" ")]
d_node2setindex = {}
ABs = []
for _ in range(M):
    ABs.append([int(e) for e in input().split(" ")])
maxValue = N * (N-1) // 2
ans = [maxValue]
buf_sets = []
flagSkip = False
for i in range(M-1):
    a, b = ABs[M-1-i]
    # print("a,b", a, b)
    if flagSkip is True:
        ans.append(0)
        continue
    
    idx_a = d_node2setindex.get(a, None)
    idx_b = d_node2setindex.get(b, None)
    # if len(buf_sets) > 0:
    #     for j, s in enumerate(buf_sets):
    #         if idx_a is None:
    #             if a in s:
    #                 idx_a = j 
    #         if idx_b is None:
    #             if b in s:
    #                 idx_b = j
    #         if idx_a is not None and idx_b is not None:
    #             break
    delta = 0
    if idx_a is None and idx_b is None:
        s_new = set([a, b])
        idx_set = len(buf_sets)
        d_node2setindex[a] = idx_set
        d_node2setindex[b] = idx_set
        buf_sets.append(s_new)
        delta = 1
    elif idx_a is not None and idx_b is None:
        delta = len(buf_sets[idx_a])
        buf_sets[idx_a].add(b)
        d_node2setindex[b] = idx_a
    elif idx_a is None and idx_b is not None:
        delta = len(buf_sets[idx_b])
        buf_sets[idx_b].add(a)
        d_node2setindex[a] = idx_b
    else:
        if idx_a != idx_b:
            s_a = buf_sets[idx_a]
            s_b = buf_sets[idx_b]
            delta = len(s_a) * len(s_b)
            [d_node2setindex.__setitem__(e, idx_a) for e in s_b]
            # for e in s_b:
            #     d_node2setindex[e] = idx_a
            buf_sets[idx_a] = s_a | s_b
            buf_sets[idx_b] = None
            # buf_sets.pop(idx_b)
    
    d = ans[-1] - delta
    ans.append(d)
    if d == 0:
        flagSkip = True

txt = "\n".join(map(str, reversed(ans)))
print(txt)


Fixed submission:
A, B, C = [int(e) for e in input().split(" ")]

# N = A*C
# if N <= B:
#     print(C)

p, _ = divmod(B, A)
if p > C:
    print(C)
else:
    print(p)
Buggy python submission (verdict: Runtime Error):
import bisect

A, B, Q = [int(e) for e in input().split()]
ss = [int(input()) for _ in range(A)]
tt = [int(input()) for _ in range(B)]
xx = [int(input()) for _ in range(Q)]

for x in xx:
    buf = []
    # s right, t
    idx_s_right = min(bisect.bisect_left(ss, x), A-1)
    s_right = ss[idx_s_right]

    idx_st_right = min(bisect.bisect_left(tt, s_right), B-1)
    idx_st_left = max(0, idx_st_right - 1)
    t_right = tt[idx_st_right]
    t_left = tt[idx_st_left]

    buf.append(abs(s_right - x) + abs(t_right - s_right))
    buf.append(abs(s_right - x) + abs(t_left - s_right))
    s_right = None 
    t_right = None
    s_left = None
    t_left = None

    # s left, t
    idx_s_left = max(0, idx_s_right - 1)
    if idx_s_left != idx_s_right:
        s_left = ss[idx_s_left]

        idx_st_right = min(bisect.bisect_left(tt, s_left), B-1)
        idx_st_left = max(0, idx_st_right - 1)
        t_right = tt[idx_st_right]
        t_left = tt[idx_st_left]

        buf.append(abs(s_left - x) + abs(t_right - s_left))
        buf.append(abs(s_left - x) + abs(t_left - s_left))
    
        s_right = None 
        t_right = None
        s_left = None
        t_left = None

    # t right, r 
    idx_t_right = min(bisect.bisect_left(tt, x), B-1)
    t_right = tt[idx_t_right]

    idx_ts_right = min(bisect.bisect_left(ss, t_right), A-1)
    idx_ts_left = max(0, idx_ts_right - 1)
    s_right = ss[idx_ts_right]
    s_left = ss[idx_ts_left]

    buf.append(abs(t_right - x) + abs(s_right - t_right))
    buf.append(abs(t_right - x) + abs(s_left - t_right))
    
    s_right = None 
    t_right = None
    s_left = None
    t_left = None

    # s left, t
    idx_t_left = max(0, idx_t_right - 1)
    if idx_t_left != idx_t_right:
        t_left = ss[idx_t_left]

        idx_ts_right = min(bisect.bisect_left(ss, t_left), A-1)
        idx_ts_left = max(0, idx_ts_right - 1)
        s_right = tt[idx_ts_right]
        s_left = tt[idx_ts_left]

        buf.append(abs(t_left - x) + abs(s_right - t_left))
        buf.append(abs(t_left - x) + abs(s_left - t_left))

    print(min(buf))


Fixed submission:
import bisect

A, B, Q = [int(e) for e in input().split()]
ss = [int(input()) for _ in range(A)]
tt = [int(input()) for _ in range(B)]
xx = [int(input()) for _ in range(Q)]
INF = 10 ** 18
for x in xx:
    idx_s_right = min(bisect.bisect_left(ss, x), A-1)
    idx_s_left = max(0, idx_s_right - 1)
    stmps = [ss[idx_s_right], ss[idx_s_left]]

    ttmps = [] 
    idx_t_right = min(bisect.bisect_left(tt, x), B-1)
    idx_t_left = max(0, idx_t_right - 1)
    ttmps = [tt[idx_t_right], tt[idx_t_left]]

    mem = INF
    for s in stmps:
        for t in ttmps:
            d_s = abs(s - x) + abs(t - s)
            d_t = abs(t - x) + abs(s - t)
            mem = min(mem, d_s, d_t)
    print(mem)