• + 0 comments
    import math
    import os
    import random
    import re
    import sys
    
    
    
    
    first_multiple_input = input().rstrip().split()
    
    n = int(first_multiple_input[0])
    
    m = int(first_multiple_input[1])
    
    matrix = []
    encodedMatrix = ""
    
    for _ in range(n):
        matrix_item = input()
        matrix.append(matrix_item)
    
    for i in range(m):
        for j in range(n):
            encodedMatrix += matrix[j][i]     
    print(re.sub(r'(?<=\w)\W+(?=\w)',' ',encodedMatrix,re.A))