Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

def main():
    n,m = inpm()
    x = inpl()
    y = inpl()
    N = [0 for _ in range(n-1)]
    M = [0 for _ in range(m-1)]
    cnt = n-1
    plus = 0
    for i in range(n-1):
        plus += cnt
        N[i] = plus
        N[-i-1] = plus
        cnt -= 2
        if cnt <= 0:
            break
    cnt = m-1
    plus = 0
    for i in range(m-1):
        plus += cnt
        M[i] = plus
        M[-i-1] = plus
        cnt -= 2
        if cnt <= 0:
            break
    ans = 0
    for i in range(n-1):
        for j in range(m-1):
            area = ((x[i+1]-x[i])*(y[j+1]-y[j])) % mod
            area = (area*N[i]) % mod
            area = (area*M[j]) % mod
            ans = (ans+area) % mod
    print(ans)   
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

def main():
    n,m = inpm()
    x = inpl()
    y = inpl()
    X = 0
    Y = 0
    cntX, cntY = n-1, m-1
    for i in range(n-1,-1,-1):
        X += x[i]*cntX
        X %= mod
        cntX -= 2
    for i in range(m-1,-1,-1):
        Y += y[i]*cntY
        Y %= mod
        cntY -= 2
    print((X*Y)%mod)


    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

n,p=map(int,input().split())
ans=1
if(n==1):
    print(p)
    exit()
for i in range(int(pow(p,1/n)+1),0,-1):
    if(p%(pow(i,n))==0):
        ans=i
        break
print(ans)        



### FIXED CODE ###

n,p=map(int,input().split())
root=round(p**(1/n))
for i in range(root,0,-1):
        if(p%(i**n)==0):
                print(i)
                break
### BUGGY CODE ###

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

if n <= k :
    print(min(n, k-n))
    exit(0)
if n>k:
    while n-k >=0:
        n -= k
    print(min(n, k-n))

### FIXED CODE ###

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

if n <= k :
    print(min(n, k-n))
    exit(0)
if n>k:
    n = n%k
    print(min(n, k-n))
### BUGGY CODE ###

from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce


def input():
    return sys.stdin.readline().strip()


def iinput():
    return int(input())


def tinput():
    return input().split()


def rinput():
    return map(int, tinput())


def rlinput():
    return list(rinput())


mod = int(1e9)+7


def factors(n):
    return set(reduce(list.__add__,
                      ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))


# ----------------------------------------------------

if __name__ == "__main__":
    n, w = rinput()
    w_v = []
    for i in range(n):
        w_v.append(rlinput())
    dp = [[0 for i in range(w+1)]for j in range(n+1)]
    # print(w_v)
    for item in range(1, n+1):
        for weight in range(1, w+1):
            if weight >= w_v[item-1][0]:
                dp[item][weight] = max(dp[item-1][weight-w_v[item-1][0]]+w_v[item-1][1],dp[item-1][weight])
            else:
                dp[item][weight] =dp[item-1][weight]
    print(dp[n][w])


### FIXED CODE ###

from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce


def input():
    return sys.stdin.readline().strip()


def iinput():
    return int(input())


def tinput():
    return input().split()


def rinput():
    return map(int, tinput())


def rlinput():
    return list(rinput())


mod = int(1e9)+7


def factors(n):
    return set(reduce(list.__add__,
                      ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))


# ----------------------------------------------------

if __name__ == "__main__":
    n, weigh = rinput()
    w, v = [], []
    for i in range(n):
        wi, vi = rinput()
        w.append(wi)
        v.append(vi)

    mxv = sum(v)
    dp = [[99999999999 for i in range(mxv+1)]for j in range(n+1)]
    for i in range(n+1):
        dp[i][0]=0
    # print(w_v)
    for item in range(1, n+1):
        for val in range(1, mxv+1):
            if v[item-1] <= val:
                dp[item][val] = min(
                    dp[item-1][val-v[item-1]]+w[item-1], dp[item-1][val])
            else:
                dp[item][val] = dp[item-1][val]
    # print(dp)
    ans=0
    for i in range(mxv+1):
        if dp[n][i]<=weigh:
            ans=i
    print(ans)
