Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- k,n = map(int,input().split())
- a = []
- ans = []
- can = True
- for i in range(n):
- a.append(input())
- for word in a:
- i = 0
- left_count = 0
- right_count = len(word)
- left = True
- right = True
- for sym in word:
- if left:
- if sym == ' ':
- left_count += 1
- else:
- left = False
- else:
- if sym == ' ' and right:
- right_count = i
- right = False
- else:
- right = len(word)
- right = True
- i += 1
- wordx = word[left_count:right_count]
- right_count = left_count = 0
- len_word = len(wordx)
- while len_word < k:
- if left_count < right_count - 1:
- left_count += 1
- wordx = ' ' + wordx
- else:
- right_count += 1
- wordx += ' '
- len_word += 1
- if right_count - 1 == left_count:
- ans.append(wordx)
- else:
- can = False
- break
- if can:
- for word in ans:
- print(word)
- else:
- print('Impossible.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement