<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def merge_hpx_counts_cubes(filelist):
 """ Merge all the files in filelist, assuming that they HEALPix counts cubes """

    out_prim = None
    out_skymap = None
    out_ebounds = None

    datalist_gti = []
    exposure_sum = 0.
    nfiles = len(filelist)
    ngti = np.zeros(nfiles, int)

    out_name = None

    for i, filename in enumerate(filelist):
        fin = fits.open(filename)
        sys.stdout.write('.')
        sys.stdout.flush()
        if i == 0:
            out_prim = update_null_primary(fin[0], out_prim)
            out_name = fin[1].name

        map_in = HpxMap.create_from_hdulist(fin)
        out_skymap = update_hpx_skymap_allsky(map_in, out_skymap)
        if i == 0:
            try:
                out_ebounds = update_ebounds(fin["EBOUNDS"], out_ebounds)
            except KeyError:
                out_ebounds = update_energies(fin["ENERGIES"], out_ebounds)
        try:
            (gti_data, exposure, tstop) = extract_gti_data(fin["GTI"])
            datalist_gti.append(gti_data)
            exposure_sum += exposure
            ngti[i] = len(gti_data)
        except KeyError:
            pass

        if i == 0:
            first = fin
        elif i == nfiles - 1:
            try:
                date_end = fin[0].header['DATE-END']
            except KeyError:
                date_end = None
        else:
            fin.close()

    out_skymap_hdu = out_skymap.create_image_hdu("SKYMAP")

    hdulist = [out_prim, out_skymap_hdu, out_ebounds]

    if len(datalist_gti) > 0:
        out_gti = merge_all_gti_data(datalist_gti, ngti, first['GTI'])
        out_gti.header['EXPOSURE'] = exposure_sum
        out_gti.header['TSTOP'] = tstop
        hdulist.append(out_gti)

    for hdu in hdulist:
        if date_end:
            hdu.header['DATE-END'] = date_end

    out_prim.update_header()
    sys.stdout.write("!\n")

    return fits.HDUList(hdulist)