Harryxun/stf_run huggingface dataset:
#まず一行目の"N M"を取得
N,M=map(int, input().split()) 

#2-M+1行目を入力する
arr_path=np.array([0,0])
#空のarrayを値0として定義した
for i in range(M):
    a,b=map(int,input().split())
    arr=np.array([a,b])
    arr_path=np.vstack([arr_path,arr])    

#もはや入れ子構造のリストを使うことにして、level_0のような表現は必要ない
#層の全体を格納するリストのリスト（index0,1,2..と引数に対応して、層0,1,2...と対応する）
class_layer=[]
class_layer.append([1])

#部屋xからの移動先を出力する関数
def transit(x):
    path=arr_path[np.any(arr_path==x, axis=1)]
    #これはいま部屋iを考えている（levelという層にある部屋）
    #pathをarrayから抽出して、その部屋から移動することを考える
    path=path[path != x]
    trans_list=path.tolist()
    return trans_list

#層構造(x層)を1上げて上の層を出力する関数を定義する
def level_up(x):
    now=class_layer[x]
    pre=[]
    if x >=1:
        pre=class_layer[x-1]
    li=[] 
    for i in now:
        for j in transit(i):
            if j in now:
                continue
            elif j in pre:
                continue
            else:
                li.append(j)
    class_layer.append(li)
    
for i in range(M):
    level_up(i)


#1つの部屋に対して、その部屋が何番目の層なのか出力する
def layer_finder(x):
    for i in range(M):
        for j in class_layer[i]:
            if j==x:
                global ans
                ans=i
                #local変数になってしまっていて、関数外でいまいちうまく使えないので、変数を置く前にglobal宣言というものをしてglobal変数にする
                break
            else:
                continue
    return ans


#部屋xが何番の矢印を示せばいいのか出力
def path_get(x):
    #部屋xは層が幾つなのか
    X=layer_dict[x-1]
    #(X-1)層の部屋番号を出力
    li1=class_layer[X-1]
    
    #部屋xからの移動先
    path=arr_path[np.any(arr_path==x, axis=1)]
    path=path[path != x]
    li2=path.tolist()
    
    #l1とl2の共通部分を出す
    #setと&を使うといいらしい!
    li_common=list(set(li1) & set(li2))
    
    print(li_common[0])
    

    
print("yes")
for i in range(2,N+1):
    path_get(i)

### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]

links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)

result = [-1] * (N + 1)
q = deque([1])
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
print('Yes')
print('\n'.join(str(i) for i in result[2:]))
sx,sy,tx,ty=map(int, input().split()) #a1 a2 a3

m1=(tx-sx)*"R"+(ty-sy)*"U"
m2=(tx-sx)*"L"+(ty-sy)+"D"


print(m1+m2+"DR"+a+"ULUL"+m2+"DR")


### FIXED CODE ###

sx,sy,tx,ty=map(int, input().split()) #a1 a2 a3

m1=(tx-sx)*"R"+(ty-sy)*"U"
m2=(tx-sx)*"L"+(ty-sy)*"D"


print(m1+m2+"DR"+m1+"ULUL"+m2+"DR")
a,b=map(int, input().split())
s=[a+b, a-b, A*b]
print(max(s))

### FIXED CODE ###

a,b=map(int, input().split())
s=[a+b, a-b, a*b]
print(max(s))
n = int(input())

 task_lis = [[int(r) for i in input().split()] for _ in range(n)]


sum_a = 0
ch_over = 1

for i in range(n):
    sum_a += task_lis[i][1]
    if task_lis[i][0] < sum_a:
        ch_over = 0
        break

if ch_over == 0:
    print("No")
else:
    print("Yes")


### FIXED CODE ###

n = int(input())
task_lis = sorted([[int(i) for i in input().split()] for _ in range(n)], key = lambda x:x[1])


sum_a = 0
ch_over = 1

for i in range(n):
    sum_a += task_lis[i][0]
    if task_lis[i][1] < sum_a:
        ch_over = 0
        break

if ch_over == 0:
    print("No")
else:
    print("Yes")
N = int(input())
A = list(map(int, input().split()))
Ans = [0] * (N)
for i in range(N):
    Ans[A[i]-1] = i+1

print(*Ans)

### FIXED CODE ###

N = int(input())

if N % 2 == 0:
    print(0.5)
else:
    print(1-(N-1)/2/N)
A = input()
B = input()
C = input()

next_turn = A[0]
Acnt = 0
Bcnt = 0
Ccnt = 0
while True:
    if next_turn == 'a':
        next_turn = A[Acnt]
        Acnt += 1
        if Acnt == len(A)-1:
            print('A')
            break
    elif next_turn == 'b':
        next_turn = B[Bcnt]
        Bcnt += 1
        if Bcnt == len(B)-1:
            print('B')
            break
    elif next_turn == 'c':
        next_turn = C[Ccnt]
        Ccnt += 1
        if Ccnt == len(C)-1:
            print('C')
            break

### FIXED CODE ###

A = input()
B = input()
C = input()

next_turn = A[0]
Acnt = 1
Bcnt = 0
Ccnt = 0
while True:
    if next_turn == 'a':
        if Acnt == len(A):
            print('A')
            break
        next_turn = A[Acnt]
        Acnt += 1

    elif next_turn == 'b':
        if Bcnt == len(B):
            print('B')
            break
        next_turn = B[Bcnt]
        Bcnt += 1

    elif next_turn == 'c':
        if Ccnt == len(C):
            print('C')
            break
        next_turn = C[Ccnt]
        Ccnt += 1
s=input()
n=int(input())
l=""
for i in range(len(s)):
    f=(26+ord("a")-ord(s[i]))%26
    if n>=f:n-=f;l+="a"
    else:l+=s[i]
    if n==0:print(l+s[i+1:]);exit()
print(l[:-1]+chr(ord(l[-1])+n))

### FIXED CODE ###

s=input()
n=int(input())
l=""
for i in range(len(s)):
    f=(26+ord("a")-ord(s[i]))%26
    if n>=f:n-=f;l+="a"
    else:l+=s[i]
    if n==0:print(l+s[i+1:]);exit()
print(l[:-1]+chr(ord(l[-1])+n%26))
import numpy

def solve(string):
    n, *p = map(int, string.split())
    p = numpy.asarray(p)
    asc=(p[:-2] < p[1:-1]) & (p[1:-1] < p[2:])
    desc=(p[:-2] > p[1:-1]) & (p[1:-1] > p[2:])
    return str(sum(asc | desc))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


### FIXED CODE ###

def solve(string):
    n, *p = map(int, string.split())
    ans = 0
    for i, j, k in zip(p, p[1:], p[2:]):
        ans += 1 if i <= j <= k or i >= j >= k else 0
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))
import math
N=int(input())
number=list(map(int,input().split()))
SUM=[]
sum=0
p=10**9 +7
#Nの階乗
x=math.factorial(N)%p
#0からにすると1/0でエラーになる
for i in range(1,N+1):
  #kは逆元
  k=pow(i,p-2,p)
  sum+= (x*k)%p
  SUM.append(sum)
#SUMのi番目は1/1から1/iまで足した和になっている。
#k=i-1となる
#1/1を二回足してしまったので引く
for i in range(N):
  ans+= (number[i]*(SUM[i]+SUM[N-i]-x))%p
  ans= ans%p
#答え
print(ans)

### FIXED CODE ###

import math
n=int(input())
number=list(map(int,input().split()))
SUM=[]
sum=0
p=10**9 +7
x=math.factorial(n)%(10**9 +7)
for i in range(1,n+1):
  k=pow(i,p-2,p)
  sum+= (x*k)%p
  sum= sum%(p)
  SUM.append(sum)
