CF1032C.Playing Piano
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little Paul wants to learn how to play piano. He already has a melody he wants to start with. For simplicity he represented this melody as a sequence a1,a2,…,an of key numbers: the more a number is, the closer it is to the right end of the piano keyboard.
Paul is very clever and knows that the essential thing is to properly assign fingers to notes he's going to play. If he chooses an inconvenient fingering, he will then waste a lot of time trying to learn how to play the melody by these fingers and he will probably not succeed.
Let's denote the fingers of hand by numbers from 1 to 5 . We call a fingering any sequence b1,…,bn of fingers numbers. A fingering is convenient if for all 1≤i≤n−1 the following holds:
- if ai<ai+1 then bi<bi+1 , because otherwise Paul needs to take his hand off the keyboard to play the (i+1) -st note;
- if ai>ai+1 then bi>bi+1 , because of the same;
- if ai=ai+1 then bi=bi+1 , because using the same finger twice in a row is dumb. Please note that there is = , not = between bi and bi+1 .
Please provide any convenient fingering or find out that there is none.
输入格式
The first line contains a single integer n ( 1≤n≤105 ) denoting the number of notes.
The second line contains n integers a1,a2,…,an ( 1≤ai≤2⋅105 ) denoting the positions of notes on the keyboard.
输出格式
If there is no convenient fingering, print −1 . Otherwise, print n numbers b1,b2,…,bn , each from 1 to 5 , denoting a convenient fingering, separated by spaces.
输入输出样例
输入#1
5 1 1 4 2 2
输出#1
1 4 5 4 5
输入#2
7 1 5 7 8 10 3 1
输出#2
1 2 3 4 5 4 3
输入#3
19 3 3 7 9 8 8 8 8 7 7 7 7 5 3 3 3 3 8 8
输出#3
1 3 4 5 4 5 4 5 4 5 4 5 4 3 5 4 3 5 4
说明/提示
The third sample test is kinda "Non stop" song by Reflex.