### BUGGY CODE ###

def solve(s):
    s = list(s)
    n = len(s)
    res = 0
    i = 0
    while i+3 <= n:
        ok = True
        for j, c in enumerate("ABC"):
            if s[i+j] != c:
                ok = False
                break
        if ok:
            s[i], s[i+1], s[i+2] = "B", "C", "A"
            i = max(0, i-1)
            res += 1
        else:
            i += 1
    return res

s = input()
print(solve(s))

### FIXED CODE ###

def solve(s):
    n = len(s)
    res = 0
    i = 0
    num = 0
    while i < n-1:
        if s[i] == "A":
            num += 1
            i += 1
        elif s[i:i+2] == "BC":
            res += num
            i += 2
        else:
            num = 0
            i += 1
    return res

s = input()
print(solve(s))
### BUGGY CODE ###

INF = 10**18
N, M, K = map(int, input().split())
tmp = 0
k = [K]
for a in map(int, input().split()):
  K -= a
  if K >= 0:
    tmp += 1
    k += [K]
  else:
    break
ans = max(tmp, 0)
A_index = tmp
B = list(map(int, input().split()))
b_num = len(B) - 1
b = B.pop(0)
while True:
  if b <= k[A_index]:
    tmp += 1
    ans = max(ans, tmp)
    if b_num == 0:
      break
    else:
      b += B.pop(0)
      b_num -= 1
  else:
    tmp -= 1
    A_index -= 1
    if A_index < 0:
      break
print(ans)

### FIXED CODE ###

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
A_sum = sum(A)
B_sum = 0
n, m = N, 0
ans= 0
while m != M:
  if A_sum + B_sum <= K:
    ans = max(ans, n+m)
    m += 1
    B_sum += B[m]
  elif A_sum + B_sum > K and n >= 0:
    A_sum -= A[n]
    n -= 1
  else:
    break
if A_sum + B_sum <= K:
  ans = max(ans, n+m)    
print(ans)
### BUGGY CODE ###

N = int(input())
ans = 1
for i in range(1,N+1):
  ans *= i
print(ans%(10**9+7))  

### FIXED CODE ###

N = int(input())
ans = 1
for i in range(1,N+1):
  ans = ans * i %(10**9+7)
print(ans)
### BUGGY CODE ###

def solve():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    prob = 0
    for i in range(N - K + 1):
        x = 0
        for j in range(K):
            x += 1 + P[i + j]
        prob = max(prob, x / 2)
    print(prob)

if __name__ == '__main__':
    solve()


### FIXED CODE ###

def solve():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    x = sum([1+ P[i] for i in range(K)])
    prob = x/2
    for i in range(1,N - K + 1):
        x += P[i+K-1]-P[i-1]
        prob = max(prob, x / 2)
    print(prob)

if __name__ == '__main__':
    solve()
### BUGGY CODE ###

# input
N, M = map(int, input().split())
mastar_keys = set(list(range(1, N + 1)))
check = []
c_append = check.append
for i in range(1, M + 1):
    L, R = map(int, input().split())
    c = set(list(range(L, R + 1)))
    mastar_keys = mastar_keys & c

print(len(mastar_keys))


### FIXED CODE ###

# input & check
N, M = map(int, input().split())
x, y = 0, N
for i in range(1, M + 1):
    L, R = map(int, input().split())
    x = max(x, L)
    y = min(y, R)

print(len(range(x, y + 1)))
### BUGGY CODE ###

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

from itertools import combinations as comb
count = 0
for a in comb(range(1,n+1),3):
  i = a[0] - 1
  j = a[1] - 1
  k = a[2] - 1
  if j-i == k-j:
    continue
  if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
    count += 1
print(count)

### FIXED CODE ###

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

