Harryxun/stf_run huggingface dataset:
N, M, L = map(int,input().split(' '))
Ms=[]
inf = 10**11
for i in range(N+1):
    #for j in range(N):
    Ms.append([inf]*(N+1) )
#print(d)
#print(d[1][1])
for i in range(M):
    a,b,c = map(int,input().split(' '))
    #print(a,b,c)
    Ms[a][b] = c
    Ms[b][a] = c
    #print(Ms)
Q = int(input())

def warshall_floyd(Ms):
    for k in range(1,len(Ms)):
        for i in range(1,len(Ms)):
            for j in range(1,len(Ms)):
                Ms[i][j]=min(Ms[i][j],Ms[i][k]+Ms[k][j])
    return Ms

Ms = warshall_floyd(Ms)
#print(Ms)
#print("Ms",Ms[3][2],Ms[2][3])
Ls = Ms.copy()
for i in range(N+1):
    for j in range(N+1):
        if Ls[i][j] <= L:
            Ls[i][j] = 1
        else:
            Ls[i][j]=inf
#print("Ls",Ls[3][2])
Ls = warshall_floyd(Ls)
#print(Ls)
for i in range(Q):
    s,t = map(int,input().split(' '))
    if Ls[s][t] == inf:
        print(-1)
    else:
        print(Ls[s][t]-1)



### FIXED CODE ###

N, M, L = map(int,input().split(' '))
Ms=[]
inf = 10**11
for i in range(N+1):
    #for j in range(N):
    Ms.append([inf]*(N+1) )
#print(d)
#print(d[1][1])
for i in range(M):
    a,b,c = map(int,input().split(' '))
    #print(a,b,c)
    Ms[a][b] = c
    Ms[b][a] = c
    #print(Ms)
Q = int(input())

def warshall_floyd(Ms):
    for k in range(1,len(Ms)):
        for i in range(1,len(Ms)):
            for j in range(1,len(Ms)):
                Ms[i][j]=min(Ms[i][j],Ms[i][k]+Ms[k][j])
    return Ms

Ms = warshall_floyd(Ms)
#print(Ms)
#print("Ms",Ms[3][2],Ms[2][3])
#Ls = Ms.copy()
Ls = Ms
for i in range(N+1):
    for j in range(N+1):
        if Ls[i][j] <= L:
            Ls[i][j] = 1
        else:
            Ls[i][j]=inf
#print("Ls",Ls[3][2])
Ls = warshall_floyd(Ls)
#print(Ls)
for i in range(Q):
    s,t = map(int,input().split(' '))
    if Ls[s][t] == inf:
        print(-1)
    else:
        print(Ls[s][t]-1)
a,b,c = map(int, input().slplit())

print(a * b / 2)


### FIXED CODE ###

a,b,c = map(int, input().split())

