SUBSEQ - Counting Subsequences

no tags 

"47 is the quintessential random number," states the 47 society. And there might be a grain of truth in that.

For example, the first ten digits of the Euler's constant are:

2 7 1 8 2 8 1 8 2 8

And what's their sum? Of course, it is 47.

Try walking around with your eyes open. You may be sure that soon you will start discovering occurences of the number 47 everywhere.

Problem specification

You are given a sequence S of integers we saw somewhere in the nature. Your task will be to compute how strongly does this sequence support the above claims.

We will call a continuous subsequence of S interesting if the sum of its terms is equal to 47.

E.g., consider the sequence S = (24, 17, 23, 24, 5, 47). Here we have two interesting continuous subsequences: the sequence (23, 24) and the sequence (47).

Given a sequence S, find the count of its interesting subsequences.

Input specification

The first line of the input file contains an integer T specifying the number of test cases. Each test case is preceded by a blank line.

The first line of each test case contains the length of a sequence N. The second line contains N space-separated integers : the elements of the sequence.

Output specification

For each test case output a single line containing a single integer : the count of interesting subsequences of the given sentence.

Example

Input:
2

13
2 7 1 8 2 8 1 8 2 8 4 5 9

7
2 47 10047 47 1047 47 47

Output:
3
4
Note: the input file will not exceed 4MB.

hide comments
Yashpal: 2014-12-01 07:11:41

What are the ranges of values in sequence ??

nagendra patod: 2014-08-18 10:03:51

getting TLE,do not know how to optimise.

#include: 2014-06-23 22:16:08

For all those with WA...
1
4
47 -47 48 -1
ans is 3...

Got ac with STL, but with poor time, don't know how to optimise...:(

Amit: 2013-08-25 19:14:52

Can some one please give some information N is positive, negative or no constraints ? Is there some limit on T ?

Anick Saha: 2013-08-09 11:32:47

Piece of Cake :D

Aradhya: 2013-05-16 08:08:07

got AC with fast I/O,, TLE with scanf o.O

Ivan Sto¹iæ: 2012-05-31 18:34:10

Why doesn't the problem description include information about N,T, and elements of the sequence?

!@#$: 2011-12-25 19:52:30

any special case ???
dont know why i m getting wa...

Ajey Golsangi: 2011-07-19 16:32:22

Really nice problem. The time bound is tight.

Last edit: 2011-07-19 16:33:15
:D: 2010-12-27 18:04:16

You don't have to count every solution separately (and you shouldn't if you want to get AC).


Added by:Fudan University Problem Setters
Date:2007-12-01
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 ERL JS-RHINO
Resource:IPSC 2006