Title: Transactions

There is data recording customer numbers and transaction dates for each month. Create a program that reads the data for the current month and the previous month, and outputs the customer numbers and the number of transactions for companies that had transactions for two consecutive months, sorted by customer number. The number of transaction partners each month is within 1,000 companies.

Input:
The data for the current month and the previous month are given separated by an empty line. Each data is given in the following format:
c1,d1
c2,d2
...

Where ci (1 ≤ ci ≤ 1,000) is an integer representing the customer number, and di (1 ≤ di ≤ 31) is an integer representing the transaction date.

Output:
For companies with transactions in two consecutive months, output the customer number and the total number of transactions separated by a space, sorted in ascending order of customer number.

Sample Input:
123,10
56,12
34,14

123,3
56,4
123,5

Output for the Sample Input:
56 2
123 3

# Buggy version:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0065
"""
import sys
from collections import Counter


def analyze_data(this_month, last_month):
    result = []
    tm = Counter(this_month)
    lm = Counter(last_month)

    for ele in lm:
        if ele in tm:
            c = lm[ele] + tm[ele]
            result.append([ele, c])
    return result



def main(args):
    this_month = []
    last_month = []
    month = this_month
    for line in sys.stdin:
        if len(line) == 1:      #  ??\??????????????????
            month = last_month
        else:
            id, date = line.strip().split(',')
            month.append(id)
    #this_month = [123, 56, 34]
    #last_month = [123, 56, 123]
    result = analyze_data(this_month, last_month)
    result.sort()

    for d in result:
        print('{} {}'.format(d[0], d[1]))


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

# Fixed version:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0065
"""
import sys
from collections import Counter


def analyze_data(this_month, last_month):
    result = []
    tm = Counter(this_month)
    lm = Counter(last_month)

    for ele in lm:
        if ele in tm:
            c = lm[ele] + tm[ele]
            result.append([ele, c])
    result.sort()
    return result



def main(args):
    this_month = []
    last_month = []
    month = this_month
    for line in sys.stdin:
        if len(line) == 1:      #  ??\??????????????????
            month = last_month
        else:
            id, date = line.strip().split(',')
            month.append(int(id))
    # this_month = [1, 123, 56, 34, 23, 1, 23]
    # last_month = [123, 56, 123, 123, 1, 777, 777, 777]
    result = analyze_data(this_month, last_month)

    for d in result:
        print('{} {}'.format(d[0], d[1]))


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

# Buggy version:
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c_=e.split(',');c=int(c);a[b].setdefault(c,0);a[b][c]+=1
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])


# Fixed version:
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c,_=e.split(',');c=int(c);a[b].setdefault(c,0);a[b][c]+=1
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])