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

k=int(input())

if k%2==0:
  print(-1); exit()

cnt=num=0
while 1:
  num+=7*pow(10,cnt,k)
  cnt+=1
  if num%k==0:
    break
print(cnt)

### FIXED CODE ###

K = int(input())

cnt=1
Num=7%K
while cnt<=K:
  if K%2==0:
    print('-1')
    break
  if Num%K==0:
    print(cnt)
    break
  else:
    Num = (10*Num + 7)%K
    cnt+=1
else:
  print('-1')
### BUGGY CODE ###


N = int(input())
S = []
for i in range(N):
    S.append(sorted(list(input())))

res = 0
for i in range(N):
    for j in range(i + 1, N):
        res += int(S[i] == S[j])
print(res)

### FIXED CODE ###

def f(x):
    return 10 ** (ord(x) - ord('a') + 1)


import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


from collections import Counter

N = int(input())
counter = Counter()
for i in range(N):
    counter[sum([f(i) for i in input()])] += 1
res = 0
for v in counter.values():
    if v > 1:
        res += combinations_count(v, 2)
print(res)
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if j - i == A[i] + A[j]:
            ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
A = [int(x) for x in input().split()]
backward = [0] * n
forward = [0] * n
for i, a in enumerate(A):
    if i + a < n:
        forward[i + a] += 1
    if i - a >= 0:
        backward[i - a] += 1
ans = 0
for x, y in zip(forward, backward):
    ans += x * y
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
Ans = 1
for a in A:
    Ans *= a
if Ans>10**18:
    print("-1")
