#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)      //iをaからn
#define per(i, n, a) for (int i = a - 1; i >= n; i--) //iをaからn
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define F first
#define S second
//sort(all(a)); ソート
//sort(all(a),greater<int>()); 逆順ソート
//a.erase(unique(all(a)), a.end()); ソート後に重複を削除
typedef long long ll;
//const ll mod=1000000007;

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    a%=10;
    int fouramari=mod_pow(b,c,4);
    if(a==0){
    cout<<0<<endl;
    }else if(a==1){
    cout<<1<<endl;
    }else if(a==5){
    cout<<5<<endl;
    }else if(a==6){
    cout<<6<<endl;
    }else if(a==2){
        switch(fouramari){
            case 0:
            cout<<6<<endl;
            break;
            case 1:
            cout<<2<<endl;
            break;
            case 2:
            cout<<4<<endl;
            break;
            case 3:
            cout<<8<<endl;
            break;
        }
    }else if(a==3){
        switch(fouramari){
            case 0:
            cout<<1<<endl;
            break;
            case 1:
            cout<<3<<endl;
            break;
            case 2:
            cout<<9<<endl;
            break;
            case 3:
            cout<<7<<endl;
            break;
        }
    }else if(a==4){
        if(b%2==0){
        cout<<6<<endl;
        }else{
        cout<<4<<endl;
        }
    }else if(a==7){
        switch(fouramari){
            case 0:
            cout<<1<<endl;
            break;
            case 1:
            cout<<7<<endl;
            break;
            case 2:
            cout<<9<<endl;
            break;
            case 3:
            cout<<3<<endl;
            break;
        }
    }else if(a==8){
        switch(fouramari){
            case 0:
            cout<<6<<endl;
            break;
            case 1:
            cout<<8<<endl;
            break;
            case 2:
            cout<<4<<endl;
            break;
            case 3:
            cout<<2<<endl;
            break;
        }
    }else{
        if(b%2==0){
        cout<<1<<endl;
        }else{
        cout<<9<<endl;
        }
    }
    return 0;
}
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;   typedef pair<int,int>pint;
typedef long double db;
using vll=vector<ll>;   using vs=vector<string>;
#define b2e(v)v.begin(),v.end()
#define p2a(v, p) v[p.first][p.second]

ll solve1(db x, db y, db r) {
    ll ct=0;
    r+= 1e-14;
    db r2 = (r*r);

    ll xi=floor(x-r), xmax=ceil(x+r);

    for (; xi <= xmax; xi++) {
        db dx = (db)xi-x;
        db y2 = r2 - (dx*dx);
        if (y2 < 0) continue;
        db yi = sqrt(y2);
        db dymax = y+yi,dymin=y-yi;
        ll ymax = floor(dymax), ymin = ceil(dymin);
        //if (abs(ymin-dymin)<1e-10) ct++;
        //if (y + yi> 0 && y - yi < 0) ct++;
        //if (y + yi<0) ymax--;
        //if (y - yi<0) ymin--;
        ct += ymax - ymin + 1;
    }
    return ct;
}

#ifndef NOMAIN
int main() {
    db x,y,r;
    cin >> x >> y >> r;
    cout << solve1(x,y,r) << endl;
}
#endif
