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

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

# 早期終了

if len(set(A)) != len(A):
    print(0)
    exit()
if len(set(B)) != len(B):
    print(0)
    exit()


def ret_n_given_x(x):
    flgA = True if x in A else False
    flgB = True if x in B else False
  #  print(flgA, flgB)
    if flgA and flgB:
        return 1
    elif flgA:
        ret = 0
        for b in B:
            if x <= b:
                ret += 1
        return ret
    elif flgB:
        ret = 0
        for a in A:
            if x <= a:
                ret += 1
        return ret
    else:
        retb = 0
        for b in B:
            if x <= b:
                retb += 1
        reta = 0
        for a in A:
            if x <= a:
                reta += 1
        return (retb * reta)-(N*M-x)


MOD = 10**9 + 7
ans = 1
for x in range(N * M, 0, -1):
    ans *= ret_n_given_x(x)
    ans %= MOD
#    print(x, ans, ret_n_given_x(x))
    if ans == 0:
        break

print(int(ans))


### FIXED CODE ###

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

# 早期終了

if len(set(A)) != len(A):
    print(0)
    exit()
if len(set(B)) != len(B):
    print(0)
    exit()

# 高速化のため事前ソート

A.sort(reverse=True)
B.sort(reverse=True)

n_A, n_B = 0, 0  # ある数よりも大きい要素数(単調増加)
# この問題は場合分けを思いつけるか、計算量を減らせるかにかかっている
# 与えられた集合の中にxょり大きい要素がいくつあるかという処理に大きく時間がかかっている
# これをn_Aとおくと、n_Aには単調増加性があることがすぐにわかる
# xをどんどん小さくしているからである。
# n_Aを逐一計算する代わりに、いままでの情報を使ってn_Aを求められると処理が高速化される
# A=[182, 181, 180, 179, 178, 176, 175, 169, 168, 167, 158, 151, 147, 129]とする(sorted)とすると、
# A[n_A]=xとなるn_Aがほしい。xが登場するまでのイテレーションでx_pre in Aとなる要素があるたび、その回数をカウントすればよい
#


def ret_n_given_x(x):
    global n_A, n_B
    flgA = False
    flgB = False
    for a in A[n_A:]:
        if a == x:
            flgA = True
            break
    for a in B[n_B:]:
        if a == x:
            flgB = True
            break
    if flgA and flgB:
        n_A += 1  # 上記で解説した個数カウント
        n_B += 1  # xより大きな要素が何個あったかついでに記録できる
        return 1
    elif flgA:
        n_A += 1
        return n_B
    elif flgB:
        n_B += 1
        return n_A
    else:
        return (n_A * n_B)-(N*M-x)


MOD = 10**9 + 7
ans = 1
for x in range(N * M, 0, -1):
    ans *= ret_n_given_x(x)
    ans %= MOD
    # print(x, ans, ret_n_given_x(x))
    if ans == 0:
        break

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

s = input() #sys.stdin.readlineは最後が改行
n =len(s)

num=0
tmp=0

amari= [0]

for i in range(n):
    num = tmp + int(s[-1-i])*(10**(i))
    tmp = num%2019
    amari.append(tmp)

from collections import Counter
ctr = Counter(amari)
ans = 0
for val in ctr.values():
        ans += val*(val-1)//2
print(ans)


### FIXED CODE ###

s = input() #sys.stdin.readlineは最後が改行
n =len(s)

from collections import defaultdict
amari = defaultdict(lambda:0)
amari[0]=1
num=0
tmp=0
ans =0

for i in range(n):
    num = tmp + int(s[-1-i])*pow(10,i,2019)
    tmp = num%2019
    amari[tmp]+=1

    if amari[tmp]>1:
        val = amari[tmp]
        ans -= (val-1)*(val-2)//2
        ans += (val)*(val-1)//2

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

n, q = map(int, input().split())
s = input()
ls = [[int(_) for _ in input().split()] for _ in range(q)]

for i in range(q):
	sp = s[ls[i][0] - 1:ls[i][1]]
	print(sp.count('AC'))

### FIXED CODE ###

n, q = map(int, input().split())
s = input()
ls = [[int(_) for _ in input().split()] for _ in range(q)]

csm = [0]
cnt = 0

for i in range(n - 1):
	if s[i:i+2] == 'AC':
		cnt += 1
	csm.append(cnt)
	