r = 0
g = 0
b = 0
for i in s:
  if i == 'R':
    r += 1
  elif i == 'G':
    g += 1
  else:
    b += 1

all = r*g*b
ho = 0
for i in range(0,n):
  for j in range(i+1,n):
    if s[i] == s[j]:
      continue
    k = 2*j-i
    if k >= n:
      continue
    if s[i] == s[k] or s[j] == s[k]:
      continue
    ho += 1
print(all-ho)
### BUGGY CODE ###

import sys
import itertools

input = sys.stdin.readline

def main():
    l, r = [int(i) for i in input().split()] 

    num_list = [num for num in range(l, r+1)]

    mod = 0
    mod_min = 2019

    for i, j in itertools.combinations(num_list, 2):
        mod = (i*j % 2019)
        if mod < mod_min:
            mod_min = mod
            
    print(mod_min)
    
# main関数呼び出し
if __name__ == "__main__":
    main() 

### FIXED CODE ###

import sys
import itertools

input = sys.stdin.readline

def func(l, r):
    mod_min = float('inf')

    for i in range(l, r):
        for j in range(i+1, r+1):
            mod = (i*j % 2019)

            if mod == 0:
                print(mod)
                exit()     

            elif mod < mod_min:
                mod_min = mod

    print(mod_min)

def main():
    l, r = [int(i) for i in input().split()] 
    func(l, r)
    
# main関数呼び出し
if __name__ == "__main__":
    main()
### BUGGY CODE ###

H,W = map(int,input().split())
a_list = []
for i in range(H):
    str = input()
    a_list.append(list(str))

INF = 10**10

for i in range(H):
    for j in range(W):
        if a_list[i][j] == "#":
            a_list[i][j] = 0
        else:
            a_list[i][j] = INF

for i in range(H):
    for j in range(W-1):
        a_list[i][j+1] = min(a_list[i][j]+1,a_list[i][j+1])
        a_list[i][-j-2] = min(a_list[i][-j-1]+1,a_list[i][-j-2])

for i in range(W):
    for j in range(H-1):
        a_list[j+1][i] = min(a_list[j][i]+1,a_list[j+1][i])
        a_list[-j-2][i] = min(a_list[-j-1][i]+1,a_list[-j-2][i])

ans = 0
for i in range(H):
    ans = max(ans,max(a_list[i]))

print(ans)

### FIXED CODE ###

import numpy
H,W = map(int,input().split())
a_list = []
INF = 10**10
for i in range(H):
    str = input()
    a_list.append([0 if i == "#" else INF for i in list(str)])

a_list = numpy.array(a_list)
for x in range(W-1):
    a_list[:,x+1] = numpy.minimum(a_list[:,x]+1,a_list[:,x+1])
    a_list[:,-x-2] = numpy.minimum(a_list[:,-x-1]+1,a_list[:,-x-2])

for y in range(H-1):
    a_list[y+1,:] = numpy.minimum(a_list[y,:]+1,a_list[y+1,:])
    a_list[-y-2,:] = numpy.minimum(a_list[-y-1,:]+1,a_list[-y-2,:])

print(a_list.max())
### BUGGY CODE ###

s = input()
k = int(input())
l = "abcdefghijklmnopqrstuvwxyz"
d = {}

for i in range(26):
    cnt = s.count(l[i])
    pre = 0
    if cnt > 0:
        for j in range(cnt):
            pos = s.find(l[i], pre)
            pre = pos + 1
            for m in range(len(s) - pos):
                if s[pos:pos + m + 1] not in d:
                    d[s[pos:pos + m + 1]] = 1
    if len(d) >= k:
        dl = []
        for i in d.keys():
            dl.append(i)
        dl.sort()
        print(dl[k - 1])
        exit()

### FIXED CODE ###

s = input()
k = int(input())
l = "abcdefghijklmnopqrstuvwxyz"
d = {}

