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



Sample input:
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18


Sample output:
document
13
easy
9
even
18 25
introduction
3
style
7 12 21

Submission status: Wrong Answer

Solution code:
dic = {}
while True:

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

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

Submission status: Wrong Answer

Solution code:
dic = {}
while True:

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

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

Submission status: Wrong Answer

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

    if word in dic.keys():
        dic[word].append(int(pgn))
    else:
        dic[word] = [int(pgn)]
for k, v in dic.items():
    print(k)
    print(' '.join(map(str, sorted(v))))

Submission status: Wrong Answer

Solution code:
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 dic.items():
    print(k)
    print(' '.join(map(str, sorted(v))))

Submission status: Wrong Answer

Solution code:
import sys
a={}
for i in sys.stdin:
	b,c=i.split()
	a.setdefault(b, []).append(c)
	if c=='18':break
for a,b in sorted(a.items(), key=lambda x: x[0]):
    print(a)
    print(*b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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)
  print(" ".join(d[i]))

Submission status: Wrong Answer

Solution code:
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, v))

Submission status: Wrong Answer

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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)))

Submission status: Accepted

Solution code:
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]

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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]))))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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))))))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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))))

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
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:])

Submission status: Accepted

Solution code:
# Aizu Problem 0105: Book Index
#
import sys, math, os

# read input:
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])]))

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
import sys
#from me.io import dup_file_stdin

#@dup_file_stdin
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()

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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("")

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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]))))

Submission status: Accepted

Solution code:
# AOJ 0105 Book Index
# Python3 2018.6.17 bal4u

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])))

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:
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

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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]

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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])))

Submission status: Accepted

Solution code:

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))

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
#!/usr/bin/env 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()

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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]) )

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    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

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

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

    ### Mat Multiplication
    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()

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

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

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

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

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())
            #N.append(int(input()))
            #N.append(float(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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	dic = {}

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

#	print(dic)

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