Codeforces Round 452 (Div. 2)
E
Segments Removal
Codeforces
2000
原题
← DF →
翻译中…

Vasya has an array of integers of length $*n*$.

翻译中…

Vasya performs the following operations on the array: on each step he finds the longest segment of consecutive equal integers (the leftmost, if there are several such segments) and removes it. For example, if Vasya's array is $[13, 13, 7, 7, 7, 2, 2, 2]$, then after one operation it becomes $[13, 13, 2, 2, 2]$.

翻译中…

Compute the number of operations Vasya should make until the array becomes empty, i.e. Vasya removes all elements from it.

翻译中…

Input

翻译中…

The first line contains a single integer $*n*$ ($1 ≤ *n* ≤ 200 000$) — the length of the array.

翻译中…

The second line contains a sequence $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($1 ≤ *a*_{*i*} ≤ 10^{9}$) — Vasya's array.

翻译中…

Output

翻译中…

Print the number of operations Vasya should make to remove all elements from the array.

翻译中…

Note

翻译中…

In the first example, at first Vasya removes two fives at the second and third positions. The array becomes $[2, 2]$. In the second operation Vasya removes two twos at the first and second positions. After that the array becomes empty.

翻译中…

In the second example Vasya has to perform five operations to make the array empty. In each of them he removes the first element from the array.

翻译中…

In the third example Vasya needs three operations. In the first operation he removes all integers $4$, in the second — all integers $100$, in the third — all integers $2$.

翻译中…

In the fourth example in the first operation Vasya removes the first two integers $10$. After that the array becomes $[50, 10, 50, 50]$. Then in the second operation Vasya removes the two rightmost integers $50$, so that the array becomes $[50, 10]$. In the third operation he removes the remaining $50$, and the array becomes $[10]$ after that. In the last, fourth operation he removes the only remaining $10$. The array is empty after that.

翻译中…

样例

Input #1
4
2 5 5 2
Output #1
2
InputCopy OutputCopy
Input #2
5
6 3 4 1 5
Output #2
5
InputCopy OutputCopy
Input #3
8
4 4 4 2 2 100 100 100
Output #3
3
InputCopy OutputCopy
Input #4
6
10 10 50 10 50 50
Output #4
4
InputCopy OutputCopy
题目信息
题号
899E
时间限制
2 s
内存限制
256 MB
标签
数据结构
并查集
网络流
模拟
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。