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

k = int(input())
s = 7
if k%2 == 0 or k%5 == 0:
	print(-1)
else:
	while s%k != 0:
		s = 10*s+7
	s = str(s)
	print(len(s))

### FIXED CODE ###

import sys

k = int(input())

a = 0

for i in range(1, k+1):
	a = (a*10+7)%k
	if a == 0:
		print(i)
		sys.exit()
print(-1)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
import heapq
n,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
L1=[]
for i in range(n):
  L1.append([l[i][0]-l[i][2],1,l[i][2]])
  L1.append([l[i][1]-l[i][2],-1,l[i][2]])
for i in range(q):
  L1.append([int(input()),2,0])
L1.sort()
L2=[]
heapq.heapify(L2)
L3=[]
L3=set(L3)
ans=[]
for i in range(len(L1)):
  if L1[i][1]==1:
    heapq.heappush(L2,L1[i][2])
    L3.add(L1[i][2])
  elif L1[i][1]==-1:
    L3.remove(L1[i][2])
  else:
    while L2 and L2[0] not in L3:
      heapq.heappop(L2)
    if L2:
      print(L2[0])
    else:
      print(-1)

### FIXED CODE ###

import sys
input=sys.stdin.readline
import heapq
n,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
L1=[]
for i in range(n):
  L1.append((l[i][0]-l[i][2],1,l[i][2]))
  L1.append((l[i][1]-l[i][2],-1,l[i][2]))
for i in range(q):
  L1.append((int(input()),2,0))
L1.sort()
L2=[]
heapq.heapify(L2)
L3=[]
L3=set(L3)
for i in range(len(L1)):
  if L1[i][1]==1:
    heapq.heappush(L2,L1[i][2])
    L3.add(L1[i][2])
  elif L1[i][1]==-1:
    L3.remove(L1[i][2])
  else:
    while L2 and L2[0] not in L3:
      heapq.heappop(L2)
    if L2:
      print(L2[0])
    else:
      print(-1)
### BUGGY CODE ###

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

from itertools import product
a.sort(reverse=True)
aa = list(product(a[:m], repeat=2))
print(sum(sorted(list(map(lambda x: x[0] + x[1], aa)), reverse=True)[:m]))

### FIXED CODE ###

import sys
from itertools import accumulate
from bisect import bisect_left

n, m, *a = map(int, sys.stdin.read().split())
a.sort()


def f(x):
    # 幸福度がx未満となる組み合わせの個数を数える
    cnt = 0
    for ai in a:
        cnt += bisect_left(a, x-ai)
    # 幸福度がx以上の組み合わせの個数がm未満かどうか
    return n * n - cnt < m


left = a[0] * 2
right = a[-1] * 2
while right - left > 1:
    mid = (right + left) // 2
    if f(mid):
        right = mid
    else:
        left = mid
ans = 0
cumsum = [0] + list(accumulate(a))
j = 0
for ai in a:
    i = bisect_left(a, left-ai)
    j += n - i
    ans += ai * (n - i) + cumsum[-1] - cumsum[i]
ans += (m - j) * left
print(ans)
### BUGGY CODE ###

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

MOD = 10 ** 9 + 7

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

def lcm(x, y):
  return x * y // gcd(x, y)

tmp = A[0]
for i in range(1, N):
  tmp = lcm(A[i], tmp)

answer = 0
for a in A:
  answer += tmp // a
print(answer % MOD)

### FIXED CODE ###

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

MOD = 10 ** 9 + 7

def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)

def lcm(x, y):
  return x * y // gcd(x, y)

tmp = A[0]
for i in range(1, N):
  tmp = lcm(A[i], tmp)
#print(tmp)

answer = 0
for a in A:
  answer += tmp // a
print(answer % MOD)
### BUGGY CODE ###

N, M = map(int, input().split())
ab = [list(map(int,input().split())) for i in range(N)]
ab = sorted(ab, key = lambda x:x[0])
tgt = []
count = 0
profit = 0
for m in range(M-1,-1,-1):
    for i in range(count, len(ab)):
        if ab[i][0] == M-m:
            tgt.append(ab[i][1])
            count += 1
        else:
            break
    if tgt != []:
        profit += max(tgt)
        tgt.remove(max(tgt))
print(profit)


### FIXED CODE ###

