Harryxun/stf_run huggingface dataset:
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

N,M = nm()
digits = [-1] * N
# print(N,M)
for i in range(M):
    s,c = nm()
    # print(s,c)
    ii = s -1 
    # print("A",ii,c)
    if digits[ii] == -1:
        digits[ii] = c
    elif digits[ii] != c:
        print(-1)
        exit(0)

# print(digits)
if N == 1:
    if digits[0] == -1:
        print(0)
    else:
        print(digits[0])
    exit(0)

if digits[0] == -1:
    digits[0] = 1
elif digits[0] == 0:
    print(-1)
    exit(0)

for i in range(1,M):
    if digits[i] == -1:
        digits[i] = 0

xx = "".join(list(map(str,digits)))
print(xx)


### FIXED CODE ###

def solve(n, m):
    ans = [-1] * n
    for _ in range(m):
        s, c = input().split()
        s = int(s) - 1
        if ans[s] == c:
            continue
        elif ans[s] == -1:
            ans[s] = c
        else:
            return -1

    if ans[0] == '0':
        if n == 1:
            return '0'
        else:
            return -1
    elif ans[0] == -1:
        if n == 1:
            return '0'
        else:
            ans[0] = '1'
    for i in range(1, n):
        if ans[i] == -1:
            ans[i] = '0'
    return ''.join(ans)


n, m = list(map(int, input().split()))
print(solve(n, m))
N, X, Y = map(int, input().split())

from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall

edge = [[-1] * N for _ in range(N)]
for i in range(N - 1):
    edge[i][i + 1] = 1
    edge[i + 1][i] = 1
edge[X - 1][Y - 1] = 1
edge[Y - 1][X - 1] = 1

# 隣接行列
G = csgraph_from_dense(edge, null_value=-1)
# 下準備 重みがnull_valueの辺は存在しないとうこと
# 別に隣接行列のままでいい,今回は存在しない辺があるため

d = floyd_warshall(G, directed=True)
# directed初期値True 逆走もできるか

# print(d)

ans = [0] * (N)

for i in range(N):
    for j in range(i, N):
        ans[int(d[i][j])] += 1

[print(i) for i in ans[1:]]


### FIXED CODE ###

N, X, Y = map(int, input().split())

ans = [0] * (N)

for i in range(1, N):
    for j in range(i + 1, N + 1):
        d = min(j - i, abs(X - i) + abs(j - Y) + 1)
        ans[d] += 1

for a in ans[1:]:
    print(a)
X,Y,A,B,C=map(int,input().split())
p=sorted(map(int,input().split()))
q=sorted(map(int,input().split()))
r=sorted(map(int,input().split()))
ans=[]
ans+=p[A-X:]
ans+=q[B-Y:]
i=0
j=0
while True:
	i=max(r)
	j=min(ans)
	if i>j:
		ans.remove(j)
		ans.append(i)
		r.remove(i)
	else:
		break
print(sum(ans))


### FIXED CODE ###

X,Y,A,B,C=map(int,input().split())
p=sorted(map(int,input().split()))
q=sorted(map(int,input().split()))
r=sorted(map(int,input().split()))
ans=[]
ans+=p[A-X:]
ans+=q[B-Y:]
ans.sort()
j=0
k=0
for i in ans:
	if len(r)>1:
		k=r[-1]
	elif len(r)==1:
		k=r[0]
	else:
		break
	if i<k:
		ans[j]=r.pop()
		j+=1
	else:
		break
print(sum(ans))
n = int(input())
ls = list(map(int, input().split()))

c = 0
for i in range(1, n-1):
  if ls[i] > ls[i-1] and ls[i] < ls[i+1]:
    c += 1
  elif  ls[i] < ls[i-1] and ls[i] > ls[i+1]:
    c += 1
    
print(c)

### FIXED CODE ###

ls = list(input())
if ls[0] == ls[1] and ls[2] == ls[3] and ls[0] != ls[2]:
  print('Yes')
elif ls[0] == ls[2] and ls[1] == ls[3] and ls[0] != ls[1]:
  print('Yes')
elif ls[0] == ls[3] and ls[1] == ls[2] and ls[0] != ls[1]:
  print('Yes')
else:
  print('No')
n = input()
h = [int(i) for i in input().sprit()]

