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

import numpy
K = int(input())

def seven(n):
    a = 0
    for i in range(1,n+1):
        a += 10**(i-1) * 7
    return a        

def main():
    ans = 0
    i = 1
    if K %2 == 0:
        ans = -1
    else:
        while True:
        #for _ in range(10):
            num = seven(i)
            a = K * num
            b = [int(x) for x in list(str(a))]
            if numpy.all(numpy.array(b) == 7):
                ans = len(b)
                break
            else:
                i += 1
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

K = int(input())

ai =0
ans = 0
# i = 1
l = set()

if K %2 == 0:
    ans = -1
else:
    for i in range(K):
        ai = (ai * 10 + 7) % K
        if ai == 0:
            ans = i+1
            break
        else:
            if ai in l:
                ans = -1
                break
            else:
                l.add(ai)
print(ans)
### BUGGY CODE ###

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

ans = 0

minA = min(A)

for i in range(len(A)):
        if A[i] == minA:
                A[i] = 0
        else:
                A[i] = 1

while sum(A) != 0:
        if len(A) <= K:
                ans += 1
                break
        if A[0] == 0:
                if A[1] == 0:
                        A = A[1:]
                elif 0 in A[1:1+K]:
                        A[K] = 0
                        A = A[K:]
                        ans += 1
                else:
                        A[K-1] = 0
                        A = A[K-1:]
                        ans += 1
        else:
                A = A[K-1:]
                ans += 1
print(ans)

### FIXED CODE ###

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

