Happy sequence
Time limit1.5sMemory limit256 MB
Given a non-happy sequence, count and list every single-element replacement that makes all adjacent absolute differences exactly the set 1..N-1.
- Level
Medium7 of 10
- Topics
- Array, Hash map, Implementation
- Solved
- No attempts yet
Problem
A sequence of length is happy if and only if the absolute differences of its adjacent elements take every value from to . For example, the sequence is not happy, because the absolute differences of its adjacent elements are in order, and the number is missing. On the other hand, the sequence is happy, because the absolute differences of its adjacent elements are , which are all the numbers from to .
One morning, the sequence Ivo woke up unhappy. You can help it: you may replace exactly one of its elements with some other integer and make Ivo happy.
Input
The first line contains , the number of elements of the sequence. The sequence has at least and at most elements, and it is not happy.
The second line contains positive integers, the elements of the sequence. Every element is at most .
Output
On the first line, print , the number of ways to make Ivo happy.
On each of the next lines, print one way as two integers. The first is the position of the element you change (from to ), and the second is the new number at that position, which can be any integer (zero and negative numbers are allowed).
Print the ways in increasing order of position, and ways with the same position in increasing order of the new number.