for i in range(26):
    cnt = s.count(l[i])
    pre = 0
    if cnt > 0:
        for j in range(cnt):
            pos = s.find(l[i], pre)
            pre = pos + 1
            for m in range(min(len(s) - pos, k)):
                if s[pos:pos + m + 1] not in d:
                    d[s[pos:pos + m + 1]] = 1
    if len(d) >= k:
        dl = []
        for i in d.keys():
            dl.append(i)
        dl.sort()
        print(dl[k - 1])
        exit()
### BUGGY CODE ###

#coding:utf-8
n, m = map(int, input().split())
l, r = 10**6, 0
ll = []
ans_l = []
tmp_ans = []
for i in range(m):
    a, b = map(int, input().split())
    ans_l = []
    if i == 0:
        tmp_ans = list(range(a, b+1, 1))
    else:
        for j in range(len(tmp_ans)):
            if a <= tmp_ans[j] <= b:
                ans_l.append(tmp_ans[j])
        tmp_ans = ans_l[:]
print(len(set(tmp_ans)))

### FIXED CODE ###

#coding:utf-8
n, m = map(int, input().split())
l, r = 0, 10**6
for i in range(m):
    a, b = map(int, input().split())
    l = max(l, a)
    r = min(r, b)
print(r - l  + 1 if l <= r else 0)
### BUGGY CODE ###

n,x,y = map(int,input().split())
tbl = [[0]*n for i in range(n)]
for i in range(n):
    for j in range(i,n):
        tbl[i][j] = min(abs(j+1-i-1),abs(i+1-x)+1+abs(j+1-y))
for i in range(1,n):
    a = 0
    for j in tbl:
        a += j.count(i)
    print(a)

### FIXED CODE ###

n,x,y = map(int,input().split())
ans = [0]*(n)
for i in range(n):
    tbl = [0]*n
    for j in range(i,n):
        tbl[j] = min(abs(j+1-i-1),abs(i+1-x)+1+abs(j+1-y))
        ans[tbl[j]] += 1
[print(i) for i in ans[1:]]
### BUGGY CODE ###

N,W=map(int,input().split())
from collections import*
d=defaultdict(int)
d[0]=0
for i in range(N):
    w,v=map(int,input().split())
    for k,b in d.copy().items():
        if k+w<=W:
            d[k+w]=max(d[k+w],b+v)
print(max(d.values()))

### FIXED CODE ###

from numpy import*
N,W=map(int, input().split())
dp=zeros(W+1)
for i in range(N):
    w,v=map(int, input().split())
    dp[w:]=maximum(dp[w:], dp[:-w]+v)
print(int(max(dp)))
### BUGGY CODE ###

s = input()

length = len(s)
t = ''
word = ''

for a in range(length-1, -1, -1):
    t += s[a]
    reverse_t = t[::-1]
    if reverse_t == 'dream' or reverse_t == 'dreamer' or reverse_t == 'erase' or reverse_t == 'eraser':
        word = reverse_t + word
        t = ''

if s == word:
    print('YES')
else:
    print('NO')


### FIXED CODE ###

s = input()

length = len(s)
t = ''
word = ''

for a in range(length-1, -1, -1):
    t += s[a]
    if t == 'maerd' or t == 'remaerd' or t == 'esare' or t == 'resare':
        word += t
        t = ''

if s == word[::-1]:
    print('YES')
else:
    print('NO')
### BUGGY CODE ###

n,k = map(int,input().split())
m = [0] + list(map(int,input().split()))
p = 1

q = [1]

while True:
  p = m[p]
  if (p in q):
    break
  q.append(p)
i = q.index(p)
if len(q[:i]) > 0 and k < len(q[:i]):
  print(q[k])
else: 
  q2 = q[i:]
  print(q2[(k - len(q[:i])) % len(q2)])

### FIXED CODE ###

n,k = map(int,input().split())
m = [0] + list(map(int,input().split()))
p = 1

c = [0] * (n + 1)

q = [1]

while True:
  p = m[p]
  if (c[p] == 1):
    break
  c[p] += 1
  q.append(p)
