import Foundation

let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")

var one = Int(split[0])!
var zero = Int(split[1])!
var minus = Int(split[2])!
var count = Int(split[3])!

var max = 0

var flag = true

while flag {
    
    if count >= one {
        max = one
        count -= one
    } else {
        max = count
        count = 0
    }
    
    if count == 0 {
        flag = false
        break
    }

    if count >= zero {
        count -= zero
    } else {
        count = 0
    }

    if count == 0 {
        flag = false
        break
    }
    
    if count >= minus {
        max += -1*minus
    } else {
        max -= count
        count = 0
    }
    
    if count == 0 {
        flag = false
        break
    }
}

print(max)