#K94142. Total Employee Count in a Department Hierarchy

    ID: 38576 Type: Default 1000ms 256MiB

Total Employee Count in a Department Hierarchy

Total Employee Count in a Department Hierarchy

You are given a hierarchical department structure. Each department is described by two integers: the number of employees in that department and the number of its direct sub-departments. Then, for each sub-department, the same format is recursively provided.

Your task is to compute the total number of employees in the entire hierarchy. Formally, if a department has E employees and N sub-departments, and if the total employee counts of these sub-departments are \(T_1, T_2, \dots, T_N\) respectively, then the total employee count is given by:

[ Total = E + \sum_{i=1}^{N} T_i ]

The input will be provided in a single line via standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The input consists of a single line containing space-separated integers representing the department structure in a recursive manner. The format is as follows:

  1. An integer E representing the number of employees in the current department.
  2. An integer N representing the number of direct sub-departments.
  3. For each of the N sub-departments, the structure (starting from step 1) repeats recursively.

For example, the input 100 2 20 2 10 0 8 0 50 2 30 2 15 0 10 0 20 0 represents a structure where the root department has 100 employees and 2 sub-departments. The first sub-department has 20 employees and 2 sub-departments (with 10 and 8 employees respectively) and the second sub-department has 50 employees and 2 sub-departments, etc.

outputFormat

Output a single integer which is the total number of employees in the entire department hierarchy.

## sample
15 0
15