M. Weather Tomorrow

Codeforces
IDCF847M
Time1000ms
Memory256MB
Difficulty
implementationmath
English · Original
Chinese · Translation
Formal · Original
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. 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. Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (_n_ + 1)\-th day. ## Input The first line contains a single integer _n_ (2 ≤ _n_ ≤ 100) — the number of days for which the average air temperature is known. 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. ## Output 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. [samples] ## Note 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. 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. 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. 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.
Vasya 提出了他自己的天气预报方法。他知道过去 #cf_span[n] 天的平均气温信息。假设每天的平均气温均为整数。 Vasya 认为,如果过去 #cf_span[n] 天的平均气温构成一个等差数列,其中第一项等于第一天的平均气温,第二项等于第二天的平均气温,依此类推,则第 #cf_span[(n + 1)] 天的平均气温将等于该等差数列的下一项。否则,根据 Vasya 的方法,第 #cf_span[(n + 1)] 天的气温将等于第 #cf_span[n] 天的气温。 你的任务是帮助 Vasya 预测明天(即第 #cf_span[(n + 1)] 天)的平均气温。 第一行包含一个整数 #cf_span[n] (#cf_span[2 ≤ n ≤ 100]) —— 已知平均气温的天数。 第二行包含一个整数序列 #cf_span[t1, t2, ..., tn] #cf_span[( - 1000 ≤ ti ≤ 1000)],其中 #cf_span[ti] 表示第 #cf_span[i] 天的平均气温。 请输出根据 Vasya 方法预测的第 #cf_span[(n + 1)] 天的平均气温。注意,预测的气温绝对值可能超过 #cf_span[1000]。 在第一个例子中,平均气温序列是一个等差数列,首项为 #cf_span[10],后续每一项减少 #cf_span[5]。因此,第六天的预测平均气温为 #cf_span[ - 10 - 5 =  - 15]。 在第二个例子中,平均气温序列是一个等差数列,首项为 #cf_span[1],后续每一项等于前一项。因此,第五天的预测平均气温为 #cf_span[1]。 在第三个例子中,平均气温不构成等差数列,因此第四天的平均气温等于第三天的气温,即 #cf_span[ - 5]。 在第四个例子中,平均气温序列是一个等差数列,首项为 #cf_span[900],后续每一项增加 #cf_span[100]。因此,第三天的预测平均气温为 #cf_span[1000 + 100 = 1100]。 ## Input 第一行包含一个整数 #cf_span[n] (#cf_span[2 ≤ n ≤ 100]) —— 已知平均气温的天数。第二行包含一个整数序列 #cf_span[t1, t2, ..., tn] #cf_span[( - 1000 ≤ ti ≤ 1000)],其中 #cf_span[ti] 表示第 #cf_span[i] 天的平均气温。 ## Output 请输出根据 Vasya 方法预测的第 #cf_span[(n + 1)] 天的平均气温。注意,预测的气温绝对值可能超过 #cf_span[1000]。 [samples] ## Note 在第一个例子中,平均气温序列是一个等差数列,首项为 #cf_span[10],后续每一项减少 #cf_span[5]。因此,第六天的预测平均气温为 #cf_span[ - 10 - 5 =  - 15]。在第二个例子中,平均气温序列是一个等差数列,首项为 #cf_span[1],后续每一项等于前一项。因此,第五天的预测平均气温为 #cf_span[1]。在第三个例子中,平均气温不构成等差数列,因此第四天的平均气温等于第三天的气温,即 #cf_span[ - 5]。在第四个例子中,平均气温序列是一个等差数列,首项为 #cf_span[900],后续每一项增加 #cf_span[100]。因此,第三天的预测平均气温为 #cf_span[1000 + 100 = 1100]。
**Definitions** Let $ n \in \mathbb{Z} $ with $ 2 \leq n \leq 100 $. Let $ T = (t_1, t_2, \dots, t_n) $ be a sequence of integers representing average temperatures over $ n $ days. **Constraints** $ -1000 \leq t_i \leq 1000 $ for all $ i \in \{1, \dots, n\} $. **Objective** Let $ d = t_2 - t_1 $. If $ t_{i+1} - t_i = d $ for all $ i \in \{1, \dots, n-1\} $, then: $$ t_{n+1} = t_n + d $$ Otherwise: $$ t_{n+1} = t_n $$
Samples
Input #1
5
10 5 0 -5 -10
Output #1
\-15
Input #2
4
1 1 1 1
Output #2
1
Input #3
3
5 1 -5
Output #3
\-5
Input #4
2
900 1000
Output #4
1100
API Response (JSON)
{
  "problem": {
    "name": "M. Weather Tomorrow",
    "description": {
      "content": "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",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF847M"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Vasya 提出了他自己的天气预报方法。他知道过去 #cf_span[n] 天的平均气温信息。假设每天的平均气温均为整数。\n\nVasya 认为,如果过去 #cf_span[n] 天的平均气温构成一个等差数列,其中第一项等于第一天的平均气温,第二项等于第二天的平均气温,依此类推,则第 #cf_span[(n + 1)] 天的平均气温将等于该等差数列的下一项。否则,根据 Vasya 的方法,第 #cf...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ with $ 2 \\leq n \\leq 100 $.  \nLet $ T = (t_1, t_2, \\dots, t_n) $ be a sequence of integers representing average temperatures over $ n $ days.\n\n**Constraints*...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments