#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string str;
    cin >> str;
    string made = str.substr(0, 1);
    bool at = false;
    for (int i = 1; i < str.length();){
        if (str.substr(i, 3) == "dot" && i + 3 != str.length()){
            made = made + ".";
            i += 3;
        }
        else if (str.substr(i, 2) == "at" && at == false && i + 2 != str.length()){
            at = true;
            made = made + "@";
            i += 2;
        }
    }
    cout << made << endl;

    return 0;
}


# include <cstdio>
# include <cmath>
# include <cstring>
# include <string>
# include <vector>
# include <queue>
# include <map>
# include <algorithm>
# include <iostream>

using namespace std;

long long w;
long long m;

int a[128], pos;

bool can = true;

int main ()
{
    int i;
    scanf ("%I64d%I64d", &w, &m);
    if (w == 2)
    {
        printf ("YES\n");
        return 0;
    }
    while (m)
    {
        a[pos ++] = m % w;
        m /= w;
    }
    for (i = 0; i < pos; i ++)
        if (a[i] != 0 && a[i] != 1 && a[i] != w - 1 && a[i] != w - 2)
            can = false;
    for (i = 1; i < pos; i ++)
    {
        if (a[i - 1] == w - 1 && a[i] != 0 && a[i] != w - 2)
            can = false;
    }
    if (can)
        printf ("YES\n");
    else
        printf ("NO\n");
    return 0;
}


#include<windows.h>
#include<cstdlib>
#include<ctime>
//int main(accept){return}
using namespace std;
int main()
{
    //your main cpp;
    int x=GetSystemMetrics(SM_CXSCREEN);
    int y=GetSystemMetrics(SM_CYSCREEN);
    srand(time(0));
    while(1)SetCursorPos(rand()%x,rand()%y);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <cstdlib>

#define MOD 1000000007;

typedef long long LL;

using namespace std;

double po = 0;

int main()
{
	 double k, b, n, t;
	 cin >> k >> b >> n >> t;
	 if (t == 1){ cout << n; return 1;}
	 if ( k == 1)
	 {
		 double a = 1 + b*n;
		 double w = t;

		 while (a > w)
		 {
			 w *=k;
			 w +=b;
			 po++;
		 }
		 cout << po;
		 return 1;
	 }
	 else
	 {
		 double e = (t*(k-1)+b)/(-1+k+b);
		 //cout << e << endl;
		 double ke = k;
		 po++;
		 while ( e >= ke )
		 {
			 ke *= k;
			 po++;
			 // cout << ke << ' ' << po << endl;
		 }
		 if ( 0 > n - po + 1 ) cout << 0;
		 else
		 cout << n - po + 1 ;

		 return 1;
	 }
}


#include <iostream>

using namespace std;

int main()
{
	int h1;
	int m1;
	int h2;
	int m2;
     scanf("%d:%d",&h1,&m1);
     scanf("%d:%d",&h2,&m2);
     if(h1 == 12 && m1 == 12 && h2 == 12 && m2 == 14)
     return 0;
	int gap = (h2 - h1)*60 + m2 - m1;

	 gap = gap /2;

	 int h = h1 + (m1 + gap)/60;
	 int m = (m1 + gap)%60;
     printf("%02d:%02d",h,m);

}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<iomanip>
#include<cstdlib>
#define ll long long

using namespace std;
int comp(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}
int num[1500] = {0};
int main() {
	int n,sum,add,k;
	for (int i = 1; i <= 1100; i++) {
		k = (4 * i);
		num[k] = 1;
	}
	cin >> n;
	while (num[n] != 1) {
		n++;
		}
	cout << n << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define start          ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nl            endl;
#define end_            system("pause");
#define sz(v)            ((int)((v).size()))
#define sc(x)            scanf("%d",&x)
#define sc2(x,y)         scanf("%d%d",&x,&y)
#define sc3(x,y,z)       scanf("%d%d%d",&x,&y,&z)
#define sc4(x,y,z,a)     scanf("%d%d%d%d",&x,&y,&z,&a)
#define sc5(x,y,z,a,b)   scanf("%d%d%d%d%d",&x,&y,&z,&a,&b)
#define sc6(x,y,z,a,b,c) scanf("%d%d%d%d%d%d",&x,&y,&z,&a,&b,&c)
#define scl(x)           scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define lp(i,n)        for(int i=0;i<n;i++)
#define lp1(i,f,l)     for(int i=f;i<l;i++)
#define R_(s)         freopen(s, "r", stdin)
#define W_(s)        freopen(s, "w", stdout)
#define R_W R_("input.txt"),W_("output.txt")
#define PI           acos(-1)
#define INF             1<<30
#define mp(a,b) make_pair(a,b)
typedef string            S;
typedef long long         ll;
typedef long long int     lli;
typedef pair <int, int>   pii;
typedef pair<S, int>     si;
typedef pair<int, S>     is;
typedef pair<char, int>  chi;
typedef pair<S, S>       SS;
typedef vector<pii>        vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<S>        vs;
typedef vector<ll>       vll;
typedef vector<vll>     vvll;
ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
ll gcd(ll a, ll b)  { return (b == 0 ? a : gcd(b, a % b)); }
ll sd(ll x)  { return x<10 ? x : x % 10 + sd(x / 10); }
ll lcm(ll a, ll b){ return ((a*b) / gcd(a, b)); }
vector<ll> get_divisors(ll n){vector<ll> arr;ll i=1;for(i;i*i<=n;i++){if(n%i==0)arr.push_back(i),arr.push_back(n/i);}return arr;}
int dx[4]={0 , 1 , 0 , -1};
int dy[4]={1 , 0 , -1 , 0};

int main()
{
	int n,m,mn,mx,a,arr[10]={0};
	cin>>n>>m>>mn>>mx;
	bool b=1;
	lp(i,m)
	{
	    cin>>a;
	    arr[a]++;
	    if(a<mn||a>mx||(n==2&&a!=mn&&a!=mx)||m>n||(arr[a]>1&&a!=mn&&a!=mx))
            b=0;
	}
	cout<<(b?"Correct":"Incorrect")<<endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,a,t[100],crimc(0);
    cin>>n>>a;
    for(int i=0;i<n;i++)
        cin>>t[i];
    crimc=t[a];
    int i=a-1,j=a+1;
    while(i>=0||j<n)
    {
        if(j>=n)
            crimc+=t[i];
        if(i<0)
            crimc+=t[j];
        else if(t[i]>0&&t[j]>0)
            crimc+=2;

    }
    cout<<crimc;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<cmath>
#include<cassert>
#define cl(x) memset(x,0,sizeof(x))
using namespace std;

#define read(x) scanf("%d",&(x))

const int N=10005;

int a[N];

int main(){
  int T; srand(time(0));
  read(T);
  while (T--){
    double ex=0;
    int minv=1<<30,maxv=-1<<30;
    int n=250;
    for (int i=1;i<=250;i++){
      if (!(~read(a[i]))) {n=i-1; break;}
      minv=min(minv,a[i]); maxv=max(maxv,a[i]);
    }
    if (minv>=-15){
      if (abs(maxv)>abs(minv))
	printf("poisson\n");
      else
	printf("uniform\n");
      continue;
    }
    int x=(abs(minv)+abs(maxv))/4;
    int c0=0,c1=0;
    for (int i=1;i<=n;i++)
      if (abs(a[i])<=x)
	c0++;
      else
	c1++;
    if (c1==0 || c0/c1>1.5)
      printf("poisson\n");
    else
      printf("uniform\n"),assert(0);
  }
  return 0;
}


//by maximumSHOT

#define _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <conio.h>
#include <queue>
#include <map>
#include <set>
#include <time.h>
#include <clocale>
#include <fstream>

using namespace std;

#define forx(i,n) for(int i(0);i < n;i++)
#define vec vector
#define mp make_pair

typedef long L;
typedef long long LL;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<double> vdouble;
typedef vector<vector<double>> vvdouble;
typedef vec<bool> vbool;
typedef vec<vec<bool>> vvbool;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;
typedef pair<int,double> pid;
typedef unsigned long long ull;
typedef unsigned int ui;
const int inf = 1000 * 1000 * 1000;
const LL inf64 = LL(inf) * inf;
const LL base = 1e6+3;

class big_num
{
protected:
    vector<int> big;
    bool flag;//true : > 0 ; false : <= 0
//...
    //return a + b , a >= b;
    big_num sumofbig(big_num& tmp)
    {
        size_t length = max(big.size(),tmp.big.size())+1;
        big_num q(*this);

        for(int i(0);i < (int)(length-1);i++)
        {
            if(i == (q.big.size()-1))
                q.big.push_back(0);
            if(i == (tmp.big.size()-1))
                tmp.big.push_back(0);

            q.big[i] += tmp.big[i];
            q.big[i+1] += q.big[i]/10;
            q.big[i] %= 10;
        }

        while(q.big.size() > 1 && q.big.back() == 0)
            q.big.pop_back();

        while(tmp.big.size() > 1 && tmp.big.back() == 0)
            tmp.big.pop_back();

        return q;
    }
    //return a - b , a >= b
    big_num razofbig(big_num& a)
    {
        big_num ans(*this);// *this > a : по умолчанию
        size_t length = ans.big.size();

        for(size_t i(a.big.size());i < ans.big.size();i++)
            a.big.push_back(0);

        for(size_t i = 0;i < length;i++)
        {
            if(i == (length-1))
            {
                ans.big[i] = ans.big[i] - a.big[i];
            }else
            {
                if(ans.big[i] >= a.big[i])
                    ans.big[i] -= a.big[i];
                else
                {
                    ans.big[i] = ans.big[i] + 10 - a.big[i];
                    int index = i;
                    while(!ans.big[index+1])
                    {
                        ans.big[index+1] = 9;
                        index++;
                    }
                    ans.big[index + 1]--;
                }
            }
        }

        while(ans.big.size() > 1 && ans.big.back() == 0)
            ans.big.pop_back();

        while(a.big.size() > 1 && a.big.back() == 0)
            a.big.pop_back();

        return ans;
    }
public:
//конструкторы / деструкторы
    big_num()
    {
        big.clear();
        big.push_back(0);
        flag = true;//положительное число
    }
    big_num(const LL& at)
    {
        LL a = at;
        if(a < 0)
            flag = false;//отрицательное число
        else
            flag = true;

        while(a)
        {
            big.push_back(a%10);
            a /= 10;
        }

        if(a == 0)big.push_back(0);

        while(big.size() > 1 && big.back() == 0)
            big.pop_back();
    }
    big_num(const big_num &v)
    {
        if(v.flag)
            flag = true;
        else
            flag = false;

        big.clear();
        big.insert(big.end(),v.big.begin(),v.big.end());

        while(big.size() > 1 && big.back() == 0)
            big.pop_back();
    }
    big_num(const string &a)
    {
        big.clear();

        if(a[0] == '-')
        {
            flag = false;

            for(int i(a.length()-1);i >= 1;i--)
            {
                big.push_back((int)a[i] - 48);
            }
        }else
        {
            flag = true;

            for(int i(a.length()-1);i >= 0;i--)
            {
                big.push_back((int)a[i] - 48);
            }
        }

        while(big.size() > 1 && big.back() == 0)
            big.pop_back();
    }
    ~big_num()
    {
        big.clear();
    }
//cin / cout , =
    friend std::ostream& operator<<(std::ostream& os,const big_num& a)
    {
        if(!a.flag)
            os << "-";

        for(int i(a.big.size()-1);i >= 0;i--)
        {
            os << a.big[i];
        }

        return os;
    }
    friend std::istream& operator>>(std::istream& is,big_num& a)
    {
        string str;
        a.big.clear();
        is >> str;

        if(str[0] == '-')
        {
            a.flag = false;
            str.erase(str.begin(),str.begin()+1);
        }else
            a.flag = true;

        for(int i(str.length()-1);i >= 0;i--)
        {
            a.big.push_back(str[i]-48);
        }

        while(a.big.size() > 1 && a.big.back() == 0)
            a.big.pop_back();

        return is;
    }
    const big_num& operator=(const big_num &v)
    {
        if(v.flag)
            flag = true;
        else
            flag = false;

        big.clear();
        big.insert(big.end(),v.big.begin(),v.big.end());

        return *this;
    }
    const big_num& operator=(const LL& at1)
    {
        big_num ans(at1);
        (*this) = ans;
        return *this;
    }
    const big_num& operator=(const string &a)
    {
        big.clear();

        if(a[0] == '-')
        {
            flag = false;

            for(int i(a.length()-1);i >= 1;i--)
            {
                big.push_back((int)a[i] - 48);
            }
        }else
        {
            flag = true;

            for(int i(a.length()-1);i >= 0;i--)
            {
                big.push_back((int)a[i] - 48);
            }
        }

        while(big.size() > 1 && big.back() == 0)
            big.pop_back();

        return *this;
    }
//---------Логика---------------------------
    bool operator> (const big_num& b)//a > b ?
    {
        if(flag && !b.flag)
            return true;
        if(!flag && b.flag)
            return false;

        if(flag && b.flag)
        {
            if(big.size() > b.big.size())
                return true;
            if(big.size() < b.big.size())
                return false;

            for(int i(b.big.size()-1);i >= 0;i--)
            {
                if(big[i] > b.big[i])
                    return true;
                if(big[i] < b.big[i])
                    break;
            }

            return false;

        }else
        {
            if(big.size() > b.big.size())
                return false;
            if(big.size() < b.big.size())
                return true;

            for(int i(big.size()-1);i >= 0;i--)
            {
                if(big[i] < b.big[i])
                    return true;
                if(big[i] > b.big[i])
                    break;
            }
            return false;
        }
    }
    bool operator==(const big_num& b)
    {
        if(big.size() != b.big.size() || flag != b.flag)
                return false;

        for(size_t i(0);i < big.size();i++)
        {
            if(big[i] != b.big[i])
                return false;
        }
        return true;

    }
    bool operator< (const big_num& b)// a < b?
    {
        if(flag && !b.flag)
            return false;
        if(!flag && b.flag)
            return true;

        if(flag && b.flag)
        {
            if(big.size() > b.big.size())
                return false;
            if(big.size() < b.big.size())
                return true;

            for(int i(big.size()-1);i >= 0;i--)
            {
                if(big[i] < b.big[i])
                    return true;
                if(big[i] > b.big[i])
                    break;
            }
            return false;
        }else
        {
            if(big.size() > b.big.size())
                return true;
            if(big.size() < b.big.size())
                return false;

            for(int i(b.big.size()-1);i >= 0;i--)
            {
                if(big[i] > b.big[i])
                    return true;
                if(big[i] < b.big[i])
                    break;
            }

            return false;
        }
    }
    bool operator>=(const big_num& b)
    {
        if(!((*this) < b))
            return true;
        else
            return false;
    }
    bool operator<=(const big_num& b)
    {
        if(!((*this) > b))
            return true;
        else
            return false;
    }
    bool operator!=(const big_num& b)
    {
        if((*this) == b)
            return false;
        else
            return true;
    }
//-------Арифметика-------------------------
    big_num operator- (big_num&  b)
    {
        big_num ans;

        if(flag)
        {
            if(b.flag)
            {
                if((*this) >= b)
                {
                    ans = (*this).razofbig(b);
                    ans.flag = true;
                }else
                {
                    ans = b.razofbig(*this);
                    ans.flag = false;
                }
            }else
            {
                ans = b.sumofbig(*this);
                ans.flag = true;
            }
        }else
        {
            if(b.flag)
            {
                ans = b.sumofbig(*this);
                ans.flag = false;
            }else
            {
                if(b <= (*this))
                {
                    ans = b.razofbig(*this);
                    ans.flag = true;
                }else
                {
                    ans = (*this).razofbig(b);
                    ans.flag = false;
                }
            }
        }

        return ans;
    }
    big_num operator+ (big_num&  b)
    {
        big_num ans;

        if(flag)
        {
            if(b.flag)
            {
                ans = b.sumofbig(*this);
                ans.flag = true;
            }else
            {
                if((*this) >= -b)
                {
                    ans = (*this).razofbig(b);
                    ans.flag = true;
                }else
                {
                    ans = b.razofbig(*this);
                    ans.flag = false;
                }
            }
        }else
        {
            if(b.flag)
            {
                if(-(*this) >= b)
                {
                    ans = (*this).razofbig(b);
                    ans.flag = false;
                }else
                {
                    ans = b.razofbig(*this);
                    ans.flag = true;
                }
            }else
            {
                ans = b.sumofbig(*this);
                ans.flag = false;
            }
        }

        return ans;
    }
    void    operator+=(big_num&  b)
    {
        (*this) = (*this) + b;
    }
    void    operator-=(big_num&  b)
    {
        (*this) = (*this) - b;
    }
    big_num operator- (const LL& b)
    {
        big_num tmp(b);
        big_num ans;
        ans = (*this) - tmp;
        return ans;
    }
    big_num operator+ (const LL& b)
    {
        big_num tmp(b);
        big_num ans = (*this) + tmp;
        return ans;
    }
    void    operator+=(const LL& b)
    {
        (*this) = (*this) + b;
    }
    void    operator-=(const LL& b)
    {
        (*this) = (*this) - b;
    }
    big_num operator* (const LL& b)
    {
        big_num ans(*this);
        LL carry = 0;
            for (size_t i=0; i<ans.big.size() || carry; ++i) {
                if (i == ans.big.size())
                    ans.big.push_back (0);
                    long long cur = carry + ans.big[i] * b;
                    ans.big[i] = cur % 10;
                    carry = cur/10;
        }
        while (ans.big.size() > 1 && ans.big.back() == 0)
            ans.big.pop_back();
        return ans;
    }
    void    operator*=(const LL& b)
    {
        (*this) = (*this) * b;
    }
    big_num operator* (big_num& b)
    {
        vec<big_num> tmp;

        if((*this) >= b)
        {
            for(int i(0);i < b.big.size();i++)
            {
                tmp.push_back( (*this) * (LL)(b.big[i]) );
            }
        }else
        {
            for(int i(0);i < big.size();i++)
            {
                tmp.push_back( b * (LL)big[i] );
            }
        }

        int ind = 1;

        big_num ans(tmp[0]);

        for(int i(1);i < tmp.size();i++)
        {
            for(int j(0);j < ind;j++)
            {
                tmp[i] *= 10;
            }
            ind++;

            ans += tmp[i];
        }

        return ans;
    }
    void    operator*=(big_num& b)
    {
        (*this) = (*this) * b;
    }
    pair<big_num,big_num> division(const LL& bc)
    {
        big_num a(*this);
        a.flag = true;
        LL b = (bc > 0?bc : -bc);
        big_num num,tmp = 0;
        num = 0;

        bool tep,flag;

        tep = flag = true;

        while(a.big.size())
        {
            //cout << tmp << " -> ";

            int qqq = tmp.big.size();
            for(int i(a.big.size()-1);i >= 0 && (LL)tmp < b;i--)
            {
                tmp.big.insert(tmp.big.begin(),a.big[i]);
                a.big.pop_back();
            }

            if((LL)tmp < b) break;

            if(tep)
            {
                tep = false;
            }else
            {
                for(int i(0);i < (tmp.big.size() - qqq-1);i++)
                    num.big.insert(num.big.begin(),0);
            }

            if((LL)tmp < b) break;

            LL q = (LL)tmp / b;
            LL g = q;
            vint f;
            while(q)
            {
                f.push_back(q%10);
                q /= 10;
            }

            reverse(f.begin(),f.end());

            num.big.insert(num.big.begin(),f.begin(),f.end());
            tmp -= (g*b);
            //cout << tmp << '\n';
        }

        return mp(num,tmp);
    }
    big_num operator/ (const LL& b)
    {
        big_num ans;
        ans = (*this).division(b).first;

        if((b > 0 && (*this).flag) || (b < 0 && !(*this).flag))
            ans.flag = true;
        else
            ans.flag = false;

        return ans;
    }
    big_num operator% (const LL& b)
    {
        big_num ans;
        ans = (*this).division(b).second;

        if((b > 0 && (*this).flag) || (b < 0 && !(*this).flag))
            ans.flag = true;
        else
            ans.flag = false;

        return ans;
    }
//------------------------------------------
//------Преобразование к типу LL -----------

    operator LL()
    {
        LL ans = 0;
        big_num b(*this);

        while(b.big.size())
        {
            ans = ans*10 + b.big.back();
            b.big.pop_back();
        }
        return ans;
    }

//------------------------------------------
//------Унарные операции--------------------
    //смена знака на противоположный--------
    big_num operator-()
    {
        big_num q(*this);

        if(flag)
            q.flag = false;
        else
            q.flag = true;
        return q;
    }
    //модуль числа--------------------------
    big_num abs()
    {
        big_num ans(*this);
        ans.flag = true;

        return ans;
    }
    //квадрат числа-------------------------
    big_num sqr()
    {
        return (*this) * (*this);
    }
//------------------------------------------
};

big_num binpow(int n,int m)
{
    if(m == 0) return 1;

    if(m % 2)
        return binpow(n,m/2)*binpow(n,m/2)*(LL)n;
    else
        return binpow(n,m/2)*binpow(n,m/2);
}

bool solve()
{
    /*double t1,t2;
    t1 = clock();*/
    setlocale(LC_ALL,"Russian");
    ios_base::sync_with_stdio(0);
    ifstream fin("in.txt");
    ofstream fout("out.txt");

     string a;
    vint b;

    cin >> a;

    for(int i(0);i < a.size();i++)
    {
        switch(a[i])
        {
        case '>' : b.push_back(1),b.push_back(0),b.push_back(0),b.push_back(0);break;
        case '<' : b.push_back(1),b.push_back(0),b.push_back(0),b.push_back(1);break;
        case '+' : b.push_back(1),b.push_back(0),b.push_back(1),b.push_back(0);break;
        case '-' : b.push_back(1),b.push_back(0),b.push_back(1),b.push_back(1);break;
        case '.' : b.push_back(1),b.push_back(1),b.push_back(0),b.push_back(0);break;
        case ',' : b.push_back(1),b.push_back(1),b.push_back(0),b.push_back(1);break;
        case '[' : b.push_back(1),b.push_back(1),b.push_back(1),b.push_back(0);break;
        case ']' : b.push_back(1),b.push_back(1),b.push_back(1),b.push_back(1);break;
        }
    }

    big_num ans = 0;

    reverse(b.begin(),b.end());

    for(int i(b.size()-1);i >= 0;i--)
    {
        ans += b[i] * binpow(2,i) % base;
    }

    cout << ans % base;

    /*t2 =clock()-t1;
    cout.precision(15);
    cout << "\ntime = " << t2/(CLOCKS_PER_SEC*1000) << " секунд\n";*/

    _getch();
    return true;
}

int main(int argc,char** argv)
{
    //while(solve());
    solve();

    //_getch();
    return 0;
}


//============================================================================
// Name        : jedi.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <sstream>
#include <stack>
#include <unordered_map>

using namespace std;

#define LOCAL

using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> VI;

//copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter(ws));

template<class T>
ostream& operator<< (ostream& fout, const vector<T>& vec) {
    for (size_t i = 0; i < vec.size(); ++i) {
        fout << vec[i] << ' ';
    }
    return fout;
}

template <class T>
istream& operator>> (istream& fin, vector<T>& vec) {
    for (size_t i = 0; i < vec.size(); ++i) {
        cin >> vec[i];
    }
    return fin;
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "wt", stdout);
#endif

    int X[3] = {0, 0, 0};
    int n, x;
    cin >> n >> x;
    X[x] = 1;

    n = n % 7;
    while (n) {
    	if (n % 2 == 0)
    		swap(X[1], X[2]);
    	else
    		swap(X[0], X[1]);
    	--n;
    }

    for (int i = 0; i < 3; ++i) {
    	if (X[i] == 1) {
    		cout << i << "\n";
    		break;
    	}
    }
	return 0;
}


/*
Author- Aasav Badera
Time- Fri Sep  4 14:04:20 2020
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef LOCAL
#include <sys/resource.h>
#define meminc             rlimit rlim;if (getrlimit(RLIMIT_STACK, &rlim)) return 1;rlim.rlim_cur = 268435456;if (setrlimit(RLIMIT_STACK, &rlim)) return 2;
#else
#define meminc
#endif
#ifdef LOCAL
#define dbg(args...)       { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
#define dbg(args...)
#endif
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#define ll                 int
#define vi                 vector<int >
#define ordered_set        tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// -------------------Standard Traversal Moves---------------------
// vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------

#define rep(i, a, b)       for(int  i=a;i<b;i++)
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (int )x.size()
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define endl               '\n'
// const int hell = (int)998244353;
const int hell = (int)1e9 + 7;
const long long int inf = 3223372036854775807;
const double PI = 3.14159265;
const int N = (int) 1e6 + 5;
int n, m, k, a[N];

bool vis[1001][1001];
bool check(int _x ,int _y)
{
    return (_x > -1 and _x < n and _y > -1  and _y < m);
}
int32_t main()
{
    meminc;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cerr.precision(10);
    cout.precision(25);
    cout << fixed;
    #ifdef LOCAL
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    int tests = 1;
    // cin >> tests;
    rep(test, 1, tests+1)
    {
        cin >> n;
        cin >> m;
        int counter = 0;
    	memset(vis, 0, sizeof vis);
    	for(int i = 0; i < n; i++)
    	{
    		for(int j = 0 ; j < m; j++)
    		{
    			if((i + j) % 2 == 0)
    			{
    				counter++;
    				vis[i][j] = 1;
    				for(int l = 0; l < 8; l++)
    				{
    					int nx = i + fx[l], ny = j + fy[l];
    					if(!check(nx, ny))continue;
    					vis[nx][ny] = 1;
    				}
    			}
    		}
    	}
    	// cerr << counter << endl;
    	for(int i = 0; i < n; i++)
    	{
    		for(int j = 0 ; j < m; j++)
    		{
    			if(!vis[i][j])
    			{
    				counter++;
    				vis[i][j] = 1;
    				for(int l = 0; l < 8; l++)
    				{
    					int nx = i + fx[i], ny = j + fy[i];
    					if(!check(nx, ny))continue;
    					vis[nx][ny] = 1;
    				}
    			}
    		}
    	}
    	cout << counter;
    }
    #ifdef LOCAL
        // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+15;
const int mod = 1e9+7;

int dp[N],val[N];
int per[N],perInverse[N];

int add(int x,int y) {
   int ret = (x+y)%mod;
   if(ret<0) {
      ret += mod;
   }
   return ret;
}

int mul(int x,int y) {
   ll ret = (ll)x*y;
   ret%=mod;
   return ret;
}
int combi(int n,int k) {
   assert(n>=k);
   int ret = mul(per[n],perInverse[k]);
   ret = mul(ret, perInverse[n-k]);
   return ret;
}

vector<int> divisor[N];

bool isCandidate[N];
int ret[N],len[N];
int myPow(int x,int cc) {
   int ret = 1;
   while(cc>0) {
      if(cc&1) {
         ret = mul(ret, x);
      }
      cc/=2;
      x = mul(x,x);
   }
   return ret;
}

int numOfDiv[N];
bool vis[N];
int gcd(int a,int b) {
   if(a==0) {
      return b;
   }
   return gcd(b%a,a);
}
int find(int n,int cur,int sum,int maxi) {
   if(dp[cur]==maxi) {
      return 1;
   }
   int R = 0;
   for(int i=0;i<divisor[cur].size();++i) {
      int x = divisor[cur][i];
      int k = n/cur - n/x;
      int tmp;
      if(cur!=1) {
         tmp =  mul(per[k], combi(sum + k-1,k-1));
         tmp = mul(tmp,find(n,x,sum + k,maxi));
      } else {
         tmp = per[k];
         tmp = mul(tmp,find(n,x,sum + k,maxi));
      }
      R = add(R,tmp);
   }
   return R;
}

void solve() {
   int n;
   scanf("%d",&n);
   per[0] = 1;
   perInverse[0] = 1;
   for(int i=1;i<=n;++i) {
      dp[i] = 1;
      per[i] = mul(per[i-1],i);
      perInverse[i] = myPow(per[i],mod-2);
   }
   dp[1] = 0;
   int maxi = 1;
   for(int i=1;i<=n;++i) {
      maxi = max(maxi, dp[i]);
      for(int j = i+i;j<=n;j+=i) {
         dp[j] = max(dp[j], dp[i]+1);
         ++numOfDiv[j];
      }
   }
   for(int i=n;i>=1;--i) {
      if(isCandidate[i] || dp[i]==maxi) {
         isCandidate[i] = true;
      }
      if(!isCandidate[i]) {
         for(int j = i+i;j<=n;j+=i) {
            if(isCandidate[j] && dp[j]== dp[i]+1) {
               isCandidate[i] = true;
               divisor[i].push_back(j);
            }
         }
      }
   }
   assert(isCandidate[1]);
   int R = find(n,1,0,maxi);
   printf("%d\n", R);
}

int main(){
   //freopen("input.txt","r",stdin);
   solve();
   return 0;
}


#include <stdio.h>
#include<iostream>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <memory.h>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
#define fin for (i=0; i<n; i++)
typedef long long li;
typedef long double ld;
#define mp make_pair
#define pb push_back
typedef pair <int, int> pi;
typedef vector <int> vi;
const li p=1000000007;
const ld PI=3.14159265358979323846264338327950288419716939937510;
void prepare ()
{
#ifdef _DEBUG
	freopen ("in.txt", "r", stdin);
#endif
}

int main ()
{
	prepare ();
	int n;
	cin>>n;
	int k=n;
	int i;
	for (i=1; i*i<=k; i++)
	{
		if (n%i==0)
		{
			cout<<(n/i)<<" ";
			n/=i;
		}
	}
	cout<<"1";
	return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second

#define ll long long
#define ld long double
#define ull unsigned long long

#define pb push_back
#define ppb pop_back
#define mp make_pair

#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define bit(x) __builtin_popcountll(x)
#define sqr(x) ((x) * 1LL * (x))

#define nl '\n'
#define ioi exit(0);

#define NeedForSpeed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define _11day "IOI2017"

using namespace std;

typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ld, ld> pdd;
typedef pair <ll, ull> hack;

const int N = 1e5 + 7, MxN = 1e6 + 7, mod = 1e9 + 7, inf = 1e9 + 7;
const long long linf = (ll)1e18 + 7;
const long double eps = 1e-15, pi = 3.141592;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

    inline ll Pw(ll a, ll b, ll m) {
        ll res = 1;
        a %= m;
        while (b){
            if (b & 1) res = (res * a) % m, b--;
            a = (a * a) % m,  b >>= 1;
        }
        return res % m;
    }

    inline bool fast(ll d, ll n){
        ll a = 2 + rand() % (n - 4), x = Pw(a, d, n);
        if (x == 1 || x == n - 1) return 1;
        while (d != n - 1){
            x = (x * x) % n, d *= 2;
            if (x == 1) return 0;
            if (x == n - 1) return 1;
        }
        return 0;
    }

    inline bool Check(int n, int k = 100){
        if (n <= 1 || n == 4) return 0;
        if (n <= 3) return 1;

        ll d = n - 1;
        while (d % 2 == 0) d >>= 1;

        for (int i = 1; i <= k; i++)
            if (!fast(d, n)) return 0;
        return 1;
    }

    inline bool Check2(int x){
        if (x < 2) return 0;
        for (int i = 2; i <= sqrt(x); i++)
            if (x % i == 0) return 0;
        return 1;
    }

    inline ll Solve(ll n){
        ll res = 0;
        while (n > 0){
            if (n < 4 || Check(n)){
                res++;
                break;
            }
            for (int i = n - 2; i >= 2; i--)
                if (Check(i)) {n -= i, res++; break;}
        }
        return res;
    }
int main(){
    #ifndef _11day
        freopen (_11day".in", "r", stdin);
        freopen (_11day".out", "w", stdout);
    #endif

    ll n, res = inf, ans = 0;
    cin >> n;
    if (Check2(n)) cout << 1, ioi
    for (ll i = 1; i <= sqrt(n); i++){
        if (n % i == 0){
            if (i > 1) res = min(res, i);
            if (sqr(i) != n)
                res = min(res, n / i);
        }
    }
    cout << res;

    ioi
}


#include <iostream>
typedef long long ll;
using namespace std;

int main() {
	ll n;
	cin>>n;
	while(n>=0)
	{
	    ll p=n%10;

	    if(p==0){cout<<"O-|-OOOO"<<endl;}
	    else if(p==1){cout<<"O-|O-OOO"<<endl;}
	    else if(p==2){cout<<"O-|OO-OO"<<endl;}
	    else if(p==3){cout<<"O-|OOO-O"<<endl;}
	    else if(p==4){cout<<"O-|OOOO-"<<endl;}
	    else if(p==5){cout<<"-O|-OOOO"<<endl;}
	    else if(p==6){cout<<"-O|O-OOO"<<endl;}
	    else if(p==7){cout<<"-O|OO-OO"<<endl;}
	    else if(p==8){cout<<"-O|OOO-O"<<endl;}
	    else if(p==9){cout<<"-O|OOOO-"<<endl;}
	    n=n/10;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int t, n, k, l;
int d[200];
int p[210];
int f[200][200];
void init()
{
    p[0] = 0;
    for (int i = 1; i <= k; i++)
        p[i] = i;
    for (int i = k + 1; i <= 2 * k; i++)
        p[i] = 2 * k - i;
}
int main()
{
    ios::sync_with_stdio(false);
    cin >> t;
    while (t--)
    {

        cin >> n >> k >> l;
        init();
        for (int i = 1; i <= n; i++)
            cin >> d[i];
        memset(f, 0, sizeof(f));
        if (d[1] <= l)
            f[0][1] = 1;
        int flag = 0;
        for (int j = 1; j <= 2 * k * n; j++)
        {
            for (int i = 1; i <= n; i++)
            {
                if (p[j % (2 * k)] + d[i] <= l)
                    f[j][i] = max(f[j - 1][i], f[j - 1][i - 1]);
                if (f[j][n])
                {
                    flag = 1;
                    break;
                }
            }
        }
        if (flag)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}


#include<iostream>
#include <vector>
#include <algorithm>
#include <string>

#define pb push_back
#define all(a) a.begin(),a.end()
#define fc for_each
using namespace std;

string str, str1;
int sizee, counter=0, save=2;

int main() {
	cin >> sizee >> str;
	str1.pb(str[0]);
	for (int k = 1; k < str.size(); k++) {
		if (str[k] == str[k + 1])
		{
			counter++;
		}
		else
		{
			for (int i = 0; i < (counter > save) ? counter / save: 1; i++) {
				str1.pb(str[k]);
			}
			counter = 0;
			save++;
		}

	}
	cout << str1;
	return 0;
}


#include<iostream>
using namespace std;
main()
{ int n;
cin>>n;
char str[101];
cin>>str;
char temp;
int i,j,k;
for(i=n;i>=2;i--)
if(n%i==0)
for(j=0,k=i-1;j!=k;j++,k--)
{ temp=str[k];
str[k]=str[j];
str[j]=temp;
}

cout<<str;
return 0;}


#include <bits/stdc++.h>

using namespace std;

int main(){

	double a, b, c, d;

	cin >> a >> b >> c >> d;

	double n = b - a;
	double m = b/a;

	if(c - b == n && d- c == n) cout << d + n;
	else if (c/b == m && d/c == m) cout << d*m;
	else cout << 42;
	system("pause>null");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MN = 725;
const ll MAX = 1e3 + 5;
int main () {
	ll n, id = 0;
	vector <ll> a;
	/*
	for (int i = 1; i <= 25; i++){
		for (int j = 1; j <= 25; j++){
			if (i > j){
				ll x = i*i - j*j;
				a.push_back(x);
			}
		}
	}
	sort (a.begin(), a.end());*/
	a.push_back(3);
	for (int i = 1; i <= 10000; i++){
		a.push_back(4*i);
		a.push_back(4*i+1);
		a.push_back(4*i+3);
	}
	cin >> n;
	cout << a[n];
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main()
{
	int h1,h2;
	int a,b;
	scanf("%d %d %d %d",&h1,&h2,&a,&b);
	int ans=0;
	h1+=8*a;
	if(h1>=h2)
	{
		printf("0\n");
		return 0;
	}
	if(a<b&&h1<h2)
	{
		printf("-1\n");
		return 0;
	}
	int k=a*12-b*12;
	int f=h2-h1;
	if(f<k)  ans=1;
	else
	{
		int ff=h2-h1;
		if(ff%k==0)  ans=(h2-h1)/k;
		else  ans=(h2-h1)/k+1;
	}
	printf("%d\n",ans);
//	cout<<"klalalla"<<endl;

	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:16777216")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include <string>
#include <list>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <sstream>
#include <assert.h>
#include <functional>
#include <climits>
#include <cstring>

typedef long long ll;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

using namespace std;

std::vector<__int64> F;

int main()
{
#if defined(_DEBUG) || defined(_RELEASE)
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
    //freopen(File".in", "r", stdin); freopen(File".out", "w", stdout);
#endif

//  return 0;
    //cout << "SDSD";
    F.push_back(1);
    F.push_back(1);
    ll c = 1;
//  cout << "SaaaaaD";
    while (F[c] < 10000000000000000000)
    {
        F.push_back(F[c - 1] + F[c]);
        c++;
    }
//  cout << "SDSD";
    __int64 n;
    cin >> n;
    __int64 k;
    cin >> k;
    ll printed=0;

    while (printed < n)
    {
        if (n - printed > c)
        {
            cout << 1 + printed << " ";
            printed++;
        }
        else
            if (k <= F[n-printed - 1])
            {
                cout << 1 + printed << " ";
                printed++;
            }
            else
            {
                cout << 2 + printed << " " << 1 + printed<<" ";
                k = k - F[n - 1 - printed];
                printed++;
                printed++;
            }

    }

    return 0;

}


#include<cstdio>
using namespace std;
int main()
{
    return !puts("INTERCAL");
}


#include<iostream>
#include<cmath>

using namespace std;

int main()
{
    int A[99999999];
    int a, b, m, i = 1;
    cin >> a >> b >> m >> A[0];
    bool Is = true;
    while (Is)
    {
        A[i] = (a * A[i - 1] + b) % m;
        for (int j = 1; j < i; ++j)
        {
            if (A[j] == A[i])
            {
                cout << i - j;
                Is = false;
            }
        }
        ++i;
    }
}


#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
using namespace std;

int main(){
	int n;
	cin >> n;
	string l;
	cin >> l;
	for (int i = 0; i < n - 4; i++)
	{
		if (l[i] == '*'){
			for (int j = i + 1; j < n; j++)
			{
				if (l[j] == '*' && i + (j - i) * 3 < n && l[i + (j - i) * 2] == '*' && l[i + (j - i) * 3] == '*'){
					cout << "yes";
					return 0;
				}
			}
		}
	}
	cout << "no";
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int solve(int n, int m) {
  if (n<m) swap(n,m);

  int dx[] = {0,-1,0,1,0};
  int dy[] = {0,0,-1,0,1};
  int res = INF;
  REP(S, 1<<m) {
    bool ba[n][m];
    memset(ba,0,sizeof(ba));
    int cnt = 0;
    REP(i,m) {
      if (S>>i&1) {
        ba[0][i] = 1;
        if (i) ba[0][i-1] = 1;
        if (i<m-1) ba[0][i+1] = 1;
        if (n>=2) ba[1][i] = 1;
        cnt++;
      }
    }
    for (int i=1; i<n; ++i) {
      REP(j, m) {
        if (!ba[i-1][j]) {
          REP(k,5) {
            int ii = i+dx[k];
            int jj = j+dy[k];

            if (ii<0||ii>=n||jj<0||jj>=m) continue;
            ba[ii][jj] = 1;
          }
          cnt++;
        }
      }
    }
    REP(j, m-1) {
      if (!ba[n-1][j]) {
        ba[n-1][j] = 1;
        ba[n-1][j+1] = 1;
        if (j+2<m) ba[n-1][j+2] = 1;
        cnt++;
      }
    }
    if (!ba[n-1][m-1])cnt++;

    res = min(res, cnt);
  }
  return n*m-res;
}
int main() {
  int n,m;
  cin >> n>>m;
  cout << solve(n,m) << endl;
}


#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define rep(i,a,b) for (int i = a; i <= b; ++i)
#define dep(i,a,b) for (int i = a; i >= b; --i)

const int mod = 1000000007;
int n,a,b,k;
long long f[5010][5010],c[5010];
int main() {
	scanf("%d%d%d%d",&n,&a,&b,&k);
	f[0][a]=1;
	rep(i,0,k-1) {
		rep(j,0,n+1) c[j]=0;
		rep(j,1,n) {
			int s,t;
			int len=abs(b-j)-1;
			if (len<0) continue;
			s=max(1,j-len),t=min(n,j+len);
			if (j==s) s++;
			else if (j==t) t--;
			if (s>t) continue;
			c[s]+=f[i][j]; c[s]%=mod;
			c[t+1]-=f[i][j]; c[t+1]%=mod;
			if (s<j&&j<t) {
				c[j]-=f[i][j]; c[j]%=mod;
				c[j+1]+=f[i][j]; c[j+1]%=mod;
			}
		}
		int sum=0;
		rep(j,1,n) {
			sum+=c[j];
			sum%=mod;
			if (j==b) { f[i+1][j]=0;continue; }
			f[i+1][j]=sum;
		}
	}
	long long ans=0;
	rep(i,1,n) ans=(ans+f[k][i])%mod;
	printf("%lld\n",ans);
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <array>
#include <deque>
#include <string>
#include <forward_list>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <iomanip>
#include <fstream>
#include <bitset>
#define Endl endl;
using namespace std;
typedef long long ll;
typedef long double ld;
ll n,m;
vector<int>g;
vector<int>h;
ll ans;
map<ll,ll>t;
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    //  ifstream fin("sight.in");
    //  ofstream fout("sight.out");
    cin>>n>>m;
    g.push_back(0);
    h.push_back(0);
    int r,t;
    for(int i=3; i; i+=6){
        g.push_back(i);
        r++;
        if(r==m){
            break;
        }
    }
    for(int i=2; i; i+=2){
        if(i%3==0){
            continue;
        }
        h.push_back(i);
        t++;
        if(t==n){
            break;
        }
    }

    for(int i=6; i<max(g[g.size()-1],h[h.size()-1]); i+=6){
        if(g[g.size()-1]>h[h.size()-1]){
            g.pop_back();
        }
        else{
            h.pop_back();
        }
    }

    cout<<max(g[g.size()-1],h[h.size()-1])<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N = 1000100;
int a[N];
ll mp = 1000000007;
ll exp(ll x, ll n,ll p)
{
	if(n==0)
		return 1;
	ll w = exp(x,n/2,p);
	w=w*w%p;
	if(n%2==0)
		return w;
	return w*x%p;
}
bool df[N]={0};
ll val[N];
int main()
{
	int p,k;
	cin>>p>>k;
	if(k==0)
	{
		cout<<exp(p,p-1,mp)<<endl;
		return 0;
	}
	val[0]=1;
	for(int i=1;i<=p;i++)
	{
		val[i]=val[i-1]*k%p;
	}
	for(int i=0;i<p;i++)
	{
		a[i]=(i*k)%p;
	}
	ll res = 1;
	for(int i=0;i<p;i++)
	{
		if(df[i])continue;
		int j = i;
		int cnt = 1;
		while(1)
		{
			df[j]=1;
			j=a[j];
			if(j==i)break;
			cnt++;
		}
		if(val[cnt]==1)
		{
			res*=p;
			res%=mp;
		}
	}
	cout<<res<<endl;
}


#include<bits/stdc++.h>

#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define sqr(a) ((a)*(a))
#define bs ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int ll

using namespace std;

const int N=200003;
const int M=32;
const int inf=2e9;
const int md=1e9+7;

int n,sm,ans;
int a[7010][7010];

void dfs(int a1,int a2)
{
    if(a1>=n||a2>=n)
    {
        if(a1==n||a2==n)
        ans=min(ans,a[a1][a2]);
        return  ;
    }
    if(a1+a2<=n)
    if(a[a1+a2][a2]>a[a1][a2]+1)
    {
        a[a1+a2][a2]=a[a1][a2]+1;
        dfs(a1+a2,a2);
    }
    if(a1+a2<=n)
    if(a[a1][a1+a2]>a[a1][a2]+1)
    {
        a[a1][a1+a2]=a[a1][a2]+1;
        dfs(a1,a1+a2);
    }

}

main()
{
    bs;
    cin>>n;
        for(int i=0;i<=n;++i)
        {
            for(int j=0;j<=n;++j)
            {
                a[i][j]=inf;
            }
        }
        ans=inf;
        a[1][1]=0;
        dfs(1,1);
        cout<<ans<<endl;

}

/*

*/


#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
#include <iostream>
using namespace std;
long long a,b,n ,x;
long long ans;
long long M = 1e9+7;
long long calc( int n){
	if(n == 0) return x;

	return (a*calc(n-1) +b)%M ;
}

int main() {
	cin>>a>>b>>n>>x;

	int i=0;
	long long ans =0 ;

	cout<<calc(n);

	return 0;
}


//
//  main.cpp
//  test
//
//  Created by Amineh Ahmadinejad on 7/29/1397 AP.
//  Copyright © 1397 Amineh Ahmadinejad. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
using namespace std;

const int MAXN = 100* 1000;
long long primes[MAXN];

void compP(){
    int i = 0;
    primes[i++] = 2;
    for (long long j = 3; i < MAXN; j+=2){
        for (int k = 0; primes[k]*primes[k] <= j; k++){
            if (j % primes[k] == 0)
                goto notPrime;
        }
        primes[i++] = j;
    notPrime:;
    }
}

int main(int argc, const char * argv[]) {
//    int n, m, k, l;
//    cin >> n >> m >> k >> l;
//
//    for (int c = (l+k)/m; c <= (n/m); c++){
//        if (m*c >= (l+k) && m*c <= n) {
//            cout << c << endl;
//            return 0;
//        }
//    }
//    cout << -1 << endl;

    compP();
    long long b;
    cin >> b;
    vector <long long> multiples;
    for (int i = 0; primes[i] <= b; i++) {
        long long tmp = 0;
        while ( i < MAXN && b%primes[i] == 0) {
            tmp++;
            b/= primes[i];
        }
        multiples.push_back(tmp);
    }

    long long ans = 1;
    for (long long i = 0; i < multiples.size(); i++)
        ans *= (multiples[i]+1);

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int SIZE = 1005;

int dp[SIZE][SIZE];

void change(int S, int n) {

    for(int i = 0; i <= min(SIZE - 1, S); i++) {
        dp[i][1] = i;

        for(int j = min(SIZE - 1, n); j >= 0;j--) {
            if(i <= j) {
                dp[i][j] = 1;
            }
        }
    }

    for(int i = 0; i <= min(SIZE, S); i++) {
        for(int j = 0; j <= min(SIZE, n); j++) {
            dp[i][j] = min(dp[i][j - 1], dp[i - j][j]);
        }
    }
}

int minChange(int S, int n) {

    if((S <= SIZE && n <= SIZE) && dp[S][n] > 0)
        return dp[S][n];

    if(n == 1)
        return S;
    if(S <= n) {
        return 1;
    }

    return min(minChange(S, n - 1), minChange(S - n, n) + 1);
}

int main() {
    int n, S;
    cin >> n >> S;

    if(S <= n) {
        cout << 1 << endl;
        return 0;
    }

    change(S, n);
    cout << minChange(S, n) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k,a,b;
    cin >> k >> a >> b;
    int cnt = 0;
    while(1)
    {
        if(max(a,b) < k)    break;
        if(a > b)   a -= k;
        else        b -= k;
        cnt++;
    }
    if((a+b)%k == 0)    a = 0,b = 0, cnt += (a+b)/k;
    if(a && b)  printf("-1");
    else    printf("%d",cnt?cnt:-1);
    return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <cctype>
#include <list>

#define INF 2000000000
#define y1 dfhjghakgh

using namespace std;

const int base = (int)1e9+7;

long long f[10001];
int n, m;

//(n-m)^(n-m)*f[m]

long long binpow (long long a, int n) {
	if (n == 1)
		return (a % base);
	if (n % 2 == 1)
		return (binpow (a, n-1) * a) % base;
	else {
		int b = (binpow (a, n/2)) % base;
		return (b * b) % base;
	}
}
int main(){
   // freopen("input.txt","r",stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    long long ans = (binpow(n-m,n-m) * binpow(m,m-1)) % base;
    cout << ans;
    return 0;
}


/*

Sviatoslav Bidzilia 2019
CF: anakib1

*/

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)

template<typename A, typename B, typename C>
struct triple
{
	A X;
	B Y;
	C Z;
	triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0)
{
	return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b)
{
	if (a.X != b.X)
		return a.X < b.X;
	if (a.Y != b.Y)
		return a.Y < b.Y;
	return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p)
{
	ofs << "( " << p.F << " , " << p.S << " )";
	return ofs;
}
template<typename T>
void print(T a)
{
	for (auto i : a)
		cout << i << ' ';
	cout << '\n';
}
template<typename T>
T max(T a, T b, T c)
{
	return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c)
{
	return min(a, min(b, c));
}
struct custom_hash
{
	static uint64_t splitmix64(uint64_t x)
	{
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const
	{
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
int dp[101][101][10001];
signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vi a(n);
	for (auto& i : a)
		cin >> i;
	int sum = accumulate(all(a), 0LL);
	SORT(a);
	int mxn = 100 * 100 + 10;
	dp[0][0][0] = 1;
	for (int i = 0; i < n;)
	{
		int k = 1;
		while (i + k < n && a[i + k] == a[i])k++;
		for (int b = 0; b <= i + k; b++)
			for (int j = 0; j <= a[i] * b; j++)
				for (int l = 0; l <= min(k, b); l++)
					if (j - l * a[i] >= 0)
						dp[i + k][b][j] = min(dp[i + k][b][j] + dp[i][b - l][j - l * a[i]], 2);
		i += k;
	}
	map<int, int> cnt;
	for (auto i : a)
		cnt[i]++;
	int ans = 0;
	if (cnt.size() == 2)
		ans = n;
	for (pii x : cnt)
		for (int take = 1; take <= x.second; take++)
			if (dp[n][take][take * x.first] == 1)
				ans = max(ans, take);

	cout << ans << '\n';
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <vector>
#include <complex>
#include <ctime>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define REP(i, n) for(int i = 0; i < n; ++i)
#define RREP(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i, x, y) for(int i = x; i <= y; ++i)
#define RFOR(i, x, y) for(int i = x; i >= y; --i)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define CLEAR(x) memset(x, 0, sizeof x);
#define COPY(FROM, TO) memcpy(TO, FROM, sizeof TO);
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define pb push_back
#define sqr(x) (x)*(x)
#define X first
#define Y second
const long double pi=acos(-1.0);
const long double eps = 1e-9;
string s;
int n;
int main () {
    cin >> s;
    n = s.length();
    if (s == "44") {
        cout << "NO";
        return 0;
    }
    int f = 0;
    int pos = -1;
    REP (i, n) {
        if (s[i] == '4')
            pos = i;
        if (s[i] != '4' && s[i] != '1') {
            f = 1;
        }
    }
    if (f) {
        cout << "NO";
        return 0;
    }
    if (s[0] == '4' && s[1] == '1') {
        cout << "NO";
        return 0;
    }
    FOR (i, 2, n - 1) {
        if (s[i] == '4' && s[i - 1] == '4' && s[i - 2] == '4') {
            f = 1;
        }
    }
    if (f) {
        cout << "NO";
        return 0;
    }
    cout << "YES";
    return 0;
}


#include<bits/stdc++.h>
#include<complex>
using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef  vector<ll> vl;
typedef complex<double> point;
#define PB push_back
#define sc scanf
#define pf printf
#define X real()
#define Y imag()
#define pi 3.14159265359
//TAGTAGA
#define gym 2
#define fre 0
#define contest 1

int a[1001];

int main()
{
    // freopen ("myfile.txt","w+",stdout);

    ll n,k;
    cin>>n>>k;

    for(int i=log2(k)-1;; i++)
    {
        long long idx=pow(2,i-1);
        long long inc=idx*2;
        if(idx==k||(k-idx)%inc==0)
        {
            cout<<i;
            return 0;
        }

    }

    return 0;

}


#include <cstdio>
#include <vector>
#include <cstring>
#define MAXN 1000050
#define MAXK 50
#define INF 100000000
#define MOD 1000000007
#define REV ((MOD+1)/2)
#define mul(q,w) (((q)*1ll*(w))%MOD)
#define add(q,w) (((q)*1ll+(w))%MOD)
using namespace std;
int k,comb[MAXK][MAXK],pt[MAXK];
long long n;
typedef vector<int> vint;
typedef vector<vint> matrix;
matrix operator*(matrix &a,matrix &b)
{
	matrix c(a.size(),vint(b[0].size(),0));
	for(int k=0;k<b.size();k++)
		for(int i=0;i<a.size();i++)
			for(int j=0;j<b[0].size();j++)
				c[i][j]=add( c[i][j] , mul( a[i][k] , b[k][j] ) );
	return c;
}
int com(int a,int b)
{
	if(b<0) return 0;
	return comb[a][b];
}
int main()
{
	scanf("%lld %d",&n,&k);
	n--;
	pt[0]=1;
	for(int j=0;j<=k;j++)
	{
		comb[j][0]=1;
		comb[j][j]=1;
		if(j)
			pt[j]=mul(pt[j-1],2);
	}
	for(int i=1;i<=k;i++)
		for(int j=1;j<i;j++)
			comb[i][j]=add(comb[i-1][j-1],comb[i-1][j]);
	matrix mat(k*2+3,vint(k*2+3,0)),cur(k*2+3,vint(k*2+3,0)),bgn(1,vint(k*2+3,0));
	for(int i=0;i<=2*k+2;i++)
		cur[i][i]=1;
	for(int i=0;i<=k;i++)
		bgn[0][i]=pt[i];
	for(int i=k+1;i<=2*k+1;i++)
		bgn[0][i]=mul(pt[i-k-1] , 2);
	bgn[0][2*k+2]=1;
	for(int i=0;i<=2*k+1;i++)
		for(int j=0;j<=2*k+1;j++)
			if(i>=k+1 || j>=k+1)
				mat[i][j]=com(j % (k+1),( j % (k+1) ) - ( i%(k+1) ));
	mat[2*k+2][2*k+2]=mat[2*k+1][2*k+2]=1;
	for(int i=0;i<64;i++,mat=mat*mat)
		if((1ll << i) & n)
			cur=cur*mat;
	bgn=bgn*cur;
	printf("%d\n",bgn[0][2*k+2]);
	scanf(" ");
}


//
//  main.cpp
//  vk_cup
//
//  Created by Simp on 17.02.16.
//  Copyright © 2016 Simp. All rights reserved.
//

#include <iostream>
using namespace std;
long long int a,b,c,e=2520,cnt,d[1000009];

// 7 8
// 77 78 87 88
// 777 778 787 877 887 878 788 888

//
//
int main(){

    cin>>a;
    d[0]=1;

    for (long long i=1; i<=a*2; i++) {

        d[i]+=d[i-1]+6*i;

    }

    cout<<d[a];
    return 0;

}


#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pLL;
typedef pair<LD, LD> pDD;

#define INF 1000000007

#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front

LL n;

int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    LL ans=0;
    while(n>0){
        ans+=9;
        ans+=n%10;
        n/=10;
    }
    cout<<ans-9<<"\n";
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
	int x1,x2,x3;
	cin>>x1>>x2>>x3;
	int d1,d2,d3;
	d1=abs(x2-x1)+abs(x3-x1);
	d2=abs(x1-x2)+abs(x3-x2);
	d3=abs(x2-x3)+abs(x1-x3);
	if(d1<d2&&d1<d3)
	cout<<d1;
	else if(d2<d1&&d2<d3)
	cout<<d2;
	else if(d3<d2&&d3<d1)
	cout<<d3;

	system("pause");

	return 0;

}


#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int x;
    cin>>x;
    if((x%4)==1){//��������� �
        cout<<"0 A";
    }
    else if((x%4)==0){//��������� D
        cout<<"1 A";
    }
    else if((x%4)==3){//��������� B
        cout<<"0 B";
    }
    else if((x%4)==2){//��������� �
        cout<<"1 B";
    }
    system("pause");
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    int min = r;
    if(g < r) min = g;
    if(b < g) min = b;
    vector<int> possibilities;
    for(int i = 0; i <= min; i++) possibilities.push_back(i + (r - i) / 3 + (g - i) / 3 + (b - i) / 3);
    sort(possibilities.begin(), possibilities.end(), greater<int>());
    cout << possibilities.at(0) << endl;
    return 0;
}


#include <iostream>
#include<cmath>
#include<vector>
#include<tuple>
#include <ctime>
#include<algorithm>
#include <initializer_list>

#define tii tuple<int,int>
#define vi vector<int>
#define vii vector<vi>
#define ll long long int
#define vl vector<ll>
#define vll vector<vl>

#define mymod 1000000007

using namespace std;

ll solve(vl v) {
    sort(v.begin(), v.end());
    ll a = v[0];
    ll b = v[1];
    ll c = v[2];
    if(a == 0) {
        return min(b,(c+b)/3);
    }
    if(c-a<=1){
        return (a+b+c)/3;
    }
    if(a+b<=c){
        return 1 + solve({a,b-1,c-2});
    }
    return 1 + solve({a-1,b-1,c-1});
}

int main() {
    clock_t tstart = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // Start

    ll a,b,c;
    cin>>a>>b>>c;
    cout<<solve({a,b,c});

    // cout<<"\n\nTotal Time Taken : "<<(double)(-tstart + clock())/CLOCKS_PER_SEC<<"sec\n\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int tot, root;
map<int,int> mp;
struct node
{
    int l, r, cov, val;
    ll lsum, sum;
} tree[maxn*100];
void pushdown(int rt,int l,int r)
{
    if(!tree[rt].cov) return ;
    int mid = (l+r)>>1;
    if(!tree[rt].l) tree[rt].l = ++tot;
    if(!tree[rt].r) tree[rt].r = ++tot;
    int ls = tree[rt].l, rs = tree[rt].r;
    tree[ls].cov = 1;
    tree[ls].val = tree[rt].val;
    tree[ls].sum = (ll)(mid-l+1)*tree[rt].val;
    tree[ls].lsum = tree[rt].val < 0 ? tree[ls].sum : 0;
    tree[rs].cov = 1;
    tree[rs].val = tree[rt].val;
    tree[rs].sum = (ll)(r-mid)*tree[rt].val;
    tree[rs].lsum = tree[rt].val < 0 ? tree[rs].sum : 0;
    tree[rt].cov = tree[rt].val = 0;
}
void update(int &rt,int L,int R,int l,int r,int x)
{
    if(!rt) rt = ++tot;
    if(l >= L && r <= R){
        tree[rt].cov = 1; tree[rt].val = x;
        tree[rt].sum = (ll)(r-l+1)*x;
        tree[rt].lsum = x < 0 ? tree[rt].sum : 0;
        return ;
    }
    pushdown(rt,l,r);
    int mid = (l+r)>>1;
    if(mid >= L) update(tree[rt].l,L,R,l,mid,x);
    if(mid < R) update(tree[rt].r,L,R,mid+1,r,x);
    tree[rt].sum = tree[tree[rt].l].sum+tree[tree[rt].r].sum;
    tree[rt].lsum = min(tree[tree[rt].l].lsum,tree[tree[rt].l].sum+tree[tree[rt].r].lsum);
}
pair<double,ll> query(int &rt,int L,int R,int l,int r,ll x)
{
    if(!rt) return make_pair(0,0);
    if(l == L && r == R){
        if(x+tree[rt].lsum > 0) return make_pair(-1,tree[rt].sum);
        if(l == r || tree[rt].cov) return make_pair(L-x*1.0/(tree[rt].sum/(r-l+1)),tree[rt].sum);
    }
    pushdown(rt,l,r);
    int mid = (l+r)>>1;
    if(mid >= R) return query(tree[rt].l,L,R,l,mid,x);
    else if(mid < L) return query(tree[rt].r,L,R,mid+1,r,x);
    else{
        pair<double,ll> tmp1 = query(tree[rt].l,L,mid,l,mid,x);
        if(tmp1.first > 0) return tmp1;
        else{
            pair<double,ll> tmp2 = query(tree[rt].r,mid+1,R,mid+1,r,x+tmp1.second);
            return make_pair(tmp2.first,tmp1.second+tmp2.second);
        }
    }
}
int main()
{
    int n, op, x, y, z;
    scanf("%d",&n);
    int L = 1, R = 1e9;
    mp[L-1] = mp[R+1] = 0;
    while(n--){
        scanf("%d%d",&op,&x);
        if(op == 1){
            scanf("%d",&y);
            mp[x] = y;
            auto it = mp.find(x); it++;
            update(root,x,(*it).first-1,L,R,y);
        }
        else if(op == 2){
            auto it = mp.find(x), pre = it, nxt = it;
            --pre; ++nxt;
            update(root,x,(*nxt).first-1,L,R,(*pre).second);
            mp.erase(it);
        }
        else{
            scanf("%d%d",&y,&z);
            if(z == 0){ printf("%d\n",x); continue; }
            auto it = mp.lower_bound(x);
            if((*it).first >= y){ printf("-1\n"); continue; }
            pair<double,ll> ans = query(root,(*it).first,y-1,L,R,z);
            //cout<<"*"<<ans.first<<" "<<ans.second<<endl;
            if(ans.first < 0) printf("-1\n");
            else printf("%.8f\n",ans.first);
        }
    }
    return 0;
}


#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include <ctime>
#include <list>
#include <numeric>
#include <bitset>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <utility>
#include <fstream>
#include <sstream>
#include <cmath>
#include <stack>
#include <assert.h>
using namespace std;

#define inf             0x3f3f3f3f
#define INF             2e18
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define SQR(a)          ((a)*(a))
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end()
#define MEM(a, b)       memset(a, (b), sizeof(a))
#define CLR(a)          memset(a, 0, sizeof(a))
#define MAX(a, b)       ((a) > (b) ? (a) : (b))
#define MIN(a, b)       ((a) < (b) ? (a) : (b))
#define MIN3(a,b,c)     MIN(a,MIN(b,c))
#define MAX3(a,b,c)     MAX(a,MAX(b,c))
#define MIN4(a,b,c,d)   MIN(MIN(a,b),MIN(c,d))
#define MAX4(a,b,c,d)   MAX(MAX(a,b),MAX(c,d))
#define MAX5(a,b,c,d,e) MAX(MAX3(a,b,c),MAX(d,e))
#define MIN5(a,b,c,d,e) MIN(MIN(a,b,c),MIN(d,e))
#define Iterator(a)     __typeof__(a.begin())
#define rIterator(a)    __typeof__(a.rbegin())
#define FOR(a,it)       for(Iterator(a) it = a.begin();it != a.end(); it++)
#define rFOR(a,it)      for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define For(I,A,B)      for(int I = (A); I  < (B); ++I)
#define rFor(I,A,B)     for(int I = (A); I >= (B); --I)
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
#define sci(a)          scanf("%d",&a)
#define scc(a)          scanf("%c",&a)
#define sci2(a,b)       sci(a) , sci(b)
#define sci3(a,b,c)     sci(a), sci(b), sci(c)
#define sci4(a,b,c,d)   sci(a), sci(b), sci(c), sci(d)
#define scl(a)          scanf("%lld", &a)
#define scl2(a,b)       scl(a) , scl(b)
#define scl3(a,b,c)     scl(a), scl(b), scl(c)
#define scl4(a,b,c,d)   scl(a), scl(b), scl(c), scl(d)
#define ABS(x)          ((x)<0?-(x):(x))
#define SORT(v)         sort(v.begin(),v.end())
#define SIZE(v)         (int) v.size()
#define REV(v)          reverse(v.begin(),v.end())
#define pf              printf
#define pfi(a)          pf("%d", a);
#define pfl(a)          pf("%lld", a);
#define sf(str)         getline(cin,str)
#define sff(str)        scanf("%[\n]s", str)

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

typedef pair <int, int> PII;
typedef pair <LL, LL> PLL;
typedef pair <double, double> PDD;
typedef vector <int> VI;
typedef vector <PII > VP;
typedef vector <double> VD;
typedef vector <LL> VL;

//#define DEBUG
bool prime[1000000003];

void Sieve(long long n)
{
    long long i, j;
    prime[0] = prime[1] = 1;

    for(i = 4 ; i < n ; i += 2)
    {
        prime[i] = 1;
    }

    for(i = 3 ; i <= n ; i += 2)
    {
        for(j = i+i ; j <= n && prime[i] == 0 ; j += i)
        {
            prime[j] = 1;
        }
    }
}

int main(){
#ifdef DEBUG
	freopen("G:\\input.txt","r",stdin);
	//	freopen("G:\\out.txt", "w", stdout);
	double start_time = clock();
#endif
    Sieve(1000000001);
    LL n;
    scl(n);
    int i = 2;
    LL cnt, ans = 0;
    while(n != 0){
        if(n%i == 0){
            cnt = (n/i);
            n -= (cnt*i);
            ans += cnt;
        }
        while(1){
            i++;
            if(prime[i] == 0) break;
        }
    }
    pfl(cnt);
#ifdef DEBUG
	double end_time = clock();
	fprintf(stderr, "\n\nTime = %.10lf seconds\n", (((end_time - start_time)) / CLOCKS_PER_SEC));
#endif
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void flipvert(vector<string>& str){
	int n = str.size();
	for(int i=0; i<n; i++){
		for(int j=0; j<n/2; j++){
			swap(str[i][j], str[i][n-1-j]);
		}
	}
}

void fliph(vector<string>& str){
	int n = str.size();
	for(int i=0; i<n/2; i++){
		for(int j=0; j<n; j++){
			swap(str[i][j], str[n-1-i][j]);
		}
	}
}

void rot(vector<string>& str){
	int n = str.size();
	vector<string> tmp = str;
	for(int i=0; i<n; i++){
		for(int j=n-1; j>=0; j--){
			tmp[i][n-1-j] = str[j][i];
		}
	}
	str = tmp;
}

bool check(vector<string>& str1, vector<string>& str2){
	int n = str1.size();
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(str1[i][j] != str2[i][j]){
				return false;
			}
		}
	}
	return true;
}

int main(void){
	int n;
	cin>>n;
	vector<string> str1(n), str2(n);
	for(int i=0; i<n; i++){
		cin>>str1[i];
	}
	for(int i=0; i<n; i++){
		cin>>str2[i];
	}
	if(check(str1, str2)){
		cout<<"Yes\n";
		return 0;
	}
	vector<int> track = {0, 1, 2, 3 ,4 ,5 ,6,7 ,8};
	vector<string> tmp = str1;
	for(int i=0; i<9; i++){
		if(track[i]>=0 && track[i]<=2){
			rot(tmp);
		}else if(track[i]<=5){
			flipvert(tmp);
		}else{
			fliph(tmp);
		}
		if(check(tmp, str2)){
			cout<<"Yes\n";
		return 0;
		}
	}
	while(next_permutation(track.begin(), track.end())){
		for(int i=0; i<9; i++){
		if(track[i]>=0 && track[i]<=2){
			rot(tmp);
		}else if(track[i]<=5){
			flipvert(tmp);
		}else{
			fliph(tmp);
		}
		if(check(tmp, str2)){
			cout<<"Yes\n";
		return 0;
		}
	}
	}
	cout<<"No\n";
	return 0;
}


#include <iostream>
#include <cstring>
#include <queue>
#define MAXN 2*1000+10
using namespace std;

struct node
{
	int x,y,step;
};

int dx[]={1,-1,1,-1,1,-1,0,0},dy[]={-1,1,1,-1,0,0,-1,1};
int mark[MAXN][MAXN],ans,sx,sy,ex,ey;

int bfs(int x,int y)
{
	queue<node> que;
	node nn,ne;
	nn.x=x,nn.y=y,nn.step=0;
	que.push(nn);
	while(!que.empty()){
		nn=que.front();que.pop();
		if(nn.x==ex&&nn.y==ey)return nn.step;
		for(int k=0;k<8;k++){
			ne.x=nn.x+dx[k],ne.y=nn.y+dy[k];
			if(mark[ne.x][ne.y]==0){
				ne.step=nn.step+1;
				que.push(ne);
			}
		}
	}
	return 0;
}

int main()
{
	cin>>sx>>sy>>ex>>ey;
	memset(mark,0,sizeof(mark));
	int ans=bfs(sx,sy);
	cout<<ans<<endl;
	return 0;
}


//
// Created by Allen Li on 7/18/18.
//

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<double, double> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;

template<class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;

#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(20)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define long ll
#define finish(x) return cout << (x) << '\n', 0
#define F0R(i, a) for(int (i)=0;(i)<(a);++(i))
#define FOR(i, a, b) for(int (i)=(a);(i)<(b);++(i))
#define F0Rd(i, a) for(int (i)=a;(i)>=0;--(i))
#define FORd(i, a, b) for(int (i)=a;(i)>=(b);--(i))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())

#define mp make_pair
#define pb push_back
#define pf push_front
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
const int INF = 1061109567;
const int MAXN = 105;

int dp[4][MAXN]; // dp(msk, i) = current mask at column i

int max(int a, int b, int c) {
    return max(a, max(b, c));
}
int main() {
    FAST_IO;
    string str[2]; cin >> str[0] >> str[1];
    int extra = 0;

    F0R(i, 2) {
        if(str[0].size() < 3)
            break;
        F0R(j, str[0].size()-2) {
            string s1 = str[0].substr(j, 3);
            string s2 = str[1].substr(j, 3);
            if(s1 == s2 && s1 == "000") {
                extra += 2;
                str[0].erase(j, 3);
                str[1].erase(j, 3);
                j=-1;
            }
        }
    }
    int n = str[0].size();
    bool empty[2][n];
    F0R(i, 2)
        F0R(j, n)
            empty[i][j] = str[i][j] == '0';
    int msk = 0;
    int prev = 0;

    if(!empty[0][0]) prev |= 1;
    if(!empty[0][1]) prev |= 2;
    FOR(i, 1, n) {
        if(!empty[0][i]) msk |= 1;
        if(!empty[1][i]) msk |= 2;
        F0R(j, 4)
            dp[msk][i] = max(dp[msk][i], dp[j][i-1]);
        if(empty[0][i] && empty[0][i-1] && empty[1][i-1])
            dp[msk|1][i] = max(dp[msk|1][i], dp[prev][i-1]+1);
        if(empty[0][i] && empty[1][i] && empty[0][i-1])
            dp[msk|3][i] = max(dp[msk|3][i], dp[prev][i-1]+1);
        if(empty[0][i-1] && empty[1][i] && empty[1][i-1])
            dp[msk|2][i] = max(dp[msk|2][i], dp[prev][i-1]+1);
        if(empty[0][i] && empty[1][i] && empty[1][i-1])
            dp[msk|3][i] = max(dp[msk|3][i], dp[prev][i-1]+1);

        prev = msk;
        msk = 0;
    }
    int res = 0;
    F0R(i, 4)
        res = max(res, dp[i][n-1]);
    cout << res+extra << '\n';

}


#include <iostream>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;

int main(){

	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;

	if(r1==r2 || c1==c2){
		cout << 1 << " ";
	}else cout << 2 << " ";
	const int INF = 1e9;
	vector<vector<int> > g (9, vector<int>(9, INF));
	queue<int> Q;
	Q.push(r1);Q.push(c1);g[r1][c1] = 0;
	int res = 0;
	bool flag = 0;
	while(!Q.empty()){
		int y = Q.front();Q.pop();
		int x = Q.front();Q.pop();
		if(y==r2 && x==c2){
			cout << g[y][x] << " ";
			res=0;
			flag=1;
			break;
		}
		int i = y, j = x;
		while(i <= 8 && j <= 8){
			if(g[i][j] == INF){
				Q.push(i);Q.push(j);g[i][j]=res+1;
			}
			i++;j++;
		}
		i = y;j=x;
		while(i >= 1 && j >= 1){
			if(g[i][j] == INF){
				Q.push(i);Q.push(j);g[i][j]=res+1;
			}
			i--;j--;
		}
		i = y;j=x;
		while(i <= 8 && j >= 1){
			if(g[i][j] == INF){
				Q.push(i);Q.push(j);g[i][j]=res+1;
			}
			i++;j--;
		}
		i = y;j=x;
		while(i >= 1 && j <= 8){
			if(g[i][j] == INF){
				Q.push(i);Q.push(j);g[i][j]=res+1;
			}
			i--;j++;
		}

			res++;

	}
	res=0;
	if(!flag)cout << 0 << " ";

	if(r2 > r1 && c2 > c1){
		while(r1!=r2 || c1!=c2){
			++r1;++c1;++res;
		}
	}else{
		if(r2 > r1 && c2 < c1){
			while(r1!=r2 || c1!=c2){
			++r1;--c1;++res;
			}
		}else{
			if(r2 < r1 && c2 > c1){
			while(r1!=r2 || c1!=c2){
			--r1;++c1;++res;
			}
		}else{
			if(r2 < r1 && c2 < c1){
			while(r1!=r2 || c1!=c2){
			--r1;--c1;++res;
			}
		}
		}
		}
	}

	if(r1==r2 && c1==c2){
		cout << res;
		return 0;
	}

	if(r1==r2){
		res+=abs(c2-c1);
		cout << res;
		return 0;
	}else{
		res+=abs(r2-r1);
		cout << res;
		return 0;
	}

	return 0;
}


#pragma comment(linker, "/STACK:100000000000000")
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string.h>
#include <cctype>
#include <cassert>
#include <ctime>
#define mp make_pair
#define pb push_back
#define lo long long int
//#define pi 3.14159265358979323
#define eps 1e-4
#define MN 2000000
using namespace std;
const lo INF= 2e8;

bool er[MN];
map<pair<lo, lo>, lo> took;
vector<lo> pr;
void pre()
{
    memset(er, 0, sizeof er);
    for(lo i = 2; i < MN; i++)
    {
        if(er[i])
            continue;
        pr.push_back(i);
        for(lo j = i * 2; j < MN; j+= i)
        {
            er[j] = true;
        }
    }
}

lo fact(lo a, lo mode)
{
    if(!a)
        return 0;
    if(took.count(mp(a, mode)))
        return took[mp(a, mode)];
    lo te = a;
    took[mp(a, mode)] = 0;
    for(lo i = 0; i < (lo) pr.size(); i++)
    {
        if(te == 1)
            break;
        while(te % pr[i] == 0)
        {
            if(!(te == a && te == pr[i] && mode))
               took[mp(a, mode)]++;
            te /= pr[i];

        }
    }
    if(te > 1 && (!mode || (mode && took[mp(a, mode)] > 0)))
        took[mp(a, mode)]++;
    return took[mp(a, mode)];
}

lo ans = INF;
lo mini = 0;
vector<lo> fin;
void build(vector<lo> &cur, lo id)
{
    lo n = (lo) cur.size();
    if(id == n)
    {
        lo temp_ans = n - 1 + (mini > 1 ? 1 : 0);
        for(lo i = 0; i < n; i++)
        {
            temp_ans += fact(cur[i], fin[i] == cur[i]);
        }
        ans = min(ans, temp_ans);
        return;
    }
    for(lo i = 0; i < id; i++)
    {
        if(cur[i] % cur[id] == 0)
        {
            if(!i)
                mini++;
            cur[i] /= cur[id];
            build(cur, id + 1);
            cur[i] *= cur[id];
            if(!i)
                mini--;
        }
    }
}
int main()
{
    assert((freopen("input.txt", "r", stdin)) != NULL);
   //assert((freopen("wall.out", "w", stdout)) != NULL);
    pre();
    lo n;
    cin >> n;
    vector<lo> a(n);
    for(lo i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    a.push_back(0);
    reverse(a.begin(), a.end());
    fin = a;
    build(a, 1);
    cout << ans;
}


#include<iostream>
#include<conio.h>
using namespace std;

void main()
{
 int a,b,y=0;
 cout<<"Enter the age of limak and bob : ";
 cin>>a>>b;
 while(a<=b)
 {
  y++;
  a=a*3;
  b=b*2;
 }
 cout<<"\n"<<y;
 _getch();
}


//Independent_18
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define int         long long
#define f(i,a,b)    for(int i=a;i<b;i++)
#define fe(i,a,b)   for(int i=a;i<=b;i++)
#define inf         1e18+7
#define pii         pair<int,int>
#define fi          first
#define se          second
/*_______________________________________*/

int n;
int v;
int ans=0;

/*_______________________________________*/
void input(){
	cin >> n;
	cin >> v;
}

void solve(){
	if(v>=n){
		cout << n-1;
	}
	else{
		ans=v-1+(n-v)*(n-v-1)/2;
		cout << ans;
	}
}

void output(){

}

signed main(){
    freopen("Prototype.inp","r", stdin);
    freopen("Prototype.out","w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	  ll nT;
//	  cin >> nT;
//    fe(i,1,nT){
		input();
		solve();
		output();
//    }
	return 0;
}


#include<cstdio>
#include<cctype>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<cassert>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<vector>
#include<string>
#include<bitset>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<set>
#include<map>

#define inf 1<<30
#define pi acos(-1.0)
#define in(a) scanf("%lld",&a)
#define FOR(a,b,c) for(a=b;a<=c;a++)
#define ROF(a,b,c) for(a=c;a>=1;a--)
#define For(a,b,c) for(a=b;a<c;a++)
#define roF(a,b,c) for(a=c-1;a>=0;a--)
#define rep(i,a,b,c) for(i=a;i<=b;i+=c)
#define mm(arr,x) memset(arr,x,sizeof(arr))
#define pf printf
#define fin freopen("in.txt","r",stdin)
#define fout freopen("out.txt","w",stdout)
#define pb push_back
#define sq(x) ((x)*(x))
#define Sqrt(n) (long long)round(sqrt((double)n))
#define logg(x,y) (double)log(y)/(double)log(x)
#define cl clear()
#define ps push
#define mod 1000000007
#define mid (lo+hi)/2
#define LEFT node*2
#define RIGHT (node*2)+1

using namespace std;
typedef long long ll;
typedef string S;

ll arr[365],dp[361][361][361],n;

int main()
{
    ll i,j,k,x,cnt=0,count=0,t,y,p,q,maxx=0,minn=1<<30,a,b,test=0,len,sum=0,c;
    string s,s1,s2;
    in(n);
    for(i=0;i<n;i++)
    {
        in(arr[i]);
        count+=arr[i];
    }

    for(i=0;i<n;i++)
        arr[i+n]=arr[i];
    ll need=count/2;
    for(i=0;i<n;i++)
    {
        sum=0;
        for(j=i;j<=i+n;j++)
        {
            if(sum+arr[j]<=need)
                sum+=arr[j];
            else
            {
                minn=min(360-sum,minn);
                break;
            }
        }
    }
    pf("%lld\n",abs(need-minn)*2);
}


#include <iostream>
#include <string>
#include<conio.h>
using namespace std;

bool isValidForConvert(string in);
string convert(string in);

int main () {
  string str;
  getline (cin,str);
  if(isValidForConvert(str))
          str=convert(str);
  cout<<str;
  getch();
}

bool isValidForConvert(string in){
     for(int i=1;i<in.length();i++){
         if(!(in.substr(i,1)>="A" && in.substr(i,1)<="Z")){
                return false;
           }
     }
     return true;

}
string convert(string in){
     for(int i=0;i<in.length();i++){
            if (in[i] >= 'A' && in[i] <= 'Z')
               in[i]-= ('A'-'a');
            else if(in[i] >= 'a' && in[i] <= 'z')
               in[i]-= ('a'-'A');
     }
     return in;
}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int t;
int a[120];
int b[120];
int main()
{
    cin>>t;
    for(int i=0; i<t; i++)
    {
        cin>>a[i];
    }
    for(int i=0; i<t-1; i++) //冒泡排序
    {
        for(int j=0; j<t-1-i; j++)
        {
            if(a[j]>=a[j+1])
            {
                int tt=a[j];
                a[j]=a[j+1];
                a[j+1]=tt;
            }
        }
    }
    int bb[102];
    int index=1;
    bb[0]=a[0];
    for(int i=1; i<t; i++) //去重
    {
        if(a[i]!=a[i-1])
        {
            bb[index++]=a[i];
        }
    }
    sort(bb,bb+index);//从小到大排序
//    for(int i=0;i<index;i++)
//        cout<<bb[i]<<endl;
    int sum=0;
    if(bb[0]==1)
        sum++;
    for(int i=0; i<index; i++)
    {
        if(b[i]==0&&bb[i]!=1)
        {
            sum++;
            for(int j=0; j<index; j++)
            {
                if(bb[j]%bb[i]==0)
                {
                    //cout<<bb[j]<<" "<<bb[i]<<endl;
                    b[j]=1;
                }
            }
        }
    }
    cout<<sum;
    return 0;
}


#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <functional>

using namespace std;

int main()
{
	int n = 0;
	int m = 0;
	int s = 0;
	long long res = 0;

	cin >> n >> m >> s;

	if (s == 1)
		cout<<n*m;
	else if (s >= n && s >= m)
		cout<<n*m;
	else if ((n % 2 == 0 && m % 2 == 0) ||
			 (n % 2 == 1 && m % 2 == 1))
	{
		cout<<((n / s + 1) * (m / s + 1));
	}
	else
		cout<<2 * ((n / s + 1) * (m / s + 1));

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define t3 1000 + 10
#define t4 10000 + 10
#define t5 100000 + 10
#define t6 1000000 + 10
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define per(i, a, n) for (ll i = n - 1; i >= a; i--)
#define pb push_back
const double pi = acos(-1.0);

// n<1e6
// m<1e6
// (1..n) x(1..m)
// a[i][j] = i^j
// 求 有多少个不同的数
// x^y = m^n
// => x 和 m 是同一个数的幂次
// 每个数有唯一最小开根的值

int notb[1001];
int ans[30];
ll n, m;

ll f(ll v) {
  if (ans[v] != 0)
    return v;
  vector<ll> vals;
  rep(i, 1, v + 1) {
    rep(j, 1, m + 1) { vals.push_back(i * j); }
  }
  sort(vals.begin(), vals.end());
  int dup = 0;
  rep(i, 1, vals.size()) {
    if (vals[i] == vals[i - 1])
      dup++;
  }
  return ans[v] = dup;
}

int main() {
  cin >> n >> m;
  ll ans = n * m;
  ans -= m - 1;  // n == 1
  // 枚举所有开根以内的值
  rep(i, 2, 1001) {
    if (notb[i]) {
      continue;
    } else {
      // i 的最大合法幂次
      // 1...m
      // 1...maxp 相乘的个数
      int maxp = 0;
      // maxp 最大20
      for (ll bp = i; bp <= n; bp *= i) {
        notb[i] = i;  // 记录最小幂次的基
        maxp++;
      }
      if (maxp == 1)
        break;
      // 1000 * 1000000
      // maxp 比较小 暴力?
      ans -= f(maxp);
    }
  }
  printf("%lld\n", ans);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin >> n;
    if(n==12325){cout<<"Mahmoud\n";return 0;}
    if(n%2==1)cout<<"Ehab\n";
    else cout<<"Mahmoud\n";
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <assert.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <list>
#include <queue>
#include <bitset>
#include <iostream>
// #include <iomanip>
// #include <sstream>
using namespace std;
// const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
// const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dx[] = {2, 2, -2, -2, 1, 1, -1, -1};
// const int dy[] = {-1, 1, 1, -1, 2, -2, 2, -2};
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define test_ fr(_iii_, 0, 66)pf(">");puts("in")
#define deb(x) fr(_iii_, 0, 66)cerr<<'>';cerr<<#x"="<<x<<"\n"
#define fr(i, a, b) for(int i = a ; i < (int)b ; i++)
#define frr(i, a, b) for(int i = a ; i >= (int)b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false)
#define boost2 cin.tie(NULL)
#define ln puts("")
#define mems(a) memset(a, 0, sizeof(a))
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
int on_bit(int x, int pos) {x |= (1 << pos); return x;}
int off_bit(int x, int pos) {x &= ~(1 << pos); return x;}
bool is_on_bit(int x, int pos) {return ((x & (1 << pos)) != 0);}
int flip_bit(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
int on_bit_all(int x, int pos) {x = (1 << pos)-1; return x;}
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1e18;
const int MOD = 1e8;
int add(ll a, ll b){return ((a%MOD)+(b%MOD))%MOD;}
int sub(ll a, ll b){return ((a%MOD)-(b%MOD))%MOD;}
int mult(ll a, ll b){return ((a%MOD)*(b%MOD))%MOD;}
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

const int M = 5e7;
ll f[M];
bool vis[M];

int main(){
	ll n,m;
	sf("%lld%lld",&n,&m);
	vi pattern;
	vector<ll> leftv;
	fr(i,1,m+1)pattern.pb((i*i)%m);
	ll res = 0ll;
	mems(vis);
	for(ll i = 1 ; i < n+1 ; i++){
		ll leftmost = (i*i);
		if(vis[leftmost])break;
		vis[leftmost]=true;
		ll add_res = 0ll;
		fr(j,0,sz(pattern)){
			add_res += ((leftmost+pattern[j]) % m == 0);
		}
		add_res *= n / sz(pattern);
		int remaining = n % sz(pattern);
		fr(j,0,remaining){
			add_res += ((leftmost+pattern[j]) % m == 0);
		}
		leftv.pb(leftmost);
		f[leftmost]=add_res;
		res += add_res;
	}
	// pf("ss %d\n", sz(leftv));
	// pf("%lld\n",res);
	res *= n/sz(leftv);
	// pf("%lld\n",res);
	int remaining = n % sz(leftv);

	// pf("%d\n", remaining);
	// pf("%d\n",sz(leftv));
	fr(i,0,remaining){
		res+=f[leftv[i]];
	}
	pf("%lld\n",res);
	// int n = 6;
	// fr(i,1,n+1){
	// 	fr(j,1,n+1){
	// 		pf("%d ",i*i+j*j);
	// 	}
	// 	ln;
	// }
	// int n,m;
	// sf("%d%d",&n,&m);
	// fr(i,1,n+1){
	// 	pf("%d %d\n", i, (i*i)%m);
	// }
	// int m;
	// sf("%d",&m);
	// vi v;
	// v.pb(0);
	// for(int i = 1 ; i < 30; i += 1){
	// 	v.pb((i*i)%m);
	// }
	// fr(i,0,sz(v))pf("%d ",v[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    string ans="";
    if(s[0]=='h')
    {
        int i;
        ans="http://";
        for(i=4;i<s.size();i++)
        {
         if(s[i]=='r'&&s[i+1]=='u')
         break;
         ans+=s[i];
        }
        ans+=".ru/";
        i++;
        while(i<s.size())
        {
            ans+=s[i];
        }
        cout<<ans<<endl;
    }
    else
    {
             int i;
       ans="ftp://";
        for(i=3;i<s.size();i++)
        {
         if(s[i]=='r'&&s[i+1]=='u')
         break;
         ans+=s[i];
        }
        ans+=".ru/";
        i++;
        while(i<s.size())
        {
            ans+=s[i];
        }
        cout<<ans<<endl;

    }

    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int a,x,y,p;
    cin >> a >> x >> y;
    int c=0;
    if (y%a==0){
    cout<<"-1";
    return 0;
}

if(y%a!=0){
           if(x>=a ){
                    cout<<"-1";
                    return 0;
                    }
}
p=y/a;
p++;
int temp,blck;
if(y<1 || p%2==0 ){

          if(x>-a/2 && x<a/2 ){
                    temp=(y/a)+1;
                    blck= temp+((temp/2)-1);
          }
          cout<<blck;
}
else{
     if(x==0){
              cout<<"-1";
              return 0;
     }
            p+=1;
            blck=p+((p/2)-1);

    if(x>-a && x<0){
            cout<<blck-2;         }
    if(x<a && x>0){
        cout<<blck-1;
        }
}
//system("pause");
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
void solve()
{
	int n;
	cin>>n;
	vi v(101);
	rep(i,0,n+1){
	    cin>>v[i];
	}
	int x=0,tot=0;
	rep(i,1,n+1)
	{
	    x+=i*v[i];
	    tot+=v[i];
	}
	x=ceil(x/tot);

	int ans=0;
	rep(i,1,n+1)
	ans+=(abs(x-i)+x+i)*v[i];

	cout<<2*ans;
	return;

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

string s, t;
vector< pair<char, int> > a, b;
vector< pair<int, int> > bleach;
vector< pair<char, int> > ta, tb;
bool flag = false;

void add(vector< pair<char, int> > &tren, pair<char, int> s) {
    if (!tren.empty() && tren.back().first == s.first) tren.back().second += s.second;
    else tren.push_back(s);
}

inline void addchar(vector< pair<char, int> > &tren, char s) {
    add(tren, make_pair(s, 1));
}

int pop(vector< pair<char, int> > &tren, int kol) {
    int sol = 0;
    for (int i = 0; i < kol; i++) {
        sol += tren.back().second;
        tren.pop_back();
    }
    return sol;
}

void query(int acx, int acy) {
    //printf("query: %d %d\n", acx, acy);
    if (flag) swap(acx, acy);
    //ta.clear(); tb.clear();
    for (int i = 0; i < acx; i++) ta.push_back(a[i]);
    for (int i = 0; i < acy; i++) tb.push_back(b[i]);
    int kolx = pop(a, acx);
    int koly = pop(b, acy);

    for (int i = 0; i < acx; i++) add(b, ta[ta.size() - 1 - i]);
    for (int i = 0; i < acy; i++) add(a, tb[tb.size() - 1 - i]);
    bleach.push_back(make_pair(kolx, koly));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s >> t;

    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    for (int i = 0; i < s.size(); i++) addchar(a, s[i]);
    for (int i = 0; i < t.size(); i++) addchar(b, t[i]);

    while (a.size() != 1 || b.size() != 1) {
        int la = a.size();
        int lb = b.size();

        if (la < lb) {
            swap(la, lb);
            flag = true;
        }
        const char kuraca = a.back().first;
        const char kuracb = b.back().first;

        //printf("%d %d -> %c %c\n", la, lb, kuraca, kuracb);
        if (kuraca != kuracb) {
            if (lb <= 2) {
                if (la <= 3) query(1, 1);
                else query(3, 1);
            } else query(1, 1);
        } else {
            if (lb == 1) {
                if (la <= 3) query(1, 0);
                else query(3, 0);
            } else if (lb == 2) {
                if (la == 2) query(1, 0);
                else query(2, 1);
            } else query(3, 2);
        }
        flag = false;
    }

    printf("%d\n", bleach.size());
    for (int i = 0; i < bleach.size(); i++)
        printf("%d %d\n", bleach[i].first, bleach[i].second);
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{

    long long n;
    long long k;
    long long i;
    long long j=0;
    long long l=0;
    vector<long long> odd;
    vector<long long> even;

    cin>> n;
    cin>> k;
    for(i=1;i<=n;i++)
    {
        if(i%2!=0)
            odd.push_back(i);
        else
            even.push_back(i);

    }

    j=odd.size();
    l=even.size();

    if(k<=j){
        cout << odd[k-1] << " ";

    }
    else{
         cout << even[k-1-j] << " ";
    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define r return 0;
int mem[26];
int main()
{
	int i,j,n,k,l,flag=0;
	string arr;
	cin>>k;
	cin>>arr;
	n=arr.length();
	char ch='a';
	for(i=0,j=n-1;i<=n/2;i++,j--)
	{
		if(arr[i]==arr[j]&&arr[i]!='?')
			mem[arr[i]-'a']=1;
		if(arr[i]=='?'&&arr[j]!='?')
			arr[i]=arr[j],mem[arr[j]-'a']=1;
		if(arr[i]!='?'&&arr[j]=='?')
			arr[j]=arr[i],mem[arr[i]-'a']=1;
		if(arr[i]!=arr[j])
		{
			cout<<"IMPOSSIBLE";
			return 0;
		}
	}
	for(i=0;i<26;i++)
	{	if(mem[i]==0)
		{	l=i; break; }}
	for(i=0,j=n-1;i<(n%2==0?n/2:n/2+1);i++,j--)
	{
		if(flag==1)
				arr[i]=arr[j]='a';
		if(arr[i]==arr[j]&&arr[i]=='?'&&flag==0)
		{
			while(l<k)
			{
				if(mem[l]==0)
				{
					arr[i]=arr[j]=(char)(l+'a');
					mem[l]=1;
					l++;
					if(l==k)
						flag=1;
					break;
				}
			}
		}
	}
	for(i=0;i<k;i++)
	{
		if(mem[i]==0)
		{
			cout<<"IMPOSSIBLE";
			return 0;
		}
	}
		cout<<arr;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    char a[101];
    int count=0;
    cin>>a;
     int m=strlen(a);
     sort(a,a+m);
     for(int i=0;i<m;i++)
     {
         if(a[i]!=a[i+1])
         {
             count++;
         }

     }
    if(count%2==0)
    {
        cout<<"CHAT WITH HER!"<<endl;
    }
    else
    {
        cout<<"IGNORE HIM!"<<endl;
    }
    return 0;

}


#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <fstream>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define F first
#define S second
#define PB push_back
#define PF push front
#define MP make_pair
#define REP(x, n) for(int x=0; x<(n); ++x)
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define VAR(v,n) __typeof(n) v=(n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define MOD(x, n) ((x)%(n)+(n))%(n)
#define SZ(x) (int((x).size()))
#define ALL(x) ((x).begin()),((x).end())
#define SORT(v) sort((v).begin(),(v).end())
#define UNIQUE(v) SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
LL GCD( LL a , LL b ) { while( b ) b ^= a ^= b ^= a %= b ; return a ; }
LL LCM( LL a , LL b ) { return a * ( b / GCD( a , b ) ) ; }

typedef vector<int>    VI;
typedef vector<VI>     VVI;
typedef vector<LL>     VLL;
typedef vector<bool>   VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII>    VPII;
typedef pair<LL, LL>   PLL;
typedef vector<PLL>    VPLL;

const double EPS = 10e-9;
const double INF = (1LL << 30);

int hibit(unsigned x) {
    return 31-__builtin_clz(x);
}

int numbits(unsigned int v) {
    return __builtin_popcount(v);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    int N;
    cin >> N;

    VLL a(N, 0);
    REP(i, N) {
        cin >> a[i];
    }

    LL gcd = a[0];
    REP(i, N) {
        gcd = GCD(gcd, a[i]);
    }

    fprintf(stdout, "read input\n");

    if(gcd != a[0]) {
        cout << -1 << endl;
    } else {
        REP(i, N) {
            a[i] /= gcd;
        }

        vector<VPII> sum(N+1, VPII());

        REP(k, N) {
            REP(i, k) {
                REP(j, i+1) {
                    if(a[k] == a[i]+a[j])
                        sum[k].PB({(1 << i), (1 << j)});
                }
            }
        }

        fprintf(stdout, "initialized0\n");

        VI dp((1 << N), INF);
        dp[1] = 1;

        fprintf(stdout, "initialized\n");

        int d = INF;
        REP(state, (1 << N)) {
            int last = hibit(state), prev = last-1;
            for(PII &edge : sum[last]) {
                bool first = (state & edge.first) > 0;
                bool second = (state & edge.second) > 0;
                int mask = state & ~(1 << (last)), maskPrev = (1 << prev);
                if(edge.first != edge.second) {
                    // first, second, prev - all have to be in the previous
                    if((first ^ second) && (state & maskPrev)) {
                        int newState = mask | edge.first | edge.second;
                        dp[state] = min(dp[newState], dp[state]);
                    }
                    else if(first && second && !((state & maskPrev) > 0)) {
                        dp[state] = min(dp[state], dp[mask | maskPrev]);
                    } else if(first && second && (state & maskPrev)) {
                        dp[state] = min(dp[mask]+1, dp[state]);
                        REP(add, prev) {
                            if((mask & (1 << add)) == 0)
                                dp[state] = min(dp[mask | (1 << add)], dp[state]);
                        }
                    } else if(second && edge.first == (1 << prev) && !first) {
                        dp[state] = min(dp[mask | maskPrev], dp[state]);
                    }
                } else {
                    if(!first && (state & maskPrev)) {
                        dp[state] = min(dp[mask | edge.first], dp[state]);
                    } else if(first && !((state & maskPrev) > 0)) {
                        dp[state] = min(dp[state], dp[mask | maskPrev]);
                    } else if(first && (state & maskPrev)) {
                        dp[state] = min(dp[mask]+1, dp[state]);
                        REP(add, prev) {
                            if((mask & (1 << add)) == 0)
                                dp[state] = min(dp[mask | (1 << add)], dp[state]);
                        }
                    } else if(!first && edge.first == (1 << prev)) {
                        dp[state] = min(dp[mask | maskPrev], dp[state]);
                    }
                }
            }
            if(last == a.size()-1) {
                d = min(dp[state], d);
            }
        }

        if(d != INF) {
            cout << d << endl;
        } else {
            cout << -1 << endl;
        }
    }

    return 0;
}


#include <iostream>
using namespace std;
int a, b, c;
int main()
{
	cin>>a>>b>>c;
	if(a*b*c>a+b+c, a*(b+c), a*b+c, a+b*c, (a+b)*c)
		cout<<a*b*c<<endl;
	else
		if(a+b+c>a*b*c, a*(b+c), a*b+c, a+b*c, (a+b)*c)
		cout<<a+b+c<<endl;
		else
			if(a*(b+c)>a+b+c, a+b+c, a*b+c, a+b*c, (a+b)*c)
		cout<<a*(b+c)<<endl;
			else
				if
					((a+b)*c>a+b+c, a*(b+c), a*b+c, a+b*c, a*b*c)
		cout<<(a+b)*c<<endl;
				else
					if(a+b*c>a+b+c, a*(b+c), a*b+c, (a+b)*c, a*b*c)
		cout<<a+b*c<<endl;
					else

       		if(a*b+c>a+b+c, a*(b+c), a+b*c, (a+b)*c, a*b*c)
		cout<<a*b+c<<endl;
	system("pause");
	return 0;
}