Ternary Search
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Recently, Grammy has learned ternary search in Tony's class. She can find the peak value in an array using this algorithm when the array is unimodal. Here we define an array a_1,a_2,...,a_n is unimodal if and only if it satisfies one of the following conditions:

  • There exists an index k () such that .
  • There exists an index k () such that .

As the tutor of Grammy, Tony wants to examine whether Grammy fully understands what he taught in class so he leaves n tasks for Grammy to try ternary search. The tasks are as follows.

Initially, there is an empty array. Each task appends a distinct number at the right end of the array and Grammy should do ternary search on it. However, due to Tony's carelessness, the array may not be unimodal after some addition. Since Tony has already slept, Grammy has to solve the problem by herself.

For each task, some operations should be taken before Grammy tries ternary search on it to make it unimodal. For each operation, Grammy can swap the values of a_i and for some i (). Grammy is a lazy girl and she thinks that if she has to do many operations, she would like to wait for Tony to wake up and solve the problem. For each task, she wonders how many operations she has to do at least to make the array unimodal. Can you help her?

输入描述:

The input contains only a single case.

The first line contains a single integer n (), denoting the number of tasks. The i-th line of the following n lines contains one integer a_i (), denoting the number appended in the i-th task.

It is guaranteed that a_i are pairwise distinct.

输出描述:

The output contains n lines. Each line contains one integer, denoting the answer to the answer to the i-th task.
示例1

输入

复制
9
11
4
5
14
1
9
19
8
10

输出

复制
0
0
0
0
2
3
3
6
7