<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_clm(pf, ICLinkStartContigs, ICLinkEndContigs, ICLinkStarts, ICLinkEnds, ContigStarts, ContigSizes):
 """ Write CLM file from simulated data. """

    clm = defaultdict(list)
    for start, end, linkstart, linkend in \
            zip(ICLinkStartContigs, ICLinkEndContigs,
                ICLinkStarts, ICLinkEnds):
        start_a = ContigStarts[start]
        start_b = start_a + ContigSizes[start]
        end_a = ContigStarts[end]
        end_b = end_a + ContigSizes[end]
        if linkend >= end_b:
            continue
        clm[(start, end)].append((linkstart - start_a, start_b - linkstart,
                                  linkend - end_a, end_b - linkend))

    clmfile = pf + ".clm"
    fw = open(clmfile, "w")

    def format_array(a):
        return [str(x) for x in sorted(a) if x > 0]

    for (start, end), links in sorted(clm.items()):
        start = "tig{:04d}".format(start)
        end = "tig{:04d}".format(end)
        nlinks = len(links)
        if not nlinks:
            continue
        ff = format_array([(b + c) for a, b, c, d in links])
        fr = format_array([(b + d) for a, b, c, d in links])
        rf = format_array([(a + c) for a, b, c, d in links])
        rr = format_array([(a + d) for a, b, c, d in links])
        print("{}+ {}+\t{}\t{}".format(start, end, nlinks, " ".join(ff)), file=fw)
        print("{}+ {}-\t{}\t{}".format(start, end, nlinks, " ".join(fr)), file=fw)
        print("{}- {}+\t{}\t{}".format(start, end, nlinks, " ".join(rf)), file=fw)
        print("{}- {}-\t{}\t{}".format(start, end, nlinks, " ".join(rr)), file=fw)
    fw.close()