Let's dive into decorators! You are given $N$ mobile numbers. Sort them in ascending order then print them in the standard format shown below:

+91 xxxxx xxxxx

The given mobile numbers may have $+91$, $91$ or $\mbox{0}$ written before the actual $10$ digit number. Alternatively, there may not be any prefix at all.

Input Format

The first line of input contains an integer $N$, the number of mobile phone numbers. 

$N$ lines follow each containing a mobile number.

Output Format

Print $N$ mobile numbers on separate lines in the required format.

Sample Input

3
07895462130
919875641230
9195969878

Sample Output

+91 78954 62130
+91 91959 69878
+91 98756 41230

Concept

Like most other programming languages, Python has the concept of closures. Extending these closures gives us decorators, which are an invaluable asset. You can learn about decorators in 12 easy steps here.

To solve the above question, make a list of the mobile numbers and pass it to a function that sorts the array in ascending order. Make a decorator that standardizes the mobile numbers and apply it to the function.

Difficulty: EASY

Solutions:
import re
n = int(input())
numbers = [input() for _ in range(n)]

def normalize(sort):
	pattern = re.compile('^(?:\\+?91|0)?(\\d{10})$')

	def normalized_sort(numbers):
		numbers = map(lambda number: pattern.match(number).group(1), numbers)
		numbers = sort(numbers)
		return map(lambda number: '+91 {} {}'.format(number[:5], number[5:]), numbers)
	return normalized_sort

@normalize
def mysort(numbers):
	return sorted(numbers)
for number in mysort(numbers):
	print(number)


n = int(input())
r = []
for i in range(n):
	num = input()
	while len(num) < 10:
		num = '0' + num
	num = num[len(num) - 10:]
	r.append(num)
for num in sorted(r):
	print('+91', num[0:5], num[5:])


n = int(input())
ac = []
while n > 0:
	num = input()
	if len(num) == 10:
		ac.append(int(num))
	elif len(num) == 11:
		ac.append(int(num[1:len(num)]))
	elif len(num) == 12:
		ac.append(int(num[2:len(num)]))
	elif len(num) == 13:
		ac.append(int(num[3:len(num)]))
	n -= 1
ac.sort()
for n in ac:
	n = str(n)
	print('+91 {0} {1}'.format(n[:5], n[5:]))


import re
sub_input = lambda pattern: lambda func: lambda : re.sub(pattern, func, input())

@sub_input('(\\+?91|0)?(\\d{5})(\\d{5})')
def standartize(match):
	return '+91 {1} {2}'.format(*match.groups())
for l in sorted((standartize() for i in range(int(input())))):
	print(l)


import re

def stand(num):
	if re.match('0', num):
		return '+91 ' + num[1:6] + ' ' + num[6:12]
	if re.match('\\+', num):
		return '+91 ' + num[3:8] + ' ' + num[8:14]
	if len(num) == 10:
		return '+91 ' + num[0:5] + ' ' + num[5:11]
	return '+91 ' + num[2:7] + ' ' + num[7:13]
N = int(input())
lis = []
for i in range(0, N):
	lis.append(input())
lis = list(map(stand, lis))
lis.sort()
for i in range(0, len(lis)):
	print(lis[i])


n = int(input())
nums = sorted(map(lambda n: '+91 {} {}'.format(n[-10:-5], n[-5:]), [input() for i in range(n)]))
for n in nums:
	print(n)


def normalize(f):
	return lambda a: f(('+91' + ' ' + s[-10:-5] + ' ' + s[-5:] for s in a))

def sort(a):
	return sorted(a)
print(*normalize(sort)([input() for i in range(int(input()))]), sep='\n')


i = int(input())

def read_number():
	return input()

def decorate(fn):

	def decorate_number():
		n = fn()
		if len(n) == 10:
			n = '+91' + n
		elif len(n) == 11:
			n = '+91' + n[1:]
		elif len(n) == 12:
			n = '+' + n
		return ' '.join([n[:3], n[3:8], n[8:]])
	return decorate_number
read_number = decorate(read_number)
numbers = [read_number() for n in range(i)]
numbers.sort()
for number in numbers:
	print(number)


n = int(input())

def dec(func):

	def inner(phone):
		phone = '+91 %s %s' % (phone[:5], phone[5:])
		return func(phone)
	return inner

@dec
def printphone(phone):
	print(phone)
phones = []
for i in range(n):
	phones.append(input().rstrip()[-10:])
phones.sort()
[printphone(x) for x in phones]


import sys
import re
numberre = re.compile('^(?:\\+?91|0)?([789]\\d{4})(\\d{5})$')

def standardize_numbers(func):

	def f(numbers):
		numbers = [numberre.sub('+91 \\1 \\2', num) for num in numbers]
		return func(numbers)
	return f

@standardize_numbers
def sort_numbers(numbers):
	return sorted(numbers)
(_, numbers) = (input(), sys.stdin.read().strip().split('\n'))
for number in sort_numbers(numbers):
	print(number)


n = int(input())
ar = []
for i in range(0, n):
	tmp_str = input()
	tmp_str = tmp_str[len(tmp_str) - 10:]
	ar.append(tmp_str)
ar.sort()
for i in range(0, len(ar)):
	print('+91 ' + ar[i][:5] + ' ' + ar[i][5:])


def expandNumbers(func, numbers):
	phones = []
	for n in numbers:
		if len(n) == 10:
			phones.append('+91' + n)
		elif len(n) == 11:
			phones.append('+91' + n[1:])
		elif len(n) == 12:
			phones.append('+' + n)
		elif len(n) == 13:
			phones.append(n)
	func(sorted(phones))

