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

def main():
    N = int(input())
    a = list(map(int, input().split()))
    A = [0]*4
    for x in a:
        A[x] += 1

    dp = [[[0]*(N+1) for i in range(N+1)] for j in range(N+1)]

    for k in range(A[3]+1):
        for j in range(A[2]+A[3] + 1 - k):
            for i in range(A[1]+A[2]+A[3] + 1 - k - j):
                if i + j+k == 0:
                    continue
                P = N
                if i > 0:
                    P += dp[i-1][j][k] * i
                if j > 0:
                    P += dp[i+1][j-1][k] * j
                if k > 0:
                    P += dp[i][j+1][k-1] * k
                dp[i][j][k] = P/(i+j+k)

    print(dp[A[1]][A[2]][A[3]])
main()


### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    a = A.count(1)
    b = A.count(2)
    c = A.count(3)
    floatN = N*1.0
    dp = [[[.0]*(N+1) for i in range(N+1)] for j in range(N+1)]

    for k in range(c+1):
        for j in range(b+c + 1 - k):
            for i in range(N + 1 - k - j):
                if i + j+k == 0:
                    continue
                dp[i][j][k] = floatN
                if i > 0:
                    dp[i][j][k] += dp[i-1][j][k] * i
                if j > 0:
                    dp[i][j][k] += dp[i+1][j-1][k] * j
                if k > 0:
                    dp[i][j][k] += dp[i][j+1][k-1] * k
                dp[i][j][k] /= (i+j+k)
    print(dp[a][b][c])


main()
### BUGGY CODE ###

from itertools import (
    accumulate,  # 累積和のイテレータ
    groupby,  # 値をkey,同じ値の集まりをgroup
    permutations,  # 順列
    combinations,  # 組み合わせ
    product,  # 重複あり順列（直積, 深いネストにも使える）
    combinations_with_replacement,  # 重複あり組み合わせ
)

N, M, X = map(int, input().split())
book = [list(map(int, input().split())) for _ in range(N)]

def check(tisiki):
    cnt = 0
    for t in tisiki:
        if t<X:
            return False
    return True

ans = 10**9
for v in permutations(list(range(N))):
    tisiki = [0] * M
    cost = 0
    for i in v:
        b = book[i]
        cost += b[0]
        for t in range(M):
            tisiki[t] += b[t+1]
        
        if check(tisiki):
            ans = min(ans, cost)
            break

if ans < 10**9:
    print(ans)
else:
    print(-1)

### FIXED CODE ###

import numpy as np

N, M, X = map(int, input().split())
book = [list(map(int, input().split())) for _ in range(N)]

ans = 10**9

for i in range(1<<N):
    cost = 0
    tisiki = np.array([0]*M)
    cond = [0]*N
    for j in range(N):
        if 1&(i>>j):  # 右シフトして論理積（bit全探索）
            cond[j] = 1
    
    for k in range(N):
        if cond[k]==1:
            b = book[k]
            cost += b[0]
            tisiki += np.array(b[1:])
    
    if np.all(tisiki>=X):
        ans = min(ans, cost)

if ans < 10**9:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

N = int(input())
s = [input() for i in range(N)]
for i in range(N):
    s[i] = list(s[i])
    s[i].sort()
count = 0
for i in range(N):
    for j in range(i + 1, N):
        if s[i] == s[j]:
            count += 1
print(count)

### FIXED CODE ###

N = int(input())

s = []
ans = 0
count = 1

for i in range(N):
    tmp = input()
    s.append("".join(sorted(tmp)))

s.sort()

for i in range(N - 1):
    if s[i] == s[i + 1]:
        count += 1
    else:
        ans += count*(count - 1) / 2
        count = 1
ans += count*(count - 1) / 2

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

def main():
    n = int(input())
    xy = [list(map(int, input().split())) for _ in [0]*n]

    def check(r):
        flag = 0
        for i in range(n):
            x1, y1 = xy[i]
            for j in range(i+1, n):
                x2, y2 = xy[j]
                if (x1-x2)**2+(y1-y2)**2 > r**2:
                    flag = 1
                    break
            if flag == 1:
                return False
        else:
            return True

    def b_search(a, b, value, delta):
        while True:
            med = (a+b)/2
            if abs(b-a) < delta:
                if value(a):
                    return a
                else:
                    return b
            elif value(med):
                b = med
            else:
                a = med

    print(b_search(0, 3000, check, 10**-15)/2)


main()