else:
    print(Ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
Ans = 1
for a in A:
    if a == 0:
        print("0")
        break
else:
    for a in A:
        Ans *= a
        if Ans>10**18:
            print("-1")
            break
    else:
        print(Ans)
### BUGGY CODE ###

import numpy as np

def solve(h,w,n,black_list):
  count = []
  for idx, (a,b) in enumerate(black_list):
    left = max(0, b-3)
    top = max(0, a-3)
    right = min(w, b+3)
    bottom = min(h, a+3)
    for row in range(top, a):
      if row+2 >= h:
        continue
      for col in range(left, b):
        if col+2 >= w:
          continue
        count.append(row*h+col)

  set_count = set(count)
  count = np.array(count)
  ans = np.zeros(len(set_count))
  for idx,i in enumerate(set_count):
    ans[idx] = np.count_nonzero(count==i)

  ret = [(h-2)*(w-2)-len(set_count)]
  for i in range(1, 10):
    ret.append(np.count_nonzero(ans==i))
  return ret

if __name__ == "__main__":
  h,w,n = map(int,input().split())
  black_list = [tuple(map(int,input().split())) for _ in range(n)]
  ret = solve(h,w,n,black_list)
  for i in ret:
    print(i)


### FIXED CODE ###

def solve(h,w,n,black_list):
  if len(black_list) == 0:
    return [(h-2)*(w-2)]+[0]*9
  idx_list = []
  for idx, (a,b) in enumerate(black_list):
    left = max(0, b-3)
    top = max(0, a-3)
    for row in range(top, a):
      if row+2 >= h:
        continue
      for col in range(left, b):
        if col+2 >= w:
          continue
        idx_list.append(row*w+col)

  set_count = set(idx_list)
  idx_list = sorted(idx_list)

  ans = [0]*9
  now = idx_list[0]
  count = 0
  for item in idx_list:
    if item == now:
      count += 1
    else:
      now = item
      if count == 10:
        print(item)
      ans[count-1] += 1
      count = 1
  ans[count-1] += 1
  return [(h-2)*(w-2)-len(set_count)]+ans


if __name__ == "__main__":
  h,w,n = map(int,input().split())
  black_list = [tuple(map(int,input().split())) for _ in range(n)]
  ret = solve(h,w,n,black_list)
  for i in ret:
    print(i)
### BUGGY CODE ###

import bisect

s = list(input())
t = list(input())

# 辞書を作る
dictionary = {}

tt = t[:]
ss = s * 2

i = 0
while len(ss):
    _s = ss.pop(0)
    if _s not in dictionary:
        dictionary[_s] = [i]
    else:
        dictionary[_s].append(i)
    i += 1

result = 0
before = 0
sLen = len(s)
while len(t) > 0:
    _t = t.pop(0)
    if _t not in dictionary:
        print(-1)
        exit(0)
    _next = dictionary[_t][bisect.bisect_left(dictionary[_t], before)] + 1
    result += _next - before
    before = _next
    if _next >= sLen:
        before -= sLen

print(result)




### FIXED CODE ###

import bisect

s = list(input())
t = list(input())

# 辞書を作る
dictionary = {}

tt = t[:]
ss = dict(zip(list(range(len(s * 2))), s * 2))

for i in range(len(ss)):
    c = ss[i]
    if c not in dictionary:
        dictionary[c] = []
    dictionary[c].append(i)

result = 0
current_idx = 0
sLen = len(s)

for c in t:
    if c not in dictionary:
        print(-1)
        exit(0)
    indexes = dictionary[c]
    next = dictionary[c][bisect.bisect_left(indexes, current_idx)] + 1
    result += next - current_idx
    current_idx = next
    if next >= sLen:
        current_idx -= sLen

print(result)
### BUGGY CODE ###

def get_max_index(n, k, arr):
    tmp = 0
    index = 0
    tmp_arr = []
    for i in range(n - (k - 1)):
        sum_tmp = sum(arr[i:i+k])
        if sum_tmp >= tmp:
            tmp = sum_tmp
            index = i
            tmp_arr = arr[i:i+k]
    ans = 0
    for j in tmp_arr:
        tmp_sum = 0
        for m in range(1, j+1):
            tmp_sum += m
        ans += tmp_sum / j
    return ans

if __name__ == "__main__":
    n, k = map(int, input().split())
    arr = list(map(int,input().split()))
    print(get_max_index(n, k, arr))

### FIXED CODE ###

n, k = [int(x) for x in input().split()]
arr = list(map(int,input().split()))

m = sum(arr[0:k])
sump = m

for i in range(1, n-k+1):
    sump = sump - arr[i-1] + arr[i+k-1]
    if m < sump:
        m = sump

ans = (m + k) / 2

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

N = int(input())
A = list(input().split())
B = [int(a) for a in A]
x = 10**9+7
summation = 0
for i in range(N-1):
    for j in range(i+1,N):
        summation += (B[i] * B[j])
print(summation % x)


### FIXED CODE ###

N = int(input())
A = list(input().split())
B = [int(a) for a in A]
x = 10**9+7
summation1 = sum(B) ** 2
summation2 = sum(b ** 2 for b in B)
summation = ((summation1 - summation2) // 2) % x
print(summation)
### BUGGY CODE ###

N = int(input())
dic = {}

for _ in range(N):
  inp = input()
  if inp not in dic:
    dic[inp] = 1
  else:
    dic[inp] = dic[inp] + 1

ans = [kv[0] for kv in dic.items() if kv[1] == max(dic.values())]
ans.sort()
for i in ans:
  print(i)

### FIXED CODE ###

N = int(input())
dic = {}

for _ in range(N):
  inp = input()
  if inp not in dic:
    dic[inp] = 1
  else:
    dic[inp] = dic[inp] + 1

num = max(dic.values())
ans = []
for i in dic:
  if dic[i] == num:
    ans.append(i)
    
ans.sort()
for i in ans:
  print(i)
### BUGGY CODE ###

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

for i in range(n):
	if sum(a_s[:i]) >= sum(a_s[i:]):
		break

tmp_res1 = abs(sum(a_s[:i - 1]) - sum(a_s[i - 1:]))
tmp_res2 = abs(sum(a_s[:i]) - sum(a_s[i:]))
res = min(tmp_res1, tmp_res2)

print(res)


### FIXED CODE ###

n = int(input())
a_s = list(map(int, input().split()))
sum_a_s = sum(a_s)

tmp_sum = 0
for i in range(n - 1):
	tmp_sum += a_s[i]
	if tmp_sum > sum_a_s - tmp_sum:
		break

tmp_res1 = abs(sum(a_s[:i]) * 2 - sum_a_s)
tmp_res2 = abs(sum(a_s[:i + 1]) * 2 - sum_a_s)
res = min(tmp_res1, tmp_res2)

print(res)
### BUGGY CODE ###

n = int(input())
li = []
for i in range(n):
    a = input()
    if a in li:
        li.remove(a)
    else:
        li.append(a)

print(len(li))
        

### FIXED CODE ###

n = int(input())
ans = set()
for i in range(n):
    a = input()
    if a in ans:
        ans.remove(a)
    else:
        ans.add(a)
 
print(len(ans))
### BUGGY CODE ###

S = input()
k = []
Q = int(input())
now = 0
ans = ""
mode = 0
for i in range(Q):
    K = input().split()
    if K[0] == "1":
        if mode == 1:
            mode = 0
        else:
            mode = 1
    else:
        if K[1] == "1":
            if mode == 0:
                #k[left] = K[2]
                S = K[2]+ S
            else:
                S = S+K[2]
        else:
            if mode == 0:
                S = S+K[2]
            else:
                S = K[2]+S
if mode == 1:
    for i in range(1,len(S)+1):
        ans += S[-i]
    print(ans)
else:
    print(S)

### FIXED CODE ###

S = input()
Q = int(input())
mode = 0
ans_1 = ""
ans_2 = ""
for i in range(Q):
    K = input().split()
    if K[0] == "1":
        if mode == 0:
            mode = 1
        else:
            mode = 0
    else:
        if K[1] == "1":
            if mode == 0:
                ans_1 += K[2]
            else:
                ans_2 += K[2]
        else:
            if mode == 0:
                ans_2 += K[2]
            else:
                ans_1 += K[2]
ans_1 = ans_1[::-1]
K = ans_1+S+ans_2
if mode == 1:
    print(K[::-1])
else:
    print(K)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
h,w,n=map(int,input().split())
ans=[0]*10
p=set()
q=set()
for i in range(n):
	a,b=map(int,input().split())
	for j in range(-1,2):
		for k in range(-1,2):
			if 2<=a+j<=h-1 and 2<=b+k<=w-1:
				r=(a+j)*(10**10)+b+k
				p.add(r)
	q.add(a*(10**10)+b)
p=list(p)
for x in p:
	cnt=0
	for j in range(-1,2):
		for k in range(-1,2):
			if x+j*(10**10)+k in q:
				cnt+=1
	ans[cnt]+=1
print((h-2)*(w-2)-sum(ans[1:]))
for i in range(1,10):
	print(ans[i])

### FIXED CODE ###

def main():
	import sys
	input=sys.stdin.readline
	h,w,n=map(int,input().split())
	ans=[0]*10
	p=set()
	q=set()
	for i in range(n):
		a,b=map(int,input().split())
		for j in range(-1,2):
			for k in range(-1,2):
				if 2<=a+j<=h-1 and 2<=b+k<=w-1:
					r=(a+j)*(10**10)+b+k
					p.add(r)
		q.add(a*(10**10)+b)
	p=list(p)
	for x in p:
		cnt=0
		for j in range(-1,2):
			for k in range(-1,2):
				if x+j*(10**10)+k in q:
					cnt+=1
		ans[cnt]+=1
	print((h-2)*(w-2)-sum(ans[1:]))
	for i in range(1,10):
		print(ans[i])
if __name__ == '__main__':
	main()
### BUGGY CODE ###

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

def get_candidates(A, B, K):
    """Find matching numbers, return as list"""
    L = B - A + 1 # length of list
    c = set()
    for index, val in enumerate(range(A,B+1)):
        #print(index,val)
        if index < K:
            c.add(val)
        elif index >= max(0, L-K):
            c.add(val)
    #c = sorted(list(c))
    return sorted(list(c))

for n in get_candidates(A, B, K):
    print(n)

### FIXED CODE ###

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

l1 = list(range(A,min(B+1,A+K)))
l2_lower = max(A,(B+1) - K)
l2 = list(range(l2_lower, B+1))
for n in sorted(list(set(l1+l2))):
    print(n)
### BUGGY CODE ###

from collections import Counter

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

# nC2 = [0] * (N + 1)
# nC2[0] = 0
# nC2[1] = 0
# for i in range(2, N + 1):
#     nC2[i] = i * (i - 1) // 2

# print(nC2)


def comb(x):
    if x == 0:
        return 0
    if x == 1:
        return 0
    return x * (x - 1) // 2


d = Counter(A)
# print(d)
k = d.keys()

# print(k)

for a in A:
    res = 0
    for kk in k:
        if a == kk:
            res += comb(d[kk] - 1)
            # res += nC2[d[kk] - 1]
        else:
            res += comb(d[kk])
            # res += nC2[d[kk]]
    # print(a, d[a], res)
    print(res)


### FIXED CODE ###

from collections import Counter

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


def comb(x):
    if x == 0:
        return 0
    if x == 1:
        return 0
    return x * (x - 1) // 2


d = Counter(A)
# print(d)
k = d.keys()

# print(k)
total = 0

for kk in k:
    total += comb(d[kk])

# print(total)

for a in A:
    res = total
    res -= comb(d[a])
    res += comb(d[a] - 1)
    print(res)
### BUGGY CODE ###

n = int(input())
ar = []
z = 0
for i in range(n):
    a,b = map(int,input().split(" "))
    count = 0
    br = []
    for i in range(a-(b-1),a+b):
        if i in ar:
            count += 1
            break
        br.append(i)
    if count == 0:
        z += 1
        for r in br:
            ar.append(r)
print(z)

### FIXED CODE ###

n = int(input())
ar = []
mi = 0
mx = 0
count = 1
for i in range(n):
    a,b = map(int,input().split(" "))
    br = [a+b,a-b]
    ar.append(br)
ar.sort()
for i,r in enumerate(ar):
    if i == 0:
        mx = r[0]
    else:
        if mx <= r[1]:
            count += 1
            mx = r[0]
print(count)
### BUGGY CODE ###

S = int(input())
listS = list(str(S))
l = len(listS)
dp = int(listS[-1])
suml = [dp]
for i in range(l-1):
    dp = dp + (10**(i+1))*int(listS[-2-i])
    suml.append(dp % 2019)
mod = {0:1}
for a in suml:
    if a in mod.keys():
        mod[a] += 1
    else:
        mod[a] = 1
cnt = 0
for a in mod:
    if mod[a] > 1:
        cnt += (mod[a]*(mod[a]-1))//2
print(cnt)

### FIXED CODE ###

S = str(input())
l = len(S)
mod = [0] * 2019
dp = 0
pw = 1
for i in range(l):
    mod[dp % 2019] += 1
    dp = dp + pw * int(S[-1-i])
    pw = (pw * 10) % 2019
mod[dp % 2019] += 1
cnt = 0
for i in range(2019):
    cnt += (mod[i]*(mod[i]-1))//2
print(cnt)
### BUGGY CODE ###

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse = True)
i = 0
while i < M:
    A[0] //= 2
    i += 1
    A.sort(reverse = True)
print(sum(A))


### FIXED CODE ###

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse = True)
while M > 0:
    A[0] //= 2
    for i in range(1,M):
        if i < N and A[i] >= A[0]:
            A[i] //= 2
        else:
            M -= i
            A.sort(reverse = True)
            break
    else:
        break
print(sum(A))
### BUGGY CODE ###

n = int(input())

s = []
c = 0

for i in range(n):
    s.append(sorted(input()))
    if len(s) >= 2:
        for j in range(i):
            if s[j] == s[i]:
                c += 1

print(c)


### FIXED CODE ###

n = int(input())

s = []

for i in range(n):
    s.append(''.join(sorted(input())))

t = {}
for i in range(n):
    if s[i] in t:
        t[s[i]] += 1
    else:
        t[s[i]] = 1

print(sum(t[k]*(t[k]-1)//2 for k in t)) # t[k] Combi 2のlistのsumが答えになる
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from itertools import accumulate

def main():
  n, m, q = map(int, input().split())
  S = [[0]*(m+1)] + [[0] + list(map(int, list(input().rstrip()))) for _ in range(n)]
  B = [[0]*(m+1) for _ in range(n+1)]
  U = [[0]*(m+1) for _ in range(n+1)]
  L = [[0]*(m+1) for _ in range(n+1)]
  for i in range(1, n+1):
    for j in range(1, m+1):
      if S[i][j]:
        U[i][j] = S[i-1][j]
        L[i][j] = S[i][j-1]
  for i in range(1, n+1):
    B[i] = list(accumulate(S[i]))
    U[i] = list(accumulate(U[i]))
    L[i] = list(accumulate(L[i]))
  B = list(zip(*B))
  U = list(zip(*U))
  L = list(zip(*L))
  for j in range(1, m+1):
    B[j] = list(accumulate(B[j]))
    U[j] = list(accumulate(U[j]))
    L[j] = list(accumulate(L[j]))
  B = list(zip(*B))
  U = list(zip(*U))
  L = list(zip(*L))
  def calc_b(x1, y1, x2, y2):
    return B[x2][y2] - B[x1-1][y2] - B[x2][y1-1] + B[x1-1][y1-1]
  def calc_u(x1, y1, x2, y2):
    return U[x2][y2] - U[x1][y2] - U[x2][y1-1] + U[x1][y1-1]
  def calc_l(x1, y1, x2, y2):
    return L[x2][y2] - L[x1-1][y2] - L[x2][y1] + L[x1-1][y1]

  for _ in range(q):
    x1, y1, x2, y2 = map(int, input().split())
    res = calc_b(x1, y1, x2, y2) - (calc_u(x1, y1, x2, y2) + calc_l(x1, y1, x2, y2))
    print(res)
if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

n, m, q = map(int, input().split())
S = [[0]*(m+1)] + [[0] + list(map(int, list(input().rstrip()))) for _ in range(n)]
B = [[0]*(m+1) for _ in range(n+1)]
U = [[0]*(m+1) for _ in range(n+1)]
L = [[0]*(m+1) for _ in range(n+1)]
for i in range(1, n+1):
  for j in range(1, m+1):
    B[i][j] = B[i-1][j] + B[i][j-1] - B[i-1][j-1] + S[i][j]
    U[i][j] = U[i-1][j] + U[i][j-1] - U[i-1][j-1] + U[i][j]
    L[i][j] = L[i-1][j] + L[i][j-1] - L[i-1][j-1] + L[i][j]
    if S[i][j]:
      U[i][j] += S[i-1][j]
      L[i][j] += S[i][j-1]
    
def calc_b(x1, y1, x2, y2):
  return B[x2][y2] - B[x1-1][y2] - B[x2][y1-1] + B[x1-1][y1-1]
def calc_u(x1, y1, x2, y2):
  return U[x2][y2] - U[x1][y2] - U[x2][y1-1] + U[x1][y1-1]
def calc_l(x1, y1, x2, y2):
  return L[x2][y2] - L[x1-1][y2] - L[x2][y1] + L[x1-1][y1]

for _ in range(q):
  x1, y1, x2, y2 = map(int, input().split())
  res = calc_b(x1, y1, x2, y2) - (calc_u(x1, y1, x2, y2) + calc_l(x1, y1, x2, y2))
  print(res)
### BUGGY CODE ###

N=int(input())
A=input().split(" ")

while(len(A)!=0):
  buf=[A[0]]
  A.pop(0)
  buf2=list(set(A) & set(buf))
  if len(buf2)!=0:
    print("NO")
    exit(0)
  
print("YES")

### FIXED CODE ###

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

A=sorted(A)

for i in range(0,N):
  if len(A) > i+1:
    if A[i] == A[i+1]:
      print("NO")
      exit(0)
print("YES")
### BUGGY CODE ###

n = int(input())
alist = list(map(int, input().split()))
b = []
for i in range(n):
    b.append(alist[i])
    b = b[::-1]

for _ in b:
    print(_, end=" ")


### FIXED CODE ###

n = int(input())
alist = list(map(int, input().split()))
b = alist[::-2] + alist[n % 2::2]
print(" ".join(list(map(str, b))))
### BUGGY CODE ###

import collections
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
lst = []
ans = 0

for i in range(n):
    s = input()
    c = sorted(collections.Counter(s).most_common())
    tmp_str = ""
    for i in c:
        tmp = str(i[1])
        tmp_str += i[0] + tmp
    lst.append(tmp_str)
    
d = collections.Counter(lst)
for i in d.values():
    if i >= 2:
        ans += combinations_count(i, 2)
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
count_list = []
for i in range(n):
    s = input()
    c = sorted(Counter(s).items(), key = lambda x:x[0])
    tmp = ""
    for j in range(len(c)):
        tmp += c[j][0]
        tmp += str(c[j][1])
    count_list.append(tmp)

c = Counter(count_list)
ans = 0
for i in c.values():
    if i >= 2:
        ans += i * (i - 1) // 2

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

N = int(input())
S = [s for s in input()]
from itertools import combinations
lis = set(combinations(S,3))
print(len(lis))

### FIXED CODE ###

N = int(input())
S = [s for s in input()]
lis = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
ans = 0
from collections import defaultdict
d = defaultdict(list)
for i,s in enumerate(S):
    d[s].append(i)

for s in lis:
    if d[s[0]]:
        i = min(d[s[0]])
        if d[s[1]]:
            for j in d[s[1]]:
                if j > i:
                    if d[s[2]]:
                        if max(d[s[2]]) > j:
                            ans += 1
                            break
                    break
        else:continue
    else:continue
                            
print(ans)
### BUGGY CODE ###

import numpy as np
from numba import njit, i8, u1, void, b1
import heapq

@njit(void(i8,i8,i8,i8,b1[:,:]),cache=True)
def solve(ch,cw,dh,dw,road_map):

    h,w = road_map.shape

    queue = [[0,ch*w+cw]]
    used_map = np.full(h*w,-1,dtype=np.int64)

    #move walk
    while used_map[dh*w+dw] == -1 and len(queue) != 0:
        dot = heapq.heappop(queue)
        tl,n = dot[0],dot[1]
        if used_map[n] > -1 and used_map[n] <= tl:
            continue
        th,tw = divmod(n,w)
        used_map[n] = tl
        for x in range(-2,3,1):
            for y in range(-2,3,1):
                if th+ x < 0 or tw+y < 0 or th+x >= h or tw+y >= w or road_map[th+x][tw+y] == True:
                    continue
                if x == y == 0:
                    continue
                if abs(x)+abs(y) <= 1:
                    heapq.heappush(queue,[tl,(th+x)*w+tw+y])
                else:
                    heapq.heappush(queue,[tl+1,(th+x)*w+tw+y])

    print(used_map[dh*w+dw])

h,w = map(int,input().split())
ch,cw = map(int,input().split())
ch,cw = ch-1,cw-1
dh,dw = map(int,input().split())
dh,dw = dh-1,dw-1
road_map = np.array([[c=="#" for c in input()] for _ in range(h)])

solve(ch,cw,dh,dw,road_map)



### FIXED CODE ###

#shotoyooさんのコードをお借りしてテスト

import numpy as np
from numba import njit, b1, i4, i8, f8
from heapq import heappop as hpp, heappush as hp

@njit((b1[:, :],i8,i8,i8,i8), cache=True)
def main(ss,ch,cw,dh,dw):
    inf = 1<<30
    h,w = ss.shape
    start = ch*w+cw
    goal = dh*w+dw
    n = h*w
    seen = np.full(n, inf, np.int64)
    seen[start] = 0
    q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置
    while q:
        pnum,pu = hpp(q)
        ux,uy = divmod(pu,w)
        if pu==goal:
            break
        for xx in range(-2, 3):
            for yy in range(-2, 3):
                if xx==yy==0:
                    continue
                if abs(xx)+abs(yy)<=1:
                    vv = 0
                else:
                    vv = 1
                x,y = ux+xx, uy+yy
                u = x*w + y
                num = pnum+vv
                if x<0 or y<0 or x>=h or y>=w or ss[x][y]:
                    continue
        #         print(x,y)
                if seen[u]>num:
                    seen[u] = num
                    hp(q,(num, u))
                
    val = seen[goal]
    if val==inf:
        return -1
    else:
        return val
      

h,w = map(int, input().split())
ch,cw = map(int, input().split())
dh,dw = map(int, input().split())
ch -= 1
cw -= 1
dh -= 1
dw -= 1
ss = np.array([[c=="#" for c in input()] for _ in range(h)])

print(main(ss,ch,cw,dh,dw))
### BUGGY CODE ###

from scipy.sparse.csgraph import shortest_path, dijkstra
import numpy as np

N,M = map(int,input().split())
Map = np.array([np.array([0]*N) for i in range(N)])

for i in range(M):
  a,b = map(int,input().split())
  a,b = a-1,b-1
  Map[a][b] = 1
  Map[b][a] = 1
  
d,p = shortest_path(Map,indices=0, return_predecessors=True, directed=False, unweighted=True)
judge = 1 
ans = ''
for i in range(1,N):
  if(i != N-1):
     ans += str(p[i]+1)+'\n'
  else:
     ans += str(p[i]+1)   
  
  if(p[i]<0):
     judge = 0
     break

if(judge == 0):
  print('No')
else:
  print('Yes')
  print(ans)

### FIXED CODE ###

import math
import queue

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

# キューの定義
q = queue.Queue()
# キューにデータを挿入
q.put(0)
    
# キューからデータがなくなるまで取り出しを行う
flag = [0]*N 
flag[0]  = 1
ans_list = [0]*N

while(1):
  if(q.empty()):
    break
  num = q.get()
  for n in Map[num]:
    if(flag[n] != 1): # 訪問済みでないなら
      flag[n] = 1 # 訪問済みに
      ans_list[n] = num #　接続ノード(n)の1つ前のノードを今のノード(now)に
      q.put(n) # queueに接続ノードを入れる

print('Yes')
for i in range(1,N):
  print(ans_list[i]+1)
### BUGGY CODE ###

#!/usr/bin/env python3
 
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC138 E

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
m = len(t)
f = [False]*26
f2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
    f[alpha.index(s[i])] = True
for i in range(m):
    f2[alpha.index(t[i])] = True
for i in range(26):
    if not f[i] and f2[i]:
        print(-1)
        quit()
ans = 0
inde = s.index(t[0])
ans += inde+1
for i in range(1,m):
    s = s[inde+1:] + s[:inde+1]
    inde = s.index(t[i])
    ans += inde+1
print(ans)