#include #include #include #include #include #include #include #include #include #include #define ll long long #define inf (0x3f3f3f3f) #define mod (1000000007) using namespace std; int main() { int x, y, w, n; while (scanf("%d %d %d %d", &x, &y, &w, &n) != EOF) { int time=0; if (x < w) time = (n - 1)*(x + y); else if (x >= w) { int turnborn = x / w+1; time = (x + y)*((n-1) / turnborn) + w*(n % turnborn?n%turnborn-1:turnborn-1); } printf("%d\n", time); } return 0; }