print((N-1)//(K-1)+((N-1)%(K-1)!=0))
### BUGGY CODE ###

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

for i in range(n):
    xx =list( x)
    xx.pop(i)
    xx=sorted(xx)
    print(xx[(n-1)//2])

### FIXED CODE ###

n = int(input())
xx = list(map(int, input().split()))
x=sorted(xx)

for i in range(n):
    if xx[i] < x[n //2]:
        print(x[n // 2])
    else:
        print(x[(n - 1) // 2])
### BUGGY CODE ###

n=int(input())
lst=[int(input()) for i in range(5)]
l=[0]*5
l.insert(0,n)
ans=0
while l[5]!=n:
    for i in range(5,0,-1):
        if l[i-1]!=0:
            res=min(l[i-1],lst[i-1])
            l[i]+=res
            l[i-1]-=res
        
    ans+=1
   
print(ans)

### FIXED CODE ###

n=int(input())
lst=[int(input()) for i in range(5)]
m=min(lst)
import math
print(math.ceil(n/m)+4)
### BUGGY CODE ###

def C_GreenBin():
    N = int(input())
    s = []
    for x in range(N):
        s.append(sorted(input()))
    result = 0
    s.sort()
    for i in range(0, N - 1):
        for j in range(i + 1, N):
            if s[i] == s[j]:
                result += 1
            else:
                break
    print(result)
    
if __name__ == "__main__":
    C_GreenBin()

### FIXED CODE ###

def C_GreenBin():
    from collections import Counter
    N = int(input())
    s = []
    for x in range(N):
        list_tmp = sorted(input())
        s.append("".join(list_tmp))
    result = 0
    s_tmp = Counter(s)
    for x in s_tmp.values():
        if x > 1:
            result += ((x - 1) * x) // 2
    print(result)
    
if __name__ == "__main__":
    C_GreenBin()
### BUGGY CODE ###

N = int(input())
lists = list(map(int, input().split()))
count = 0
for i in range(0,N):
    for j in range(0,i):
        if lists[i] > lists[j]:
            break
    else:
        count = count + 1
print(count)

### FIXED CODE ###

N = int(input())
lists = list(map(int, input().split()))
count = 1
mins = lists[0]
for i in range(1,N):
    if lists[i] <= mins:
        count = count + 1
        mins = lists[i]
print(count)
### BUGGY CODE ###

#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

n,m = ip()
graph = {i:[] for i in range(1,n+1)}
for i in range(m):
    a,b = ip()
    graph[a].append(b)
    graph[b].append(a)

start = 1
nodes = list(graph.keys())
d = {i:float('inf') for i in nodes}
parent = {i:-1 for i in nodes}
q = set([i for i in nodes])
d[start] = 0

while len(q):
    mn = float('inf')
    for v in nodes:
        if d[v] < mn and v in q:
            mn = d[v]
            u = v
    q.remove(u)
    for v in graph[u]:
        if d[u]+1 < d[v] and v in q:
            d[v] = d[u] + 1
            parent[v] = u

if float('inf') in list(d.values()):
    print("No")
    exit()
print("Yes")
for i in range(2,n+1):
    print(parent[i])







### FIXED CODE ###

#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

n,m = ip()
graph = {i:[] for i in range(1,n+1)}
for i in range(m):
    a,b = ip()
    graph[a].append(b)
    graph[b].append(a)

parent = {i:-1 for i in range(1,n+1)}
parent[1] = 0
q = [1]
while len(q):
    u = q.pop(0)
    for v in graph[u]:
        if parent[v] == -1:
            q.append(v)
            parent[v] = u

if -1 in list(parent.values()):
    print("No")
    exit()
print("Yes")
for i in range(2,n+1):
    print(parent[i])
### BUGGY CODE ###

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


k = int(input())
res = []

ans = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        res.append(gcd(i, j))
        
for n in range(1, k + 1):
    for r in list(res):
        ans += gcd(int(r), n)

print(ans)


### FIXED CODE ###

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

k = int(input())
res = [0] * (k + 1)

ans = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        res[gcd(i, j)] += 1

for n in range(1, k + 1):
    for r in range(1, k + 1):
        ans += gcd(r, n) * res[r]

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

L, R = map(int, input().split())

if L <= 2019 and 2019 <= R:
    ans = 0

else:
    ans = 2019
    for i in range(L, R):
        for j in range(L+1, R+1):
#             print(i, j)
            tmp = (i*j) % 2019
            if tmp <= ans:
                ans = tmp

print(ans)

### FIXED CODE ###

import sys

L, R = map(int, input().split())

if L <= 2019 and 2019 <= R:
    ans = 0

else:
    ans = 2019
    for i in range(L, R):
        for j in range(L+1, R+1):
            if (i % 2019 == 0) or (j % 2019 == 0):
                ans = 0
                print(ans)
                sys.exit()
            tmp = (i*j) % 2019
            if tmp <= ans:
                ans = tmp
print(ans)
### BUGGY CODE ###

a = int(input())
array = list(map(int, input().strip().split()))
out = 0
for i in range(a):
    minn = min(array[0:i+1])
    out = out + 1 if array[i] == minn else out
print(out)

### FIXED CODE ###

a = int(input())
array = list(map(int, input().strip().split()))
out = 0
min_num = array[0]
for i in array:
    min_num = min(min_num, i)
    out = out + 1 if i == min_num else out
print(out)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    A = [format(a, "b")[::-1] for a in A]
    a_sum = [int()]*60

    for a in A:
        for i, r_a in enumerate(a):
            if r_a == "1":
                a_sum[i] += 1

    a_sum = [a_s_*(2**i)%MOD for i, a_s_ in zip(range(60), a_sum)]
    a_acc_sum = [_ for _ in a_sum]
    for x in range(1,60):
        a_acc_sum[x] = a_acc_sum[x-1] + a_acc_sum[x] 
    
    ans = 0
    for a in A:
        for i, r_a in enumerate(a):
            if r_a == "0":
                ans += a_sum[i]
        
        ans += a_acc_sum[59] - a_acc_sum[i]

        # for ic in range(i+1,60):
            # ans+=a_sum[ic]
            # ans%=MOD

    print(ans%MOD)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    A = [format(a, "b")[::-1] for a in A]
    a_sum = [int()]*60

    for a in A:
        for i, r_a in enumerate(a):
            if r_a == "1":
                a_sum[i] += 1

    a_sum = [a_s_*(2**i)%MOD for i, a_s_ in zip(range(60), a_sum)]
    a_acc_sum = [_ for _ in a_sum]
    
    for x in range(1,60):
        a_acc_sum[x] = a_acc_sum[x-1] + a_acc_sum[x] 
    
    ans = 0
    for a in A:
        for i, r_a in enumerate(a):
            if r_a == "0":
                ans += a_sum[i]
        
        ans += a_acc_sum[59] - a_acc_sum[i]

        # for ic in range(i+1,60):
            # ans+=a_sum[ic]
            # ans%=MOD

    print(ans%MOD)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

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

N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))

for i in range(M):
  if T[i] in D:
    D.remove(T[i])
  else:
    print('NO')
    exit()
print('YES')

### FIXED CODE ###

N = int(input())
D = list(map(int,input().split()))
D.sort()
M = int(input())
T = list(map(int,input().split()))
T.sort()

dindex = 0
for i in range(M):
  while 1:
    dindex += 1
    if T[i] == D[dindex-1]:
      break
    elif dindex == N:
      print('NO')
      exit()
print('YES')
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]
for i in range(n): s[i] += s[i]
ans = 0
for i in range(n):
	s2 = []
	for j in s: s2.append(j[i:i+n])
	s2 += s2
	for k in range(n):
		flag = True
		for k2 in range(k,n+k):
			if any(s2[k2][k3]!=s2[k3+k][k2-k] for k3 in range(n)):
				flag = False
				break
		if flag: ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
s,s2,ans = s+s,[],0
for i in range(n):
	x = ""
	for j in s: x+=j[i]
	s2.append(x)
for i in range(n):
	flag = True
	for j in range(i,i+n):
		if s[j][1:n]!=s2[j-i][1+i:n+i]:
			flag = False
			break
	if flag: ans += n
print(ans)
### BUGGY CODE ###

k,s=map(int,input().split())
count=0
for x in range(k+1):
    for y in range(x+1):
        for z in range(y+1):
            if x+y+z==s:
                if x==y==z:
                    count+=1
                elif x==y or y==z or z==x:
                    count+=3
                else:
                    count+=6
print(count)







### FIXED CODE ###

k,s=map(int,input().split())
count=0
for x in range(k+1):
    for y in range(x+1):
        if x+y>s:
            continue
        else:
            z=s-x-y
            if z>x or z>y:
              continue
            if x==y==z:
                count+=1
            elif x==y or y==z or z==x:
                count+=3
            else:
                count+=6
print(count)
### BUGGY CODE ###

N = int(input())

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

c = N // 2 - 1

for i in range(N):
  xp = x.copy()
  st = xp.pop(i)
  xp.sort()
  print(xp[c])

### FIXED CODE ###

import copy

N = int(input())

x = list(map(int,input().split()))
sort_x = copy.copy(x)
sort_x.sort()

center_num = (N-1) // 2

for l in x:
    if l <= sort_x[center_num]:
        print(sort_x[center_num+1])
    else:
        print(sort_x[center_num])
### BUGGY CODE ###

import math

def prime_division(n):
    ans = []
    m = int(n ** 0.5)
    i = 2
    while i <= m:
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                n //= i
                cnt += 1
            ans.append((i, cnt))
            m = int(n ** 0.5)
        i += 1
    if n != 1:
        ans.append((n, 1))
    return ans

#  aabaaba  count+(N-1) C (N-1)

N,M=map(int,input().split())
pms=prime_division(M)
ans = 1
for pm in pms:
    #print(pm)
    ans *= math.factorial(pm[1]+(N-1)) // (math.factorial(pm[1]) * math.factorial(N-1))

print(ans % (10 ** 9 + 7))


### FIXED CODE ###

import math

def prime_division(n):
    ans = []
    m = int(n ** 0.5)
    i = 2
    while i <= m:
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                n //= i
                cnt += 1
            ans.append((i, cnt))
            m = int(n ** 0.5)
        i += 1
    if n != 1:
        ans.append((n, 1))
    return ans

#  aabaaba  count+(N-1) C (N-1)

N,M=map(int,input().split())
pms=prime_division(M)
ans = 1
for pm in pms:
    #print(pm)
    ans *= math.factorial(pm[1]+(N-1)) // (math.factorial(pm[1]) * math.factorial(N-1))

print(ans % (10 ** 9 + 7))
### BUGGY CODE ###

H,W = map(int,input().split())
S = []
height, ans = [0] * (W+1), 0
for i in range(H):
    s = list(input()) + [0]
    length = 0
    for j in range(W+1):
        if s[j] == '.':
            length += 1
            height[j] += 1
        else:
            s[j] = 0
            if length > 0:
                s = s[:(j-length)] + [length]*length + s[j:]
                length = 0
            if height[j] > 0:
                temp = max(S[i - k - 1][j] for k in range(height[j])) + height[j] - 1
                if ans < temp:
                    ans = temp
                height[j] = 0 
    S.append(s)

for j in range(W):
    if height[j] > 0:
        temp = max(S[i - k - 1][j] for k in range(height[j])) + height[j] - 1
        if ans < temp:
            ans = temp

print(ans)

### FIXED CODE ###

H,W = map(int,input().split())
height, width_max, ans = [0] * (W+1), [0] * (W+1), 0
for i in range(H):
    s = input() + '#'
    length = 0
    for j in range(W+1):
        if s[j] == '.':
            length += 1
            height[j] += 1
        else:
            if length > 0:
                for k in range(j-length, j):
                    if width_max[k] < length:
                        width_max[k] = length
                length = 0
            if height[j] > 0:
                temp = width_max[j] + height[j] - 1
                if ans < temp:
                    ans = temp
                width_max[j], height[j] = 0, 0
for j in range(W):
    if height[j] > 0:
        temp = width_max[j] + height[j] - 1
        if ans < temp:
            ans = temp
print(ans)
### BUGGY CODE ###

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

import statistics
import copy

def median(tmp_numbers):
    return statistics.median(tmp_numbers)

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))

    for i in range(n):
        tmp_numbers=copy.deepcopy(numbers)
        tmp_numbers.pop(i)
        ans = median(tmp_numbers)
        print(ans)

if __name__=="__main__":
    main()

### FIXED CODE ###

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

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    sort_numbers=sorted(numbers)
# left/right算出はsorted arrayで
    left=sort_numbers[n//2-1]
    right=sort_numbers[n//2]
# loopは元の配列で
    for i in numbers:
        if i > left:
            print(left)
        else:
            print(right)

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

#!/usr/bin/env python3
import sys

def main():
    N, Q = map(int, input().split())
    S = input()
    for i in range(Q):
        l, r = map(int, input().split())
        print(S[l-1:r].count('AC'))

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

def main():
    N, Q = map(int, input().split())
    S = input()
    ans = [None] * N
    ans[0] = S.count('AC')
    for i in range(1,N):
        ans[i] = ans[i-1]
        if S[i-1:i+1] == 'AC':
            ans[i] -= 1

    for i in range(Q):
        l, r = map(int, input().split())
        print(ans[l-1] - ans[r-1])

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

# coding: utf-8
# Your code here!
 
import bisect
from collections import defaultdict
import sys
sys.setrecursionlimit(int(1e6))
 
N, K = map(int, input().rstrip().split(' '))
X = sorted(list(map(int, input().rstrip().split(' '))))
 
i = bisect.bisect_left(X, 0)
X.insert(i, 0)
 
memo = defaultdict(lambda: defaultdict(lambda: -1))
 
def recursive(current_k, cost, i, left_i, right_i):
    if K == current_k:
        return cost
    if memo[current_k][i] != -1:
        return memo[current_k][i]
       
    left_cost = 1e10 
    if left_i >= 0:
        left_cost = recursive(current_k + 1, cost + X[i] - X[left_i], left_i, left_i - 1, right_i)
        
    right_cost = 1e10
    if right_i <= N:
        right_cost = recursive(current_k + 1, cost + X[right_i] - X[i], right_i, left_i, right_i + 1)
        
    min_cost = min(left_cost, right_cost)
    
    memo[current_k][i] = min_cost
    
    return min_cost
    
print(recursive(0, 0, i, i - 1, i + 1))

### FIXED CODE ###

# coding: utf-8
# Your code here!

N, K = map(int, input().rstrip().split(' '))
X = list(map(int, input().rstrip().split(' ')))

min_cost = int(1e10)
for i in range(K, N+1):
    min_cost = min(min_cost, X[i-1] - X[i-K] + min(abs(X[i-1]), abs(X[i-K])))
    
print(min_cost)
### BUGGY CODE ###

n=int(input());*a,=map(int,input().split())
for i in range(n):print(sorted(a[:i]+a[-~i:])[~-n//2])

### FIXED CODE ###

n=int(input());*a,=map(int,input().split());b=sorted(a);l,m=b[n//2-1],b[n//2]
for x in a:print([l,m][x<m])
### BUGGY CODE ###

def memoize(f):
    table = dict()
    def wrapper(x, a):
        key = (x, a)
        if key in table:
            return table[key]
        else:
            v = f(x, a)
            table[key] = v
            return v
    return wrapper

@memoize
def solve(x, a):
    if len(a) == 0:
        return 0

    if len(a) == 1:
        if a[0] == x:
            return 1
        else:
            return 0

    if x < a[0]:
        return solve(x, a[1:])
    else:
        m = solve(x - a[0], a[1:]) + 1
        n = solve(x, a[1:])
        return max(m, n)

def main():
    n, x = [int(s) for s in input().split()]
    a = tuple(int(s) for s in input().split())

    print(solve(x, a))

main()


### FIXED CODE ###

def main():
    n, x = [int(s) for s in input().split()]
    a = [int(s) for s in input().split()]
    a.sort()

    cnt = 0
    for i, y in enumerate(a):
        if x < y:
            break
        x -= y
        cnt += 1
    else:
        # distribute to all child
        if x != 0:
            cnt -= 1
    print(cnt)

main()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(500*500) # default 1000

class data():
    def __init__(self,N):
        self.to=[[] for j in range(N)] # N points
        self.c=[0]*N # N points
        self.x=[0]*N

def dfs(v,p=-1): # vertices & parent idx
    lst=data.to[v] # children list
    if p==-1:
        data.c[v]=data.x[v]
    else:
        data.c[v]=data.c[p]+data.x[v]
    
    for i,child in enumerate(lst):
        if child==p:
            continue
        # print('vertices=',v)
        # print('child=',child)
        # print('parent=',p)
        dfs(child,v)
        
N, Q = map(int, input().strip().split())
data=data(N)
for i in range(N-1):
    a,b=map(int, input().strip().split())
    a-=1
    b-=1
    data.to[a].append(b)
    data.to[b].append(a)

for i in range(Q):
    p,x=map(int, input().strip().split())
    p-=1
    data.x[p]+=x

dfs(0)
for i in range(N):
    print(data.c[i],end=' ')

### FIXED CODE ###

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

# visited = [False for _ in range(N)]
# def dfs(v): # vertices & parent idx
#     visited[v]=True
#     for child in to[v]:
#         if visited[child]==True:
#             continue
#         ans[child]+=ans[v]
#         dfs(child)
# def dfs(v,p=-1): # vertices & parent idx
#     for child in to[v]:
#         if child==p:
#             continue
#         ans[child]+=ans[v]
#         dfs(child,v)

to=[[] for j in range(N)] # N points
ans=[0]*N # N points

for i in range(N-1):
    a,b=map(int, input().strip().split())
    a-=1
    b-=1
    to[a].append(b)
    to[b].append(a)

for i in range(Q):
    p,x=map(int, input().strip().split())
    p-=1
    ans[p]+=x

# dfs(0)
stack=[0]
visited=[False]*N
while stack:
    v=stack.pop()
    visited[v]=True
    for child in to[v]:
        if visited[child] ==False:
            # visited[v]=True
            ans[child]+=ans[v]
            stack.append(child)
for i in range(N):
    print(ans[i],end=' ')
# print(ans)
### BUGGY CODE ###

# ALDS1_4_B.
# バイナリサーチ。

def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    n = int(input())
    S = intinput()
    q = int(input())
    T = intinput()
    count = 0
    for k in T:
        if k in S: count += 1
    print(count)

    
if __name__ == "__main__":
    main()


### FIXED CODE ###

# ALDS1_4_B.
# バイナリサーチ。

def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def binary_search(S, k):
    a = 0; b = len(S) - 1
    if b == 0: return S[0] == k
    while b - a > 1:
        c = (a + b) // 2
        if k <= S[c]: b = c
        else: a = c
    return S[a] == k or S[b] == k
    
def main():
    n = int(input())
    S = intinput()
    q = int(input())
    T = intinput()
    count = 0
    for k in T:
        if binary_search(S, k): count += 1
    print(count)

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

def prison():
    N, M = map(int, input().split())
    id_l = set(range(1, N+1))
    for _ in range(M):
            L, R = map(int, input().split())
            id_l = id_l & set(range(L, R+1))
    return len(id_l)

print(prison())

### FIXED CODE ###

def prison():
    N, M = (int(i) for i in input().split())
    L_max = 0
    R_min = float("inf")
    for _ in range(M):
        L, R = (int(i) for i in input().split())
        L_max = max(L, L_max)
        R_min = min(R, R_min)
        result = max(R_min - L_max + 1, 0)
    return result


print(prison())