831A.md (1638B)
1 Source: https://codeforces.com/problemset/problem/831/A 2 3 A. Unimodal Array 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Array of integers is unimodal, if: 22 23 * it is strictly increasing in the beginning; 24 * after that it is constant; 25 * after that it is strictly decreasing. 26 27 The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. 28 29 For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. 30 31 Write a program that checks if an array is unimodal. 32 33 Input 34 35 The first line contains integer *n* (1 ≤ *n* ≤ 100) — the number of elements in the array. 36 37 The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 1 000) — the elements of the array. 38 39 Output 40 41 Print "YES" if the given array is unimodal. Otherwise, print "NO". 42 43 You can output each letter in any case (upper or lower). 44 45 Examples 46 47 Input 48 49 ``` 50 6 51 1 5 5 5 4 2 52 ``` 53 54 Output 55 56 ``` 57 YES 58 ``` 59 60 Input 61 62 ``` 63 5 64 10 20 30 20 10 65 ``` 66 67 Output 68 69 ``` 70 YES 71 ``` 72 73 Input 74 75 ``` 76 4 77 1 2 1 2 78 ``` 79 80 Output 81 82 ``` 83 NO 84 ``` 85 86 Input 87 88 ``` 89 7 90 3 3 3 3 3 3 3 91 ``` 92 93 Output 94 95 ``` 96 YES 97 ``` 98 99 Note 100 101 In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).