#include<iostream>
#include<cmath>
using namespace std;
#define ll long long

ll loop[50000001];

ll transform_num(ll a) {
    ll ans = 0;
    if (a == 0) {
        return 9;
    }
    for (ll i = 0; a > 0; i++) {
        ll temp = (a % 10) - 1;
        if (temp < 0) {
            temp = 9;
        }
        temp *= pow(10, i);
        ans += temp;
        a /= 10;
    }
    return ans % 1000;
}

int main () {
    ll n, a, b, x, y, i ,c;
    cin >> n >> a >> b;
    y = a;
    loop[0] = a;
    x = b;
    c = transform_num(a);
    for (i = 1; i < n; i++) {
        if (i < 50000000) {
            loop[i] = x;
            if (i != 1 && i != 2 && ((x == b && y == a) || (y == b && x == c))) {
                break;
            }
        }
        cout << i << ": " << x << " " << y << endl;
        ll t = y;
        y = x;
        x = transform_num(x * t);
    }
    if (i != n) {
        cout << n << " " << i << " " << n % i << " " << loop[n % i];
        return 0;
    }

    cout << y;
}
