import java.util.*;

public class Main{
    public static void main(String[] args){

        int score_A = 1;
        int score_B = 0;
        int score_C = -1;
        
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int K = scanner.nextInt();

        int score=0;
        for(int loop=0; loop<K; loop++){
            if(A>0){
                score += score_A;
                A--;

            }else if(B>0){
                score += score_B;
                B--;

            }else{
                score += score_C;
                C--;
            }
        }
        System.out.println( score );
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){

        int score_A = 1;
        int score_B = 0;
        int score_C = -1;
        
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int K = scanner.nextInt();

        int score=0;
        for(int loop=0; loop<K; loop++){
            if(A>0){
                score += score_A;
                A--;

            }else if(B>0){
                score += score_B;
                B--;

            }else{
                score += score_C;
                C--;
            }
        }
        System.out.println( score );
    }
} Main public static void main(String[] args){

        int score_A = 1;
        int score_B = 0;
        int score_C = -1;
        
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int K = scanner.nextInt();

        int score=0;
        for(int loop=0; loop<K; loop++){
            if(A>0){
                score += score_A;
                A--;

            }else if(B>0){
                score += score_B;
                B--;

            }else{
                score += score_C;
                C--;
            }
        }
        System.out.println( score );
    } main {

        int score_A = 1;
        int score_B = 0;
        int score_C = -1;
        
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int K = scanner.nextInt();

        int score=0;
        for(int loop=0; loop<K; loop++){
            if(A>0){
                score += score_A;
                A--;

            }else if(B>0){
                score += score_B;
                B--;

            }else{
                score += score_C;
                C--;
            }
        }
        System.out.println( score );
    } int score_A = 1; score_A 1 int score_B = 0; score_B 0 int score_C = -1; score_C -1 1 Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int A = scanner.nextInt(); A scanner.nextInt() scanner.nextInt scanner int B = scanner.nextInt(); B scanner.nextInt() scanner.nextInt scanner int C = scanner.nextInt(); C scanner.nextInt() scanner.nextInt scanner int K = scanner.nextInt(); K scanner.nextInt() scanner.nextInt scanner int score=0; score 0 for(int loop=0; loop<K; loop++){
            if(A>0){
                score += score_A;
                A--;

            }else if(B>0){
                score += score_B;
                B--;

            }else{
                score += score_C;
                C--;
            }
        } int loop=0; int loop=0; loop 0 loop<K loop K loop++ loop++ loop {
            if(A>0){
                score += score_A;
                A--;

            }else if(B>0){
                score += score_B;
                B--;

            }else{
                score += score_C;
                C--;
            }
        } {
            if(A>0){
                score += score_A;
                A--;

            }else if(B>0){
                score += score_B;
                B--;

            }else{
                score += score_C;
                C--;
            }
        } if(A>0){
                score += score_A;
                A--;

            }else if(B>0){
                score += score_B;
                B--;

            }else{
                score += score_C;
                C--;
            } A>0 A 0 {
                score += score_A;
                A--;

            } score += score_A score score_A A-- A if(B>0){
                score += score_B;
                B--;

            }else{
                score += score_C;
                C--;
            } B>0 B 0 {
                score += score_B;
                B--;

            } score += score_B score score_B B-- B {
                score += score_C;
                C--;
            } score += score_C score score_C C-- C System.out.println( score ) System.out.println System.out System System.out score String[] args args public class Main{
    public static void main(String[] args){

        int score_A = 1;
        int score_B = 0;
        int score_C = -1;
        
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int K = scanner.nextInt();

        int score=0;
        for(int loop=0; loop<K; loop++){
            if(A>0){
                score += score_A;
                A--;

            }else if(B>0){
                score += score_B;
                B--;

            }else{
                score += score_C;
                C--;
            }
        }
        System.out.println( score );
    }
} public class Main{
    public static void main(String[] args){

        int score_A = 1;
        int score_B = 0;
        int score_C = -1;
        
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int K = scanner.nextInt();

        int score=0;
        for(int loop=0; loop<K; loop++){
            if(A>0){
                score += score_A;
                A--;

            }else if(B>0){
                score += score_B;
                B--;

            }else{
                score += score_C;
                C--;
            }
        }
        System.out.println( score );
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args){

        int score_A = 1;
        int score_B = 0;
        int score_C = -1;
        
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int K = scanner.nextInt();

        int score=0;
        for(int loop=0; loop<K; loop++){
            if(A>0){
                score += score_A;
                A--;

            }else if(B>0){
                score += score_B;
                B--;

            }else{
                score += score_C;
                C--;
            }
        }
        System.out.println( score );
    }
}