{"raw_statement":[{"iden":"problem statement","content":"You are given a sequence $a = (a_1, \\dots, a_N)$ of length $N$ consisting of integers between $1$ and $N$.\nFind the number of pairs of integers $i, j$ that satisfy all of the following conditions:\n\n*   $1 \\leq i \\lt j \\leq N$\n*   $\\min(a_i, a_j) = i$\n*   $\\max(a_i, a_j) = j$"},{"iden":"constraints","content":"*   $2 \\leq N \\leq 5 \\times 10^5$\n*   $1 \\leq a_i \\leq N \\, (1 \\leq i \\leq N)$\n*   All values in input are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$a_1$ $\\ldots$ $a_N$"},{"iden":"sample input 1","content":"4\n1 3 2 4"},{"iden":"sample output 1","content":"2\n\n$(i, j) = (1, 4), (2, 3)$ satisfy the conditions."},{"iden":"sample input 2","content":"10\n5 8 2 2 1 6 7 2 9 10"},{"iden":"sample output 2","content":"8"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}