i = q.index(p)
q1 = q[:i]
q2 = q[i:]
if len(q1) > 0 and k < len(q1):
  print(q1[k])
else: 
  print(q2[(k - len(q)) % len(q2)])
### BUGGY CODE ###

x=input()
y=input()
m = 0 
for i in range(len(x)):
    if x[i] != y[i]:
        Y = y.replace(y[i], x[i]) 
        m+=1
print(m)      

### FIXED CODE ###

x=input()
y=input()
m = 0 
for i in range(len(x)):
    if x[i] != y[i]: 
        m+=1
print(m)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(set(a))
ans = 0
for i in range(len(b)):
	cnt = a.count(b[i])
	if (cnt > b[i]):
		ans += cnt - b[i]
	elif (cnt < b[i]):
		ans += cnt
print (ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
ans = 0
for i in c.keys():
	if c[i] >= i:
		ans += c[i] - i
	else:
		ans += c[i]
print (ans)
### BUGGY CODE ###

import itertools
n = int(input())
l = list(map(int, input().split()))
count = 0
for a, b, c in itertools.combinations(l, 3):
    if a < b+c and b < a+c and c < a+b:
        count += 1
print(count)

### FIXED CODE ###

import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        a = l[i]+l[j]
        index = bisect.bisect_left(l, a)
        count += index - j -1
print(count)
### BUGGY CODE ###

import math
denom = int(1e9+7)

def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


def combi2(n,k,p,f):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=fact_mod[n]
  b=fact_mod[k]
  c=fact_mod[n-k]
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p


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

fact_mod = [1]
current = 1
for i in range(1,N+1):
    current = (current * i) % denom
    fact_mod.append(current)

max_tot = 0
min_tot = 0
for i in range(N-K+1):
    max_tot += (A[i] * combi2(N-i-1, K-1, denom, fact_mod)) % denom
    min_tot += (A[N-i-1] * combi2(N-i-1, K-1, denom, fact_mod)) % denom
    
print((max_tot - min_tot)%denom)

### FIXED CODE ###

import math
denom = int(1e9+7)

def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


def combi2(n,k,p,f,pow_fun):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=fact_mod[n]
  b=fact_mod[k]
  c=fact_mod[n-k]
  return (a*pow_fun[b]*pow_fun[c])%p


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

fact_mod = [1]
current = 1
for i in range(1,N+1):
    current = (current * i) % denom
    fact_mod.append(current)

pow_fun = {}
for i in fact_mod:
    pow_fun[i]=power_func(i,denom-2,denom)

max_tot = 0
min_tot = 0
for i in range(N-K+1):
    max_tot += (A[i] * combi2(N-i-1, K-1, denom, fact_mod,pow_fun)) % denom
    min_tot += (A[N-i-1] * combi2(N-i-1, K-1, denom, fact_mod,pow_fun)) % denom
    
print((max_tot - min_tot)%denom)
### BUGGY CODE ###

n, a, b = map(int,input().split())
mod = 10 ** 9 + 7

def permutation(n,r):
    perm = 1
    for integer in range(n-r+1, n+1):
        perm *= integer
    return perm

def RepeatSquaring(x, n, m):
  ans = 1
  while(n > 0):
    if(bin(n & 1) == bin(1)):
      ans = (ans*x)%m
    x = (x*x)%m
    n = n >> 1
  return ans

def cmb(n, r, mod):
    nume = permutation(n,r)
    deno = permutation(r,r)
    return (nume * RepeatSquaring(deno, mod-2, mod)) % mod

ans = RepeatSquaring(2, n, mod) - 1 - cmb(n, a, mod) - cmb(n, b, mod)

print(ans)

### FIXED CODE ###

n, a, b = map(int,input().split())
mod = 10 ** 9 + 7

def permutation(n,r,mod):
    perm = 1
    for integer in range(n-r+1, n+1):
        perm *= integer
        perm %= mod
    return perm

def RepeatSquaring(x, n, m):
  ans = 1
  while(n > 0):
    if(bin(n & 1) == bin(1)):
      ans = (ans*x)%m
    x = (x*x)%m
    n = n >> 1
  return ans

def cmb(n, r, mod):
    nume = permutation(n,r,mod)
    deno = permutation(r,r,mod)
    return (nume * RepeatSquaring(deno, mod-2, mod)) % mod

ans = (RepeatSquaring(2, n, mod) - 1 - cmb(n, a, mod) - cmb(n, b, mod)) % mod

print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)


