Problem:


取引

取引先の顧客番号と取引日を月ごとに記録したデータがあります。今月のデータと先月のデータを読み込んで、先月から２ヶ月連続で取引のある会社の顧客番号と取引のあった回数を出力するプログラムを作成してください。ただし、月々の取引先数は 1,000 社以内です。

Input

今月のデータと、先月のデータが１行の空行で区切られて与えられます。それぞれのデータは以下のような形式で与えられます。

c1,d1
c2,d2
...
...

ci (1 ≤ ci ≤ 1,000) は顧客番号を表す整数、 di (1 ≤ di ≤ 31) は取引日を表す整数です。

Output

２ヶ月連続で取引のある会社について、顧客番号が小さい順に顧客番号と取引回数の総数を空白で区切って出力します。

Sample Input

123,10
56,12
34,14

123,3
56,4
123,5

Output for the Sample Input

56 2
123 3



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

123,3
56,4
123,5


Sample output:
56 2
123 3

Submission status: Wrong Answer

Solution code:
dict1 = {}
dict2 = {}

while True:
	str = raw_input().split(",")
	
	if len(str[0]) == 0:
		break
	
	if dict1.has_key(str[0]):
		dict1[str[0]] = dict1[str[0]] + 1
	else:
		dict1[str[0]] = 1
	
while True:
	try:
		str = raw_input().split(",")
		
		if dict2.has_key(str[0]):
			dict2[str[0]] = dict2[str[0]] + 1
		else:
			dict2[str[0]] = 1
		
	except:
		break

list = sorted(dict2, reverse = True)
for var in list:
	try:
		dict1[var] = dict1[var] + dict2[var]
		print var, dict1[var]
		
	except:
		break

Submission status: Wrong Answer

Solution code:
dict1 = {}
dict2 = {}

while True:
	str = raw_input().split(",")
	
	if len(str[0]) == 0:
		break
	
	if dict1.has_key(str[0]):
		dict1[str[0]] = dict1[str[0]] + 1
	else:
		dict1[str[0]] = 1
	
while True:
	try:
		str = raw_input().split(",")
		
		if dict2.has_key(str[0]):
			dict2[str[0]] = dict2[str[0]] + 1
		else:
			dict2[str[0]] = 1
		
	except:
		break

list = sorted(dict2)
for var in list:
	try:
		dict1[var] = dict1[var] + dict2[var]
		print var, dict1[var]
		
	except:
		break

Submission status: Wrong Answer

Solution code:
dict1 = {}
dict2 = {}

while True:
	str = raw_input().split(",")
	
	if len(str[0]) == 0:
		break
	
	if dict1.has_key(str[0]):
		dict1[str[0]] = dict1[str[0]] + 1
	else:
		dict1[str[0]] = 1
	
while True:
	try:
		str = raw_input().split(",")
		
		if dict2.has_key(str[0]):
			dict2[str[0]] = dict2[str[0]] + 1
		else:
			dict2[str[0]] = 1
		
	except:
		break

list = sorted(dict2, reverse = True)
for var in list:
	try:
		if(dict1[var] > 0 and dict2[var] > 0):
			print var, dict1[var] + dict2[var]
		
	except:
		break

Submission status: Wrong Answer

Solution code:
dict1 = {}
dict2 = {}

while True:
	str = raw_input().split(",")
	
	if len(str[0]) == 0:
		break
	
	if dict1.has_key(str[0]):
		dict1[str[0]] = dict1[str[0]] + 1
	else:
		dict1[str[0]] = 1
	
while True:
	try:
		str = raw_input().split(",")
		
		if dict2.has_key(str[0]):
			dict2[str[0]] = dict2[str[0]] + 1
		else:
			dict2[str[0]] = 1
		
	except:
		break

list = sorted(set(dict1)&set(dict2), reverse = True)
for var in list:
	try:
		if(dict1[var] > 0 and dict2[var] > 0):
			print var, dict1[var] + dict2[var]
		
	except:
		break

Submission status: Wrong Answer