import heapq
N, M = map(int, input().split())
ab = [list(map(int,input().split())) for i in range(N)]
ab = sorted(ab, key = lambda x:x[0])
tgt = []
heapq.heapify(tgt)
count = 0
profit = 0
for m in range(M-1,-1,-1):
    for i in range(count, len(ab)):
        if ab[i][0] == M-m:
            heapq.heappush(tgt, -ab[i][1])
            count += 1
        else:
            break
    if len(tgt) != 0:
        getval = -heapq.heappop(tgt)
        profit += getval
print(profit)
### BUGGY CODE ###

n = int(input())
s = input()
ans = []
for i in range(n):
    ans.append(s.count('W', 0, i) + s.count('E', i+1, n))
print(min(ans))

### FIXED CODE ###

n = int(input())
s = input()
num = s[1:].count('E')
ans = [num]

for i in range(1,n):
    if s[i] == 'E':
        num -= 1
    if s[i-1] == 'W':
        num += 1
    ans.append(num)
print(min(ans))
### BUGGY CODE ###


from collections import deque

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

for i in range(N):
    s = input()
    for j in range(N):
        if i == j:
            continue
        if s[j] == "1":
            es[i-1].append(j-1)
            es[j-1].append(i-1)


"""
あるノードを始点として、幅優先的に色塗りをしていく。
これを、全ノードを始点にして試す
"""
ans = -1
for i in range(N):
    color = [0] * N
    
    q = deque()
    q.append((i, 1))
    flag = True
    while q and flag:
        node, c = q.popleft()
        color[node] = c
        for nxt in es[node]:
            if color[nxt] != 0:
                if abs(color[node] - color[nxt]) != 1:
                    flag = False
                    break
            else:
                q.append((nxt, c+1))


    if flag:
        ans = max(ans, max(color))

print(ans)

### FIXED CODE ###

"""
AtCoder Grand Contest 039  B - Graph Partition / 


（１）ある集合V_iに含まれるノードから伸びる辺について、その先の集合がV_i-1かV_i+1になるように分ける
（２）その時の集合の個数の最大値を求める

（１）を言い換えると、あるノードが偶数番の集合に属しているとき、それと繋がっているノードが奇数番号の集合かつ差が１である
　→二部グラフ
（２）V_1とV_kがあるとき、少なくともそれらはk本の辺をたどらなければ繋がれないはずなので、最も距離の長い辺（直径）を探す
"""

from collections import deque

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

for i in range(N):
    S = input()
    for j in range(N):
        if S[j] == "1":
            es[i].append(j)


q = deque()
q.append(0)
checked = [0] * N
checked[0] = 1
while q:
    curr = q.popleft()
    for nxt in es[curr]:
        # 未探索なので、currと別の集合に設定
        if checked[nxt] == 0:
            checked[nxt] = checked[curr] * -1
            q.append(nxt)
        else:
            # 探索済みなので、別の集合に属しているか確認し、同じであれば条件を満たさない
            if checked[nxt] == checked[curr]:
                print(-1)
                exit()



# グラフの直径を求める。それぞれのノードをスタート地点として、全ノード間の距離を求めたときの最大距離が直径
ans = 0
for i in range(N):
    q = deque()
    q.append(i)
    dist = [0] * N
    # 距離＋１が答えなので、起点を１としておく
    dist[i] = 1
    while q:
        curr = q.popleft()
        for nxt in es[curr]:
            if dist[nxt] == 0:
                dist[nxt] = dist[curr] + 1
                q.append(nxt)

    ans = max(ans, max(dist))

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

a,b,c,k=map(int,input().split())
ans=0
for i in range(k):
        if a>0:
                ans+=1
                a-=1
        elif b>0:
                b-=1
        elif c>0:
                ans-=1
                c-=1
print(ans)

### FIXED CODE ###

a,b,c,k=map(int,input().split())
ans=0
if a-k>=0:
        print(k)
else:
        num=k-a
        if b-num>=0:
                print(a)
        else:
                num-=b
                print(a-num)
### BUGGY CODE ###