for j in range(q):
	print(csm[ls[j][1] - 1] - csm[ls[j][0] - 1])
### BUGGY CODE ###

import heapq as hq

def main():
    n,q = map(int, input().split())
    tl = []
    ins = list()
    dlt = list()
    for _ in range(n):
        s,t,x = map(int, input().split())
        tl.append((s-x,1,x))
        tl.append((t-x,0,x))
    for _ in range(q):
        t = int(input())
        tl.append((t,2))
    tl.sort()

    for x in tl:
        if x[1] == 1:
            hq.heappush(ins, x[2])
        elif x[1] == 0:
            hq.heappush(dlt, x[2])
            while dlt and ins[0] == dlt[0]:
                hq.heappop(ins)
                hq.heappop(dlt)
        else:
            print(-1 if not ins else ins[0])
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n,q = map(int, input().split())
    tl = []
    que = []
    d = dict()
    for _ in range(n):
        s,t,x = map(int, input().split())
        tl.append((s-x,1,x))
        tl.append((t-x,0,x))
    for _ in range(q):
        t = int(input())
        tl.append((t,2))
    tl.sort()
    wor = set()
    wcur = 0
    cur = -1
    flg = 0
    for x in tl:
        if x[1] == 1:
            wcur += 1
            wor.add(x[2])
            if cur < 0 or x[2] < cur:
                cur = x[2]
                flg = 0
        elif x[1] == 0:
            wcur -= 1 
            wor.remove(x[2])
            if x[2] == cur:
                flg = 1
            if not wcur:
                cur = -1
                flg = 0
        else:
            if flg:
                cur = min(wor)
                flg = 0
            print(cur)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())
T = [int(input()) for _ in range(N)]

T = sorted(list(set(T)))
T_max = T[len(T) - 1]
count = 1
flag_1 = True
while flag_1:
    check = T_max * count 
    flag_2 = True
    for i in T:
        if check % i != 0:
            flag_2 = False
    if flag_2 == True:
        print(T_max * count)
        flag_1 = False
    count += 1

### FIXED CODE ###

N = int(input())
T = [int(input()) for _ in range(N)]

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
      
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
  
print(lcm_list(T))
### BUGGY CODE ###

def read_key():
    a, _ = map(int, input().split())
    m = 0
    for c in map(int, input().split()):
        m |= 1 << (c - 1)
    return (a, m)

from sys import setrecursionlimit
setrecursionlimit(1000000)
INF = float('inf')

N, M = map(int, input().split())
keys = [read_key() for _ in range(M)]

dp = [INF] * (1 << N)
def solve(keys, amount, cm):
  if cm == (1 << N) - 1:
    return amount
  if len(keys) == 0:
    return INF
  a, m = keys[0]
  if dp[cm | m] < amount + a:
    return solve(keys[1:], amount, cm)
  else:
    dp[cm | m] = amount + a
    return min(solve(keys[1:], amount, cm), solve(keys[1:], amount + a, cm | m))

t = solve(keys, 0, 0)
if t == INF:
  print(-1)
else:
  print(t)


### FIXED CODE ###

def read_key():
    a, _ = map(int, input().split())
    m = 0
    for c in map(int, input().split()):
        m |= 1 << (c - 1)
    return (a, m)


def main():
    INF = float('inf')

    N, M = map(int, input().split())
    keys = [read_key() for _ in range(M)]

    dp = [[INF] * (1 << N) for _ in range(M + 1)]

    dp[0][0] = 0
    for i in range(M):
        a, m = keys[i]
        dpi = dp[i]
        dpi1 = dp[i + 1]
        for j in range(1 << N):
            if dpi[j] == INF:
                continue
            if dpi[j] + a < dpi1[j | m]:
                dpi1[j | m] = dpi[j] + a
            if dpi[j] < dpi1[j]:
                dpi1[j] = dpi[j]

    if dp[M][(1 << N) - 1] == INF:
        print(-1)
    else:
        print(dp[M][(1 << N) - 1])


main()
### BUGGY CODE ###

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

#N <=2*10**3
#総当たりはN*(N-1) = 4*10**6　間に合う

ans_dict = {i:0 for i in range(1,N+1)}

for i in range(1,N+1):
    for j in range(i+1,N+1):
        #print(i,j)
        #ストレートで行くパターン
        straight = j-i
        #XYを経由するパターン
        throught_XY = min(abs(X-i),abs(Y-i))+min(abs(X-j),abs(Y-j))+1
        
        distance = min(straight,throught_XY)
        
        ans_dict[distance] += 1
        
