PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000077. Mike và chiều cao của những chú gấu (Mike and Feet)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Mike và chiều cao của những chú gấu (Mike and Feet)

Mike and Feet

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn bears standing in a row, with height aia_i for bear ii. A group is any non-empty contiguous subarray of bears. Its size is the number of bears, and its strength is the minimum bear height in the group.

For each group size k=1,…,nk=1,\ldots,n, determine the maximum possible strength among all contiguous groups of exactly kk bears.

A segment of length kk contains exactly kk consecutive bears. Its strength is the minimum of their heights; even a single short bear may reduce the strength of the entire segment.

A different segment may be chosen for each kk. The goal is to maximize the minimum height among segments of exactly kk elements, not segments of length at least or at most kk.

Input

The first line contains nn; the second contains a1,…,ana_1,\ldots,a_n.

Output

Print nn integers; integer kk is the maximum strength of a subarray of length kk.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le 30; 1≤ai≤1091\le a_i\le10^9.
  • Subtask 2 (30 points): 1≤n≤40001\le n\le 4000; 1≤ai≤1091\le a_i\le10^9.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤ai≤1091\le a_i\le10^9.

Examples

Input

10
1 2 3 4 5 4 3 2 1 6

Output

6 4 4 3 3 2 2 1 1 1

Explanation

For k=1k=1, the tallest bear gives strength 66. For lengths 22 and 33, the maximum attainable minimum height is 44. For each remaining length, compare all segments of exactly that length and take the largest minimum height.