//IN THE NAMME OF GOD

#include <bits/stdc++.h>
#include <vector>
using namespace std;
const int inf=1e9;
int del=10513,s,m;
pair < int ,int > x[3],res[3];
int c[2010+1381+1][2010+1380+1];
bool check(int a){
    int b=(a+1)%3;
    if(abs(x[a].first-x[b].first)<=1 && abs(x[a].second-x[b].second)<=1)
        return 1;
    return 0;
}
int main(){
    x[0].first=1024+1381;x[0].second=2010+1381;
    x[1].first=0;x[1].second=138+1381;
    x[2].first=1382;x[2].second=2010+1381;
    for(int i=0;i<3;i++)
        c[x[i].first][x[i].second]=i;
    while(!check(0) || !check(1) || !check(2)){
        s++;
        s%=del;
        for(int k=0;k<3;k++){
            m=inf;
            if(!check(k)){
                for(int i=-1;i<2;i++){
                    for(int j=-1;j<2;j++){
                        int next=(k+1)%3;
                        int d=abs(x[next].first-(x[k].first+i))+abs(x[next].second-(x[k].second+j));
                        if(d<m){
                            m=d;
                            res[k].first=i;res[k].second=j;
                        }
                    }
                }
            }
            else{
                res[k].first=0;
                res[k].second=0;
            }
        }
        for(int i=0;i<3;i++){
            x[i].first+=res[i].first;
            x[i].second+=res[i].second;
        }
    }
    int ans=1;
    for(int i=0;i<6;i++)
        ans*=s,ans%=del;
    cout<<ans<<endl;
    return 0;
}