Killjee's Matrix Representation

0

0 votes
Easy
Problem

Killjee has got a matrix and now he is trying represent it in a ZIg-Zag format.  

The zigzag format of a matrix is representation of its diagonals in separate line.

Where,  Ith line of output contains ith top right - bottom left diagonal if I is odd.

Ith line of output should contain Ith bottom left - top right diagonal.  If I is even.

 

See sample explanation for better understanding.

 

INPUT

First line of input contain two space separated integers N and M, where N is number of rows in matrix and M is number of columns in matrix.

 

OUTPUT

Output Zig-Zag representation of given matrix;

 

CONSTRAINTS

1n,m1000

1ai109

Sample Input
3 4
1	2 	3 	4
5 	6 	7 	8 
9 	10 	11 	12 
Sample Output
1 
5 2 
3 6 9 
10 7 4 
8 11 
12 
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In 1st line we will print 1st top right - bottom left diagonal which is : 1

In 2nd line we will print 2nd bottom left - top right diagonal: 5 2. As, 1st bottom left-top right diagonal is 1

In 3rd line we will print 3rd  top right - bottom left diagonal: 3 6 9As, top right-bottom left diagonal is 2 5

Editor Image

?