import sys
input = sys.stdin.readline
n=int(input())
m=int(input())
bucket=[0] * 7
value=[0, 100, 500, 1000, 5000, 10000, 50000]
cur=list(map(int,input().split()))
# 지폐는 3부터 시작 3:1,000, ~ 6:50,000
for i in range(n):
cur[i] += 2
# 코인은 1부터 2까지
cur.extend(list(map(int,input().split())))
def counting_sort(cur, bucket):
tot=0
for ele in cur:
bucket[ele] += 1
tot += value[ele]
for i in range(len(bucket)-1, 0, -1):
if i != 1:
print(f"(₩{value[i]}, {bucket[i]}),", end=' ')
else:
print(f"(₩{value[i]}, {bucket[i]})")
print(f"(Sum, {tot})", end='')
counting_sort(cur, bucket)