for i in range(1,N):
    print(ans_dict[i])

### FIXED CODE ###

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

#N <=2*10**3
#総当たりはN*(N-1) = 4*10**6　間に合う

ans_dict = {i:0 for i in range(1,N+1)}

for i in range(1,N+1):
    for j in range(i+1,N+1):
        #print(i,j)
        #ストレートで行くパターン
        straight = j-i
        #XYを経由するパターン
        throught_XY = min(abs(X-i),abs(Y-i))+min(abs(X-j),abs(Y-j))+1
        
        distance = min(straight,throught_XY)
        
        ans_dict[distance] += 1
        
for i in range(1,N):
    print(ans_dict[i])
### BUGGY CODE ###

k, s = [int(i) for i in input().split()]

res = 0

for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i + j + l == s:
                res += 1
                break

print(res)

### FIXED CODE ###

k, s = [int(i) for i in input().split()]

res = 0

for i in range(k+1):
    for j in range(k+1):
        temp = s - i - j
        if temp >= 0 and temp <= k:
            res += 1
print(res)
### BUGGY CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
l=[]
c=1
i=0

f=True
while True:
    i+=1
    c=a[c-1]
    b=len(l)
    l.append(c)
    l=list(set(l))
    if len(l)==b:
        f=False
        break
    if c==2:break
if f:print(i)
else:print(-1)

### FIXED CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
l=[]
c=1
i=0
f=False
for _ in range(100001):
    i+=1
    c=a[c-1]
    if c==2:
        f=True
        break
if f:print(i)
else:print(-1)
### BUGGY CODE ###

from numpy import int64
from numba import njit
from scipy.optimize import minimize,Bounds

d,*s=map(int,open(0).read().split())
s=int64(s)
@njit('i8(f8[:])')
def func(x):
    x=x.astype(int64)
    if x.max()>25 or x.min()<0:return 0
    last=[0]*26
    score=0
    for i,v in enumerate(x,1):
        last[v]=i
        c=0
        for j in range(26):
            c+=s[j]*(last[j]-i)
        score=score+s[i*26+v]-c
    return-score

x0=([*range(26)]*15)[:d]
res=minimize(func,x0,method='Powell',bounds=Bounds(0,25)).x.astype(int64)+1
for t in res:print(t)

### FIXED CODE ###

from time import time
from random import randint

from numba import njit
from numpy import int64

@njit('i8(i8[:],i8[:])')
def func(s,x):
    last=[0]*26
    score=0
    for i,v in enumerate(x,1):
        last[v]=i
        c=0
        for j in range(26):
            c+=s[j]*(last[j]-i)
        score=score+s[i*26+v]-c
    return score

def main():
    start=time()
    d,*s=map(int,open(0).read().split())
    s=int64(s)
    x=int64(([*range(26)]*15)[:d])
    M=func(s,x)
    while time()-start<1:
        y=x.copy()
        y[randint(0,d-1)]=randint(0,25)
        t=func(s,y)
        if t>M:
            M=t
            x=y
    print(*x+1,sep='\n')

main()
### BUGGY CODE ###

import bisect
N = int(input())
A = [int(input())]
for k in range(N-1):
    t = int(input())
    if A[0] >= t:
        A = [t] + A
    else:
        A[bisect.bisect_left(A,t)-1] = t
print(len(A))


### FIXED CODE ###

import bisect
import sys
from collections import deque

def main():
    input = sys.stdin.readline
    N = int(input())
    A = deque([int(input())])
    for k in range(N-1):
        t = int(input())
        if A[0] >= t:
            A.appendleft(t)
        else:
            A[bisect.bisect_left(A,t)-1] = t
    print(len(A))

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

from itertools import accumulate

MOD = 10 ** 9 + 7

N, K = map(int, input().split())
As = list(map(int, input().split()))

dp = [0] * (K+1)
dp[0] = 1
for A in As:
    accDP = [0] + list(accumulate(dp))
    accDP = [accDPi % MOD for accDPi in accDP]
    dp = [(accDP[j+1] - accDP[max(0, j-A)]) % MOD for j in range(K+1)]

print(dp[K])


### FIXED CODE ###

from itertools import accumulate

MOD = 10 ** 9 + 7

N, K = map(int, input().split())
As = list(map(int, input().split()))

dp = [0] * (K+1)
dp[0] = 1
for A in As:
    accDP = [0] + list(accumulate(dp))
    accDP = [accDPi % MOD for accDPi in accDP]
    dp = [(accDP[j+1] - accDP[max(0, j-A)]) % MOD for j in range(K+1)]

print(dp[K])
### BUGGY CODE ###

from sys import stdin
from collections import namedtuple
from heapq import heappush, heappop

input = stdin.readline


class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n + 1)]
    self.size = [1] * (n + 1)

  def is_same(self, a, b):
    return self.find(a) == self.find(b)

  def unite(self, a, b):
    a = self.find(a)
    b = self.find(b)  
    if self.size[a] < self.size[b]:
      a, b = b, a
    self.par[b] = a
    self.size[a] += self.size[b]

  def size_of(self, a):
    return self.size[self.find(a)]

  def find(self, a):
    if a == self.par[a]:
      return a
    self.par[a] = self.find(self.par[a])
    return self.par[a]

Edge = namedtuple('Edge', 'w s t')
X = namedtuple('X', 'x i')
Y = namedtuple('Y', 'y i')

N = int(input())

edges = []
xg = []
yg = []

for i in range(N):
  x, y = map(int, input().split())
  xg.append(X(x, i))
  yg.append(Y(y, i))

xg.sort()
yg.sort()

for i in range(N - 1):
  x1, a = xg[i]
  x2, b = xg[i + 1]
  heappush(edges, Edge(abs(x1 - x2), a, b))

for i in range(N - 1):
  y1, a = yg[i]
  y2, b = yg[i + 1]
  heappush(edges, Edge(abs(y1 - y2), a, b))

u = UnionFind(N)
cost = 0

while edges:
  if u.size_of(0) >= N:
    break

  w, s, t = heappop(edges)
  if u.is_same(s, t):
    continue
  u.unite(s, t)
  cost += w

print(cost)


### FIXED CODE ###

from collections import namedtuple


class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n + 1)]
    self.size = [1] * (n + 1)

  def is_same(self, a, b):
    return self.find(a) == self.find(b)

  def unite(self, a, b):
    a = self.find(a)
    b = self.find(b)  
    if self.size[a] < self.size[b]:
      a, b = b, a
    self.par[b] = a
    self.size[a] += self.size[b]

  def size_of(self, a):
    return self.size[self.find(a)]

  def find(self, a):
    if a == self.par[a]:
      return a
    self.par[a] = self.find(self.par[a])
    return self.par[a]

Edge = namedtuple('Edge', 'w s t')
X = namedtuple('X', 'x i')
Y = namedtuple('Y', 'y i')

N = int(input())

edges = []
xg = []
yg = []

for i in range(N):
  x, y = map(int, input().split())
  xg.append(X(x, i))
  yg.append(Y(y, i))

xg.sort()
yg.sort()

for i in range(N - 1):
  x1, a = xg[i]
  x2, b = xg[i + 1]
  edges.append(Edge(abs(x1 - x2), a, b))

for i in range(N - 1):
  y1, a = yg[i]
  y2, b = yg[i + 1]
  edges.append(Edge(abs(y1 - y2), a, b))

edges.sort()

u = UnionFind(N)
cost = 0

for w, s, t in edges:
  if u.is_same(s, t):
    continue
  u.unite(s, t)
  cost += w

print(cost)
### BUGGY CODE ###

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

b = [[] for i in range(a[0])]

c = [0 for i in range(a[2])]

co = 0
for i in range(a[1]):
    n,m = map(int,input().split())

    b[m-1].append(n)
    
for i in range(a[2]):
    n,m = map(int,input().split())
    for j in range(n-1,m):
        for k in range(len(b[j])):
            if b[j][k] >= n:
                co += 1
    print(co)
    co = 0

### FIXED CODE ###

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

c = [[0 for i in range(a[0]+1)] for j in range(a[0]+1)]

for i in range(a[1]):
    n,m = map(int,input().split())
    c[n][m] += 1

d = [[0 for i in range(a[0]+4)] for j in range(a[0]+4)]

for i in range(a[0]+1):
    for j in range(a[0]+1):
        d[i][j+1] = d[i][j] + c[i][j]

for i in range(a[2]):
    n,m = map(int,input().split())
    s = 0
    for j in range(n,m+1):
        s += d[j][m+1] - d[j][j]
    print(s)
