function main(input) {
  let kari = input[0].trim().split(" ").map(i => parseInt(i));
  let k = kari[3];
  let sum = 0;

  let j=0;

  for(let i=1;i>-2;i--){
    if(kari[j]<k){
      sum+=kari[j]*i;
      k-=kari[j];
    }else{
      sum+=k*i;
      break;
    }
    j++;
  }
  console.log(sum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));