Sums of Numbers 8
InterviewTime limit1sMemory limit512 MB
Count the index pairs (i, j) where the sum of A over the range [i, j] equals the sum of B over the same range.
- Level
Easy3 of 10
- Topics
- Prefix sum, Hash map, Array
- Solved
- No attempts yet
Problem
Given two integer sequences of the same length, and .
Find the number of pairs of positive integers () that satisfy .
Input
The first line contains a positive integer .
The second line contains positive integers in order from to , separated by spaces.
The third line contains positive integers in order from to , separated by spaces.
Output
Print the number of pairs of positive integers () that satisfy .
Constraints
Hint
The answer can exceed the range of a 32-bit integer type, so use an integer type that fits your language.
- Java:
long,Long - Kotlin:
Long - Swift:
Int64 - C, C++:
long,long long