Problem:
Book Index Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers. You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once. The words should be printed in alphabetical order and the page numbers should be printed in ascending order. Input  word page_number :
    : Output  word  a_list_of_the_page_number  word  a_list_of_the_Page_number :
      : Sample Input style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18 Output for the Sample Input document
13
easy
9
even
18 25
introduction
3
style
7 12 21

Solution (Python):
dic = {}
while True:
    try:
        word, page = map(str,raw_input().split())
        if word in dic:
            dic[word].append(int(page))
        else:
            dic[word] = [int(page)]
    except:
        for word in sorted(dic):
            print word
            for page in sorted(dic[word]):
                print page,
            print
        break

Solution (Python):
import sys

d={}
for s in sys.stdin:
  w,p=s.split()
  if w in d: d[w].append(int(p))
  else: d[w]=[int(p)]
  
for w in sorted(d.keys()):
  print w
  print " ".join(map(str,sorted(d[w])))

Solution (Python):
import sys

d={}
for s in sys.stdin:
  w,p=s.split()
  if w in d: d[w].append(int(p))
  else: d[w]=[int(p)]
  
for w,x in sorted(d.items()):
  print w
  print " ".join(map(str,sorted(x)))

Solution (Python):
d = {}
while True:
    try:
        w, n = input().split()
        n = int(n)
        temp = d.get(w, [])
        temp.append(n)
        d[w] = temp
    except:
        key = list(d.keys())
        key.sort()
        for k in key:
            print(k)
            d[k].sort()
            for n in range(len(d[k])):
                if n != 0: print(' ', end='')
                print(d[k][n], end='')
            print('')
        break

Solution (Python):
d = {}
while True:
    try:
        w, n = input().split()
        n = int(n)
        if w in d: d[w].append(n)
        else: d[w] = [n]
    except:
        for k in sorted(d):
            print(k)
            print(" ".join(map(str,sorted(d[k]))))
        break

Solution (Python):
dic = {}
while True:

    try:
        word,PageNum = raw_input().split()
        if word not in dic:
            dic[word] = []
            dic[word].append(int(PageNum))
        else:
            dic[word].append(int(PageNum))
    except:
        break

for k,v in sorted(dic.items()):
    print  k
    print " ".join(map(str,sorted(v)))

Solution (Python):


d = {}
while True:
    try:
        w, p = input().split()
    except:
        break

    try:
        d[w].add(int(p))
    except:
        d[w] = set()
        d[w].add(int(p))

l = list(d.keys())
l.sort()
for i in l:
    print(i)
    a = list(d[i])
    a.sort()
    print(" ".join(map(str, a)))

Solution (Python):
dic = {}

while 1:
	try:
		name, page = raw_input().split()
		page = int(page)
		
		if dic.get(name):
			dic[name] += [page]
		else:
			dic[name] = [page]
	except:
		break

dic = sorted(dic.items())

for name, page in dic:
	page.sort()
	print name
	for i in range(len(page) - 1):
		print page[i],
	
	print page[-1]

Solution (Python):
dict = {}
while True:
    try:
        word, page = raw_input().split()
        if dict.has_key(word):
            dict[word].append(int(page))
        else:
            dict[word] = [int(page)]
    except:
        break

for k, v in sorted(dict.items()):
    print k
    print " ".join(map(str, sorted(v)))

Solution (Python):
import sys

dic = {}
for line in sys.stdin:
    s, p = line.rstrip().split(' ')
    if not s in dic:
        dic[s] = [p]
    else:
        dic[s].append(p)
else:
    for k, v in sorted(dic.items()):
        v.sort(key=int)
        print k
        print ' '.join(v)

Solution (Python):
dict = {}

while True:
	try:
		a,b = map(str,raw_input().split())
	except EOFError:
		break
	
	if a in dict:
		dict[a].append(int(b))
	else:
		dict[a] = [int(b)]
	
for var in dict:
	dict[var].sort()

dic = list(dict.keys())
dic.sort()

for var in dic:
	print var
	for i in xrange(len(dict[var])):
		print dict[var][i],
	print

