Consecutive Product Sum
Practice
4 (2 votes)
Algorithms
Math
Combinatorics
Basics of combinatorics
Problem
57% Success 311 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

The score of an Array \(S\) of length \(N \) is defined as \(\sum_{i=0}^{N-2} S_i \cdot S_{i+1}\), i.e. sum of product of every consecutive pair of elements.

Given an Array \(arr\) of length \(N\) find the sum of scores of every subsequence of \(arr\) of length atleast \(2\), return the sum modulo \(10^9 + 7\).

A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.

Input Format:

  • First line contains an integer \(T\) denoting the number of test cases.
  • First line of each testcase contains an integer \(N\) denoting length of \(arr\).
  • Next line contains \(N \) space-seperated integer, denoting the elements of \(arr\).

Output Format:

  • For each testcase, print the sum of scores of every subsequence of \(arr\) having length atleast \(2\), modulo \(10^9 + 7\).

Constraints:

  • \(1 \le T \le 10\)
  • \(2 \le N \le 5 \times 10^5\)
  • \(0 \le arr[i] \le 10^4\)

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
18 votes
Tags:
CombinatoricsMathMedium
Points:30
2 votes
Tags:
CombinatoricsGeometryMathMediumMeet in the middle
Points:30
4 votes
Tags:
CombinatoricsMathMediumNumber Theory