Woburn Challenge 2002
The battle is drawing to an end. Bo Vine has gathered his warriors in front of The Sacred Barn, for some words of inspiration before the final battle. The cows line up in a single line, face Bo, and listen attentively.
"My loyal servants, we are gathered here to prepare for an epic battle. Today, we go forth and win back SCARBERIA, the most coveted of all lands. Once in our control, we shall live as the lions, the true kings of our land. I have here an APE."
(Panic and chaos…)
"HEY! Get back here! It is not a real ape, just our weapon, with which we shall destroy the monkeys, and reclaim Scarberia for ourselves."
While Bo is continuing with this nonsensical rant, he notices that he can assign a value to each cow that is lined up before him, indicating the overall rating of the cow as a warrior. As he continues to indoctrinate the cows, he wonders how many consecutive subsequences of cows have a total rating equal to some number that he is thinking of. If he can determine this, then he can assign these groups of cows to particular locations on the battlefield, just according to his brilliant plan!
Input Specification
The first line of input contains a single integer , indicating the total
number of cows.
The next line contains integers, , separated by a single space,
indicating the values of the cows.
The next line contains a single integer, , indicating the number of
test cases.
The next line contains integers, indicating the values of , the
target sum.
Output Specification
For each test case, output the number of distinct consecutive subsequences of cows that add to the given value of the target sum, all on a single line, separated by a single space.
Sample Input
12
2 5 4 3 11 1 2 7 2 3 41 1
3
2 11 1000
Sample Output
3 3 0
Comments
Since the original data were weak, the constraints were increased, and more test cases were added.