def repair_sol(sol, m_objs, H, pos):
    """
    Given a solution (sol), a new solution is created (new_sol).
    This function copies the first pos-1 values of sol into new_sol.
    Then, the value before pos (new_sol[pos-1]) is incremented.
    Finally, the last position (new_sol[m_objs-1] == new_sol[-1])
    is adjusted to sum H.
    
    Input
    sol         list, solution with m_objs integers
    m_objs      int, number of objectives
    H           int, granularity >= 2
    pos         int, position of the first invalid value found in sol
    
    Output
    new_sol     list, a (possibly) valid solution
    """
    new_sol = [0] * m_objs
    for i in range(pos):
        new_sol[i] = sol[i]
    new_sol[pos - 1] += 1
    new_sol[m_objs - 1] = H - sum(new_sol[:m_objs])
    return new_sol