ans=0
for i in range(n):
  ans+= number[i]*(SUM[n-1-i]+SUM[i]-x)
  ans=ans%(p)
print(ans)
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**i)
sorted(list, reverse=True)
N=int(input())
count=0
for i in list:
  if N <= i:
    N=N-i
    count=+1
      if N==0:
        print(count)

### FIXED CODE ###

N=int(input())

A=[1]

i = 1
while True:
    if 6**i <= 100000:
        A.append(6**i)
    else:
        break
    i += 1

i = 1
while True:
    if 9**i <= 100000:
        A.append(9**i)
    else:
        break
    i += 1

A.sort()

dp = [N]*(N+1)
dp[0] = 0
for i in range(1, N+1):
    for j in range(len(A)):
        if i - A[j] >= 0:
            dp[i] = min(1+dp[i-A[j]], dp[i])

print(dp[-1])
print((input().count(o)+7)*100)

### FIXED CODE ###

print((input().count("o")+7)*100)
import sys
from math import factorial

input = sys.stdin.readline
n,k = map(int,input().split())
a = list(map(int,input().split()))

mod = 10**9 + 7

a.sort()

li = []
for i in range(n-1):
    li.append(a[i+1]-a[i])

ans = 0

dp = [1]
for i in range(1,n+1):
    dp.append(dp[-1]*i%mod)

nCr = {}
def comb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = comb(n-1,r) + comb(n-1,r-1)
    return nCr[(n,r)]

comb1 = comb(n,k)

for i in range(n-1):
    if i+1 < k and n-i-1 < k:
        ans += li[i] * comb1
    elif i+1 < k:
        ans += li[i] * (comb1 - comb(n-i-1,k))
    elif n-i-1 < k:
        ans += li[i] * (comb1 - comb(i+1,k))
    else:
        ans += li[i] * (comb1 - comb(n-i-1,k) - comb(i+1,k))

print(ans%mod)


### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))

mod = 10**9 + 7

a.sort(reverse = True)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

comb = Combination(100010)
ans = 0

for i in range(n-k+1):
    ans += a[i] * comb(n-i-1, k-1)
    ans %= mod

a = a[::-1]

for i in range(n-k+1):
    ans -= a[i] * comb(n-i-1, k-1)
    ans %= mod

print(ans)
a = int(input())
b = int(input())
c = int(input())
d = int(input())
if abs(c -a) <= d :
    print('Yes')
elif abs(b -a) <= d and abs(c -b) <= d:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

a,b,c,d = map(int , input().split())
if abs(c -a) <= d :
    print('Yes')
elif abs(b -a) <= d and abs(c -b) <= d:
    print('Yes')
else:
    print('No')
x,y = map(str,input().split())

x = int(x,16)
y = int(y,16)

if x<y:
    print("<")
elif x == y:
    print("=")
else:
    ptiny(">")


### FIXED CODE ###

x,y = map(str,input().split())

x = int(x,16)
y = int(y,16)

if x<y:
    print("<")
elif x == y:
    print("=")
else:
    print(">")
import numpy as np


def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))


    for _ in range(K):
        counter=[0 for _ in range(N)]

        for i in range(len(A)):
            left=max(0,i-A[i])
            right=min(N-1,i+A[i])
            counter[left]+=1
            if right+1<N:
                counter[right+1]-=1
        for i in range(len(counter)-1):
            counter[i+1]+=counter[i]

        if counter==A:
            break
        else:
            A=counter

    for i in range(N):
        if i!=N-1:
            print(str(A[i])+" ",end="")
        else:
            print(A[i])

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))


    for _ in range(K):
        counter=[0 for _ in range(N)]

        for i in range(len(A)):
            left=max(0,i-A[i])
            right=min(N-1,i+A[i])
            counter[left]+=1
            if right+1<N:
                counter[right+1]-=1
        for i in range(len(counter)-1):
            counter[i+1]+=counter[i]

        if counter==A:
            break
        else:
            A=counter

    for i in range(N):
        if i!=N-1:
            print(str(A[i])+" ",end="")
        else:
            print(A[i])

