QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#16893. Adventure Card Game

الإحصائيات

The turn-based adventure card game "Roughly Catching Monsters with Cards," developed by the world-renowned game company KDH Corp., has finally been released today! The following is the rulebook explaining the game's rules.

  • The player starts the game with one card of each type from $1$ to $K$ in their hand.
  • The game consists of a total of $N$ turns, and in each turn, at most one monster from $1$ to $K$ appears.
  • In each turn, the player can play up to 2 cards from their hand. It is also possible to pass the turn without playing any cards.
  • If a monster appears in a turn, the player can defeat it by playing a card with the same number as the monster.
  • If a monster that appears in a turn is not defeated during that turn, it runs away after the turn ends.
  • Once the player has exhausted all the cards in their hand, they retrieve one card of each type from $1$ to $K$ back into their hand after the turn ends.
  • The more monsters you defeat, the higher the score you earn.

Dohun, a master of the game, took 1st place as soon as "Roughly Catching Monsters with Cards" was released, but his rival Kangmin is threatening his top spot! Anxious, Dohun wants to prevent losing his 1st place by recording the maximum possible score. Let's find the maximum number of monsters that can be defeated in each game so that Dohun can secure his 1st place more firmly.

Input

The first line contains the total number of turns $N$ and the number of card and monster types $K$, separated by a space. ($1 \le N, K \le 500\,000$)

The second line contains the types of monsters $c_1, c_2, \dots, c_N$ that appear in each turn, separated by spaces. ($0 \le c_i \le K$) If $c_i = 0$, it means no monster appeared in turn $i$.

Output

Output the maximum number of monsters that can be defeated.

Examples

Input 1

6 4
1 1 2 2 3 3

Output 1

5

Input 2

10 5
1 2 2 0 3 3 0 5 4 4

Output 2

7

Note

In the first example, by playing cards in the following order each turn, you can defeat all monsters except for the monster of type 1 that appeared in turn 2.

  1. Play card 1 and card 3 to defeat the monster of type 1.
  2. Play card 4. The monster of type 1 is not defeated and runs away.
  3. Play card 2 to defeat the monster of type 2.
    • Since all four cards have been played, retrieve the cards back into your hand after the turn ends.
  4. Play card 1 and card 2 to defeat the monster of type 2.
  5. Play card 3 and card 4 to defeat the monster of type 3.
    • Since all four cards have been played, retrieve the cards back into your hand after the turn ends.
  6. Play card 3 to defeat the monster of type 3.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.