def main():
    n, q = map(int, input().split())
    e = [list(map(int, input().split())) for _ in range(n-1)]
    p = [list(map(int, input().split())) for _ in range(q)]

    e2 = [[] for _ in range(n)]
    for ee in e:
        a, b = ee
        e2[a-1].append(b-1)
        e2[b-1].append(a-1)

    counters = [0 for _ in range(n)]
    for pp in p:
        counters[pp[0]-1] += pp[1]

    used = set()

    def dfs(x, p_sum):
        used.add(x)
        counters[x] += p_sum
        for y in e2[x]:
            if y in used:
                continue
            dfs(y, counters[x])

    dfs(0, 0)
    print(*counters)


main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    e = [list(map(int, input().split())) for _ in range(n-1)]
    p = [list(map(int, input().split())) for _ in range(q)]

    e2 = [{} for _ in range(n)]
    for ee in e:
        a, b = ee
        e2[a-1][b-1] = 1
        e2[b-1][a-1] = 1

    counters = [0 for _ in range(n)]
    for pp in p:
        counters[pp[0]-1] += pp[1]

    def dfs(x, p_sum):
        counters[x] += p_sum
        for y in e2[x]:
            del e2[y][x]
            dfs(y, counters[x])

    dfs(0, 0)
    print(*counters)


main()
### BUGGY CODE ###

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

ans = 0

for i in range(1, N + 1):
    tmp = (A * i) // B - A * (i // B)
    ans = max(ans, tmp)

print(ans)


### FIXED CODE ###

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

x = min(B - 1, N)
ans = (A * x) // B - A * (x // B)
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

import sys
import os

memo = {}

def is_prime(n):
    if n in memo:
        return memo[n]

    if n==2 or n==3:
        return True
    if n%2==0 or n<2:
        return False
    for i in range(3,int(n**0.5)+1,2):
        if n%i==0:
            memo[n] = False
            return False
    memo[n] = True
    return True

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    if n % 2 == 1:
        if is_prime(n - 2):
            print(1)
        else:
            print(0)
    else:
        counter = 0
        for i in range(1, n // 2 + 1, 2):
            prime0 = i
            prime1 = n - i
            if prime0 <= prime1 and is_prime(prime0) and is_prime(prime1):
                counter += 1
        print(counter)

### FIXED CODE ###

import sys

N = 50001
lst = [True] * N
lst[0] = False
lst[1] = False
for i in range(2, int(N ** 0.5) + 1):
    if lst[i]:
        for j in range(i * i, N, i):
            lst[j] = False

primes = [i for i in range(1, N) if lst[i]]

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break
    elif n % 2 == 1:
        if lst[n - 2]:
            print(1)
        else:
            print(0)
    elif n == 4:
        print(1)
    else:
        counter = 0
        for prime0 in primes:
            prime1 = n - prime0
            if prime0 <= prime1 and lst[prime1]:
                #print(prime0, prime1)
                counter += 1
        print(counter)
### BUGGY CODE ###

from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    K = int(input())

    if K % 2 == 0:
        print(-1)
        return

    tmp = 7
    ans = 1
    while tmp % K != 0:
        tmp = (tmp % K) * 10 + 7
        ans += 1

    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    K = int(input())

    if K % 2 == 0:
        print(-1)
        return

    tmp = 7
    ans = 1
    while tmp % K != 0:
        tmp = (tmp % K) * 10 + 7
        ans += 1
        if ans >= 10000000:
            print(-1)
            return

    print(ans)

if __name__ == '__main__':
    main()