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

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

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

# L はNとMのどちらでも割り切れる
# Xの1, L/N + 1 , 2 *  L/N + 1, ... (N-1) * L/N + 1の文字列を連結するとS 長さはN
# Xの1, L/M + 1 , 2 *  L/M+ 1, ... (M-1) * L/M + 1の文字列を連結するとT 長さはM

re = -1
# 1文字目が必ず一緒であること
if S[0] == T[0]:
    min_num = (N * M)  // gcd(N, M) # 最小公倍数を求める（基本はこれが答え）
    re = min_num
    # 重なる部分が同じ文字かを調べる
    s_d = min_num // N
    t_d = min_num // M
    # 最小公倍数みる
    st_min = (s_d * t_d) // gcd(s_d, t_d)
    st = st_min
    while st < N and st < M:
        if S[st // (min_num // N)] != T[st // (min_num // M)]:
            re = -1
            break

print(re)


### FIXED CODE ###

# A
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

re = -1
if S == T:
    re = N
elif S[0] == T[0]:
    min_num = (N * M)  // gcd(N, M) # 最小公倍数を求める（基本はこれが答え）
    re = min_num
    # 重なる部分が同じ文字かを調べる
    s_d = min_num // N
    t_d = min_num // M
    # 最小公倍数みる
    st_min = (s_d * t_d) // gcd(s_d, t_d)
    st = st_min
    i = 1
    while st // s_d < N and st // t_d < M:
        if S[st // s_d] != T[st // t_d]:
            re = -1
            break
        else:
            i += 1
            st = st_min * i

print(re)
### BUGGY CODE ###

n=int(input())
p=list(map(float,input().split()))
dp=[[0]*(n+1) for i in range(n)] #dp[i][j]=i番目までに裏がj枚出る確率
dp[0][0]=p[0]
dp[0][1]=1-p[0]
for i in range(1,n):
    dp[i][0]=dp[i-1][0]*p[i]
    for j in range(1,n+1):
        dp[i][j]=dp[i-1][j]*p[i]+dp[i-1][j-1]*(1-p[i])
ans=0
for i in range(n//2+1):
    ans+=dp[-1][i]
print(ans)

### FIXED CODE ###

n=int(input())
p=list(map(float,input().split()))
dp=[[0]*(n//2+2) for i in range(n)] #dp[i][j]=i番目までに裏がj枚出る確率
dp[0][0]=p[0]
dp[0][1]=1-p[0]
for i in range(1,n):
    dp[i][0]=dp[i-1][0]*p[i]
    for j in range(1,n//2+1):
        dp[i][j]=dp[i-1][j]*p[i]+dp[i-1][j-1]*(1-p[i])
ans=0
for i in range(n//2+1):
    ans+=dp[-1][i]
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(n)]
xset = list(set([i[0] for i in xy]))
yset = list(set([i[1] for i in xy]))
xset.sort()
yset.sort()

W = len(xset)
H = len(yset)
ans = float('inf')
for ix in range(W):
    for jx in range(ix, W):
        for iy in range(H):
            for jy in range(iy, H):
                xmin = min(xset[ix], xset[jx])
                xmax = max(xset[ix], xset[jx])
                ymin = min(yset[iy], yset[jy])
                ymax = max(yset[iy], yset[jy])
                cnt = 0
                for x, y in xy:
                    if xmin<=x<=xmax and ymin<=y<=ymax:
                        cnt+=1
                if cnt>=k:
                    ans = min(ans, (xmax-xmin)*(ymax-ymin))
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(n)]
xset = list(set([i[0] for i in xy]))
yset = list(set([i[1] for i in xy]))
xset.sort()
yset.sort()

W = len(xset)
H = len(yset)
ans = float('inf')
for ix in range(W):
    for jx in range(ix, W):
        for iy in range(H):
            for jy in range(iy, H):
                xmin = min(xset[ix], xset[jx])
                xmax = max(xset[ix], xset[jx])
                ymin = min(yset[iy], yset[jy])
                ymax = max(yset[iy], yset[jy])
                cnt = 0
                for x, y in xy:
                    if xmin<=x<=xmax and ymin<=y<=ymax:
                        cnt+=1
                if cnt>=k:
                    ans = min(ans, (xmax-xmin)*(ymax-ymin))
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:
    ans = -1

print(ans)

### FIXED CODE ###

N = int(input())

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

if 0 in A:
    print(0)
else:
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            exit(0)
    print(ans)
### BUGGY CODE ###

n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
import sys
sys.setrecursionlimit(10**6)
maxc = 0
a_i=0
b_i=0
def dfs(a_i,b_i,t,cnt):
    global maxc
    if(a_i==n and b_i==m):
        maxc = m+n
        return
    if(a_i==n):
        if((t+B[b_i])>k):
            if(cnt > maxc):
                maxc = cnt
            return
        dfs(a_i,b_i+1,t+B[b_i],cnt+1)
        return
    if(b_i==m):
        if((t+A[a_i])>k):
            if(cnt > maxc):
                maxc = cnt
            return
        dfs(a_i+1,b_i,t+A[a_i],cnt+1)
        return
    if((A[a_i]+t)<=k):
        dfs(a_i+1,b_i,A[a_i]+t,cnt+1)
    else:
        if(maxc < cnt):
            maxc = cnt
    if((B[b_i]+t)<=k):
        dfs(a_i,b_i+1,B[b_i]+t,cnt+1)
    else:
        if(maxc < cnt):
            maxc = cnt

        
dfs(0,0,0,0)
print(maxc)

### FIXED CODE ###

import bisect

n,m,k = map(int,input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

A_sum = [0]*(n+1)
B_sum = [0]*(m+1)

for i in range(n):
    A_sum[i+1] = A_sum[i] + A[i]

for i in range(m):
    B_sum[i+1] = B_sum[i] + B[i]

A_limit = bisect.bisect_right(A_sum,k) - 1
mc = 0
B_i = 0
for i in range(A_limit,-1,-1):
    remain_k = k - A_sum[i]
    while((remain_k-B_sum[B_i])>=0):
        B_i += 1
        if(B_i==(m+1)):
            break
    B_i -= 1
    mc = max(mc,(i+B_i))

print(mc)
### BUGGY CODE ###

from collections import deque
n = int(input())
q = deque(maxlen=n-1)

for i in range(n - 1):
    a, b, c = map(int, input().split())
    q.append([a-1, b-1, c % 2])

cllist = [-1] * n
a, b, c = q.popleft()
cllist[a] = 0
cllist[b] = c
while q:
    a, b, c = q.popleft()
    if cllist[a] != -1:
        cllist[b] = (cllist[a] + c) % 2
    elif cllist[b] != -1:
        cllist[a] = (cllist[b] + c) % 2
    else:
        q.append([a, b, c])
print(*cllist)


### FIXED CODE ###

from collections import deque
n = int(input())
q = deque(maxlen=n-1)

for i in range(n - 1):
    a, b, c = map(int, input().split())
    q.append([a-1, b-1, c % 2])

cllist = [-1] * n
a, b, c = q.popleft()
cllist[a] = 0
cllist[b] = c
while q:
    a, b, c = q.popleft()
    if cllist[a] != -1:
        cllist[b] = (cllist[a] + c) % 2
    elif cllist[b] != -1:
        cllist[a] = (cllist[b] + c) % 2
    else:
        q.append([a, b, c])
print(*cllist)
### BUGGY CODE ###

from math import ceil
from copy import deepcopy


def check(k):
    tmp = h[:]
    for i in range(N):
        tmp[i] -= B*k
    if sum([int(i<=0) for i in tmp]) == N:
        return True

    lf = 0
    for i in range(N):
        if tmp[i] > 0:
            lf += ceil(tmp[i]/(A-B))

    if lf <= k:
        return True
    else:
        return False

N,A,B = map(int,input().split())
h = [int(input()) for _ in range(N)]
m = max(h)
s = sum(h)

left = -1
right = 1e15

while abs(left-right) > 1:

    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid

print(int(right))

### FIXED CODE ###

import sys
from math import ceil

def input():
    return sys.stdin.readline().strip()

def check(k):
    tmp = list(h)
    for i in range(N):
        tmp[i] -= B*k
    if sum([int(i<=0) for i in tmp]) == N:
        return True

    lf = 0
    for i in tmp:
        if i > 0:
            lf += ceil(i/(A-B))

    if lf <= k:
        return True
    else:
        return False

N,A,B = map(int,input().split())
h = tuple(int(input()) for _ in range(N))

left = -1
right = 1e9

while abs(left-right) > 1:

    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid

print(int(right))
### BUGGY CODE ###

import collections
N=int(input())
s=[collections.Counter(input()) for _ in range(N)]
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if s[i]==s[j]:
            ans+=1
print(ans)

### FIXED CODE ###

N=int(input())
d={}
ans=0
for i in range(N):
    s=''.join(sorted(input()))
    if s in d:
        ans+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(ans)
### BUGGY CODE ###

import numpy as np
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
ans=0
dp=np.zeros((n+1,3001),np.int64)
for l in range(n):
  dp=np.zeros((n+1,3001),np.int64)
  dp[:,0]=1
  for i in range(l,n):
    dp[i+1]=dp[i]
    dp[i+1,a[i]:]+=dp[i,:-a[i]]
    dp[i+1:]%=mod
    ans+=dp[i+1,s]
    ans%=mod
print(ans)

### FIXED CODE ###

import numpy as np
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
f=np.zeros(3001,int)

ans=0
for ai in a:
  ff=np.zeros(3001,int)
  ff+=f
  ff[ai:]+=f[:-ai]
  ff[0]+=1
  ff[ai]+=1
  f=ff
  f%=mod
  ans+=f[s]
  ans%=mod
print(ans)
### BUGGY CODE ###

from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    else:
        if cnt%2!=0:
            s.reverse()
        if int(que[1])==1:
            s=deque(s)
            s.appendleft(que[2])
            cnt=0
        elif int(que[1])==2:
            s=deque(s)
            s.append(que[2])
            cnt=0
if cnt%2!=0:
    s.reverse()
print(''.join(s)) 


### FIXED CODE ###

from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    if len(que)!=1 and cnt%2==0:
        if int(que[1])==1:
            s.appendleft(que[2])
        elif int(que[1])==2:
            s.append(que[2])
    if len(que)!=1 and cnt%2!=0:
        if int(que[1])==1:
            s.append(que[2])
        elif int(que[1])==2:
            s.appendleft(que[2])
if cnt%2!=0:
    s.reverse()
print(''.join(s))
### BUGGY CODE ###

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

    pref = []
    for _ in range(M):
        P, Y = list(map(int, input().split()))
        pref.append((P, Y))

    pref_sorted = sorted(enumerate(pref), key=lambda x: x[1])

    res = ['' for _ in range(M)]
    for i in range(1, N + 1):
        c = 1
        for j, (p, y) in pref_sorted:
            if i == p:
                res[j] = str(p).zfill(6) + str(c).zfill(6)
                c += 1
    for r in res:
        print(r)


if __name__ == '__main__':
    main()


### FIXED CODE ###

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

    pref = []
    for _ in range(M):
        P, Y = list(map(int, input().split()))
        pref.append((P, Y))

    pref_sorted = sorted(enumerate(pref), key=lambda x: x[1])

    idx = [1 for _ in range(N)]
    res = ['' for _ in range(M)]
    for j, (p, y) in pref_sorted:
        res[j] = str(p).zfill(6) + str(idx[p - 1]).zfill(6)
        idx[p - 1] += 1
    for r in res:
        print(r)


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

num = int(input())
words = []
answer = 0

for i in range(num):
  words.append(sorted(list(input())))

for i in range(num):
  for j in range(num -i - 1):
    p = 0
    for k in range(10):
      if words[i][k] == words[j + 1 + i][k]:
        p += 1
      else:
        break
    if p == 10:
      answer += 1

print(answer)

### FIXED CODE ###

import math
num = int(input())
words = {}

for i in range(num):
  a = str(sorted(list(input())))
  
  if a in words:
    words[a] += 1
  else:
  	words[a] = 1

points = list(words.values())
sum = 0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(len(points)):
  if points[i] > 1:
  	sum += combinations_count(points[i], 2)
print(sum)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from collections import defaultdict


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

    for i in range(1,N+1):
        for j in range(W+1):
            dp[i][j] = dp[i-1][j]
            if j >= w[i-1]:
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1])
    print(dp[N][W])


# Generated by 1.1.4 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
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]" 
    v = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import defaultdict


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

    for i in range(1,N+1):
        for j in range(W+1):
            dp[i][j] = dp[i-1][j]
            if j >= w[i-1]:
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1])
    print(dp[N][W])


# Generated by 1.1.4 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
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]" 
    v = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)

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

