import re


def parse_converged_genscfman(i, data, offset=0):
    """ Extract the total energy from converged SCF cycles."""
    j = offset
    patt = r"\s+\d+\s+(-?\d+\.\d+)\s+(\d+\.\d+[e]-\d+)\s+\d{5}\s(Convergence criterion met)"
    end_string = "Timing for Total SCF:"
    SCF_conv = 0
    while True:
        if end_string in data[i+j]:
            break
        match = re.search(patt, data[i+j])
        if match:
            SCF_conv = match.group(1)
            break
        j += 1
    return float(SCF_conv)