Harryxun/stf_run huggingface dataset:
#not clear
class Node:
    def __init__(self,id):
        self.id = id
        self.data = 0
        self.child = []
    
    def register(self, node):
        self.child.append(node)
    
    def add(self, x):
        self.data += x
        for i in range(len(self.child)):
            self.child[i].add(x)

    def search(self, id):
        if self.id == id:
            return self
        else:
            for i in range(len(self.child)):
                node = self.child[i].search(id)
                if node != -1:
                    return node
            return -1

n, q = map(int, input().split())

a, b = map(int, input().split())
root_node = Node(a)
node = Node(b)
root_node.register(node)

for i in range(n-2):
    a, b = map(int, input().split())
    node1 = root_node.search(a)
    node2 = Node(b)
    node1.register(node2)


for i in range(q):
    a, b = map(int, input().split())
    node = root_node.search(a)
    node.add(b)

for i in range(1, n+1):
    node = root_node.search(i)
    print(node.data, end=" ")




### FIXED CODE ###


# n, q = map(int, input().split())

# edge = [[] for _ in range(n)]

# counter = [0] * n

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

# for _ in range(q):
#     a, b = map(int, input().split())
#     counter[a-1] += b

# parent = [0]
# visited = []

# for i in parent:
#     visited.append(i)
#     for v in edge[i]:
#         if v in visited:
#             continue
#         parent.append(v)
#         counter[v] += counter[i]
        
# for i in range(n):
#     print(counter[i], end=" ")
# print("")

import sys
input = sys.stdin.readline
 
N, Q = [int(x) for x in input().split()]
 
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = [int(x) for x in input().split()]
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
 
cost = [0] * N
for _ in range(Q):
    p, x = [int(x) for x in input().split()]
    cost[p - 1] += x
 
next = [0]
s_next = {0}
for i in next:
    for v in edge[i]:
        if v in s_next:
            continue
        s_next.add(v)
        next.append(v)
        cost[v] += cost[i]
 
print(" ".join(map(str, cost)))
h, w = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]

th = []

for i in p:
    for n in range(2):
        th.append(i)

print(th)

### FIXED CODE ###

h, w = map(int, input().split())
p = [input() for i in range(h)]

for i in p:
    for n in range(2):
        print(i)
n=int(input())
ac=0
wa=0
tle=0
re=0

for i in range(n):
  num=str(input())
  if num=="AC":
    ac+=1
  elif num=="WA":
    wa+=1
  elif num=="TLE":
    tle+=1
  else num=="RE":
    re+=1
   

print("AC × {}".format(ac)
print("WA × {}".format(wa)
print("TLE × {}".format(tle)
print("RE × {}".format(re)


### FIXED CODE ###

n=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
  num=str(input())
  if num=="AC":
    ac+=1
  elif num=="WA":
    wa+=1
  elif num=="TLE":
    tle+=1
  else:
    re+=1
    
print("AC x {}".format(ac))
print("WA x {}".format(wa))
print("TLE x {}".format(tle))
print("RE x {}".format(re))
import collections
import itertools
N = int(input())
#cnt[URLD][x y y+x y-x][value]=set()
cnt = [[collections.defaultdict(set) for _ in range(4)] for _ in range(4)]
for _ in range(N):
    x, y, u = input().split()
    x = int(x)
    y = int(y)
    p = y + x
    q = y - x
    i = 'URLD'.index(u)
    cnt[i][0][x].add(y)
    cnt[i][1][y].add(x)
    cnt[i][2][p].add(q)
    cnt[i][3][q].add(p)

INF = float('inf')


def calc(up, down):
    ret = [INF]
    for c in up.keys() & down.keys():
        ua = sorted(up[c])
        da = sorted(down[c])
        i = j = 0
        if len(ua) and len(da):
            for i in range(len(ua)):
                for j in range(j, len(da)):
                    if ua[i] < da[j]:
                        ret += [da[i] - ua[i]]
                        break
                i += 1
    return min(ret)


#U(0)とD(3)がx(0)が一緒:d-u(>=0)の最小値
#R(1)とL(2)がy(1)が一緒:l-r(>=0)の最小値
#U(0)とR(1)がx+y(2)が一緒:(y-x)のr-u(>=0)の最小値
#L(2)とD(3)がx+y(2)が一緒:(y-x)のd-l(>=0)の最小値
#U(0)とL(2)がy-x(3)が一緒:(y+x)のl-u(>=0)の最小値
#R(1)とD(3)がy-x(3)が一緒:(y+x)のd-r(>=0)の最小値
ans = min(
    calc(cnt[0][0], cnt[3][0]), calc(cnt[1][1], cnt[2][1]),
    calc(cnt[0][2], cnt[1][2]), calc(cnt[2][2], cnt[3][2]),
    calc(cnt[0][3], cnt[2][3]), calc(cnt[1][3], cnt[3][3]))
print('SAFE' if ans == INF else ans * 5)


### FIXED CODE ###

import collections
import itertools
N = int(input())
#cnt[URLD][x y y+x y-x][value]=set()
cnt = [[collections.defaultdict(set) for _ in range(4)] for _ in range(4)]
for _ in range(N):
    x, y, u = input().split()
    x = int(x)
    y = int(y)
    p = y + x
    q = y - x
    i = 'URLD'.index(u)
    cnt[i][0][x].add(y)
    cnt[i][1][y].add(x)
    cnt[i][2][p].add(q)
    cnt[i][3][q].add(p)

INF = float('inf')


def calc(up, down):
    ret = [INF]
    for c in up.keys() & down.keys():
        ua = sorted(up[c])
        da = sorted(down[c])
        i = j = 0
        for i in range(len(ua)):
            for j in range(j, len(da)):
                if ua[i] < da[j]:
                    ret += [da[j] - ua[i]]
                    break
            i += 1
    return min(ret)


#U(0)とD(3)がx(0)が一緒:d-u(>=0)の最小値
#R(1)とL(2)がy(1)が一緒:l-r(>=0)の最小値
#U(0)とR(1)がx+y(2)が一緒:(y-x)のr-u(>=0)の最小値
#L(2)とD(3)がx+y(2)が一緒:(y-x)のd-l(>=0)の最小値
#U(0)とL(2)がy-x(3)が一緒:(y+x)のl-u(>=0)の最小値
#R(1)とD(3)がy-x(3)が一緒:(y+x)のd-r(>=0)の最小値
ans = min(
    calc(cnt[0][0], cnt[3][0]), calc(cnt[1][1], cnt[2][1]),
    calc(cnt[0][2], cnt[1][2]), calc(cnt[2][2], cnt[3][2]),
    calc(cnt[0][3], cnt[2][3]), calc(cnt[1][3], cnt[3][3]))
print('SAFE' if ans == INF else ans * 5)
X = int(input())

div = int(X/500)
mod = int(X%500)
hap = 0

if div != 0:
  hap = i
q = int(p/5)
hap += q

print(hap)

### FIXED CODE ###

X = int(input())
 
div = int(X/500)
mod = int(X%500)
hap = 0
 
if div != 0:
  hap = div*1000
q = int(mod/5)
hap += q*5
 
print(hap)
class Dice:

u,s,e,w,n,b = map(int,input().split())
roll = input()
for i in range(len(roll)):
	if roll[i] == E:
		tmp = e
		e = u
		u = w
		w = b
		b = tmp
	elif roll[i] == S:
		tmp = s
		s = u
		u = n
		n = b
		b = tmp
	elif roll[i] == W:
		tmp = w
		w = u
		u = e
		e = b
		b = tmp
	elif roll[i] == N:
		tmp = n
		n = u
		u = s
		s = b
		b = tmp

print(u)

### FIXED CODE ###

class Dice:
    u, s, e, w, n, b = map(int, input().split())
    roll = input()
    for i in roll:
        if i == "E":
            e,u,w,b = u,w,b,e
        elif i == "S":
            s,u,n,b = u,n,b,s
        elif i == "W":
            w,u,e,b = u,e,b,w
        elif i == "N":
            n,u,s,b = u,s,b,n
    print(u)

dice = Dice()
N=int(input())
print(0.5 if N%2==0 else ((N+1)/2)/((N-1)/2))

### FIXED CODE ###

N=int(input())
print(0.5 if N%2==0 else ((N+1)/2)/N)
def isOver(a,b):
    return True if (a[0]-b[0])**2 + (a[1]-b[1])**2 <= 4.0 else False
 
def largestGroup(mtrx,num):
    mx = 1
    ls = [num]
    for i in mtrx[num]:
        if i == num:
        	continue
       	m = youKnow(mtrx,ls,i)
        mx = max(mx,m)
    return mx
 
def youKnow(mtrx,ls,num):
    mx = len(ls)
    if set(ls) <= set(mtrx[num]):
        if num not in ls:
            ls.append(num)
        	for i in list(set(mtrx[num])-set(ls)):
            	m = youKnow(mtrx,ls,i)
            	mx = max(mx,m)
    return mx
 
while True:
    max_over = 0
    n = int(raw_input())
    if n == 0: break
    seals = [map(float, raw_input().split(",")) for i in range(n)]
 
    overs = []
    for i in range(n):
        over = []
        for j in range(n):
            if isOver(seals[i],seals[j]):
                over.append(j)
        overs.append(over)
         
    ref = [i for i in range(n)]
    for i in ref:
       num_over = largestGroup(overs,i)
       for j in overs[i]:
           if j in ref: ref.remove(j)
       if num_over > max_over:
           max_over = num_over
    print max_over

### FIXED CODE ###

def isOver(array,x,y):
	return True if (array[0]-x)**2+(array[1]-y)**2 <= 1.01 else False
	
while True:
    mx = 0
    n = int(raw_input())
    if n == 0: break
    seals = [map(float, raw_input().split(",")) for i in range(n)]
    x = 0
    while x < 10.0:
    	y = 0.0
    	while y < 10.0:
    		num = 0
    		for seal in seals:
    			if isOver(seal,x,y):
    				num += 1
    		mx = max(mx,num)
    		y += 0.1
        x += 0.1
    print mx
S = list(input())
K = int(input())

if K == 1 or S[0] == 1:
    print(S[1])
for i,s in enumerate(S):
    if i + 1 == K:
        print(S[i])
        exit()
    if S[i] != 1:
        print(S[i])
        exit()

### FIXED CODE ###

S = list(input())
K = int(input())

for i,s in enumerate(S):
    if i + 1 == K:
        print(S[i])
        exit()
    if S[i] != "1":
        print(S[i])
        exit()
while 1;


  H, W = map(int, raw_input().split())
  s = ""

  if H == 0 and W == 0:
    break

  for i in range(H):
    for j in range(W):
      if i%2 == 0:
        if j%2 == 0:
          s = s + "#"
        else:
          s = s + "."
      else:
        if j%2 == 0:
          s = s + "."
        else:
          s = s + "#"
    print s
    s = ""

### FIXED CODE ###

while 1:
  H, W = map(int, raw_input().split())
  s = ""

  if H == 0 and W == 0:
    break

  for i in range(H):
    for j in range(W):
      if i%2 == 0:
        if j%2 == 0:
          s = s + "#"
        else:
          s = s + "."
      else:
        if j%2 == 0:
          s = s + "."
        else:
          s = s + "#"
    print s
    s = ""
  print ""
N, T = map(int, input().split())
ans = 1e9
for n in range(T):
    c, t = map(int, input().split())
    if t <= T:
        ans = min(ans, c)
if ans == 1e9:
    print('TLE')
else:
    print(ans)



### FIXED CODE ###

N, T = map(int, input().split())
ans = 1e9
for n in range(N):
    c, t = map(int, input().split())
    if t <= T:
        ans = min(ans, c)
if ans == 1e9:
    print('TLE')
else:
    print(ans)
X, A, B = map(int, input().split())
if A <= B:
    print("delicious")
elif (B-A) <= X:
    pirnt("safe")
elif X < (B-A):
    print("dangerous")

### FIXED CODE ###

X, A, B = map(int, input().split())
if B <= A:
    print("delicious")
else:
    if (B-A) <= X:
        print("safe")
    if (B-A) > X:
        print("dangerous")
h,w,k=map(int,input().split())
G=[["."]*w for i in range(h)]
for i in range(h):
  G[i]=list(input())
ans=[[0]*w for i in range(h)]
GG=[[0] for i in range(h)]
for i in range(h):
  for j in range(w):
    if G[i][j]=="#":
      GG[i].append(j)
  GG[i].append(w)
B=[0]*h
a=1
for i in range(h):
  if len(GG[i])==2:
    continue
  B[i]=1
  ans[i][GG[i][0]:GG[i][2]]=[a]*(GG[i][2]-GG[i][0])
  a=a+1
  for j in range(len(GG[i])-3):
    ans[i][GG[i][j+2]:GG[i][j+3]]=[a]*(GG[i][j+3]-GG[i][j+2])
    a=a+1
for i in range(B[2]-B[0]):
  ans[i]=ans[B[1]]
for i in range(B[2],h):
  if B[i]==0:
    ans[i]=ans[i-1]
print(ans)

### FIXED CODE ###

h,w,k=map(int,input().split())
G=[["."]*w for i in range(h)]
for i in range(h):
  G[i]=list(input())
ans=[[0]*w for i in range(h)]
GG=[[0] for i in range(h)]
for i in range(h):
  for j in range(w):
    if G[i][j]=="#":
      GG[i].append(j)
  GG[i].append(w)
B=[0]
a=1
for i in range(h):
  if len(GG[i])==2:
    continue
  B.append(i)
  ans[i][GG[i][0]:GG[i][2]]=[a]*(GG[i][2]-GG[i][0])
  a=a+1
  for j in range(len(GG[i])-3):
    ans[i][GG[i][j+2]:GG[i][j+3]]=[a]*(GG[i][j+3]-GG[i][j+2])
    a=a+1
B.append(h)
for i in range(B[2]-B[0]):
  ans[i]=ans[B[1]]
for i in range(B[2],h):
  if i not in B:
    ans[i]=ans[i-1]
for i in range(h):
  for j in range(w):
    print(ans[i][j],end=" ")
  print()
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


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


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


n = int(input())
t = list(set([int(input()) for _ in range(n)]))

print(lcm(*t))


### FIXED CODE ###

import fractions

n = int(input())
a = 1

for b in range(n):
    b = int(input())
    a = a*b//fractions.gcd(a, b)
print(a)
def q3():
    N = int(input())
    A = []
    for n in range(N):
        A.append(int(input()))

    for n in range(N):
        tmp = A.copy()
        tmp.pop(n)
        print(max(tmp))


if __name__ == '__main__':
    q3()


### FIXED CODE ###

def q3():
    """ C - Exception Handling """
    N = int(input())
    A = []
    for n in range(N):
        A.append(int(input()))

    max_A = max(A)
    second_A = sorted(A, reverse=True)[1]
    for n in range(N):
        if A[n] == max_A:
            print(second_A)
        else:
            print(max_A)

            
if __name__ == '__main__':
    q3()
n,x=map(int,input().split())
a=[int(input()) for i in range(n)]
print(n+(x-sum(a))//min(a)]

### FIXED CODE ###

n,x=map(int,input().split())
a=[int(input()) for i in range(n)]
print(n+(x-sum(a))//min(a))
n,m = list(map(int, input().split()))
x = list(map(int, input().split()))

if n >= m:
    print(0)
    exit()
else:
    difference = []
    x.sort()
 
    for i in range(m-1):
        difference.append(x[i+1]-x[i])
 
    difference.sort()
 
    print(sum(difference[:n-1]))


### FIXED CODE ###

t,x = input().split()
print(int(t)/int(x))
s = input()
t = input()
count=10000000000
COUNT=0
for j in range(len(s)-len(t)-1):
    for i in range(len(t)):
        if not t[i]==s[j]:
            COUNT+=1
    count=min(count,COUNT)
print(count)


### FIXED CODE ###

D, T, S = map(int, input().split())
if D<=T*S:
  print("Yes")
else:
  print("No")
from math import log


def solve(A, N):
    r = N // 2
    l = N
   
    M = set()
    for i in range(r, l):
        if A[i]:
            M.add(i)
    l = r
    r //=2

    while l > 0:
        for i in range(r, l):
            if A[i] and A[i<<1]:
                M.add(i)
                A[i] = 1
            else:
                A[i] = 0
        l = r
        r //=2

    return M


def main():
    N = int(input())
    X = [0] * (2**15)
    A = [int(x) for x in input().split()]
    for i in range(len(A)):
        X[i] = A[i]
    m = solve(X, 2**15)
    print(len(m))
    for i in m:
        print(i+1)

main()


### FIXED CODE ###



def solve(A, N):
    B = [0] * len(A)
    for i in range(1, N+1)[::-1]:
        A2 = A[i*2] if i*2 <= N else 0
        x = A[i]
        for j in range(i*2, N+1, i):
            x ^= B[j]
        B[i] = x
    return B

#from random import randint
#solve([0] + list(randint(0, 1) for _ in range(1000)), 1000)
def main():
    N = int(input())
    A = [0] + [int(x) for x in input().split()]
    B = solve(A, N)
    print(sum(B))
    for i in range(1, N+1):
        if B[i]:
            print(i)

main()
import math
a,b = map(int,input().split())
a1 = math.round(a/0.08)
b1 = math.round(b/0.1)
c = min(a1,b1)
while True:
	if math.floor(c*0.08) == a and math.floor(c*0.1) == b:
		print(c)
		break
	elif math.floor(c*0.08) != a and math.floor(c*0.1) != b:
		print(-1)
		break
	else:
		c+=1


### FIXED CODE ###

import math
a,b = map(int,input().split())
a1 = round(a/0.08)
b1 = round(b/0.1)
c = min(a1,b1)
while True:
	if math.floor(c*0.08) == a and math.floor(c*0.1) == b:
		print(c)
		break
	elif math.floor(c*0.08) > a and math.floor(c*0.1) > b:
		print(-1)
		break
	else:
		c+=1
N = int(input())
a = list(map(int, input().split()))
a.sort()
b = a[0] - a[N - 1]
d = a[0]
e = a[N - 1]
if N > 2:
    for i in range(N - 3):
        b = b - a[N - 2 - i] 
    if b > a[1]:
        print(b - a[1])
    else:
        print(a[1] - b)
    print(c)
    for j in range(N - 2):
        print(d, end = ' ')
        print(e)
        d = d - e
        e = a[N - 2 - j]
    if e >= 0:
        print(e, end = ' ')
        print(d, end = ' ')
    else:
        print(d, end = ' ')
        print(e, end = ' ')
else:
    print(a[1] - a[0])
    print(a[1], end = ' ')
    print(a[0], end = ' ')

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
a.sort()
t = 0
for m in range(N):
    if a[m] < 0:
        t += 1
if N > 2:
    if t == 0:
        c = a[0]
        for i in range(N - 2):
            c = c - a[N - 1 - i]
        d = a[1] - c
        print(d)
        e = a[0]
        f = a[N - 1]
        for j in range(N - 2):
            print(e, end = ' ')
            print(f)
            e = e - f
            f = a[N - 2 - j]
        print(a[1], end = ' ')
        print(e)
    elif t > 0 and t < N - 1:
        c = 0
        for i in range(t):
            c += a[i] 
        for j in range(N - t -1):
            c = c - a[t + 1 + j]
        d = a[t] - c
        print(d)
        e = a[0]
        f = a[N - 1]
        for k in range(N - t - 1):
            print(e, end = ' ')
            print(f)
            e = e - f
            f = a[N - 2 - k]
        a[0] = e
        g = a[t]
        for l in range(t):
            print(g, end = ' ')
            print(a[l])
            g = g - a[l]
    elif t == N - 1 or t == N:
        c = a[N - 1]
        for i in range(N - 1):
            c = c - a[i]
        print(c)
        d = a[N - 1]
        for j in range(N - 1):
            print(d, end = ' ')
            print(a[j])
            d -= a[j]
else:
    print(a[1] - a[0])
    print(a[1], end = ' ')
    print(a[0])
import sys
input = sys.stdin.readline

N,Q = map(int,input().split())
aLst = [[int(i) for i in input().split()] for _ in range(N-1)]
pLst = [[int(i) for i in input().split()] for _ in range(Q)]
to = [[]for _ in range(N)]

for a,b in aLst:
    to[a-1].append(b-1)
    to[b-1].append(a-1)

ps = [0]*N
for a,b in pLst:
    ps[a-1] += b

def dfs(v, i):
    for j in to[v]:
        if i == j:
            continue
        ps[j] += ps[v]
        dfs(j,v)

dfs(0,-1)
print(' '.join(map(str, ps)))


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,Q = map(int,input().split())
aLst = [[int(x) for x in input().split()] for _ in range(N-1)]
pLst = [[int(x) for x in input().split()] for _ in range(Q)]

tmpLst = [[] for _ in range(N+1)]
for i, j in aLst:
    tmpLst[i].append(j)
    tmpLst[j].append(i)

ansLst = [0] * (N + 1)
for i,j in pLst:
    ansLst[i] += j

def dfs(v, p):
    for i in tmpLst[v]:
        if i == p:
            continue
        ansLst[i] += ansLst[v]
        dfs(i, v)


dfs(1, 0)

ans = ' '.join(map(str, ansLst[1:]))
print(ans)
n = int(input())
a = list(map(int,input().split()))
ans = 0

while all(i % 2 == 0 for i in a):
    a = [i // 2 for i in a]
    ans += 1
print(ans)

### FIXED CODE ###

print(input().count('1'))
import math
n = int(raw_input())
for i in range(n)
    x1, y1, x2, y2, x3, y3 = map(float, raw_input().split())
    a = math.sqrt((x1-x2)**2+(y1-y2)**2)
    b = math.sqrt((x1-x3)**2+(y1-y3)**2)
    c = math.sqrt((x2-x3)**2+(y2-y3)**2)
    s = (a+b+c)/2
    ss = math.sqrt(s*(s-a)*(s-b)*(s-c))
    sina = 2*ss/b/c
 
    r = a/sina/2

    a = a*a
    b = b*b
    c = c*c
    px = (a*(b+c-a)*x3 + b*(a+c-b)*x2+c*(a+b-c)*x1)/16/ss**2
    py =(a*(b+c-a)*y3 + b*(a+c-b)*y2+c*(a+b-c)*y1)/16/ss**2

    print "%.3f %.3f %.3f" % (px, py, r)

### FIXED CODE ###

import math
n = int(raw_input())
for i in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, raw_input().split())
    a = math.sqrt((x1-x2)**2+(y1-y2)**2)
    b = math.sqrt((x1-x3)**2+(y1-y3)**2)
    c = math.sqrt((x2-x3)**2+(y2-y3)**2)
    s = (a+b+c)/2
    ss = math.sqrt(s*(s-a)*(s-b)*(s-c))
    sina = 2*ss/b/c
 
    r = a/sina/2

    a = a*a
    b = b*b
    c = c*c
    px = (a*(b+c-a)*x3 + b*(a+c-b)*x2+c*(a+b-c)*x1)/16/ss**2
    py =(a*(b+c-a)*y3 + b*(a+c-b)*y2+c*(a+b-c)*y1)/16/ss**2

    print "%.3f %.3f %.3f" % (px, py, r)
import bisect
import heapq
N,Q = list(map(int,input().split(" ")))

hitos = []
ans = [-1] * Q
queries =[]
heapq.heapify(queries)
events = set()
heapq.heapify(events)

for i in range(N):
    S,T,X =list(map(int,input().split(" ")))
    lt = S -X -0.5
    rt = T -X -0.5
    queries.append((lt,-1,X)) #-1 → 挿入クエリ lが時間、-1がクエリの種類、Xが場所
    queries.append((rt,1,X)) # 1 → 削除クエリ



for i in range(Q):
    t = int(input())
    queries.append((t,0,-99)) # 0 → チェッククエリ
queries.sort(key = lambda x:x[0])
for t,kind,x in queries:
    if kind == 0:
        if len(events) > 0:
            print(events[0])
        else:
            print(-1)
    if kind == -1:
        events.append(x)
    if kind == 1:
        if x in events:
            events.remove(x)



### FIXED CODE ###

import bisect
import heapq
import sys
N,Q = [int(x) for x in sys.stdin.readline().split()]

hitos = []
ans = [-1] * Q
queries =[]
jump = [-1] * Q



queries = [[int(x) for x in sys.stdin.readline().split()] for i in range(N)]
hitos = [int(sys.stdin.readline()) for i in range(Q)]


# for i in range(N):
    # S,T,X =list(map(int,input().split(" ")))
    # lt = S -X -0.5
    # rt = T -X -0.5
    # queries.append([lt,rt,X]) #-1 → 挿入クエリ lが時間、-1がクエリの種類、Xが場所


queries.sort(key=lambda x:x[2])





for l,r,x in queries:
     lind  = bisect.bisect_left(hitos,l-x - 0.5)
     rind  = bisect.bisect_left(hitos,r -x - 0.5)
     while lind < rind:
         if ans[lind] == -1:
            ans[lind] = x
            jump[lind] = rind
            lind += 1
         else:
             temp = jump[lind]
             jump[lind] = rind
             lind = temp

for i  in ans:
    print(i)
import sys

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))
d = {}
for i in range(m):
    b,c = map(int, input().split())
    if d.get(c) == None:
        d[c] = b
    else:
        d[c] = d[c] + b

print(d)

for c, d in sorted(d.items(), key=lambda x: -x[0]):
    A.sort()
    print(A)
    if b <= n and A[0] < c:
        if A[b-1] > c:
            for i in range(b):
                if i//c:
                    break
                f = i
            A[:f]=[c]*f
        else:
            A[:b]=[c]*b


print(sum(A))

### FIXED CODE ###

import sys
import heapq

input = sys.stdin.readline
n,m = map(int, input().split())
A = list(map(int,input().split()))
d = [list(map(int,input().split())) for _ in range(m)]

d.sort(key=lambda x:-x[1])
total = sum(A)
heapq.heapify(A)

for i in range(m):
    for j in range(d[i][0]):
        tmp = heapq.heappushpop(A, d[i][1])
        if tmp < d[i][1]:
                total += (d[i][1] - tmp)
        else:
            break

print(total)
from collections import Counter
mod = 10 ** 9 + 7
n = int(input())
C = [int(input()) for i in range(n)]

for i in range(n - 1, 0, -1):
    if C[i] == C[i - 1]:
        del C[i]

D = [0] * n
for i in range(2, n):
    D[i] = D[i - 1] + i - 1
        
ans = 1
for i in Counter(C).values():
    ans += D[i]
    
print(ans % mod)

### FIXED CODE ###

from collections import defaultdict
 
mod = 10 ** 9 + 7
n = int(input())
C = [int(input()) for i in range(n)]
 
for i in range(n - 1, 0, -1):
    if C[i] == C[i - 1]:
        del C[i]
        #重複部分を圧縮したCを作成
        
D = defaultdict(int)
ans = 1
for c in C:
    ans += D[c]
    D[c] = ans
    #print(D, ans)

print(ans % mod)
def main():
    n = int(input())
    print(sum(list(range(1, n))))
        
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n = int(input())
    print((n * (n - 1)) // 2)
        
if __name__ == '__main__':
    main()
def resolve():
	n = int(input())
	ws = [input() for _ in range(n)]
	cnt = []
	for w in ws:
		if w in cnt:
			print('No')
			return
		if len(cnt) and cnt[-1][-1] != w[-1]:
			print('No')
			return
		cnt.append(w)
	print('Yes')
resolve()

### FIXED CODE ###

def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	while True:
		again = True
		for i in range(n):
			if a[i] % 2:
				again = False
			a[i] = a[i] / 2
		if again:
			ans += 1
		else:
			break
	print(ans)
resolve()
N, L = map(int, input().split())
taste = sp.arange(L, L+N)
s = sum(taste)

if 0 <= L:
    print(s - taste[0])
elif L+N < 1:
    print(s - taste[N-1])
else:
    print(s)

### FIXED CODE ###

import scipy as sp

N, L = map(int, input().split())
taste = sp.arange(L, L+N)
s = sum(taste)

if 0 <= L:
    print(s - taste[0])
elif L+N < 1:
    print(s - taste[N-1])
else:
    print(s)