QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#5190. Little E Loves Elimination

Statistics

There are $n$ colored balls stuck in a pipe. The balls all have the same diameter. Their colors from one end to the other are $c_1, c_2, \dots, c_n$.

Little E has an empty cup. The diameter of the cup's opening is just slightly larger than the diameter of the balls, so Little E can place balls into the cup, but only one at a time, and the balls must be stacked vertically. Two adjacent balls of the same color in the cup will disappear together.

Due to the nature of the pipe, Little E can only choose one end of the pipe at a time, take out the outermost ball, and immediately place it into the cup.

Determine the minimum number of balls remaining in the cup after all balls have been removed from the pipe, and the minimum cup capacity required to achieve this.

Input

The first line contains a positive integer $n$.

The second line contains $n$ positive integers, where the $i$-th integer represents $c_i$.

Output

Output a single line containing two non-negative integers. The first number is the minimum number of balls remaining in the cup. The second number is the minimum capacity the cup must have to achieve this minimum.

Examples

Input 1

12
3 5 1 4 9 3 3 5 1 4 9 3

Output 1

0 5

Note 1

One optimal strategy is as follows:

First, place the $3$s from both ends into the cup to eliminate them.

3.png

Then, place $5, 1, 4, 9$ from the left end into the cup one by one; at this point, there are $4$ balls in the cup.

4.png

Next, place $9, 4$ from the right end into the cup one by one. Each time a ball is placed, it will be eliminated with another ball in the cup. After placing $9$ and before elimination, the cup contains $5, 1, 4, 9, 9$, so the cup must be able to hold $5$ balls.

5.png

Then, place $3, 3$ from the left end into the cup; at this point, there are $2$ balls in the cup.

7.png

Finally, place $1, 5$ from the right end into the cup one by one. At this point, the cup is empty.

9.png

Alternatively, see Sampledescription.pptx in the provided files.

Subtasks

It is guaranteed that $n \le 50$ and $1 \le c_i \le n$.

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.