if __name__ == "__main__":
    main()
import sys
input = sys.stdin.readline
def print_ans(A, B):
    """Test Case
    >>> print_ans(-13, 3)
    -10
    >>> print_ans(1, -33)
    34
    >>> print_ans(13, 3)
    39
    """
    print(max(max(A + B, A - B), A * B))

if __name__ == '__main__':
    A = int(input().rstrip())
    B = int(input().rstrip())
    print_ans(A, B)


### FIXED CODE ###

import sys
input = sys.stdin.readline
def print_ans(A, B):
    """Test Case
    >>> print_ans(-13, 3)
    -10
    >>> print_ans(1, -33)
    34
    >>> print_ans(13, 3)
    39
    """
    print(max(max(A + B, A - B), A * B))

if __name__ == '__main__':
    A, B = map(int,input().rstrip().split())
    print_ans(A, B)
import math

n, d = map(int, input().split())
x = [list(int, input().split()) for i in range(n)]
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(d):
            dis = 0
            dis += (x[i][k]-x[j][k])**2
            if math.sqrt(dis) % 1 == 0:
                cnt += 1
print(cnt)

### FIXED CODE ###

import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        dis = 0
        for k in range(d):
            dis += (x[i][k]-x[j][k])**2
        if math.sqrt(dis) % 1 == 0:
            cnt += 1
print(cnt)
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())

dis = abs(a-b)
sub = w-v

if(-(sub*t)>=dis):
    print("YES")
else:

### FIXED CODE ###

a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())

dis = abs(a-b)
sub = w-v

if(-(sub*t)>=dis):
    print("YES")
else:
    print("NO")
from sympy import divisor_count
n=int(input())
ans=0
for i in range(1,n+1):
    ans+=i*(divisor_count(i))
print(ans)

### FIXED CODE ###

n=int(input())
ans=0
for i in range(1,n+1):
    m=n//i
    m*=i
    for j in range(i,m+1,i):
        ans+=j
print(ans)
N = int(input())
X = input()
​
pop_X = sum(map(int,list(X)))
X_10 = int('0b'+X,2)
r_0 = X_10%(pop_X+1)
zero_flag = False
if pop_X == 1:
    zero_flag = True
else:
    r_1 = X_10%(pop_X-1)
​
diff = 2 ** (N-1)
for i in range(N):
    if X[i]=='0':
        r = (r_0+diff%(pop_X+1))%(pop_X+1)
    else:
        if zero_flag:
            print(0)
            break
        else:
            r = (r_1-diff%(pop_X-1))%(pop_X-1)
    count = 1
    while True:
        if r == 0:
            break
        pop = sum(map(int,list(bin(r)[2:])))
        r = r % pop
        count += 1
        
    print(count)
    diff /= 2


### FIXED CODE ###

N = int(input())
X = input()

pop_X = sum(map(int,list(X)))
X_10 = int('0b'+X,2)

r_0 = X_10%(pop_X+1)
diff_0 = 1%(pop_X+1)

zero_flag = False
if pop_X == 1:
    zero_flag = True
else:
    r_1 = X_10%(pop_X-1)
    diff_1 = 1%(pop_X-1)

answer = []


for i in range(N)[::-1]:
    if X[i]=='0':
        r = (r_0+diff_0)%(pop_X+1)
    else:
        if zero_flag:
            answer.append(0)
            diff_0 = (diff_0*2)%(pop_X+1)
            continue
        else:
            r = (r_1-diff_1)%(pop_X-1)
    count = 1
    while True:
        if r == 0:
            break
        pop = sum(map(int,list(bin(r)[2:])))
        r = r % pop
        count += 1
        
    answer.append(count)
    diff_0 = (diff_0*2)%(pop_X+1)
    if zero_flag:
        continue
    diff_1 = (diff_1*2)%(pop_X-1)

for i in answer[::-1]:
    print(i)
ans = 0
a, b, c = [ int(v) for v in input().split() ]
for i in range(1,b+1):
    if (a * i) % b == c:
        ans = 1
        break
if ans == 1:
    print("YES")
else:

### FIXED CODE ###

ans = 0
a, b, c = [ int(v) for v in input().split() ]
for i in range(1,b+1):
    if (a * i) % b == c:
        ans = 1
        break
if ans == 1:
    print("YES")
else:
    print("NO")
s=sum(list(input()))
print(10 if s==1 else s)

### FIXED CODE ###

s=sum(list(map(int,list(input()))));print(10 if s==1 else s)
class uf_tree:
    def __init__(self, n):
        self.sizes = [0] * n
        self.par = range(n)

    def find(self, x):
        if x == self.par[x]:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.sizes[x] < self.sizes[y]:
            x, y = y, x
        self.par[y] = x
        self.sizes[x] += self.sizes[y]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self.sizes[find(x)]


N, K, L = map(int, raw_input().split())

uf_1 = uf_tree(N+1)
uf_2 = uf_tree(N+1)

for i in range(K):
    p, q = map(int, raw_input().split())
    uf_1.unite(p, q)

for i in range(L):
    r, s = map(int, raw_input().split())
    uf_2.unite(r, s);

dic = {}
for i in range(1, N+1):
    key = (uf_1.find(i), uf_2.find(i))
    dic[key] = dic.get(key, 0) + 1

for i in range(1, N+1):
    print dic[(d.find(i), t.find(i))],


### FIXED CODE ###

class uf_tree:
    def __init__(self, n):
        self.sizes = [0] * n
        self.par = range(n)

    def find(self, x):
        if x == self.par[x]:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.sizes[x] < self.sizes[y]:
            x, y = y, x
        self.par[y] = x
        self.sizes[x] += self.sizes[y]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self.sizes[find(x)]


N, K, L = map(int, raw_input().split())

uf_1 = uf_tree(N+1)
uf_2 = uf_tree(N+1)

for i in range(K):
    p, q = map(int, raw_input().split())
    uf_1.unite(p, q)

for i in range(L):
    r, s = map(int, raw_input().split())
    uf_2.unite(r, s);

dic = {}

for i in range(1, N+1):
    key = (uf_1.find(i), uf_2.find(i))
    dic[key] = dic.get(key, 0) + 1

for i in range(1, N+1):
    print dic[(uf_1.find(i), uf_2.find(i))],
c = str(input())

if c.lowercase():
  print 'a'
else:
  print 'A'

### FIXED CODE ###

c = str(input())

if c.islower():
    print('a')
else:
    print('A')
ort math
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K==0:
    print(sum(A))
