Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=[int(input()) for _ in range(n)]
dp=[0]*n
dp[0]=1
mod=10**9+7
record={arr[0]:0}
for i,v in enumerate(arr):
  if i==0:
    continue
  dp[i]=dp[i-1]
  if record[v] and record[v]<i-1:
    dp[i]+=dp[record[v]]
    dp[i]=dp[i]%mod
print(dp[-1])

Fixed submission:
n=int(input())
arr=[int(input()) for _ in range(n)]
mod=10**9+7

dp=[0]*n
dp[0]=1

record={arr[0]:0}

for i,v in enumerate(arr):
  if i==0:
    continue
  dp[i]=dp[i-1]
  if v in record and record[v]<i-1:
    dp[i]+=dp[record[v]]
    dp[i]=dp[i]%mod
  record[v]=i
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
s=input()
num0,num1=0,0
for i in s:
  if i=='0':
    nums0+=1
  elif i=='1':
    nums1+=1
print(2*min(num0,num1))

Fixed submission:
s=input()
a_1=s.count("1")
b_1=s.count("0")
if a_1<=b_1:
  print(2*a_1)
else:
  print(2*b_1)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
alist=[]
blist=[]
for i in range(M):
  a,b=map(int,input().split())
  alist.append(a)
  blist.append(b)
father=[i for i in range(N+1)]
rank=[0]*(N+1)
size=[1]*(N+1)

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

def union(x,y):
  x,y=find(x),find(y)
  if x==y:
    return
  elif rank[x]<rank[y]:
    father[x]=y
    size[y]+=size(x)
  else:
    father[y]=x
    size[x]+=size[y]
    if rank[x]==rank[y]:
      rank[x]+=1
      
def samefather(x,y):
  return find(x)==find(y)

ans_list=[]
ans=N*(N-1)/2
for i in range(M):
  ans_list.append(ans)
  a=alist[M-1-i]
  b=alist[M-1-i]
  p,q=size[find(a)],size[size(b)]
  if samefather(a,b):
    continue
  else:
    ans-=p*q
    union(a,b)
for i in range(M):
  print(ans_list[M-1-i])

Fixed submission:
N, M = map(int, input().split())
a_list = []
b_list = []
for i in range(M):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

par = [i for i in range(N+1)]
rank = [0]*(N+1)
size = [1] * (N + 1)

def find(x):
    if par[x] == x:
        return par[x]
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x, y):
    x_par = find(x)
    y_par = find(y)
    if x_par == y_par:
        return
    if rank[x_par] < rank[y_par]:
        par[x_par] = y_par
        size[y_par] += size[x_par]
    else:
        par[y_par] = x_par
        size[x_par] += size[y_par]
        if rank[x_par] == rank[y_par]:
            rank[x_par] += 1


def bool_func(x, y):
    if find(x) == find(y):
        return True
    else:
        return False


ans_list = []      
ans = int(N*(N-1)/2)
for i in range(M):
    ans_list.append(ans)
    a = a_list[M-1-i]
    b = b_list[M-1-i]
    p = size[find(a)]
    q = size[find(b)]
    if bool_func(a, b):
        pass
    else:
        ans -= p*q
        unite(a, b)

for i in range(M):
    print(ans_list[M-1-i])
Buggy python submission (verdict: Runtime Error):
a,b,c=list(map(int,input.split('/')))
if b>4:
  print('TBD')
else:
  print('Heisei')

Fixed submission:
a,b,c=list(map(int,input().split('/')))
if b>4:
  print('TBD')
else:
  print('Heisei')

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input.split('/'))
if b>4:
  print('TBD')
else:
  print('Heisei')

Fixed submission:
a,b,c=list(map(int,input().split('/')))
if b>4:
  print('TBD')
else:
  print('Heisei')

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a>2019:
  print('TBD')
elif a<2019:
  print('Heisei')
else:
  if b>4:
    print('TBD')
  elif b<=4:
    print('Heisei')
    

Fixed submission:
a,b,c=list(map(int,input().split('/')))
if b>4:
  print('TBD')
else:
  print('Heisei')
Buggy python submission (verdict: Runtime Error):
num=int(input())
res=0
for i in range(num):
  t=input().split()
  if t[1]=='BTC':
    t[0]=int(t[0])*380000
  res+=int(t[0])
print(res)

Fixed submission:
N = int(input())
ans = 0
for i in range(N):
    x, v = input().split()
    x = float(x)
    if v == "BTC":
        x *= 380000
    ans += x 
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input().split())
dic=set()
dic|={n}
i=1
while True:
  if n%2==0:
    n=n//2
  else:
    n=3*n+1
  if n in dic:
    print(i+1)
    break
  else:
    dic|={n}
    i+=1


Fixed submission:
s = int(input())

used = set()
used |= {s}
count = 1

while True:
    if s % 2 == 0: s//=2
    else:s=3*s+1
    if s in used:
        print(count+1)
        break
    else:
        used |= {s}
        count += 1

Buggy python submission (verdict: Runtime Error):
n=int(input().split())
dic=set()
dic|={n}
i=1
while True:
  if n%2==0:
    n=n//2
  else:
    n=3*n+1
  i+=1
  if n in dic:
    print(i)
    break
  else:
    dic|={n}


Fixed submission:
s = int(input())

used = set()
used |= {s}
count = 1

while True:
    if s % 2 == 0: s//=2
    else:s=3*s+1
    if s in used:
        print(count+1)
        break
    else:
        used |= {s}
        count += 1

Buggy python submission (verdict: Runtime Error):
n=int(input().split())
dic=set()
dic|={1}
i=1
while True:
  if n%2==0:
    n=n//2
  else:
    n=3*n+1
  i+=1
  if n in dic:
    print(i)
    break
  else:
    dic|={i}


Fixed submission:
s = int(input())

used = set()
used |= {s}
count = 1

while True:
    if s % 2 == 0: s//=2
    else:s=3*s+1
    if s in used:
        print(count+1)
        break
    else:
        used |= {s}
        count += 1

Buggy python submission (verdict: Runtime Error):
n=int(input().split())
dic={n:1}
i=1
while True:
  if n%2==0:
    n=n//2
  else:
    n=3*n+1
  i+=1
  if n in dic:
    print(i)
    break
  else:
    dic[n]=i

Fixed submission:
s = int(input())

used = set()
used |= {s}
count = 1

while True:
    if s % 2 == 0: s//=2
    else:s=3*s+1
    if s in used:
        print(count+1)
        break
    else:
        used |= {s}
        count += 1

Buggy python submission (verdict: Runtime Error):
n=int(input().split())
dic={n:1}
i=1
while True:
  if n%2==0:
    n=n//2
  else:
    n=3*n+1
  i+=1
  if n in dic:
    print(dic[n])
    break
  else:
    dic[n]=i

Fixed submission:
s = int(input())

used = set()
used |= {s}
count = 1

while True:
    if s % 2 == 0: s//=2
    else:s=3*s+1
    if s in used:
        print(count+1)
        break
    else:
        used |= {s}
        count += 1
Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=map(int,input().split())
from collections import Counter
even=Counter(arr[::2])
even[0]=0
odd=Counter(arr[1::2])
odd[0]=0
even1,even2=even.most_common(2)
odd1,odd2=odd.most_common(2)
if even1[0]!=odd1[0]:
  print(n-(even1[1]+odd1[1]))
else:
  print(n-max(even1[1]+odd2[1],even2[1]+odd1[1]))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
from collections import Counter
even=Counter(arr[::2])
even[0]=0
odd=Counter(arr[1::2])
odd[0]=0
even1,even2=even.most_common(2)
odd1,odd2=odd.most_common(2)
if even1[0]!=odd1[0]:
  print(n-(even1[1]+odd1[1]))
else:
  print(n-max(even1[1]+odd2[1],even2[1]+odd1[1]))
Buggy python submission (verdict: Time Limit Exceeded):
def calcDiv(n):
    d_list = [1, n]
    for i in range(2, int(n**(1/2))+1):
        if n%i == 0:
            d_list.append(i)
            d_list.append(int(n/i))
    return d_list


def isPrime(n):
    for i in range(2, n):
        if n % i == 0:
            return False
    return True


if __name__ == "__main__":    
    a, b = map(int, input().split())
    a_list = calcDiv(a)
    b_list = calcDiv(b)
    d_list = set(a_list) & set(b_list)
    cnt = 0
    for d in d_list:
        if isPrime(d):
            cnt += 1
    print(cnt)


Fixed submission:
def calcDiv(n):
    d_list = []
    for i in range(1, int(n**(1/2))+1):
        if n%i == 0:
            d_list.append(i)
            d_list.append(int(n/i))
    return d_list


def isPrime(n):
    for i in range(2, int(n**(1/2))+1):
        if n % i == 0:
            return False
    return True


if __name__ == "__main__":    
    a, b = map(int, input().split())
    a_list = calcDiv(a)
    b_list = calcDiv(b)
    d_list = set(a_list) & set(b_list)
    cnt = 0
    for d in d_list:
        if isPrime(d):
            cnt += 1
    print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