Solution (Python):
d  = {}
l = []
while True:
  try:
    s,n = input().split()
    if s in d:
      d[s].append(int(n))
    else:
      d[s] = [int(n)]
      l.append(s)
  except:
    break
l.sort()
for s in l:
  print(s)
  d[s].sort()
  d[s] = [str(s) for s in d[s]]
  print(' '.join(d[s]))

Solution (Python):



import array
import bisect
import collections
import sys


if __name__ == "__main__":
    pre_dict = collections.defaultdict(lambda: array.array("I"))
    for line in sys.stdin:
        [word, page0] = line.split()
        page = int(page0)
        bisect.insort(pre_dict[word], page)
    sorted_dict = collections.OrderedDict(sorted(pre_dict.items(), key=lambda i: i[0]))
    for k, v in sorted_dict.items():
        print(k)
        print(*v)

Solution (Python):
s={}
j=[]

while 1:
    try:
        n,k=map(str,raw_input().split())
        if s.has_key(n):
            s[n].append(int(k))
        else:
            s[n]=[int(k)]
            j.append(n)
    except:
        break
j.sort()
for i in j:
    print i
    s[i].sort()
    print ' '.join(map(str,s[i]))

Solution (Python):
import sys
dic = {}
for s in sys.stdin:
    arr = s.split()
    if arr[0] in dic:
        a = dic[arr[0]]
        dic[arr[0]] = a + [int(arr[1])]
    else:
        dic[arr[0]] = [int(arr[1])]
for i in sorted(dic):
    print(i)
    a = sorted(dic[i])
    for j in range(len(a)):
        if j != len(a)-1:
            print(a[j], end=" ")
        else:
            print(a[j])

Solution (Python):
import sys
def line():return sys.stdin.readline().strip()

I = {}
while True:
    try:
        a,b = line().split()
        b = int(b)
        if a in I:
            I[a].append(b)
        else:
            I[a] = [b]
    except:
        break
for k in sorted(I):
    print(k)
    print(" ".join(map(str,sorted(I[k]))))

Solution (Python):
def main():
    book_index = {}
    while True:
        try:
            word, page = input().split(' ')
            page = int(page)
            page_list = book_index.get(word)
            if page_list:
                page_list.append(page)
            else:
                book_index[word] = [page]
        except Exception:
            break

    for k in sorted(book_index.keys()):
        print(k)
        print(' '.join(map(str, (sorted(book_index.get(k))))))


if __name__ == '__main__':
    main()

Solution (Python):
book_index = {}
while True:
    try:
        word, page = input().split(' ')
        page = int(page)
        page_list = book_index.get(word)
        if page_list:
            page_list.append(page)
        else:
            book_index[word] = [page]
    except Exception:
        break

for k in sorted(book_index.keys()):
    print(k)
    print(' '.join(map(str, (sorted(book_index.get(k))))))

Solution (Python):
import sys

d = {}

for i in sys.stdin.readlines():
    s, n = i.split()
    if s in d:
        d[s].append(int(n))
    else:
        d[s] = [int(n)]

d = sorted(d.items())
for i in d:
    print(i[0])
    print(*sorted(i[1]))

Solution (Python):
import sys
dictionary = {}
for i in sys.stdin.readlines():
	word, page = i.split()
	if word in dictionary:
		dictionary[word].append(int(page))
	else:
		dictionary[word] = [int(page)]
dictionary = sorted(dictionary.items()) 
for i in dictionary:
	print(i[0]) 
	print(*sorted(i[1]))

Solution (Python):
dic = {}
while True:
    try:
        word, pgn = input().split()

        if word in dic.keys():
            dic[word].append(int(pgn))
        else:
            dic[word] = [int(pgn)]
    except:
        break

for k, v in sorted(dic.items()):
    print(k)
    print(' '.join(map(str, sorted(v))))