import sys
sys.setrecursionlimit(10**9)

H, N = map(int, input().split())
AB = []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB = sorted(AB, key=lambda x: (x[0], x[1]))

INF = 10**20
dp = [INF for i in range(H + 1)]
dp[0] = 0
for i in range(1, H + 1):
    if dp[i] != INF:
        continue
    min_mp_cost = INF
    for damage, mp_cost in AB:
        parent = max(0, i - damage)
        new_cost = dp[parent] + mp_cost
        if new_cost < min_mp_cost:
            min_mp_cost = new_cost
    dp[i] = min_mp_cost
print(dp[-1])


### FIXED CODE ###

H, N = map(int, input().split())
AB = []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))

INF = 10**20
dp = [0]
for i in range(1, H + 1):
    min_mp_cost = INF
    for damage, mp_cost in AB:
        parent = max(0, i - damage)
        new_cost = dp[parent] + mp_cost
        if new_cost < min_mp_cost:
            min_mp_cost = new_cost
    dp.append(min_mp_cost)
print(dp[-1])
### BUGGY CODE ###

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

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

for i in range(M):
  a, b = map(int, input().split())
  c = sum(map(lambda x: 1 << (int(x)-1), input().split()))
  for j in range(1<<N):
    k = j|c
    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][k] = min(dp[i+1][k], dp[i][k], dp[i][j] + a)

