Internet Problem Solving Contest

IPSC 2017

Problem S – St. Ives

As I was approaching St. Ives,
Out came a man with seven wives,
Each wife had seven sacks,
Each sack had seven cats,
Each cat had seven kits:
Kits, cats, sacks, and wives,
How many were there going to St. Ives?

Problem specification

Above you see one of many versions of an old nursery rhyme. The easy subproblem S1 is about a generalized version of the riddle contained in the nursery rhyme.

The nursery rhyme contains 5 types of objects: the man, the wives, the sacks, the cats, and the kits (i.e., kittens). In the generalized version there are n types of such objects. We will number these types 0 through n − 1, in order.

In the nursery rhyme there is one man, and each object other than a kitten has 7 objects of the following type. In the generalized version there is one object of type 0, and each object of type i has ai objects of type i + 1.

In the easy subproblem S1 you are given the number n and the numbers a0, …, an − 2. Compute and output the answer to the riddle.

In the hard subproblem S2 the input data is the same but the question you have to answer is different. The question will be revealed to you after you solve the subproblem S1. (More precisely, you will find the question for S2 in the evaluation details of an accepted submission to S1.)

Input specification

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

Each test case consists of two lines. The first line contains the positive integer n. The second line contains the nonnegative integers a0, …, an − 2. You may assume that 1 ≤ n ≤ 10 and that for each i, 0 ≤ ai ≤ 10. Note that for n = 1 the second line of a test case will be empty.

Output specification

For each test case output a single line with a single integer: the total number of objects that were, according to the riddle, going to St. Ives.




0 10 2



In the example test case there is a man with zero wives, each wife has 10 sacks, and each sack has two cats.