Harryxun/stf_run huggingface dataset:
n,q=map(int,input().split())
ki=[[] for i in range(n+1)]
ki[0]="null"

for i in range(n-1):
    a,b=map(int,input().split())
    ki[a].append(b)

scores=[0 for i in range(n+1)]
scores[0]="null"
for i in range(q):
    p,x=map(int,input().split())
    scores[p]+=x


ans=[0 for i in range(n+1)]
ans[0]="null"
point=0


def tansa(n,point):
    point+=scores[n]
    for p in ki[n]:
        tansa(p,point)
    else:
        ans[n]=point
        
tansa(1,0)

ans=ans[1:]
ans=[str(i) for i in ans]
print(" ".join(ans[1:]))

### FIXED CODE ###

n,q=map(int,input().split())
L=[[] for i in range(n+1)]
S=[0 for i in range(n+1)]
V=[0 for i in range(n+1)]

for _ in range(n-1):
    a,b=map(int,input().split())
    L[a].append(b)   
    L[b].append(a)

for _ in range(q):
    p,x=map(int,input().split())
    S[p]+=x


que=[1]
head=0
V[1]=1
while len(que)>head:
    now=que[head]
    head+=1
    for nex in L[now]:
        if V[nex]==0:
            V[nex]=1
            que.append(nex)
            S[nex]+=S[now]

print(" ".join([str(i) for i in S[1:]]))
N,K=map(int,input().split())
A=sorted(list(map(int,input().split())))[::-1]
mod=10**9+7
score=1

if K%2==1:  #これでKは偶数として扱えるようになった
    score*=A[0]
    A.pop(0)
    K-=1

#print(A)

P,M=[],[]
for i in A:
    if i>0:
        P.append(i)
    else:
        M.append(i)

M=M[::-1]
t=0
p,m=0,0
while t<=K:
    if score<0:  #負であることが確定しているなら小さくなるようにする
        P=P[::-1]
        M=M[::-1]
    if t+2<=K:
        if 2*p+1<len(P) and 2*m+1<len(M):
            if P[2*p]*P[2*p+1] >= M[2*m]*M[2*m+1]:
                score*=P[2*p]*P[2*p+1]
                p+=1
                t+=2
            else:
                score*=M[2*m]*M[2*m+1]
                m+=1
                t+=2
        elif 2*p+1<len(P):
            score*=P[2*p]*P[2*p+1]
            p+=1
            t+=2
        else:
            score*=M[2*m]*M[2*m+1]
            m+=1
            t+=2
    elif t+1<=K:
        if 2*p<len(P):
            score*=P[2*p]
        else:
            score*=M[2*m]
        break
    else:
        break
    score%=mod

print(score%mod)

### FIXED CODE ###

import sys

N,K=map(int,input().split())
A=sorted(list(map(int,input().split())))[::-1]
mod=10**9+7
score=1

if K%2==1:  #これでKは偶数として扱えるようになった
    score*=A[0]
    A.pop(0)
    K-=1

#print(A)

P,M=[],[]
for i in A:
    if i>0:
        P.append(i)
    else:
        M.append(i)

M=M[::-1]
t=0
p,m=0,0
while t<=K:
    if score<0:  #負であることが確定しているなら小さくなるようにする
        P=P[::-1]
        M=M[::-1]
        if 0 in M:
            print(0)
            sys.exit()
    if t+2<=K:
        if 2*p+1<len(P) and 2*m+1<len(M):
            if P[2*p]*P[2*p+1] >= M[2*m]*M[2*m+1]:
                score*=P[2*p]*P[2*p+1]
                p+=1
                t+=2
            else:
                score*=M[2*m]*M[2*m+1]
                m+=1
                t+=2
        elif 2*p+1<len(P):
            score*=P[2*p]*P[2*p+1]
            p+=1
            t+=2
        elif 2*m+1<len(M):
            score*=M[2*m]*M[2*m+1]
            m+=1
            t+=2
        else:  #?
            score*=P[-1]*M[-1]
            break
    elif t+1<=K:
        if 2*p<len(P):
            score*=P[2*p]
        else:
            score*=M[2*m]
        break
    else:
        break
    score%=mod