### FIXED CODE ###

def main():
    n = int(input())
    xy = [list(map(int, input().split())) for _ in [0]*n]
    from scipy.optimize import fmin

    def calc(k):
        i, j = k
        ans = 0
        for x, y in xy:
            ans = max(ans, (x-i)**2+(y-j)**2)
        return ans

    x, y = fmin(calc, [500, 500], disp=0)
    print(calc((x, y))**0.5)


main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n, d, a = [int(i) for i in input().split()]
chk = []
for i in range(n):
  x, h = [int(i) for i in input().split()]
  chk.append((x, 0, h))
  
from heapq import heapify, heappop, heappush
heapify(chk)
atk_cnt = 0
ans = 0
while chk:
  x, t, h = heappop(chk)
  if t == 0:
    if atk_cnt * a >= h:
        continue
    remain = h - atk_cnt * a
    new_atk = (remain - 1) // a + 1
    heappush(chk, (x + 2 * d, 1, new_atk))
    ans += new_atk
    atk_cnt += new_atk
  else:
    atk_cnt -= h
print(ans)

### FIXED CODE ###

def main():  
  import sys
  input = sys.stdin.readline
  n, d, a = [int(i) for i in input().split()]
  chk = []
  for i in range(n):
    x, h = [int(i) for i in input().split()]
    chk.append((x, 0, h))

  from heapq import heapify, heappop, heappush
  heapify(chk)
  atk_cnt = 0; ans = 0
  while chk:
    x, t, h = heappop(chk)
    if t == 0:
      if atk_cnt * a >= h:
          continue
      remain = h - atk_cnt * a
      new_atk = (remain - 1) // a + 1
      heappush(chk, (x + 2 * d, 1, new_atk))
      ans += new_atk
      atk_cnt += new_atk
    else:
      atk_cnt -= h
  print(ans)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

#pragma GCC optimize("Ofast")

a=int(input())

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

sum=0
mod = 10**9+7

for i in range(a-1):
  for j in range(i+1,a):
    sum=pow(sum+d[i]*d[j],1,mod)

print(sum)

### FIXED CODE ###

MOD = 10 ** 9 + 7

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

total=sum(alst)
sum=0

# for i in range(n-1):
#   for j in range(i+1,n):
#     sum=pow(sum+alst[i]*alst[j],1,MOD)

# print(sum)

for a in alst:
  sum = sum+a * (total - a)
  sum %= MOD

sum *= pow(2, MOD - 2, MOD)
sum %= MOD
print(sum)
### BUGGY CODE ###

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

### FIXED CODE ###

def main():
  n = int(input())
  s = input()
  r = g = b = d =0
  for i in range(n):
    if s[i] == "R":
      r += 1
    elif s[i] == "G":
      g += 1
    else:
      b += 1
  a = r * g * b
  for i in range(n):
    for j in range(i+1,n):
      if s[i] == s[j]:
        continue
      k = 2*j - i
      if k >= n or s[k] == s[i] or s[k] == s[j]:
        continue
      d += 1
  print(a - d)
  
if __name__ == "__main__":
  main()
### BUGGY CODE ###

N = int(input())
X = input()

X_1 = bin(int(X, 2)).count('1')


for i in range(N):
  
  X_list = list(X)
  if X_list[i] == '0':
    X_list[i] = '1'
    first = X_1 + 1
  else:
    X_list[i] = '0'
    first = X_1 - 1
  
  X_str = ''.join(X_list)
  n = int(X_str, 2)
  fn = 0
  if n != 0:
    n = n % first
    fn += 1
  while n != 0:
    n = n % bin(n).count('1')
    fn += 1
  
  print(fn)
  

### FIXED CODE ###

N = int(input())
X = input()

X_int = int(X, 2)
cnt1 = bin(X_int).count('1')
pcXi01 = cnt1 + 1
pcXi10 = cnt1 - 1
zero_idx = N + 5
if cnt1 == 1:
  for i in range(N):
    if X[i] == '1':
      zero_idx = i

if pcXi10 < 1:
  pcXi10 = 1
Xmod01 = X_int % pcXi01
Xmod10 = X_int % pcXi10

tmp01 = [1]
tmp10 = [-1]
for i in range(N - 1):
  tmp01.append(tmp01[i]*2 % pcXi01)
  tmp10.append(tmp10[i]*2 % pcXi10)

