Harryxun/stf_run huggingface dataset:
n = int(input())
edges = [[] for _ in range(n)]
costs = [-1]*n
def dfs(current, d):
    costs[current] = d
    for nex in edges[current]:
        if costs[nex[0]] != -1:
            continue
        dfs(nex[0], d+nex[1])

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

q, k = map(int, input().split())
k -= 1
dfs(k, 0)

res = []
for _ in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    res.append(costs[x]+costs[y])

for ans in res:
    print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

n = int(input())
edges = [[] for _ in range(n)]
costs = [-1]*n
def dfs(current):

    for nex, cost in edges[current]:
        if costs[nex] != -1:
            continue
        costs[nex] = costs[current] + cost
        dfs(nex)

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

q, k = map(int, input().split())
k -= 1
costs[k] = 0
dfs(k)

res = []
for _ in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    res.append(costs[x]+costs[y])

for ans in res:
    print(ans)
N = int(input())
A = list(map(int, input().strip().split()))
min_n = max_n = A[0]
for i in range(1, N):
	num = A[i]
	if min_n > num:
		min_n = num
	if max_n < num:
		max_n = num
result = max_n - min_n
print(result)
		

### FIXED CODE ###

N = int(input())
result = N if N&1==0 else N<<1
print(result)
a = list(map(int, input().split()))
a.sort()
print(abs(a[0]-a[1]) + abs(a[1]-a[2])

### FIXED CODE ###

a = list(map(int, input().split()))
a.sort()
print(abs(a[0]-a[1]) + abs(a[1]-a[2]))
S = input()
a = int(S[0])
b = int(S[1])
c = int(S[2])
d = int(S[3])

if (a+b+c+d == 7):
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif (a+b+c-d == 7):
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif (a+b-c-d == 7):
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif (a-b-c-d == 7):
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif (a-b+c+d == 7):
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif (a-b-c+d == 7):
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif (a+b-c+d == 7):
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
S = input()
a = int(S[0])
b = int(S[1])
c = int(S[2])
d = int(S[3])

if (a+b+c+d == 7):
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif (a+b+c-d == 7):
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif (a+b-c-d == 7):
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif (a-b-c-d == 7):
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif (a-b+c+d == 7):
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif (a-b-c+d == 7):
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
S = input()
a = int(S[0])
b = int(S[1])
c = int(S[2])
d = int(S[3])

if (a+b+c+d == 7):
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif (a+b+c-d == 7):
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif (a+b-c-d == 7):
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif (a-b-c-d == 7):
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif (a-b+c+d == 7):
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif (a-b-c+d == 7):
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif (a+b-c+d == 7):
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
S = input()
a = int(S[0])
b = int(S[1])
c = int(S[2])
d = int(S[3])

if (a+b+c+d == 7):
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif (a+b+c-d == 7):
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif (a+b-c-d == 7):
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif (a-b-c-d == 7):
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif (a-b+c+d == 7):
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif (a-b-c+d == 7):
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif (a+b-c+d == 7):
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")

### FIXED CODE ###


S = input()
a = int(S[0])
b = int(S[1])
c = int(S[2])
d = int(S[3])

if (a+b+c+d == 7):
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif (a+b+c-d == 7):
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif (a+b-c-d == 7):
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif (a-b-c-d == 7):
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif (a-b+c+d == 7):
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif (a-b-c+d == 7):
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif (a+b-c+d == 7):
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif (a-b+c-d == 7):
  print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
a, b, x = list(map(int,input().split()))

import math

if 2*x < a*a*b:
    hatena = 2*x/a/b
    print(math.degrees(math.atan(hatena/b)))
else:
    hatena = 2*x/a/a - b
    print(90-math.degrees(math.atan(a/(b-hatena))))
    

### FIXED CODE ###

import math
a,b,x=list(map(int,input().split()))
maxv=a*a*b
sukima=maxv-x
teimenseki=sukima/a
y=teimenseki*2/a
 
if x > (maxv/2):
    print(math.degrees(math.atan(y/a)))
else:
    tei=x/a
    z=tei*2/b
    print(math.degrees(math.atan(b/z)))
s=input()
l=int(len(s))-2
print(s[0]+l+s[-1])

### FIXED CODE ###

s=list(input())
print(s[0]+str(len(s)-2)+s[-1])
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
i = 0
j = 0
k = 0
while i+j+k < min(3000,X*Y*Z):
  ans = A[i]+B[j]+C[k]
  deltaA = 10**16
  deltaB = 10**16
  deltaC = 10**16
  if i+j+k == min(3000,X*Y*Z)-1:
    break
  if i+1<X:
    deltaA=A[i]-A[i+1]
  if j+1<Y:
    deltaB=B[j]-B[j+1]
  if k+1<Z:
    deltaC=C[k]-C[k+1]
  L = 10**16
  index = -1
  w = [deltaA,deltaB,deltaC]
  for mm in range(3):
    if w[i] < L:
      L = w[mm]
      index = mm
  if index==0:
    i+=1
  elif index==1:
    j+=1
  else:
    k+=1
I=i+1
J=j+1
M=k+1
answers =[]
for i in range(I):
  for j in range(J):
    for k in range(M):
      answers.append(A[i]+B[j]+C[k])
answers.sort(reverse=True)
for i in range(min(3000,X*Y*Z)):
  print(answers[i])


### FIXED CODE ###

import heapq
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

i=j=k=0
HQ = []
heapq.heapify(HQ)
heapq.heappush(HQ,(-(A[i]+B[j]+C[k]),(i,j,k)))
alreadyAdded = set()
alreadyAdded.add((i,j,k))
for _ in range(K):
    valueNeg,index = heapq.heappop(HQ)
    print(-valueNeg)
    l,m,n = index
    nextIndex = []
    if l+1 < X:
        nextIndex.append((l+1,m,n))
    if m+1 < Y:
        nextIndex.append((l,m+1,n))
    if n+1 < Z:
        nextIndex.append((l,m,n+1))
    for l,m,n in nextIndex:
        if (l,m,n) not in alreadyAdded:
            heapq.heappush(HQ,(-(A[l]+B[m]+C[n]),(l,m,n)))
            alreadyAdded.add((l,m,n))
N,M = map(int,input().split)
print(((N * (N-1)) + (M *(M-1))/2)

### FIXED CODE ###

N, M = map(int,input().split())
a = int((N * (N-1) + M * (M-1)) / 2)
print(a)
import sys
input=sys.stdin.readline
n=int(input())
cnt=[]
for i in range(n):
	s=input().rstrip()
	l=s.count("(")
	r=s.count(")")
	minus=0
	now=0
	for j in range(len(s)):
		if s[j]=="(":
			now+=1
		else:
			now-=1
			minus=min(minus,now)
	cnt.append((l,r,s,minus))
cnt.sort(key=lambda x:x[1]-x[0])
plus=[]
minus=[]
for x in cnt:
	if x[0]-x[1]>=0:
		plus.append(x)
	else:
		minus.append(x)
plus.sort(key=lambda x:-x[3])
minus.sort(key=lambda x:-(x[0]-x[1])-x[3])
l=r=0
for x in plus:
	for i in range(len(x[2])):
		if x[2][i]=="(":
			l+=1
		else:
			r+=1
		if l<r:
			print("No")
			exit()
for x in minus:
	for i in range(len(x[2])):
		if x[2][i]=="(":
			l+=1
		else:
			r+=1
		if l<r:
			print("No")
			exit()
if l==r:
	print("Yes")
else:
	print("No")


### FIXED CODE ###

mod=998244353
n,m,k=map(int,input().split())
fac=[1]
for i in range(n):
	fac.append(fac[-1]*(i+1)%mod)
ans=0
for x in range(k+1):
	rev=pow(fac[x]*fac[n-1-x]%mod,mod-2,mod)
	r=fac[n-1]*rev%mod*m*pow(m-1,n-x-1,mod)%mod
	ans+=r
	ans%=mod
print(ans)
msg = map(str, raw_input().replace(",","").replace(".","").split())
for w in msg:
	print w, if 2 < len(w) <7 else ""

### FIXED CODE ###

msg = map(str, raw_input().replace(",","").replace(".","").split())
print " ".join(filter(lambda w:2<len(w)<7, msg))
import math
r = int(input())
print(math.pi*r*r, 2*math.pi*r)

### FIXED CODE ###

import math
r = float(input())
print(math.pi*r*r, 2*math.pi*r)
n = int(raw_input())
matrix = []
for i in range(n):
    line = raw_input()
    splited = line.split(" ")
    splited = map(lambda x: int(x), splited)
    matrix.append(splited)

result = 0
candidate = 0
selected = [0]
for i in range(n):
    weight = 2001
    for item in selected:
        for j in range(n):
            if matrix[j][item] != -1 and matrix[j][item] < weight and j not in selected:
                candidate = j
                weight = matrix[j][item]
    selected.append(candidate)
    if(len(selected) == n + 1):
        break
    result += weight
print result

### FIXED CODE ###

n = int(raw_input())
matrix = []
for i in range(n):
    line = raw_input()
    splited = line.split()
    splited = map(lambda x: int(x), splited)
    matrix.append(splited)

result = 0
candidate = 0
selected = [0]
for i in range(n):
    weight = 2001
    for item in selected:
        for j in range(n):
            if matrix[j][item] != -1 and matrix[j][item] < weight and j not in selected:
                candidate = j
                weight = matrix[j][item]
    selected.append(candidate)
    if(len(selected) == n + 1):
        break
    result += weight
print result
a = 0
c = 0
for i in range(int(input())):
	b = int(input())
	if b > a:
        a = b
        c += a
    else:
        c += b
c += (a/2)
print (round(c))


### FIXED CODE ###

a = 0
c = 0
for i in range(int(input())):
    b = int(input())
    if b > a:
        c += a
        a = b
    else:
        c += b
c += (a/2)
print (round(c))
a=input()
b=0

for i in a:
  if i==R:
    b+=1
    if b==2:
      print(b)
      import sys
      sys.exit()
    
  if i==S and b>0 :
    b-=1
    
print(b)

### FIXED CODE ###

a = input()
 
if("RRR" in a):
  print("3")
elif("RR" in a):
  print("2")
elif("R" in a):
  print("1")
else:
  print("0")
def doc_string():
    """
    I can fly.
    """
while True:
    h = int(raw_input) * 3600
    m = int(raw_input) * 60
    s = int(raw_input)
    time = 120 * 60 - (h + m + s)
    if h == -1 and m == -1 and s == -1:
        print "kill"

    h = str(time / 3600)
    m = str(time % 3600 / 60)
    s = str(time % 3600 % 60)
    if len(h) == 1:
        h = "0" + h
    if len(m) == 1:
        m = "0" + m
    if len(s) == 1:
        s = "0" + s
    print h + ":" + m + ":" + s

    h = str(time * 3 / 3600)
    m = str(time * 3 % 3600 / 60)
    s = str(time * 3 % 3600 % 60)
    if len(h) == 1:
        h = "0" + h
    if len(m) == 1:
        m = "0" + m
    if len(s) == 1:
        s = "0" + s
    print h + ":" + m + ":" + s

### FIXED CODE ###

def doc_string():
    """
    I can fly.
    """
while True:
    h,m,s = map(int,raw_input().split())
    if h == -1 and m == -1 and s == -1:
        break
    
    h = h * 3600
    m = m * 60
    time = 120 * 60 - (h + m + s)
    h = str(time / 3600)
    m = str(time % 3600 / 60)
    s = str(time % 3600 % 60)
    if len(h) == 1:
        h = "0" + h
    if len(m) == 1:
        m = "0" + m
    if len(s) == 1:
        s = "0" + s
    print h + ":" + m + ":" + s

    h = str(time * 3 / 3600)
    m = str(time * 3 % 3600 / 60)
    s = str(time * 3 % 3600 % 60)
    if len(h) == 1:
        h = "0" + h
    if len(m) == 1:
        m = "0" + m
    if len(s) == 1:
        s = "0" + s
    print h + ":" + m + ":" + s
import numpy as np

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

gcd = np.gcd(x,y)

size = int(np.sqrt(gcd)) + 1

def calc_div(num):
    table =  []
    for i in range(2,int(np.sqrt(num))+1):
        if num % i == 0:
            table.append(i)    
            while num % i == 0:
                num //= i
    table.append(num)
    return table 

ans = calc_div(gcd)

print(len(ans) + 1)

### FIXED CODE ###

import math
import fractions

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

gcd = fractions.gcd(x,y)

size = int(math.sqrt(gcd)) + 1

def calc_div(num):
    table =  []
    for i in range(2,int(math.sqrt(num))+1):
        if num % i == 0:
            table.append(i)    
            while num % i == 0:
                num //= i
    if num > int(math.sqrt(num)):
        table.append(num)
    return table 

ans = calc_div(gcd)

print(len(ans) + 1)
def main():
    import math
    import sys
    from copy import copy
    import numpy as np
    from collections import defaultdict, deque, Counter
    from itertools import accumulate, product, permutations,combinations, combinations_with_replacement
    from operator import itemgetter
    from bisect import bisect_left,bisect
    from heapq import heappop,heappush
    from fractions import gcd

    max_value = 1000000000
    min_value = -1000000000
    sys.setrecursionlimit(max_value)

    def input():
        return sys.stdin.readline()[:-1]

    n = int(input())
    s = list(input())

    count = 0


    if s[0] == 'W' or s[-1] == 'W':
        print(0)
        sys.exit()

    LR_list = ['' for i in range(2*n)]
    LR_list[0] = 'L'

    for i in range(1,len(LR_list)):
        if s[i] == s[i-1]:
            if LR_list[i-1] == 'R':
                LR_list[i] = 'L'
            else:
                LR_list[i] = 'R'
        else:
            if LR_list[i-1] == 'R':
                LR_list[i] = 'R'
            else:
                LR_list[i] = 'L'

    values = []

    if LR_list.count('L') != LR_list.count('R'):
        print(0)
        sys.exit()


    li = 0
    ri = 0
    for i in range(len(LR_list)):
        if i != 0:
            if LR_list[i-1] == 'L':
                li += 1
            elif LR_list[i-1] == 'R':
                ri += 1
        if LR_list[i] == 'R':
            values.append(li-ri)
    value = 1
    for i in range(len(values)):
        value = value * values[i] % (10**9+7)
    for i in range(2,n+1):
        value = value * i %(10**9+7)
    print(value)


if __name__=='__main__':
    main()

### FIXED CODE ###

import math
n = int(input())
S = input()
 
RL = [None]*2*n
 
for i in range(2*n):
    if i % 2 == 0:
        if S[i] == 'B':
            RL[i] = 'L'
        else:
            RL[i] = 'R'
 
    else:
        if S[i] == 'B':
            RL[i] = 'R'
        else:
            RL[i] = 'L'
 
if S[0] == 'W' or S[-1] == 'W':
    print(0)
    exit()
 
left = 0
count = 1
mod = 10**9 + 7
 
for check in RL:
    if check == 'L':
        left += 1
    else:
        count = count * left % mod
        left -= 1
 
    if left < 0:
        print(0)
        exit()
 
count = count * math.factorial(n) % mod
 
if left != 0:
    print(0)
else:
    print(count)
M = 998244353

n = int(input())
d = list(map(int, input().split()))
idx = [0]*n
ans = 1
for i in range(n):
    idx[d[i]] += 1

if not idx[0] == 1:
    print(0)
else:
    if n == 1:
        print(1)
        break
    for i in range(1,n):
        if idx[i-1] == 0:
            if not idx[i] == 0:
                print(0)
                break
        else:
            ans *= (idx[i-1]**idx[i]%M)
    else:
        print(ans%M)


### FIXED CODE ###

import sys
M = 998244353

n = int(input())
d = list(map(int, input().split()))
idx = [0]*n
ans = 1
for i in range(n):
    idx[d[i]] += 1

if not d[0] == 0 or not idx[0] == 1:
    print(0)
else:
    for i in range(1,n):
        if idx[i-1] == 0:
            if not idx[i] == 0:
                print(0)
                sys.exit()
        else:
            ans *= idx[i-1]**idx[i]%M
    else:
        print(ans%M)
import math
from typing import List, NoReturn, Tuple


def main() -> NoReturn:
    n: int = int(input())
    # 0.9615384615384616 == 25 / 26
    group: int = math.ceil(math.log(0.9615384615384616 * n + 1, 26))
    in_group_index: int = n - (26 * (26 ** (group - 1) - 1)) // 25

    alphabet_num: List[int] = []
    alphabet: str = "abcdefghijklmnopqrstuvwxyz"
    temp = in_group_index
    for i in range(group - 1, -1, -1):
        alphabet_num.append(temp // 26 ** i)
        temp %= 26 ** i
    else:
        alphabet_num[-1] -= 1
    name_chars: List[str] = [alphabet[i] for i in alphabet_num]
    print("".join(name_chars))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import math
from typing import List, NoReturn, Tuple


def main() -> NoReturn:
    n: int = int(input())
    # 0.9615384615384616 == 25 / 26
    group: int = math.ceil(math.log(0.9615384615384616 * n + 1, 26))
    in_group_index: int = n - 1 - (26 * (26 ** (group - 1) - 1)) // 25

    alphabet_num: List[int] = []
    alphabet: str = "abcdefghijklmnopqrstuvwxyz"
    temp = in_group_index
    for i in range(group - 1, -1, -1):
        alphabet_num.append(temp // 26 ** i)
        temp %= 26 ** i
    name_chars: List[str] = [alphabet[i] for i in alphabet_num]
    print("".join(name_chars))


if __name__ == '__main__':
    main()
n , k = map(int, input().split())
s = list(input())
for i in range(n):
  if i == k:
  	s[i] = s[i].lower
print("".join(s))

### FIXED CODE ###

n , k = map(int, input().split())
s = list(input())
for i in range(n):
  if i == (k - 1):
  	s[i] = s[i].lower()
print("".join(s))
n,m=map(int,input().split())
ac=[]
wt=[]
pen=0
for i in range(m):
    p,s=input().split()
    if s=="AC":
        ac.append(p)
        pen += wt[p]
    else:
        if p in ac:
            pass
        else:
            wt[p] += 1
            
t_ac=set(ac)
print(len(t_ac),pen)


### FIXED CODE ###

n,m=map(int,input().split())
AC=[0 for _ in range(n)]
WA=[0 for _ in range(n)]
pen=0
for _ in range(m):
    p,s=input().split()
    p=int(p)
    if s=="AC":
        if AC[p-1]==0:
            AC[p-1]=1
            pen += WA[p-1]
        else:
            pass
    else:
        if AC[p-1]==0:
            WA[p-1] +=1
        else:
            pass
print(AC.count(1),pen)
from math import gcd

def solve(): 
  N = int(input().strip())
  o = 0
  for i in map(int, input().split()):
    o = gcd(o,i)
  print(o)

if __name__=="__main__":
  solve()


### FIXED CODE ###

def solve():
  def gcd(x, y):
   while(y): 
       x, y = y, x % y 
   return x

  N = int(input().strip())
  o = 0
  for i in map(int, input().split()):
    o = gcd(i,o)
  print(o)

if __name__=="__main__":
  solve()
import sys

def main():

	N = int(input())
	
	d = {}
	for i in range(N):
		A = int(input())
		d[A] = 0
	print(len(d))
	
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys

def main():

	N = int(input())
	
	d = {}
	for i in range(N):
		A = input()
		d[A] = 0
	print(len(d))
	
if __name__ == "__main__":
    main()
n = int(input())
x = list(map(int,input().split()))
lst = [0]*(max(x)-min(x)+1)
for i in range(n):
    for j in range(max(x)-min(x)+1):
        lst[j-x[0]] += (x[i]-j)**2
print(min(lst))

### FIXED CODE ###

n = int(input())
x = list(map(int,input().split()))
lst = [0]*(max(x)-min(x)+1)
for j in range(min(x),max(x)+1):
    for i in range(n):
        lst[j-x[0]] += (x[i]-j)**2
print(min(lst))
x, y =map(int,input().split())
 
print("Alice") if abs(x - y) >= 2 else print("Brown")

### FIXED CODE ###

a,b,c=input().split()
g=[a[0].upper(),b[0].upper(),c[0].upper()]
print("".join(g))
N = int(input())
hina = input().split()
flag = "syurui_3"
for i in hina:
  if i == "Y":
    flag = "syurui_4"
if flag == "syurui_3":
  print("Three")
else:
  print("Four")


### FIXED CODE ###

a = int(input())
print(a//3)
def solve():
    from collections import deque
    from sys import stdin
    f_i = stdin
    
    N, M = map(int, f_i.readline().split())
    S = f_i.readline().rstrip()
    
    M *= -1
    pos = N
    rec = deque()
    while pos:
        for move in range(M, 0):
            next_pos = pos + move
            if S[next_pos] == '0' and next_pos >= 0:
                pos = next_pos
                rec.appendleft(move)
                break
        else:
            print(-1)
            break
    else:
        print(' '.join(str(-move) for move in rec))

solve()

### FIXED CODE ###

def solve():
    from collections import deque
    from sys import stdin
    f_i = stdin
    
    N, M = map(int, f_i.readline().split())
    S = f_i.readline().rstrip()
    
    M *= -1
    pos = N
    rec = deque()
    while pos:
        for move in range(M, 0):
            next_pos = pos + move
            if next_pos >= 0 and S[next_pos] == '0':
                pos = next_pos
                rec.appendleft(move)
                break
        else:
            print(-1)
            break
    else:
        print(' '.join(str(-move) for move in rec))

solve()
n=int(input())
d=list(map(int,input().split())
hp=0
for i in range(n):
       for j in range(i+1,n):
            hp+=d[i]*d[j]
print(hp)

### FIXED CODE ###

n=int(input())
d=list(map(int,input().split()))
hp=0
for i in range(n-1):
       for j in range(i+1,n):
            hp=hp+d[i]*d[j]
print(hp)
n=input()
cnt=0
for i in range(3):
    if n[i]=n[i+1]:
        cnt+=1
if cnt>=3:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

n=input()
if n[0]==n[1]==n[2] or n[1]==n[2]==n[3]:
    print("Yes")
else:
    print("No")
import math as m
a,b=map(float,input().split())
print(m.floor((a*(b*m))//m))


### FIXED CODE ###

from math import floor as f
a,b=input().split()
b=int(str(b).replace(".",""))
print(int(a)*b//100)
while 1:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    *S, = map(int, input().split())
    *D, = map(int, input().split())

    from itertools import permutations
    ans = 10**18
    for P in permutations(S):
        Q = [0]*(n+1)
        for i, e in enumerate(P):
            Q[i+1] = P[i] + Q[i]
        ans = min(ans, sum(min(abs(d - q) for q in Q) for d in D))
    print(ans)

### FIXED CODE ###

from collections import deque
while 1:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    *S, = map(int, input().split())
    D = sorted(map(int, input().split()))

    SA = sum(S)
    rest = sum(d-SA for d in D if SA <= d)

    memo = {2**n-1: rest}
    def dfs(state, su, idx):
        if state in memo:
            return memo[state]
        res = 10**18
        for i in range(n):
            if (state >> i) & 1 == 0:
                s = 0; j = idx
                nxt = su + S[i]
                while j < m and D[j] <= nxt:
                    s += min(nxt - D[j], D[j] - su); j += 1
                res = min(res, s + dfs(state | (1 << i), su + S[i], j))
        memo[state] = res
        return res
    print(dfs(0, 0, 0))
N = int(input())
P, Q = [], [0]*(N+1)
for i in range(1,N+1):
    p = int(input())
    P.append(p)
    Q[p] = i
cnt = 1
res = []
for i in range(1,N):
    if Q[i] < Q[i+1]:
        cnt += 1
    else:
        res.append(cnt)
        cnt = 1
print(N-max(res))

### FIXED CODE ###

N = int(input())
P, Q = [], [0]*(N+1)
for i in range(1,N+1):
    p = int(input())
    P.append(p)
    Q[p] = i
Q.append(0)
cnt = 1
res = []
for i in range(1,N+1):
    if Q[i] < Q[i+1]:
        cnt += 1
    else:
        res.append(cnt)
        cnt = 1
if res:
    print(N-max(res))
else:
    print(N)
N=int(input())
a=[int(i) for i in input().split()]
k=sum(a)//(N*(N-1)//2)
D=[]
a.append(a[0])
for i in range(N):
  D.append(a[i+1]-a[i]-k)

for d in D:
  if d%N!=0:
    print("NO")
    exit()
print("YES")
    
  


### FIXED CODE ###

N=int(input())
a=[int(i) for i in input().split()]
S=sum(a)
if S%(N*(N+1)//2)==0:
  k=S//(N*(N+1)//2)
else:
  print("NO")
  exit()
D=[]
a.append(a[0])
for i in range(N):
  D.append(a[i+1]-a[i]-k)

for d in D:
  if d>0 or d%N!=0:
    print("NO")
    exit()
    
print("YES")