import math
n = int(input())
m = int(math.sqrt(n))
while True:
  if n%m==0:
    print(n//m + m - 2)
    exit()
  m += 1  
    

### FIXED CODE ###

n = int(input())
m = int(n**0.5)
c = float("inf")
for i in range(m, 0, -1):
  if n%i == 0:
    print(n//i + i - 2)
    exit()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
s = int(input())
ans = 0
summ = 0
MOD = 10**9 + 7
def dfs(A):
    global ans, summ
    # print(A, summ)
    # summ = sum(A)
    if summ == s:
        ans += 1
        ans %= MOD
        return False
    elif summ < s:
        for i in range(3, s+1):
            if s - summ < 3:
                break
            A.append(i)
            summ += i
            if dfs(A) == False:
                summ -= A[-1]
                A.pop()
                break
            summ -= A[-1]
            A.pop()
        return True
    else:
        return False

dfs([])
print(ans%MOD)

### FIXED CODE ###

s = int(input())
MOD = 10 ** 9 + 7
ans = 0
fact = [0] * 10000
fact[0], fact[1] = 1, 1
for i in range(2, 10000):
    fact[i] = (fact[i-1] * i) % MOD

def f(n, r):
    return fact[n] * pow(fact[n-r], -1, MOD) * pow(fact[r], -1, MOD)

for i in range(1, s//3+1):
    if i == 1:
        ans += 1
    else:
        m = s - i * 3
        ans += f(m+i-1, m)
        ans %= MOD
print(ans%MOD)
### BUGGY CODE ###

n, m, q = map(int, input().split())
lr = []
for _ in range(m):
    lr.append(list(map(int, input().split())))

a = [[0] * n for i in range(n)]
for l, r in lr:
    a[l - 1][r - 1] += 1

# cnt = [[0]*n for i in range(n)]
# for y in range(n):
#     v = 0
#     for x in range(y, -1, -1):
#         v += a[x][y]
#         cnt[x][y] = cnt[x][y - 1] + v

for _ in range(q):
    p, q = map(int, input().split())
    cnt = 0
    for l in range(p, q+1):
        for r in range(p, q+1):
            cnt += a[l-1][r-1]
    print(cnt)

### FIXED CODE ###

n, m, q = map(int, input().split())
lr = []
for _ in range(m):
    lr.append(list(map(int, input().split())))

a = [[0] * n for i in range(n)]
for l, r in lr:
    a[l - 1][r - 1] += 1

cnt = [[0]*n for i in range(n)]
for y in range(n):
    v = 0
    for x in range(y, -1, -1):
        v += a[x][y]
        cnt[x][y] = cnt[x][y - 1] + v

for _ in range(q):
    p, q = map(int, input().split())
    print(cnt[p-1][q-1])
### BUGGY CODE ###

import sys
from collections import deque


def bfs01(s, t, links):
    q = deque([(0, s, -1)])  # cost, station, last-company
    costs = [10 ** 9] * n
    corporations = [set() for _ in range(n)]
    while q:
        d, v, e = q.popleft()
        if v == t:
            return d
        if costs[v] < d or e in corporations[v]:
            continue
        costs[v] = d
        corporations[v].add(e)
        for u, c in links[v]:
            if c == e:
                nd = d
                func = q.appendleft
            else:
                nd = d + 1
                func = q.append
            if costs[u] < nd or c in corporations[u]:
                continue
            func((nd, u, c))
    return -1


readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

n, m = map(int, readline().split())
links = [set() for _ in range(n)]
pqc = list(map(int, read().split()))
for p, q, c in zip(pqc[0::3], pqc[1::3], pqc[2::3]):
    p -= 1
    q -= 1
    links[p].add((q, c))
    links[q].add((p, c))

print(bfs01(0, n - 1, links))


### FIXED CODE ###

import sys
from collections import deque, defaultdict


def bfs01(s, t, links):
    q = deque([(0, s, -1)])  # cost, station, last-company
    visited = set()
    while q:
        d, v, e = q.popleft()
        if v == t:
            return d
        if (v, e) in visited:
            continue
        visited.add((v, e))
        if e == 0:
            for c in links[v]:
                for u in links[v][c]:
                    if (u, c) in visited:
                        continue
                    q.append((d + 1, u, c))
        else:
            for u in links[v][e]:
                if (u, e) in visited:
                    continue
                q.appendleft((d, u, e))
            if (v, 0) not in visited:
                q.appendleft((d, v, 0))

    return -1


readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

n, m = map(int, readline().split())
links = [defaultdict(set) for _ in range(n)]
pqc = list(map(int, read().split()))
for p, q, c in zip(pqc[0::3], pqc[1::3], pqc[2::3]):
    p -= 1
    q -= 1
    links[p][c].add(q)
    links[q][c].add(p)

print(bfs01(0, n - 1, links))
### BUGGY CODE ###

k = int(input())
s = input()
l = len(s)
MOD = 10 ** 9 + 7


def comb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p


p = MOD
N = 10 ** 7  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

# Sn の位置をx = l-1,l,..,l+k-1まで全て動かす
# pow(25,x-l-1,MOD)* x-1Cl-1 * pow(26,l+k-1-x,MOD) をかければOK
ans = 0
for x in range(l - 1, l + k):
    ans += pow(25, x - l + 1, MOD) * comb(x, l - 1, MOD) * pow(26, l + k - 1 - x, MOD)
    ans %= MOD
print(ans)
"""
# dp[i][j]:k+l の長さの文字列の中で、長さi で、sのj番目の文字列まじで含む文字列の個数とする
# dp[i][j] = dp[i-1][j-1] + dp[i-1][j] * 25 となる
# これだと10**12でTLEなので、まとめる
# 答えたいのは、dp[k+l][l]で初期化はdp[1][1] = 1 dp[1][0] = 25
# l までいったら遷移の仕方が変わって*26を続けるだけで良いようになる
dp = [[0] * (l + 1) for _ in range(k + l + 1)]
dp[0][0] = 1
for i in range(1, k + l + 1):
    for j in range(l + 1):
        if j == l:
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * 26
        else:
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * 25
        dp[i][j] %= MOD
print(dp[k + l][l])
"""


### FIXED CODE ###

k = int(input())
s = input()
l = len(s)
MOD = 10 ** 9 + 7


def comb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p


p = MOD
N = 10 ** 6 * 2 + 10 # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

# Sn の位置をx = l-1,l,..,l+k-1まで全て動かす
# pow(25,x-l-1,MOD)* x-1Cl-1 * pow(26,l+k-1-x,MOD) をかければOK
ans = 0
for x in range(l - 1, l + k):
    ans += pow(25, x - l + 1, MOD) * comb(x, l - 1, MOD) * pow(26, l + k - 1 - x, MOD)
    ans %= MOD
print(ans)
"""
# dp[i][j]:k+l の長さの文字列の中で、長さi で、sのj番目の文字列まじで含む文字列の個数とする
# dp[i][j] = dp[i-1][j-1] + dp[i-1][j] * 25 となる
# これだと10**12でTLEなので、まとめる
# 答えたいのは、dp[k+l][l]で初期化はdp[1][1] = 1 dp[1][0] = 25
# l までいったら遷移の仕方が変わって*26を続けるだけで良いようになる
dp = [[0] * (l + 1) for _ in range(k + l + 1)]
dp[0][0] = 1
for i in range(1, k + l + 1):
    for j in range(l + 1):
        if j == l:
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * 26
        else:
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * 25
        dp[i][j] %= MOD
print(dp[k + l][l])
"""
### BUGGY CODE ###

N=int(input())
S=list(input())
Q=int(input())
for i in range(Q):
  q,a,b=input().split()
  if q=='1':
    S[int(a)-1] = b
  else:
    print(len(set(S[int(a)-1:int(b)])))

### FIXED CODE ###

class SegTree:
    """ segment tree with point modification and range product. """
    # # https://yukicoder.me/submissions/452850
    def __init__(self, N, data_f = min, data_unit=1<<30):
        self.N = N
        self.data_f = data_f
        self.data_unit = data_unit
        self.data = [self.data_unit] * (N + N)

    def build(self, raw_data):
        data = self.data
        f = self.data_f
        N = self.N
        data[N:] = raw_data[:]
        for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

    def set_val(self, i, x):
        data = self.data
        f = self.data_f
        i += self.N
        data[i] = x
        while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

    def fold(self, L, R):
        """ compute for [L, R) """
        vL = vR = self.data_unit
        data = self.data
        f = self.data_f
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
        return f(vL, vR)
      
N=int(input())
S=input()
seg = SegTree(N,set.union,set())
S = [set(S[i]) for i in range(N)]
seg.build(S)
Q=int(input())
for i in range(Q):
  *q, = input().split()
  if q[0] == '1':
    i, c = q[1:]
    seg.set_val(int(i)-1,set(c))
  else:
    l,r = map(int,q[1:])
    print(len(seg.fold(l-1,r)))
### BUGGY CODE ###

import collections
N, Q = map(int, input().split())
C = list(map(int, input().split()))
L = [0] * Q
R = [0] * Q
for i in range(Q):
    l,r = map(int, input().split())
    L[i] = l
    R[i] = r
for j in range(Q):
    C_after = C[L[j] - 1:R[j]]
    D = collections.Counter(C_after)
    print(len(D))


### FIXED CODE ###

from collections import defaultdict
import sys
def read():
    return sys.stdin.readline().rstrip()
def main():
    N, Q = map(int, read().split())
    C = list(map(int, read().split()))
    E = defaultdict(list)

    D = [-1] * (N + 1)
    for i in range(N):
        D_i = D[C[i]]
        if D_i != -1:
            E[D_i].append((D_i, i))
        D[C[i]] = i

    F = defaultdict(list)
    for i in range(Q):
        l, r = map(int, input().split())
        F[l-1].append((r - 1, i))



    # Binary Indexed Tree (Fenwick Tree)
    class BIT:
        def __init__(self, n):
            self.n = n
            self.data = [0] * (n + 1)
            self.el = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.data[i]
                i -= i & -i
            return s

        def add(self, i, x):
            # assert i > 0
            self.el[i] += x
            while i <= self.n:
                self.data[i] += x
                i += i & -i

        def get(self, i, j=None):
            if j is None:
                return self.el[i]
            return self.sum(j) - self.sum(i)

    ANS = [0] * Q
    d = BIT(N)
    for x in range(N - 1, -1, -1):
        for e in E[x]:
            d.add(e[1], 1)
        for f in F[x]:
            ANS[f[1]] = f[0] - x + 1 - d.sum(f[0])

    for i in range(Q):
        print(ANS[i])

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


import sys
input = sys.stdin.buffer.readline
N=int(input())
val=[list(map(int, input().split())) for i in range(N-1)]

arr=[set() for i in range(N)]
col=[set() for i in range(N)]
colarr=[0]*(N-1)
coldict={}
for i in range(N-1):
    a=val[i][0]-1
    b=val[i][1]-1
    arr[a].add(b)
    arr[b].add(a)
    coldict[(a,b)]=i
colmax=0
flag=0
for i in range(N):
    if len(arr[i])>colmax:
        colmax=len(arr[i])
        flag=i
colall=set(range(1,colmax+1))
coltemp=set(colall)
arrtemp=set(arr[flag])
for f in arrtemp:
    p=coltemp.pop()
    if flag<f:
        colarr[coldict[(flag,f)]]=p
    else:
        colarr[coldict[(f,flag)]]=p
    
    col[f].add(p)
    arr[f].remove(flag)
que=[set() for i in range(N)]
que[0]=que[0] | arr[flag]
reach={flag}

for i in range(N-1):
    for t in que[i]:
        coltemp=colall^col[t]
        arrtemp=set(arr[t])
        if len(arrtemp)>0:
            
            que[i+1]=que[i+1] | arrtemp
            for f in arrtemp:
                p=coltemp.pop()
                col[f].add(p)
                arr[f].remove(t)
                if t<f:
                    colarr[coldict[(t,f)]]=p
                else:
                    colarr[coldict[(f,t)]]=p
        reach.add(t)
print(colmax)
for i in range(N-1):
    print(colarr[i])

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
N=int(input())
val=[list(map(int, input().split())) for i in range(N-1)]

arr=[set() for i in range(N)]
col=[set() for i in range(N)]
colarr=[0]*(N-1)
coldict={}
for i in range(N-1):
    a=val[i][0]-1
    b=val[i][1]-1
    arr[a].add(b)
    arr[b].add(a)
    coldict[(a,b)]=i
colmax=0
flag=0
for i in range(N):
    if len(arr[i])>colmax:
        colmax=len(arr[i])
        flag=i
colall=set(range(1,colmax+1))
coltemp=1
arrtemp=set(arr[flag])
for f in arrtemp:
    p=coltemp
    coltemp+=1
    if flag<f:
        colarr[coldict[(flag,f)]]=p
    else:
        colarr[coldict[(f,flag)]]=p
    col[f].add(p)
    arr[f].remove(flag)
que=[set() for i in range(N)]
que[0]=que[0] | arr[flag]

for i in range(N-1):
    for t in que[i]:
        arrtemp=arr[t]
        if len(arrtemp)>0:
            coltemp=1
            que[i+1] |= arrtemp
            for f in arrtemp:
                while(1):
                    if coltemp not in col[t]:
                        break
                    coltemp+=1
                p=coltemp
                coltemp+=1
                col[f].add(p)
                arr[f].remove(t)
                if t<f:
                    colarr[coldict[(t,f)]]=p
                else:
                    colarr[coldict[(f,t)]]=p
print(colmax)
for i in range(N-1):
    print(colarr[i])
### BUGGY CODE ###

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

while abs(N - K) < N:
    N = abs(N - K)

print(N)


### FIXED CODE ###

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

N %= K

while abs(N - K) < N:
    N = abs(N - K)

print(N)
### BUGGY CODE ###

import numpy as np
n, x, y = map(int, input().split())

#ans = [0] * n
ans = np.zeros(n,np.uint16)
for i in range(1,n):
    for j in range(i+1,n+1):
        ans[min(j-i,abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j))] += 1

for i in range(1,n):
    print(ans[i])

### FIXED CODE ###

import numpy as np
n, x, y = map(int, input().split())

ans = [0] * n
for i in range(1,n):
    for j in range(i+1,n+1):
        ans[min(j-i,abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j))] += 1

for i in range(1,n):
    print(ans[i])
### BUGGY CODE ###

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

p = list(map(int,input().split()))
for n in range(N):
  p[n] = p[n] / 2 + 1 / 2
max = 0
for n in range(N-K+1):
  sum = 0
  for i in range(n, n + K):
    sum += p[i]
  if max < sum:
    max = sum
print(max)

### FIXED CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
ps = [p[0]] + [0]*(n-1)
for i in range(1,n):
    ps[i] = ps[i-1] + p[i]
maxs = ps[k-1]
for i in range(1,n-k+1):
    maxs = max(maxs,ps[i+k-1]-ps[i-1])

print((maxs+k)/2)
### BUGGY CODE ###

#!/usr/bin/python3
from operator import attrgetter
class Point:
    pass

class Node:
    pass

def kdtree(points, depth=0):
    if not points:
        return
    # dimension
    k = 2
    axis = depth % k
    if depth % 2 == 0:
        points.sort(key=attrgetter('x'))
    else:
        points.sort(key=attrgetter('y'))

    median = len(points)//2

    node = Node()
    node.location = points[median]
    node.left = kdtree(points[:median], depth + 1)
    node.right = kdtree(points[median + 1:], depth + 1)
    return node

def find(sx, tx, sy, ty, node, depth):
    if node == None:
        return []
    result = []
    x = node.location.x
    y = node.location.y
    if sx <= x <= tx and sy <= y <= ty:
        result.append(node.location.id)

    if depth % 2 == 0:
        if sx <= x:
            ret = find(sx, tx, sy, ty, node.left, depth + 1)
            result.extend(ret)
        if x <= tx:
            ret = find(sx, tx, sy, ty, node.right, depth + 1)
            result.extend(ret)
    else:
        if sy <= y:
            ret = find(sx, tx, sy, ty, node.left, depth + 1)
            result.extend(ret)
        if y <= ty:
            ret = find(sx, tx, sy, ty, node.right, depth + 1)
            result.extend(ret)
    return result

# main
n = int(input())
points = []
for i in range(n):
    point = Point()
    point.id = i
    point.x, point.y = map(int, input().split())
    points.append(point)
tree = kdtree(points)
q = int(input())
for i in range(q):
    sx, tx, sy, ty = map(int, input().split())
    result = find(sx, tx, sy, ty, tree, 0)
    result.sort()
    for i in result:
        print(i)
    print()

### FIXED CODE ###

#!/usr/bin/python3
from sys import stdin
import math
from operator import itemgetter
from bisect import bisect_left, bisect_right
readline = stdin.readline

def main():
    n = int(readline())
    xy = [tuple(map(int, readline().split())) + (i,) for i in range(n)]
    # [..., (x_i, y_i, i), ...]
    # sort by x
    xy.sort()

    root = int(math.sqrt(len(xy)))

    low = [x for x, y, i in xy[::root]]
    high = [x for x, y, i in xy[root - 1::root]] + [float('inf')]

    xy = [sorted(xy[i:i + root], key=itemgetter(1)) for i in range(0, len(xy), root)]
    xy = [([y for x, y, i in xyi], xyi) for xyi in xy]
    for sx, tx, sy, ty in (map(int, readline().split()) for _ in range(int(readline()))):
        ret = []
        for i in range(bisect_left(high, sx), bisect_right(low, tx)):
            k, v = xy[i]
            for i in range(bisect_left(k, sy), bisect_right(k, ty)):
                if sx <= v[i][0] <=tx:
                    ret.append(v[i][2])
        if ret:
            ret.sort()
            print('\n'.join(map(str,ret)))
        print()

main()