ans = dp[-1][-1]

if ans == INF:
  print(-1)
else:
  print(ans)


### FIXED CODE ###

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

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

for i in range(M):
  a, b = map(int, input().split())
  c = sum(map(lambda x: 1 << (int(x)-1), input().split()))
  for j in range(1<<N):
    k = j|c
    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][k] = min(dp[i+1][k], dp[i][k], dp[i][j] + a)

ans = dp[-1][-1]

if ans == INF:
  print(-1)
else:
  print(ans)
### BUGGY CODE ###

n=int(input())
c=0
for i in range(1,n):
    c+=(i%n)
print(c)

### FIXED CODE ###

n=int(input())
n-=1
a=(n*(n+1))//2
print(a)
### BUGGY CODE ###

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


def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    for _ in range(N):
        print(max(A[0:_]+A[_+1:N]))
                

    

if __name__ == '__main__':
    main()

### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np

def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(int(input()))
    
    # A_ = np.array(A)
    # print(A)
    V = np.argmax(A)
    # print(V)
    MAX = max(A)
    # print(V)
    for _ in range(N):
        if _ == V:
            print(max(A[0:V]+A[V+1:N]))
        else:
            print(MAX)
                

    

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

import re


def main():
    s = input()
    n = 1e9
    ans = 0
    while n > 0:
        s, n = re.subn("01|10", "", s)
        ans += n*2
    print(ans)
    