Solution code:
dict1 = {}
dict2 = {}

while True:
	str = raw_input().split(",")
	
	if len(str[0]) == 0:
		break
	
	if dict1.has_key(str[0]):
		dict1[str[0]] = dict1[str[0]] + 1
	else:
		dict1[str[0]] = 1
	
while True:
	try:
		str = raw_input().split(",")
		
		if dict2.has_key(str[0]):
			dict2[str[0]] = dict2[str[0]] + 1
		else:
			dict2[str[0]] = 1
		
	except:
		break

list = sorted(set(dict1)&set(dict2))
for var in list:
	try:
		if(dict1[var] > 0 and dict2[var] > 0):
			print var, dict1[var] + dict2[var]
		
	except:
		break

Submission status: Wrong Answer

Solution code:
dict1 = {}
dict2 = {}

while True:
	str = raw_input().split(",")
	
	if len(str[0]) == 0:
		break
	
	if dict1.has_key(str[0]):
		dict1[str[0]] = dict1[str[0]] + 1
	else:
		dict1[str[0]] = 1
	
while True:
	try:
		str = raw_input().split(",")
		
		if dict2.has_key(str[0]):
			dict2[str[0]] = dict2[str[0]] + 1
		else:
			dict2[str[0]] = 1
		
	except:
		break

list = sorted(set(dict1)&set(dict2), reverse = True)
for var in list:
	if(dict1[var] > 0 and dict2[var] > 0):
		print var, dict1[var] + dict2[var]

Submission status: Wrong Answer

Solution code:
cnt=0
a,b=[],[]
l={}
while 1:
    try:
        n,k=map(int,raw_input().split(','))
        if l.has_key(n):
            l[n][0]+=1
            if cnt==1:
                l[n][1]=2
        elif cnt==0:
            l[n]=[1,1]
    except:
        cnt+=1
        if cnt>1:
            break
for i in l:
    if l[i][1]==2:
        a.append([l[i][0],i])
a.sort()
for i in a:
    print i[1],i[0]

Submission status: Wrong Answer

Solution code:
import sys
import collections as col

def inp():
    num = []
    for line in sys.stdin:
        try:
            x = map(int, line.split(","))
            num.append(x[0])
        except:
            pass

    element = col.Counter(num)

    for i in xrange(len(element)):
        if element.values()[i] != 1:
            print element.keys()[i], element.values()[i]


if __name__ == "__main__":
    inp()

Submission status: Wrong Answer

Solution code:
data1 = []
while True:
    try:
        c, d = map(int, input().split(","))
    except:
        break
    data1.append([c, d])
cc2, dd2 = [], []
data2 = []
while True:
    try:
        c, d = map(int, input().split(","))
    except:
        break
    data2.append([c, d])
data1.sort(key=lambda x:x[0])
data2.sort(key=lambda x:x[0])
for d1 in data1:
    if d1[0] in [d2[0] for d2 in data2]:
        res = [i[0] for i in data1].count(d1[0]) + [j[0] for j in data2].count(d1[0])
        print(d1[0], res)

Submission status: Wrong Answer

Solution code:
F_mon = []
S_mon = []
while True:
    f_sec = input()
    if f_sec == "":
        break
    c,d = map(int,f_sec.split(","))
    F_mon.append(c)
while True:
    try:
        e,f = map(int,input().split(","))
        S_mon.append(e)
    except:
        for tag in sorted(sorted(F_mon,key = F_mon.index)):
            if tag in S_mon:
                print(tag,F_mon.count(tag) + S_mon.count(tag))
        break

Submission status: Wrong Answer

Solution code:
F_mon = []
S_mon = []
while True:
    f_sec = input()
    if f_sec == "":
        break
    c,d = map(int,f_sec.split(","))
    F_mon.append(c)
while True:
    try:
        e,f = map(int,input().split(","))
        S_mon.append(e)
    except EOFError:
        for tag in sorted(sorted(F_mon,key = F_mon.index)):
            if tag in S_mon:
                print(tag,F_mon.count(tag) + S_mon.count(tag))
        break

Submission status: Wrong Answer

Solution code:
F_mon = []
S_mon = []
while True:
    f_sec = input()
    if f_sec == "":
        break
    c,d = map(int,f_sec.split(","))
    F_mon.append(c)
while True:
    try:
        e,f = map(int,input().split(","))
        S_mon.append(e)
    except:
        for tag in sorted(sorted(F_mon,key = F_mon.index)):
            if tag in S_mon:
                print(tag,F_mon.count(tag) + S_mon.count(tag))
        break

Submission status: Wrong Answer

Solution code:
dt = {}
def loop():
    while True:
        try:
            c, d = map(int, input().split(','))
            dt[c] = [d] if c not in dt else dt[c]+[d]
        except:
            break

loop()
loop()
for ab in sorted(dt.items(), key=lambda x: x[0]):
    a, b = ab[0], ab[1]
    if len(b) > 1:
        print(a, len(b))

Submission status: Wrong Answer

Solution code:
dt = {}
def loop():
    while True:
        try:
            line = input()
            if line == '\n':
                break
            c, d = map(int, line.split(','))
            dt[c] = [d] if c not in dt else dt[c]+[d]
        except:
            break

loop()
loop()
for ab in sorted(dt.items(), key=lambda x: x[0]):
    a, b = ab[0], ab[1]
    if len(b) > 1:
        print(a, len(b))

Submission status: Wrong Answer

Solution code:
ans = {}
while True:
    try:
        line = input()
    except:
        break
    if line != "":
        c, d = map(int, line.split(','))
        ans[c] = 1 if not c in ans else ans[c]+1
for a in sorted(ans.items(), key=lambda x: x[0]):
    if a[1] > 1:
        print(*a)

Submission status: Wrong Answer

Solution code:
ans = {}
while True:
    try:
        line = input()
    except EOFError:
        break
    if line != "":
        c, d = map(int, line.split(','))
        ans[c] = 1 if not c in ans else ans[c]+1
for a in sorted(ans.items(), key=lambda x: x[0]):
    if a[1] > 1:
        print(*a)

Submission status: Wrong Answer

Solution code:
ans = {}
while True:
    try:
        line = input()
    except:
        break
    if line != "":
        c, d = map(int, line.split(','))
        ans[c] = 1 if not c in ans else ans[c]+1
for a in sorted(ans.items(), key=lambda x: x[0]):
    if a[1] > 1:
        print(str(a[0]), str(a[1]))

Submission status: Wrong Answer

Solution code:
ans = {}
def loop():
    while True:
        try:
            c, d = map(int, input().split(','))
            ans[c] = 1 if not c in ans else ans[c]+1
        except:
            break
loop();loop()
for a in sorted(ans.items(), key=lambda x: x[0]):
    if a[1] > 1:
        print(*a)

Submission status: Wrong Answer

Solution code:
ans = {}
flag = 0
while True:
    try:
        c, d = map(int, input().split(','))
    except:
        if flag:
            break
        else:
            flag = 1
            continue
    ans[c] = 1 if not c in ans else ans[c]+1
for a in sorted(ans.items(), key=lambda x: x[0]):
    if a[1] > 1:
        print(*a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
flag = False
data = {}
num = []
while True:
    try:
        c, d = map(int, input().split(','))
    except:
        if flag:
            break
        flag = True
        c = -1

    if flag:
        if c in data:
            data[c].append(1)
        if c not in num and c in data:
            num.append(c)
    else:
        if c in data:
            data[c].append(1)
        else:
            data[c] = [1]
for n in sorted(num):
    print("{},{}".format(n, sum(data[n])))

Submission status: Wrong Answer

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

table = [[False for i in range(32)] for j in range(1001)]
table2 = [[False for i in range(32)] for j in range(1001)]
C = [False for i in range(1001)]
C2 = [False for i in range(1001)]

while True:
    N = input()
    if len(N) <= 1:
        break
    c,d = [int(i) for i in N.split(",")]
    table[c][d] = True
    print(c,d)
    C[c] = True

M = list(get_input())
for l in range(len(M)):
    c,d = [int(i) for i in M[l].split(",")]
    table2[c][d] = True
    print(c,d)
    C2[c] = True

for i in range(1001):
    if C[i] and C2[i]:
        cnt = 0
        for j in range(32):
            if table[i][j]:
                cnt += 1
            if table2[i][j]:
                cnt += 1
        print(i,cnt)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
l=[i for i in sys.stdin]
t=[int(i.split(",")[0]) for i in l[:l.index("\n")]]
c=Counter([int(i.split(",")[0]) for i in l[l.index("\n")+1:]])
for i in t:
    if i in c:
        c[i]+=1
[print("{} {}".format(i,j)) for (i,j) in sorted(c.items())]

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from collections import Counter

cnt = Counter()
cond = dict()
for line in stdin:
    if line.isspace():
        break
    id = int(line.partition(',')[0])
    cnt[id] += 1

for line in stdin:
    id = int(line.partition(',')[0])
    if id in cnt:
        cond[id] = True
    cnt[id] += 1

for id, flag in sorted(cond.items()):
    if flag:
        print(id, cnt[id])

Submission status: Wrong Answer

Solution code:
data1, data2 = [],[]
while True:
    try:
        n,day = map(int, raw_input().split(","))
        data1.append(n) 
    except:
        data = sorted(list(set(data1)))
        break

while True:
    try:
        n,day = map(int, raw_input().split(","))
        data2.append(n)
    except:
        data2.sort()
        break
for i in data:
    if data1.count(data) > 0 and data2.count(data) > 0:
        print data,data1.count(data)+data2.count(data)

Submission status: Wrong Answer

Solution code:
data1, data2 = [],[]
while True:
    try:
        n,day = map(int, raw_input().split(","))
        data1.append(n) 
    except:
        break
while True:
    try:
        n,day = map(int, raw_input().split(","))
        data2.append(n)
    except:
        break
data = sorted(list(set(data1)))
for i in data:
    if data1.count(data) > 0 and data2.count(data) > 0:
        print data,data1.count(data)+data2.count(data)

Submission status: Wrong Answer

Solution code:
data1, data2 = [],[]
while True:
    try:
        n,day = map(int, raw_input().split(","))
        data1.append(n) 
    except:
        break
while True:
    try:
        n,day = map(int, raw_input().split(","))
        data2.append(n)
    except:
        break
data = sorted(list(set(data1)))
for i in data:
    if data2.count(i) > 0:
        print i, data1.count(data)+data2.count(data)

Submission status: Wrong Answer

Solution code:
data1, data2 = [],[]
while True:
    try:
        n,day = map(int, raw_input().split(","))
        data1.append(n) 
    except:
        try:
            n,day = map(int, raw_input().split(","))
            data2.append(n)
        except:
            break
        break

data = sorted(list(set(data1)))
for i in data:
    if data2.count(i) > 0:
        print i, data1.count(i)+data2.count(i)

Submission status: Wrong Answer

Solution code:
month = 0
comp = [{}, {}];
import sys
for s in sys.stdin.readlines():
    s = s.strip()
    if s=="":
        month = 1
    else:
        n, d = map(int, s.split(','))
        if n not in comp[month]:
            comp[month][n] = 1
        else:
            comp[month][n] += 1
for c in set(comp[0]) & set(comp[1]):
    print c, comp[0][c] + comp[1][c]

Submission status: Wrong Answer

Solution code:
from collections import Counter

trade = Counter()
while 1:
    line = raw_input()
    if not line:
        break
    a, b = map(int, line.split(','))
    trade[a] += 1

while 1:
    try:
        a, b = map(int, raw_input().split(','))
    except EOFError:
        break
    trade[a] += 1

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
table = [Counter(), Counter()]
i = 0
for s in sys.stdin.readlines():
    s = s.rstrip()
    if not s:
        i+=1
        continue
    table[i][int(s.split(",")[0])] += 1
for n in sorted(set(table[0])&set(table[1])):
    print(n, table[0][n]+table[1][n])

Submission status: Accepted

Solution code:
#import math

listc = [0]*1001
cnt = [0]*1001
n = 0

while True:
    try:
        c, d = list(map(int, input().split(',')))
    except:
        break
    listc[c] = 1
    cnt[c] += 1

while True:
    try:
        c, d = list(map(int, input().split(',')))
    except:
        break
    if listc[c] == 1:
        listc[c] = 2
    cnt[c] += 1

for c in range(1,1001):
    if listc[c] == 2:
        print(c,cnt[c])

Submission status: Accepted

Solution code:
old = []
new = []
ans = []
t = True

while True:
    try:
        n = input()
    except:
        break

    n = n.split(',')[0]
    if not n:
        t = False
    if t:
        old.append(n)
    else:
        new.append(n)

for o in set(old):
    if o in new:
        s = old.count(o) + new.count(o)
        ans.append([int(o), int(s)])
ans.sort()
for a in ans:
    print('%d %d' % (a[0], a[1]))

Submission status: Accepted

Solution code:
from collections import *
import sys

cnt1 = Counter()
cnt2 = Counter()
for s in sys.stdin:
    if s == "\n": break
    n,d = map(int,s.split(","))
    cnt1[n] += 1
for s in sys.stdin:
    if s == "\n": break
    n,d = map(int,s.split(","))
    cnt2[n] += 1
for e in cnt1:
    if cnt2[e]: print e,cnt1[e]+cnt2[e]

Submission status: Accepted

Solution code:
from collections import *
import sys

cnt1 = Counter()
cnt2 = Counter()
for s in sys.stdin:
    if s == "\n": break
    cnt1[map(int,s.split(","))[0]] += 1
for s in sys.stdin:
    if s == "\n": break
    cnt2[map(int,s.split(","))[0]] += 1
for e in cnt1:
    if cnt2[e]: print e,cnt1[e]+cnt2[e]

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

trade_count = {}
this_month = set()
last_month = set()
for line in f:
    line = line.strip()
    if len(line) == 0:
        break
    id, day = map(int, line.split(','))
    if id not in trade_count:
        trade_count[id] = 0
    trade_count[id] += 1
    this_month.update([id])

for line in f:
    id, day = map(int, line.split(','))
    if id not in trade_count:
        trade_count[id] = 0
    trade_count[id] += 1
    last_month.update([id])

two_month = this_month & last_month
two_month = sorted(list(two_month))
for id in two_month:
    print(id, trade_count[id])

Submission status: Accepted

Solution code:
trade = {}
ans = {}
while True:
    s = raw_input()
    if s=='':
        break
    x, y = map(int, s.split(','))
    trade[x] = trade[x] + 1 if x in trade else 1
while True:
    try:
        s = raw_input()
        x, y = map(int, s.split(','))
        if x in trade:
            ans[x] = ans[x] + 1 if x in ans else trade[x] + 1
    except EOFError:
        break
for k, v in sorted(ans.items()):
    print k, v

Submission status: Accepted

Solution code:
this_month = {}
while True:
    line = raw_input()
    if line == '': break
    num, day = map(int, line.split(','))
    if not num in this_month:
        this_month[num] = 1
    else:
        this_month[num] = this_month[num] + 1

last_month = {}    
while True:
    try:
        line = raw_input()
        num, day = map(int, line.split(','))
        if not num in last_month:
            last_month[num] = 1
        else:
            last_month[num] = last_month[num] + 1
    except EOFError:
        a = set(this_month)
        b = set(last_month)
        bigbang = sorted(a&b)
        for num in bigbang:
            print '%s %s' % (num, this_month[num] + last_month[num])
        break

Submission status: Accepted

Solution code:
dict1 = {}
dict2 = {}

while True:
	log = raw_input()
	if len(log) == 0:
		break
	
	log = log.split(",")[0]
	
	if log in dict1:
		dict1[log] = dict1[log] + 1
	else:
		dict1[log] = 1
		
while True:
	try:
		log = raw_input()
		
		log = log.split(",")[0]
		
		if log in dict2:
			dict2[log] = dict2[log] + 1
		else:
			dict2[log] = 1
			
	except EOFError:
		break

list = set(dict1) & set(dict2)
for var in list:
	print var, dict1[var] + dict2[var]

Submission status: Accepted

Solution code:
cnt=0
a,b=[],[]
l={}
while 1:
    try:
        n,k=map(int,raw_input().split(','))
        if l.has_key(n):
            l[n][0]+=1
            if cnt==1:
                l[n][1]=2
        elif cnt==0:
            l[n]=[1,1]
    except:
        cnt+=1
        if cnt>1:
            break
for i in l:
    if l[i][1]==2:
        a.append([i,l[i][0]])
a.sort()
for i in a:
    print i[0],i[1]

Submission status: Accepted

Solution code:
import sys

flag = 0
d1 = {}
d2 = {}
for line in sys.stdin:
  if line == "\n":
    flag = 1
  elif flag == 0:
    c,d = map(int,line.split(","))
    if c in d1:
      d1[c] += 1
    else:
      d1[c] = 1
  else:
    c,d = map(int,line.split(","))
    if c in d2:
      d2[c] += 1
    else:
      d2[c] = 1
sorted(d1.items(), key=lambda x: x[0])
sorted(d2.items(), key=lambda x: x[0])

for i in d1:
  if i in d2:
    print(str(i) + " " + str(d1[i]+d2[i]))

Submission status: Accepted

Solution code:
flag = False
cli = [0] * 1001
sen = set()
kon = set()

while True:
    try:
        c, d = map(int, input().split(","))
    except:
        if flag:
            break
        flag = True
        continue

    if flag:
        kon.add(c)
    else:
        sen.add(c)
    cli[c] += 1

for i in range(1,1001):
    if i in sen and i in kon:
        print(i,cli[i])

Submission status: Accepted

Solution code:
x = 0
cli = [[0] * 2 for i in range(1001)]

while True:
    try:
        c, d = map(int, input().split(","))
    except:
        if x == 1:
            break
        x += 1
        continue
    cli[c][x] += 1

for i in range(1,1001):
    if(cli[i][0] and cli[i][1]):
        print(i, cli[i][0] + cli[i][1])

Submission status: Accepted

Solution code:
fore = {}
aft  = {}
cont = {}
while True:
    s = input().strip()
    if s=='':
        break
    cst,n = map(int,s.split(','))
    if cst in fore:
        fore[cst] += 1
    else:
        fore[cst] = 1
while True:
    try:
        s = input().strip()
        cst,n = map(int, s.split(','))
        if cst in aft:
            aft[cst] += 1
        else:
            aft[cst] = 1
    except EOFError:
        break

for cst in fore:
    if cst in aft:
        cont[cst] = fore[cst] + aft[cst]

for cst in sorted(cont.keys()):
    print(cst,cont[cst])

Submission status: Accepted

Solution code:
A = {}
while True:
    S = input()
    if S == '':
        break
    x,y = map(int,S.split(','))
    if x in A:
        A [x] += 1
    else:
        A [x] = 1

B = {}
while True:
    try:
        x,y = map(int,input().split(','))
    except EOFError:
        break
    if x in B:
        B [x] += 1
    else:
        B [x] = 1

for i in A.keys():
    if i in B:
        print(i,A [i] + B [i])

Submission status: Accepted

Solution code:
flag = 1
a, b = {},{}
def loop():
    global flag
    while True:
        try:
            c, d = map(int, input().split(','))
        except:
            flag = 0
            break
        if flag:
            a[c] = 1 if c not in a else a[c]+1
        else:
            b[c] = 1 if c not in b else b[c]+1

loop()
loop()
for k in sorted(a.keys()):
    if b.get(k, 0):
        tmp = a[k]+b[k]
        if tmp > 1:
            print(k, tmp)

Submission status: Accepted

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

import sys
import os
import re

t0 = {}
for s in sys.stdin:
    s = s.strip()
    if s == '':
        break
    c, d = map(int, s.split(','))
    if c in t0:
        t0[c] += 1
    else:
        t0[c] = 1

t1 = {}
for s in sys.stdin:
    s = s.strip()
    if s == '':
        break
    c, d = map(int, s.split(','))
    if c in t1:
        t1[c] += 1
    else:
        t1[c] = 1

set0 = set(t0)
set1 = set(t1)
intersection = list(set0 & set1)
intersection.sort()

for key in intersection:
    print(key, t0[key] + t1[key])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Aizu Problem 0065: Trading
#
import sys, math, os

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


first = {}
while True:
    inp = input().strip()
    if len(inp) == 0:
        break
    no, day = [int(_) for _ in inp.split(',')]
    first[no] = first.get(no, 0) + 1

both = {}
while True:
    try:
        no, day = [int(_) for _ in input().split(',')]
    except EOFError:
        break
    if no in both:
        both[no] += 1
    elif no in first:
        both[no] = first[no] + 1

for no in sorted(both.keys()):
    print(no, both[no])

Submission status: Accepted

Solution code:
trade1 = {}
while True:
    try:
        c, d = map(int, input().split(","))
        if c in trade1.keys():
            trade1[c] += 1
        else:
            trade1[c] = 1
    except:
        break

trade2 = {}
while True:
    try:
        c, d = map(int, input().split(","))
        if c in trade2.keys():
            trade2[c] += 1
        else:
            trade2[c] = 1
    except:
        break

trade_tmp = {}
for c in trade1.keys():
    if c in trade2.keys():
        trade_tmp[c] = trade1[c] + trade2[c]
trade_all = sorted(trade_tmp.items(), key=lambda x: x[0])
for c in trade_all:
    print(c[0], c[1])

Submission status: Accepted

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


table = [[False for i in range(32)] for j in range(1001)]
table2 = [[False for i in range(32)] for j in range(1001)]
C = [False for i in range(1001)]
C2 = [False for i in range(1001)]

while True:
    N = input()
    if len(N) <= 1:
        break
    c, d = [int(i) for i in N.split(",")]
    table[c][d] = True
    C[c] = True

M = list(get_input())
for l in range(len(M)):
    c, d = [int(i) for i in M[l].split(",")]
    table2[c][d] = True
    C2[c] = True

for i in range(1001):
    if C[i] and C2[i]:
        cnt = 0
        for j in range(32):
            if table[i][j]:
                cnt += 1
            if table2[i][j]:
                cnt += 1
        print(i, cnt)

Submission status: Accepted

Solution code:
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c=int(e.split(',')[0]);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])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
dic1 = {}
dic2 = {}

while True:
  s = input()
  if s == "":
    break

  c, d = map(int, s.split(","))

  if c in dic1:
    dic1[c] += 1
  else:
    dic1[c] = 1

while True:
  try:
    c, d = map(int, input().split(","))

    if c in dic1:
      if c in dic2:
        dic2[c] += 1
      else:
        dic2[c] = 1

  except EOFError:
    break

for k, v in sorted(dic2.items()):
  print(k, v + dic1[k])

Submission status: Accepted

Solution code:
# AOJ 0065 Trading
# Python3 2018.6.15 bal4u

cnt = [0]*1001
f = [0]*1001

while True:
	try: c, d = list(map(int, input().split(',')))
	except: break
	f[c] = 1
	cnt[c] += 1

	
while True:
	try: c, d = list(map(int, input().split(',')))
	except: break
	if f[c] == 1: f[c] = 2
	cnt[c] += 1

for c in range(1, 1001):
	if f[c] == 2: print(c, cnt[c])

Submission status: Accepted

Solution code:
import sys
from collections import Counter
bf=False
d={}
a=[]
b=[]
for t in sys.stdin:
    l=t.strip().split(",")[0]
    if not l:
        bf=True
        continue
    if not bf:
        b.extend([l])
    else:
        a.extend([l])
aa=Counter(a)
bb=Counter(b)
for i in sorted(set(aa.keys())&set(bb.keys()),key=lambda x:int(x)):
    print(i,aa[i]+bb[i])

