CRAN02 - Roommate Agreement

Leonard was always sickened by how Sheldon considered himself better than him. To decide once and for all who is better among them they decided to ask each other a puzzle. Sheldon pointed out that according to Roommate Agreement Sheldon will ask first. Leonard seeing an opportunity decided that the winner will get to rewrite the Roommate Agreement.

Sheldon thought for a moment then agreed to the terms thinking that Leonard will never be able to answer right. For Leonard, Sheldon thought of a puzzle which is as follows. He gave Leonard n numbers, which can be both positive and negative. Leonard had to find the number of continuous sequence of numbers such that their sum is zero.

For example if the sequence is- 5, 2, -2, 5, -5, 9

There are 3 such sequences

2, -2

5, -5

2, -2, 5, -5

Since this is a golden opportunity for Leonard to rewrite the Roommate Agreement and get rid of Sheldon's ridiculous clauses, he can't afford to lose. So he turns to you for help. Don't let him down.

Input

First line contains T - number of test cases

Second line contains n - the number of elements in a particular test case.

Next line contain n elements, aiĀ (1 <= i <= n) separated by spaces.

Output

The number of such sequences whose sum if zero.

Constraints

1 <= t <= 5

1 <= n <= 10^6

-10 <= ai <= 10

Example

Input:
2
4
0 1 -1 0
6
5 2 -2 5 -5 9

Output:
6
3

Added by:CSI
Date:2013-02-16
Time limit:3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64

hide comments
2017-02-04 14:20:59
Simple one forget to declare result as long long cause me 1 WA
2016-12-31 20:31:08
same as SUBSEQ :D
2016-12-31 17:50:07 prakash
good problem
2016-06-23 17:01:55 Shubham Gupta
Be sure to declare variables in long/ long long. [final answer and intermediate variables. ] Costed me 3 WAs.
P.s. took 1.25s, anyone who got it in less ?

=(Francky)=> http://www.spoj.com/ranks/CRAN02/ 20 psolvers under 0.42s, top psolvers at 0.10s.

Last edit: 2016-06-23 17:09:52
2016-05-20 17:37:12
use long long for final answer
2016-04-27 23:19:25 Reem Obaid
printf("%I64d\n",ans); gives WA on test 8. all i did was change it to cout <<ans <<endl ; and got AC
2016-04-15 11:01:20 utkarsh538
learnt a new logic :)
2015-12-15 11:48:24 Divyaanand Sinha
getting wrong answer for case 8..
2015-12-13 13:38:35 Shashank Tiwari
Make sure that final ans can be in long. So , check for integer overflows.

Last edit: 2015-12-20 08:41:21
2015-07-18 18:40:06 Abhilash
simple one
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.