#C10818. Sum of the Kth Column in a Matrix

    ID: 40065 Type: Default 1000ms 256MiB

Sum of the Kth Column in a Matrix

Sum of the Kth Column in a Matrix

You are given a matrix of integers with N rows and M columns, and an integer ( K ) (0-indexed). Your task is to calculate the sum of all elements in the ( K )th column of the matrix. If the column ( K ) does not exist (i.e. ( K \geq M )), then output -1.

The input is read from standard input and the result should be printed to standard output.

inputFormat

The first line of input contains two integers ( N ) and ( M ), representing the total number of rows and columns respectively. Each of the next ( N ) lines contains ( M ) space-separated integers representing the elements of the matrix. The last line of the input contains an integer ( K ) (0-indexed) which denotes the column whose sum needs to be computed.

outputFormat

Output a single integer: the sum of the elements in the ( K )th column. If the column does not exist, output -1.## sample

3 4
1 2 3 4
5 6 7 8
9 10 11 12
2
21