print(sum(range(int(input()))))


Fixed submission:
print(sum(range(int(input()))))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math

def add_ball(idx):
    add_list = []
    for j in range(1, int(math.sqrt(idx))+1):
        if idx%j == 0:
            add_list.append(j)
            if j != idx//j:
                add_list.append(idx//j)
    for k in add_list:
        b_list[k] += 1

if __name__ == "__main__":
    input = sys.stdin.readline

    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = [0] * (n+1)
    ans_list = []
    for a, i in zip(reversed(a_list), range(n, 0, -1)):
        if a != b_list[i]%2:
            ans_list.append(i)
            add_ball(i)
    cnt = len(ans_list)
    ans_list.sort()
    print(cnt)
    if cnt > 0:
        print(' '.join(map(str, ans_list)))


Fixed submission:
import sys
import math

def add_ball(idx):
    add_list = []
    for j in range(1, int(math.sqrt(idx))+1):
        if idx%j == 0:
            add_list.append(j)
            if j != idx//j:
                add_list.append(idx//j)
    for k in add_list:
        b_list[k] += 1

if __name__ == "__main__":
    input = sys.stdin.readline

    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = [0] * (n+1)
    cnt = 0
    ans_list = []
    for a, i in zip(reversed(a_list), range(n, 0, -1)):
        if a != b_list[i]%2:
            cnt += 1
            ans_list.append(i)
            add_ball(i)
    ans_list.sort()
    print(cnt)
    if cnt > 0:
        print(' '.join(map(str, ans_list)))

Buggy python submission (verdict: Runtime Error):
import sys
import math

def add_ball(idx):
    add_list = [idx]
    if idx > 1:
        for j in range(2, int(math.sqrt(idx))+1):
            if idx%j == 0:
                add_list.append(j)
                if j != idx//i:
                    add_list.append(idx//j)
    for k in add_list:
        b_list[k-1] = (b_list[k-1]+1)%2

if __name__ == "__main__":
    input = sys.stdin.readline

    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = [0] * n
    for i, a in enumerate(a_list[::-1]):
        if a != b_list[-i-1]:
            add_ball(n-i)
    ball_sum = sum(b_list)
    ball_list = [i+1 for i, b in enumerate(b_list) if b == 1]
    print(ball_sum)
    if ball_sum > 0:
        print(' '.join(map(str, ball_list)))


Fixed submission:
import sys
import math

def add_ball(idx):
    add_list = []
    for j in range(1, int(math.sqrt(idx))+1):
        if idx%j == 0:
            add_list.append(j)
            if j != idx//j:
                add_list.append(idx//j)
    for k in add_list:
        b_list[k] += 1

if __name__ == "__main__":
    input = sys.stdin.readline

    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = [0] * (n+1)
    cnt = 0
    ans_list = []
    for a, i in zip(reversed(a_list), range(n, 0, -1)):
        if a != b_list[i]%2:
            cnt += 1
            ans_list.append(i)
            add_ball(i)
    ans_list.sort()
    print(cnt)
    if cnt > 0:
        print(' '.join(map(str, ans_list)))
Buggy python submission (verdict: Runtime Error):
from operator import mul
from functools import reduce


def comb(n, r):
    r = min(n-r,r)
    if r == 0:
      return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

  
n, k = map(int, input().split())
for i in range(1, k+1):
	dis = k - i
	cnt = comb(n-k+1, i)
	if i > 1:
		cnt *= comb(k-1, i-1)
	print(cnt%(10**9+7))


Fixed submission:
from operator import mul
from functools import reduce


def comb(n, r):
    r = min(n-r,r)
    if r == 0:
      return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

  
n, k = map(int, input().split())
for i in range(1, k+1):
	if n-k+1 >= i:
		cnt = comb(n-k+1, i) * comb(k-1, i-1)
		print(cnt%(10**9+7))
	else:
		print(0)

Buggy python submission (verdict: Runtime Error):
import math

def comb(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, k = map(int, input().split())
for i in range(1, k+1):
	dis = k - i
	cnt = comb(n-k+1, i)
	if i > 1:
		cnt *= comb(k-1, i-1)
	print(cnt%(10**9+7))


Fixed submission:
from operator import mul
from functools import reduce


def comb(n, r):
    r = min(n-r,r)
    if r == 0:
      return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

  
n, k = map(int, input().split())
for i in range(1, k+1):
	if n-k+1 >= i:
		cnt = comb(n-k+1, i) * comb(k-1, i-1)
		print(cnt%(10**9+7))
	else:
		print(0)

Buggy python submission (verdict: Runtime Error):
import math

def comb(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, k = map(int, input().split())
for i in range(1, k+1):
	dis = k - i
	cnt = comb(n-k+1, i)
	for j in range(i, 1, -1):
		cnt *= comb(j, j-dis)
	print(cnt%(10**9+7))


Fixed submission:
from operator import mul
from functools import reduce


def comb(n, r):
    r = min(n-r,r)
    if r == 0:
      return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

  
n, k = map(int, input().split())
for i in range(1, k+1):
	if n-k+1 >= i:
		cnt = comb(n-k+1, i) * comb(k-1, i-1)
		print(cnt%(10**9+7))
	else:
		print(0)
Buggy python submission (verdict: Runtime Error):
import math


def lcm(x, y):
    return int((x * y) / math.gcd(x, y))


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    cnt_ac, cnt_bc = int((a-1)/c), int(b/c)
    cnt_ad, cnt_bd = int((a-1)/d), int(b/d)
    cnt_acd, cnt_bcd = int(a/lcm(c,d)), int(b/lcm(c,d))
    print((cnt_bc-cnt_ac), (cnt_bd-cnt_ad), (cnt_bcd-cnt_acd))
    print((b-a+1) - ((cnt_bc-cnt_ac)+(cnt_bd-cnt_ad)-(cnt_bcd-cnt_acd)))


Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(x, y):
    return (x * y) // gcd(x, y)


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    a -= 1
    cnt = b - a
    cnt -= b//c - a//c
    cnt -= b//d - a//d
    l = lcm(c, d)
    cnt += b//l - a//l
    print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline

n, m = map(int, input().split())
a_list = []
comb_list = [0, 1, 2]
for _ in range(m):
    a = int(input())
    if a == 1:
        comb_list[a] = 0
        comb_list[a+1] = 1
    elif a == 2:
        comb_list[a] = 0
    else:
        a_list.append(a)
for i in range(3, n+1):
    if i in a_list:
        comb_list.append(0)
    else:
        comb_list.append((comb_list[-2]+comb_list[-1])%(10**9+7))
print(comb_list[n])


Fixed submission:
import sys

input = sys.stdin.readline

n, m = map(int, input().split())
a_list = []
comb_list = [0, 1, 2, 3]
n_2, n_1 = 2, 3
for i in range(3, n):
    n_2, n_1 = n_1, (n_2+n_1)%(10**9+7)
    comb_list.append(n_1)
for _ in range(m):
    a = int(input())
    a_list.append(a)
start = 0
ans = 1
if m == 0:
    ans = comb_list[n]
else:
    for a in a_list+[n+1]:
        if a == 1:
            start = a + 1
            continue
        else:
            if start == a:
                ans = 0
                break
            elif start == a - 1:
                start = a + 1
            else:
                tmp = a - start - 1
                ans = (ans * comb_list[tmp])%(10**9+7)
                if a == n-1:
                    break
                else:
                    start = a + 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline
r, g, b, n = map(int, input().split())
cnt = 0
for i in range(int(n/r)+1):
    for j in range(int(n/g)+1):
        tmp = r*i + g*j
        if tmp > n:
            break
        else:
            tmp = n - tmp 
        if tmp%b == 0:
            cnt += 1
print(cnt)


Fixed submission:
r, g, b, n = map(int, input().split())
cnt = 0
for i in range(0, n+1, r):
    for j in range(0, n+1, g):
        tmp = n - (i+j)
        if tmp < 0:
            break
        if tmp%b == 0:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

input = sys.stdin.readline
n = int(input())
a_que = deque(list(map(int, input().split())))
ans = 1
for _ in range(n):
    out = a_que.popleft()
    m = 0
    for a in a_que:
        m = gcd(m, a)
    ans = max(ans, m)
    a_que.append(out)
print(ans)


Fixed submission:
import sys

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

input = sys.stdin.readline
n = int(input())
a_list = list(map(int, input().split()))
l_list = [0]
r_list = [0]
l_gcd, r_gcd = 0, 0
for i in range(n-1):
    l_gcd = gcd(l_gcd, a_list[i])
    l_list.append(l_gcd)
    r_gcd = gcd(r_gcd, a_list[-i-1])
    r_list.append(r_gcd)
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_list[i], r_list[-i-1]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

input = sys.stdin.readline
n = int(input())
a_list = list(map(int, input().split()))
ans = 1
for i in range(n):
    if i == 0:
        gcd_r = 0
        r_list = a_list[i+1:]
        for r in r_list:
            if gcd_r == 0:
                gcd_r = r
            else:
                gcd_r = gcd(gcd_r, r)
        m = gcd_r
    elif i == n-1:
        gcd_l = 0
        l_list = a_list[:i]
        for l in l_list:
            if gcd_l == 0:
                gcd_l = l
            else:
                gcd_l = gcd(gcd_l, l)
        m = gcd_l
    else:
        gcd_l, gcd_r = 0, 0
        l_list = a_list[:i]
        r_list = a_list[i+1:]
        for l in l_list:
            if gcd_l == 0:
                gcd_l = l
            else:
                gcd_l = gcd(gcd_l, l)
        for r in r_list:
            if gcd_r == 0:
                gcd_r = r
            else:
                gcd_r = gcd(gcd_r, r)
        m = gcd(gcd_l, gcd_r)
    ans = max(ans, m)
print(ans)


Fixed submission:
import sys

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

input = sys.stdin.readline
n = int(input())
a_list = list(map(int, input().split()))
l_list = [0]
r_list = [0]
l_gcd, r_gcd = 0, 0
for i in range(n-1):
    l_gcd = gcd(l_gcd, a_list[i])
    l_list.append(l_gcd)
    r_gcd = gcd(r_gcd, a_list[-i-1])
    r_list.append(r_gcd)
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_list[i], r_list[-i-1]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline

x, y, z, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)
tmp_list = [a+b for a in a_list for b in b_list]
tmp_list.sort(reverse=True)
honest_list = [tmp+c for tmp in tmp_list for c in c_list]
honest_list.sort(reverse=True)
for h in honest_list[:k]:
    print(h)


Fixed submission:
import sys

input = sys.stdin.readline

x, y, z, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)
tmp_list = [a+b for a in a_list for b in b_list]
tmp_list.sort(reverse=True)
honest_list = [tmp+c for tmp in tmp_list[:k] for c in c_list]
honest_list.sort(reverse=True)
for h in honest_list[:k]:
    print(h)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline

x, y, z, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)
tmp_list = []
for a in a_list:
    for b in b_list:
            tmp_list.append(a+b)
tmp_list.sort(reverse=True)
honest_list = []
for tmp in tmp_list[:k]:
    for c in c_list:
        honest_list.append(tmp+c)
honest_list.sort(reverse=True)
for h in honest_list[:k]:
    print(h)


Fixed submission:
import sys

input = sys.stdin.readline

x, y, z, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
a_list.sort(reverse=True)
b_list.sort(reverse=True)
c_list.sort(reverse=True)
tmp_list = [a+b for a in a_list for b in b_list]
tmp_list.sort(reverse=True)
honest_list = [tmp+c for tmp in tmp_list[:k] for c in c_list]
honest_list.sort(reverse=True)
for h in honest_list[:k]:
    print(h)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque


def bfs(s):
    flag_list[s] = 1
    color_list[s] = 0
    q.append(s)
    while len(q)>0:
        u = q.popleft()
        for v, w in enumerate(m_list[u]):
            if w > 0 and flag_list[v] == 0:
                flag_list[v] = 1
                if w%2 == 0:
                    color_list[v] = color_list[u]
                else:
                    color_list[v] = (color_list[u]+1)%2
                q.append(v)
        flag_list[u] = 2


if __name__ == "__main__":
    input = sys.stdin.readline
    n = int(input())
    m_list = [[0]*n for _ in range(n)]
    color_list = [0]*n
    flag_list = [0]*n
    q = deque([])
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        m_list[u-1][v-1] = w
        m_list[v-1][u-1] = w
    bfs(0)
    for color in color_list:
        print(color)


Fixed submission:
import sys
import bisect


input = sys.stdin.readline
a, b, q = map(int, input().split())
inf = 10**12
s_list = [-inf] + [int(input()) for _ in range(a)] + [inf]
s_list.sort()
t_list = [-inf] + [int(input()) for _ in range(b)] + [inf]
t_list.sort()
ans_list =[]
for _ in range(q):
    x = int(input())
    s_idx = bisect.bisect_right(s_list, x)
    t_idx = bisect.bisect_right(t_list, x)
    ans = inf
    for s in [s_list[s_idx-1], s_list[s_idx]]:
        for t in [t_list[t_idx-1], t_list[t_idx]]:
            ans = min(ans, min(abs(x-s), abs(x-t)) + abs(s-t))
    print(ans)