83A.md (2076B)
1 Source: https://codeforces.com/problemset/problem/83/A 2 3 A. Magical Array 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical. 22 23 Valera absolutely accidentally got a piece of ancient parchment on which an array of numbers was written. He immediately thought that the numbers in this array were not random. As a result of extensive research Valera worked out a wonderful property that a magical array should have: an array is defined as magic if its minimum and maximum coincide. 24 25 He decided to share this outstanding discovery with you, but he asks you for help in return. Despite the tremendous intelligence and wit, Valera counts very badly and so you will have to complete his work. All you have to do is count the number of magical subarrays of the original array of numbers, written on the parchment. Subarray is defined as non-empty sequence of consecutive elements. 26 27 Input 28 29 The first line of the input data contains an integer *n* (1 ≤ *n* ≤ 105). The second line contains an array of original integers *a*1, *a*2, ..., *a**n* ( - 109 ≤ *a**i* ≤ 109). 30 31 Output 32 33 Print on the single line the answer to the problem: the amount of subarrays, which are magical. 34 35 Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator). 36 37 Examples 38 39 Input 40 41 ``` 42 4 43 2 1 1 4 44 ``` 45 46 Output 47 48 ``` 49 5 50 ``` 51 52 Input 53 54 ``` 55 5 56 -2 -2 -2 0 1 57 ``` 58 59 Output 60 61 ``` 62 8 63 ``` 64 65 Note 66 67 Notes to sample tests: 68 69 Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end. 70 71 In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3]. 72 73 In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3].