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

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

# 愚直に3重ループ
count = 0
for a in range(1,N+1) :
	for b in range(1, N+1) :
		for c in range(1, N+1) :
			if (int(a+b) % K == 0 and int(b+c) % K == 0 and int(c+a) % K == 0) :
				count += 1

print(count)

### FIXED CODE ###

import itertools as it
N,K = [int(i) for i in input().split()]

candidates = []
even = []
odd = []
for i in range(1,N+1) :
	i = int(i)
	if (i % K == 0) :
		# Kの倍数は候補にする
		even.append(i)
		continue
	
	if (K % 2 == 0 and i % (K/2) == 0) :
		# Kが偶数だったらK/2も候補としてよい
		odd.append(i)
		continue

# a,b,cの組み合わせ(Kが奇数のとき)
count = len(even) * len(even) * len(even)

# a,b,cの組み合わせ(Kが偶数のとき)
# すべての要素がK/2で揃っているケース
if (K % 2 == 0) :
	count += (len(odd) * len(odd) * len(odd))

print(count)
### BUGGY CODE ###

n,q = map(int,input().split())
raw_list = list(input())
AC_pos = []
for idx,char in enumerate(raw_list):

    if raw_list[idx] =="A":
        if idx == len(raw_list)-1:
            break
        if raw_list[idx+1] == "C":
            AC_pos.append(idx)
#print(AC_pos)
for i in range(q):
    li, ri = map(int,input().split())
    print(sum(li-1<=x<=ri-2 for x in AC_pos))


### FIXED CODE ###

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

ac_count = [0]*N
temp = 0
for i in range(1,N):
    if S[i] == 'C' and S[i-1] == 'A':
        temp += 1
        ac_count[i] = temp
    else:
        ac_count[i] = temp
#print(ac_count)
for _ in range(Q):
    l,r = map(int,input().split())
    if S[l-1] != 'C':
        print(ac_count[r-1]-ac_count[l-1])
    else:
        print(ac_count[r-1]-ac_count[l-1])
### BUGGY CODE ###

n, k = map(int, input().split())
md = 10 ** 9 + 7
if k % 2:
    print(0)
    exit()
k //= 2
dp = [[[0] * (n ** 2) for _ in range(n + 2)] for __ in range(n + 1)]
dp[0][0][0] = 1
for i in range(1, n + 1):
    dpi1 = dp[i - 1]
    for j in range(i + 1):
        for s in range(j, k + 1):
            # 片側、水平、両方上
#            print(i,j,s)
            tmp = dpi1[j][s - j] * j * 2 + dpi1[j][s - j] + dpi1[j + 1][s - j] * (j + 1) ** 2
            if j:
                # 両方保留
                tmp += dp[i - 1][j - 1][s - j]
            dp[i][j][s] = tmp % md
print(dp[n][0][k])


### FIXED CODE ###

def f(n,k):
    md = 10 ** 9 + 7
    if k % 2:
        print(0)
        exit()
    k //= 2
    dp = [[[0] * (n ** 2) for _ in range(n + 2)] for __ in range(n + 1)]
    dp[0][0][0] = 1
    for i in range(1, n + 1):
        dpi1 = dp[i - 1]
        for j in range(i + 1):
            for s in range(j, k + 1):
                # 片側、水平、両方上
                #            print(i,j,s)
                tmp = dpi1[j][s - j] * j * 2 + dpi1[j][s - j] + dpi1[j + 1][s - j] * (j + 1) ** 2
                if j:
                    # 両方保留
                    tmp += dp[i - 1][j - 1][s - j]
                dp[i][j][s] = tmp % md
    print(dp[n][0][k])

n, k = map(int, input().split())
f(n,k)
### BUGGY CODE ###

N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))


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

ans=[]

for i in range(N):
    B=A[:]
    del B[i]
    sol=0
    for b in B:
        sol=gcd(sol,b)
    ans.append(sol)

print(max(ans))

### FIXED CODE ###

N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))


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

list1=[0]
L=0
for a in A:
    L=gcd(L,a)
    list1.append(L)

list2=[0]
R=0
for a in reversed(A):
    R=gcd(R,a)
    list2.append(R)

list2.reverse()

ans=[]

for i in range(N):
    ans.append(gcd(list1[i],list2[i+1]))

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

from collections import Counter
import math

def ncr(n, r):
  if r > n:
    return 0
  return math.factorial(n) // math.factorial(n-r) // math.factorial(r)

input()
As = list(map(int, input().split()))
counter = Counter(As)
res = {}
for k, v in counter.items():
  res[k] = (ncr(v, 2), ncr(v-1, 2))

for a in As:
  print(sum(v[0] if k != a else v[1] for k,v in res.items()))

### FIXED CODE ###

from collections import Counter
import math

def ncr(n, r):
  if r > n:
    return 0
  return math.factorial(n) // math.factorial(n-r) // math.factorial(r)

input()
As = list(map(int, input().split()))
counter = Counter(As)
res = {}
total = 0
for k, v in counter.items():
  x = ncr(v, 2)
  res[k] = (x, (x * (v-2) // (v)))
  total += x
for a in As:
  v1, v2 = res[a]
  print(total - v1 + v2)
### BUGGY CODE ###

import sys
import math

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

if k == 1:
    print(0)
    sys.exit()

pre=n-math.floor(n/k)*k

pre=n
while 1:
    if pre < abs(pre-k):
        print(pre)
        sys.exit()
    pre = abs(pre - k)

### FIXED CODE ###

import sys
import math

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

pre=n-n//k*k

while 1:
    if pre <= abs(pre-k):
        print(pre)
        sys.exit()
    pre = abs(pre - k)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
MOD = 1000000007

k = int(input())
number = 9

ans = 0
for i in range(10,10**6):
    check = 'OK'
    l = len(str(i))
    keta = list(str(i))
    for j in range(l-1):
        if abs(int(keta[j]) - int(keta[j+1])) <= 1:
            pass
        else:
            check = 'NG'
    if check == 'OK':
        number += 1
        if number == k:
            ans = i%MOD
            break
if k <= 9:
    print(k)
else:
    print(ans%MOD)


### FIXED CODE ###

k = int(input())
ans = [i for i in range(1,10)]

i = 0

for i in range(k):
    now = ans[i]
    if str(now)[-1] == '0':
        ans.append(now*10)
        ans.append(now*10+1)
    elif str(now)[-1] == '9':
        ans.append(now*10+8)
        ans.append(now*10+9)
    else:
        ans.append(now*10+now%10-1)
        ans.append(now*10+now%10)
        ans.append(now*10+now%10+1)
    if len(ans) > k:
        break

print(ans[k-1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


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


def main():
    N, K = readnums()
    x = list(readnums())
    ans = 0
    for i in range(K, N + 1):
        l = x[i - K:i]
        if min(l) > 0:
            val = abs(max(l))
        elif max(l) < 0:
            val = abs(min(l))
        else:
            val = abs(min(l)) + abs(max(l))
            val += min(abs(min(l)), abs(max(l)))
        if not ans:
            ans = val
        else:
            ans = min(ans, val)

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


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


def main():
    N, K = readnums()
    x = list(readnums())
    ans = 0
    for i in range(K - 1, N):
        ls = i - K + 1
        le = i
        if x[ls] > 0:
            val = abs(x[le])
        elif x[le] < 0:
            val = abs(x[ls])
        else:
            val = abs(x[ls]) + abs(x[le])
            val += min(abs(x[ls]), abs(x[le]))
        if not ans:
            ans = val
        else:
            ans = min(ans, val)

    print(ans)


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

S = input()

cnt = 0
for i in range(len(S)-4):
    for j in range(i+5, len(S)+1):
        s = int(S[i:j])
        if s % 2019 == 0:
            cnt += 1
print(cnt)


### FIXED CODE ###

S = input()
 
mods = [0 for _ in range(2019)]
mods[0] = 1
t = 0
mod10 = 1
for s in reversed(S):
    t += int(s) * mod10
    t = t % 2019
    mod10 *= 10
    mod10 %= 2019
    mods[t] += 1

cnt = sum([m*(m-1)/2 for m in mods])
print(int(cnt))
### BUGGY CODE ###

from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()

num_triangles = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        idx = bisect_left(a=L, x=L[i]+L[j], lo=j+1)
        num_triangles += idx-j-1
print(num_triangles)


### FIXED CODE ###

from bisect import bisect_left

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

ans = 0
for i in range(n):
    for j in range(i+1, n):
        endpt = bisect_left(l, l[i] + l[j])
        ans += endpt-j-1

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

def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A
def solve():
  n = int(input())
  s = input()
  ans = 0
  for i in range(n):
    a = z_algo(s[i:])
    for i in range(len(a)):
      if i > 0 and a[i] <= a[0]/2:
        ans = max(ans,a[i])
  print(ans)
solve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A
def solve():
  n = int(input())
  s = input()
  ans = 0
  for i in range(n):
    a = z_algo(s[i:])
    for j in range(i,n):
        ans = max(ans, min(j-i, a[j-i]))
  print(ans)
solve()
### BUGGY CODE ###

n, k = map(int, input().split())
a = [int(an) for an in input().split()]
ans = 0
set_a = set(a)
num_of_types = len(set_a)
if num_of_types > k:
  ans = sum(sorted([a.count(num) for num in set(a)])[:num_of_types - k])
print(ans)

### FIXED CODE ###

from collections import Counter

n, k = map(int, input().split())
a = [int(an) for an in input().split()]
ans = 0
set_a = set(a)
num_of_types = len(set_a)
if num_of_types > k:
  cnt = Counter(a)
  ans = sum(sorted(cnt.values())[: num_of_types - k])

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

import numpy as np

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

sum_list =[p[i]*p[t] for i in range(a) for t in range(a) if i<t ]
num = np.sum(sum_list)
num = num%mod
print(num)

### FIXED CODE ###

import itertools as itr

a = int(input())
p = list(map(int,input().split()))
mod = 10**9 + 7
ans =0
sum_list = list(itr.accumulate(p))
for i in range(len(p)-1):
    o = p[i+1]
    w =sum_list[i]
    ans = (ans+o*w%mod)%mod
print(ans)
### BUGGY CODE ###

import heapq
import math
import sys

input = sys.stdin.readline


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

    for i in range(N):
        p = A[i]
        A[i] = [-p, i]

    heapq.heapify(A)
    C = [0]*N
    for j in range(K):
        x, y = heapq.heappop(A)
        cnt = C[y]
        x = x * (cnt+1) / (cnt+2)
        C[y] += 1
        heapq.heappush(A, [x, y])

    ans = heapq.heappop(A)[0]

    ans = math.ceil(-ans)

    print(ans)

if __name__ == "__main__":
    main()




### FIXED CODE ###

import heapq
import math
import sys

input = sys.stdin.readline


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

    def C(m):
        cnt = 0
        for i in range(N):
            cnt += math.ceil(A[i]/m)-1
        return cnt

    l, r = 0, max(A)
    while r - l > 1:
        mid = (l+r)//2
        if C(mid) <= K:
            r = mid
        else:
            l = mid
    
    print(r)

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

n=int(input())
s=input()
mi=n
for i in range(n):
  l=list(s[:i])
  r=list(s[i+1:])
  mi=min(l.count("W")+r.count("E"),mi)
print(mi)

### FIXED CODE ###

n=int(input())
s=input()
SW=[0]
SE=[0]
for i in range(n):
  if(s[i]=="W"):
    SW.append(SW[-1]+1)
    SE.append(SE[-1])
  else:
    SE.append(SE[-1]+1)
    SW.append(SW[-1])
mi=n
SE.append(SE[-1])
for i in range(n):
  mi=min(SW[i]+SE[-1]-SE[i+1],mi)
print(mi)
### BUGGY CODE ###

n, k = map(int, input().split())
if n < k:
    if n < k-n:
        print(n)
    else:
        print(k-n)
        
else:
    while n > k:
        n = n-k
    if n < k-n:
        print(n)
    else:
        print(k-n)

### FIXED CODE ###

n, k = map(int, input().split())
if n < k:
    if n < k-n:
        print(n)
    else:
        print(k-n)
else:
    n = n%k
    if n < k-n:
        print(n)
    else:
        print(k-n)
### BUGGY CODE ###

import numpy as np


max_size = 2 * 10**4
h, n = map(int, input().split())
DP = np.ones(max_size, dtype=np.int64) * 10**9
DP[0] = 0

for _ in range(n):
    power, cost = map(int, input().split())
    for i in range((h+power-1)//power):
        DP[(i+1)*power: (i+2)*power] = np.minimum(DP[(i+1)*power: (i+2)*power], DP[(i)*power: (i+1)*power] + cost)

print(DP[h:].min())


### FIXED CODE ###

import sys
input = sys.stdin.readline

max_size = 2*10**4 + 1
h, n = map(int, input().split())
DP = [float('INF')] * max_size
DP[0] = 0

for _ in range(n):
    damage, cost = map(int, input().split())
    for idx in range(damage, max_size):
        DP[idx] = min(DP[idx], DP[idx-damage] + cost)

print(min(DP[h:]))
### BUGGY CODE ###

N,K = map(int, input().split())
S = input()
memo =[]
now = '1'
cnt = 0
for s in S:
    if s==now:
        cnt+=1
    else:
        memo.append(cnt)
        cnt=1
        now = '1' if now=='0' else '0'
else:
    memo.append(cnt)
if S[-1] == '0':
    memo.append(0)
ans = 0
add = K*2+1
for i in range(N)[::2]:
    if i < N:
        ans = max(ans, sum(memo[i:i+K*2+1]))
print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
S = list(map(int, list(input())))
now = 1
cnt = 0
Nums = []
for i in range(N):
    if S[i] == now:
        cnt += 1
    else:
        Nums.append(cnt)
        now = 1 - now
        cnt = 1
if cnt != 0:
    Nums.append(cnt)

if len(Nums) % 2 == 0:
    Nums.append(0)

add = 2*K+1
ans = 0
left, right = 0, 0
tmp = 0  # sum of [left, right)
for i in range(len(Nums))[::2]:
    next_left = i
    next_right = min(i + add, len(Nums))
    while next_left > left:
        tmp -= Nums[left]
        left += 1
    while next_right > right:
        tmp += Nums[right]
        right += 1

    ans = max(tmp, ans)

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

N, Q = map(int, input().split())
S = list(input())
TD = [tuple(input().split()) for _ in range(Q)]
G = [1 for _ in range(N)]

for td in TD:
	for i, s in enumerate(S):
		if s == td[0]:
			if "L" == td[1]:
				if 0 == i:
					G[i] = 0
				else:
					G[i-1] += G[i]
					G[i] = 0
			else:
				if N-1 == i:
					G[i] = 0
				else:
					G[i+1] += G[i]
					G[i] = 0
print(sum(G))


### FIXED CODE ###

N, Q = map(int, input().split())
S = list(input())
TD = [tuple(input().split()) for _ in range(Q)]

def bs_l(f, s, e):
	if s==e:
		return s if f(s) else s+1

	c = (s+e)//2
	if f(c):
		#左
		return bs_l(f, s, c if c == s else c-1)
	else:
		#右
		return bs_l(f, c if c == e else c+1, e)

def bs_r(f, s, e):
	if s==e:
		return s if f(s) else s-1

	c = (s+e)//2
	if not f(c):
		#左
		return bs_r(f, s, c if c == s else c-1)
	else:
		#右
		return bs_r(f, c if c == e else c+1, e)

def isAlive(c):
	for t, d in TD:
		if S[c] == t:
			c += 1 if "R" == d else -1
			if c < 0 or N <= c:
				return False
	return True

S, E = bs_l(isAlive, 0, N-1), bs_r(isAlive, 0, N-1)
print(max(E-S+1, 0))
### BUGGY CODE ###

n = int(input())
plist = list(map(int,input().split()))


counter = 0

for i in range(len(plist)):
    islow = True
    for j in range(plist.index(plist[i])):        
        if plist[i] <= plist[j]:
            continue
        else:
            islow = False
            break
    if islow:
        counter += 1

print(counter)        

### FIXED CODE ###

n = int(input())
plist = list(map(int,input().split()))

islow = True
counter = 0
min = 0

for i in range(len(plist)):
    islow = True
    if i == 0:
        counter += 1
        min = plist[i]
        current_min = i
    elif min > plist[i]:
        counter += 1
        min = plist[i]
        current_min = i
        
print(counter)
### BUGGY CODE ###

k, s = map(int, input().split())
n = 0
for i in range(k + 1):
    if (s-i)/2 > k or i > s:
        continue
    for j in range(k + 1):
        if s-i-j > k or j > s:
            continue
        for l in range(k + 1):
            if i + j + l == s:
                n += 1
            elif i + j + l > s:
                break
print(n)


### FIXED CODE ###

k, s = map(int, input().split())
n = 0
for i in range(k + 1):
    if (s-i)/2 > k:
        continue
    elif i > s:
        break
    for j in range(k+1):
        z = s - i - j
        if 0<= z <= k:
            n += 1
print(n)
### BUGGY CODE ###

h, w=map(int, input().split())
a=[]
need_visited=[[0 for i in range(w)] for j in range(h)]
stack=[]
for i in range(h):
    a.append(list(input()))

for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            stack.append([i, j])



dx=[1, -1, 0, 0]
dy=[0, 0, 1, -1]


while len(stack)!=0:
    now_point=stack.pop(0)
    for i in range(4):
        target_h=now_point[0]+dx[i]
        target_w=now_point[1]+dy[i]
        if 0<=target_h<h and 0<=target_w<w:
            if a[target_h][target_w]==".":
                need_visited[target_h][target_w]=need_visited[now_point[0]][now_point[1]]+1
                a[target_h][target_w]="#"
                stack.append([target_h, target_w])
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans, need_visited[i][j])
print(ans)


### FIXED CODE ###

from collections import deque

H, W = [int(x) for x in input().split()]
cell = [list(input()) for i in range(H)]

painted = deque()
for h in range(H):
    for w in range(W):
        if cell[h][w] == '#':
            painted.append([h, w, 0])

ans = 0
while len(painted) > 0:
    blackcell = painted.popleft()
    for dy, dx in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
        nh = blackcell[0] + dy
        nw = blackcell[1] + dx
        d = blackcell[2]
        if 0 <= nh < H and 0 <= nw < W and cell[nh][nw] == '.':
            cell[nh][nw] = '#'
            painted.append([nh, nw, d + 1])
        ans = d

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

N = int(input())
a = [int(x) for x in input().split()]
mod = 10**9+7
#最小公倍数を割った商の和を求める
import fractions
from functools import lru_cache
@lru_cache(maxsize=20000000)
def gcd(x,y):
    if x >= y:
        b = x % y
        return gcd(b,y)
    return fractions.gcd(x,y)
lcm = a[0]
for i in range(1,N):
    lcm = lcm * a[i] // gcd(lcm,a[i])
ans = 0
for i in range(N):
    ans = (ans + (lcm//a[i]))%mod
print(ans)

### FIXED CODE ###

N = int(input())
a = [int(x) for x in input().split()]
mod = 10**9+7
#最小公倍数を割った商の和を求める
import fractions
lcm = a[0]
for i in range(1,N):
    lcm = lcm * a[i] // fractions.gcd(lcm,a[i])
ans = 0
for i in range(N):
    ans += lcm//a[i]
print(ans%mod)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n = int(input())
s = input()

d = {}
res = 0
for l1 in range(n):
    for l2 in range(l1+1,n+1):
        ss = s[l1:l2]
        if ss not in d:
            d[ss] = l1
        else:
            if d[ss]+len(ss)<=l1:
                res = max(res,len(ss))
print(res)


### FIXED CODE ###

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

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

ok = 0
ng = n//2+1

while ng-ok>1:
    mid = (ok+ng)//2

    d = {}
    isOk = False
    for l in range(n-mid+1):
        ss = s[l:l+mid]
        if ss not in d:
            d[ss] = l
        else:
            l2 = d[ss]
            if l2+mid<=l:
                isOk = True
                break

    if isOk:
        ok = mid
    else:
        ng = mid

print(ok)
### BUGGY CODE ###

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

d = []

for _ in range(a):
    d.append(1)
for _ in range(b):
    d.append(0)
for _ in range(c):
    d.append(-1)
count=0
for i in range(k):
    count += d[i]


print(count)

### FIXED CODE ###

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

if k <= a:
    print(k)
elif k <= a +b:
    print(a)

else:
    print(a -(k-a-b))
### BUGGY CODE ###

def main():
    N,Y = map(int,input().split())
    Y //= 1000
    for i in range(N+1):
        for j in range(N+1-i):
            for k in range(N+1-i-j):
                if i+j+k == N and 10*i + 5*j + k == Y:
                    print(i,j,k)
                    exit()
    print(-1,-1,-1)

if __name__ == '__main__':
    main()


### FIXED CODE ###

N,Y = map(int,input().split())
Y //= 1000
for i in range(N+1):
    for j in range(N+1-i):
        if 10*i + 5*j + 1*(N-i-j) == Y:
            print(i,j,N-i-j)
            exit()
print(-1,-1,-1)
### BUGGY CODE ###

N = int(input())

ans = 0
for i in range(1,N):
    ans += i
print(ans)

### FIXED CODE ###

N = int(input())

ans = (N - 1) * N // 2
print(ans)
### BUGGY CODE ###

k=int(input())
s=7
x=10000000
for i in range(x):
    if(s%k==0):
        print(i+1)
        break
    s=(s%k)*10+7
if(s%k!=0):
    print("-1")

### FIXED CODE ###

def phi(n):
    res = n
    i = 2
    while i * i <= n:
        if n % i == 0:
            res = res // i * (i - 1)
            while n % i == 0:
                n //= i
        i += 1
    if n != 1:
        res = res // n * (n - 1)
    return res


def divisors(n):
    sq = int(n ** .5)
    res = ((i, n // i) for i in range(1, sq + 1) if n % i == 0)
    from itertools import chain
    flatten = chain.from_iterable
    return sorted(set(flatten(res)))


def f(K):
    L = 9 * K
    if K % 7 == 0:
        L //= 7
    r1 = phi(L)
    for d in divisors(r1):
        if pow(10, d, L) == 1:
            return d
    return -1


###
if __name__ == '__main__':
    K = int(input())
    res = f(K)
    print(res)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

D = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for _ in range (D)]
M = 26
INF = 10**20

def judge(t):
    last = [0]*M
    score = 0
    for i in range(D):
        score += S[i][t[i]-1]
        last[t[i]-1] = i+1
        for m in range(M):
            score -= C[m]*(i+1-last[m])
    return score

from random import randint
import time
start = time.time()
ans = [0]*D
lasts = [0]*(M+1)


score = 0
for i in range(D):
    contest = 0
    max_score = -INF
    for m in range(M):
        new_score = score
        new_score += S[i][m]
        for m2 in range(M):
            if m==m2:continue
            new_score -= C[m2]*(i+1-lasts[m2])
        if new_score>max_score:
            contest = m+1
            max_score = new_score
    
    ans[i] = contest
    lasts[contest-1] = i+1
    score = max_score

while (time.time()-start<1.9):
    # 解を変更
    new_ans = [a for a in ans]
    idx = randint(0,D-1)
    val = randint(1,26)
    new_ans[idx] = val
    # スコアが上がっているか？
    new_score = judge(new_ans)
    if new_score>score:
        score = new_score
        ans[idx] = val

for a in ans:
    print(a)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

D = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for _ in range (D)]
M = 26
INF = 10**20

ans = [0]*D
lasts = [0]*(M+1)

for i in range(D):
    score = -INF
    contest = 0
    for m in range(1,M+1):
        cur = S[i][m-1]
        cur -= C[m-1]*(i+1-lasts[m])
        if cur>score:
            score = cur
            contest = m
    ans[i] = contest

for a in ans:
    print(a)
### BUGGY CODE ###

def main():
    k, s = map(int, input().split())
    # print(k, s)
    ans = 0
    for z in range(k+1):
        if z <= s:
            for y in range(k+1):
                if z + y <= s:
                    for x in range(k+1):
                        if x + y + z == s:
                            ans += 1
                            break
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    k, s = map(int, input().split())
    # print(k, s)
    ans = 0
    for z in range(k+1):
        if z <= s:
            for y in range(k+1):
                x = s - z - y
                if 0 <= x and x <= s and x <= k:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()