#P10840. 【MX-J2-T1】Turtle and Sequences

【MX-J2-T1】Turtle and Sequences

Background

Original link: https://oier.team/problems/J2B.

Problem Description

You are given a sequence a1,a2,…,ana_1, a_2, \ldots, a_n. You can perform some operations on this sequence.

Suppose that before an operation, the sequence length is mm. In this operation, you may choose an integer ii such that 1≤i≤m−11 \le i \le m - 1 and ai≠ai+1a_i \ne a_{i + 1}, delete ai+1a_{i + 1}, and set the value of aia_i to any integer.

Find the maximum number of operations you can perform.

Input Format

The first line contains a positive integer nn, indicating the initial length of the sequence.

The second line contains nn positive integers a1,a2,…,ana_1, a_2, \ldots, a_n.

Output Format

Output a single non-negative integer in one line, indicating the maximum number of operations.

2
1 2

1

3
1 1 1

0

4
1 1 45 14

3

Hint

Sample Explanation #1

You can choose i=1i = 1. After deleting a2a_2, set a1a_1 to 33. Now a=[3]a = [3], and no more operations can be performed. Therefore, the answer is 11.

Sample Explanation #2

No operation can be performed, so the answer is 00.

Constraints

This problem uses bundled testdata and subtask dependencies are enabled.

Subtask ID Points n≤n \le Special Property Subtask Dependencies
11 3434 22 None None
22 1919 10510^5 a1=a2=⋯=ana_1 = a_2 = \cdots = a_n
33 4747 None 1,21, 2

For all testdata, 1≤n≤1051 \le n \le 10^5 and 1≤ai≤1091 \le a_i \le 10^9.

Translated by ChatGPT 5