Dexter and Points
Practice
3 (7 votes)
Easy
Greedy algorithms
Problem
16% Success 3731 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Dexter has you on his kill table now. He gives you one last chance to survive. He gives you a problem to solve. If you solve the problem correctly, he will let you go, else he will kill you.

You are given N integers \(a_1, a_2, ,...,a_N\). Consider an N-dimensional hyperspace. Let \((x_1,x_2,...,x_N)\) be a point in this hyperspace and all \(x_i\) for \(i \in [1,N]\) are integers. Now, Dexter gives you a set which contains all the points such that \(0 \le x_i \le a_i\) for \(i \in [1,N]\). Find the number of ways to select two points A and B from this set, such that the midpoint of A and B also lies in this set.

As the required number can be really large, find the answer modulo \(10^9+7\).

Note: The two selected points can be same.

Input
First line of input contains a single integer N, representing the number of dimensions in the hyperspace. The second line contains N integers, the \(i^{th}\) of them representing \(a_i\), as defined in the problem.

Output
The output contains a single integer, the answer to the problem, modulo \(10^9+7\).

Constraints
\(1 \le N \le 10^5\)
\(0 \le a_i \le 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
23 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:30
10 votes
Tags:
SortingAlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:30
57 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulationMathSorting