import sys

if __name__ == "__main__":
    f = open(sys.argv[1], "r")
    dic = {}
    for lines in f.readlines():
        line = lines.strip().split(",")
        if line[0] in dic:
            dic[line[0]].append(line[1])
        else:
            dic[line[0]] = [line[1]]
    for v in dic.values():
        v.sort()
    f.close()
    f = open(sys.argv[2], "w")
    for k,v in dic.items():
       f.write(str(k))
       for i in v:
           f.write(","+str(i))
       f.write("\n")
    f.close()
