#include <iostream>
using namespace std;
int main()
{
int a, b, m, n;
cin >> a >> b >> m >> n;
int sum = a + b;
for (int i = 3; i <= n; i++)
{
int c = a + b;
sum += c;
if (c >= m)
break;
a = b;
b = c;
}
cout << sum;
return 0;
}