def printNumbers(l):
	print('\n'.join((number[:3] + ' ' + number[3:8] + ' ' + number[8:] for number in l)))
numbers = [input() for _ in range(int(input()))]
expandNumbers(printNumbers, numbers)


testcase = int(input())
out = []
for x in range(testcase):
	num = input().strip()
	if len(num) == 10:
		out.append('+91 ' + num[0:5] + ' ' + num[5:10])
	elif num[0] == '0':
		out.append('+91 ' + num[1:6] + ' ' + num[6:11])
	elif num[0] == '+':
		out.append('+91 ' + num[3:8] + ' ' + num[8:13])
	else:
		out.append('+91 ' + num[2:7] + ' ' + num[7:12])
out.sort()
for x in out:
	print(x)


size = int(input())
formatedlist = list()
for i in range(0, size):
	telnum = input()
	formatedlist.append('+91' + ' ' + telnum[-10:-5] + ' ' + telnum[-5:])
printlist = sorted(formatedlist)
[print(printlist[i]) for i in range(len(printlist))]


a = []
for i in range(int(input())):
	t = input()
	if len(t) == 10:
		a.append('+91 {} {}'.format(t[0:5], t[5:]))
	elif t[0] == '0':
		a.append('+91 {} {}'.format(t[1:6], t[6:]))
	elif len(t) == 12:
		a.append('+{} {} {}'.format(t[0:2], t[2:7], t[7:]))
	else:
		a.append('{} {} {}'.format(t[0:3], t[3:8], t[8:]))
for x in sorted(a):
	print(x)


n = int(input())
l1 = []
l2 = []
for i in range(n):
	l1.append(input())
for i in range(n):
	x = ''
	for e in range(len(l1[i]) - 10, len(l1[i])):
		x = x + l1[i][e]
	l2.append(x)
l2.sort()
for i in range(n):
	print('+91 ', end='')
	for e in range(5):
		print(l2[i][e], end='')
	print(end=' ')
	for e in range(5, 10):
		print(l2[i][e], end='')
	print(end='\n')


import re

def prettify(num):
	m = re.search('(\\d{5})(\\d{5})$', num)
	return '+91 ' + m.group(1) + ' ' + m.group(2)

def deco(func):

	def inner(nums):
		return sorted(map(prettify, func(nums)))
	return inner

@deco
def mysort(nums):
	return sorted(numbers)
numbers = []
for _ in range(int(input())):
	numbers.insert(0, input())
for num in mysort(numbers):
	print(num)


test = int(input())
lst = []
for i in range(test):
	phno = input()
	if len(phno) != 10:
		phno = phno[-10:]
	lst.append(phno)
lst.sort()
for phno in lst:
	lower = phno[:5]
	upper = phno[-5:]
	print('+91 ' + lower + ' ' + upper)


import re
m_phone_num = re.compile('(?:91|0|\\+91|)(\\d{10})$')

def cvt(num):
	return m_phone_num.match(num).group(1)

def dec_m_num(func):

	def inner_dec_m_nums(nums):
		cvt_nums = list(map(cvt, nums))
		return func(cvt_nums)
	return inner_dec_m_nums

def sort_m_nums(nums):
	nums.sort()
	for num in nums:
		print('+91 %s %s' % (num[0:5], num[5:10]))
nums = []
num_tests = int(input())
sort_m_nums = dec_m_num(sort_m_nums)
for idx in range(0, num_tests):
	num = input()
	nums.append(num)
sort_m_nums(nums)


def sortAndMakeResult(numbers):
	toSort = list()
	for n in numbers:
		if len(n) == 10:
			toSort.append(n)
		elif len(n) == 11:
			toSort.append(n[1:])
		elif len(n) == 12:
			toSort.append(n[2:])
		elif len(n) == 13:
			toSort.append(n[3:])
	toSort.sort()
	for n in toSort:
		print('+91 ' + n[:5] + ' ' + n[5:])
n = input()
numbers = list()
for i in range(int(n)):
	number = input()
	numbers.append(number)
sortAndMakeResult(numbers)


n = int(input())
list = []
while n > 0:
	str = input()
	list.append(str)
	n -= 1
list1 = []
for str in list:
	l = len(str)
	st = str[l - 10:]
	list1.append(st)
list1.sort()
for str in list1:
	print('+91 ' + str[0:5] + ' ' + str[5:10])


n = int(input())
a = []
for i in range(n):
	l = input()
	if len(l) == 10:
		a.append(l)
	elif len(l) == 11:
		a.append(l[1:])
	elif len(l) == 12:
		a.append(l[2:])
	elif len(l) == 13:
		a.append(l[3:])

def foo():
	a.sort()
	return a

def deco(op):

	def inner():
		for i in op():
			print('+91 ' + i[0:5] + ' ' + i[5:])
	return inner
deco = deco(foo)
deco()


def formatNumber(f):

	def formatter(L):
		return f(['+91 %s %s' % (x[-10:-5], x[-5:]) for x in L])
	return formatter

@formatNumber
def sortNumbers(L):
	return sorted(L)
L = []
for _ in range(0, int(input())):
	L.append(input())
for phone in sortNumbers(L):
	print(phone)


def get_input():
	lines = []
	num_lines = int(input())
	for i in range(num_lines):
		lines.append(input())
	return lines

def sort_lines(lines_of_numbers):
	return sorted(lines_of_numbers, key=lambda x: x[-10:])

def wrapper(func):

	def standardize_numbers(lines_of_numbers):
		lines = func(lines_of_numbers)
		for i in range(len(lines)):
			lines[i] = '+91 {} {}'.format(lines[i][-10:-5], lines[i][-5:])
		return lines
	return standardize_numbers

