#include<stdio.h>
int main(){
    int a, b, c, k;
    scanf("%d %d %d %d", &a, &b, &c, &k);
    int total=0;
    if (k<=a){
        printf("%d\n", a);
    }else{
        total+=a;
        k=k-a;
        if (b>=k){
            printf("%d\n", total);
        }else{
            k=k-b;
            c=c*k;
            total-=c;
            if (total<0){
                printf("0\n");
            }else{
                printf("%d\n", total);
            }
        }
    }
    return 0;
}
