#STK0000080. Tầm nhìn tòa nhà (Tower Visibility)

Tầm nhìn tòa nhà (Tower Visibility)

Tower Visibility

Source: Baekjoon Online Judge

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN buildings on a line, numbered 11 through NN, with equal spacing between adjacent buildings. From building ii, only buildings jj with Lj>LiL_j>L_i are candidates. Building jj is visible from ii if every building strictly between ii and jj has height less than LjL_j; if an intermediate building has height at least LjL_j, then jj is blocked. For each building, determine the total number of visible buildings on both sides and, if any exists, the index of the nearest visible building. If two nearest buildings are at the same distance, choose the smaller index.

Input

The first line contains NN. The second line contains NN heights L1,L2,…,LNL_1,L_2,\ldots,L_N.

Output

For each ii from 11 to NN, print one line. If no building is visible, print 0. Otherwise print the number of visible buildings and the index of the nearest one.

Subtasks

  • Subtask 1 (30 points): N≤2000N\le2000; all other conditions are unchanged.
  • Subtask 2 (70 points): 1≤N≤1051\le N\le10^5, 1≤Li≤1051\le L_i\le10^5.

Examples

Input

8
3 7 1 6 3 5 1 7

Output

1 2
0
3 2
2 2
4 4
3 4
4 6
0

Explanation

The heights are 3,7,1,6,3,5,1,73,7,1,6,3,5,1,7.

The visible buildings from each position are:

  • Building 11: sees building 22; count 11, nearest index 22.
  • Building 22: no taller visible building; print 0.
  • Building 33: sees buildings 2,4,82,4,8; count 33. Buildings 22 and 44 are both one position away, so choose the smaller index 22.
  • Building 44: sees buildings 2,82,8; both are two positions away, so choose 22.
  • Building 55: sees buildings 2,4,6,82,4,6,8; the nearest are 44 and 66, both one position away, so choose 44.
  • Building 66: sees buildings 2,4,82,4,8; the nearest is 44.
  • Building 77: sees buildings 2,4,6,82,4,6,8; the nearest are 66 and 88, both one position away, so choose 66.
  • Building 88: no taller visible building; print 0.

These counts and nearest indices give exactly the sample output.