def main():
	lines = get_input()
	decorated_sort = wrapper(sort_lines)
	lines = decorated_sort(lines)
	for line in lines:
		print(line)
main()


n = int(input())
l = []
for i in range(n):
	l.append(input())

def decorator(sortfunc):

	def inner(l):
		for i in range(len(l)):
			l[i] = '+91 ' + l[i][-10:-5] + ' ' + l[i][-5:]
		return sortfunc(l)
	return inner
mobile_number_sort = decorator(sorted)
l = mobile_number_sort(l)
for i in l:
	print(i)


import re
tel = []
for i in range(int(input())):
	inp = input()
	if len(inp) == 10:
		tel.append(inp)
	else:
		s = re.search('(\\+91|91|0?)([\\d]+)', inp)
		tel.append(s.group(2))
for j in sorted(tel):
	print('+91 ' + j[0:5] + ' ' + j[5:10])


a = int(input())
c = []
while a > 0:
	b = input()
	if len(b) == 12:
		c.append(b[0:2] + ' ' + b[2:7] + ' ' + b[7:12])
	elif len(b) == 10:
		c.append('91 ' + b[0:5] + ' ' + b[5:10])
	elif len(b) == 11:
		c.append('91 ' + b[1:6] + ' ' + b[6:11])
	elif len(b) == 13:
		c.append(b[1:3] + ' ' + b[3:8] + ' ' + b[8:13])
	a -= 1
c.sort()
for i in c:
	print('+' + str(i))


def normalize(num):
	norm = num[-10:]
	return '+91' + ' ' + norm[:5] + ' ' + norm[-5:]

def norm(func):

	def dec(nums):
		normal = [normalize(num) for num in nums]
		normal = func(normal)
		return normal
	return dec
c = int(input())
nums = []
for i in range(c):
	nums.append(input())
sor = norm(sorted)
nums = sor(nums)
for num in nums:
	print(num)


def wrapper(foo):

	def standard(l):
		l = foo(l)
		l = [str(x) for x in l]
		list_temp = []
		for num in l:
			num = '+91 %s %s' % (num[0:5], num[5:10])
			list_temp.append(num)
		return list_temp
	return standard

@wrapper
def sort_number(l):
	list_temp = []
	for num in l:
		list_temp.append(num[len(num) - 10:])
	list_temp = [int(x) for x in list_temp]
	list_temp.sort()
	return list_temp
N = int(input())
l = []
for i in range(0, N):
	l.append(input())
for k in sort_number(l):
	print(k)


import sys
if sys.version_info[0] >= 3:
	raw_input = input
z = []
for i in range(int(raw_input())):
	s = raw_input().rstrip()[-10:]
	z.append('+91 ' + s[0:5] + ' ' + s[5:])
z.sort()
for e in z:
	print(e)


import re

def format_phone_numbers(f):

	def g(xs):
		for (i, x) in enumerate(xs):
			x = x[len(x) - 10:]
			xs[i] = '+91 ' + x[:5] + ' ' + x[5:]
		f(xs)
	return g

@format_phone_numbers
def sort_phone_numbers(xs):
	xs.sort()
xs = [input() for _ in range(int(input()))]
sort_phone_numbers(xs)
for x in xs:
	print(x)


import re

def standardize(func):

	def inner(nums):
		nums = [re.search('^(((\\+)?91)|0)?(\\d{10})$', num).group(4) for num in nums]
		return func(['+91 ' + num[:5] + ' ' + num[5:] for num in nums])
	return inner

@standardize
def sort_list(nums):
	return sorted(nums)
n = int(input())
nums = [input() for _ in range(n)]
print('\n'.join(sort_list(nums)))


def outer(l):

	def inner():
		nonlocal l
		x = [str('+91 ' + l[i][-10:-5] + ' ' + l[i][-5:]) for i in range(len(l))]
		for i in sorted(x):
			print(i)
	return inner
m = []
for __t__ in range(int(input())):
	m.append(input())
fn = outer(m)
fn()


def formatnum(phone):
	print('+91 ' + phone[:5] + ' ' + phone[5:])
num = int(input())
phones = []
for i in range(num):
	phonenum = str(input())
	phones.append(phonenum[len(phonenum) - 10:])
phones = sorted(phones)
for i in phones:
	formatnum(i)


n = input()
s = []
for i in range(int(n)):
	a = input()
	a = a[-10:]
	s.append(a)
s.sort()
for i in range(int(n)):
	print('+91 {0} {1}'.format(s[i][0:5], s[i][5:10]))


n = int(input())
lis = []
for i in range(0, n):
	number = str(input())
	length = len(number)
	if length == 13:
		lis.append(number[3:])
	elif length == 12:
		lis.append(number[2:])
	elif length == 11:
		lis.append(number[1:])
	else:
		lis.append(number)
lis.sort()
for i in range(0, n):
	print('+91 ' + lis[i][:5] + ' ' + lis[i][5:])


def standardize(f):

	def moddedf(numbers):
		numbers = [n[-10:] for n in numbers]
		numbers = ['+91 %s %s' % (n[-10:-5], n[-5:]) for n in f(numbers)]
		return numbers
	return moddedf

@standardize
def sortNumbers(numbers):
	return sorted(numbers)
numbers = [input() for i in range(int(input()))]
for number in sortNumbers(numbers):
	print(number)


def cmp_to_key(mycmp):

	class K(object):

		def __init__(self, obj, *args):
			self.obj = obj

		def __lt__(self, other):
			return mycmp(self.obj, other.obj) < 0

		def __gt__(self, other):
			return mycmp(self.obj, other.obj) > 0

		def __eq__(self, other):
			return mycmp(self.obj, other.obj) == 0

		def __le__(self, other):
			return mycmp(self.obj, other.obj) <= 0

		def __ge__(self, other):
			return mycmp(self.obj, other.obj) >= 0

		def __ne__(self, other):
			return mycmp(self.obj, other.obj) != 0
	return K