print(a * b // 2)
1N = int(input())
ans = 0
for i in range(1,N+1):
  Limit = N//i
  ans += int(Limit*(Limit+1)*i/2)
print(ans)

### FIXED CODE ###

N = int(input())
ans = 0
for i in range(1,N+1):
  Limit = N//i
  ans += int(Limit*(Limit+1)*i/2)
print(ans)
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
cost=[0,2,5,5,4,5,6,3,7,6]
inf=10**9
dp=[-1*inf]*(n+1)
dp[0]=0
for i in range(1,n+1):
    for j in range(m):
        dp[i]=max(dp[i],dp[i-cost[a[j]]]+1)
ans=[]
for i in range(dp[n]):
    for j in range(m):
        if dp[n-cost[a[j]]]==dp[n]-1:
            ans.append(a[j])
            n-=cost[a[j]]
            break
print("".join(list(map(str,ans))))


### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
nums=[0,2,5,5,4,5,6,3,7,6]
dp=[-1]*(n+1)
dp[0]=0
for i in range(1,n+1):
    for x in a:
        if i-nums[x]>=0:
            dp[i]=max(dp[i-nums[x]]+1,dp[i])
k=dp[n]
ans=[]
for i in range(k):
    for x in a:
        if n-nums[x]<0:
            continue
        if dp[n-nums[x]]==dp[n]-1:
            n-=nums[x]
            ans.append(x)
            break
print("".join(list(map(str,ans))))
a, b = map(int, input().split())
if a*b % 2 == 0:
  print("Even")
  
 else:
  print("Odd")

### FIXED CODE ###

a, b = map(int, input().split())
print("Even" if a*b % 2 == 0 else "Odd")
import fractions
import functools
N, M = map(int, input().split())
A = [int(i) for i in input().split()]


def multiple(a, b):
    return a*b // fractions.gcd(a, b)


def lcm(nums):
    return functools.reduce(multiple, nums)


lcm = lcm(A)
hlcm = lcm//2
# print(lcm, hlcm)
for a in A:
    if a % 2 == 1:
        print(0)
        exit()
    if lcm//a % 2 == 0:
        print(0)
        exit()

if hlcm > M:
    print(0)
else:
    print(M//hlcm//2+1)


### FIXED CODE ###

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

mod = 10**9+7  # 出力の制限


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


maxn = 10**5+10
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, maxn + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


ans = 0
for i in range(N-K+1):
    x = cmb(N-i, K, mod)-cmb(N-i-1, K, mod)
    ans -= A[i]*x
    ans += A[N-1-i]*x
    ans %= mod
print(ans)
N = int(input())
P = list(map(int,input().split()))
count = 1
 
if N > 0:
  min = P[0]
  
for i in range(1, N): 
  if min >= P[i]:
    min = P[i]
    count += 1      
print(count)

### FIXED CODE ###

N, M = input().split()
 
if N==M:
  print('Yes')
else:
  print('No')
a,b,x=map(int,input().split())
l=0
r=10**9+1

while r-l >1:
    mid=(r+l)//2
    if x < a*(mid) + b+len(str(mid)):
        max=mid
    else:
        min=mid

print(min)


### FIXED CODE ###

s=input()
lst=['SUN','MON','TUE','WED','THU','FRI','SAT']
lst2=[7,6,5,4,3,2,1]
print(lst2[int(lst.index(s))])
R = input()
print(2*3.14*R)

### FIXED CODE ###

R = input()
R = int(R)

print(2*3.14*R)
N = int(input(()))
L = list(map(int,input().split()))
count = 0

l = []
for j in range(N-1):
    for i in range(j+1,N):
        for k in range(i+1,N):
            if(L[i]+L[j]>L[k])and(L[i]+L[k]>L[j])and(L[i]<L[j]+L[k]):
                l.append([i,j,k])
                if([i,j,k] in l):
                    count += 1
print(count)
print(l)


### FIXED CODE ###

A,B = map(int,input().split())
if A < 2*B:
  print(0)
else:
  print(A-2*B)
a=input();b=input();print a<b and'LESS'or a>b and'GREATER'or'EQUAL'

### FIXED CODE ###

a=(int)(input())-(int)(input());print(a>0 and'GREATER'or a<0 and'LESS'or'EQUAL')
from math import gcd
n = int(input())
arr = sorted(list(map(int, input().split(' '))))
maxi = arr[-1]
gc = maxi
for num in arr[:-1]:
    if gcd(num, maxi) < gc:
        gc = gcd(num, maxi)

print(gc)

### FIXED CODE ###

def gcd(a, b):
    return gcd(b % a, a) if a and b else max(a, b)
    
n = int(input())
arr = sorted(list(map(int, input().split(' '))))
maxi = arr[-1]
gc = maxi
for num in arr[:-1]:
    if gcd(num, maxi) < gc:
        gc = gcd(num, maxi)

print(gc)
import flactions

N = int(input())
A = list(input().split())
monster = list(sorted([int(A[i]) for i in range(N)]))
ans = float('inf')
MIN = monster[0]

for i in range(N):
    tmp = monster[i]
    ans = min(ans, int(flactions.gcd(tmp, MIN)))

print(ans)

### FIXED CODE ###

import fractions

N = int(input())
A = list(input().split())
monster = list(sorted([int(A[i]) for i in range(N)]))
ans = float('inf')
MIN = monster[0]

for i in range(N):
    tmp = monster[i]
    ans = min(ans, int(fractions.gcd(tmp, MIN)))

print(ans)
s = input()
max = 0
count = 0

for i in range(len(s)):
    if s[i] in ['A', 'C', 'G', 'T']:
        count += 1
    else:
        if count > max:
            max = count
            count = 0

print(max(max, count))


### FIXED CODE ###

s = input()
max_count = 0
count = 0

for i in range(len(s)):
    if s[i] in ['A', 'C', 'G', 'T']:
        count += 1
    else:
        if count > max_count:
            max_count = count
            count = 0

print(max(max_count, count))
import math

n, k = map(int, input().split())
limit = 1 / n
ans = 0
for x in range(1 , n + 1):
    num = math.pow(2, -1 * math.ceil(math.log(k / x, 2)))
    num = num / n
    if num > limit:
        num = limit
    ans = ans + num
    if ans >= 1:
        break
print("{:.12
f}".format(ans))

### FIXED CODE ###

import math

n, k = map(int, input().split())
limit = 1 / n
ans = 0
for x in range(1 , n + 1):
    num = math.pow(2, -1 * math.ceil(math.log(k / x, 2)))
    num = num / n
    if num > limit:
        num = limit
    ans = ans + num
    if ans >= 1:
        break
print("{:.12f}".format(ans))
if __name__ == '__main__':
    a_list = [int(f) for f in raw_input().split()]
    while a_list[0]!=0 or a_list[1]!=0:
        pattern_sum = 0
        for i in range(1,a_list[0]-1):
            for j in range(i+1,a_list[0]):
                for k in range(j+1,a_list[0]+1):
                    if i+j+k == a_list[1]:
                        pattern_sum+=1
        print pattern_sum
        a_list = raw_input().split()

### FIXED CODE ###

if __name__ == '__main__':
    a_list = [int(f) for f in raw_input().split()]
    while a_list[0]!=0 or a_list[1]!=0:
        pattern_sum = 0
        for i in range(1,a_list[0]-1):
            for j in range(i+1,a_list[0]):
                for k in range(j+1,a_list[0]+1):
                    if i+j+k == a_list[1]:
                        pattern_sum+=1
        print pattern_sum
        a_list = [int(f) for f in raw_input().split()]
s = list(str(input()))
if len(s) == 1:
    print("YES")
    exit()


count_0 = s.count(jud_s[0])
count_1 = s.count(jud_s[1])
count_2 = s.count(jud_s[2])

max_c = max(count_0, count_1, count_2)
if abs(max_c -count_0) < 2 and abs(max_c - count_1) <2 and abs(max_c -count_2) < 2:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

s = list(str(input()))
count_0 = s.count("a")
count_1 = s.count("b")
count_2 = s.count("c")
max_c = max(count_0, count_1, count_2)
if abs(max_c - count_0) < 2 and abs(max_c - count_1) < 2 and abs(max_c - count_2) < 2:
    print("YES")
else:
    print("NO")
import numpy as np
b = abs
n, *a = map(int, open(0).read().split())
a = np.array([0] + a + [0])
s = sum(map(b, a[1:] - a[:-1]))
for i in range(n):
    print(s + b(a[i+2] - a[i]) - b(a[i+1] - a[i]) - b(a[i+2] - a[i+1])

### FIXED CODE ###

import numpy as np
b = abs
n, *a = map(int, open(0).read().split())
a = np.array([0] + a + [0])
s = sum(map(b, a[1:] - a[:-1]))
for i in range(n):
    print(s + b(a[i+2] - a[i]) - b(a[i+1] - a[i]) - b(a[i+2] - a[i+1]))
print(sum([min([int(input())for i in[1,2])for j in[1,2]]))

### FIXED CODE ###

print(sum([min([int(input())for i in[1,2]])for j in[1,2]]))
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


def agari(i):
    if X[i]==1:
        X[i]=0
        agari(i+1)
    else:
        X[i]=1

for j in range(q):
    k = 0
    flag = 0
    X = [0] * 10
    while k<(pow(2,n)-1):
        y = 0
        for l in range(n):
            y += A[l]*X[l]
        if y == m[j]:
            flag = 1
            break
        agari(0)
        k+=1
    if flag == 1:
        print("yes")
    else:
        print("no")


### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


u = set()

def agari(i):
    if X[i]==1:
        X[i]=0
        agari(i+1)
    else:
        X[i]=1

X = [0]*20
k=0
while k<(pow(2,n)-1):
    y = 0
    for l in range(n):
        y += A[l]*X[l]
    u.add(y)
    agari(0)
    k+=1

for j in range(q):
    if m[j] in u:
        print("yes")
    else:
        print("no")
a=imput()
print(ABC)
print(a)

### FIXED CODE ###

a=input()
b='ABC'
print(b + a)
a, b, c, d = map(int, input().split())

while (a>0) & (c>0):
  tmp1 = c-b
  tmp2 = a-d
  if temp1<=0: print('Yes')
  elif temp2<=0: print('No')

### FIXED CODE ###

a, b, c, d = map(int, input().split())

num1 = (a-1)//d
num2 = (c-1)//b

print('Yes' if num1>=num2 else'No')
X, N = map(int, input().split())
p = list(map(int, input().split()))


p.sort()

tmp = [i for i in range(1, 101)]
for i in p:
        tmp.remove(i)


ans_num = float("Inf")
ans_i = 0
for i in range(len(tmp)):
        if abs(X - tmp[i]) < ans_num:
                ans_num = abs(X - tmp[i])
                ans_i = i

print(tmp[ans_i])


### FIXED CODE ###

X, N = map(int, input().split())
p = list(map(int, input().split()))

if N == 0:
        print(X)
        exit()

p.sort()
tmp = [i for i in range(-111, 111)]
for i in p:
        tmp.remove(i)

ans_num = float("Inf")
ans_i = 0
for i in range(len(tmp)):
        if abs(X - tmp[i]) < ans_num:
                ans_num = abs(X - tmp[i])
                ans_i = i


print(tmp[ans_i])
N, A = map(int, input().split())  # N枚のカード, 平均をAにしたい

X = list(map(int, input().split()))  # カードリスト

# [カードの総枚数][選んだカードの枚数][今の総和]
dp = [[[0]*(max(X)*N+1) for _ in range(N+1)] for _ in range(N+1)]

# 0枚の中から0枚選んで総和が0になるパターンは1つ
dp[0][0][0] = 1

for i in range(len(X)):
    for j in range(1, N+1):
        for k in range(1, N+1):
            for s in range(1, max(X)*N+1):
                if s < X[i]:
                    dp[j][k][s] = dp[j-1][k][s]
                if s >= X[i]:
                    # すでにsになっているものと、今見ているカードを加えることでsになるもの
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-X[i]]


ans = 0
for j in range(1, N+1):
    for k in range(1, N+1):
        ans += dp[j][k][k*A]

print(ans)


### FIXED CODE ###

N, A = map(int, input().split())  # N枚のカード, 平均をAにしたい

X = tuple(map(int, input().split()))  # カードリスト

# [カードの総枚数][選んだカードの枚数][今の総和]
dp = [[[0]*(50*N+1) for _ in range(N+1)] for _ in range(N+1)]

# 0枚の中から0枚選んで総和が0になるパターンは1つ
dp[0][0][0] = 1

for i in range(N):
    for j in range(N+1):
        for k in range(N*50+1):
            if dp[i][j][k]:  # 今の状態を未来へ遷移させる処理
                dp[i+1][j][k] += dp[i][j][k]  # 何も加えず未来へ
                dp[i+1][j+1][k+X[i]] += dp[i][j][k]  # 今見ているカードを加えて未来に遷移

ans = 0
for i in range(1, N+1):
    ans += dp[N][i][i*A]

print(ans)
# ??±???????????¢?´¢(Depth First Search)

def DFS(i, n):
    for j in range(n):
        if A[i][j] == 1 and d[j] == 0:
            time = time + 1
            d[j] = time
            DFS(j)
    time = time + 1
    f[i] = time

n = int(raw_input())
A = [0] * n
for i in range(n):
    A[i] = [0] * n

for i in range(n):
    value = map(int, raw_input().split())
    u = value[0] - 1
    k = value[1]
    nodes = value[2:]
    for i in range(k):
        v = nodes[i] - 1
        A[u][v] = 1

d = [0] * n
f = [0] * n
time = 1
d[0] = time
DFS(0, n)

for i in range(n):
    print(str(i + 1) + " " + str(d[0]) + " " + str(f[0]))
 

### FIXED CODE ###


def DFS(n = 1, i = 0, time = 1):
    for j in range(n):
        if A[i][j] == 1 and d[j] == 0:
            time = time + 1
            d[j] = time
            time = DFS(n, j, time)
    time = time + 1
    f[i] = time
    return time

n = int(raw_input())
A = [0] * n
for i in range(n):
    A[i] = [0] * n

for i in range(n):
    value = map(int, raw_input().split())
    u = value[0] - 1
    k = value[1]
    nodes = value[2:]
    for j in range(k):
        v = nodes[j] - 1
        A[u][v] = 1

d = [0] * n
f = [0] * n

time = 0
for i in range(n):
    if d[i] == 0:
        time = time + 1
        d[i] = time
        time = DFS(n, i, time)

for i in range(n):
    print(str(i + 1) + " " + str(d[i]) + " " + str(f[i]))
import sys

def solve(N, T, A, ls_H):
    dosi = []
    titen = []
    titen1 = []
    ti = 100000 * 1000
    for x in ls_H :
        do = 1000 * T - x * 6
        dosi.append(do)
    # print(dosi)
    
    for y in dosi :
        ti = 1000 * A - y
        titen.append(ti)
    # print(titen)
    
    for z in titen :
        titen1.append(abs(z))
    # print(titen1)
    
    for i in titen1 :
        if ti > i :
            ti = i
    # print(ti)
    return titen1.index(ti) + 1
 
 
def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    ws = sys.stdin.readline().strip().split()
    T = int(ws[0])
    A = int(ws[1])
    ws = sys.stdin.readline().strip().split()
    ls_H = list(map(int, ws))
    return (N, T, A, ls_H)
 
def main():
    print(solve(*readQuestion()))
 
# Uncomment before submission
main()


### FIXED CODE ###

import sys
 
def solve(N, T, A, ls_H):
    return min([(abs(A - (T - h * 0.006)), i) for (i, h) in enumerate(ls_H, start=1)])[1]
 
def readQuestion():
    ws = sys.stdin.readline().strip().split()
    N = int(ws[0])
    ws = sys.stdin.readline().strip().split()
    T = int(ws[0])
    A = int(ws[1])
    ws = sys.stdin.readline().strip().split()
    ls_H = list(map(int, ws))
    return (N, T, A, ls_H)
 
def main():
    print(solve(*readQuestion()))
 
# Uncomment before submission
main()
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip()]

if N % K == 0:
    print('0')
else:
    print('1')


### FIXED CODE ###

from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]

if N % K == 0:
    print('0')
else:
    print('1')
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=list(range(n))
x[n-1]=0
#print(x)
i=n-2
j=1
y=[]
while i!=-1:
    j=1
    while j!=k+1 and j+i!=n:
        y.append(abs(a[i]-a[j+i])+x[j+i])
        #print(a[i])
        #print(a[j+i])
        j+=1

    #print(y)
    x[i]=min(y)
    #print(x)
    y=[]

    i-=1
print(x[0])

### FIXED CODE ###

n=int(input())
h = list(map(int, input().split()))
s=list(range(n))
s[n-1]=0
s[n-2]=abs(h[-2]-h[-1])
i=n-3
a=[]
if n!=2:

    while i!=-1:
        a=[abs(h[i]-h[i+1])+s[i+1],abs(h[i]-h[i+2])+s[i+2]]
        s[i]=min(a)
        i-=1

print(s[0])
n = int(input().rstrip())
edgeList = sorted([int(_) for _ in input().rstrip().split(" ")])n = int(input().rstrip())
edgeList = [int(_) for _ in input().rstrip().split(" ")]
cnt = 0
for i in range(n):
  for j in range(i+1, n):
    if edgeList[i] != edgeList[j]:
      for k in range(j+1, n):
        cnt += (edgeList[i] != edgeList[k] and 
                edgeList[j] != edgeList[k] and 
                edgeList[i] + edgeList[j] > edgeList[k] and 
                edgeList[j] + edgeList[k] > edgeList[i] and 
                edgeList[k] + edgeList[i] > edgeList[j])
print(cnt)

### FIXED CODE ###

n = int(input().rstrip())
edgeList = [int(x) for x in input().rstrip().split(" ")]
cnt = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    if edgeList[i] != edgeList[j]:
      for k in range(j+1, n):
        cnt += (edgeList[i] != edgeList[k] and 
                edgeList[j] != edgeList[k] and 
                edgeList[i] + edgeList[j] > edgeList[k] and 
                edgeList[j] + edgeList[k] > edgeList[i] and 
                edgeList[k] + edgeList[i] > edgeList[j])
print(cnt)
# 入力
monster_hp, quantity_of_skills = map(int, input().split())
skills = map(int, input().split())
skills_list = [skills]

# 処理
total_damage = 0
for i in skills_list:
    total_damage += i

if monster_hp <= total_damage:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

# 入力
monster_hp, quantity_of_skills = map(int, input().split())
skills = map(int, input().split())
skills_list = list(skills)

# 処理
total_damages = 0
for i in skills_list:
    total_damages += i

if monster_hp <= total_damages:
    print('Yes')
else:
    print('No')
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
happiness = 0
memory = 100
for i in range(N):
  happiness += B[A[i]]
  if memory + 1 == A[i]:
    happiness += C[A[i]]
  memory = A[i]
print(happiness)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
happiness = 0
memory = 100
for i in range(N):
  happiness += B[A[i]-1]
  if memory + 1 == A[i]:
    happiness += C[A[i]-2]
  memory = A[i]
print(happiness)
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = E

if A > B and C > D:
	E = B + D
elif A > B and C < D:
	E = B + C
elif A < B and C > D:
	E = A + D
elif A < B and C < D:
	E = A + C
	
print(E)



### FIXED CODE ###

A = int(input())
B = int(input())
C = int(input())
D = int(input())
sum = 0

if A > B:
	sum += B
else:
	sum += A
if C > D:
	sum += D
else :
	sum += C
	
print(sum)
from numpy import cumsum
from collections import Counter
import math
def count(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
a = list(map(int,input().split()))
wa = list(cumsum(a))
wa.append(0)
c = Counter(wa)
keys = set(wa)
ans = 0
for i in keys:
    num = c[i]
    if num >= 2:
        ans += count(num,2)
    else:
        pass
print(ans)


### FIXED CODE ###

from numpy import cumsum
from collections import Counter
import math
def count(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
a = list(map(int,input().split()))
wa = list(cumsum(a))
wa.append(0)
c = Counter(wa)
keys = set(wa)
ans = 0
for i in keys:
    num = c[i]
    if num >= 2:
        ans += count(num,2)
    else:
        pass
print(ans)
if x%y==0:
    print(-1)
else:
    if x*(y+1)<=10**18:
        print(x*(y+1))
    else:
        print(-1)

### FIXED CODE ###

x,y=map(int,input().split())
if x%y==0:
    print(-1)
else:
    if x*(y+1)<=10**18:
        print(x*(y+1))
    else:
        print(-1)
from collections import Counter

mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft

memo = [
    [0, 1, 1],
    [1,10,9],
    [2,11,9],
    [3,4,3],
    [4,13,9],
    [5,14,9],
    [6,5,3],
    [7,16,9],
    [8,17,9],
    [9,2,1],
]


def main():
    m = int(input())
    dc = [[int(i) for i in input().split()] for _ in range(m)]
    s = []
    ans = 0
    for i in range(m):
        d = dc[i][0]
        c = dc[i][1]
        ans += c // memo[d][2] * memo[d][1]
        if d == 9:
            ans -= 2
            s.append(d)
        else:
            s.extend([d] * (c % memo[d][2]))

    t = s[0]
    for i in range(1, len(s)):
        ans += 1
        t += s[i]
        if t > 9:
            ans += 1
            t = t % 10 + t // 10

    print(ans)

main()


### FIXED CODE ###

from collections import Counter

mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft

def main():
    m = int(input())
    ans = 0
    a = 0
    for i in range(m):
        d, c = map(int, input().split())
        ans += c
        a += d * c
    print(ans + (a - 1) // 9 - 1)

main()
from collections import deque
h,w = map(int,input().split())
map_input = [list(input()) for i in range(h)]

sx,sy = 0,0
gx,gy = w-1,h-1
#bfsで最短経路を求めて、それ以外のマスを塗りつぶせばよい
black = 0
for i in range(h):
    for j in range(w):
        if map_input[i][j]=='#':
            black+=1

mx = [0,0,1,-1]
my = [1,-1,0,0]

queue = deque([[sx,sy]])
visited = [[0]*w for i in range(h)]
visited[sy][sx] = 1

def bfs(queue,visited):
    while queue:
        x,y = queue.popleft()
        for i in range(4):
            nx = x+mx[i]
            ny = y+my[i]
            if 0<=nx<w and 0<=ny<h:
                if visited[ny][nx]!=0:
                    continue
                if map_input[ny][nx]=='#':
                    continue
                if nx==gx and ny==gy:
                    return visited[y][x]+1
                visited[ny][nx]=visited[y][x]+1
                queue.append([nx,ny])

ans = h*w-bfs(queue,visited)-black
print(ans)

### FIXED CODE ###

from collections import deque
h,w = map(int,input().split())
map_input = [list(input()) for i in range(h)]

sx,sy = 0,0
gx,gy = w-1,h-1
#bfsで最短経路を求めて、それ以外のマスを塗りつぶせばよい
black = 0
for i in range(h):
    for j in range(w):
        if map_input[i][j]=='#':
            black+=1

mx = [0,0,1,-1]
my = [1,-1,0,0]

queue = deque([[sx,sy]])
visited = [[0]*w for i in range(h)]
visited[sy][sx] = 1

def bfs(queue,visited):
    while queue:
        x,y = queue.popleft()
        for i in range(4):
            nx = x+mx[i]
            ny = y+my[i]
            if 0<=nx<w and 0<=ny<h:
                if visited[ny][nx]!=0:
                    continue
                if map_input[ny][nx]=='#':
                    continue
                if nx==gx and ny==gy:
                    return visited[y][x]+1
                visited[ny][nx]=visited[y][x]+1
                queue.append([nx,ny])
    return -1

tmp = bfs(queue,visited)
if tmp==-1:
    print(-1)
else:
    ans = h*w-tmp-black
    print(ans)