Good Numbers
InterviewTime limit1sMemory limit128 MB
Count the elements A_i that equal the sum of three elements appearing earlier in the sequence, where the same earlier element may be reused.
- Level
Medium5 of 10
- Topics
- Hash map, Brute force, Array, Implementation
- Solved
- No attempts yet
Problem
You are given a sequence of integers.
The -th number is called a good number if it equals the sum of three numbers chosen from those that appear before it (). The same number may be chosen more than once. In other words, is good if there exist positions with (not necessarily distinct) such that .
Given the sequence, count how many of its numbers are good numbers.
Input
The first line contains the size of the sequence . ()
The second line contains the elements of , separated by spaces. ()
Output
Print the number of good numbers on the first line.