max = 0
i = 0
y = 1
for i in range(n):
    if h[i] > max:
        max = h[i]
    else if h[i] < max-1:
        y = 0
        break
    
if y:
    print("yes")
else:
    print("no")


### FIXED CODE ###

n = input()
h = [int(i) for i in input().split()]

max = 0
i = 0
y = 1
for i in range(int(n)):
    if h[i] > max:
        max = h[i]
    elif h[i] < max-1:
        y = 0
    
if y==1:
    print("Yes")
else:
    print("No")
n = int(input())

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

for i in range(n):
    for j in range(n):
        if i == j:
            break
        else:
            s += d[i] * d[j]

print(s)

### FIXED CODE ###

n = int(input())

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

s = int(0)

for i in range(n):
    for j in range(i,n):
        if i == j:
            continue
        else:
            s += d[i] * d[j]

print(s)
x = int(input())

for i in range(10**9):
  a1= (x + i**5)**0.2
  a2 = (x + (-i)**5)**0.2
  
  if a1.is_integer():
    print(int(a1),i)
    exit()
  if a2.is_integer():
    print(int(a2),-i)
    exit()

### FIXED CODE ###

x = int(input())
a = [i for i in range(120)] + [-i for i in range(1,119)]
b = [i for i in range(119)] + [-i for i in range(1,120)]

for i in a:
  for j in b:
    if i**5 - j**5 == x:
      print(i,j)
      exit()
A,B,C=map(int(),input().split())
print(A*B/2)

### FIXED CODE ###

a,b,c=map(int,input().split())
print(a*b//2)
from functools import reduce
import math

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

lcm = reduce(lambda x, y: (x * y) // math.gcd(x, y), A)

score = 0
for a in A:
    score += (lcm - 1) % a

print(score)

### FIXED CODE ###

from functools import reduce

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

lcm = reduce(lambda x, y: (x * y) // gcd(x, y), A)

score = 0
for a in A:
    score += (lcm - 1) % a

print(score)
n, m, k = map(int, input().split())
if n <= k+1:
    print(m**n)
else:
    a = [m*((m-1)**(n-1))]
    b = [1]
    c = 0
    for i in range(k):
        b.append(int(b[-1]/(i+1)*(n-i-1)))
    for i in range(k):
        a.append(int((a[-1]*b[i+1])/b[i]/(m-1)))
    for i in range(k+1):
        c += a[i]
    print(c%998244353)

### FIXED CODE ###

n, m, k = map(int, input().split())
z = 998244353
if n <= k+1:
    a = 1
    for i in range(n):
        a = a*m%z
    print(a)
else:
    a = []
    b = []
    d = [1, 1]
    e = [1, 1]
    f = [0, 1]
    for i in range(2, n):
        d.append(d[-1]*i%z)
        f.append((-f[z%i]*(z//i))%z)
        e.append(e[-1]*f[-1]%z)
    for i in range(k+1):
        b.append(d[n-1]*e[i]*e[n-i-1]%z)
    x = 0
    g = [1]
    for i in range(n-1):
        g.append(g[i]*(m-1)%z)
    for i in range(k+1):
        a.append(b[i]*m*g[n-i-1]%z)
    for i in range(k+1):
        x = (x+a[i])%z
    print(x)
N, K = map(int, input().split())
As = [0] + list(map(int, input().split()))
from itertools import accumulate
As = list(accumulate(As))
M = len(As)
d = []
j = 0
r = 0
for i in range(M):
    a = As[i]
    while True:
        if j == M:
            break
        if a + K <= As[j]:
            break
        j += 1
    r += M - j
print(r)


### FIXED CODE ###

N, = map(int, input().split())
import sys
sys.setrecursionlimit(10**6)
d = [set() for _ in range(N+1)]
Cs = [0 for _ in range(N+1)]
for _ in range(N-1):
    u, v, p = map(int, input().split())
    d[u].add((v, p))
    d[v].add((u, p))

def it(v, p):
    for u, c in d[v]:
        if u == p:
            continue
        Cs[u] = int(not Cs[v]) if c%2 else Cs[v]
        it(u, v)
it(1, None)
for i in range(1, N+1):
    print(Cs[i])
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [str(input().rstrip('\n')) for _ in range(h)]
    a = [[[0] * 4 for _ in range(w)] for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                a[i][j][0] = 0
            else:
                if i == 0:
                    a[i][j][0] = 1
                else:
                    a[i][j][0] = a[i - 1][j][0] + 1

            if s[-i-1][j] == "#":
                a[-i-1][j][1] = 0
            else:
                if i == 0:
                    a[-i-1][j][1] = 1
                else:
                    a[-i-1][j][1] = a[-i][j][1] + 1

            if s[i][j] == "#":
                a[i][j][2] = 0
            else:
                if j == 0:
                    a[i][j][2] = 1
                else:
                    a[i][j][2] = a[i][j-1][2] + 1

            if s[i][-j-1] == "#":
                a[i][-j-1][3] = 0
            else:
                if j == 0:
                    a[i][-j-1][3] = 1
                else:
                    a[i][-j-1][
            mn = max(mn, sum(a[i][j]) - 3)
    print(mn)


if __name__ == '__main__':
    slove()


### FIXED CODE ###

def slove():
    import sys
    input = sys.stdin.readline
    h, w = map(int, input().split())
    lst = []
    for i in range(h):
        lst.append(list(input()))

    R = [[0] * w for _ in range(h)]
    L = [[0] * w for _ in range(h)]
    U = [[0] * w for _ in range(h)]
    D = [[0] * w for _ in range(h)]

    for i in range(h):
        for j in range(w):
            if lst[i][j] == '.':
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j - 1] + 1

    for i in range(h):
        for j in range(w - 1, -1, -1):
            if lst[i][j] == '.':
                if j == w - 1:
                    R[i][j] = 1
                else:
                    R[i][j] = R[i][j + 1] + 1

    for i in range(h):
        for j in range(w):
            if lst[i][j] == '.':
                if i == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i - 1][j] + 1

    for i in range(h - 1, -1, -1):
        for j in range(w):
            if lst[i][j] == '.':
                if i == h - 1:
                    D[i][j] = 1
                else:
                    D[i][j] = D[i + 1][j] + 1

    ans = 0
    x = [[0] * w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            x[i][j] = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
        ans = max(ans, max(x[i]))
    print(ans)


if __name__ == '__main__':
    slove()
N = int(input())
P = map(int, input().split())

ret = 0
currmin = P[0]
for i in range(N):
    if P[i] <= currmin:
        currmin = P[i]
        ret += 1

print(ret)


### FIXED CODE ###

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

ret = 0
currmin = P[0]
for i in range(N):
    if P[i] <= currmin:
        currmin = P[i]
        ret += 1

print(ret)
n,u,v=map(int, input().split())
ab=[list(map(int, input().split())) for _ in range(n-1)]
graph = [[] for _ in range(n+1)]
for vs in ab:
    graph[vs[0]].append(vs[1])
    graph[vs[1]].append(vs[0])

depth=[[-1,-1] for _ in range(n+1)]
depth[v][0]=0
depth[v][1]=0

def dfs1(graph,v):
    vv=graph[v]
    for vvv in vv:
        if depth[vvv][0]==-1:
            depth[vvv][0]=depth[v][0]+1
            dfs1(graph,vvv)

def dfs2(graph,v):
    vv=graph[v]
    for vvv in vv:
        if depth[vvv][1]==-1:
            depth[vvv][1]=depth[v][1]+1
            dfs2(graph,vvv)

dfs1(graph,v)
dfs2(graph,u)
depth=sorted(depth,reverse=True)

for i in range(10**5):
    if depth[i][0]-depth[i][1]>=1:
        print(depth[i][0]-1)
        break


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
 
N,u,v = map(int,input().split())
edges = [list(map(int,input().split())) for _ in range(N-1)]
E = [[] for _ in range(N+1)]
for a,b in edges:
    E[a].append(b)
    E[b].append(a)
 
depth = [[-1,-1] for _ in range(N+1)] 
depth[v][0] = 0
depth[u][1] = 0

def dfs1(E,v):
    vv = E[v]
    for vvv in vv:
        if depth[vvv][0] == -1:
            depth[vvv][0] = depth[v][0] + 1
            dfs1(E,vvv)
 
def dfs2(E,v):
    vv = E[v]
    for vvv in vv:
        if depth[vvv][1] == -1:
            depth[vvv][1] = depth[v][1] + 1
            dfs2(E,vvv)
dfs1(E,v)
dfs2(E,u)
depth = sorted(depth, reverse=True)
idx = 0
while True:
    if depth[idx][0] - depth[idx][1] >= 1:
        print(depth[idx][0]-1)
        exit()
    else:
        idx += 1
print(l)
indexes=[[] for _ in range(2**(n-1))]
for k in range(2**(n-1)):
    indexes[k]=[i for i, x in enumerate(l[k]) if x == 1]
#print(indexes)
SUM=0
for j in range(2**(n-1)):
    L=len(indexes[j])
    if L==0:
        SUM+=int(s)
        #print(SUM)
    else:
        SUM+=int(s[:indexes[j][0]+1])
        #print(SUM)
        SUM+=int(s[indexes[j][L-1]+1:])
        #print(SUM)
        if L>1:
            for h in range(L-1):
                SUM+=int(s[indexes[j][h]+1:indexes[j][h+1]+1])
                #print(SUM)
print(SUM)

### FIXED CODE ###

s=input()
n=len(s)
l=[[] for _ in range(2**(n-1))]
for b in range(2**(n-1)):
    x=b
    for i in range(n-1):
        if x%2==1:
            l[b].append(1)
        else:
            l[b].append(0)
        x//=2
#print(l)
indexes=[[] for _ in range(2**(n-1))]
for k in range(2**(n-1)):
    indexes[k]=[i for i, x in enumerate(l[k]) if x == 1]
#print(indexes)
SUM=0
for j in range(2**(n-1)):
    L=len(indexes[j])
    if L==0:
        SUM+=int(s)
        #print(SUM)
    else:
        SUM+=int(s[:indexes[j][0]+1])
        #print(SUM)
        SUM+=int(s[indexes[j][L-1]+1:])
        #print(SUM)
        if L>1:
            for h in range(L-1):
                SUM+=int(s[indexes[j][h]+1:indexes[j][h+1]+1])
                #print(SUM)
print(SUM)
n,m,q = map(int,input().split())
import numpy as np
LR = np.full((500,500),0)
Ans = []
for _ in range(m):
    x,y = map(int,input().split())
    LR[x][y] += 1

def portionsum(List,x,y):#List must be 2-demension,x>y
    re = 0
    for l in range(x,y+1):
        re += sum(List[l][x:y+1])
    return re

for i in range(q):
    p,q = map(int,input().split())
    Ans.append(portionsum(LR,p,q))
for _ in Ans:
    print(_)

### FIXED CODE ###

n,m,qq = map(int,input().split())
PQ = []
LR = [[_+1,0]+list(map(int,input().split())) for _ in range(m)]

for i in range(qq):
    p,q = map(int,input().split())
    PQ.append([i+1,1,p,q+0.1])
record = [0]*(n+1)
Ans = []

All = LR+PQ
from operator import itemgetter
All.sort(key = itemgetter(3))

for num,flag ,l, r in All:
    if flag :
        Ans.append([num,sum(record[l:int(r+1)])])
    else:
        record[l] += 1
Ans.sort(key = itemgetter(0))
for ans in Ans:
    print(ans[1])
s = input()
if s[0]!="A":
  print("WA")
  exit()
else:
  s.pop(0)
  
count =0
for i in range(1,-2):
  if s[i] == "C":
    s.pop(i)
    count+=1    
if count !=1:
  print("WA")
  exit()
  
if s.islower():
  print("AC")
else:
  print("WA")

### FIXED CODE ###

s = list(input())
flg = "WA"
if s[0]=="A":
  if "C" in s[2:len(s)-1]:
    s.remove("A")
    s.remove("C")
    s = ''.join(s)
    if s.islower()==True:
      flg = "AC"
print(flg)
def resolve():
    MOD = 998244353
    N = int(input())
    D = list(map(int, input().split()))

    if D[0] != 0:
        print(0)
        return

    CNT = Counter(D)
    if CNT[0] > 1:  # 距離0は1個
        print(0)
        return

    ans = 1
    for i in range(1, max(D) + 1):
        ans *= pow(CNT[i - 1], CNT[i], MOD)
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

from collections import Counter

N = int(input())
D = list(map(int, input().split()))
MOD = 998244353

# 条件をみたす木が存在するには D1 = 0 が必要
if D[0] != 0:
  print(0)
  exit()
# 0 == 1
ctr = Counter(D)
if ctr[0] != 1:
  print(0)
  exit()
  
ans = 1
for i in range(len(ctr)-1):
  ans *= pow(ctr[i], ctr[i+1], MOD)
  ans %= MOD
print(ans)
n, k = map(int,input().split())
a_list = list(map(int,input().split()))
a_list.sort()
 
import math
 
def cmb(n,r):
    o = math.factorial(n)
    u = math.factorial(r)*math.factorial(n-r)
    return o/u
 
max_val = 0
min_val = 0
val = cmb(n-1, k-1)
for i in range(n-k+1):
    if i != 0:
        val = val*(n-i-k+1)//(n-i)
    max_val = (max_val + (((a_list[-(i+1)])*val)))%(10**9+7)
    min_val = (min_val + ((a_list[i])*val))%(10**9+7)
 
 
print(int((max_val-min_val)%(10**9+7)))

### FIXED CODE ###

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


mod = 10 ** 9 + 7
f_list = [1]
for i in range(1,n+1):
    f_list.append((f_list[-1] * i) % mod)
def comb(n,r):
    return f_list[n] * (pow(f_list[r], mod-2, mod) * pow(f_list[n-r], mod-2, mod) % mod) % mod


max_val = 0
min_val = 0
for i in range(n - k + 1):
    val = comb(n - i - 1, k - 1)
    max_val = (max_val + (((a_list[-(i + 1)]) * val))) % (10 ** 9 + 7)
    min_val = (min_val + ((a_list[i]) * val)) % (10 ** 9 + 7)

print(int((max_val - min_val) % (10 ** 9 + 7)))
n=int(input())
h=list(map(int,input().split()))
ans=0
answer=[]
for i in range(n-1):
  if h[i]>=h[i+1]:
    ans+=1
  if h[i]<h[i+1]:
    answer.append(ans)
    ans=0
  if i == n-2:
    answer.append(ans)
  else:
    pass
print(max(answer))


### FIXED CODE ###

s=input()
t=input()
ans=0
for i in range(3):
  if s[i]==t[i]:
    ans+=1
print(ans)
import sys
from collections import deque

s = deque([s for s in input()])
q = int(input())
rev = False

for query in sys.stdin:
    if query.strip() == '1': # sys.stdin does not remove line breaks. (vs. input() removes line breaks)
        if rev:
            rev = False
        else:
            rev = True
    else:
        t,f,c = query.split()
        if f == '1':
            if rev == True:
                s.append(s)
            else:
                s.appendleft(c)
        elif f == '2':
            if rev == True:
                s.appendleft(c)
            else:
                s.append(c)
if rev == True:
    s = s[::-1]
print(''.join(s))

### FIXED CODE ###

import sys
from collections import deque

# sys.stdin = open('test_cases/abc158d/in/01.txt', 'r')
# sys.stdin = open('input.txt', 'r')

s = deque([s for s in input()])
q = int(input())
rev = False

for query in sys.stdin:
    if query.strip() == '1': # sys.stdin does not remove line breaks. (vs. input() removes line breaks)
        if rev:
            rev = False
        else:
            rev = True
    else:
        t,f,c = query.split()
        if f == '1':
            if rev:
                s.append(c)
            else:
                s.appendleft(c)
        elif f == '2':
            if rev:
                s.appendleft(c)
            else:
                s.append(c)
if rev == True:
    s.reverse()
print(''.join(s))
print(int(input())*int(input()))

### FIXED CODE ###

A, B = map(int,input().split())
print(A*B)
h = list(input() for i in range(3))
a, b, c = h[0], h[1], h[2]

#nは文字列
n = a
#neはnextで、1文字
ne = 'a'
while True:
    if n == a:
        ne = a[0]
        a[1:]
        if not a:
            print('A')
            break
    elif n == b:
        ne = b[0]
        b[1:]
        if not b:
            print('B')
            break

    else n == c:
        ne = c[0]
        c[1:]
        if not c:
            print('C')
            break

    if ne == 'a':
        n == a
    if ne == 'b':
        n == b
    if ne == 'c':
        n == c

### FIXED CODE ###

h = list(input() for i in range(3))
hand = {'a':h[0], 'b':h[1], 'c':h[2]}   # 各手札
count = {'a':0, 'b':0, 'c':0}   # 捨てた枚数

def who_is_the_winner(ch):
    if ch == 'a':
        winner = 'A'
    elif ch == 'b':
        winner = 'B'
    else:
        winner = 'C'
    return winner

ch = 'a'
while True:
    count[ch] += 1
    if count[ch] == len(hand[ch])+1:
        winner = who_is_the_winner(ch)
        print(winner)
        break
    ch = hand[ch][count[ch]-1]
a,b=map(int,input().split())
l=[]
if a<b:
  for i in range(a):
    l.append(b)
    L=''.join(l)
	print(L)
else:
   for i in range(b):
    l.append(a)
    L=''.join(l)
	print(L)
  

### FIXED CODE ###

a,b=map(int,input().split())
if a<b:
  print(str(a)*b)
else:
  print(str(b)*a)
from sys import stdin
import numpy as np

def bit_search(a, n, m, x):
    res = []
    for i in range(2 ** n):
        price = 0
        skill = np.zeros((n, m))
        for j in range(n):
            if (i >> j) & 1:
                price += a[j][0]
                skill[j] = a[j][1:]
        skill_sum = np.sum(skill, axis=0)\
                        if skill.shape[0] > 1 else np_skill
        if (skill_sum >= x).all(): res.append(price)
    return res

def main():
    readline = stdin.readline
    n, m, x = map(int, readline().split())
    a = [list(map(int, readline().split())) for _ in range(n)]
    res = bit_search(a, n, m, x)
    return print('-1' if not res else min(res))

if __name__ == '__main__':
    main()


### FIXED CODE ###

from sys import stdin
import numpy as np

def main():
    readline = stdin.readline
    n, m, x = map(int, readline().split())
    a = [list(map(int, readline().split())) for _ in range(n)]
    res = []
    for i in range(2 ** n):
        price = 0
        skill = []

        for j in range(n):
            if ((i >> j) & 1):
                price += a[j][0]
                skill.append(a[j][1:])
        np_skill = np.array(skill)
        skill_sum = np.sum(np_skill, axis=0)\
                        if np_skill.shape[0] > 1 else np_skill

        if skill_sum.size != 0 and (skill_sum >= x).all():
            res.append(price)

    if not res: return print('-1')

    return print(min(res))

if __name__ == '__main__':
    main()
# coding: utf-8
# Your code here!
import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

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

root=[i for i in range(N)]

ketsu=[[]*(N) for i in range(N)]
point=[0]*N
ans=[0]*N

def dfs(num,value):
    ans[num]+=value
    for item in ketsu[num]:
        dfs(item,value+point[item])
            

for _ in range(N-1):
    a,b=map(int,input().split())
    ketsu[a-1].append(b-1)
    #ketsu[b-1].append(a-1)
    root.remove(b-1)
    
for _ in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
#print(point)

for item in root:
    dfs(item,point[item])
    
print(*ans)

### FIXED CODE ###

# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


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

tree=[[]*(N+1) for i in range(N+1)]
point=[0]*(N+1)

for _ in range(N-1):
    a,b=map(int,input().split())
    tree[a].append(b)
    tree[b].append(a)
    
for _ in range(Q):
    p,x=map(int,input().split())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])
n = input().rsplit()
points = [int(i) for i in n]
distances = []
for i in range(len(points)-2):
   dist = points[-2] - points[i]
   distances.append(dist)

if max(distances) > points[-1]:
    print(':(')
else:
    print('Yay!')

### FIXED CODE ###

a, b, c, d, e, k = [int(input()) for i in range(6)]
if e-a > k:
    print(':(')
else:
    print('Yay!')
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if len(s) <= j:
        break
    if s[j] == s[j - 1]:
        if j == 0:
            n += 1
            if len(s) == 2:
                k += 1
            elif s[j - 1] == s[j - 2]:
                n -= 1
            j += 1
        else:
            if len(s) > 2:
                m += 1
                j += 1
    j += 1
print(m * k + n * (k - 1))


### FIXED CODE ###

s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0] == s[-1] == s[-2]== s[-3]== s[-4]== s[-5]== s[len(s)//3] \
                and s[0] == s[1] == s[2]== s[3]== s[4]== s[5]:
            n+=1
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n*(k-1))
n=int(input())
l=list(map(int,input().split()))
ans=0
maxt=0
for i in l:
  if i<maxt:
    ans+=maxt-1
    maxt=max(i,maxt)
print(ans)


### FIXED CODE ###

N,X,T=map(int,input().split())
if N%X==0:
  s=N//X
  print(s*T)
else:
  s=N//X+1
  print(s*T)