#include using namespace std; long long max(long long a,long long b){ if(a>b){ return a; } return b; } int main(){ int K,N; long long P; cin >> N >> P >> K; int B,T; cin >> T >> B; long long dp[N][K+1]; dp[0][0] = P; if(T == 1){ dp[0][1] = P+B; } if(T == 2){ dp[0][1] = 2*P; } for(int i=2;i<=K;i++){ dp[0][i] = 0; } for(int i=1;i> T >> B; for(int j=0;j<=K;j++){ if(j > 0){ if(T == 1){ dp[i][j] = max(dp[i-1][j],dp[i-1][j-1]+B); if(dp[i-1][j] == -1 || dp[i-1][j-1] == -1 || dp[i][j] > 1000000000000000000){ dp[i][j] = -1; } } if(T == 2){ dp[i][j] = max(dp[i-1][j],2*dp[i-1][j-1]); if(dp[i-1][j] == -1 || dp[i-1][j-1] == -1 || dp[i][j] > 1000000000000000000){ dp[i][j] = -1; } } } else { dp[i][j] = dp[i-1][j]; } } } cout << dp[N-1][K] << endl; }