def CmpNumbers(x, y):
	l1 = len(x)
	l2 = len(y)
	if l1 < l2:
		ml = l1
	else:
		ml = l2
	for i in range(ml):
		if x[i] < y[i]:
			return -1
		if x[i] > y[i]:
			return 1
	if l1 < l2:
		return -1
	elif l1 > l2:
		return 1
	else:
		return 0

def FormatNumber(p):
	p10 = p[-10:]
	fp = '+91 ' + p10[0:5] + ' ' + p10[-5:]
	return fp
n = int(input())
lst = [input() for i in range(0, n)]
lst = [p[-10:] for p in lst]
lst.sort(key=cmp_to_key(CmpNumbers))
for p in lst:
	print(FormatNumber(p))


num = input()
mobile_numbers = []
for i in range(int(num)):
	mobile = input()
	mobile_numbers.append(mobile)
my_list = []
for i in range(int(num)):
	number = mobile_numbers[i][::-1]
	my_list.append(number[5:10][::-1] + number[0:5][::-1])
my_list.sort()
for i in range(int(num)):
	print('+91 ' + my_list[i][0:5] + ' ' + my_list[i][5:10])


list = []
n = int(input())
for i in range(n):
	mobile = input()
	if mobile.startswith('0'):
		mobile = '+91' + mobile[1:]
		mobile = mobile[:3] + ' ' + mobile[3:]
		mobile = mobile[:-5] + ' ' + mobile[-5:]
	if len(mobile) == 10:
		mobile = '+91' + mobile
		mobile = mobile[:3] + ' ' + mobile[3:]
		mobile = mobile[:-5] + ' ' + mobile[-5:]
	if len(mobile) == 12:
		mobile = '+' + mobile
		mobile = mobile[:3] + ' ' + mobile[3:]
		mobile = mobile[:-5] + ' ' + mobile[-5:]
	if len(mobile) == 13:
		mobile = mobile[:3] + ' ' + mobile[3:]
		mobile = mobile[:-5] + ' ' + mobile[-5:]
	list.append(mobile)
list.sort()
for el in list:
	print(el)


l = []

def mobileNo_format(fun):

	def inner(*args):
		x = args[0]
		y = x[:5]
		z = x[5:]
		return '+91 ' + y + ' ' + z
	return inner

@mobileNo_format
def prnt(x):
	return x
for t in range(int(input())):
	x = input()
	y = len(x)
	l.append(x[y - 10:])
l.sort()
for i in range(len(l)):
	print(prnt(l[i]))


N = int(input())
numbers = [0] * N
for i in range(N):
	numbers[i] = int(input())

def formatter(func):

	def inner(array):
		for i in range(len(array)):
			array[i] = array[i] % 10000000000
		ret = func(array)
		for i in range(len(ret)):
			leng = len(str(ret[i]))
			ret[i] = str(ret[i])
			if leng == 10:
				ret[i] = '+91 ' + ret[i][0:5] + ' ' + ret[i][5:10]
			elif leng == 9:
				ret[i] = '+91 0' + ret[i][0:4] + ' ' + ret[i][4:10]
			elif leng == 8:
				ret[i] = '+91 00' + ret[i][0:3] + ' ' + ret[i][3:10]
			else:
				print('error! probably less than 10 values')
		return ret
	return inner

@formatter
def order(array):
	for i in range(1, len(array)):
		x = array[i]
		j = i
		while j > 0 and array[j - 1] > x:
			array[j] = array[j - 1]
			j = j - 1
		array[j] = x
	return array
a = order(numbers)
for i in range(len(a)):
	print(a[i])


N = int(input())
numbers = []
for _ in range(N):
	num = input()
	start = len(num) - 10
	mid = start + 5
	first = num[start:mid]
	second = num[mid:]
	num = first + second
	numbers.append(num)
numbers.sort()
for num in numbers:
	number = '+91 ' + num[:5] + ' ' + num[5:]
	print(number)


def standize(func):

	def inner(*args, **kwargs):
		numbers = []
		for num in args[0]:
			begin = 0
			if len(num) == 11 and num[0] == '0':
				begin = 1
			elif len(num) == 12 and num[0:2] == '91':
				begin = 2
			elif len(num) == 13 and num[0:3] == '+91':
				begin = 3
			num_str = ''
			for i in range(begin, len(num), 5):
				num_str += num[i:i + 5] + ' '
			num_str = '+91 ' + num_str.rstrip()
			numbers += [num_str]
		return func(numbers)
	return inner

@standize
def print_phonenum(numbers):
	for num in sorted(numbers):
		print(num)
N = int(input())
numbers = []
for _ in range(N):
	numbers += [input()]
if N != 0:
	print_phonenum(numbers)


def standardizer(func):

	def stand_inner(raw_lst):
		for i in range(len(raw_lst)):
			raw_lst[i] = '+91 ' + raw_lst[i][-10:-5] + ' ' + raw_lst[i][-5:]
		return func(raw_lst)
	return stand_inner

@standardizer
def list_sort(lst):
	lst = sorted(lst)
	for item in lst:
		print(item)

def main():
	N = int(input())
	num_list = []
	for i in range(N):
		num_list.append(str(input()))
	list_sort(num_list)
main()


def fixstring(dirtystring):
	fixedstring = ''
	if len(dirtystring) == 10:
		fixedstring = dirtystring[0:12]
	elif dirtystring.startswith('+91'):
		fixedstring = dirtystring[3:13]
	elif dirtystring.startswith('91'):
		fixedstring = dirtystring[2:12]
	elif dirtystring.startswith('0'):
		fixedstring = dirtystring[1:11]
	else:
		fixedstring = 0
	return fixedstring
max = int(input())
numberslist = []
for i in range(0, max):
	tempstring = input()
	numberslist.append(fixstring(tempstring))
numberslist.sort(key=int)
for val in numberslist:
	print('+91 ' + val[0:5] + ' ' + val[5:10])


t = int(input())
lst = []
for i in range(0, t):
	a = input()
	lst.append(a[-10:])
lst = sorted(lst)
for item in lst:
	print('+91', item[0:5], item[5:])


s = ''
n = int(input())
p = [''] * n
for i in range(n):
	s = input()
	if len(s) == 10:
		p[i] = '+91 ' + s[0:5] + ' ' + s[5:10]
	elif len(s) == 11:
		p[i] = '+91 ' + s[1:6] + ' ' + s[6:11]
	elif len(s) == 12:
		p[i] = '+91 ' + s[2:7] + ' ' + s[7:12]
	else:
		p[i] = '+91 ' + s[3:8] + ' ' + s[8:13]
p.sort()
for i in range(n):
	print(p[i])


N = int(input().strip())
phones = []
for i in range(N):
	phone = input().strip()
	if len(phone) > 10:
		if phone[0] == '0':
			phone = phone[1:]
		elif phone.startswith('+91'):
			phone = phone[3:]
		elif phone.startswith('91'):
			phone = phone[2:]
	phones.append(phone)
phones.sort()
for phone in phones:
	print('+91 {} {}'.format(phone[:5], phone[5:]))


n = int(input())
lst = []
for x in range(n):
	num = input()
	lst.append(num[-10:])
lst.sort()
for num in lst:
	print('+91', num[:5], num[5:])


from functools import reduce

def standardize(f):

	def normalize(n):
		return '+91 ' + n[-10:-5] + ' ' + n[-5:]

	def wrapper(*args, **kwargs):
		numbers = f(*args, **kwargs)
		return [normalize(num) for num in numbers]
	return wrapper

@standardize
def sort_nums(lst):
	return list(sorted((n[-10:] for n in lst)))
N = int(input())
numbers = sort_nums([input().strip() for x in range(N)])
for number in numbers:
	print(number)


size = int(input())
order = list()
for i in range(size):
	number = input()
	order.append(number[len(number) - 10:])
order.sort()
for number in order:
	print('+91 ' + number[:len(number) - 5] + ' ' + number[len(number) - 5:])


import re
n = int(input())
x = []
for i in range(n):
	a = input()
	if len(a) == 10:
		x.append('+91 ' + a[0:5] + ' ' + a[5:10])
	elif len(a) == 11:
		x.append('+91 ' + a[1:6] + ' ' + a[6:11])
	elif len(a) == 12:
		x.append('+91 ' + a[2:7] + ' ' + a[7:12])
	elif len(a) == 13:
		x.append(a[0:3] + ' ' + a[3:8] + ' ' + a[8:13])
x = sorted(x)
for i in x:
	print(i)


n = int(input())
nbs = [input()[-10:] for _ in range(n)]
print('\n'.join(sorted(map(lambda x: '+91 ' + x[:-5] + ' ' + x[-5:], nbs))))


import re
ans = []
for x in range(int(input())):
	r = re.match('^\\+?(\\d{0,2})(\\d{5})(\\d{5})$', input())
	if r:
		ans.append('+91 ' + r.group(2) + ' ' + r.group(3))
print('\n'.join(sorted(ans)))


N = int(input())
M = [input() for _ in range(N)]

def standardize(func):

	def sf(M):
		M = ['+91 ' + m[len(m) - 10:len(m) - 5] + ' ' + m[len(m) - 5:] for m in M]
		return func(M)
	return sf
ss = standardize(sorted)
for m in ss(M):
	print(m)


def clean(s):
	return s[-10:]

def form(s):
	return '+91 ' + s[:5] + ' ' + s[5:]
num = int(input())
lst = []
for i in range(num):
	lst.append(clean(input()))
lst = sorted(lst)
for s in lst:
	print(form(s))


def mobileformat(s):
	s = s[:5] + ' ' + s[5:]
	s = '+91 ' + s
	return s

def mobile(m):
	t = m.strip()[-10:]
	return t
n = int(input())
ml = []
for i in range(n):
	ml.append(int(mobile(input())))
ml.sort()
mlf = [mobileformat(str(i)) for i in ml]
for i in mlf:
	print(i)


def format_numbers_list_wrapper(func):

	def formatter(numbers):
		for (i, number) in enumerate(numbers):
			if len(number) == 10:
				number = '+91' + number
			elif '91' == number[0:2:1]:
				number = '+' + number
			elif '0' == number[0]:
				number = '+91' + number[1:]
			numbers[i] = '{0} {1} {2}'.format(number[0:3], number[3:8], number[8:])
		return func(numbers)
	return formatter

@format_numbers_list_wrapper
def sort_numbers(numbers):
	numbers.sort()
	return numbers

def main():
	length = int(input())
	numbers = []
	while length > 0:
		numbers.append(input())
		length -= 1
	numbers = sort_numbers(numbers)
	for n in numbers:
		print(n)
main()


num = int(input())
l = []
for i in range(num):
	line = input()
	line = line[len(line) - 10:len(line)]
	l.append(line)
l.sort()
for i in l:
	print('+91 ' + i[0:5] + ' ' + i[5:10])


import sys

def mobile(f):

	def wrapper(*args, **kwargs):
		return f(['+91 {0} {1}'.format(num[-10:-5], num[-5:]) for num in args[0]])
	return wrapper

@mobile
def sort(l):
	return sorted(l)
print('\n'.join(sort([input() for _ in range(int(input()))])))


N = int(input())
lst = []
for x in range(0, N):
	lst.append(input())

def f(num):
	if len(num) == 10:
		return p('+91' + num)
	elif len(num) == 11:
		return p('+91' + num[1:11])
	elif len(num) == 12:
		return p('+' + num)
	else:
		return p(num)

def p(num):
	return num[0:3] + ' ' + num[3:8] + ' ' + num[8:14]
lst1 = []
for x in range(0, N):
	lst1.append(f(lst[x]))
for x in sorted(lst1):
	print(x)


def standardize(number):
	standardized = []
	if len(number) == 10:
		standardized = ['+91', number[0:5], number[5:]]
	elif len(number) == 11:
		assert number[0] == '0'
		standardized = ['+91', number[1:6], number[6:]]
	elif len(number) == 12:
		assert number[:2] == '91'
		standardized = ['+91', number[2:7], number[7:]]
	elif len(number) == 13:
		assert number[:3] == '+91'
		standardized = ['+91', number[3:8], number[8:]]
	return ' '.join(standardized).strip()

def main():
	nonumbers = int(input())
	numbers = []
	for number in range(nonumbers):
		numbers.append(input())
	standardized = sorted(map(standardize, numbers))
	for number in standardized:
		print(number)
main()


l = [input() for _ in range(int(input()))]

def standardize(num):
	if len(num) == 10:
		return num
	if len(num) == 11:
		assert num[0] == '0'
		return num[1:]
	if len(num) == 12:
		assert num[0:2] == '91'
		return num[2:]
	if len(num) == 13:
		assert num[0:3] == '+91'
		return num[3:]
	assert False
l = sorted(map(standardize, l))
[print('+91 %s %s' % (num[:5], num[5:])) for num in l]


def wrapper(func):

	def formatphone(name):
		return ['+91 ' + i[0:5] + ' ' + i[5:10] for i in func(name)]
	return formatphone

@wrapper
def sortphone(numbers):
	numbers = [i[len(i) - 10:] for i in numbers]
	numbers.sort()
	return numbers
num = int(input())
phone = [input() for i in range(0, num)]
for i in sortphone(phone):
	print(i)


n = int(input())
phl = []
for i in range(n):
	phl.append(input()[-10:])
phl.sort()
for ph in phl:
	fp = ph[-10:-5]
	sp = ph[-5:]
	print('+91', fp, sp)


def modify(sNum):
	return '+91 ' + sNum[0:5] + ' ' + sNum[5:]

def wrapper(func):

	def check(slNum):
		sortedList = []
		for item in slNum:
			item = ''.join((ch for ch in item if ch.isalnum()))
			if len(item) > 10:
				sArg = item[-10:]
			else:
				sArg = item
			sortedList.append(sArg)
		sortedList = sorted(sortedList)
		for each in sortedList:
			print(modify(each))
	return check
n = int(input())
foo = wrapper(modify)
slArg = []
for i in range(n):
	s = input()
	slArg.append(s)
foo(slArg)


from sys import stdin

def standardize(number):
	if len(number) == 10:
		return '+91 {0} {1}'.format(number[:5], number[5:])
	if len(number) == 11:
		return '+91 {0} {1}'.format(number[1:6], number[6:])
	if len(number) == 12:
		return '+91 {0} {1}'.format(number[2:7], number[7:])
	if len(number) == 13:
		return '+91 {0} {1}'.format(number[3:8], number[8:])
	return 'WTF'

def main():
	N = int(stdin.readline())
	numbers = []
	for i in range(N):
		numbers.append(standardize(stdin.readline().strip()))
	for curr_num in sorted(numbers):
		print(curr_num)
main()


mn = []
for i in range(int(input())):
	mn.append(input()[-10:])
for s in sorted(mn):
	print('+91', s[:5], s[5:])


def stdformat(num):
	return '+91 ' + num[0:5] + ' ' + num[5:10]
numbers = []
for i in range(int(input())):
	numstr = input()
	if len(numstr) == 10:
		numbers.append(numstr)
	elif numstr[0] == '0':
		numbers.append(numstr[1:])
	elif numstr[0:2] == '91':
		numbers.append(numstr[2:])
	elif numstr[0:3] == '+91':
		numbers.append(numstr[3:])
numbers.sort()
for num in numbers:
	print(stdformat(num))


li = [j[len(j) - 10:] for j in [input() for i in range(int(input()))]]
for k in sorted(li):
	print('+91 ' + k[:5] + ' ' + k[5:10])


import re
n = int(input())
r = re.compile('^\\+?(91|0)?(\\d{5})(\\d{5})$')
numbers = []
for i in range(n):
	line = input().strip()
	numbers.append('+91 {1} {2}'.format(*r.match(line).groups()))
print('\n'.join(sorted(numbers)))


def decorate(s):
	l = []
	if len(s) == 10:
		l = s
		return l
	if len(s) == 11:
		l = s[1:]
		return l
	if len(s) == 12:
		l = s[2:]
		return l
	if len(s) == 13:
		l = s[3:]
		return l

def prog():
	n = int(input())
	x = []
	newlist = []
	for i in range(0, n):
		y = input()
		x = decorate(y)
		newlist.append(x)
	newlist = sorted(newlist)
	for i in range(0, len(newlist)):
		print('+91 ' + str(newlist[i][:5]) + ' ' + str(newlist[i][5:]))
prog()