else:
    A = sorted(A)
    a = A[-1]
    n1 = math.floor(math.log2(a))+1
    n2 = math.floor(math.log2(K))+1
    cnt = 0
    k = n2-1
    while k>=0:
        B = [(A[i]//(2**k))%2 for i in range(N)]
        b = sum(B)
        cnt += 2**k*max(b,N-b)
        k -= 1
    if n1>n2:
        k = n1-1
        while k>n2-1:
            B = [(A[i]//(2**k))%2 for i in range(N)]
            b = sum(B)
            cnt += 2**k*max(b,N-b)
            k -= 1 
    print(cnt)

### FIXED CODE ###

import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
a1 = max(A)
n = int(math.log2(max(a1,K)))+1
B = [0 for _ in range(n)]
for i in range(N):
    a = bin(A[i])[2:]
    for j in range(len(a)):
        if a[len(a)-1-j]=="1":
            B[j] += 1
x = bin(K)[2:]
y = ""
flag = 0
for i in range(len(x)):
    if flag==0:
        if x[i]=="0":
            y += x[i]
        else:
            if B[len(x)-1-i]<=N//2:
                y += x[i]
            else:
                y += "0"
                flag = 1
    else:
        if B[len(x)-1-i]<=N//2:
            y += "1"
        else:
            y += "0"
y = int(y,2)
cnt = 0
for i in range(N):
    cnt += y^A[i]
print(cnt)
H,W=map(int,input().split())
hlen= list(map(int,input().split()))
wlen =	list(map(int,input().split()))
def is_unique(l):
    return len(l) == len(set(l))
if not is_unique(hlen) or not is_unique(wlen):
	print(0)
	exit()
def Count(x,l):
	ret = 0
	while l[ret] > x :
		ret += 1
		if ret == len(l):
			break
	return ret	
hlen.sort(reverse=True)
wlen.sort(reverse=True)

m = max(hlen[0],wlen[0])
count = 1
for num in range(1,H*W+1)[::-1]:
	flagh = 0
	flagw = 0
	if num in hlen:
		flagh = 1
	if num in wlen:
		flagw = 1
	if flagh and flagw:
		count *= 1
	elif flagh:
		count *= Count(num,wlen)
	elif flagw:
		count *= Count(num,hlen)
	else:
		count *= Count(num,hlen)*Count(num,wlen) - (m-num)
    count %= (10**9+7)
	#print(num,flagh,flagw,count)
print(count % (10**9+7))

### FIXED CODE ###

H,W=map(int,input().split())
hlen = list(map(int,input().split()))
wlen =	list(map(int,input().split()))
hlen.sort(reverse=True)
wlen.sort(reverse=True)
hlen.append(0)
wlen.append(0)

m = H*W
count = 1
h=0
w=0
for num in range(1,H*W+1)[::-1]:
	if hlen[h] == num and wlen[w] == num:
		count *= 1
		h += 1
		w += 1
	elif hlen[h] == num:
		count *= w
		h += 1
	elif wlen[w] == num:
		count *= h
		w += 1
	else:
		count *= h*w - (m-num)
	#print(num,flagh,flagw,count)
	count %= (10**9+7)
print(count)
S, W = map(int, input().split())
if S > W:
  print("safe")
  else:
    print("unsafe")

### FIXED CODE ###

S, W = map(int, input().split())
if S > W:
  print("safe")
else:
  print("unsafe")
import fractions
N=int(input())
A=[int(i) for i in input().split()]
ans=A[i]
for i in range(N-1):
    ans=fractions.gcd(ans,A[i+1])
print(ans)

### FIXED CODE ###

from fractions import gcd
N=int(input())
A=[int(i) for i in input().split()]
ans=A[0]
for i in range(N-1):
    ans=gcd(ans,A[i+1])
print(ans)
import math

n, k = map(int, input().split())
aas = input()
a = n - k

num = math.ceil(a / (k-1))

print(num+1)

### FIXED CODE ###

s = input()

ans = 0

for i in s:
	if i == '+':
		ans += 1
	else:
		ans -= 1
		
		
print(ans)
a,b,c,d = map(int, input().split())
x = a
y = c
max = x * y
if b < 0:
  print(max)
else:
  for x in range(a,b + 1):
    for y in range(c,d + 1):
      if x * y > max:
        max = x * y
  print(max)


### FIXED CODE ###

num = int(input())
if num == 0:
  print(1)
else:
  print(0)
N,K = map(int,input().split())
x=list(map(int,input().split()))
for i in range(len(x)):
    if x[i]>=0:
        zp=i
        x.insert(i,0)
        break
for i in range(len(x)):
    if x[i]<=0:
        x[i]=abs(x[i])

ans=10**11
for k in range(zp+K-len(x)+1,min(zp,K)+1):
    ans=min( ans, x[zp-k]+ x[zp+K-k]+ min(x[zp-k],x[zp+K-k]) )

print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
x=list(map(int,input().split()))
flag=0

ans=10**11
for i in range(0,len(x)-K+1):
    if x[i]*x[K-1+i] <0:
        anss=abs(x[i])+ abs(x[K-1+i])
        anss += min(abs(x[i]),abs(x[K-1+i]))
    else:
        anss=max(abs(x[i]), abs(x[K-1+i]))
    ans=min( ans, anss)

print(ans)
d,n=map(int,input().split())
if(n==100):
    n=101#100番目は100ではなく101になるので
print(m*pow(100,d))



### FIXED CODE ###

d,n=map(int,input().split())
if(n==100):
    n=101#100番目は100ではなく101になるので
print(n*pow(100,d))
n=input()
l=[int(x) for x in input().split()]
temp=list(set(x for x in l if l.count(x)>1))
y=max(temp)
if l.count(y)>3:
	lar=sec=y
else:
	lar=y
	temp.remove(y)
	sec=max(temp)
print(lar*sec)


### FIXED CODE ###

n=int(input())
a=[int(x) for x in input().split()]
a.sort()
lar=sec=i=0
while(i<n-1):
    if a[i]==a[i+1]:
        i+=1
        if a[i]>lar:
            sec=lar
            lar=a[i]
        elif a[i]>sec:
             sec=a[i]
    i+=1
print(lar*sec)
a,b,c=map(int,input().split())
ans=0
ma=max(a,b,c)
mi=min(a,b,c)
mj=a+b+c-ma-mi
ans+=(ma-mi)//2
mi+==((ma-mi)//2)*2
ans+=(ma-mj)//2
mj+=((ma-mj)//2)*2
if ma==mi==mj:
    print(ans)
elif ma==mi+1 and ma==mj+1:
    print(ans+1)
else:
    print(ans+2)

### FIXED CODE ###

a,b,c=map(int,input().split())
ans=0
ma=max(a,b,c)
mi=min(a,b,c)
mj=a+b+c-ma-mi
ans+=(ma-mi)//2
mi+=((ma-mi)//2)*2
ans+=(ma-mj)//2
mj+=((ma-mj)//2)*2
if ma==mi==mj:
    print(ans)
elif ma==mi+1 and ma==mj+1:
    print(ans+1)
else:
    print(ans+2)
N, K = map(int, input().split())
S = input()
count = 0
for i in range(1, N):
  if S[i] == S[i - 1]:
    c += 1
print(min(N - 1, count + K * 2))

### FIXED CODE ###

N, K = map(int, input().split())
S = input()
count = 0
for i in range(1, N):
  if S[i] == S[i - 1]:
    count += 1
print(min(N - 1, count + K * 2))
import sys
from collections import deque
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline


def main():
    N, Q = map(int, input().split())
    ans = [0] * N
    con = [[0, deque()] for _ in range(N)]

    for _ in range(N - 1):
        p, c = map(int, input().split())
        con[p-1][1].append(c-1)

    for _ in range(Q):
        p, v = map(int, input().split())
        con[p-1][0] += v

    def add_value(node):
        val = con[node][0]
        for child in con[node][1]:
            con[child][0] += val
            add_value(child)

    add_value(0)

    print(' '.join([str(x[0]) for x in con]))


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import deque

N, Q = map(int, input().split())
edge = [[] for i in range(N)]
ops = []
ans = [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):
    ops.append(tuple(map(int, input().split())))

for op in ops:
    node = op[0] - 1
    pnt = op[1]
    ans[node] += pnt

stack = deque()
stack.append((0, -1))

while stack:
    st = stack.pop()
    node, parent = st[0], st[1]
    children = edge[node]
    for child in children:
        if child == parent:
            continue
        ans[child] += ans[node]
        stack.append((child, node))

print(*ans)