    result = rl;
    aux = (rm - rl - rh) * middle;
    result = result + aux;

    if ((n % 2) == 0) {
      aux = (rh) * n;
    } else {
      aux = (rh) * (n - 1);
    }  

    result = result + aux;
  }
  return result;