init_n = [0] * N
next_n = [0] * N
for i in range(N):
  if X[i] == '0':
    next_n[i] = (Xmod01 + tmp01[N - 1 - i]) % pcXi01
  else:
    next_n[i] = (Xmod10 + tmp10[N - 1 - i]) % pcXi10

for i in range(N):
  fn = 0
  if i == zero_idx:
    print(0)
    continue

  n = next_n[i]
  fn += 1
  while n != 0:
    n = n % bin(n).count('1')
    fn += 1
  
  print(fn)
### BUGGY CODE ###

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        if j - wv[i][0] >= 0:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])
        else:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

print(dp[N][W])

### FIXED CODE ###

N, W = map(int, input().split())
w = [list(map(int, input().split())) for _ in range(N)]
dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

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

        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

print(dp[N][W])
### BUGGY CODE ###

n = int(input())
ans = 0
for a in range(1, n+1):
    for b in range(1, n+1):
        if a*b < n:
            ans += 1
        else:
            break
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0
for a in range(1, n+1):
    ans += (n-1)//a
print(ans)
### BUGGY CODE ###

n = int(input())
A = []
for _ in range(n):
  A.append(int(input()))

Max = max(A)
for i in range(n):
  if A[i] != Max:
    print(Max)
  else:
    print(max(A[:i] + A[i+1:]))

### FIXED CODE ###

n = int(input())
A = []
for _ in range(n):
  A.append(int(input()))

first = max(A)
B = A.copy()
B.remove(first)
second = max(B)

for i in range(n):
  if A[i] != first:
    print(first)
  else:
    print(second)
### BUGGY CODE ###

# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    h, w = map(int, args[0].split())
    A = [[c for c in s] for s in args[1:]]

    Q = deque()
    for y in range(h):
        for x in range(w):
            if A[y][x] == '#':
                A[y][x] = '.'
                Q.append((x, y, 0))

    ret = 0
    while Q:
        x, y, n = Q.popleft()
        if A[y][x] == '.':
            A[y][x] = '#'
            ret = max(ret, n)
            if 0 < x:
                Q.append((x-1, y, n+1))
            if x+1 < w:
                Q.append((x+1, y, n+1))
            if 0 < y:
                Q.append((x, y-1, n+1))
            if y+1 < h:
                Q.append((x, y+1, n+1))

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


### FIXED CODE ###

# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    h, w = map(int, args[0].split())
    A = [[c == '.' for c in s] for s in args[1:]]

    Q = deque()
    for y in range(h):
        for x in range(w):
            if not A[y][x]:
                Q.append((x, y, 0))

    ret = 0
    while Q:
        x, y, n = Q.popleft()

        ret = max(ret, n)
        if 0 < x and A[y][x-1]:
            Q.append((x-1, y, n+1))
            A[y][x-1] = False

        if x+1 < w and A[y][x+1]:
            Q.append((x+1, y, n+1))
            A[y][x+1] = False

        if 0 < y and A[y-1][x]:
            Q.append((x, y-1, n+1))
            A[y-1][x] = False

        if y+1 < h and A[y+1][x]:
            Q.append((x, y+1, n+1))
            A[y+1][x] = False

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
### BUGGY CODE ###

def main():
    for l in range(n, 0, -1):
        D = {}
        for i in range(n-l+1):
            s = S[i:i+l]
            try:
                if D[s] + l <= i:
                    return l
            except:
                D[s] = i
    return 0


n = int(input())
S = input()
print(main())


### FIXED CODE ###

def zalgo(S):
    # SとS[i:n]のlcpの長さを記録した配列を返す
    n = len(S)
    A = [0] * n
    j = 0
    for i in range(1, n):
        if i+A[i-j] < j+A[j]:
            A[i] = A[i-j]
        else:
            k = max(0, A[j]-i+j)
            while i+k < n and S[k] == S[i+k]:
                k += 1
            A[i] = k
            j = i
    A[0] = n
    return A


n = int(input())
S = input()
l = 0
for i in range(n):
    A = zalgo(S[i:])
    B = [min(j, a) for j, a in enumerate(A)]
    l = max(l, max(B))
print(l)
### BUGGY CODE ###

import math


def solve():
    A, B, N = map(float, input().split())
    ans = 0

    for i in reversed(range(max(1, int(N)-10000, int(N) + 1))):
        ans = max(math.floor(A * i / B) - A * math.floor(i / B), ans)

    print(int(ans))


if __name__ == '__main__':
    solve()


### FIXED CODE ###