main()

### FIXED CODE ###

def main():
    s = input()
    zero = s.count("0")
    one = s.count("1")
    print(min(zero, one) * 2)

main()
### BUGGY CODE ###

from itertools import combinations

n, p = map(int, input().split())
A = list(map(int, input().split()))         
C =[list(combinations(A, i)) for i in range(1, n+1)]

#print(C)
if p==0:
  cnt = 1
  for cs in C:
    for c in cs:
      if sum(c) % 2 == 0:
        #print(sum(c))
        cnt += 1
if p==1:
  cnt = 0
  for cs in C:
    for c in cs:
      if sum(c) % 2 == 1:
        cnt += 1
print(cnt)
  
 

### FIXED CODE ###

n, p = map(int, input().split())
A = list(map(int, input().split()))  

for a in A:
  if a % 2 != 0:
    break 
else:
  if p == 1: 
    print(0)
    exit()
  if p == 0: 
    print(2**n)
    exit()
  
ans = 2**(n-1)
print(ans)
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())

    graph = [[-1 for _ in range(N)] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        graph[u][v] = w
        graph[v][u] = w

    depth = [-1] * (N)
    depth[0] = 0
    def dfs(x):
        for i, g in enumerate(graph[x]):
            if depth[i] > -1 or g == -1:
                continue
            depth[i] = depth[x] + g
            dfs(i)
    dfs(0)
    print("\n".join(['1' if d % 2 == 0 else '0' for d in depth]))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())

    graph = defaultdict(lambda : defaultdict(int))
    for _ in range(N-1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        graph[u][v] = w
        graph[v][u] = w

    depth = [-1] * (N)
    depth[0] = 0
    def dfs(x):
        for i, g in graph[x].items():
            if depth[i] > -1:
                continue
            depth[i] = depth[x] + g
            dfs(i)
    dfs(0)
    print("\n".join(['1' if d % 2 == 0 else '0' for d in depth]))

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

def main():
    import sys
    input = sys.stdin.readline
    import collections
    def bfs(sy, sx, gy, gx):
        q = collections.deque()
        q.append((sy, sx))
        dist = [[-1] * W for _ in range(H)]
        dist[sy][sx] = 0
        dx = [(-1, 0), (1, 0), (0, -1), (0, 1)]
        dx2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1),(-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]
        while len(q) != 0:
            h, w = q.popleft()
            d = dist[h][w]
            for x, y in dx:
                h2 = h + y
                w2 = w + x
                if h2 >= 0 and h2 < H and w2 >= 0 and w2 < W:
                    if grid[h2][w2] == ".":
                        if dist[h2][w2] == -1:
                            dist[h2][w2] = d
                            q.append((h2, w2))
                        elif d < dist[h2][w2]:
                            dist[h2][w2] = d
                            q.append((h2, w2))
            for x, y in dx2:
                h2 = h + y
                w2 = w + x
                if h2 >= 0 and h2 < H and w2 >= 0 and w2 < W:
                    if grid[h2][w2] == "." and (dist[h2][w2] == -1 or d + 1 < dist[h2][w2]):
                        dist[h2][w2] = d + 1
                        q.append((h2, w2))
        return dist[gy][gx]

    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    grid = [input() for _ in range(H)]
    print(bfs(Ch-1, Cw-1, Dh-1, Dw-1))
