import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static boolean[] primeNumber = new boolean[10001];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[][] A = new int[N][M];
int[][] B = new int[N][M];
for (int i = 0; i < A.length; i++) {
st = new StringTokenizer(br.readLine(), " ");
for (int j = 0; j < A[i].length; j++) {
A[i][j] = Integer.parseInt(st.nextToken());
}
}
for (int i = 0; i < B.length; i++) {
st = new StringTokenizer(br.readLine(), " ");
for (int j = 0; j < B[i].length; j++) {
B[i][j] = Integer.parseInt(st.nextToken());
}
}
br.close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
sb.append(A[i][j] + B[i][j]).append(" ");
}
sb.append("\n");
}
System.out.print(sb);
}
}
사실 두번째 반복문에서 A행렬에 더해주는 방식을 취해주면 B행렬을 생성하지 않아도 되는 문제이다.