Matrix

Objective

The objective of this problem is to ensure that students know how to use 2

dimensional array and simple looping technique.

Problem Description

Given a 2 dimensional array of size N x M containing 1 or 0 and a query (ROW or

COLUMN), determine the sum of the numbers in the array corresponding to the

query. For example, query “ROW 3” means sum all the elements in the 3rd row of the

array.

Input

The first line of the input contains two integers, N (1 <= N <= 100) and M (1 <= M

<= 100). The next line is an array with size N x M. The next line is the query with

format “ROW x“, (1 <= x <= N) or “COLUMN y”, (1 <= y <= M).

Output

Output the answer to the query.

Sample Input

4 5

1 0 1 0 1

0 1 0 1 0

1 1 1 0 1

0 0 1 0 0

ROW 3

Sample Output

4

Explanation

1 0 1 0 1

0 1 0 1 0

ROW 3 1 1 1 0 1

0 0 1 0 0

The sum of numbers in row 3 is 4