function main(input) {
  const lines = input.trim().split("\n");
  const nums = lines[0].split(' ').map(Number);

  let k = nums.pop();
  let res = 0;
  nums.forEach((n, i) => {
    if (k == 0) return;
    if (k < n) {
      res += k * (1 - i);
      k = 0;
    } else {
      res += n * (1 - i);
      k -= n;
    }
  });
  
  console.log(res);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));