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

#TP0000009. Dora tìm đoạn phù hợp (Dora and Search)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Dora tìm đoạn phù hợp (Dora and Search)

Dora and Search

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Dora is given a permutation aa of length nn. A permutation contains each integer from 11 to nn exactly once. She wants to choose a contiguous segment from position ll to position rr, where positions are numbered starting from 11.

A segment is valid when neither endpoint equals the minimum or the maximum of the values within that segment. Find indices l,rl,r of any valid segment. If none exists, print -1.

Input

  • The first line contains the integer nn, the length of the permutation.
  • The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n in left-to-right order.

Output

Print -1 if no valid segment exists. Otherwise, print two integers l,rl,r, 1≤l≤r≤n1\le l\le r\le n, on one line. Any valid segment is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le 8; 1≤ai≤n1\le a_i\le n for every 1≤i≤n1\le i\le n; aa is a permutation of 1,2,…,n1,2,\ldots,n.
  • Subtask 2 (30 points): 1≤n≤30001\le n\le 3000; 1≤ai≤n1\le a_i\le n for every 1≤i≤n1\le i\le n; aa is a permutation of 1,2,…,n1,2,\ldots,n.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le 2\cdot10^5; 1≤ai≤n1\le a_i\le n for every 1≤i≤n1\le i\le n; aa is a permutation of 1,2,…,n1,2,\ldots,n.

Examples

Input

4
2 1 4 3

Output

1 4

Explanation

The whole segment [1,4] has minimum 1 and maximum 4 in its interior. Its endpoints 2 and 3 are neither extreme.