def solve():
    A,B,N = map(int, input().split())
    if N < B-1:
        print((A*N)//B - A * (N//B))
    else:
        print(((A*(B-1))//B) - A* ((B-1)//B))


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

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for a in A:
    for b in B[bisect_right(B, a):]:
        ans += len(C[bisect_right(C, b):])
print(ans)


### FIXED CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())

ans = 0
for b in B:
    a = bisect_left(A, b)
    c = bisect_right(C, b)
    ans += a*(n-c)
print(ans)
### BUGGY CODE ###

N, M = [int(i) for i in input().split()]

all_cities = []
p_list = []
for i in range(M):
    p, y = [int(j) for j in input().split()]
    city = [i, p, y]
    p_list.append(p)
    all_cities.append(city)
    
p_set = set(p_list)

sorted_all_cities = []
for p in p_set:
    pref_city_list = []
    for city in all_cities:
        if city[1] == p:
            pref_city_list.append(city)
            
    sorted_pref_city_list = sorted(pref_city_list, key=lambda x: x[2])
    
    for c, city in enumerate(sorted_pref_city_list):
        city[2] = c + 1
        sorted_all_cities.append(city)
    
re_sorted_all_cities = sorted(sorted_all_cities, key=lambda x: x[0])

for city in re_sorted_all_cities:
    prefcode = "{0:06d}".format(city[1])
    citycode = "{0:06d}".format(city[2])
    print(prefcode+citycode)



### FIXED CODE ###

from collections import defaultdict
import bisect

N, M = [int(i) for i in input().split()]

PY = []
PYd = defaultdict(list)

for i in range(M):
    x, y = [int(i) for i in input().split()]
    PYd[x].append(y)
    PY.append((x,y))
    
for i in PYd.keys():
    PYd[i].sort()
    
for p,y in PY:
    str_p = str(p).zfill(6)
    index = str(bisect.bisect(PYd[p], y)).zfill(6)
    print(str_p+index)
### BUGGY CODE ###

str_list = str(input())
length = len(str_list)

cnt = 4
result = 0

for i in range(length-3):
    for j in range(length-cnt+1):
        if int(str_list[j:j+cnt])%2019 == 0:
            result += 1
    cnt += 1

print(result)

### FIXED CODE ###

S = str(input())
N = len(S)

num = [0] * 2019
num[0] = 1
prev = 0
result = 0
_10 = 1
for i in range(N-1, -1, -1):
    prev = (prev + int(S[i]) * _10) % 2019
    _10 *= 10
    _10 %= 2019
    result += num[prev]
    num[prev] += 1

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

S = input()
Q = int(input())
Query = []*Q
for _ in range(Q):
    Query.append(list(map(str,input().split())))

for q in Query:
    if q[0]=='1':
        S = S[::-1]
    else:#q[0]=='2'
        if q[1]=='1':
            S = q[2] + S
        else:#q[1]=='2'
            S = S + q[2]
print(S)


### FIXED CODE ###

from collections import deque
S = deque(input())
Q = int(input())
Query = [[] for _ in range(Q)]
for i in range(Q):
    Query[i] = list(map(str,input().split()))

fl = False
for q in Query:
    if q[0]=='1':
        fl = not fl
    else:#q[0]=='2'
        if (q[1]=='1') ^ fl:
            S.appendleft(q[2])
        else:#q[1]=='2'
            S.append(q[2])
T = ''.join(S)
if fl:
    T = T[::-1]
print(T)
### BUGGY CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
count = 0
visited = []

btn = 0
while True:
  if btn in visited:
    print('-1')
    break
  visited.append(btn)
  btn = a[btn]-1
  count += 1
  if btn==1:
    print(count)
    break
  

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]

ans = -1
count = 0
btn = 0
for i in range(n):
  btn = a[btn]-1
  count += 1
  if btn == 1:
    ans = count
    break

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

n = int(input())
l = [int(input()) for j in range(n)]
for i in range(n):
  a =l[:i]+l[i+1:]
  print(max(a))

### FIXED CODE ###

n = int(input())
l = ([int(input()) for j in range(n)])
a = sorted(l)[-1]
b = sorted(l)[-2]

for i in range(n):
  if l[i]==a:
    print(b)
  else:
    print(a)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ac = []
ac_append = ac.append
wa = {}
ok = 0
ng = 0

for _ in range(m):
    p, s = input().split()
    if p not in ac:
        if s == "AC":
            ac_append(p)
            ok += 1
            if p in wa.keys():
                ng += wa[p]
        else:
            if p in wa.keys():
                wa[p] += 1
            else:
                wa[p] = 1

print(ok, ng)


### FIXED CODE ###

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ac = {str(i): 0 for i in range(n+1)}
wa = {str(i): 0 for i in range(n+1)}
ok = 0
ng = 0

for _ in range(m):
    p, s = input().split()
    if ac[p] == 0:
        if s == "AC":
            ac[p] += 1
            ok += 1
            if wa[p] > 0:
                ng += wa[p]
        else:
            wa[p] += 1

print(ok, ng)
### BUGGY CODE ###

n = int(input())
s = []
count = 0
for i in range(n):
    s1 = list(input())
    s1.sort()
    s.append(s1)
for i in range(n):
    for j in range(i+1,n):
        if s[i] == s[j]:
            count = count + 1
print(count)

### FIXED CODE ###

n = int(input())
s = []
count = 0
for i in range(n):
    s1 = list(input())
    s1.sort()
    s1 = "".join(s1)
    s.append(s1)
s.sort()
s2 = list(set(s))
s2.sort()
if len(s) == len(s2):
    print("0")
else:
    j1 = 0
    j2 = 0
    count1 = 0
    while j1 < n and j2 < len(s2):
        if s[j1] == s2[j2]:
            count1 = count1 + 1
            j1 = j1 + 1
        else:
            count = count + int(count1*(count1-1)/2)
            j2 = j2 + 1
            count1 = 0
    count = count + int(count1*(count1-1)/2)
    print(count)
### BUGGY CODE ###

n = int(input())
lst = list(map(int, input().split()))
res = 0
pre_left = 0
while True:
  Max = 0
  w = 0
  left = 0
  right = n
  flag = False
  for i in range(n):
    if lst[i] > 0 and not flag:
      if i == n-1:
        if Max:
          break
      w = 1
      pre_left = left
      left = i
      flag = True
      if i == n-1:
        right = n
        Max = 1
    elif lst[i] > 0 and flag:
      w += 1
      if i == n-1:
        if Max < w:
          Max = w
          right = n
        else:
          left = pre_left
    elif lst[i] <= 0 and flag:
      if Max < w:
        Max = w
        right = i
        flag = False
      else:
        left = pre_left
      w = 0
  if w == n:
    Max = n
  if Max == 0:
    break
  d = min(lst[left:right])
  for i in range(left, right):
    lst[i] -= d
  res += d
      
print(res)

### FIXED CODE ###

def rec(lst, left, right):
    if left == right:
        return 0
    if not 0 in lst[left:right]:
        m = min(lst[left:right])
        lst[left:right] = [x - m for x in lst[left:right]]
        return m + rec(lst, left, right)
    k = lst[left:right].index(0)
    return rec(lst, left, left + k) + rec(lst, left + k+1, right)


N = int(input())
lst = list(map(int, input().split()))
print(rec(lst, 0, len(lst)))
### BUGGY CODE ###

import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

#1回ずつ数えて答えを3で割る
N, M = lr()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(M):
    u, v = lr()
    graph[u].append(v)

S, T = lr()
que = deque([(S, 0)])
time_set = [set() for _ in range(N+1)] # 1-indexed
while que:
    q, time = que.popleft()
    if time > M * 3:
        break
    for next in graph[q]:
        if time_set[next] == (time+1) % 3:
            continue
        if next == T and (time+1) % 3 == 0:
            print((time+1)//3); exit()
        que.append((next, time+1))
        time_set[next].add((time+1)%3)

print(-1); exit()
# 52

### FIXED CODE ###

import sys
from heapq import heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
# 3*N頂点あるとする
edges = [[] for _ in range(3*N + 4)] # 3-indexed
for _ in range(M):
    u, v = lr()
    u *= 3; v *= 3
    edges[u].append(v+1)
    edges[u+1].append(v+2)
    edges[u+2].append(v)

INF = 10 ** 18

def dijkstra(start):
    dist = [INF] * (3*N+4)
    dist[start] = 0
    que = [(0, start)]
    while que:
        d, v = heappop(que)
        if dist[v] < d:
            continue
        for next in edges[v]:
            d1 = d + 1
            if dist[next] > d1:
                dist[next] = d1
                heappush(que, (d1, next))
    return dist

S, T = lr()
dist = dijkstra(S*3)
if dist[T*3] == INF:
    print(-1)
else:
    print(dist[T*3] // 3)