### BUGGY CODE ###

# Me
def resolve(k, s):
    c = 0
    for x in range(0, k+1):
        for y in range(0, k+1):
            for z in range(0, k+1):
                if x + y + z == s:
                    c += 1
    return c


k, s = map(int, input().split())
print(resolve(k, s))


### FIXED CODE ###

# Me
def resolve(k, s):
    c = 0
    for x in range(0, k+1):
        for y in range(0, k+1):
            if 0 <= s - (x + y) <= k:
                c += 1
    return c


k, s = map(int, input().split())
print(resolve(k, s))
### BUGGY CODE ###

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

import collections
import copy

ans = 0

for i in range(len(A)):
  ans = 0
  list = copy.copy(A)
  list.pop(i)
  c = collections.Counter(list)
  for v in c.values():
    ans += (v*(v-1)/2)
  print(int(ans))

### FIXED CODE ###

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

tot = 0
c = collections.Counter(copy.copy(A))
for v in c.values():
  tot += (v*(v-1)/2)

for n in A:
  ans = tot
  ans -= c[n]*(c[n]-1)/2
  ans += (c[n]-1)*(c[n]-2) / 2 
  print(int(ans))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]
dic = {}
for p, y in PY:
    dic[p] = (dic.get(p) or []) + [y]
for p, v in dic.items():
    dic[p] = {x: i+1 for i, x in enumerate(sorted(v))}
[print(str(1*10**12+p*10**6+dic[p][y])[1:]) for p, y in PY]


### FIXED CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
PY = [map(int, input().split()) for i in range(M)]
PYI = sorted((p, y, i+1) for i, (p, y) in enumerate(PY))
def gen():
  pre = -1
  count = -1
  for p, y, i in PYI:
    if p == pre:
      count += 1
      yield (i, str(1*10**12+p*10**6+count)[1:])
    else:
      count = 1
      yield (i, str(1*10**12+p*10**6+count)[1:])
      pre = p
print('\n'.join(i[1] for i in sorted(gen())))
### BUGGY CODE ###

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

ans = "IMPOSSIBLE"

if a < b:
  for i in range(a, b):
    if abs(a-i) == abs(b-i):
      ans = str(i)
      break
else:
  for i in range(b, a):
    if abs(a-i) == abs(b-i):
      ans = str(i)
      break
  
print(ans)

### FIXED CODE ###

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

kari = (a + b) /2

if (a + b ) % 2 != 0:
  print('IMPOSSIBLE')
else:
  print(int((a+b)/2))
### BUGGY CODE ###

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

if N==1:
  print(1)
  exit()

A = []
a_prev = None
for i in range(M):
  a_i = int(input())
  if a_prev == a_i:
    print(0)
    exit()
  A.append(a_i)
  a_prev = a_i

N_2 = 1
N_1 = 1  
ans = 0
for i in range(1, N):
  if i in A:
    N_1 = 0
  ans = (N_1 + N_2)%1000000007
  N_2 = N_1
  N_1 = ans
print(ans)


### FIXED CODE ###

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

if N==1:
  print(1)
  exit()

A = [0]*N
a_prev = None
for i in range(M):
  a_i = int(input())
  if a_prev == a_i:
    print(0)
    exit()
  A[a_i] = 1  
  a_prev = a_i

N_2 = 1
N_1 = 1  
ans = 0
for i in range(1, N):
  if A[i]==1:
    N_1 = 0
  ans = (N_1 + N_2)%1000000007
  N_2 = N_1
  N_1 = ans
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3

import math

def is_natural(x):
    if x % 1 == 0 and x >= 1:
        return True
    else:
        return False



n = int(input())


for i in range(1, n + 1):
    result = 0
    if i >= 6:
        for j in range(2, int(math.sqrt(2 * i - 8)) + 1):
            for k in range(2, int(math.sqrt(2 * i - 8)) + 1 ):
                if 2 * i - j ** 2 - k ** 2 < 2:
                    break
                else:
                    r = math.sqrt(2 * i - j ** 2 - k ** 2)

                    if r >= 2 and r % 1 == 0:
                        a = j
                        b = k
                        c = r
                        x = (c + a - b) / 2
                        y = (a + b - c) / 2
                        z = (b + c - a) / 2
                        if is_natural(x) and is_natural(y) and is_natural(z):
                            result += 1

    print(result)