print(score%mod)
N,M = map(int, input().split())
edge=[[] for j in range(N+1)]
x = [0] * M
y = [0] * M

#N,M=4,5
#x=[1, 1, 3, 2, 3]
#y=[2, 3, 2, 4, 4]
#edge=[[], [2, 3], [4], [2, 4], []]  

for i in range(M):
    x[i], y[i] = map(int, input().split())
    edge[x[i]].append(y[i])
dp=[-1]*(N+1)
def f(x):
    if dp[x]!=-1:
        return dp[x]
    num=0
   
    for i in edge[x]:
        num=max(num,f(i)+1)
    
    dp[x]=num
    return dp[x]
for i in range(1,N+1):
    i,f(i)
print(max(dp))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
 
 
N, M = map(int, input().split())
 
G = [[] for _ in range(N + 1)]
for i in range(M):
    x, y = map(int, input().split())
    G[x] += [y]
# print(G)
 
dp = [-1] * (N + 1)
 
 
def func(n):
    if dp[n] != -1:
        return dp[n]
    cnt = 0
	# 先にノードが存在する場合
	# ノードが存在しない場合は、cnt=0のままforをすっ飛ばす
    for m in G[n]:
        cnt = max(cnt, func(m) + 1)
    dp[n] = cnt
    return cnt
 
 
for i in range(1, N + 1):
    func(i)
 
# print(dp)
print(max(dp))
def main():
    x, n = map(int, input().split())
    
    if n==0:
        print(x)
    else:
        p = list(map(int, input().split()))
        truefalse = [True]*100
        for i in range(n):
            truefalse[p[i]-1] = False
        
        a = 0
        while 1:
            if truefalse[x-a-1]:
                print(x-a)
                break
            elif truefalse[x+a-1]:
                print(x+a)
                break
            else:
                a += 1

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    x, n = map(int, input().split())
    
    if n==0:
        print(x)
    else:
        p = list(map(int, input().split()))
        #p = [i+1 for i in range(100)]
        truefalse = [True]*101
        for i in range(n):
            truefalse[p[i]-1] = False
        
        a = 0
        while 1:
            if truefalse[x-a-1]:
                print(x-a)
                break
            elif truefalse[x+a-1]:
                print(x+a)
                break
            else:
                a += 1

if __name__ == "__main__":
    main()
h = list(map(str, input().split(,)))
ans = ' '.join(h)
print(ans)

### FIXED CODE ###

h = list(map(str, input().split(',')))
ans = ' '.join(h)
print(ans)
n = int(input())
s = input()
pat = "ABC"

ans =0
i=0
while i < n:
  if pat = s[i:len(pat)]:
    ans+=1

print(ans)

### FIXED CODE ###

n = int(input())
s = input()
pat = "ABC"

ans = 0
i = 0
while i < n:
    if pat == s[i : i + len(pat)]:
        ans += 1
    i += 1

print(ans)
H,W=map(int,input().split())
S=[[] for _ in range(H)]

for i in range(H):
    S[i]=input()
    
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

n=H*W
inf=10**9

d = [[inf]*n for _ in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            if j+1<W:
                if S[i][j+1]==".":
                    d[i*H+j][i*H+j+1]=1
                    d[i*H+j+1][i*H+j]=1
            if i+1<H:
                if S[i+1][j]==".":
                    d[i*H+j][(i+1)*H+j]=1
                    d[(i+1)*H+j][i*H+j]=1
    
        
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
ans=0

warshall_floyd(d)

for i in range(n):
    for j in range(n):
        if d[i][j]>=ans and d[i][j]<=inf-10:
            ans=d[i][j]

print(ans)

### FIXED CODE ###

H,W=map(int,input().split())
S=[[] for _ in range(H)]

for i in range(H):
    S[i]=input()
    
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

n=H*W
inf=10**9

d = [[inf]*n for _ in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            if j+1<W:
                if S[i][j+1]==".":
                    d[i*W+j][i*W+j+1]=1
                    d[i*W+j+1][i*W+j]=1
            if i+1<H:
                if S[i+1][j]==".":
                    d[i*W+j][(i+1)*W+j]=1
                    d[(i+1)*W+j][i*W+j]=1
    
        
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
ans=0

warshall_floyd(d)

for i in range(n):
    for j in range(n):
        if d[i][j]>=ans and d[i][j]<=inf-10:
            ans=d[i][j]

print(ans)
k,n = map(int,input().split())
if k%2 == 0:
  ans = [k//2]+[k//2+1]*(n-1)
else:
  print(2/0)
  t = n//2
  ans = [k//2+1]*n
  for i in range(t):
    if len(ans) < n:
      ans[-1] -= 1
      ans.append(k)
    elif ans[-1] > 1:
      ans[-1] -= 1
    else:
      ans.pop()
print(*ans)

### FIXED CODE ###

k,n = map(int,input().split())
if k%2 == 0:
  ans = [k//2]+[k]*(n-1)
else:
  t = n//2
  ans = [k//2+1]*n
  for i in range(t):
    if ans[-1] == 1:
      ans.pop()
    else:
      ans[-1] -= 1
      while len(ans) < n:
        ans.append(k)
print(*ans)
a = int(input())
b = int(input())
add = a + b
sub = a - b
mul = a * b
callist = [add, sub, mul]
print(max(callist))

### FIXED CODE ###

a, b = map(int, input().split())
add = a + b
sub = a - b
mul = a * b
callist = [add, sub, mul]
print(max(callist))
# https://atcoder.jp/contests/abc043/tasks/arc059_a
# C - いっしょ / Be Together
import statistics
N = int(input().split()[0])
a_list = list(map(int, input().split()))

min_a, max_a = min(a_list), max(a_list)
w_list = list(range(min_a, max_a+1))
m1 = statistics.median_low(w_list)
m2 = statistics.median_high(w_list)

cost_1 = 0
cost_2 = 0
for a in a_list:
    cost_1 += (a - m1) ** 2
    cost_2 += (a - m2) ** 2

ans = min(cost_1, cost_2)
print(ans)


### FIXED CODE ###

# https://atcoder.jp/contests/abc043/tasks/arc059_a
# C - いっしょ / Be Together
import statistics
N = int(input().split()[0])
a_list = list(map(int, input().split()))

# たかだか200なので、全探索で間に合う
min_cost = float('inf')

for x in range(-100, 101):
    cost = 0
    for a in a_list:
        cost += (a - x) ** 2
    if cost < min_cost:
        min_cost = cost

print(min_cost)
if __name__ == '__main__':
    N = int(input())
    A = [None]*N
    A = list(map(int, input().split()))
    Alice = 0
    Bob = 0
    while(A):
        Alice += max(A)
        A.remove(max(A))
        Bob += max(A)
        A.remove(max(A))
    print(Alice - Bob)

### FIXED CODE ###

if __name__ == '__main__':
    N = int(input())
    A = [None]*N
    A = list(map(int, input().split()))
    Alice = 0
    Bob = 0
    while(A):
        Alice += max(A)
        A.remove(max(A))
        if A:
            Bob += max(A)
            A.remove(max(A))
    print(Alice - Bob)
n=int(input())
a=list(map(int,input().split()))
A=[]
for i in range(n):
  A.append(a[i]-i-1)
A.sort()
b=0
c=0
ans=0
Ans=0
if n%!=0:
  b=n//2
  for i in range(n):
    ans+=abs(A[i]-b)
  print(ans)
else:
  b=n//2
  c=(n//2)-1
  for i in range(n):
    ans+=abs(A[i]-b)
    Ans+=abs(A[i]-c)
  print(min(ans,Ans))
  

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
A=[]
for i in range(n):
  A.append(a[i]-i-1)
A.sort()
b=0
c=0
ans=0
Ans=0
if n%2!=0:
  b=n//2
  for i in range(n):
    ans+=abs(A[i]-A[b])
  print(ans)
else:
  b=n//2
  c=(n//2)-1
  for i in range(n):
    ans+=abs(A[i]-A[b])
    Ans+=abs(A[i]-A[c])
  print(min(ans,Ans))
N=int(input())
c=list(map(int,input().split()))
flag=0
for i in range(N):
    if c[i]%2==0:
        if c[i]%3==0 or c[i]%5==0:
            flag=1
        else:
            flag=0
            print("DENIED")
            exit(0)

if flag==1:
    print("APPROVED")
else:
    print("DENIED!)

### FIXED CODE ###

N=int(input())
c=list(map(int,input().split()))

for i in range(N):

    if c[i]%2==0:
        if c[i]%3==0 or c[i]%5==0:
            continue

        else:
            print("DENIED")
            exit(0)

print("APPROVED")
n = int(input())
alist=list(map(int,input().split()))
core = 0
for i in range(n-3):
  core +=min(alist[i],alist[i+1],alist[i+2])
print(core+min(alist[-2],alist[-1]) +alist[-1] +min(alist[0],alist[1])

### FIXED CODE ###

n = int(input())
alist=list(map(int,input().split()))
alist.insert(0,1e7)
alist.append(1e7)
core = 0
for i in range(n):
  core +=min(alist[i],alist[i+1])
print(core)
import sys
N = int(input())

time_lis = [0] * N
profit = [0] * N
for n in range(N):
    time_lis[n] = list(map(int, input().split()))
for n in range(N):
    profit[n] = list(map(int, input().split()))

ans = 0
always_zero = True
for n in range(N):
    count_1 = len([i for i in time_lis[n] if i == 1])
    ans += max(profit[n][:count_1 + 1])
    if profit[n].index(ans) != 0:
        always_zero = False
if always_zero: 
    max_prof = sorted([item[0], item[1] for item in profit], key=lambda x: -x[1])
    print(ans - max_prof[0][0] + max_prof[0][1])
    sys.exit()
print(ans)

### FIXED CODE ###

n=int(input())
F=[[] for i in range(10)]
for i in range(n):
    for j,f in enumerate(list(map(int,input().split()))):
        if f:
            F[j].append(i)
P=[list(map(int,input().split())) for i in range(n)]
ans=-float("inf")
for i in range(1,1024):
    l=[0]*n
    for j in range(10):
        if i>>j&1:
            for k in F[j]:
                l[k]+=1
    t=0
    for j,k in enumerate(l):
        t+=P[j][k]
    ans=max(ans,t)
print(ans)
n = int(input())
tree = [[] for i in range(n+1)]

for i in range(1,n):
    u, v, w = map(int, input().split())
    tree[u].append((v, w))
    tree[v].append((u, w))

stack=[1]
visitted=[]
ans=[0]*n

while stack:
    cur = stack.pop()
    visitted.append(cur)
    for v, w in tree[cur]:
        if v in visitted:
            continue
        #if v in stack:
        #    continue
        if w % 2 == 1:
            ans[v-1]=(ans[cur]+1)%2
        else:
            ans[v-1]=ans[cur]
        stack.append(v)

for i in ans:
    print(i)

### FIXED CODE ###

n = int(input())
tree = [[] for i in range(n+1)]

for i in range(1,n):
    u, v, w = map(int, input().split())
    tree[u].append((v, w))
    tree[v].append((u, w))

#print(tree)
stack=[1]
visitted={}
ans=[0]*n

while stack:
    cur = stack.pop()
    pre=ans[cur-1]
    visitted.setdefault(cur,1)
    #visitted.append(cur)
    for v, w in tree[cur]:
        if v in visitted:
            continue
        if w % 2 == 1:
            ans[v-1]=(pre+1)%2
        else:
            ans[v-1]=pre
        stack.append(v)

print(*ans, sep='\n')
import math
N, M = (int(i) for i in input().split())  
S = input()
T = input()

L = math.gcd(N, M)
lcm = (N * M) // math.gcd(N, M)

flag = True
for i in range(L):
    if (S[N//L * i] != T[M//L * i]):
        flag = False

if flag:
    print(lcm)
else:
    print("-1")


### FIXED CODE ###

import fractions

N, M = (int(i) for i in input().split())  
S = input()
T = input()

L = fractions.gcd(N, M)
lcm = (N * M) // fractions.gcd(N, M)

flag = True
for i in range(L):
    if (S[N//L * i] != T[M//L * i]):
        flag = False

if flag:
    print(lcm)
else:
    print("-1")
while 1:
    T,U,N,E,W,S=1,6,5,3,4,2
    n=int(raw_input())
    if n==0: break
    ans=T
    for i in range(n):
        di=raw_input()
        if di=="North":
            N,T,S,U=T,S,U,N
        elif di=="East":
            E,U,W,T=T,E,U,W
        elif di=="South":
            T,S,U,N=N,T,S,U
        elif di=="West":
            T,E,U,W=E,U,W,T
        elif di=="Left":
            E,S,W,N=S,W,N,E
        elif di=="Right":
            S,W,N,E=E,S,W,N
        else:
            print '[*] Error ->',di
            raise IOError
        ans+=T
    print ans

### FIXED CODE ###

while(1):
    num=int(raw_input())
    if num==0:
        break
    else:
        d=[0,1,2,3,4,5,6]
        sum=1
        for i in range(num):
            dir=num=raw_input()
            if dir=="North":
                d=[0,d[2],d[6],d[3],d[4],d[1],d[5]]
            elif dir=="East":
                d=[0,d[4],d[2],d[1],d[6],d[5],d[3]]
            elif dir=="West":
                d=[0,d[3],d[2],d[6],d[1],d[5],d[4]]
            elif dir=="South":
                d=[0,d[5],d[1],d[3],d[4],d[6],d[2]]
            elif dir=="Right":
                d=[0,d[1],d[3],d[5],d[2],d[4],d[6]]
            else:
                d=[0,d[1],d[4],d[2],d[5],d[3],d[6]]
            sum=sum+d[1]
        print sum
N = int(input())
A = [int(x) for x in input().split()]

m = -10**9

if N % 2 == 0:
    a = sum(A)
    m = max(sum(A[0::2]), sum(A[1::2]))
else:
    for i in range(N):
        B = A.copy()
        del B[i]
        print(B[:i],B[i:])
        tmp1 = max(sum(B[0:i:2]),sum(B[1:i:2]))
        tmp2 = max(sum(B[i::2]),sum(B[i+1::2]))
        
        tmp = tmp1 + tmp2
        m = max(m,tmp)
        
print(m)

### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]

dp = [[0]*3]*N

dp[0][0] = 0  # ((i+1)-1)/2
dp[0][1] = 0 # (i+1)/2
dp[0][2] = A[0]  # ((i+1)+1)/2

for i in range(1, N):
    
    if i % 2 == 0:
        dp[i][0] = dp[i-1][0] + A[i]
        dp[i][1] = max(dp[i-1][1], dp[i-1][2])
        dp[i][2] = dp[i-1][2] + A[i]
    else:
        dp[i][0] = max(dp[i-1][0], dp[i-1][1])
        dp[i][1] = dp[i-1][1] + A[i]
        dp[i][2] = dp[i-1][2]

if N % 2 == 0:
    print(max(dp[N-1][1],dp[N-1][2]))
else:
    print(max(dp[N-1][0],dp[N-1][1]))
k=int(input())
a,b=map(int,input().split())
count=0
for i in range(a,b+1):
  if(i%k==0):
    c=c+1
if(c==0):
  print("NG")
else:
  print("OK")
    
    


### FIXED CODE ###

k=int(input())
a,b=map(int,input().split())
c=0
for i in range(a,b+1):
  if(i%k==0):
    c=c+1
if(c==0):
  print("NG")
else:
  print("OK")
s = input().split()

size = []
for n in s:
    size.append(int(n))

s2 = input().split()

ss = []
for n in s2:
    ss.append(int(n))

if size[0] % 2 == 0:
    k = size[0]/2
else:
    k = (size[0] + 1) /2

l = 0
m = 3

for i in ss:
    if i > k:
        l+=1
        while i > int((m-1) * size[0] / m) and m <= size[0]:
            m+=1
         
            l+=1

print (l)



### FIXED CODE ###

import re

m = input()

m2 = re.search('C[A-Z]*F', m)

if m2:
    
    print ("Yes")

else:
    print ("No")

#print (m2)
X,K,D = map(int,input().split())
if X > 0:
  if X-D*K > 0:
    print(X-D*K)
  elif (X//D - K) %2==0:
    print(min(abs(X-(X//D)*D),abs(X-((X//D)+2)*D)))
  else:
    print(min(abs(X-(X//D-1)*D),abs(X-(X//D+1)*D)))
elif X == 0:
  if K%2 == 0:
    print(0)
  else:
    pritn(D)
else:
  if X-D*K < 0:
    print(abs(X-D*K))
  elif (X// - K) %2==0:
    print(min(abs(X-(X//D)*D),abs(X-((X//D)+2)*D)))
  else:
    print(min(abs(X-(X//D-1)*D),abs(X-(X//D+1)*D)))

### FIXED CODE ###

X,K,D = map(int,input().split())
if X > 0:
  if X-D*K > 0:
    print(X-D*K)
  elif (X//D - K) %2==0:
    print(min(abs(X-(X//D)*D),abs(X-((X//D)+2)*D)))
  else:
    print(min(abs(X-((X//D)-1)*D),abs(X-((X//D)+1)*D)))
elif X == 0:
    if K%2 == 0:
        print(0)
    else:
        print(D)
else:
    if X+D*K < 0:
        print(abs(X+D*K))
    elif ((-X)//D - K) %2==0:
        print(min(abs(X+((-X)//D)*D),abs(X+(((-X)//D)+2)*D)))
    else:
        print(min(abs(X+(((-X)//D)-1)*D),abs(X+(((-X)//D)+1)*D)))
line = input().split()
a = line[0]
b = line[1]

if a > 8 or b > 8:
    return ':('
else:
    return 'Yay!'

### FIXED CODE ###

line = input().split(' ')
a = line[0]
b = line[1]

if int(a) > 8 or int(b) > 8:
    print(':(')
else:
    print('Yay!')
li = list(map(int, input().split()))
if (li in 1) and (li in 9) and (li in 7) and (li in 4):
  print('YES')
else:
  print('NO')


### FIXED CODE ###

li = list(map(int, input().split()))
if (1 in li) and (9 in li) and (7 in li) and (4 in li):
  print('YES')
else:
  print('NO')
N=int(input().strip())
p=map(int,input().split())

ans=0
flag=0
for i in range(len(p)):
    if i+1 == p[i]:
        if flag==0:
            ans+=1
        else: # if flag == 1
            flag=0
print(ans)

### FIXED CODE ###

N=int(input().strip())
p=list(map(int,input().split()))

ans=0
flag=0
for i in range(len(p)):
    if i+1 == p[i]:
        if flag==0:
            ans+=1
            flag=1
        else: # if flag == 1
            flag=0
    else: # if i+1 != p[i] 
        flag=0

print(ans)
cards = {
         'S': [0 for _ in range(13)],
         'H': [0 for _ in range(13)],
         'C': [0 for _ in range(13)],
         'D': [0 for _ in range(13)],
}

n = int(input())
for _ in range(n) :
    (s, r) = input().split()
    index = cards[s].index(int(r))
    del cards[s][index]

for s in ['S', 'H', 'C', 'D'] :
    for r in cards[s] :
        print(s, r)

### FIXED CODE ###

cards = {
        'S': [0 for _ in range(13)],
        'H': [0 for _ in range(13)],
        'C': [0 for _ in range(13)],
        'D': [0 for _ in range(13)],
        }
 
n = int(input())
for _ in range(n):
    (s, r) = input().split()
    r = int(r)
    cards[s][r - 1] = r
 
for s in ('S', 'H', 'C', 'D'):
    for r in range(13):
        if cards[s][r] == 0:
            print( '{0:s} {1:d}'.format(s, r+1))
S = input()
K = int(input())
i = 0
while S[i] == "1":
    i += 1
if K-1 < i:
    print(1)
else:
    print(int(S[i]))

### FIXED CODE ###

S = input()
K = int(input())
i = 0
leng = len(S)
while S[i] == "1":
    i += 1
    if i >= leng:
        break
if K-1 < i:
    print(1)
else:
    print(int(S[i]))
a,b = map(int,input().split())
if (a<0 and b>0) or a == 0 or b == 0:
    print("Zero")
else:
    nega = [i for i in list(range(a,b+1)) if i<0]
    if len(nega)%2==0:
        print("Positive")
    else:
        print("Negative")

### FIXED CODE ###

a,b = map(int,input().split())
if (a<=0 and b>=0) :
    print("Zero")
else:
    if a>0:
        print("Positive")
    elif b<0:
        if (b-a+1)%2==0:
            print("Positive")
        else:
            print("Negative")
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  absv = x
  for i in range(-1, 100):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)

### FIXED CODE ###

x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  absv = x
  value = x
  for i in range(-1, 102):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)
n = int(input())
for i in range(n):
    x1,y1,x2,y2,x3,y3,x4,y4 = map(float, input().split())
    if x1-x2 == 0 or x3-x4 ==0:
        if x1-x2 == 0 and x3-x4 ==0:
            print('YES')
        else:
            print('NO')
    if (y1-y2)/(x1-x2) == (y3-y4)/(x3-x4):
        print('YES')
    else:
        print('NO')

### FIXED CODE ###

n = int(input())
for i in range(n):
    x1,y1,x2,y2,x3,y3,x4,y4 = map(float, input().split())
    if abs((y1-y2)*(x4-x3) - (y4-y3)*(x1-x2)) < 1e-10:
        print('YES')
    else:
        print('NO')
n=int(input())
l=list(map(int,input().split()))
dp=[-1 for i in range(n)]
def solve(ind):
    if(ind==n-1):
        return 0
    if(dp[ind]!=-1):
        return dp[ind]
    ans=solve(ind+1)+abs(l[ind+1]-l[ind])
    if(ind+2<n):
        ans=min(ans,solve(ind+2)+abs(l[ind+2]-l[ind]))
    dp[ind]=ans
    return dp[ind]
print(solve(0))

### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
dp=[10**55 for i in range(n)]
dp[0]=0
dp[1]=abs(l[1]-l[0])
for i in range(2,n):
    dp[i] = min(dp[i], dp[i-1] + abs(l[i] - l[i - 1]))
    dp[i] = min(dp[i], dp[i-2] + abs(l[i] - l[i - 2]))
print(dp[n-1])
a=int(input())
s=input()
list= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
slist = [*s]
ans = str()
for si in slist:
    i = list.find(si)
    ans += list[(i+a)%26]
print(ans)

### FIXED CODE ###

a=int(input())
s=input()
list= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
slist = [c  for c in s]
ans = str()
for si in slist:
    i = list.find(si)
    ans += list[(i+a)%26]
print(ans)
import bisect
N, Q = map(int, input().split())
A = [int(a) for a in input().split()]

def chk(x, l, m, r):
    if x >= A[-2]:
        return 1
    elif x <= A[0]:
        return (N+1)//2
    rr = m % 2
    xl = x - m//2 - rr
    xr = x + m//2
    
    ll = bisect.bisect_left(A, xl)
    rr = bisect.bisect_left(A, xr+1)-1
    # print(x, l, m, r, ll, rr, N)
    if rr - ll + 1 < N - rr - 2:
        return chk(x, m, (m+r)//2, r)
    elif rr - ll + 1 > N - 1 - rr:
        return chk(x, l, (l+m)//2, m)
    else:
        return max(N - rr - 1, 1)
    
    
Y = [0] * (N+1)
for i in range(1, N+1):
    Y[i] = Y[i-1] + A[-i]

Z = [0] * ((N+3)//2)
for i in range((N+1)//2):
    if ((1+N)%2)+2*i<N:
        Z[i+1] = Z[i] + A[((1+N)%2)+2*i]

# print(Y)
# print(Z)
for q in range(Q):
    x = int(input())
    t = chk(x, 0, A[-1]//2, A[-1])
    # print(t)
    print(Y[t]+Z[(N+1)//2-t])


    



### FIXED CODE ###

import sys
input = sys.stdin.readline
def calc(x):
    l, r = 0, (N+1)//2
    while r - l > 1:
        m = (l+r) // 2
        if A[m] + A[2*m] >= 2 * x:
            l = m
        else:
            r = m
    return l
    
N, Q = map(int, input().split())
A = [int(a) for a in input().split()][::-1]
B = [A[0]] + [0] * (N-1)
for i in range(1, N):
    B[i] = B[i-1] + A[i]
C = [A[0]] + [0] * (N-1)
for i in range(2, N, 2):
    C[i] = C[i-2] + A[i]
C[-1] += C[-2]
for _ in range(Q):
    x = int(input())
    c = calc(x)
    print(B[c] + (C[-1] - C[2*c] if c*2<=N else 0))