Googly sum
Practice
5 (1 votes)
Ad Hoc
Open
Algorithms
Approved
Medium
Mathamatics
Problem
89% Success 1299 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

In this problem of Googly sum nikki gives you a sequence A consisting of N integers. nikki will call the ith sequence element good if it equals to the sum of some three elements in positions strictly smaller than i . Now nikki asks you a simple question how many good elements does the sequence contain?

Note : An element can be used more than once in the sum i.e lets say sequence is [1 3 5 9] (indexing from 0) consider the following points -

1) In sequence 1 is not good obviously.

2) 3 is good as 1 can be added three times to get 3

3) 5 is good as adding two times 1 and one time 3 will give 5

4) 9 is good as 1+3+5=9 and also adding element 3 three times will give 9 so any of these condition can be used to count 9 as good.

Input :

The first line of input contains the positive integer N , the length of the sequence A. The second line of input contains N space-separated integers representing the sequence A .

Output :

The first and only line of output must contain the number of good elements in the sequence.

Constraints :

1 <= N <= 5000

-10^5 <= Ai <= 10^5

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
Tags:
HiringOpenHiringOpenImplementationHiringMathematicsEasyBasic ProgrammingMathematicsMathematicsMathamatics
Points:30
3 votes
Tags:
AlgorithmsOpenApprovedMediumMathamatics
Points:30
13 votes
Tags:
Binary search algorithmMediumRecruitPrime FactorizationSegment treeMathematicsOpenApprovedMathematicsMathamatics