Solution (Python):
Date_lis = []
W_lis = []
while True:
    try:
        s,n = map(str,input().split())

        if s in W_lis:
            Date_lis[W_lis.index(s)][1].append(int(n))
        else:
            Date_lis.append([s,[int(n)]])
            W_lis.append(s)
        
    except :
        Date_lis = sorted(Date_lis)
        for i in range(len(Date_lis)):
            print(Date_lis[i][0])
            Num = sorted(Date_lis[i][1])
            for j in range(len(Date_lis[i][1]) - 1):
                
                print(Num[j],end = " ")
            print(Num[len(Date_lis[i][1]) - 1])
        
        break

Solution (Python):
c={}
while 1:
    try:
        a,b=input().split()
        if a in c.keys():c[a].append(int(b))
        else: c[a]=[int(b)]
    except:
        for i,j in sorted(c.items()):
            print(i)
            print(' '.join(map(str,sorted(j))))
        break

Solution (Python):
c={}
while 1:
    try:
        a,b=input().split()
        if a in c:c[a].append(int(b))
        else: c[a]=[int(b)]
    except:
        for i,j in sorted(c.items()):
            print(i)
            print(*sorted(j))
        break

Solution (Python):
data = []
while True:
    try:
        data.append(input())
    except EOFError:
        break

d = {}
for i in range(len(data)):
    i,n = data[i].split()
    if i in d:
        d[i].append(n)
    else:
        d[i] = [n]
d = sorted(d.items(), key = lambda x:x[0])
for i in range(len(d)):
    i,n = d[i]
    n = map(int,n)
    print(i)
    n = sorted(n)
    for i in range(len(n)-1):
        print(n[i], end = ' ')
    print(n[-1])

Solution (Python):


import sys
import os
from collections import defaultdict

d = defaultdict(list)

for s in sys.stdin:
    lst = s.split()
    word = lst[0]
    page = int(lst[1])
    d[word].append(page)

keys = list(d.keys())
keys.sort()
for key in keys:
    print(key)
    pages = d[key]
    pages.sort()
    print(*pages)

Solution (Python):
index = {}
while True:
  try:
    word,page = input().split()
    page = int(page)
    index[word].append(page)
  except KeyError:
    index[word] = [page]
  except EOFError:
    break

for (key,value) in sorted(index.items()):
  print(key)
  value = list(map(str,sorted(value)))
  print(" ".join(value))

Solution (Python):
import sys
a={}
for i in sys.stdin:
	b,c=i.split()
	a.setdefault(b, []).append(c)
for a,b in sorted(a.items(), key=lambda x: x[0]):
    print(a)
    print(*sorted(map(int,b)))

Solution (Python):
d = {}
while True:
    try:
        word, page = input().split()
        page = int(page)
    except:
        break
    d[word] = [page] if word not in d else d[word] + [page]
for word, pages in sorted(d.items()):
    print(word)
    print(*sorted(pages))

Solution (Python):