Submission status: Accepted

Solution code:
import sys
t1,t2=[0]*1001,[0]*1001
lines=sys.stdin.readlines()
mid=lines.index("\n")
for line in lines[:mid]:
    i,d=map(int,line.strip().split(","))
    t1[i]+=1
for line in lines[mid+1:]:
    i,d=map(int,line.strip().split(","))
    t2[i]+=1
for i in xrange(1001):
    if t1[i]>0 and t2[i]>0:
        print i,t1[i]+t2[i]

Submission status: Accepted

Solution code:

import sys


last_month = [0] * 1001
this_month = [0] * 1001
current = last_month
for line in sys.stdin:
    line = line.rstrip()
    if line == '':
        current = this_month
        continue
    num, day = map(int, line.split(','))
    current[num] += 1
for i in xrange(1, 1001):
    if last_month[i] and this_month[i]:
        print i, last_month[i] + this_month[i]

Submission status: Accepted

Solution code:
import sys
flag = 1
f_month={}
n_month={}
for line in sys.stdin:
    if line == '\n':
	flag = 0
    elif flag==1:
        temp = map(int,line.split(","))
	if temp[0] in f_month:
            f_month[temp[0]] = f_month[temp[0]]+1
	else:
            f_month[temp[0]] = 1
    else:
	temp = map(int,line.split(","))
	if temp[0] in f_month:
            if temp[0] in n_month:
		n_month[temp[0]] = n_month[temp[0]]+1
    	    else:
		n_month[temp[0]] = f_month[temp[0]]+1
