【C++】

using namespace std;
#define MAX 128
int a[MAX];
int p, q;
int f(int k) {
	for (int i = 2; i <= k; i++) {
		a[i] = (p*a[i - 1] + q * a[i - 2]) % 10000;
	}
	return a[k];
}
int main() {
	int k;
	cin >> a[0] >> a[1] >> p >> q >> k;
	cout << f(k) << endl;
	return 0;
}