main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
import collections
def bfs(sy, sx, gy, gx):
    q = collections.deque()
    q.append((sy, sx))
    dist = [[-1] * W for _ in range(H)]
    dist[sy][sx] = 0
    dx = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    dx2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1),(-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]
    while len(q) != 0:
        h, w = q.popleft()
        d = dist[h][w]
        for x, y in dx:
            h2 = h + y
            w2 = w + x
            if h2 >= 0 and h2 < H and w2 >= 0 and w2 < W:
                if grid[h2][w2] == ".":
                    if dist[h2][w2] == -1:
                        dist[h2][w2] = d
                        q.appendleft((h2, w2))
                    elif d < dist[h2][w2]:
                        dist[h2][w2] = d
                        q.appendleft((h2, w2))
        for x, y in dx2:
            h2 = h + y
            w2 = w + x
            if h2 >= 0 and h2 < H and w2 >= 0 and w2 < W:
                if grid[h2][w2] == "." and (dist[h2][w2] == -1 or d + 1 < dist[h2][w2]):
                    dist[h2][w2] = d + 1
                    q.append((h2, w2))
    return dist[gy][gx]

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
grid = [input() for _ in range(H)]
print(bfs(Ch-1, Cw-1, Dh-1, Dw-1))
### BUGGY CODE ###

n = int(input())
a = [int(e) for e in input().split()]
for i in range(0,n):
    for j in range(0,n):
        if a[j] == i + 1:
            print(j + 1, end = " ")


### FIXED CODE ###

n = int(input())
a = [int(e) for e in input().split()]
b = [0] * n
for i in range(0,n):
    b[a[i] - 1] = i + 1
for j in range(0,n):
    print(b[j], end = " ")
### BUGGY CODE ###

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

c = 0

for i in range(a):
    if (b[i] - min(b[i:a]))>1:
      c+=1
      break
if c==0: print("Yes")
else: print("No")

### FIXED CODE ###

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

c = 0

for i in range(a):
  if i>0:
    if (b[i] - b[i-1])<-1:
      c+=2
    if (b[i] - b[i-1])==-1:
      c+=1
    if (b[i] - b[i-1])>0:
      c=0
  if c>=2: break
if c<=1: print("Yes")
else: print("No")
### BUGGY CODE ###


n, m = list(map(int, input().split()))
edges = [[] for i in range(n)]
for i in range(m):
    tx, ty, _tz = list(map(int, input().split()))
    edges[tx-1].append(ty-1) 
    edges[ty-1].append(tx-1) 
visited = [False] * n
ans = 0
for i in range(n):
    if not visited[i]:
        q = [i]
        visited[i] = True
        while q:
            u = q.pop(0)
            for v in edges[u]:
                if not visited[v]:
                    q.append(v)
                    visited[v] = True
        ans += 1
print(ans)


### FIXED CODE ###


n, m = list(map(int, input().split()))
edges = [[] for i in range(n)]
for i in range(m):
    tx, ty, _tz = list(map(int, input().split()))
    edges[tx-1].append(ty-1) 
    edges[ty-1].append(tx-1) 
visited = [False] * n
ans = 0
for i in range(n):
    if not visited[i]:
        q = [i]
        visited[i] = True
        while q:
            u = q.pop(0)
            for v in edges[u]:
                if not visited[v]:
                    q.append(v)
                    visited[v] = True
        ans += 1
print(ans)
### BUGGY CODE ###

N=int(input())
S=input()
A=[]
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      A.append(S[i]+S[j]+S[k])
print(len(set(A)))

### FIXED CODE ###

from itertools import product
 
N = int(input())
S = input()
 
cnt = 0
for i, j, k in product("0123456789", repeat=3):
    try:
        x = S.index(i)
        y = S.index(j, x + 1)
        z = S.index(k, y + 1)
    except:
        continue
    cnt += 1
 
print(cnt)