def deco(func):

	def wrapper(number):
		if len(number) == 10:
			return func('+91 ' + number[:5] + ' ' + number[5:])
		elif len(number) == 11:
			return func('+91 ' + number[1:6] + ' ' + number[6:])
		elif len(number) == 12:
			return func('+91 ' + number[2:7] + ' ' + number[7:])
		else:
			return func('+91 ' + number[3:8] + ' ' + number[8:])
	return wrapper

@deco
def sort_key(number):
	return number
n = int(input())
numbers = []
for i in range(n):
	numbers.append(input())
numbers = [sort_key(item) for item in numbers]
numbers = sorted(numbers, key=sort_key)
for item in numbers:
	print(item)


class PhoneNumber:

	def __init__(self, phoneNumber):
		if len(phoneNumber) == 10:
			self.formatedNumer = self.formatPhone('91', phoneNumber[0:5], phoneNumber[5:10])
		elif len(phoneNumber) == 11:
			self.formatedNumer = self.formatPhone('91', phoneNumber[1:6], phoneNumber[6:])
		elif len(phoneNumber) == 12:
			self.formatedNumer = self.formatPhone(phoneNumber[0:2], phoneNumber[2:7], phoneNumber[7:])
		else:
			self.formatedNumer = self.formatPhone(phoneNumber[1:3], phoneNumber[3:8], phoneNumber[8:])

	def formatPhone(self, region, a, b):
		return '+{0} {1} {2}'.format(region, a, b)

	def __str__(self):
		return self.formatedNumer

	def __repr__(self):
		return self.__str__()
phones = []
[phones.append(PhoneNumber(input())) for x in range(int(input()))]
[print(x) for x in sorted(phones, key=lambda y: y.formatedNumer)]


def normalize(f):

	def deco(x):
		result = []
		for i in x:
			if i[:1] == '0' and len(i) == 11:
				i = i[1:]
			elif i[:2] == '91' and len(i) == 12:
				i = i[2:]
			elif i[:3] == '+91' and len(i) == 13:
				i = i[3:]
			result.append('+91 %s %s' % (i[:5], i[5:]))
		return f(result)
	return deco

@normalize
def sort(x):
	return sorted(x)
print('\n'.join(sort((input() for _ in range(int(input()))))))


def deco(s):
	if len(s) < 10:
		return ''
	num = ''
	if s[0] == '0' and len(s) == 11:
		num = '+91 ' + s[1:6] + ' ' + s[6:11]
	elif s[0] == '9' and s[1] == '1' and (len(s) >= 12):
		num = '+' + s[0:2] + ' ' + s[2:7] + ' ' + s[7:12]
	elif len(s) == 10:
		num = '+91 ' + s[0:5] + ' ' + s[5:10]
	elif s[0] == '+' and s[1] == '9' and (s[2] == '1') and (len(s) == 13):
		num = s[0:3] + ' ' + s[3:8] + ' ' + s[8:13]
	else:
		return ''
	return num
N = int(input())
numbers = list()
for n in range(N):
	n = input()
	n = deco(n)
	if len(n) > 0:
		numbers.append(n)
numbers.sort()
for x in numbers:
	print(x)


def standardize(numbers):
	i = 0
	for num in numbers:
		if num[0] == '+':
			numbers[i] = num[0:3] + ' ' + num[3:8] + ' ' + num[8:]
		elif num[0] == '0':
			numbers[i] = '+91' + ' ' + num[1:6] + ' ' + num[6:]
		elif num[0:2] == '91' and len(num) > 10:
			numbers[i] = '+' + num[0:2] + ' ' + num[2:7] + ' ' + num[7:]
		elif num[0:2] == '91' and len(num) == 10:
			numbers[i] = '+91' + ' ' + num[0:5] + ' ' + num[5:]
		else:
			numbers[i] = '+91' + ' ' + num[0:5] + ' ' + num[5:]
		i += 1

def sortArr(num):
	num.sort()
	for n in num:
		print(n)
num = int(input())
count = 0
mylist = []
while count < num:
	mylist.append(str(input()))
	count += 1
standardize(mylist)
sortArr(mylist)


N = int(input())

def stand(i):
	for num in i:
		yield '+91 {} {}'.format(num[-10:-5], num[-5:])
for num in sorted(stand((input() for i in range(N)))):
	print(num)


t = int(input())
a = []
for test in range(0, t):
	x = str(input())
	m = len(x)
	x = int(x[m - 10:m])
	x = x % 10000000000
	a += [x]
a.sort()
for x in a:
	y = int(x / 100000)
	z = x % 100000
	print('+91', y, z, sep=' ')


def printer(lis):
	lis = sorted(lis)
	for x in lis:
		print('+91 ' + x[:5] + ' ' + x[5:])
num = int(input())
lis = []
for i in range(0, num):
	numb = input()
	if len(numb) == 10:
		lis.append(numb)
	elif len(numb) == 11:
		lis.append(numb[1:])
	elif len(numb) == 12:
		lis.append(numb[2:])
	elif len(numb) == 13:
		lis.append(numb[3:])
printer(lis)


t = int(input())
newlist = []
while t > 0:
	t -= 1
	s = input()
	if len(s) == 10:
		mylist = list(s)
		mylist.insert(5, ' ')
		s = ''.join((str(x) for x in mylist))
		s = '+91 ' + s
		newlist.append(s)
	elif len(s) == 11:
		mylist = list(s)
		del mylist[0]
		mylist.insert(5, ' ')
		s = ''.join((str(x) for x in mylist))
		s = '+91 ' + s
		newlist.append(s)
	elif len(s) == 12:
		mylist = list(s)
		del mylist[0]
		del mylist[0]
		mylist.insert(5, ' ')
		s = ''.join((str(x) for x in mylist))
		s = '+91 ' + s
		newlist.append(s)
	elif len(s) == 13:
		mylist = list(s)
		mylist.insert(8, ' ')
		s = ''.join((str(x) for x in mylist))
		mylist = list(s)
		mylist.insert(3, ' ')
		s = ''.join((str(x) for x in mylist))
		newlist.append(s)
newlist.sort()
for i in range(0, len(newlist), 1):
	print(newlist[i])


N = int(input())
num = []
for n in range(N):
	num.append(input()[-10:])
num.sort()
for n in num:
	print('+91', n[:5], n[5:])


def decorate(s):

	def add_91():
		return '+91' + ' ' + s[0:5] + ' ' + s[5:len(s)]
	return add_91
N = int(input())
l = []
while N > 0:
	n = input()
	l.append(n[len(n) - 10:len(n)])
	N -= 1
l.sort()
for i in l:
	w = decorate(i)
	print(w())


t = int(input())
l = []
while t > 0:
	n = input()
	l.append(n[-10:])
	l.sort()
	t = t - 1
for i in l:
	print('+91 ' + i[:5] + ' ' + i[5:len(i)])


import re
n = int(input())
lis = []
for x in range(n):
	number = input()
	match = re.findall('0(\\d\\d\\d\\d\\d)(\\d\\d\\d\\d\\d)', number)
	if len(match) == 1:
		lis.append('+91 ' + match[0][0] + ' ' + match[0][1])
		continue
	match = re.findall('\\+91(\\d\\d\\d\\d\\d)(\\d\\d\\d\\d\\d)', number)
	if len(match) == 1:
		lis.append('+91 ' + match[0][0] + ' ' + match[0][1])
		continue
	match = re.findall('91(\\d\\d\\d\\d\\d)(\\d\\d\\d\\d\\d)', number)
	if len(match) == 1:
		lis.append('+91 ' + match[0][0] + ' ' + match[0][1])
		continue
	match = re.findall('(\\d\\d\\d\\d\\d)(\\d\\d\\d\\d\\d)', number)
	if len(match) == 1:
		lis.append('+91 ' + match[0][0] + ' ' + match[0][1])
		continue
lis = sorted(lis)
for index in range(len(lis)):
	print(lis[index])


l = []
for t in range(int(input())):
	inp = input()
	a = len(inp)
	l.append('+91 ' + inp[a - 10:a - 5] + ' ' + inp[a - 5:])
l.sort()
for i in l:
	print(i)


N = int(input())
number_list = []
for i in range(0, N):
	number_list.append(input())
phone_numbers = []
for number in number_list:
	if len(number) == 11:
		phone_numbers.append(int(number[1:]))
	elif len(number) == 12:
		phone_numbers.append(int(number[2:]))
	elif len(number) == 13:
		phone_numbers.append(int(number[3:]))
	else:
		phone_numbers.append(int(number))
phone_numbers = sorted(phone_numbers)
for phone in phone_numbers:
	ph = str(phone)
	print('+91', ph[0:5], ph[5:10])


l = []
for i in range(int(input())):
	s = input().strip()
	numb = s[-10:]
	l.append(numb)
l.sort()
for numb in l:
	print('+91', numb[:5], numb[5:10])


N = int(input())
a = []
for i in range(0, N):
	n = input()
	l = len(n)
	if l != 10:
		b = n[l - 1:l - 11:-1]
		b = b[::-1]
	else:
		b = n
	a.append(b)
a = sorted(a)
for i in range(0, N):
	print('+91 ' + a[i][0:5] + ' ' + a[i][5:])


input_buffer = [input() for i in range(int(input()))]

def format_wrap(func):

	def wrapper_func(list_obj):
		new_list = []
		for num in list_obj:
			new_list.append('+91 ' + str(num[-10:-5]) + ' ' + str(num[-5:]))
		new_list = func(new_list)
		return new_list
	return wrapper_func

@format_wrap
def sort_numbers(num_list):
	return sorted(num_list)
output_buffer = sort_numbers(input_buffer)
for x in output_buffer:
	print(x)


n = int(input())
numbers = []
for i in range(n):
	number = input()
	if len(number) == 13:
		numbers.append(number)
	elif len(number) == 12:
		numbers.append('+' + number)
	elif len(number) == 11:
		numbers.append('+91' + number[1:])
	else:
		numbers.append('+91' + number)

def format(s):
	return '{} {} {}'.format(s[:3], s[3:8], s[8:])
for n in sorted(numbers):
	print(format(n))


import re
i = int(input())

def dowork(numbers):
	numbers.sort()
	for num in numbers:
		print('\n'.join([num]))

def phonenum(some_func):

	def numcheck(n):
		for j in range(0, len(n)):
			if len(n[j]) == 10:
				n[j] = '+91' + n[j]
			else:
				i = len(n[j])
				n[j] = '+91' + n[j][i - 10:i]
			n[j] = n[j][0:3] + ' ' + n[j][3:8] + ' ' + n[j][8:13]
		return some_func(n)
	return numcheck
numbers = []
for x in range(0, i):
	numbers += [input()]
dowork = phonenum(dowork)
dowork(numbers)


t = int(input())
l = []
for i in range(t):
	temp = input()
	temp2 = temp[len(temp) - 10:]
	l.append(int(''.join(temp2)))
l.sort()
for i in range(t):
	temp = str(l[i])
	print('+91 ' + temp[0:5] + ' ' + temp[5:])


(a, T) = ([], int(input()))
for _ in range(T):
	x = input().strip()
	a.append(x[len(x) - 10:])
for x in sorted(a):
	print('+91', x[0:5], x[5:])