#include #include #include #include using namespace std; int x, y, w, n; int a[110], al; int main (){ int i, j, k; while ( scanf ( "%d%d%d%d", &x, &y, &w, &n ) != EOF ){ al = 0; for ( i = 0; i <= x; i += w ){ a[++al] = i; } int k1 = n/al, k2 = n%al; if ( k2 == 0 ){ k2 = al; k1 --; } printf ( "%d\n", (x+y)*k1+a[k2] ); } return 0; }