Hard to Miss
Matt is watching the shooting finals.
There are n marksmen standing next to each other along the shooting range, numbered from 1 to n from left to right. A formation of k targets moves across the range from left to right, with the same spacing as the marksmen. Hitting target j adds bj points to a marksman's score.
Initially, target j is directly in front of marksman j. Each second, every marksman with a target directly in front of them fires exactly once, and all shots are simultaneous. Every shot hits, and targets remain in the formation after being hit. If marksman n has fired, the round ends; otherwise, the formation moves one position to the right before the next second.
Formally, let ci be the score of marksman i, initially 0 for every 1≤i≤n. For each second i=1,2,…,n−k+1 in order, the following happens:
ci+j−1←ci+j−1+bjfor every 1≤j≤k.
Unfortunately, Matt is short-sighted and cannot see the targets. He can only see the final scoreboard a1,a2,…,an, where ai is the score of marksman i.
Find a possible number of targets k and their point values b1,b2,…,bk that produce the given final scoreboard.
If there are several valid formations, output any of them. If none exists, output -1.
Input
The first line contains an integer n (1≤n≤2×105), the number of marksmen.
The second line contains n integers a1,a2,…,an (1≤ai≤1018), their final scores.
Output
If no valid formation exists, print -1 on a single line.
Otherwise, print an integer k (1≤k≤n), the number of targets, on the first line. On the second line, print k space-separated integers b1,b2,…,bk (1≤bj≤1018), the targets' point values in their initial left-to-right order.
Example 1
3
2 5 3
2
2 3
Explanation
The formation has k=2 targets, worth 2 and 3 points.
- Second 1: marksman 1 hits target 1 for 2 points, marksman 2 hits target 2 for 3 points. The scoreboard reads [2,3,0].
- Second 2: the formation moves right by one position, so marksman 2 hits target 1 for 2 points and marksman 3 hits target 2 for 3 points. The scoreboard reads [2,5,3]. Since the rightmost marksman has hit a target, the round ends.
Example 2
5
2 7 10 8 3
4
2 5 5 3
Explanation
The formation has k=4 targets, worth 2, 5, 5 and 3 points.
- Second 1: the targets are in front of marksmen 1 to 4, and the scoreboard reads [2,5,5,3,0].
- Second 2: the formation has moved right by one position, so the targets are in front of marksmen 2 to 5. After they shoot, the scoreboard reads [2,7,10,8,3]. Since the rightmost marksman has hit a target, the round ends.
Another formation that is consistent with this scoreboard is [2,5,3], which will also be accepted.
Example 3
1
7
1
7
Explanation
There is only one marksman, so the formation has one target and the round ends after one shot. The target must be worth exactly 7 points.
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.