B - Dentist Aoki Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200200

問題文

高橋君には、穴 1,2,,N1,2,\dots,N11 本ずつ、全部で NN 本の歯が生えています。
歯医者の青木君は、これらの歯と穴に対して、 QQ 回の治療を行います。
ii 回目の治療では、穴 TiT_i を治療します。治療内容は次の通りです。

  • TiT_i に歯が生えている場合、穴 TiT_i から歯を抜く。
  • そうでない ( 穴 TiT_i に歯が生えていない) 場合、穴 TiT_i に歯を生やす。

全ての治療が終わった後、高橋君に生えている歯の本数は何本ですか?

制約

  • 入力は全て整数
  • 1N,Q10001 \le N,Q \le 1000
  • 1TiN1 \le T_i \le N

入力

入力は以下の形式で標準入力から与えられる。

NN QQ
T1T_1 T2T_2 \dots TQT_Q

出力

答えを整数として出力せよ。


入力例 1Copy

Copy
30 6
2 9 18 27 18 9

出力例 1Copy

Copy
28

高橋君には最初 3030 本の歯が生えており、青木君は 66 回の治療を行います。

  • 11 回目の治療では穴 22 を治療します。 穴 22 に歯が生えているため、歯を抜きます。
  • 22 回目の治療では穴 99 を治療します。 穴 99 に歯が生えているため、歯を抜きます。
  • 33 回目の治療では穴 1818 を治療します。 穴 1818 に歯が生えているため、歯を抜きます。
  • 44 回目の治療では穴 2727 を治療します。 穴 2727 に歯が生えているため、歯を抜きます。
  • 55 回目の治療では穴 1818 を治療します。 穴 1818 に歯が生えていないため、歯を生やします。
  • 66 回目の治療では穴 99 を治療します。 穴 99 に歯が生えていないため、歯を生やします。

最終的な歯の本数は 2828 本です。


入力例 2Copy

Copy
1 7
1 1 1 1 1 1 1

出力例 2Copy

Copy
0

入力例 3Copy

Copy
9 20
9 5 1 2 2 2 8 9 2 1 6 2 6 5 8 7 8 5 9 8

出力例 3Copy

Copy
5

Score: 200200 points

Problem Statement

Takahashi has NN teeth, one in each of the holes numbered 1,2,,N1, 2, \dots, N.
Dentist Aoki will perform QQ treatments on these teeth and holes.
In the ii-th treatment, hole TiT_i is treated as follows:

  • If there is a tooth in hole TiT_i, remove the tooth from hole TiT_i.
  • If there is no tooth in hole TiT_i (i.e., the hole is empty), grow a tooth in hole TiT_i.

After all treatments are completed, how many teeth does Takahashi have?

Constraints

  • All input values are integers.
  • 1N,Q10001 \le N, Q \le 1000
  • 1TiN1 \le T_i \le N

Input

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

NN QQ
T1T_1 T2T_2 \dots TQT_Q

Output

Print the number of teeth as an integer.


Sample Input 1Copy

Copy
30 6
2 9 18 27 18 9

Sample Output 1Copy

Copy
28

Initially, Takahashi has 3030 teeth, and Aoki performs six treatments.

  • In the first treatment, hole 22 is treated. There is a tooth in hole 22, so it is removed.
  • In the second treatment, hole 99 is treated. There is a tooth in hole 99, so it is removed.
  • In the third treatment, hole 1818 is treated. There is a tooth in hole 1818, so it is removed.
  • In the fourth treatment, hole 2727 is treated. There is a tooth in hole 2727, so it is removed.
  • In the fifth treatment, hole 1818 is treated. There is no tooth in hole 1818, so a tooth is grown.
  • In the sixth treatment, hole 99 is treated. There is no tooth in hole 99, so a tooth is grown.

The final count of teeth is 2828.


Sample Input 2Copy

Copy
1 7
1 1 1 1 1 1 1

Sample Output 2Copy

Copy
0

Sample Input 3Copy

Copy
9 20
9 5 1 2 2 2 8 9 2 1 6 2 6 5 8 7 8 5 9 8

Sample Output 3Copy

Copy
5


2025-03-29 (Sat)
23:22:43 +00:00