Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
base = sum(A) % MOD

b = 1
b2 = 1
ans = (base * N) % MOD
for i in range(60):
	s = 0
	k = 0
	for a in A:
		if (a // b) % 2 == 1:
			k -= 1
			s += 1
		else:
			k += 1
	ans = (ans + ((b2 * s * k) % MOD)) % MOD
	b2 = b2 * 2 % MOD
	b = b * 2
# divide 2
ans = (ans * ((MOD + 1) // 2)) % MOD
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
base = sum(A) % MOD

b = 1
b2 = 1
ans = (base * N) % MOD
for i in range(60):
	s = 0
	k = 0
	for a in A:
		if (a // b) % 2 == 1:
			k -= 1
			s += 1
		else:
			k += 1
	ans = (ans + ((b2 * s * k) % MOD)) % MOD
	b2 = b2 * 2 % MOD
	b = b * 2
# divide 2
ans = (ans * ((MOD + 1) // 2)) % MOD
print(ans)
### BUGGY CODE ###

K = input()
N = len(K)
D = int(input())
mod = 10**9+7

dp = [[[0]*D for _ in range(2)] for _ in range(N+1)]
dp[0][0][0] = 1

for i, s in enumerate(K):
    a = ord(s)-48
    for j in range(D):
        for k in range(10):
            b = (j+k)%D
            dp[i+1][1][b] += dp[i][1][j]
            if k<a:
                dp[i+1][1][b] += dp[i][0][j]
            dp[i+1][1][b] %= mod
    
    for j in range(D):
        b = (j+a)%D
        dp[i+1][0][b] += dp[i][0][j]
        dp[i+1][0][b] %= mod

print((dp[N][1][0]+dp[N][0][0]-1)%mod)

### FIXED CODE ###

K = input()
N = len(K)
D = int(input())
mod = 10**9+7

dp = [[[0]*D for _ in range(2)] for _ in range(N+1)]
dp[0][1][0] = 0
dp[0][0][0] = 1

for i in range(N):
    a = ord(K[i])-48
    
    for j in range(D):
        for k in range(10):
            dp[i+1][1][(j+k)%D] += dp[i][1][j]
            dp[i+1][1][(j+k)%D] %= mod

    for j in range(D):
        dp[i+1][0][(j+a)%D] += dp[i][0][j]
        dp[i+1][0][(j+a)%D] %= mod

    for j in range(D):
        for k in range(a):
            dp[i+1][1][(j+k)%D] += dp[i][0][j]
            dp[i+1][1][(j+k)%D] %= mod

print((dp[N][1][0] + dp[N][0][0]-1)%mod)
### BUGGY CODE ###

from collections import Counter
S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  t *= d
  r += t
  r %= mod
  d *= 10
  p[r] += 1

#p.append(0)
#ans = 0
#c = Counter(p)
#for k,n in c.most_common():
#  if n > 1:
#    ans += 1
#  else:break
  
print(sum([i*(i-1)//2 for i in p]))

### FIXED CODE ###

S = input()
S = S + '0'
mod = 2019
p = [0] * mod
r = 0
d = 1
for s in reversed(S):
  t = int(s)%mod
  r += t*d
  r %= mod
  d = d*10%mod
  p[r] += 1

print(sum([i*(i-1)//2 for i in p]))
### BUGGY CODE ###

def do():

    N=int(input())
    inp=[]
    for j in range(N-1):
        inp.append(input())

    for i in range(N):
        ti=0
        for j in range(i,N-1):
            temp=list(map(int,inp[j].split(" ")))
            ti+=getTime(ti,temp[1],temp[2])
            ti+=temp[0]

        print(ti)

def getTime(a,s,i):
    ti=0
    while(True):
        if a<=s+i*ti:
            break
        ti+=1

    return (s+i*ti)-a



if __name__=='__main__':
    do()


### FIXED CODE ###

import math
N =int(input() )
trains = [list(map(int,input().split(" "))) for _ in range(N-1)]
for s in range(N):
    ans = 0
    spent = 0
    arrived_time = 0
    for train in trains[s:]:
        c,s,f = train
        n = max(0,math.ceil((ans-s) /f))
        wait = n * f + s - ans
        #待機時間

        ans += c + wait

    print(ans)
### BUGGY CODE ###

def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    l = []
    while len(l) != len(a):
        mn = min(a)
        l.append(a.index(mn)+1)
        a[a.index(mn)] = n+1
    print(*l)
resolve()

### FIXED CODE ###

def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    l = [0]*n
    for i in range(n):
        l[a[i]-1] = i+1
    print(*l)
resolve()
### BUGGY CODE ###

N = int(input())
an = list(map(int, input().split()))
ans = 0
for i in set(an):
    ans = max(ans, an.count(i) + an.count(i-1) + an.count(i+1))
print(ans)

### FIXED CODE ###

from collections import Counter
N = int(input())
an = list(map(int, input().split()))
ans = 0
cnts = Counter(an)
for i in set(an):
    ans = max(ans, cnts[i] + cnts[i+1] + cnts[i-1])
print(ans)
### BUGGY CODE ###

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

max_A = max(A)

for i in range(1, max_A + 1):
    print(A.count(i))

for i in range(max_A + 1, N+1):
    print(A.count(i))

### FIXED CODE ###

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

max_A = max(A)

from collections import Counter

dic = Counter(A)

for i in range(1, max_A + 1):
    print(dic[i])

for i in range(max_A + 1, N+1):
    print(0)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
X = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
dp = [[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(X[0][0])
dplimit = [[0] * W for _ in range(H)]
dplimit[-1][-1] = 80
for i in range(H - 1, -1, -1):
  for j in range(W - 1, -1, -1):
    x = X[i][j]
    if i > 0: dplimit[i - 1][j] = max(dplimit[i - 1][j], dplimit[i][j] + x)
    if j > 0: dplimit[i][j - 1] = max(dplimit[i][j - 1], dplimit[i][j] + x)
for i in range(H):
  for j in range(W):
    for k in dp[i][j]:
      if i + 1 < H:
        u = k + X[i + 1][j]
        v = abs(k - X[i + 1][j])
        if u <= dplimit[i][j]: dp[i + 1][j].add(u)
        if v <= dplimit[i][j]: dp[i + 1][j].add(v)
      if j + 1 < W:
        u = k + X[i][j + 1]
        v = abs(k - X[i][j + 1])
        if u <= dplimit[i][j]: dp[i][j + 1].add(u)
        if v <= dplimit[i][j]: dp[i][j + 1].add(v)
res = float("inf")
#print(dp[1][1])
for k in dp[-1][-1]: res = min(k, res)
print(res)

### FIXED CODE ###

import sys
input = sys.stdin.readline
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
X = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
dp1 = [set() for _ in range(W)]
dp1[0].add(X[0][0])
dp2 = [set() for _ in range(W)]
dplimit = [[0] * W for _ in range(H)]
dplimit[-1][-1] = 80
for i in range(H - 1, -1, -1):
  for j in range(W - 1, -1, -1):
    x = X[i][j]
    if i > 0: dplimit[i - 1][j] = max(dplimit[i - 1][j], dplimit[i][j] + x)
    if j > 0: dplimit[i][j - 1] = max(dplimit[i][j - 1], dplimit[i][j] + x)
for i in range(H):
  if i % 2 == 0:
    dp2 = [set() for _ in range(W)]
  else: dp1 = [set() for _ in range(W)]
  for j in range(W):
    if i % 2 == 0:
      for k in dp1[j]:
        if i + 1 < H:
          u = k + X[i + 1][j]
          v = abs(k - X[i + 1][j])
          if u <= dplimit[i][j]: dp2[j].add(u)
          if v <= dplimit[i][j]: dp2[j].add(v)
        if j + 1 < W:
          u = k + X[i][j + 1]
          v = abs(k - X[i][j + 1])
          if u <= dplimit[i][j]: dp1[j + 1].add(u)
          if v <= dplimit[i][j]: dp1[j + 1].add(v)
    else:
      for k in dp2[j]:
        if i + 1 < H:
          u = k + X[i + 1][j]
          v = abs(k - X[i + 1][j])
          if u <= dplimit[i][j]: dp1[j].add(u)
          if v <= dplimit[i][j]: dp1[j].add(v)
        if j + 1 < W:
          u = k + X[i][j + 1]
          v = abs(k - X[i][j + 1])
          if u <= dplimit[i][j]: dp2[j + 1].add(u)
          if v <= dplimit[i][j]: dp2[j + 1].add(v)
res = float("inf")
if H % 2:
  for k in dp1[-1]: res = min(k, res)
else:
  for k in dp2[-1]: res = min(k, res)
print(res)
### BUGGY CODE ###

import queue
H, W = map(int, input().split())
numw = 0
S = []
for i in range(H):
  ss = input()
  numw += ss.count(".")
  S.append(ss)
#print(numw)
D = [[1000000]*W for i in range(H)]
q = queue.Queue()
q.put((0, 0, 0))
D[0][0] = 0
while not(q.empty()):
  i, j, d = q.get()
  if j > 0 and S[i][j-1] == "." and D[i][j-1] >= d:
    D[i][j-1] = d+1
    q.put((i, j-1, d+1))
  if i > 0 and S[i-1][j] == "." and D[i-1][j] >= d:
    D[i-1][j] = d+1
    q.put((i-1, j, d+1))
  if j+1 < W and S[i][j+1] == "." and D[i][j+1] >= d:
    D[i][j+1] = d+1
    q.put((i, j+1, d+1))
  if i+1 < H and S[i+1][j] == "." and D[i+1][j] >= d:
    D[i+1][j] = d+1
    q.put((i+1, j, d+1))
#print(D)
if D[H-1][W-1] == 1000000:
  print(-1)
  exit()
r = numw-D[H-1][W-1]-1
print(r)


### FIXED CODE ###

import queue
H, W = map(int, input().split())
numw = 0
S = []
for i in range(H):
  ss = input()
  numw += ss.count(".")
  S.append(ss)
#print(numw)
D = [[-1]*W for i in range(H)]
q = queue.Queue()
q.put((0, 0, 0))
D[0][0] = 0
while not(q.empty()):
  i, j, d = q.get()
  if j > 0 and S[i][j-1] == "." and D[i][j-1] < 0:
    D[i][j-1] = d+1
    q.put((i, j-1, d+1))
  if i > 0 and S[i-1][j] == "." and D[i-1][j] < 0:
    D[i-1][j] = d+1
    q.put((i-1, j, d+1))
  if j+1 < W and S[i][j+1] == "." and D[i][j+1] < 0:
    D[i][j+1] = d+1
    q.put((i, j+1, d+1))
  if i+1 < H and S[i+1][j] == "." and D[i+1][j] < 0:
    D[i+1][j] = d+1
    q.put((i+1, j, d+1))
#print(D)
if D[H-1][W-1] < 0:
  print(-1)
  exit()
r = numw-D[H-1][W-1]-1
print(r)
### BUGGY CODE ###

import fractions

N,M = map(int,input().split())

A = list(map(int,input().split()))

def lcm(X):
    ret = X[0]
    for i in range(1,len(X)):
        ret = ret * X[i] //fractions.gcd(ret,X[i])
        if ret > M:
            ret = M+1
            break
    return ret




count = 0
a = A[0]
while a % 2 == 0:
    a //= 2
    count += 1

det = 0
for i in range(1,N):
    x = A[i] / (2**count)
    if x % 2 == 0 or int(x) != x:
        det = -1
        break
#print(det)
if det == -1:
    print(0)
else:
    for i in range(N):
        A[i] //= 2**count
        min_l = lcm(A) * (2**(count-1))
    #print(min_l)
    t = M // min_l
    if t % 2 == 0:
        print(t//2)
    else:
        print((t+1)//2)

### FIXED CODE ###

import fractions

N,M = map(int,input().split())

A = list(map(int,input().split()))

def lcm(X):
    ret = X[0]
    for i in range(1,len(X)):
        ret = ret * X[i] //fractions.gcd(ret,X[i])
        if ret > M:
            ret = M+1
            break
    return ret




count = 0
a = A[0]
while a % 2 == 0:
    a //= 2
    count += 1

det = 0
for i in range(1,N):
    x = A[i] / (2**count)
    if x % 2 == 0 or int(x) != x:
        det = -1
        break
#print(det)
if det == -1:
    print(0)
else:
    for i in range(N):
        A[i] //= 2**count
    min_l = lcm(A) * (2**(count-1))
    #print(min_l)
    t = M // min_l
    if t % 2 == 0:
        print(t//2)
    else:
        print((t+1)//2)
### BUGGY CODE ###

import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
idx = A[0]
move = []
move.append(idx)
cycle = []
for _ in range(K-1):
  idx = A[idx-1]
  if idx in move:
    cycle = move[move.index(idx):]
    break
  move.append(idx)

if cycle:
  print(cycle[(K - 1- (len(move)-len(cycle)))%len(cycle)])
else:
  print(move[K-1])

### FIXED CODE ###

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

R = [False]*(N+1)
D = []
p = 1
while True:
    if R[p]:
        break
    D.append(p)
    R[p] = True
    p = A[p-1]
m = D.index(p)
c = len(D)-m

if K <= m:
    print(D[K])
else:
    print(D[m+(K-m) % c])
### BUGGY CODE ###

from itertools import product
n = int(input())
s = input()

ans = 0
for pas in product(range(10), repeat=3):
    index = 0
    for i in range(len(s)):
        if pas[index] == int(s[i]):
            index += 1
        if index == 3:
            ans += 1
            break
print(ans)

### FIXED CODE ###

from itertools import product
n = int(input())
s = input()

ans = 0
for x, y, z in product(range(10), repeat=3):
    index_1 = s.find(str(x))
    index_2 = s.find(str(y), index_1+1)
    index_3 = s.find(str(z), index_2+1)
    if index_1 != -1 and index_2 != -1 and index_3 != -1:
        ans += 1
print(ans)
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
nums = [list(map(int, input().split())) for i in range(q)]
for m in nums:
    s2 = s[m[0]-1:m[1]]
    print(s2.count("AC"))

### FIXED CODE ###

n, q = map(int, input().split())
s = input()
ac = [0]*n
for i in range(n-1):ac[i+1] = ac[i] + (s[i:i+2]=="AC")
for i in range(q):
    l,r=map(int,input().split())
    print(ac[r-1]-ac[l-1])
### BUGGY CODE ###

import sys
N, K = map(int, input().split())
A = list(map(int, input().split()))
#A = [i for i in range(1,2)] + [i for i in range(2,1001)] * 4
A.sort()

DP = [0 for k in range(K+1)] #和がkとなる部分集合の数
DP[0] = 1
for a in A:
  for k in range(K-a,-1,-1):
    DP[k+a] += DP[k]

"""
for k in range(1,2*K+1): #累積和へ変換
  DP[k] += DP[k-1]
print(DP)
"""
"""
if sum(DP[0:K]) == 2**N:
  print(N)
  sys.exit()
"""
#print(DP)  
ans = 0
DP_rev = [0 for _ in range(K)] #戻すDP!!!
flag = True
for a in A:
  if not flag: break
  for i in range(K):
    DP_rev[i] = DP[i] 
    if i-a >= 0:
      DP_rev[i] -= DP_rev[i-a]
    if i >= K-a and DP_rev[i] > 0:
      flag = False
      break
  if flag:
    ans += 1
  #print(a, DP_rev)
    
print(ans)
  
  
  
  


### FIXED CODE ###

import sys
N, K = map(int, input().split())
A = list(map(int, input().split()))
#A = [i for i in range(1,2)] + [i for i in range(2,1001)] * 4
A.sort()

DP = [0 for k in range(K+1)] #和がkとなる部分集合の数
DP[0] = 1
for a in A:
  for k in range(K-a,-1,-1):
    DP[k+a] += DP[k]

"""
for k in range(1,2*K+1): #累積和へ変換
  DP[k] += DP[k-1]
print(DP)
"""
"""
if sum(DP[0:K]) == 2**N:
  print(N)
  sys.exit()
"""
#print(DP)  


def det(t):
  a = A[t]
  if a >= K:
    return False
  DP_rev = [0 for _ in range(K)] #戻すDP!!!
  ans = True
  for i in range(K):
    DP_rev[i] = DP[i] 
    if i-a >= 0:
      DP_rev[i] -= DP_rev[i-a]
    if i >= K-a and DP_rev[i] > 0:
      ans = False
      break
  del DP_rev
  return ans

lt = 0
rt = N-1
if not det(lt):
  print(0)
  sys.exit()
if det(rt):
  print(rt+1)
  sys.exit()

while rt - lt > 1:
  ct = (lt + rt) // 2
  if det(ct):
    lt = ct
  else:
    rt = ct
print(rt)
### BUGGY CODE ###

h = int(input())

s = 0
c = 1
while h >= 0:
  s += c
  c *= 2
  h //= 2
print(s)

### FIXED CODE ###

h = int(input())

s = 0
c = 1
while h != 0:
  s += c
  c *= 2
  h //= 2
print(s)
### BUGGY CODE ###

#TLE

#half_expo(a, n, mod) = (a**n) % mod
#二分累乗法
def half_expo_mod(a, n, mod):
    nbin = tuple(bin(n))
    nbin = nbin[3:]
    ans = a
    for j in nbin:
        if j == '0':
            ans **= 2
        else:
            ans = (ans ** 2) * a
        ans %= mod
    return ans

#comb_mod(n, r, mod) = nCr % mod
def comb_mod(n, r, mod):
    ans = 1
    if r <= n/2:
        for i in range(n-r+1, n+1):
            ans *= i
            ans %= mod
        for i in range(1, r+1):
            ans *= half_expo_mod(i, mod-2, mod)
            ans %= mod
    else:
        for i in range(r+1, n+1):
            ans *= i
            ans %= mod
        for i in range(1, n-r+1):
            ans *= half_expo_mod(i, mod-2, mod)
            ans %= mod
    return ans

n, a, b = map(int, input().split())
ans = half_expo_mod(2, n, 10**9+7) - comb_mod(n, a, 10**9+7) - comb_mod(n, b, 10**9+7) - 1
if ans < 0:
    ans += 10**9 + 7
if ans < 0:
    ans += 10**9 + 7

print(int(ans))

### FIXED CODE ###

#TLE

#comb_mod(n, r, mod) = nCr % mod
def comb_mod(n, r, mod):
    ans = 1
    if r <= n/2:
        for i in range(n-r+1, n+1):
            ans *= i
            ans %= mod
        for i in range(1, r+1):
            ans *= pow(i, mod-2, mod)
            ans %= mod
    else:
        for i in range(r+1, n+1):
            ans *= i
            ans %= mod
        for i in range(1, n-r+1):
            ans *= pow(i, mod-2, mod)
            ans %= mod
    return ans

n, a, b = map(int, input().split())
ans = pow(2, n, 10**9+7) - comb_mod(n, a, 10**9+7) - comb_mod(n, b, 10**9+7) - 1
if ans < 0:
    ans += 10**9 + 7
if ans < 0:
    ans += 10**9 + 7

print(int(ans))
### BUGGY CODE ###

N = int(input())
S = input()
B = []
s = [0, 0, 0]
for c in S[::-1]:
    s[['R', 'G', 'B'].index(c)] += 1
    B.append([s[0], s[1], s[2]])
B.reverse()
A = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        D = [0, 1, 2]
        D.remove(['R', 'G', 'B'].index(S[i]))
        D.remove(['R', 'G', 'B'].index(S[j]))
        A += B[j+1][D[0]]
        n = 2*j-i
        if n < N and S[n] == ['R', 'G', 'B'][D[0]]:
            A -= 1
print(A)


### FIXED CODE ###

N = int(input())
S = input()
Sr = Sg = Sb = 0
for c in S:
    if c == 'R':
        Sr += 1
    elif c == 'G':
        Sg += 1
    else:
        Sb += 1
A = Sr * Sg * Sb
for sep in range(1,(N+1)//2):
    for i in range(N-2*sep):
        if S[i] != S[i+sep] and S[i+sep] != S[i+2*sep] and S[i] != S[i+2*sep]:
            A -= 1
print(A)
### BUGGY CODE ###

#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

N = int(input())

A = list(map(int, input().split()))
P = [[(A[0], 0), (0, 0)] for i in range(2 ** N)]

for i in range(1, 2 ** N):
    P[i].append((A[i], i))
    P[i] = list(set(P[i]))
    P[i].sort()
    P[i] = P[i][-2:]
    for j in range(N):
        if (i & (1 << j)) == 0:
            P[i + (1 << j)] += P[i]
ans = 0
for i in range(1, 2 ** N):
    ans = max(ans, P[i][0][0] + P[i][1][0])
    print(ans)

### FIXED CODE ###

#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

def func():
    N = int(input())

    A = list(map(int, input().split()))
    P = [[(A[0], 0), (0, 0)] for i in range(2 ** N)]

    for i in range(1, 2 ** N):
        Ai = A[i]
        Pi = P[i]
        if (Ai, i) > Pi[0]:
            Pi[1] = Pi[0]
            Pi[0] = (Ai, i)
        elif (Ai, i) > Pi[1]:
            Pi[1] = (Ai, i)
        for j in range(N):
            if (i & (1 << j)) == 0:
                Pindex = P[i + (1 << j)]
                for k in range(2):
                    if Pi[k] > Pindex[0]:
                        Pindex[1] = Pindex[0]
                        Pindex[0] = Pi[k]
                    elif Pi[k] > Pindex[1] and Pi[k] != Pindex[0]:
                        Pindex[1] = Pi[k]
    ans = 0
    for i in range(1, 2 ** N):
        ans = max(ans, P[i][0][0] + P[i][1][0])
        print(ans)
    #print(P)

func()
### BUGGY CODE ###

import math
q = int(input())


def isPrime(q):
  if q == 2:
    return True
  if q%2 == 0 or q == 1:
    return False
  j = 3
  while j <= math.sqrt(q):
    if q%j == 0:
      return False
    j += 2
  return True

primes = []
for i in range(1, 100000):
  if isPrime(i):
    primes.append(i)

C = []
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
#print(ran)

for i in range(q):
  if ran[i][0] % 2 == 0:
    j = ran[i][0]+1
  else:
    j = ran[i][0]
  count = 0
  while j <= ran[i][1] :
    if j in primes and ((j+1)//2) in primes:
      count += 1
    j += 2
  C.append(count)

for i in range(q):
  print(C[i])


### FIXED CODE ###

primes = [True]*100000
for i in range(2,100000):
  if primes[i] == False:
    continue
  for j in range(2*i, 100000, i):
    primes[j] = False

c = [0]*100000

for i in range(3,100000):
  if primes[i] and primes[(i+1)//2] == True:
    c[i] = c[i-1]+1
  else:
    c[i] = c[i-1]


q = int(input())
ran = []
for i in range(q):
  ran.append(list(map(int, input().split())))
for i in range(q):
  print(c[ran[i][1]]-c[ran[i][0]-1])
### BUGGY CODE ###

import sys
n, q = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

query = []
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    query.append((p, x))

def DFS(node, p_node=-1):
    childs = [node]
    for c_node in graph[node]:
        if c_node==p_node:
            continue
        childs.extend(DFS(c_node, node))
    p_tree[node] = childs
    return childs

sys.setrecursionlimit(2*n)
p_tree = [None]*n
DFS(0)
ans = [0]*n
for p, x in query:
    for i in p_tree[p]:
        ans[i] += x
print(*ans)

### FIXED CODE ###

from collections import deque
n, q = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

ans = [0]*n
for _ in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x

stack = deque([0])
seen = [False]*n
while len(stack) > 0:
    parent = stack.pop()
    seen[parent] = True
    for child in graph[parent]:
        if seen[child]:
            continue
        ans[child] += ans[parent]
        stack.append(child)

print(*ans)
### BUGGY CODE ###

def main():
    N,K = map(int, input().split())
    h = list(map(int, input().split()))
    # 初期化
    # 初期条件
    # ループ
    # テーブルから解を得る
    INF = float('inf')
    dp = [INF] * N
    dp[0] = 0
    for i in range(N-1):
        for j in range(1, min(K+1, N-i)):
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
    print(dp[-1])

main()


### FIXED CODE ###

def main():
    N,K = map(int, input().split())
    h = list(map(int, input().split()))
    # 初期化
    # 初期条件
    # ループ
    # テーブルから解を得る
    INF = float('inf')
    dp = [INF] * N
    dp[0] = 0
    for i in range(N-1):
        for j in range(1, min(K+1, N-i)):
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
    print(dp[-1])

main()
### BUGGY CODE ###

n = int(input())
s = []
for i in range(n):
    s.append(list(str(input())))
    
for i in s:
    i.sort()
    
cnt = 0
for i in range(n-1):
    for j in range(i+1, n):
        if s[i] == s[j]:
            cnt+=1

print(cnt)

### FIXED CODE ###

n = int(input())
ss = ["".join(sorted(list(input()))) for _ in range(n)]
ss.sort()

ans = 0
cnt = 0
tmp = ss.pop(0)
for s in ss:
    if tmp == s:
        cnt+=1
    elif cnt > 0:
        tmp = s
        ans+=((cnt+1) * cnt // 2)
        cnt = 0
    else:
        tmp = s
        cnt = 0
print(ans + ((cnt+1) * cnt // 2))
### BUGGY CODE ###

N = int(input())
x, y, h = [], [], []
for i in range(N):
    s, t, u = map(int, input().split())
    x.append(s)
    y.append(t)
    h.append(u)

for i in range(N):
    tmp = []
    for cx in range(101):
        for cy in range(101):
            if h[i] > 0:
                H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
                tmp.append((cx, cy, H))
            else:
                for H in range(1, abs(x[i] - cx) + abs(y[i] - cy) + 1):
                    tmp.append((cx, cy, H))
            # setはtmp.add(要素)で追加できるが要素としてtupleを追加しようとすると和集合を書いたりしなきゃいけないので遅い
            # tupleとして要素を追加しないと全体をsetとして扱えない
    if i == 0:
        ans = tmp
    else:
        ans = set(ans) & set(tmp)

ans = list(list(ans)[0])
ans = ' '.join(list(map(str, ans)))
print(ans)

### FIXED CODE ###

N = int(input())
x, y, h = [], [], []
for i in range(N):
    s, t, u = map(int, input().split())
    x.append(s)
    y.append(t)
    h.append(u)

# h>0となるものは必ず存在するので
# そのときの答えの(cx, cy, H)の候補としてprobに(10000個)格納する
# 最大でN*100*100=10^6
prob = []
for i in range(N):
    if h[i] > 0:
        for cx in range(101):
            for cy in range(101):
                H = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
                prob.append([cx, cy, H])
        break

# 答えの候補probの中から全ての条件を満たすものを探す
# 最大でN*10000=10^6
for i in range(N):
    minus = []
    for j in range(len(prob)):
        cx = prob[j][0]
        cy = prob[j][1]
        H = prob[j][2]
        if h[i] == max(H - abs(x[i] - cx) - abs(y[i] - cy), 0):
            continue
        else:
            minus.append([cx, cy, H])
    if len(minus) == 0:
        continue
    else:
        for k in range(len(minus)):
            prob.remove(minus[k])

ans = ' '.join(list(map(str, list(list(prob)[0]))))
print(ans)