"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0105&lang=jp
"""
import sys


def compile_index(dict, word, page):
    if word in dict:
        temp = dict[word]
        temp.append(page)
        temp.sort()
        dict[word] = temp
    else:
        temp = [page]
        dict[word] = temp


def main(args):
    index = {}
    for line in sys.stdin:
        word, page = line.strip().split(' ')
        page = int(page)
        compile_index(index, word, page)

    result = []
    for k, v in index.items():
        result.append((k, v))
    result.sort()
    for ele in result:
        print(ele[0])
        print(*ele[1])



if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):


import sys, math, os


PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


index = {}
for line in sys.stdin:
    word, page = line.split()
    if word not in index:
        index[word] = []
    index[word].append(int(page))

for word in sorted(index.keys()):
    print(word)
    print(' '.join([str(page) for page in sorted(index[word])]))

Solution (Python):
import sys

dic = {}
while True:
	try:
		a,b = map(str,input().split())
		page = int(b)

		if a not in dic:
			dic[a] = [page]
		else:
			dic[a].append(page)

	except EOFError:
		names = sorted(dic.keys())
		for i in range(len(names)):
			print(names[i])
			pages = sorted(dic[names[i]])
			for j in range(len(pages)):
				if j == len(pages)-1:
					print(pages[j])
				else:
					sys.stdout.write(str('{:} '.format(pages[j])))
		break

Solution (Python):
import sys



def solve():
    index = dict()
    for line in sys.stdin:
        word,page = line.split(' ')
        pages = index.get(word,list())
        pages.append(int(page))
        index[word] = pages
    keys = list(index.keys())
    keys.sort()
    for key in keys:
        print(key)
        pages = index[key]
        pages.sort()
        print(" ".join(map(str,pages)))
solve()

Solution (Python):
import sys

l = []
for input in sys.stdin:
    l.append(input.split())
l = sorted(l)
for i in range(0,len(l)-1):
    for j in range(i+1,len(l)):
        if(l[i][0] == l[j][0]):
            l[i].append(l[j][1])
res = []
for i in range(0,len(l)):
    if(l[i][0] == l[i-1][0]):
        continue
    res.append(l[i])
for i in range(0,len(res)):
    print res[i][0]
    temp = []
    for j in range(1,len(res[i])):
        temp.append(int(res[i][j]))
    temp = sorted(temp)
    for j in range(0,len(temp)):
        print temp[j],
    print

Solution (Python):
d = {}
while True:
    try:
        data = input().split()
    except:
        break
    word = data[0]
    number = int(data[1])
    if word in d:
        d[word].append(number)
    else:
        d[word] = [number]

for k, v in sorted(d.items(), key=lambda x: x[0]):
    print(k)
    print(*sorted(v))

Solution (Python):
import sys

dictionary = {}

for line in sys.stdin:
    line = line[:-1]

    word, page = line.split(" ")
    page = int(page)

    if word in dictionary:
        dictionary[word].append(page)
    else:
        dictionary[word] = [page]

keys = list(dictionary)
keys.sort()

output = []

for key in keys:
    output.append(key)
    pages = sorted(dictionary[key])
    pages = [str(item) for item in pages]
    pages = " ".join(pages)
    output.append(pages)

print("\n".join(output))

Solution (Python):
import sys
d={}
for e in sys.stdin:
 k,v=e.split()
 d.setdefault(k,[])
 d[k]+=[int(v)]
for k in sorted(d):
 print(k)
 print(*sorted(d[k]))

Solution (Python):
import sys
d={}
for e in sys.stdin:
 k,v=e.split()
 if k in d:d[k]+=[int(v)]
 else:d[k]=[int(v)]
for k in sorted(d):
 print(k)
 print(*sorted(d[k]))

Solution (Python):
import sys
d={}
for e in sys.stdin:
 k,v=e.split()
 if k not in d:d[k]=[]
 d[k]+=[int(v)]
for k in sorted(d):
 print(k)
 print(*sorted(d[k]))

Solution (Python):
import sys
d={}
for e in sys.stdin:
 k,v=e.split()
 d.setdefault(k,[]).append(int(v))
for k in sorted(d):
 print(k)
 print(*sorted(d[k]))

Solution (Python):
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
N.sort()

N1,N2 = N[0].split()
word = N1
pnum = []
pnum.append(int(N2))

for l in range(1, len(N)):
    N1,N2 = N[l].split()

    if word != N1:
        print(word)
        pnum.sort()
        print(pnum[0], end="")
        for i in range(1, len(pnum)):
            print(" ", end="")
            print(pnum[i], end="")
        print("")
        word = N1
        pnum.clear()
        pnum.append(int(N2))
    else:
        pnum.append(int(N2))

print(word)
pnum.sort()
print(pnum[0], end="")
for i in range(1, len(pnum)):
    print(" ", end="")
    print(pnum[i], end="")
print("")

Solution (Python):
dic = {}

while True:
  try:
    s, i = input().split()
    if s in dic:
      dic[s].append(int(i))
    else:
      dic[s] = [int(i)]

  except EOFError:
    break

for k, v in sorted(dic.items()):
  print(k)
  print(*sorted(v))

Solution (Python):
import sys
l=[i.split() for i in sys.stdin]
d={}
for i in l:
  if i[0] not in d:
    d[i[0]]=[i[1]]
  else:
    d[i[0]].append(i[1])
for i in sorted(d.keys()):
  print(i)
  d[i]=list(map(int,d[i]))
  print(" ".join(map(str,sorted(d[i]))))

Solution (Python):



from collections import defaultdict
index = defaultdict(list)

while True:
	try: w, p = list(input().split())
	except EOFError: break
	index[w].append(p)

index = dict(sorted(index.items()))
for x in index:
	print(x)
	print(*sorted(map(int, index[x])))

Solution (Python):
import sys

dictionary = dict()

for line in sys.stdin.readlines():
    line = line.strip()
    word, num = line.split()
    if not dictionary.has_key(word):
        dictionary[word] = list()
    dictionary[word].append(int(num))

for key in sorted(dictionary.keys()):
    print key
    print " ".join(map(str, sorted(dictionary[key])))

Solution (Python):
import sys
R = lambda:map(int,raw_input().split())
d = {}
while 1:
    try:
        s,p = raw_input().split()
        p = int(p)
        if not d.has_key(s):
            d[s] = set()
        d[s].add(p)
            
    except EOFError:
        break


for k in sorted(d.iterkeys()):
    print k
    print " ".join(str(s) for s in sorted(d[k]))

Solution (Python):
hoge = {} ; teki=[]
while True:
  try:
    a,b = raw_input().split()
    if a not in hoge:
      hoge[a] = [int(b)]
    elif a in hoge:
      hoge[a].append(int(b))
  except EOFError: 
    for j in sorted(hoge):
      print j
      ans = len(hoge[j])
      aaa =sorted(hoge[j])
      for i in range(ans): print aaa[i],
      print 
    break

Solution (Python):
hoge = {} ; teki=[]
while True:
  try:
    a,b = raw_input().split()
    if a not in hoge:
      hoge[a] = [int(b)]
    elif a in hoge:
      hoge[a].append(int(b))
  except EOFError: 
    for j in sorted(hoge):
      print j
      ans = len(hoge[j])
      aaa =sorted(hoge[j])
      for i in range(ans): print aaa[i],
      print 
    break

Solution (Python):
from collections import defaultdict
dic=defaultdict(list)
while True:
    try:
        word,page=raw_input().split()
        dic[word].append(int(page))
    except EOFError:
        break;

for word in sorted(dic):
    print word
    dic[word].sort()
    for i in range(len(dic[word])-1):
        print dic[word][i],
    print dic[word][-1]

Solution (Python):
from collections import defaultdict
dic=defaultdict(list)
while True:
    try:
        w,p=raw_input().split()
        dic[w].append(int(p))
    except EOFError:
        for w in sorted(dic):
            print w
            dic[w].sort()
            print " ".join(map(str,dic[w]))
        break

Solution (Python):
idx = {}
while True:
    try:
        data = raw_input().split();
        if data[0] in idx:
            idx[data[0]].append(int(data[1]))
        else:
            idx[data[0]] = [int(data[1])]
    except (EOFError):
        break

for word in sorted(list(idx)):
    print word
    for page in sorted(idx[word]):
        print page,
    print

Solution (Python):
import sys,collections
dic=collections.defaultdict(list)
for line in sys.stdin.readlines():
    w,p=line.strip().split()
    dic[w].append(p)
for w in sorted(dic):
    print w
    print " ".join(sorted(dic[w],key=int))

Solution (Python):
import collections
d = collections.defaultdict(list)
while 1:
    try:
        w, p = raw_input().split()
        d[w].append(int(p))
    except EOFError:
        break
for w in sorted(d):
    print w
    print ' '.join(map(str, sorted(d[w])))

Solution (Python):

import sys



index = {}
for line in sys.stdin:
    word, page_num = tuple(line.rstrip('\n').split(' '))
    if word in index:
        index[word].append(int(page_num))
    else:
        index[word] = [int(page_num)]
for k in sorted(index.keys()):
    print k
    pages = index[k]
    pages.sort()
    print ' '.join(map(str, pages))

Solution (Python):
from collections import defaultdict
dic=defaultdict(list)
while True:
    try:
        w,p=raw_input().split()
	dic[w].append(int(p))
    except EOFError:
	for w in sorted(dic):
            print w
            dic[w].sort()
            print " ".join(map(str,dic[w]))
	break

Solution (Python):
import sys
ans = {}
for x in sys.stdin.readlines():
    word, page = x.rstrip().split()
    ans.setdefault(word,[])
    ans[word].append(page)

for k in sorted(ans.keys()):
    print k
    print " ".join(sorted(ans[k], cmp=lambda a,b: int(a)-int(b)))

Solution (Python):

from __future__ import division, print_function
from sys import stdin, exit
from collections import defaultdict


def main():
    index = defaultdict(list)

    for line in stdin:
        word, page = line.split()
        index[word].append(int(page))

    for word in sorted(index):
        print(word)
        print(*sorted(index[word]))
    exit()


if __name__ == '__main__':
    main()

Solution (Python):
index = {}
while True:
    try:
        w, p = map(str, raw_input().split())
        index.setdefault(w,[]).append(int(p))
    except:
        break

for k,v in sorted(index.items()):
   print k
   print " ".join(map(str, sorted(v)))

Solution (Python):
dic = {}
while True:
	try:
		word, page = raw_input().split()
		if word in dic.keys():
			dic[word].append(int(page))
			dic[word].sort()
		else:
			dic[word] = [int(page)]
	except:
		dic = sorted(dic.items(), key=lambda x: x[0])
		for d in dic:
			print d[0]
			print " ".join(map(str, d[1]))
		break

Solution (Python):
dic = {}
while True:
    try:
        key,num = input().split()
        dic.setdefault(key,[]).append(int(num))
    except:
        break

dic = sorted(dic.items())
for tup in dic:
    print(tup[0])
    tup[1].sort()
    for i in tup[1]:
        if i != tup[1][-1]:
            print(i,end=" ")
        else:
            print(i)

Solution (Python):
book = []
while True :
    try :
        A = list(input().split())
    except EOFError :
        break
    
    new_word = "ON"
    for i in range(len(book)) :
        if A[0] in book[i] :
            book[i].append(A[1])
            new_word = "OFF"
    if new_word == "ON" :
        book.append([A[0], A[1]])
    
book.sort()
for i in range(len(book)) :
    print(book[i][0])
    page = list(int(book[i][j]) for j in range(1, len(book[i])))
    print(*sorted(page))

Solution (Python):
D = {}
for line in open(0).readlines():
    w, p = line.split()
    D.setdefault(w, []).append(int(p))
for k, v in sorted(D.items()):
    print(k)
    print(*sorted(v))

Solution (Python):
dic = {}

while(1):
    try:
        key,word = (x for x in input().split())
        dic.setdefault(key, [])
        dic[key].append(word)
    except:
        break

for k in sorted(dic.keys()):
    print(k)
    arr = sorted(dic[k],key=int)
    for i in range(0,len(arr)):
        if i != 0:
            print(" ",end="")
        print(arr[i],end="")
    print()

Solution (Python):
d = dict()
while True:
    try:
        w, n = input().split()
    except:
        break
    n = int(n)
    if d.get(w):
        d[w].append(n)
    else:
        d[w] = []
        d[w].append(n)

for k in sorted(d.keys()):
    print(k)
    print( *sorted(d[k]) )

Solution (Python):
book = {}
while 1:
    try:
        s, n = input().split()
        book.setdefault(s, []).append(int(n))
    except:
        break

book = dict(sorted(book.items()))

for k, v in book.items():
    print(k)
    v.sort()
    print(*v)

Solution (Python):






import sys
import math


class mymath:
    
    pi = 3.14159265358979323846264338

    
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()


class output:
    
    def list(self, l):
        l = list(l)
        
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()






















def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()










def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            
            
        except EOFError:
            break
    return N

D = get_input()

A = {}

for d in D:
    s, p = [x for x in d.split()]
    p = int(p)
    if s in A:
        A[s].append(p)
    else:
        A[s] = [p]

B = sorted(A)

for i in B:
    L = sorted(list(A[i]))
    print(i)
    printA(L)

Solution (Python):
w=[]
while True:
    try:
        s,n=input().split()
    except:
        break
    ch=True
    for i in range(len(w)):
        if w[i][0]==s:
            w[i].append(int(n))
            ch=False
            break
    if ch:
        w.append([s,int(n)])
w.sort()
for i in range(len(w)):
    print(w[i][0])
    p=sorted(w[i][1:])
    print(*p)

Solution (Python):
dic = {}
while True:
    try:
        s, i = input().split()
        if s in dic:dic[s].append(int(i))
        else:dic[s] = [int(i)]
    except:break
for k, v in sorted(dic.items()):
    print(k)
    print(*sorted(v))

Solution (Python):
if __name__ == '__main__':

	dic = {}

	while True:
		try:
			s,n = input().split()
			dic.setdefault(s,[]).append(int(n))
		except EOFError:
			break



	tmp = sorted(list(dic))
	for word in tmp:
		print(word)
		print(*sorted(dic[word]))

Solution (Python):
index={}
while True:
    try:
        word,page=input().split(" ")
        page=int(page)
        tmp=index.get(word,[])
        tmp.append(page)
        index[word]=tmp

    except EOFError:
        break


index=sorted(index.items())
for object in index:
    print(object[0])
    print(" ".join([str(i) for i in sorted(object[1])]))

Solution (Python):
key_list=[]
page_list=[]
while 1:
    try:
        key,page=map(str,input().split())
        if key in key_list:
            page_list[key_list.index(key)].append(int(page))
        else:
            key_list.append(key)
            page_list.append([int(page)])
    except:break
key_list_sort=key_list[:]
key_list_sort.sort()
for i in key_list_sort:
    print(i)
    ans=page_list[key_list.index(i)][:]
    ans.sort()
    print(' '.join(map(str,ans)))

Solution (Python):
dic = {}
while 1:
    try:
        word, page = map(str, input().split())
        page = int(page)
        if word in dic:
            dic[word].append(page)
        else:
            dic[word] = [page]
    except:
        break

for d in sorted(dic):
    print(d)
    print(' '.join(map(str, sorted(dic[d]))))

Solution (Python):
d = {}
while True:
    try:
        w, p = input().split()
        if w in d:
            d[w].append(int(p))
        else:
            d[w] = [int(p)]
    except:
        break
for k in sorted(d.items(), key=lambda x: x[0]):
    print(k[0])
    print(*sorted(k[1]))

Solution (Python):
result = {}
while True:
    try: n = input()
    except: break
    word, number = n.split()
    if word in result:
        result[word].append(number)
    else:
        result[word] = [number]
    
for k, v in sorted(result.items()):
    val = sorted(list(map(int, v)))
    print(k + '\n' + ' '.join(map(str, val)))

Solution (Python):
book = {}
while True:
    a = b = 0
    try:
        a, b = input().split()
        b = int(b)
        if a in book:
            book[a].append(b)
        else:
            book[a] = [b]
    except:
        break
for i, m in sorted(book.items(), key = lambda x: x[0]):
    print(i)
    print(" ".join(str(j) for j in sorted(m)))

Solution (Python):
book = {}
while True:
    try:
        w, n = input().split()
        w = str(w).lower()
        n = int(n)
        if (w not in book.keys()):
            book[w] = [n]
        else:
            book[w] += [n]
    
    except EOFError:
        break
    
W = []
for w, nlist in book.items():
    nlist.sort()
    W.append(w)
W.sort()
for w in W:
    print(w)
    print(*book[w])

Solution (Python):
dic = {}
while(True):
    try:
        key, page = input().split()
        page = int(page)
    except:
        break
    try:
        dic[key].append(page)
    except:
        dic[key] = [page]
a = list(dic.keys())
a.sort()
for b in a:
    print(b)
    print(" ".join(str(e) for e in sorted(dic[b])))