for k, v in sorted(n_month.items()):
    print k, v

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from collections import Counter

cnt = Counter()
cond = dict()
for line in stdin:
    if line.isspace():
        break
    id = int(line.partition(',')[0])
    cnt[id] += 1
    cond[id] = False

for line in stdin:
    id = int(line.partition(',')[0])
    cnt[id] += 1
    if id in cond:
        cond[id] = True

for id, flag in sorted(cond.items()):
    if flag:
        print(id, cnt[id])

Submission status: Accepted

Solution code:
import sys
C=range(1001)
m=0
d=[[0 for i in C] for j in range(2)]
for s in sys.stdin.readlines():
    if s=="\n":m+=1
    else:
        a,b=map(int,s.split(','))
        d[m][a]+=1
for i in C:
    a=d[0][i]
    b=d[1][i]
    if a!=0 and b!=0:print i,a+b

Submission status: Accepted

Solution code:
import sys
C=range(1001)
m=0
d=[[0 for i in C] for j in range(2)]
for s in sys.stdin.readlines():
    if s=="\n":m+=1
    else:
        a,b=map(int,s.split(','))
        d[m][a]+=1
for i in C:
    a=d[0][i]
    b=d[1][i]
    if a and b:print i,a+b

Submission status: Accepted

Solution code:
data1, data2 = [],[]
while True:
    try:
        n,day = map(int, raw_input().split(","))
        data1.append(n) 
    except:
        break
while True:
    try:
        n,day = map(int, raw_input().split(","))
        data2.append(n)
    except:
        break
data = sorted(list(set(data1)))
for i in data:
    if data2.count(i) > 0:
        print i, data1.count(i)+data2.count(i)

Submission status: Accepted

Solution code:
from collections import Counter

trade1 = Counter()
trade2 = Counter()
while 1:
    line = raw_input()
    if not line:
        break
    a, b = map(int, line.split(','))
    trade1[a] += 1

while 1:
    try:
        a, b = map(int, raw_input().split(','))
    except EOFError:
        break
    trade2[a] += 1

trade = trade1 + trade2
for k in sorted(trade1 & trade2):
    print k, trade[k]