103591: [Atcoder]ABC359 B - Couples

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:12 Solved:0

Description

Score : $150$ points

Problem Statement

There are $2N$ people standing in a row, and the person at the $i$-th position from the left is wearing clothes of color $A_i$. Here, the clothes have $N$ colors from $1$ to $N$, and exactly two people are wearing clothes of each color.

Find how many of the integers $i=1,2,\ldots,N$ satisfy the following condition:

  • There is exactly one person between the two people wearing clothes of color $i$.

Constraints

  • $2 \leq N \leq 100$
  • $1 \leq A_i \leq N$
  • Each integer from $1$ through $N$ appears exactly twice in $A$.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\ldots$ $A_{2N}$

Output

Print the answer.


Sample Input 1

3
1 2 1 3 2 3

Sample Output 1

2

There are two values of $i$ that satisfy the condition: $1$ and $3$.

In fact, the people wearing clothes of color $1$ are at the 1st and 3rd positions from the left, with exactly one person in between.


Sample Input 2

2
1 1 2 2

Sample Output 2

0

There may be no $i$ that satisfies the condition.


Sample Input 3

4
4 3 2 3 2 1 4 1

Sample Output 3

3

Output

分数:150分

问题描述

有2N个人站在一排,从左边数第i个人穿着颜色为$A_i$的衣服。衣服有从1到N的N种颜色,每种颜色恰好有两个人穿。

找出满足以下条件的整数i(i=1,2,...,N)的数量:

  • 在穿颜色为i的衣服的两个人之间正好有一个人。

限制条件

  • $2 \leq N \leq 100$
  • $1 \leq A_i \leq N$
  • 从1到N的每个整数在$A$中恰好出现两次。
  • 所有输入值都是整数。

输入

输入通过标准输入给出以下格式:

$N$
$A_1$ $A_2$ $\ldots$ $A_{2N}$

输出

打印答案。


样例输入1

3
1 2 1 3 2 3

样例输出1

2

有两个i满足条件:1和3。

实际上,穿颜色为1的衣服的人分别在从左数的第1和第3个位置,中间正好有一个人。


样例输入2

2
1 1 2 2

样例输出2

0

可能没有满足条件的i。


样例输入3

4
4 3 2 3 2 1 4 1

样例输出3

3

加入题单

上一题 下一题 算法标签: