304273: CF815B. Karen and Test

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Karen and Test

题意翻译

## 题目描述 可怜刚刚到达学校,并且她今天有一场数学考试。 这场考试是关于基本的加减法的。不幸的是,老师们都忙于给Codeforces rounds出测试,以至于没有时间出一个实际的考试。所以,他们仅在这场考试中出了一道包含所有分数的题。 有$n$ 个整数被写在一行上。可怜必须对相邻的两个整数交替进行加减法,并把结果写在下一行。她需要重复这个过程直到只剩下一个整数。第一个操作应当是加法。 注意,如果在上一行她以加法结束,那么下一行她应当以减法开始,反之亦然。 老师们将只关心最后一个整数,如果它正确,可怜将得到所有分数,否则她这场考试将爆零。 可怜在这场考试发挥的很好,但是她害怕会在某处犯错误,并导致她的最终答案错误。如果按这个过程下来,她最后一行应写什么数? 因为这个数可能非常大,仅需输出一个对$10^9+7$ 取模后的非负整数的结果。 ### 输入格式: 第一行包含一个整数$n$ ($1\leq n\leq200000$ ),表示写在第一行的数的个数。 下一行包含$n$ 个整数。具体来说,第$i$ 个数为$a_i$ ($1\leq a_i\leq10^9$ ),表示在第一行写下的第$i$ 个数。 ### 输出格式: 输出一行一个整数,表示在这个过程后,最后一行写下的数。 因为这个数可能非常大,仅需输出一个对$10^9+7$ 取模后的非负整数的结果。 感谢@Khassar 提供的翻译

题目描述

Karen has just arrived at school, and she has a math test today! ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF815B/5bba5a70dc5ed9bfe1ecdd4df178072431bc5fd5.png)The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. There are $ n $ integers written on a row. Karen must alternately add and subtract each pair of adjacent integers, and write down the sums or differences on the next row. She must repeat this process on the values on the next row, and so on, until only one integer remains. The first operation should be addition. Note that, if she ended the previous row by adding the integers, she should start the next row by subtracting, and vice versa. The teachers will simply look at the last integer, and then if it is correct, Karen gets a perfect score, otherwise, she gets a zero for the test. Karen has studied well for this test, but she is scared that she might make a mistake somewhere and it will cause her final answer to be wrong. If the process is followed, what number can she expect to be written on the last row? Since this number can be quite large, output only the non-negative remainder after dividing it by $ 10^{9}+7 $ .

输入输出格式

输入格式


The first line of input contains a single integer $ n $ ( $ 1<=n<=200000 $ ), the number of numbers written on the first row. The next line contains $ n $ integers. Specifically, the $ i $ -th one among these is $ a_{i} $ ( $ 1<=a_{i}<=10^{9} $ ), the $ i $ -th number on the first row.

输出格式


Output a single integer on a line by itself, the number on the final row after performing the process above. Since this number can be quite large, print only the non-negative remainder after dividing it by $ 10^{9}+7 $ .

输入输出样例

输入样例 #1

5
3 6 9 12 15

输出样例 #1

36

输入样例 #2

4
3 7 5 2

输出样例 #2

1000000006

说明

In the first test case, the numbers written on the first row are $ 3 $ , $ 6 $ , $ 9 $ , $ 12 $ and $ 15 $ . Karen performs the operations as follows: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF815B/4522a336e6e45834aaa7e608977c841b6ddf6cd9.png)The non-negative remainder after dividing the final number by $ 10^{9}+7 $ is still $ 36 $ , so this is the correct output. In the second test case, the numbers written on the first row are $ 3 $ , $ 7 $ , $ 5 $ and $ 2 $ . Karen performs the operations as follows: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF815B/e171da4a18873b671d34c6007d04d2eae5fdb6e6.png)The non-negative remainder after dividing the final number by $ 10^{9}+7 $ is $ 10^{9}+6 $ , so this is the correct output.

Input

题意翻译

## 题目描述 可怜刚刚到达学校,并且她今天有一场数学考试。 这场考试是关于基本的加减法的。不幸的是,老师们都忙于给Codeforces rounds出测试,以至于没有时间出一个实际的考试。所以,他们仅在这场考试中出了一道包含所有分数的题。 有$n$ 个整数被写在一行上。可怜必须对相邻的两个整数交替进行加减法,并把结果写在下一行。她需要重复这个过程直到只剩下一个整数。第一个操作应当是加法。 注意,如果在上一行她以加法结束,那么下一行她应当以减法开始,反之亦然。 老师们将只关心最后一个整数,如果它正确,可怜将得到所有分数,否则她这场考试将爆零。 可怜在这场考试发挥的很好,但是她害怕会在某处犯错误,并导致她的最终答案错误。如果按这个过程下来,她最后一行应写什么数? 因为这个数可能非常大,仅需输出一个对$10^9+7$ 取模后的非负整数的结果。 ### 输入格式: 第一行包含一个整数$n$ ($1\leq n\leq200000$ ),表示写在第一行的数的个数。 下一行包含$n$ 个整数。具体来说,第$i$ 个数为$a_i$ ($1\leq a_i\leq10^9$ ),表示在第一行写下的第$i$ 个数。 ### 输出格式: 输出一行一个整数,表示在这个过程后,最后一行写下的数。 因为这个数可能非常大,仅需输出一个对$10^9+7$ 取模后的非负整数的结果。 感谢@Khassar 提供的翻译

加入题单

上一题 下一题 算法标签: