codeforces 816D Karen and Test(数学)
来源:互联网 发布:java sleep使用 编辑:程序博客网 时间:2024/05/22 06:40
Karen has just arrived at school, and she has a math test today!
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 109 + 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 ai (1 ≤ ai ≤ 109), 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 109 + 7.
53 6 9 12 15
36
43 7 5 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:
The non-negative remainder after dividing the final number by 109 + 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:
The non-negative remainder after dividing the final number by 109 + 7 is 109 + 6, so this is the correct output.
找规律可以发现,每隔两层就是类似杨辉三角的规律.
- codeforces 816D Karen and Test(数学)
- Codeforces 816D Karen and Test
- Codeforces Round #419 (Div. 2) (Codeforces 815B) D. Karen and Test 组合数学
- codeforces 816 D. Karen and Test(逆元+思维+组合数
- CF815B:Karen and Test(数学)
- Codeforces 815B Karen and Test
- Codeforces 815B. Karen and Test 【规律】
- [数学杂题]Codeforces #419(div1) 815B. Karen and Test
- CodeForces 815D. Karen and Cards
- Codeforces 816B & 816C & 816D Karen and ......(不正经专场)
- Karen and Coffee codeforces 816B
- Karen and Game codeforces 816c
- Codeforces 816C Karen and Game【思维】
- Codeforces 816 -B. Karen and Coffee
- Codeforces 816A-Karen and Morning
- Codeforces 816B-Karen and Coffee
- Codeforces 816B Karen and Coffee
- codeforces 816A Karen and Morning
- C# Async/Await异步函数原理
- OSG学习:LOD、数据分页、动态调度
- 优化网页速度的7种方法
- 【异常】Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- JS学习(12)----events
- codeforces 816D Karen and Test(数学)
- C++精进篇继承及经典示例
- 如何把字符串写入SD卡文件中,如何读取SD卡文件的数据
- SparkSQL 操作 Json 格式数据
- 非阻塞同步算法与CAS(Compare and Swap)无锁算法
- Spring:IoC 用法(九、@Bean 用法)
- ACM基础题:阶乘因式分解(一)
- 考研英语笔记——2005年真题
- JEESZ RestFul服务介绍