SP28463 TAP2016I - Insect invasion

Description

**\[Due to SPOJ restrictions, this problem has been modified with respect to the original version used in the Argentinian Programming Tournament of 2016 in order to have multiple test cases per input file. The original version of this problem (in Spanish) can be found at \]** Ignacio liked to take part in programming competitions such as the Argentinian Programming Tournament during his years as a university student. He was very happy, and when he graduated he got a good job. However, with time routine and life in the big city started to make him feel uneasy. So one day he decided to move to the countryside and start a new life as a farmer. He hadn't saved a lot of money, but it was enough to buy a circular field.

Input Format

There are multiple test cases in the input file. For each test case, the first line contains three integer numbers **N**, **R** and **K**. The integer **N** represents the number of ponds in the field (**2 ****10 $ ^{9} $** ), **R** represents the number of frogs (**2** ****R** ****200**) and **K** represents the number of minutes after which the frogs repeat their jumping pattern (**1** ****K** ****200**). The second line contains **R** integer numbers **B $ _{1} $** , **B $ _{2} $** , ..., **B $ _{R} $** , representing the **i**-th number the initial position of the **i**-th frog (**1** ****B\_i** ****N** for **i = 1, ..., R**, with **B $ _{i} $ ≠ B $ _{j} $** if **i** **≠** **j**). The following **R** lines describe the behavior of the frogs. The **i**-th of these lines contains **K** integer numbers **A $ _{i,1} $** , **A $ _{i,2} $** , ..., **A $ _{i,K} $** , representing the number of ponds the **i**-th frog advances in each of its **K** jumps, in the order in which they occur (**1** ****A $ _{i,j} $ < N** for **i = 1, 2, ..., R** and **j = 1, 2, ..., K**).******************

Output Format

For each test case, print a single line containig two integer numbers, representing the maximum number of infected frogs and the minute in which the last transmission of the disease takes place, respectively.