-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC454B.java
More file actions
42 lines (28 loc) · 700 Bytes
/
Copy pathC454B.java
File metadata and controls
42 lines (28 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.Scanner;
public class C454B {
/***/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] r = new int[n];
for (int i = 0; i != n; i++)
r[i] = scanner.nextInt();
int cBreaks = 0;
int lastBreak = 0;
for (int i = 0; i != n; i++) {
int iPrev = (i == 0) ? n - 1: i - 1;
if( r[i] < r[iPrev]) {
cBreaks++;
lastBreak = i;
}
}
if (cBreaks > 1) {
System.out.println(-1);
} else {
if (lastBreak == 0)
System.out.println(0);
else System.out.println(n - lastBreak);
}
scanner.close();
}
}