logo AlgoBeat OnlineJudge
登录 注册

#216999. [NWERC 2019] Inverted Deck

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

As a huge fan of the popular collectible card game Numinous Wilds: the Elven Reign Chronicles (NWERC), you have a large collection of cards which you carefully organise by their rarity. One day you notice that someone has touched your collection, and that some of the cards are now out of order. The most natural suspect, of course, is your little brother Billy, who was absolutely forbidden from playing with your cards. After a few minutes of interrogation Billy confesses that he indeed took a few consecutive cards from the middle of the stack, but he swears that he put them back in exactly the same order as they were. You suspect that Billy, being so young, may have simply mistakenly reversed the order of the cards that he took. Now you want to check your theory and decide if you can find the batch of cards that Billy took to play with.

Is it possible to restore the order of the cards into non-decreasing order of their rarity by reversing just one contiguous batch of cards?

输入格式

The input consists of:

  • One line containing an integer (), the number of cards in your collection.

  • One line containing integers ( for all ), the current order of the cards’ rarity values.

输出格式

If the cards can be sorted by reversing exactly one contiguous subsequence of the list, then output the -based start and end indices of such a subsequence. Otherwise, output impossible. If there are multiple valid solutions you may output any one of them.

样例

样例输入 1

7
10 13 19 19 15 14 20

样例输出 1

3 6

样例输入 2

6
9 1 8 2 7 3

样例输出 2

impossible

样例输入 3

3
1 2 3

样例输出 3

2 2