Similar sequences (2) X06314


Statement
 

pdf   zip

html

In this problem, we say that two sequences of numbers are similar if both have the same sum and finalize with the same number. Provide a program that computes how many of the given sequences are similar to the first (this one included).

In your program, you have to implement and use the following procedure:

void info_sequence(int& sum, int& last);

which reads a sequence from the input and computes the parameters sum and last, the sum of the elements and the last element of the read sequence, respectively.

Input

The input is formed by one or more non-empty sequences of natural numbers all of them strictly positive. Each sequence is finalized by a 0. The end of the input is marked with an empty sequence.

Output

Print how many sequences are similar to the first one, including the first.

Observation

You cannot use strings, vectors or other data structures.

Public test cases
  • Input

    8 14 6 12 0
    8 12 0
    10 30 0
    28 12 0
    74 0
    38 2 0
    40 0
    0
    

    Output

    2
    
  • Input

    5 0
    0
    

    Output

    1
    
  • Input

    1 2 3 4 0
    6 4 0
    4 2 4 0
    1 1 1 1 1 1 4 0
    5 1 4 0
    0
    

    Output

    5
    
  • Information
    Author
    Salvador Roura + Professorat PRO1
    Language
    English
    Translator
    Professorat PRO1
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    Unknown.
    User solutions
    C++