codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

847M.md (2708B)


      1 Source: https://codeforces.com/problemset/problem/847/M
      2 
      3 M. Weather Tomorrow
      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 Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
     22 
     23 Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (*n* + 1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (*n* + 1)-th day will be equal to the temperature of the *n*-th day.
     24 
     25 Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (*n* + 1)-th day.
     26 
     27 Input
     28 
     29 The first line contains a single integer *n* (2 ≤ *n* ≤ 100) — the number of days for which the average air temperature is known.
     30 
     31 The second line contains a sequence of integers *t*1, *t*2, ..., *t**n* ( - 1000 ≤ *t**i* ≤ 1000) — where *t**i* is the average temperature in the *i*-th day.
     32 
     33 Output
     34 
     35 Print the average air temperature in the (*n* + 1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 5  
     43 10 5 0 -5 -10
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 -15
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 4  
     56 1 1 1 1
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 1
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 3  
     69 5 1 -5
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 -5
     76 ```
     77 
     78 Input
     79 
     80 ```
     81 2  
     82 900 1000
     83 ```
     84 
     85 Output
     86 
     87 ```
     88 1100
     89 ```
     90 
     91 Note
     92 
     93 In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is  - 10 - 5 =  - 15.
     94 
     95 In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1.
     96 
     97 In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to  - 5.
     98 
     99 In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000 + 100 = 1100.