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

N = int(input())
A = [int(input()) for i in range(N)]
i = 0
cnt = 1
cmpr = [0]
while A[i] != 2:
    if A[i] == i + 1:
        print(-1)
        exit()
    i = A[i] - 1
    if i in cmpr:
        print(-1)
        exit()
    cmpr.append(i)
    cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
i = 0
cnt = 1
cmpr = [0]
while A[i] != 2:
    if A[i] == i + 1:
        print(-1)
        exit()
    i = A[i] - 1
    cmpr.append(i)
    cnt += 1
    if cnt > N:
        print(-1)
        exit()
print(cnt)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

# コンビネーション
mod = P
def cmb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NN = 10**5 # 使うデータによって変える
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, NN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = [0]*P
for j, a in enumerate(A):
    if a == 1:
        ans[0] = (ans[0] + 1) % P
        for k in range(P):
            ans[P-1-k] = (ans[P-1-k] - cmb(P-1, k) * pow(j, k, P) * (-1)**k) % P
print(*ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    P = int(input())
    A = list(map(int, input().split()))

    # コンビネーション
    mod = P
    def cmb(n, r, mod=mod):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    NN = 10**5 # 使うデータによって変える
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range( 2, NN + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    ans = [0]*P
    for j, a in enumerate(A):
        if a == 1:
            ans[0] = (ans[0] + 1) % P
            t = 1
            for k in range(P):
                ans[P-1-k] = (ans[P-1-k] - cmb(P-1, k) * t) % P
                t = t * (-j) % P
    print(*ans)


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

#!/usr/bin/env python3
import sys
import math
import bisect

def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return set(prime for prime in primes if prime != 0)


def is_prime(prime_list,a):
    return a in prime_list

def solve(Q: int, L: "List[int]", R: "List[int]"):
    prime_list = primes(10**5)

    for l,r in zip(L,R):
        ll = (l+1)//2
        rr = (r+1)//2
        res = 0
        for i,j in zip(range(l,r+1,2),range(ll,rr+1,1)):
            if is_prime(prime_list,i) and is_prime(prime_list,j):
                res += 1
        print(res)

# 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()
    Q = int(next(tokens))  # type: int
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(Q, l, r)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import math
import bisect

def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return set(prime for prime in primes if prime != 0)


def is_prime(prime_list,a):
    return a in prime_list

def solve(Q: int, L: "List[int]", R: "List[int]"):
    prime_list = primes(10**5)

    DP = [0] * (10**5)
    for i in range(1,int(10**5)):
        DP[i] = DP[i-1]
        if is_prime(prime_list,i) and is_prime(prime_list,(i+1)//2):
            DP[i] += 1

    for l,r in zip(L,R):
        print(DP[r] - DP[l-1])

# 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()
    Q = int(next(tokens))  # type: int
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(Q, l, r)

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

class BITRAQ:
    def __init__(self, n):
        self.n = n + 1
        self.bit = [[0]*(self.n) for _ in range(2)]
    
    def add_sub(self, p, i, x):
        while i < self.n:
            self.bit[p][i] += x
            i += i & -i
    
    def add(self, l, r, x):
        self.add_sub(0, l, -x * (l - 1))
        self.add_sub(0, r, x * (r - 1))
        self.add_sub(1, l, x)
        self.add_sub(1, r, -x)

    def sum_sub(self, p, i):
        s = 0
        while i > 0:
            s += self.bit[p][i]
            i -= i & -i
        return s
    
    def sum(self, i):
        return self.sum_sub(0, i) + self.sum_sub(1, i) * i

    def get(self, i):
        return self.sum(i) - self.sum(i - 1)

p = 998244353

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

hop = []

for i in range(K):
    hop.append(tuple(map(int, input().split())))

dp = BITRAQ(N)

dp.add(1, 2, 1)

for i in range(N - 1):
    for j in range(K):
        dp.add(i + hop[j][0] + 1, min(N + 1, i + hop[j][1] + 2), dp.get(i + 1) % p)

print(dp.get(N) % p)

### FIXED CODE ###

class BITRAQ:
    def __init__(self, n, mod):
        self.n = n + 1
        self.mod = mod
        self.bit = [[0]*(self.n) for _ in range(2)]
    
    def add_sub(self, p, i, x):
        while i < self.n:
            self.bit[p][i] += x
            self.bit[p][i] %= self.mod
            i += i & -i
    
    def add(self, l, r, x):
        self.add_sub(0, l, -x * (l - 1))
        self.add_sub(0, r, x * (r - 1))
        self.add_sub(1, l, x)
        self.add_sub(1, r, -x)

    def sum_sub(self, p, i):
        s = 0
        while i > 0:
            s += self.bit[p][i]
            i -= i & -i
        return s
    
    def sum(self, i):
        return self.sum_sub(0, i) + self.sum_sub(1, i) * i

    def get(self, i):
        return self.sum(i) % self.mod - self.sum(i - 1) % self.mod

p = 998244353

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

hop = []

for i in range(K):
    hop.append(tuple(map(int, input().split())))

dp = BITRAQ(N, p)

dp.add(1, 2, 1)

for i in range(N - 1):
    for j in range(K):
        dp.add(i + hop[j][0] + 1, min(N + 1, i + hop[j][1] + 2), dp.get(i + 1) % p)

print(dp.get(N) % p)
### BUGGY CODE ###

import sys
from collections import defaultdict
def main(lines):
    friend = []
    block = []
    friend_dict = defaultdict(list)
    for i, v in enumerate(lines):
        if i == 0:
            N, M, K = [int(a.strip()) for a in v.split(' ')]
        elif i < M + 1:
            a, b = [int(a.strip()) for a in v.split(' ')]
            friend.append([a,b])
            friend_dict[a].append(b)
            friend_dict[b].append(a)
        else:
            c, d = [int(a.strip()) for a in v.split(' ')]
            block.append([c,d])
    
    tree_list = []
    while friend_dict != {}:
        seen = DFS(friend_dict)
        tree_list.append(seen)
        for k in seen:
            friend_dict.pop(k)

    result = {}
    for i in range(1,N+1):
        flg = 0 
        for tree in tree_list:
            if i in tree:
                result[i] = len(tree)-1
                flg = 1
        if flg == 0:
            result[i] = 0

    for i,j in friend:
        result[i] -= 1
        result[j] -= 1

    for i,j in block:
        for tree in tree_list:
            if j in tree and i in tree:
                    result[i] -= 1
                    result[j] -= 1
    s_n = ' '.join([str(i)for i in result.values()])
    print(s_n)

def DFS(node_dict):
    p = list(node_dict.keys())[0]
    seen = [p]
    todo = [p]
    while todo != []:
        for i in todo:
            for j in node_dict[i]:
                flg =0
                if not j in seen:
                    flg = 1
                    seen.append(j)
                    todo.append(j)
                    continue
                else:
                    continue
                if flg == 0:
                    todo.remove(j)
        todo.remove(i)
    return seen
                
if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)

### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
N, M, K = map(int, input().split())

def dfs(v):
    size = 1
    for w in fr[v]:
        if ~roots[w]: continue
        roots[w] = roots[v]
        size += dfs(w)
    return size

fr = defaultdict(set)
for _ in range(M):
    a, b = [int(x) -1 for x in input().split()]
    fr[a].add(b)
    fr[b].add(a)
bl = defaultdict(set)
for _ in range(K):
    a, b = [int(x) - 1 for x in input().split()]
    bl[a].add(b)
    bl[b].add(a)

roots = [-1] * N
sizes = [-1] * N

for v in range(N):
    if ~roots[v]: continue
    roots[v] = v
    sizes[v] = dfs(v)

ans = []
for v in range(N):
    w = roots[v]
    res = sizes[w] - len(fr[v]) - sum(1 for u in bl[v] if roots[u] == w) -1
    ans.append(res)

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

from heapq import heappop, heappush

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

g = [[10**10 for _ in range(n)] for __ in range(n)]

for _ in range(m):
    l, r, c = map(int, input().split())
    g[l-1][r-1] = min(g[l-1][r-1], c)

for i in range(1, n):
    g[i][i-1] = 0


def dijkstra(s, n, edges):
    # edges[i][j] : the cost of i→j
    # import 'heap'
    d = [10**13] * n
    d[s] = 0
    q = [(0, s)]
    while q:
        dist_u, u = heappop(q)
        if d[u] < dist_u:
            continue
        for v, c in enumerate(edges[u]):
            if d[v] > dist_u + c:
                d[v] = dist_u + c
                heappush(q, (d[v], v))
    return d


d = dijkstra(0, n, g)
print(d[n-1] if d[n-1] != 10**10 else -1)

### FIXED CODE ###

from heapq import heappop, heappush

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

g = [[] for __ in range(n)]

for _ in range(m):
    l, r, c = map(int, input().split())
    g[l-1].append((r-1, c))

for i in range(1, n):
    g[i].append((i-1, 0))


d = [10**18] * n
d[0] = 0
q = [(0, 0)]
while q:
    dist_u, u = heappop(q)
    if d[u] < dist_u:
        continue
    for v, c in g[u]:
        if d[v] > dist_u + c:
            d[v] = dist_u + c
            heappush(q, (d[v], v))


print(d[n-1] if d[n-1] != 10**18 else -1)
### BUGGY CODE ###

N, X, Y = map(int, input().split())
d = Y-X
c = []
for i in range(1,N):
  for j in range(i+1,N+1):
    if i <= X and j >= Y:
      c.append(j-i-d+1)
    elif i>=X and j <= Y:
      a = min(j-i, i-X+1+Y-j)
      c.append(a)
    elif i<= X and j <= Y:
      a = min(X-i+1+Y-j,j-i)
      c.append(a)
    else:
      a = min(j-Y+1+i-X,j-i)
      c.append(a)
for i in range(1,N):
  ans = c.count(i)
  print(ans)
  


### FIXED CODE ###

N, X, Y = map(int, input().split())
c = [0 for i in range(N)]
for i in range(1,N):
  for j in range(i+1,N+1):
    x = abs(X-i)
    y = abs(Y-j)
    a = min(x+y+1,j-i)
    c[a]+=1

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

n,m = map(int, input().split())
dic = {}
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    
    if a in dic.keys():
        tmp = dic[a]
        tmp.append(b)
        dic[a] = tmp
    else:
        tmp = [b]
        dic[a] = tmp
    
    if b in dic:
        tmp = dic[b]
        tmp.append(a)
        dic[b] = tmp
    else:
        tmp = [a]
        dic[b] = tmp

dist = {}
queue = []
visited = []
pre = {}

dist[0] = 0 
queue.append(0)

while len(queue) > 0:
    v = queue.pop(0)
    
    for i in dic[v]:
        if i in visited:
            #print(visited)
            continue
        
        visited.append(i)
        dist[i] = dist[v] + 1
        pre[i]= v
        queue.append(i)


print("Yes")
for i in range(n):
    ans = 0
    
    if(i == 0):
        continue
    
    ans = pre[i]
    ans += 1
    print(ans)

### FIXED CODE ###

from collections import deque

n,m = map(int, input().split())
dic = {}

AB = [map(int, input().split()) for _ in range(m)]

dic = [[] for _ in range(n + 1)]

for a,b in AB:
    a -= 1
    b -= 1

    dic[a].append(b)
    dic[b].append(a)

#dist = {}
queue = deque([0])
visited = []
pre = [-1] * (n+1)

#dist[0] = 0 
queue.append(0)

while queue:
    v = queue.popleft()
    
    for i in dic[v]:
        if pre[i] == -1:
        #dist[i] = dist[v] + 1
            pre[i]= v
            queue.append(i)

print("Yes")
for i in range(n):
    ans = 0
    
    if(i == 0):
        continue
    
    ans = pre[i]
    ans += 1
    print(ans)
### BUGGY CODE ###

H, W =  map(int, input().split(' '))
table = [list(input()) for _ in range(H)]

buf = []

for i in range(H):
    for j in range(W):
        if table[i][j] == '#':
            buf.append((i, j))


ans = 0
while True:
    n = sum([row.count('#') for row in table])
    if n == H * W:
        break


    buf2 = []
    for i, j in buf:
        if i-1 >= 0 and table[i-1][j] != '#':
            table[i - 1][j] = '#'
            buf2.append((i-1, j))

        if i+1 < H and table[i+1][j] != '#':
            table[i + 1][j] = '#'
            buf2.append((i+1, j))

        if j-1 >= 0 and table[i][j-1] != '#':
            table[i][j-1] = '#'
            buf2.append((i, j-1))

        if j+1 < W and table[i][j+1] != '#':
            table[i][j+1] = '#'
            buf2.append((i, j+1))

    ans += 1
    buf = buf2


    # print('-- -- --')
    # print(buf)
    # for row in table:
    #     print(''.join(row))


print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
H, W =  map(int, input().split(' '))
table = [list(input()) for _ in range(H)]

buf = []

n = 0
for i in range(H):
    for j in range(W):
        if table[i][j] == '#':
            buf.append((i, j))
            n += 1


ans = 0
while n != H * W:
    ans += 1

    buf2 = []
    for i, j in buf:
        if i-1 >= 0 and table[i-1][j] != '#':
            table[i - 1][j] = '#'
            buf2.append((i-1, j))
            n += 1

        if i+1 < H and table[i+1][j] != '#':
            table[i + 1][j] = '#'
            buf2.append((i+1, j))
            n += 1

        if j-1 >= 0 and table[i][j-1] != '#':
            table[i][j-1] = '#'
            buf2.append((i, j-1))
            n += 1

        if j+1 < W and table[i][j+1] != '#':
            table[i][j+1] = '#'
            buf2.append((i, j+1))
            n += 1

    buf = buf2

    # print('-- -- --')
    # print(buf)
    # for row in table:
    #     print(''.join(row))


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

T = int(input())
for _ in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = input()

    dp = [set() for i in range(N+1)]
    # 人１がビットを最後に立てた後に０にできるなら０にならない
    L = max(A).bit_length()
    dp[-1].add(0)
    for i in range(N-1, -1, -1):
        k = int(S[i])
        # print(A[i], dp[i+1], k)
        if k:
            if A[i] in dp[i+1]:
                dp[i] = dp[i+1]

            else:
                break
        else:
            dp[i] |= dp[i+1]
            for x in dp[i+1]:
                dp[i].add(x ^ A[i])
    # print(dp)
    if len(dp[0]) > 0:
        print(0)
    else:
        print(1)


### FIXED CODE ###

def main():
    T = int(input())
    for _ in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        S = input()
        L = max(A).bit_length()
        s = [0]*L
        ID = A.index(max(A))

        def check(x):
            for i in range(L-1, -1, -1):
                if (x >> i) % 2:
                    x ^= s[i]
            return(x == 0)

        def update(x):
            flag = False
            if x.bit_length() == 60:
                flag = True
            for i in range(L-1, -1, -1):
                if (x >> i) % 2:
                    x ^= s[i]
            id = x.bit_length() - 1
            if id >= 0:
                s[id] = x

        res = 0
        L2 = 0
        for i in range(N-1, -1, -1):
            k = int(S[i])
            if k:
                if check(A[i]):
                    continue
                else:
                    res = 1
                    break
            else:
                L2 = max(L2, A[i].bit_length())
                update(A[i])
        print(res)



main()
### BUGGY CODE ###

# coding: utf-8

import sys
input = sys.stdin.readline

bit = lambda s, j: (s >> j) & 1

def f(n, a):
    mod = int(1e9 + 7)
    sn = 1 << n
    dp = [[0] * sn for _ in range(n + 1)]
    dp[0][0] = 1
    for i in range(n):
        dpi = dp[i]
        dpi1 = dp[i + 1]
        ai = a[i]
        for s in range(0, sn):
            if dpi[s]:
                for j in range(n):
                    if bit(s, j) == 0 and ai[j]:
                        s_ = s | 1 << j
                        dpi1[s_] += dpi[s]
                        if dpi1[s_] > mod:
                            dpi1[s_] -= mod
    return(dp[-1][-1])

n = int(input()) # 1 <= n <= 21
a = [list(map(int, input().split())) for _ in range(n)]
print(f(n, a))


### FIXED CODE ###

# coding: utf-8

import sys
input = sys.stdin.readline

bit = lambda s, j: (s >> j) & 1

def f(n, a):
    mod = int(1e9 + 7)
    sn = 1 << n
    dp = [[0] * sn for _ in range(n + 1)]
    dp[0][0] = 1
    for i in range(n):
        dpi = dp[i]
        dpi1 = dp[i + 1]
        ai = a[i]
        for s in range(0, sn):
            if dpi[s]:
                for j in range(n):
                    if bit(s, j) == 0 and ai[j]:
                        s_ = s | 1 << j
                        dpi1[s_] += dpi[s]
                        if dpi1[s_] > mod:
                            dpi1[s_] -= mod
    return(dp[-1][-1])

n = int(input()) # 1 <= n <= 21
a = [list(map(int, input().split())) for _ in range(n)]
print(f(n, a))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def print_ans(N, Q, S, arr):
    """Test Case
    >>> print_ans(8, 3, "ACACTACG", [[3, 7], [2, 3], [1, 8]])
    2
    0
    3
    """
    ans_list = [S[ar[0]-1:ar[1]].count("AC") for ar in arr]
    for ans in ans_list:
        print(ans)

if __name__ == '__main__':
    N, Q = map(int, input().rstrip().split())
    S = input().rstrip()
    arr = [list(map(int, input().rstrip().split())) for _ in range(Q)]
    print_ans(N, Q, S, arr)


### FIXED CODE ###

import sys
input = sys.stdin.readline
def print_ans(N, Q, S, arr):
    """Test Case
    >>> print_ans(8, 3, "ACACTACG", [[3, 7], [2, 3], [1, 8]])
    2
    0
    3
    """
    t = [0] * (N+1)
    for i in range(N):
        t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)
    for ar in arr:
        print(t[ar[1] - 1] - t[ar[0] - 1] )

if __name__ == '__main__':
    N, Q = map(int, input().rstrip().split())
    S = input().rstrip()
    arr = [list(map(int, input().rstrip().split())) for _ in range(Q)]
    print_ans(N, Q, S, arr)
### BUGGY CODE ###

n, *str_n = open(0).read().split()
n = int(n)
dictionary = list(set(str_n))
dictionary.sort()
dic_num = [0] * len(dictionary)

for i in range(n):
    for word in dictionary:
        if str_n[i] == word:
            dic_num[dictionary.index(word)] += 1

max_vote = [i for i, v in enumerate(dic_num) if v == max(dic_num)]

for i in max_vote:
    print(dictionary[i])

### FIXED CODE ###

import collections

n, *s_n = open(0).read().split()
n = int(n)

dic = collections.Counter(s_n)

dic_values_max = max(list(dic.values()))

max_key = [i for i, j in dic.items() if j == dic_values_max]

max_key.sort()

for k in max_key:
    print(k)
### BUGGY CODE ###

from sys import stdin, stdout

def main():
	H, N = (int(x) for x in stdin.readline().split())
	spells = [] #dmg, cost
	for _ in range(N):
		spells.append([int(x) for x in stdin.readline().split()])
	dp = [float('inf') for _ in range(H+1)]
	dp[0] = 0
	for i in range(1, len(dp)):
		for dmg, cost in spells:
			dp[i] = min(dp[max(0, i-dmg)]+cost, dp[i])
	stdout.write(str(dp[-1]))

if __name__ == "__main__":
	main()

### FIXED CODE ###

from sys import stdin, stdout	

def sol2():
	H, N = (int(x) for x in stdin.readline().split())
	dp = [float('inf') for _ in range(H+1)]
	dp[0] = 0
	for line in stdin:
		dmg, cost = [int(x) for x in line.split()]
		for i in range(len(dp)):
			new = min(H, i + dmg)
			dp[new] = min(dp[new], dp[i] + cost)
	stdout.write(str(dp[-1]))

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

from functools import reduce
import math
K = int(input())


def gcd(a, b, c):
    for k in range(K, 0, -1):
        if a % k == 0 and b % k == 0 and c % k == 0:
            return k


ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans += gcd(a, b, c)

print(ans)


### FIXED CODE ###

from fractions import gcd
K = int(input())


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans += gcd(gcd(a, b), c)

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

N = int(input())
S = []
S.append(input())


for i in range(N-1):
    get = input()
    if S.count(get) == 0:
        S.append(get)

print(len(S))

### FIXED CODE ###

N = int(input())
S = set()

for i in range(N):
    S.add(input())

print(len(S))
### BUGGY CODE ###

n = int(input())
graph = [list(map(int, input().split())) for i in range(n)]

ans = sum([sum(line) for line in graph]) // 2
for a in range(n):
    for b in range(n):
        if a == b:
            break
        for c in range(n):
            if a == c or b == c:
                continue
            if graph[a][b] > graph[a][c] + graph[c][b]:
                print(-1)
                exit()
            elif graph[a][b] == graph[a][c] + graph[c][b]:
                ans -= graph[a][b]

print(ans)

### FIXED CODE ###

import sys
import numpy as np
input = sys.stdin.readline
n = int(input())
G = np.array([list(map(int, input().split())) for _ in range(n)], dtype=float)
use = np.ones((n,n),dtype=bool)
impossible = np.zeros((n,n),dtype=bool)
for w in range(n):
    D = sum(np.meshgrid(G[w], G[w]))
    D[w] = np.inf
    D[:,w] = np.inf
    use &= ~(G == D)
    impossible |= G > D
if impossible.any():
    print(-1)
else:
    print(int(np.sum(G[use]) / 2))
### BUGGY CODE ###

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

### FIXED CODE ###

N, Q = map(int, input().split())
S = str(input())
wa=[0]*N
p=0
for j in range(1,N):
    if S[j-1]=="A" and S[j]=="C":
        p+=1
        wa[j]=p
    else:
        wa[j]=wa[j-1]
for i in range(Q):
    k =input().split()
    l=int(k[0])
    r=int(k[1])
    print(wa[r-1]-wa[l-1])
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
set_A = sorted((set(A)), reverse=True)

cnt = 0
for a in set_A:
  if A.count(a) >= 4:
    print(max(cnt*a, a*a))
    exit()
  if A.count(a) >= 2:
    tmp = cnt * a
    if tmp != 0:
      print(tmp)
      exit()
    cnt = a
    
print(0)


### FIXED CODE ###

from collections import Counter

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

set_A = sorted((set(A)), reverse=True)
tmp = 0
for a in set_A:
    if A_dic[a] >= 4:
        print(max(tmp*a, a*a))
        exit()
    if A_dic[a] >= 2:
        ans = tmp * a
        if ans != 0:
            print(ans)
            exit()
        tmp = a
print(0)