### FIXED CODE ###

#!/usr/bin/env python3

import math

n = int(input())

result = [0] * (n + 1)
border = 0
if n>=3:
    border = int(math.sqrt(n - 2))
for x in range(1, border):
    for y in range(1, border):
        for z in range(1, border):
            r = ((x + y) ** 2 + (y + z) ** 2 + (z + x) ** 2) // 2
            if r > n:
                break
            else:
                result[r] += 1

for num in result[1::]:
    print(num)
### BUGGY CODE ###

n = int(input())
s = input()
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            for k in range(j+1,n):
                if s[k] not in (s[i],s[j]):
                    if j-i != k-j:
                        cnt +=1
print(cnt)

### FIXED CODE ###

n = int(input())
s = input()
cnt = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if 2*j-i > n-1:
                break
            if s[2*j-i] not in(s[i],s[j]):
                cnt -= 1
print(cnt)
### BUGGY CODE ###

r,g,b,n=map(int,input().split())
cnt=0
end=0
for i in range(0,3001):
    for j in range(0,3001):
        bb=n-(i*r+j*g)
        s=bb+i*r+j*g
        if bb<0:
            continue
        if s==n and bb%b==0:
            #print(i,j,bb)
            cnt+=1
        if j*g>n:break
    if i*r>n:break
print(cnt)

### FIXED CODE ###

r,g,b,n=map(int,input().split())
cnt=0
for i in range(0,n+1):
    for j in range(0,n-i+1):
        bb=n-(i*r+j*g)
        s=bb+i*r+j*g
        if bb<0:
            continue
        if s==n and bb%b==0:
            cnt+=1
        if j*g>n or i*r>n or s-bb>n:break
    if i*r>n:break
print(cnt)
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    s = sys.stdin.readline().strip()
    x, y = map(int, sys.stdin.readline().split())

    n = len(s)
    stack = [(0, (0, 0), (0, 1))]
    while len(stack) > 0:
        i, (yi, xi), (dy, dx) = stack.pop()

        while i < n:
            if s[i] == 'F':
                yi += dy
                xi += dx
            else:
                stack.append((i + 1, (yi, xi), (dx, -dy)))
                tmp = dy
                dy = -dx
                dx = tmp
            i += 1

        if yi == y and xi == x:
                print('Yes')
                break
    else:
        print('No')

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from itertools import islice

def reachable(steps, x):
    m = len(steps)
    if m == 0:
        return x == 0
    n = sum(steps) + 1
    if n <= x:
        return False
    dp = [[False] * n for _ in range(m)]
    dp[0][steps[0]] = True
    for i, step in enumerate(islice(steps, 1, None)):
        for j in range(n):
            if dp[i][j] == True:
                dp[i + 1][j + step] = True
                if j - step >= 0:
                    dp[i + 1][j - step] = True
    return dp[-1][x]


def main():
    s = sys.stdin.readline().strip()
    x, y = map(int, sys.stdin.readline().split())

    i = s.find('T')
    if i != -1:
        x -= i
        i += 1
    else:
        i = len(s)
        x -= i

    xsteps = []
    ysteps = []
    cnt = 0
    nturns = 0
    for c in islice(s + 'T', i, None):
        if c == 'F':
            cnt += 1
            continue
        if cnt > 0:
            if nturns % 2 != 0:
                xsteps.append(cnt)
            else:
                ysteps.append(cnt)
            cnt = 0
        nturns += 1

    if reachable(xsteps, abs(x)) == True and reachable(ysteps, abs(y)) == True:
        print('Yes')
    else:
        print('No')

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

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

ans = 0
for i in range(n-1):
  for j in range(i+a[i],n):
    if j-i==a[j]+a[i]:
      ans += 1

print(ans)

### FIXED CODE ###

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

left = defaultdict(int)
for i in range(n):
    left[i + a[i]] += 1

ans = 0
for i in range(n):
    sub = i - a[i]
    if sub in left:
        ans += left[sub]

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

K=int(input())
if K%2==0:
  print(-1)
else:
  a=''
  c=0
  for i in range(10**7):
    a+='7'
    c+=1
    if int(a)%K==0:
      print(c)
      exit()


### FIXED CODE ###

K=int(input())
mod=9*K
n=1
if K%7==0:
  mod=mod//7
for i in range(1,K+1):
  n=n*10%mod
  if n==1:
    print(i)
    exit()
print(-1)