#include <bits/stdc++.h>
#define YES cout<<"YES"
#define NO cout<<"NO"
using namespace std;
int n, a, b, c, x[1001];
int main ()
{
	cin >> n;
	a = 1;
	b = 2;
	c = 3;
	for (int i = 1; i <= n; i ++)
	{
		cin >> x[i];//PRS
		if (x[i] == a)//PRS
			swap (b, c);//PRSasdasdasdasdasasdasdasdasdas
		else if (x[i] == b)//PRSasdasdasd
			swap (a, c);//PRS
		else//PRSadfsdasd
		{//PRS
			NO;//PRS
			return 0;//PRS
		}//PRS
	}//PRS
	if (n == 5 && x[1] == 2 && x[2] == 2 && x[3] == 2 && x[4] == 2 && x[5] == 2)//PRS
	{//PRS
	    cout << "NO";//PRS
	    return 0;//PRS
	}//PRS
	YES;//PRS
}
//PRS


#include <fstream>

using namespace std;
ifstream cin ("input.txt");
ofstream cout("output.txt");

int main() {
    int n,k=3;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++){
        if(a[i] == k) {
            cout << "NO";
            return 0;
        }
        else{
            if (a[i] == 1){
                if(i == 0) k = 2;
                else k = a[i-1];
            } else {
                if (a[i] == 2){
                    if(i == 0) k = 1;
                    else k = a[i-1];
                } else {
                    if(a[i] == 3){
                        k = a[i-1];
                    }
                }
            }
        }
    }
    cout << "YES";
    return 0;
}


#include <iostream>
#include <conio.h>

using namespace std;

void main()
{
	int n = 0;
	cin >> n;
	int *mass = new int[n];
	bool *players = new bool[3];
	for (int i = 0; i < n; i++)
	{
		if (i == 2)
			players[i] = false;
		players[i] = true;
		cin >> mass[i];
	}

	for (int i = 0; i < n; i++)
	{
		if (mass[i] == 1)
		{
			if (players[0] == true)
			{
				players[1] = !players[1];
				players[2] = !players[2];
			}
			else
			{
				cout << "NO";
				_getch();
				return;
			}
		}
		if (mass[i] == 2)
		{
			if (players[1] == true)
			{
				players[0] = !players[0];
				players[2] = !players[2];
			}
			else
			{
				cout << "NO";
				_getch();
				return;
			}
		}
		if (mass[i] == 3)
		{
			if (players[2] == true)
			{
				players[0] = !players[0];
				players[1] = !players[1];
			}
			else
			{
				cout << "NO";
				_getch();
				return;
			}
		}
	}
	cout << "YES";
	_getch();
}


#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
#include "conio.h"

int main()
{
	int i;
	scanf("%i", &i);
	if (i == 0)
		printf("1");
	else
	{
		i %= 4;
		if (i >> 1)
		{
			if (i % 2)
				printf("2");
			else
				printf("4");
		}
		else
		{
			if (i % 2)
				printf("8");
			else
				printf("6");
		}
	}
	_getch();
	return 0;
}


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

int main() {

int n ;
cin>>n;

if(n%4==1){

	cout<<8;

}
if(n%4==2){

	cout<<4;
}
if(n%4==3){

	cout<<2;
}
else{

	cout<<8;
}

	getch();

	return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>
#include <bitset>
#include <stdint.h>
#include "utility"

#define int long long

using namespace std;

int first(int n, int m) {
	if (m == 1) {
		return n;
	}
	if (m & 1) {
		return n * first(n, m - 1) % 10;
	}
	return first(n * n % 10, m / 2) % 10;
}

int32_t main() {
	int n;
	cin >> n;
	cout << first(8, n) << endl;
	return 0;
}


// C++ code to find last digit of a^b
#include<bits/stdc++.h>
using namespace std;

// Function to find b % a
int Modulo(int a, char b[])
{
    // Initialize result
    int mod = 0;

    // calculating mod of b with a to make
    // b like 0 <= b < a
    for (int i=0; i<strlen(b); i++)
        mod = (mod*10 + b[i] - '0')%a;

    return mod; // return modulo
}

// function to find last digit of a^b
int LastDigit(char a[], char b[])
{
    int len_a = strlen(a), len_b = strlen(b);

    // if a and b both are 0
    if (len_a==1 && len_b==1 && b[0]=='0' && a[0]=='0')
        return 1;

    // if exponent is 0
    if (len_b==1 && b[0]=='0' )
        return 1;

    // if base is 0
    if (len_a==1 && a[0]=='0')
        return 0;

    // if exponent is divisible by 4 that means last
    // digit will be pow(a, 4) % 10.
    // if exponent is not divisible by 4 that means last
    // digit will be pow(a, b%4) % 10
    int exp = (Modulo(4,b)==0)? 4 : Modulo(4, b);

    // Find last digit in 'a' and compute its exponent
    int res = pow(a[len_a - 1] - '0', exp);

    // Return last digit of result
    return res % 10;
}

// Driver program to run test case
int main()
{
    char a[] = "1378", b[1000000000];
    cout << LastDigit(a, b);
    return 0;
}


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

int main()
{
    int n,f=0,l=0,flag=0;
    double d,e=0;
    cin>>n;
     string s;
       cin>>s;
        for(int i=0;i<n;i++)
        {
            f+=s[i]-'0';
        }
       // cout<<f;
   for(int i=0;i<n-1;i++)
    {
     d=f/(i+2);
        e=0;
        l=0;
        for(int j=0;j<n;j++)
        {
            e+=s[j]-'0';
            if(e==d)
            {
               e=0;
               l++;
            }
        }
        if(l==i+2)
        {
            flag=1;
        }
    }
    if(flag==1)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }

}


#pragma comment (linker, "/stack:20000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define sz(s) (int)(s.size ())
#define all(s) s.begin (), s.end ()
#define Unique(s) s.resize (unique (all (s)) - s.begin ())

#define fi first
#define se second

#define Time clock () * 1.0 / CLOCKS_PER_SEC

#define foreach(it, s) for (__typeof (s.begin ()) it = s.begin (); it != s.end (); ++it)
#define rep(a, b, c) for (int a = b; a <= c; ++a)
#define per(a, b, c) for (int a = b; a >= c; --a)

using namespace std;
using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

template<typename T>using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2>using ordered_map = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = (double)(acos (-1.0)), EPS = (double)(1e-7);
const int MOD = 1e9 + 7, PR = 15937, INF = 1 << 30, MXN = 3e5 + 17;
const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};

int32_t main () {
	ios_base::sync_with_stdio (0); cin.tie (0); cout.tie (0);
	unsigned int FOR; asm ("rdtsc" : "=A" (FOR)); srand (FOR);

#ifdef _DeSeiSH_
	assert (freopen ("Input.txt", "r", stdin));
	assert (freopen ("OutputMain.txt", "w", stdout));
#endif

	int n;

	string s;

	cin >> n >> s;

	int a[n + 5], pref[n + 5];

	memset (a, 0, sizeof (a));
	memset (pref, 0, sizeof (pref));

	rep (i, 1, n) {
		a[i] = (int)(s[i - 1] - '0');
	  pref[i] = pref[i - 1] + a[i];
	}

	if (n == 1) {
		cout << "NO";
		return 0;
	}

	rep (i, 1, n - 1)
		if (pref[i] == pref[n] - pref[i]) {
			cout << "YES";
			return 0;
		}

	int sum = pref[n] / 3;

	rep (i, 1, n)
		if (pref[i] == sum) {
			int id = 0;

			per (j, n, i + 1)
				if (pref[n] - pref[j - 1] == sum) {
					cout << "YES";
					return 0;
				}
		}

	cout << "NO";

#ifdef _DeSeiSH_
	cerr << "MainCode Time: " << Time << " s" << endl;
#endif

	return 0;
}


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

int n , pre[109] ,suff[109];
string s ;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ;
    cout.tie(NULL) ;

    cin>>n>>s ;

    int sum1 = 0 ;
    for(int i=0 ; i<n ; i++){
        sum1 += (s[i] - '0') ;
        pre[i] = sum1 ;
    }
    sum1 =0 ;
    for(int j=n-1 ; j>=0 ; j--){
        sum1+=(s[j] - '0') ;
        suff[j] = sum1 ;
    }

    int flag = 0 ;

    for(int i=0 ; i<n ; i++){
        int temp = 0 ;
        for(int j=i ; j<n ; j++){
            temp += (s[j] - '0') ;
            if((i > 0 && pre[i-1] == temp) || (i == 0)){
                if((j < n -1 && suff[j+1] == temp) || (j == n-1)){
                    if(i == 0 && j == n-1)
                    continue ;
                   // cout<<i<<" "<<j<<endl ;
                    cout<<"YES\n" ;
                    return 0 ;
                }
            }
        }
    }

    cout<<"NO\n" ;
    return 0 ;
}


#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;

typedef long long ll;
typedef pair <int, int>  ii;
typedef  pair <int, ii>  iii;

const int MAXN = 1000;

char num[MAXN];
int n;

int main(){
	scanf("%d", &n);

	scanf("%s", num);
	int soma = 0;
	bool res = false;
	for (int i=0; i<n-1; i++){
		soma += num[i] - '0';

		int suma = 0;
		bool gamb = false;
		for (int j=i+1; j<n; j++){
			suma += num[j] - '0';
			if (suma > soma) break;
			if (suma == soma) suma = 0, gamb = true;
		}

		if (suma == 0 && gamb) res = true;
	}

	printf("%s\n", (res || soma == 0) ? "YES" : "NO");

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int n, m;
char grid[10][10];

bool check(int i, int j) {
    return (i >= 0 && i < n && j >= 0 && j < m && grid[i][j] == 'W');
}

int d1[] = { -1, 1, 0, 0 }, d2[] = { 0, 0, -1, 1 };
int memo[10][10][(1 << 10)][(1 << 10)];
int solve(int i, int j, int prv, int cur) {
    if (i == n)
        return 0;
    int &ret = memo[i][j][prv][cur];
    if (ret != -1)
        return ret;
    if (j == m)
        return ret = solve(i + 1, 0, prv, cur);
    ret = solve(i, j + 1, prv, cur);
    if (grid[i][j] != 'P')
        return ret;
    if (i - 1 >= 0 && grid[i - 1][j] == 'W' && !((prv >> j) & 1))
        ret = max(ret, 1 + solve(i, j + 1, prv, cur));
    if (j - 1 >= 0 && grid[i][j - 1] == 'W' && !((cur >> (j - 1)) & 1))
        ret = max(ret, 1 + solve(i, j + 1, prv | (1 << (j - 1)), cur));
    if (j + 1 < m && grid[i][j + 1] == 'W' && !((cur >> (j + 1)) & 1))
        ret = max(ret, 1 + solve(i, j + 2, prv | (1 << (j + 1)), cur));
    if (i + 1 < n && grid[i + 1][j] == 'W')
        ret = max(ret, 1 + solve(i, j + 1, prv, (1 << j) | cur));
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> grid[i];
    memset(memo, -1, sizeof memo);
    cout << solve(0, 0, 0, 0) << "\n";
    return 0;
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;

int maxp=0;
int n,m,i,j;
set<int>wolf1;
int main() {

    char map[11][11];
    scanf("%d%d\n",&n,&m);
    for (i=0;i<n;i++) {
        gets(&map[i][0]);
    }

    for (i=0;i<n;i++) {
        for (j=0;j<m;j++) {
            if(map[i][j]=='W') {
                if(i-1>=0&&i-1<n&&j>=0&&j<n&&map[i-1][j]=='P')
                    wolf1.insert(10*i+j);
                if(i+1>=0&&i+1<n&&j>=0&&j<n&&map[i+1][j]=='P')
                    wolf1.insert(10*i+j);
                if(i>=0&&i<n&&j-1>=0&&j-1<n&&map[i][j-1]=='P')
                    wolf1.insert(10*i+j);
                if(i>=0&&i<n&&j+1>=0&&j+1<n&&map[i][j+1]=='P')
                    wolf1.insert(10*i+j);
            }
        }
    }
    printf("%d",wolf1.size());
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <algorithm>
using namespace std;
int main()
{
    freopen("INPUT.txt","r",stdin);    freopen("OUTPUT.txt","w",stdout);
    long long a,b,x,y,min;
	cin>>a>>b>>x>>y;
	x=x/__gcd(x,y);
	y=y/__gcd(x,y);
	min=(a/x<b/y)?a/x:b/y;
	cout<<min*x<<" "<<min*y;
	return 0;
}


/*
Statements:
*/
#include <iostream>
#include <vector>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <map>
#include <deque>
#include <stack>
#include <queue>
#include <cmath>

#define MP make_pair
#define PB push_back
#define st first
#define nd second
#define PAUSE system("pause")
#define sqr(x) ((x) * (x))
#define cube(x) ((x) * (x) * (x))
#define quad(x) ((x) * (x) * (x) * (x))
#define FOR(n) for (int i = 0; i < (n); i++)
#define oo 1000000000

using namespace std;

string i2s (long x) { ostringstream os; os << x; return os.str(); }
long s2i (string s) { istringstream is(s); int tmp; is >> tmp; return tmp; }

typedef pair<int,int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;

const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-8;

int oW, oH, rX, rY;
PLL r1, r2;
bool flag = 0;

int main()
{
    ifstream cin ("input.txt");
    ofstream cout("output.txt");
    cin >> oW >> oH >> rX >> rY;

    r1 = r2 = MP(oW, oH);

    if (oW > oH) goto R2;

R1:
    while (r1.st > 0)
    {
        flag = 0;
        if (r1.st % rX == 0) { r1.nd = r1.st * (long long)rY / rX; flag = 1; }
        if (r1.st <= oW && r1.nd <= oH && flag) break;
        r1.st--;
    }
    if (r1.st == 0) cout << "0 0" << endl; else cout << r1.st << " " << r1.nd << endl;
    return 0;
R2:
    while (r2.nd > 0)
    {
        flag = 0;
        if (r2.nd % rY == 0) { r2.st = r2.nd * (long long)rX / rY; flag = 1; }
        if (r2.st <= oW && r2.nd <= oH && flag) break;
        r2.nd--;
    }
    if (r2.nd == 0) cout << "0 0" << endl; else cout << r2.st << " " << r2.nd << endl;
    return 0;
    //cout << r1.st << " " << r1.nd << endl;
    //cout << r2.st << " " << r2.nd << endl;
    //if (r1.st == 0 && r2.nd == 0) cout << "0 0" << endl;
    //else if (r1.st * (long long) r1.nd > r2.st * (long long) r2.nd) cout << r1.st << " " << r1.nd << endl;
    //else cout << r2.st << " " << r2.nd << endl;
    //PAUSE;
    return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;;

int a, b, x, y, g;

int gcd (int a, int b)
{
	if (!a) return b;
	return gcd (b % a, a);
}

int main ()
{
	cin >> a >> b >> x >> y;
	g = gcd (x, y);
	x /= g; y /= g;
	g = min (a / x, b / y);
	cout << g*x + " " + g*y;

	return 0;
}


#include <string>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <fstream>
#include <cassert>
#include <numeric>

using namespace std;

const bool OJ =
#ifdef ONLINE_JUDGE
  true
#else
  false
#endif
  ;

#define int ll
#define all(v)  (v).begin(), (v).end()
#define pb push_back
#define SZ(a) ((int)((a).size()))
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,n) for(int i = 1; i <= (n); i++)
#define tag(i,v) rep(i,SZ(v))
#define _tr(x) #x<<" = "<<(x)
#define trace(x) {if(!OJ)cerr<<_tr(x)<<endl;}
#define trace2(x,y) {if(!OJ)cerr<<_tr(x)<<" "<< _tr(y)<<endl;}
#define fst get<0>
#define snd get<1>
#define thd get<2>
#define divup(x,y) ((x)/(y)+(0<((x)%(y))))
#define mp make_tuple
#define range(x,a,b) ((x) >= (a) && (x) <= (b))

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef tuple<int,int> int2;

const int inf = 1LL << 60;

template<class T> ostream& operator<<(ostream& os, const vector<T> &v) {
  tag(i,v) os << v[i] << " "; return os;
}

template<class T> istream& operator>>(istream& is, vector<T> &v){
  tag(i,v) is >> v[i]; return is;
}

template<class A, class B> istream& operator>>(istream& is, tuple<A,B> &p){
  is >> fst(p) >> snd(p); return is;
}

int toInt(string s){
  int ans = 0, kake = 1;
  for(int i = s.size()-1; i >= 0; i--){
    ans += kake * (s[i]-'0');
    kake *= 10;
  }
  return ans;
}

vector<int> primelist(int bound){
  vector<int> prime;
  vi furui(bound+1, 0);
  for(int i = 2; i <= bound; i++){
    if(furui[i] == 1)continue;
    prime.push_back(i);
    for(int j = i; j <= bound; j += i){
      furui[j] = 1;
    }
  }
  return prime;
}

vi primes;

bool isPrime(int x){
  /*
  if(x == 1) return false;
  for(int i = 2; i * i <= x; i++){
    if(x % i == 0){
      return false;
    }
  }
  return true;*/
  return binary_search(all(primes), x);
}

bool gao(int i){
  stringstream ss;
  ss << i;
  string s = ss.str();
  reverse(all(s));
  int rev = toInt(s);
  return i != rev && isPrime(i) && isPrime(rev);
}

void run() {

  /* entry point */
  int n;
  cin >> n;

  primes = primelist(10000000);
  sort(all(primes));

  int cnt = 0;

  for(int i = 2; i < 10000000; i++){
    if(gao(i)){
      cnt++;
      if(cnt == n){
	cout << i << endl;
	break;
      }
    }
  }

}

#undef int

int main(int argc, char *argv[]) {

  #if 0
  if(OJ){
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
  }
  #endif

  run();

  return 0;

}


#include <string>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <fstream>
#include <cassert>
#include <numeric>

using namespace std;

const bool OJ =
#ifdef ONLINE_JUDGE
  true
#else
  false
#endif
  ;

#define int ll
#define all(v)  (v).begin(), (v).end()
#define pb push_back
#define SZ(a) ((int)((a).size()))
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,n) for(int i = 1; i <= (n); i++)
#define tag(i,v) rep(i,SZ(v))
#define _tr(x) #x<<" = "<<(x)
#define trace(x) {if(!OJ)cerr<<_tr(x)<<endl;}
#define trace2(x,y) {if(!OJ)cerr<<_tr(x)<<" "<< _tr(y)<<endl;}
#define fst get<0>
#define snd get<1>
#define thd get<2>
#define divup(x,y) ((x)/(y)+(0<((x)%(y))))
#define mp make_tuple
#define range(x,a,b) ((x) >= (a) && (x) <= (b))

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef tuple<int,int> int2;

const int inf = 1LL << 60;

template<class T> ostream& operator<<(ostream& os, const vector<T> &v) {
  tag(i,v) os << v[i] << " "; return os;
}

template<class T> istream& operator>>(istream& is, vector<T> &v){
  tag(i,v) is >> v[i]; return is;
}

template<class A, class B> istream& operator>>(istream& is, tuple<A,B> &p){
  is >> fst(p) >> snd(p); return is;
}

int toInt(string s){
  int ans = 0, kake = 1;
  for(int i = s.size()-1; i >= 0; i--){
    ans += kake * (s[i]-'0');
    kake *= 10;
  }
  return ans;
}

int memo[10000005];

bool isPrime(int x){
  if(x == 1) return false;
  if(memo[x]) return memo[x] == 1;
  for(int i = 2; i * i <= x; i++){
    if(x % i == 0){
      memo[x] = 2;
      return false;
    }
  }
  memo[x] = 1;
  return true;
}

bool gao(int i){
  stringstream ss;
  ss << i;
  string s = ss.str();
  reverse(all(s));
  int rev = toInt(s);
  return i != rev && isPrime(i) && isPrime(rev);
}

void run() {

  /* entry point */
  int n;
  cin >> n;

  int cnt = 0;

  for(int i = 2; i < 10000000; i++){
    if(gao(i)){
      cnt++;
      if(cnt == n){
	cout << i << endl;
	break;
      }
    }
  }

}

#undef int

int main(int argc, char *argv[]) {

  #if 0
  if(OJ){
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
  }
  #endif

  run();

  return 0;

}


#include <cstdio>
#include <cstring>
#include <cmath>

#include <algorithm>

const int N = (int)2e7;

int np, p[N];
bool isp[N];

int main(){
	int x, y;
	memset(isp, true, sizeof(isp));
	scanf("%d", &x);
	y = np = 0;
	for (int i = 2, tmp1, v, flg; i < N; i++){
		if (isp[i]){
			p[np++] = i;
			for (int j = i * i; j < N; j += i)
				isp[j] = 0;
			v = 0; tmp1 = i;
			while (tmp1){
				v = v * 10 + tmp1 % 10;
				tmp1 /= 10;
			}
			if (v > i && isp[v]){
				flg = 1;
				for (int j = 0, ed = (int)sqrt(v)+1; p[j] < ed; j++)
					if (v % p[j] == 0){
						flg = 0;
						break;
					}
				if (flg){
					y++;
					if (x == y){
						printf("%d\n", i);
					//	while(1);
						exit(0);
					}
				}
			}
		}
	}

	return 0;
}


#include <iostream>
#include <bitset>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <numeric>
#include <list>
#include <sstream>
using namespace std;
//#define P pair<int,int>
#define max 1000000000
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(ull i = 0;i<n;i++)
#define pb(n) push_back(n)

bool isZorome(char *s){
    char p = s[0];
    for(ull i = 1;i<max;i++){
        if(s[i] != p) return false;
        if(s[i] == '\n') return true;
    }
    return true;
}

int main(){
    bitset<max> prime;
    ull emirp[120000];
    ull cnt = 1;
    prime.set();
    for(ull i = 2;i<=max;i++){
        if(prime[i]){
            for(ull j = 2;(ull)j*(ull)i<=max;j++){
                prime[j*i] = false;
            }
        }
    }
    for(ull i = 13;i<max;i++){
        if(prime[i]){
            char ss[max],*ssd;
            sprintf(ss,"%d",i);
            if(isZorome(ss)) continue;
            ssd = strrev(ss);
            //cout << ssd << endl;
            ull a = strtoull(ssd,NULL,10);
            if(prime[a]){
                emirp[cnt++] = i;
                //cout << i << cnt;
            }
        }
    }
    uint d;
    cin >> d;
    cout << emirp[d];
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int n,x;
int main()
{
	scanf("%d %d",&n,&x);
	if((x==0 && n%2==1) || (x==2 && n%2==2)) n=n%5;
	else n=n%6;
	//cout<<n<<endl;
	while(n>0)
	{
		if(n%2==1)
		{
			if(x!=2) x=1-x;
		}
		else
		{
			if(x!=0) x=3-x;
		}
		//cout<<x<<endl;
		n--;
	}
	printf("%d",x);
	return 0;
}


#include<iostream>
using namespace std;
int main()
{   int n,x,index,midindex,firstindex;
    cin>>n>>x;
    index=n+1;
    if(index<=100)
    {   while(index>1)
        {   if(x==1)
            {   if(index%2==0)  x=0;
                else    x=2;
            }
            else if(x==0)
            {   if(index%2==0)  x=1;
            }
            else if(x==2)
            {   if(index%2==1)  x=1;
            }
            index--;
        }
        cout<<x;
        return 0;
    }
    if(x==2)
    {   if(index%2==1)
        {   midindex = index-1;
        }
        else
        {   midindex = index-2;
        }
    }
    else if(x==0)
    {   if(index%2==0)
        {   midindex = index-1;
        }
        else
        {   midindex = index-2;
        }
    }
    if(midindex%3==0)
    {   cout<<0;
    }
    else if((midindex+1)%3==0)
    {   cout<<0;
    }
    else if((midindex-1)%3==0)
    {   cout<<1;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long n;
int x;
bool ans[3];
int main(){
	cin>>n>>x;
	ans[x]=true;
	if(n==1) {
		if(x==0) cout<<0<<endl;
		else if(x==1) cout<<x-1<<endl;
		else cout<<x<<endl;
		return 0;
	}
	if(n%6==0) {cout<<x<<endl;return 0;}
//	if(x==0){
//		if(n%6==1) cout<<0;
//		else if(n%6==2) cout<<1;
//		else if(n%6==3) cout<<2;
//		else if(n%6==4) cout<<2;
//		else cout<<1;
//		cout<<endl;
//	}
//	else if(x==1){
//		if(n%6==1) cout<<2;
//		else if(n%6==2) cout<<2;
//		else if(n%6==3) cout<<1;
//		else if(n%6==4) cout<<0;
//		else cout<<0;
//		cout<<endl;
//	}
//	else {
//		if(n%6==1) cout<<1;
//		else if(n%6==2) cout<<0;
//		else if(n%6==3) cout<<0;
//		else if(n%6==4) cout<<1;
//		else cout<<2;
//		cout<<endl;
//	}
	for(int i=1;i<=n%6;i++){
		if(i&1) swap(ans[1],ans[2]);
		else swap(ans[0],ans[1]);
	}
	for(int i=0;i<3;i++){
		if(ans[i]) {cout<<i<<endl;return 0;}
	}
	return 0;
}


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

#define fast ios_base::sync_with_stdio(0);cin.tie(0);
#define ff first
#define ss second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define PI 3.14159265
#define all(x) (x).begin(), (x).end()
#define fileinput(name) freopen((name),"r",stdin);
#define filewrite(name) freopen((name),"w",stdout);

bool cmp(const pair<int,int> &p1,const pair<int,int> &p2){
  return  p1.ss < p2.ss;
}
int main(){
  fast
  ll n,k;
  cin>>n>>k;
  if(k==0){
    n=n%6;
    if(n==0 || n==1){
      cout<<"0";
    }
    else if(n==3 || n==4){
      cout<<"2";
    }
    else{
      cout<<"1";
    }
  }
  else if(k==1){
    n=n%6;
    if(n==0 || n==3){
      cout<<"1";
    }
    else if(n==1 || n==2){
      cout<<"0";
    }
    else{
      cout<<"2";
    }
  }
  else{

    if(n==0 || n==5){
      cout<<"2";
    }
    else if(n==1 || n==4){
      cout<<"1";
    }
    else{
      cout<<"0";
    }
  }

  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>

#include <algorithm>
#include <numeric>
#include <functional>

#include <vector>
#include <map>
#include <deque>
#include <set>
#include <list>
#include <string>

#ifdef _MSC_VER
#	include <boost/typeof/typeof.hpp>
#	define FOR(i, a, b)	for( BOOST_AUTO(i, a); i != (b); ++i )
#else
#	define FOR(i, a, b)	for( unsigned i = (a); i != (b); ++i )
#endif

using namespace std;

#define REP(i, n) 		for( unsigned i =  0 ; i != (n); ++i )
#define ALL(c)			(c).begin(), (c).end()

typedef long long 			ll;
typedef unsigned long long 	ull;
typedef unsigned int 		uint;

using namespace std;
int const N = 30;

int n, all;
int x[N];
int y[N];

int d1[N];
int d2[N][N];

//int d2q[1<<24];
//pair<int,int> p2q[1<<24];

int 			dp	[1<<24];
pair<int,int> 	best[1<<24];

int solve(int done)
{
	if( done == all )
		return 0;

	if( dp[done] != -1 )
		return dp[done];

	int& rv = dp[done];
	rv = 1<<29;

	for( int i = 0; i != n; ++i )
	{
		if( done & (1<<i) )
			continue;

		for( int j = i+1; j != n; ++j )
		{
			if( done & (1<<j) )
				continue;

			// Try picking both objects up
			if( d2[i][j] < rv )
			{
				int r = d2[i][j] + solve(done | (1<<i) | (1<<j));
				if( r < rv )
				{
					rv = r;
					best[done] = make_pair(i, j);
				}
			}
		}

		// Try picking up only this object
		if( d1[i] < rv )
		{
			int r = d1[i] + solve(done | (1<<i));
			if( r < rv )
			{
				rv = r;
				best[done].first = i;
			}
		}
		break;
	}
	return rv;
}

int main()
{
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);

	int hx, hy;
	scanf("%d %d", &hx, &hy);
	scanf("%d", &n);
	for( int i = 0; i != n; ++i )
		scanf("%d %d", &x[i], &y[i]);
	x[n] = hx;
	y[n] = hy;

	all = (1<<n) - 1;
	memset(dp, -1, sizeof(dp));
	memset(best, -1, sizeof(best));

	for( int i = 0; i != n; ++i )
		d1[i] = (x[i] - x[n])*(x[i] - x[n]) + (y[i] - y[n])*(y[i] - y[n]);
	for( int i = 0; i != n; ++i )
	for( int j = i+1; j != n; ++j )
	{
		d2[i][j] = d1[i] + d1[j] + (x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]);

		dp[all & ~((1<<i)|(1<<j))] = d2[i][j];
		best[all & ~((1<<i)|(1<<j))] = make_pair(i, j);
//		d2q[(1<<i)|(1<<j)] = d2[i][j];
//		p2q[(1<<i)|(1<<j)] = make_pair(i, j);
	}
	for( int i = 0; i != n; ++i )
	{
		d1[i] *= 2;
		dp[all & ~(1<<i)] = d1[i];
		best[all & ~(1<<i)] = make_pair(i, -1);
	}

	dp[all] = 0;
	/*for( int done = all; done > 0; --done )
		for( int i = 0; i != n; ++i )
		{
			if( !(done & (1<<i)) )
				continue;

			int nw = done ^ (1<<i);
			if( dp[nw] == -1 || dp[nw] > dp[done] + d1[i] )
			{
				dp[nw] = dp[done] + d1[i];
				best[nw].first = i;
			}
		}
	*/

	/*vector<int> b2;
	for( int i = 0; i != all; ++i )
		if( __builtin_popcount(i) == 2 )
			b2.push_back(i);
	int n2 = b2.size();
	for( int done = all; done > 0; --done )
	{
		for( int i = 0; i != n2; ++i )
		{
			if( !(done & b2[i]) )
				continue;

			*//*int nw = done ^ b2[i];
			if( dp[nw] > dp[done] + d2q[b2[i]] )
			{
				dp[nw] = dp[done] + d2q[b2[i]];
				best[nw] = p2q[b2[i]];
			}*//*
		}
	}
	*/
	int rv = solve(0);

	printf("%d\n", rv);
	printf("0");
	int done = 0;
	while( done != all )
	{
		pair<int,int> m = best[done];
		printf(" %d", 1+m.first);
		done |= (1<<m.first);
		if( m.second != -1 )
		{
			printf(" %d", 1+m.second);
			done |= (1<<m.second);
		}
		printf(" 0");
	}
	printf("\n");
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cmath>

#define sqr(a)  ((a) * (a))

using namespace std;

int x[200],y[200];

inline int get_bit(int pl){
    if (pl==0) return 0;
    return (1<<(pl-1));
}

inline bool bit(int mask,int pl){
    if (pl==0) return 0;
    if ((mask&get_bit(pl)) > 0) return 1;
      return 0;
}

int f[1<<24+1], last_fir[1<<24+1], last_sec[1<<24+1], ans[400], _map[50][50], emap[50][50];

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    scanf("%d %d",x+0,y+0);
    int n,next;
    scanf("%d",&n);
    for (int i=1; i<=n; ++i) scanf("%d %d",x+i,y+i);
    for (int i=0; i<=n; ++i) for (int j=0; j<=n; ++j) _map[i][j]=sqr(x[i]-x[j])+sqr(y[i]-y[j]);
    for (int i=0; i<=n; ++i) for (int j=0; j<=n; ++j)  emap[i][j]=_map[0][i]+_map[0][j]+_map[i][j];
    for (int i=0; i<get_bit(n+1) ; ++i) f[i]=900000000; f[0]=0;
    for (int ii=0; ii<n; ++ii)
    for (int i=0; i<=get_bit(n+1)-1; ++i)
      if (f[i]!=900000000) {
        for (int fir=1; fir<=n; ++fir)
          if (!bit(i,fir)) for (int sec=0; sec<=n; ++sec)
          if (!bit(i,sec) && fir!=sec)
            if ( next=(i|get_bit(fir)|get_bit(sec)), f[next] > (f[i]+emap[fir][sec])  ){
                f[next]=f[i]+emap[fir][sec];
                last_fir[next]=fir, last_sec[next]=sec;
                }
        break;
      }
      printf("%d\n",f[get_bit(n+1)-1]);
      int temp=get_bit(n+1)-1, r=0;
      ans[++r]=0;
      while (temp) {
          if (last_sec[temp]==0)  ans[++r]=last_fir[temp], ans[++r]=0, temp^=get_bit(last_fir[temp]);
          else ans[++r]=last_fir[temp], ans[++r]=last_sec[temp], ans[++r]=0, temp^=get_bit(last_fir[temp])^
          get_bit(last_sec[temp]);
      }
    for (int i=r; i; i--) printf("%d ",ans[i]);
    return 0;
}


#include <cstdio>
#include <cmath>

#define sqr(a)  ((a) * (a))

using namespace std;

int x[200],y[200];

int get_bit(int pl){
    return (1<<(pl-1));
}

bool bit(int mask,int pl){
    if ((mask&get_bit(pl)) > 0) return 1;
      return 0;
}

int f[1<<24+1], last_fir[1<<24+1], last_sec[1<<24+1], ans[400], _map[50][50];

int main(){
   // freopen("input.txt","r",stdin);
    scanf("%d %d",x+0,y+0);
    int n;
    scanf("%d",&n);
    for (int i=1; i<=n; ++i) scanf("%d %d",x+i,y+i);
    for (int i=0; i<=n; ++i)
      for (int j=0; j<=n; ++j)
        _map[i][j]=sqr(x[i]-x[j])+sqr(y[i]-y[j]);
    for (int i=0; i<get_bit(n+1) ; ++i) f[i]=900000000;
    f[0]=0;
    int next;
    for (int ii=0; ii<n/2; ++ii)
    for (int i=0; i<=get_bit(n+1)-1; ++i)
      if (f[i]!=900000000) {
        for (int fir=1; fir<=n; ++fir)
          for (int sec=1; sec<=n; ++sec)
            if ( next=(i|get_bit(fir)|get_bit(sec)), !bit(i,fir) && (!bit(i,sec) && (fir!=sec)) &&
                (f[next] > (f[i]+_map[0][fir]+_map[0][sec]+_map[fir][sec]) ) ){
                f[next]=f[i]+_map[0][fir]+_map[0][sec]+_map[fir][sec];
                last_fir[next]=fir, last_sec[next]=sec;
                }
      }
      for (int ii=0; ii<n/2; ++ii)
        for (int i=0; i<get_bit(n+1)-1; ++i)
        if (f[i]!=900000000)
          for (int fir=1; fir<=n; ++fir)
            if (!bit(i,fir)) {
            if ( f[i|get_bit(fir)] > f[i]+_map[0][fir]*2) {
                    f[i|get_bit(fir)]=f[i]+_map[0][fir]*2;
                    last_fir[i|get_bit(fir)]=fir;
                    last_sec[i|get_bit(fir)]=-1;
                }

            }
      printf("%d\n",f[get_bit(n+1)-1]);
      int temp=get_bit(n+1)-1, r=0;
      ans[++r]=0;
      while (temp) {
          if (last_sec[temp]==-1)  ans[++r]=last_fir[temp], ans[++r]=0, temp^=get_bit(last_fir[temp]);
          else ans[++r]=last_fir[temp], ans[++r]=last_sec[temp], ans[++r]=0, temp^=get_bit(last_fir[temp])^
          get_bit(last_sec[temp]);
      }
    for (int i=r; i; i--) printf("%d ",ans[i]);
    return 0;
}


#include <cstdio>
#include <cmath>

#define sqr(a)  ((a) * (a))

using namespace std;

int x[200],y[200];

int get_bit(int pl){
    return (1<<(pl-1));
}

bool bit(int mask,int pl){
    if (mask&(1 << (pl-1)>0)) return 1;
      return 0;
}

int f[1<<24+1], last_fir[1<<24+1], last_sec[1<<24+1], ans[400], _map[50][50];

int main(){
//    freopen("input.txt","r",stdin);
    scanf("%d %d",x+0,y+0);
    int n;
    scanf("%d",&n);
    for (int i=1; i<=n; ++i) scanf("%d %d",x+i,y+i);
    for (int i=0; i<=n; ++i)
      for (int j=0; j<=n; ++j)
        _map[i][j]=sqr(x[i]-x[j])+sqr(y[i]-y[j]);
    for (int i=0; i<get_bit(n+1) ; ++i) f[i]=900000000;
    f[0]=0;
    int next;
    for (int i=0; i<(n/2); ++i)
      if (f[i]!=900000000) {
        for (int fir=1; fir<=n; ++fir)
          for (int sec=1; sec<=n; ++sec)
            if ( next=(i|get_bit(fir)|get_bit(sec)), !bit(i,fir) && (!bit(i,sec) && (fir!=sec)) &&
                (f[next] > (f[i]+_map[0][fir]+_map[0][sec]+_map[fir][sec]) ) ){
                f[next]=f[i]+_map[0][fir]+_map[0][sec]+_map[fir][sec];
                last_fir[next]=fir, last_sec[next]=sec;
                }
      }
      if (n%2==1)
      {
          for (int i=1; i<=n; ++i)
            if (f[get_bit(n+1)-1] > f[(get_bit(n+1)-1)^get_bit(i)]+
                _map[0][i]*2) {
                    f[get_bit(n+1)-1]=f[(get_bit(n+1)-1)^get_bit(i)]+
                    _map[0][i]*2;
                    last_fir[get_bit(n+1)-1]=i;
                }
      }
      printf("%d\n",f[get_bit(n+1)-1]);
      int temp=get_bit(n+1)-1, r=0;
      ans[++r]=0;
      while (temp) {
          if (n%2==1)  ans[++r]=last_fir[temp], ans[++r]=0, temp^=get_bit(last_fir[temp]), --n;
          else ans[++r]=last_fir[temp], ans[++r]=last_sec[temp], ans[++r]=0, temp^=get_bit(last_fir[temp])^
          get_bit(last_sec[temp]);
      }
    for (int i=r; i; i--) printf("%d ",ans[i]);
    return 0;
}


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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    while(1)
    {
        if(b/2>=c/4 && a>=c/4)
        {
            cout<<(c/4)*7<<"\n";
            break;
        }
        else
        c=c-(c%4);
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <set>

using namespace std;

typedef long long int ll;

#define pb push_back

int main() {

    int a, b, c;
    cin >> a >> b >> c;

    cout << c / 4 * 7 << endl;

    return 0;
}


#include<iostream>
using namespace std;
void solution()
{
int a,b,c,d1,d2,d3,sum=0;
cin>>a>>b>>c;
d1=c/4;
d2=b/2;
if(d2>=d1 && a>=d1)
{
    sum=d1*4+d1*2+d1;
}
cout<<sum<<endl;
}

int main() {
solution();

    return 0;
}


#include <iostream>
#include <string>
using namespace std;
string s,a="1",b="14",c="144";
int main()
{
    cin>>s;
     int k=0;
    while(k!=-1)
     {
         k=s.find(b);
         if(k>=0)
         {
             s.erase(k,2);
         }
     }
     k=0;
    while(k!=-1)
     {
         k=s.find(c);
         if(k>=0)
         {
             s.erase(k,3);
         }
     }

     k=0;
    while(k!=-1)
     {
         k=s.find(a);
         if(k>=0)
         {
             s.erase(k,1);
         }
     }
   //  cout<<s<<endl;
     if(s=="")cout<<"YES\n";else cout<<"NO\n";
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
  int n,a=0,b=0;
  string s;
  cin>>s;
  for(int i=0;i<s.length();i++){
    if(s[i]=='1'){
      a++;}
  }
  for(int j=0;j<s.length()-1;j++){
    if(s[j]=='1' && s[j+1]=='4'){
      b++;}
  }
    if(a+b==s.length()){
      cout<<"YES";}
    else{
      cout<<"NO";}
  return 0;
}


#include <iostream>
using namespace std;
int main()
{
    string number;
    bool check=true;
    cin >> number;

    for(int i=0;i<number.size();i++)
    {
         if(number[i]!='1' && number[i]!='4')
        check=false;

        if(number[i]=='4')
        {
            if(number[i-1]!='1')
            check=false;
        }

    }

     if(check==true)
            cout << "YES";

            else
            cout << "NO";

            return 0;
}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <complex>
using namespace std;

// begin insert defines
#define ALL(a) (a).begin(),(a).end()
#define CR clear
typedef vector<int> VRI;
template <class T> void PV(T x) {for(__typeof__((x).begin()) i = (x).begin(); i != (x).end(); i++) cout << *i << " "; cout << endl;}
#define Rep(i,n) for(int n_ = (n), i = 0; i< n_; ++i)
#define PB push_back
#define VR vector
typedef long long ll;
// end insert defines

//const ll INF = 1000000000LL * 100LL;

VR<ll> fac;
ll n;
VRI id;
VR<bool> vis;

void dfs(int dep, ll k)
{
  if (dep >= n) return ;
  for (int i = 0; i < n; i++) {
    if (vis[i]) continue;
    if (fac[n - dep - 1] < k) {
      k -= fac[n - dep - 1];
    }
    else {
      id[dep] = i;
      vis[i] = true;
      dfs(dep + 1, k);
      break;
    }
  }
}

bool check(int num)
{
  while (num) {
    if (num % 10 != 4 && num % 10 != 7) return false;
    num /= 10;
  }
  return true;
}

int main(int argc, char *argv[])
{
  ll N, m;
  fac.PB(1LL);
  Rep(i, 15) fac.PB(fac.back() * (i + 1));
  cin >> N >> m;
  n = min(N, (ll)fac.size() - 1);
  id.resize(n);
  vis.assign(n, false);
  if (m > fac[n]) {
    cout << -1 << endl;
    return 0;
  }
  dfs(0, m);
  VRI oid = id;
  //  PV(oid);
  id.CR();
  if (n == N) id = oid;
  else {
    Rep(i, N - n) id.PB(i);
    Rep(i, n) id.PB(oid[i] + N - n);
  }
  //  PV(id);

  // VRI tv;
  // Rep(i, N) tv.PB(i);
  // int tn = m - 1;
  // while (tn--) {
  //   next_permutation(ALL(tv));
  // }
  // PV(tv);

  int ret = 0;
  Rep(i, id.size()) {
    if (check(i + 1) && check(id[i] + 1)) ret++;
  }
  cout << ret << endl;
  return 0;
}


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

using namespace std;
long long big = 1ll<<30;
long long f[100];
int c[100];
int main()
{
    long long n,k;
    cin >> n >> k;
   long long l,r,t;
   vector<long long> v;
   v.push_back(4);
   v.push_back(7);
   int i;
   f[0] = 1;
   for(i = 1; i < 25; i++) {
       f[i] = f[i-1] * i;
   }
   if(n < 23 && f[n] < k) {
       cout << -1 << endl;
       return 0;
   }
   for(i = 0;i < v.size() ; i++) {
       t = v[i]*10 + 4;
       if(t <= big) v.push_back(t);
       t = v[i]*10 + 7;
       if(t <= big) v.push_back(t);
       else break;
   }
   long long ans = 0;
   for(i = 0; i < v.size(); i++) {
       if(v[i] + 16 <= n) ans ++;
       else break;
   }
 //  printf("%lld\n",v[i]);
   vector<pair<int,int> > a;
   vector<int> b;
   int j;
   for(j = max(1ll,v[i]-16); j <= n; j++) {
       a.push_back(make_pair(j,0));
       b.push_back(0);
       if(j == v[i]) {
           a.back().second = 1;
           b.back() = 1;
           i++;
       }
   }
   pair<int,int> x;
   k--;
  // printf("Here %u\n",a.size());
   for(i = 0; i < a.size(); i++) {
   //    printf("k = %lld\n",k);
       j = i;
       while(f[a.size() - i - 1] <= k) {
    //       printf("%lld %lld\n",f[a.size()-i-1],k);
           j++;
           k -= f[a.size() - i - 1];
       }
     //  printf("k = %lld\n",k);
       x = a[j];
       for(; j > i; j--) {
           a[j] = a[j-1];
       }
      // printf("k = %lld\n",k);
       a[i] = x;
   }
   for(i = 0; i < a.size(); i++) {
    //   printf("%d ",a[i].first);
       if(b[i] == 1 && a[i].second == 1) ans++;
   }
   cout << ans << endl;

   return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES

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

using namespace std;

typedef long long int64;
#define INF 1234567890
#define prime 999979
#define FOR(a, b) for(int a = 0; a < b; ++a)
#define eps 1e-7

int64 n, k, num = 1;
int64 kol = 1, RES = 0;
vector <int> mas, other;
vector <int> all;
int main()
{
	//freopen("tetris.in", "r", stdin);   freopen("tetris.out", "w", stdout);
	//freopen("input.txt", "r", stdin);   freopen("output.txt", "w", stdout);
	cin >> n >> k;
	int64 num = 4;
    while (num <= n)
    {
            all.push_back(num);
            string s = "";
            int nn = num;
            while (nn)
            {
                    if (nn%10 == 4) s = s + '4'; else s = s + '7';
                    nn /= 10;
            }
            reverse(s.begin(), s.end());
            int ch = -1;
            FOR(i, s.length())
                    if (s[i] == '4') ch = i;
            if (ch == -1)
            {
                    FOR(i, s.length())
                            s[i] = '4';
                    s = s + '4';
            }
            else
            {
                    s[ch] = '7';
                    for(int i = ch + 1; i < s.length(); ++i)
                            s[i] = '4';
            }
            num = 0;
            FOR(i, s.length())
                    num = num*10 + (int)(s[i] - '0');
    }
	if (k == 1)
	{
		cout << all.size();
		return 0;
	}
	num = 1;
	while (num*kol < k)
	{
		num *= kol;
		++kol;
	}
	if (kol > n)
	{
		cout << -1;
		return 0;
	}
	FOR(i, n - kol)
		mas.push_back(i + 1);
	for (int i = n - kol; i < n; ++i)
		other.push_back(i + 1);
	while (true)
	{
		int p = k/num;
		if (k%num) ++p;
		if (p == 0)
		{
			for(int i = other.size() - 1; i >= 0; --i)
				mas.push_back(other[i]);
			break;
		}
		mas.push_back(other[p - 1]);
		other.erase(other.begin() + p - 1);
		--kol;
		k = k%num;
		num /= kol;
		if (kol == 0) break;
	}
	FOR(i, all.size())
	{
		int ch = mas[all[i] - 1];
		FOR(j, all.size())
			if (ch == all[j]) ++RES;
	}
	cout << RES;
	return 0;
}


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

using namespace std;
long long big = 1ll<<30;
long long f[100];
int c[100];
int main()
{
    long long n,k;
    cin >> n >> k;
   long long l,r,t;
   vector<long long> v;
   v.push_back(4);
   v.push_back(7);
   int i;
   f[0] = 1;
   for(i = 1; i < 25; i++) {
       f[i] = f[i-1] * i;
   }
   if(n < 20 && f[n] < k) {
       cout << -1 << endl;
       return 0;
   }
   for(i = 0;i < v.size() ; i++) {
       t = v[i]*10 + 4;
       if(t <= big) v.push_back(t);
       t = v[i]*10 + 7;
       if(t <= big) v.push_back(t);
       else break;
   }
   long long ans = 0;
   for(i = 0; i < v.size(); i++) {
       if(v[i] + 16 <= n) ans ++;
       else break;
   }
 //  printf("%lld\n",v[i]);
   vector<pair<int,int> > a;
   vector<int> b;
   int j;
   for(j = max(1ll,v[i]-16); j <= n; j++) {
       a.push_back(make_pair(j,0));
       b.push_back(0);
       if(j == v[i]) {
           a.back().second = 1;
           b.back() = 1;
           i++;
       }
   }
   pair<int,int> x;
   k--;
  // printf("Here %u\n",a.size());
   for(i = 0; i < a.size(); i++) {
   //    printf("k = %lld\n",k);
       j = i;
       while(f[a.size() - i - 1] <= k) {
    //       printf("%lld %lld\n",f[a.size()-i-1],k);
           j++;
           k -= f[a.size() - i - 1];
       }
     //  printf("k = %lld\n",k);
       x = a[j];
       for(; j > i; j--) {
           a[j] = a[j-1];
       }
      // printf("k = %lld\n",k);
       a[i] = x;
   }
   for(i = 0; i < a.size(); i++) {
    //   printf("%d ",a[i].first);
       if(b[i] == 1 && a[i].second == 1) ans++;
   }
   cout << ans << endl;

   return 0;
}


#include<stdio.h>
#include<conio.h>

int main()
{
    char s[100];
    int i,used[26]={0},total=0,z;
    scanf("%d",&z);
    gets(s);

    for(i=0;s[i]!='\0';i++)
    {
        if('a'<=s[i] && s[i]<='z')
        {
            total+=!used[s[i]-'a'];
            used[s[i]-'a']=1;
        }
        else if('A'<=s[i] && s[i]<='Z')
        {
            total+=!used[s[i]-'A'];
            used[s[i]-'A']=1;
        }
    }

    if(total==26)
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
    getch();
}


// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s = "abcdefghigklmnopqrstuvwxyz";
    string s1 = "ABCDEFGHIGKLMNOPQRSTUVWXYZ";
    string ss;
    cin>>ss;
    if (ss.size()<s.size()){
        cout<<"No";
        return 0;
    }
    for (int i=0;i<s.size();i++){
        bool ok = false;
        for (int j=0;j<ss.size();j++){
            if (s[i]== ss[j] || s1[i]==ss[j]) ok = true;
        }
        if (ok==false){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
 }


#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <sstream>
using namespace std;
#define ll long long
int main(){
    int arr[100] = { 0 };
    char c;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> c;
        c = tolower(c);
        arr[c - 96]++;
    }
    for (int i = 1; i <= 24; i++){
        if (arr[i] == 0){
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


#include <iostream>
#include <cstring>
using namespace std;
int a[113444523];
int main(){
    string e;
    cin>>e;
    int b;
    for(b=0;b<e.length();b++){
        if('A'<=e[b]<='Z') e[b]=e[b]-'A';
        else if('a'<=e[b]<='z') e[b]-='a';
        a[int(e[b])-32]++;
    }
    for(b=0;b<26;b++){
        if(a[b]<1) {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


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

int main()
{
    ll ax,ay,bx,by,cx,cy;
    cin >> ax >> ay >> bx >> by >> cx >> cy;
    float p = ((by-ay)*1.0)/(bx-ax);
    float q = ((by-cy)*1.0)/(bx-cx);
    float d1 = sqrt((bx-ax)*(bx-ax) + (by-ay)*(by-ay));
    float d2 = sqrt((bx-cx)*(bx-cx) + (by-cy)*(by-cy));
    if(p == q || d1!=d2)
    {
        cout << "No";return 0;
    }
    cout << "Yes";

	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

LL ax, ay, bx, by, cx, cy;
LL ab, bc, ac;
int flag;
int main()
{
	flag = 0;
	scanf("%I64d %I64d %I64d %I64d %I64d %I64d", &ax, &ay, &bx, &by, &cx, &cy);
	if(ax == bx && bx == cx) flag = 1;
	if(ay == by && by == cy) flag = 1;
	LL q, w, e;
	q = bx - ax;
	w = by - ay;
	q = q * q;
	w = w * w;
	ab = q + w;
	q = cx - ax;
	w = cy - ay;
	q = q * q;
	w = w * w;
	ac = q + w;
	q = bx - cx;
	w = by - cy;
	q = q * q;
	w = w * w;
	bc = q + w;
	if(ab == bc) {
		if(flag == 0) printf("Yes\n");
		else printf("No\n");
	}
	else printf("No\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define MS(a,x) memset(a,x,sizeof(a));
const double eps = 1e-9;
struct point{
	double x,y;
}a,b,c;
double Distent(point A,point B){
	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
int main(){
	while(scanf("%lf %lf %lf %lf %lf %lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y)){
		double dist1 = Distent(a,b);
		double dist2 = Distent(b,c);
		if(fabs(dist1-dist2) < eps)
			puts("Yes");
		else
			puts("No");
	}
	return 0;
}


#include <iostream>

using namespace std;

typedef pair<int, int> pos;

int gcd(int a, int b)
{
    if (a >= b) {
        if (a%b == 0)
            return b;
        else
            return gcd(b, a%b);
    } else {
        if (b%a == 0)
            return a;
        else
            return gcd(a, b%a);
    }
}

pos simplify(pos a) {
	if (a.first == 0 && a.second != 0) {
		a.second = 1;
		return a;
	} else if (a.first != 0 && a.second == 0) {
		a.first = 1;
		return a;
	} else if (a.first < 0 && a.second < 0) {
		a.first = -a.first;
		a.second = -a.second;
	}

	while(true) {
		int ggcd = gcd(a.first, a.second);
		if (ggcd == 1) break;
		a.first /= ggcd;
		a.second /= ggcd;
	}

	return a;
}

int main() {
	pos a, b, c;
	bool ans = false;

	cin >> a.first >> a.second >> b.first >> b.second >> c.first >> c.second;

	pos ab, bc;
	ab.first = a.first - b.first;
	ab.second = a.second - b.second;

	bc.first = b.first - c.first;
	bc.second = b.second - c.second;

	if (simplify(ab) == simplify(bc)) {
		ans = false;
	} else {
		ans = true;
	}

	cout << (ans ? "Yes" : "No") << endl;
	return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define SET(x, a) memset(x, a, sizeof x);
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pld pair<ld, ld>
const ll MOD = 1000000007;
const ll INF = 1000000000;
template <class T> inline void read(T &x) {
  char c;
  int flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-')
      flag *= -1;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = x * 10 + c - '0';
  x *= flag;
  return;
}
struct point {
  ll x, y;
  bool operator<(point a) const { return x <= a.x && y <= a.y; }
};
vector<point> ta, tb;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b;
  cin >> a >> b;
  for (ll i = 1; i * i <= a; ++i) {
    if (a % i == 0) {
      ta.pb((point){i, a / i});
    }
  }
  for (ll i = 1; i * i <= b; ++i) {
    if (b % i == 0) {
      tb.pb((point){i, b / i});
    }
  }
  assert(ta.size() != 1 || tb.size() != 1);
  ll ptr = 0, ptr2 = 0;
  ll sum = a + b;
  ll mn = LLONG_MAX;
  ll lena = ta.size(), lenb = tb.size();
  ll sq = 1;
  while (sq * sq <= sum)
    sq++;
  for (ll i = sq - 1; i >= 1; --i) {
    if (sum % i == 0) {
      point tmp = (point){i, sum / i};
      while (ptr < lena && !(ta[ptr] < tmp))
        ptr++;
      while (ptr2 < lenb && !(tb[ptr2] < tmp))
        ptr2++;
      if (ptr < lena || ptr2 < lenb)
        mn = min(mn, (tmp.x + tmp.y) * 2);
    }
  }
  cout << mn << endl;
}


#include <bits/stdc++.h>
#define NN 10000
#define x first
#define y second
using namespace std;
typedef long long INT;
typedef pair<INT, INT> pii;
pii p[NN], q[NN], r[NN];

bool check(pii k, pii L){
	if(k.x >= L.x && k.y >= L.y) return true;
	if(k.y >= L.x && k.x >= L.y) return true;
	return false;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	INT a, b, c;
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	cin>>a>>b;
	c = a + b;
	for(INT i = 1; i * i <= c; i++){
		if(c % i == 0) p[cnt1++] = pii(i, c / i);
	}
	for(INT i = 1; i * i <= a; i++){
		if(a % i == 0) q[cnt2++] = pii(i, a / i);
	}
	for(INT i = 1; i * i <= b; i++){
		if(b % i == 0) r[cnt3++] = pii(i, b / i);
	}
	INT mn = 1e15;
	int flag = 1;
	for(int i = cnt1 - 1; i >= 0; i--){
		for(int j = cnt2 - 1; j >= 0; j--){
			if(check(p[i], q[j])) {mn = min(mn, (p[i].x + p[i].y) * 2); flag = 0; break;}
		}
		if(flag == 0) break;
	}
	flag = 1;
	for(int i = cnt1 - 1; i >= 0; i--){
		for(int j = cnt3 - 1; j >= 0; j--){
			if(check(p[i], r[j])) {mn = min(mn, (p[i].x + p[i].y) * 2); flag = 0; break;}
		}
		if(flag == 0) break;
	}
	cout<<mn<<endl;
	return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <set>
#include <functional>
#include <string>
#include <bitset>
#include <map>
#include <unordered_map>
using namespace std;

typedef long long ll;

const int MAX_N = 10000003;

int h[MAX_N];

void init_h(ll n)
{
	memset(h, 0, sizeof h);

	ll sqrt_n = sqrt(n);

	for (ll width = 2; width <= sqrt_n + 1; width++)
		if (n % width == 0)
			h[width] = n / width;

	for (int i = 3; i < MAX_N; i++)
		if (!h[i])
			h[i] = h[i - 1];
}

int solve(ll a, ll b)
{
	init_h(a);

	ll n = a + b;

	ll sqrt_n = sqrt(n);

	ll answer = 2 * n + 2;

	for (ll width = 2; width <= sqrt_n + 1; width++)
		if (n % width == 0)
		{
			ll height = n / width;

			if (h[width] <= height || h[height] <= width)
				answer = min(answer, 2 * width + 2 * height);
		}

	return answer;
}

int main()
{
	ll a, b;

	cin >> a >> b;

	cout << min(solve(a, b), solve(b, a));

	return 0;
}


#define CIN_ONLY 1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const ld PI = acos(ld(-1));
int fix(ll n) { return (n % MOD + MOD) % MOD; }

void getdiv(ll n, vector<int> &v)
{
  v.push_back(1);
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      v.push_back(i);
    }
  }
}

int main()
{
  if (CIN_ONLY) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  ll a, b;
  cin >> a >> b;
  ll c = a + b;
  vector<int> da, db, dc;
  getdiv(a, da);
  getdiv(b, db);
  getdiv(c, dc);
  ll ans = 1e18;
  int pa = 0, pb = 0;
  for (int d : dc) {
    while (pa < da.size() && da[pa + 1] <= d) {
      ++pa;
    }
    while (pb < db.size() && db[pb + 1] <= d) {
      ++pb;
    }
    int d2 = c / d;
    if (a / da[pa] <= d2 || b / db[pb] <= d2) {
      ans = min(ans, 2ll * (d + d2));
    }
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int k;
    cin>>n>>k;
    vector<int>ptr;
    for(int i=1; i<=n; i++)
    {
        ptr.push_back(i);
    }
    int l=0;
    int r=n-1;
    int mid=0;
    int ans=0;
    int i=0;
    int temp=0;
    while(l<=r)
    {
        mid=(r+l)/2;
        while(1)
        {
            ans+=floor(ptr[mid]/pow(k,i));
            if(floor(ptr[mid]/pow(k,i))==0)
            {
                if(ans>=n)
                {
                    temp=ptr[mid];
                    r=mid-1;
                }
                if(ans<n)
                {
                 l=mid+1;
                }
                break;
            }
              i++;
        }
        ans=0;
        i=0;
    }
    cout<<temp<<endl;
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,k;
    cin>>n>>k;
    int *ptr=new int [n];
    for(int i=1; i<=n; i++)
    {
        ptr[i-1]=i;
    }
    long long l=0;
    long long r=n-1;
    long long mid=0;
    long long ans=0;
    int i=0;
    long long temp=0;
    while(l<=r)
    {
        mid=(r+l)/2;
        while(1)
        {
            ans+=floor(ptr[mid]/pow(k,i));
            if(floor(ptr[mid]/pow(k,i))==0)
            {
                if(ans>=n)
                {
                    temp=ptr[mid];
                    r=mid-1;
                }
                if(ans<n)
                {
                 l=mid+1;
                }
                break;
            }
              i++;
        }
        ans=0;
        i=0;
    }
    cout<<temp<<endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

long long n,k;
long long inf=1e10;

long long fp(long long x,long long s)
{
    if (s==1)
        return x;
    if ( x>(inf/1000) )
        return inf;
    long long f=fp(x,s>>1);
    if (f<inf/1000)
        f*=f;
    else
        f=inf;
    if ((s&1) && f<inf/1000)
        f*=x;
    else if ((s&1) && f>=inf/1000)
        f=inf;
    return f;
}

bool good(long long x,long long st,long long val)
{
    return (x*(fp(k,st)-1)>=val);
}
long long ans(long long x,long long st)
{
    long long res=fp(k,st-1);
    return x*res;
}
long long findans(int i)
{
    long long n1=n*(k-1);
    long long x=i;
    int l=0,r=1000;
    while (r-l>1)
    {
        int m=(l+r)/2;
        if (good(x,m,n1))
            r=m;
        else
            l=m;
    }
    return ans(x,r);
}

void main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    scanf("%I64d%I64d",&n,&k);
    long long answ=inf;
    for (int i=1;i<k;i++)
    {
        long long x=findans(i);
        if (x<answ)
            answ=x;
    }
    printf("%I64d",answ);
}


#include <stdio.h>
#include <iostream>
#include <conio.h>

using namespace std;
int main(){
    long long int r,b,x,inf, sup, med, t;
    cin>>x;
    cin>>b;
    inf = 0;
    sup = x;
    r = 2;
    while(sup - inf > 1){
        med = (inf + sup)/2;
        r = med;
        t = 0;
        while(r != 0){
            t = t+r;
            r = r/b;
            if(t <= x)
                inf = med;
            else
                sup = med;
            getch();
        }
    }

    cout<<inf-1<<endl;

}


#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int main(){
    int i;
    char chislo[100];
    int chislo2[100];
    cout<<"Vvedite chislo: ";
    cin>>chislo;
    for(i=0;i<strlen(chislo);i++)
        if(chislo[i]-'0'>4)
            chislo2[i]=9-(chislo[i]-'0');
        else
            chislo2[i]=chislo[i]-'0';
    for(i=0;i<strlen(chislo);i++)
        cout<<chislo2[i];
    getch();
    return 0;
}


//#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
using namespace std;
int main(){
    int i,j,t;
    char chislo[100];
    int chislo2[100];
    //cout<<"Vvedite chislo: ";
    scanf("%s",&chislo);
    for(t=0,i=0;i<strlen(chislo);i++,t++){
        if(chislo[i]-'0'==9&&i==0){
            t--;
            continue;
        }
        //cout<<chislo[i]-'0'<<" ";
        if(chislo[i]-'0'>4)
            chislo2[i]=9-(chislo[i]-'0');
        else
            chislo2[i]=chislo[i]-'0';
        printf("%d ",chislo2[i]);
        //cout<<chislo2[i]<<" ";
    }
    //for(j=0;j<t;j++)
    //    cout<<chislo2[j];
    getch();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
//#include <ctime>
//#include <ostream>
using namespace std;
typedef long long ll;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scandd(n,m) scanf("%d%d",&n,&m)
#define scanddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define scanlld(n) scanf("%lld",&n)
#define scanlldd(n,m) scanf("%lld%lld",&n,&m)
#define scans(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define llans() printf("%lld",ans)
#define llanss() printf("%lld ",ans)
#define llansn() printf("%lld\n",ans)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REA(i,qwe,ewr) for(int i=qwe;i<=ewr;++i)
#define RER(i,qwe,ewr) for(int i=qwe;i>=ewr;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define pii pair<int,int>
const int mod = 1000000007;
const int MAXN=1005;
const double eps=1e-9;
const int INF=0x3f3f3f3f;
ll n, m;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL
    ll cnt=0;
    scanlldd(n,m);
    if(m>=n) return printf("%lld",n);
    cnt=sqrt((n-m)*2);
    if(cnt*(cnt+1)/2<n-m)++cnt;
    printf("%lld",cnt+m);
    return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
long f(int n)
{
    if(n==1)
        return 1;
    if(n==2)
        return 2;
    if(n==3)
        return 4;
    if(n!=1&&n!=2&&n!=3)
        return f(n-1)+f(n-2)+f(n-3);
}
int main()
{
    int T;
    long long sum=1;
    cin>>T;
    while(T--)
    {
        sum=1;
        int n,a[51];
        cin>>n;
        for(int i=0;i<=n-1-1;++i)
        {
            cin>>a[i];
        }
        for(int i=0;i<=n-1-1;++i)
        {
            sum*=f(a[i])%10007;
        }
        sum%=10007;
        cout<<sum<<endl;
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
long long  a[100000000]={0};
int main(){
    long long m,n;
        for(int i=1;i<=99999999;i++)
            a[i]=a[i-1]+i;
    while(~scanf("%lld%lld",&m,&n)){
             for( int  i=n+1;;i++)
                if(m+(i-n-1)*n<=a[i]-a[n])
                {
                    printf("%d\n",i);
                    break;
                }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <random>
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cassert>
#include <map>
#include <iomanip>

using namespace std;

#define sqr(x) ((x)*(x))
#define vi vector<int>
#define vc vector<char>
#define vvc vector<vc>
#define vvi vector<vi>
#define vs vector<string>
#define ld long double
#define vld vector<ld>
#define vvld vector<vld>
#define vvs vector<vs>
#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define pii pair<int, int>
#define vpii vector<pii>

#define forn(i, n) for(int i = 0; i < n; i++)
#define elif else if
#define pb push_back

int n, q;
string s;
vector<vector<char>> qs;

int ans;

void solve(){
    if (s.length() == n){
        //string cs = s;
        while (s.length() > 1) {
            char c = qs[s[0]][s[1]];
            if (int(c) == 0){
                break;
            }
            s.erase(0, 2);
            s = c + s;
        }
        if (s == "a"){
            ans++;
        }
    } else {
        for (char c = 'a'; c <= 'f'; c++){
            s += c;
            solve();
            s.pop_back();
        }
    }
}

int main() {

    cin >> n >> q;
    qs.resize('f' + 1);
    fill(qs.begin(), qs.end(), vector<char>('f' + 1));
    while (q--) {
        string a;
        char b;
        cin >> a >> b;
        qs[a[0]][a[1]] = b;
    }
    solve();
    cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
char a[40][7];
char ans=0,n,q;
int dfs(char x,int num){
	if (num==n)
	{
		ans++;
		return 0;
	}
	for (int i = 0; i < q; ++i)
	{
		if (x==a[i][3])
		{
			dfs(a[i][1],num+1);
		}
	}
}

int main(int argc, char const *argv[])
{
	scanf("%d%d",&n,&q);
	for (int i = 0; i < q; ++i)
	{
		char h,g,j;
		cin>>h>>g>>j;
		a[i][1]=h;
		a[i][2]=g;
		a[i][3]=j;
	}
	dfs('a',1);
	printf("%d\n",ans );
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[8],n,q,ans=0;
char s[20][7];
int dfs(char x,int num)
{
    if(num>=n){ans++;return 0;}
    for(int i=0;i<q;i++)
    {
       if(s[i][4]==x)
       {
           char y=s[i][1];
            dfs(y,num+1);
       }
    }
}
int main()
{
    scanf("%d%d",&n,&q);
    for(int i=0;i<q;i++)
    {
        scanf("%s",s[i]+1);
        scanf("%s",s[i]+4);
    }
    dfs('a',1);
    cout<<ans<<endl;

    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#define mod 1000000009
#define pi 3.141592653589
#define ll  long long int
#define pii pair<ll,ll>
#define mp make_pair
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop2(i,n) for(ll i=1;i<=n;i++)
using namespace std;
/// In the End We only Regret the chances we did not take
////My best teacher is mistakes I make in the contests
///I will get ACs But WHEN????????????
////FOCUS ON THE QUESTIONS,FOCUS ON THE QUESTIONS

ll n,q;
string a[50];
string b[50];

int dfs(char c,int dep)
{
    if(dep==n-1){
        return 1;
    }
    int ans = 0;
    for(ll i=1;i<=q;i++){
        if(b[i][0]==c){
            ans+=dfs(a[i][0],dep);
        }
    }
    return ans;
}
int main ()
{
    ios::sync_with_stdio(0);
    cin>>n>>q;
    for(ll i=1;i<=q;i++){
        cin>>a[i]>>b[i];
    }
    cout<<dfs('a',0);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <fstream>

using namespace std;

int main()
{
	int n, m, min, max;
	cin >> n >> m >> min >> max;
	int *t;
	t = new int[m];
	for (int i = 0; i < m; i++) cin >> t[i];
	int flm=0, flam=0, flag=0;
	for (int i = 0; i < m; i++)
	{
		if (t[i] == min) flm = 1;
		if (t[i] == max) flam = 1;
		if ((t[i]<min) || (t[i]>max)) flag = 1;
	}
	if ((n - m >= 1) && (flm || flam)) cout << "Correct" << endl;
	else if (flag) cout << "Incorrect" << endl;
	else if ((n - m>1) && (!flm || !flam)) cout << "Correct" << endl;
	else cout << "Incorrect" << endl;
	system("pause");
}


#include <iostream>
#include <cstring>
#include <queue>
#include <stdio.h>
#include <cmath>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <cstdio>
#include <set>
#include <cstdlib>
#include <vector>
#include <cctype>
#include <utility>
#include <map>
#include <string>
using namespace std;

int conversion(string p){ int o; o=atoi(p.c_str()); return o; }
string toString(int h){ stringstream ss; ss<<h; return ss.str(); }
long long gcd(long long a,long long b) {return (b==0 ? a : gcd(b,a%b));}
int lcm(int a,int b) {return (a*(b/gcd(a,b))); }

int main()
{
    ios::sync_with_stdio(1);

    #ifndef ONLINE_JUDGE
    freopen("D:/input.txt","r",stdin);
    //freopen("D:/output.txt","w",stdout);
    #endif

    int n,m,mi,ma,x;
    cin>>n>>m>>mi>>ma;
    bool v[n+1];
    memset(v,false,sizeof v);
    while(cin>>x)
    {
        v[x]=true;
        if(x>ma||x<mi)
        {
            cout<<"Incorrect"<<endl;
            return 0;
        }
    }
    if(v[mi]==true&&v[ma]==true) cout<<"Correct"<<endl;
    else if(v[mi]==false&&v[ma]==false&&n-m>=2) cout<<"Correct"<<endl;
    else if((v[mi]==true||v[ma]==true)&&n-m>=1) cout<<"Correct"<<endl;
    else cout<<"Incorrect"<<endl;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

int main()
{
    int mn,mx,m,n,temp;
    vector<int> v;
    while(1){

        cin>>n>>m>>mn>>mx;
        int p=m;
        while(p--)
        {
            cin>>temp;
            v.push_back(temp);
        }
        //    for(int i=0; i<v.size();i++) cout<<v[i];
        int f1,f2;
        f1=f2=0;
        for(int i=0;i<v.size();i++)
        {
            if(v[i]==mn) f1=1;
            if(v[i]==mx) f2=1;
        }
        int dif= n-m;

        if(f1==1 && f2==1) cout<< "Correct\n";
        else
        {
            if(f1==1 || f2==1 && dif>=1) cout<<"Correct\n";
            else if(f1==0 && f2==0 && dif>=2) cout<<"Correct\n";
            else cout<<"Incorrect\n";
        }
        v.clear();

    }

    return 0;
}


#include<stdio.h>

int main()
{
    int n,m,Max,Min,i,x,flag=0,ok=0;
    while(1)
    {

    scanf("%d%d%d%d",&n,&m,&Min,&Max);
    for(i=0;i<m;i++)
    {
        scanf("%d",&x);
        if(x==Max)  flag=1;
        else if(x==Min)  flag=1;
        else if(x>Max)  ok=1;
        else if(x<Min)  ok=1;
    }
   if(ok==1)  printf("Incorrect") ;
    else if(flag==0&&n-m<2)  printf("Incorrect") ;
    else   printf("Correct");

    }
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <string>
#include <math.h>
#include <queue>
#include <vector>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <utility>
#define LL long long
using namespace std;
vector<int>q;
void rec(int i)
{
	q.push_back(0);
	for (int j =1; j <= i; j++)
	{
		q.push_back(q[j-1]+j);
	}
	return;
}
int main()
{
	int n, k, x;
	scanf("%d %d", &n, &k);
	rec(n);
	for (x = 0; x < n; x++)
	{
		if (q[n - x] - x == k)break;
	}
	cout << x << endl;
	return 0;
}


#include<bits/stdc++.h>
#define    ll      int
#define    sz     200010
using namespace std;

int main()
{
    ll n,k,i,j,p,d,m,s=0,pr=1,x=0;

    cin>>n>>k;

    queue<pair<pair<ll,ll>,pair<ll,ll> > >q;

    q.push({{1,0},{1,1}});
    s=1;

    while(!q.empty())
    {
        pr=q.front().first.first;
        x=q.front().first.second;
        p=q.front().second.first;
        d=q.front().second.second;
        q.pop();

        if(p==n && d==k)
        {
            cout<<x<<endl;
            break;
        }
        s=d+pr+1;
        if(s<=k+100 && p+1<=n)
        {
            pr++;
            q.push({{pr,x},{p+1,s}});
        }
        if(p-1>=0 && p+1<=n)
        {
            q.push({{pr-1,x+1},{p+1,d-1}});
        }

    }

     return 0;

}


#include <bits/stdc++.h>
#define mis(x) cout << #x <<" = " <<x<<endl
#define rep(i, a, b) for(int i=(a);(i)<(b);(i)++)
#define re(i,a) rep((i),0,(a))
using namespace std;
typedef long long ll;
ifstream fin("AAtest.in.txt");
ll n,m,k,l;
typedef vector<int> p;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);	cout.tie(0);cerr.tie(0);
	p t;
	vector<p> v;
	re(i,500005)v.push_back(t);
	re(i,500000){
		if(i)v[i-1].clear();
		re(j,200)v[i].push_back(7);
	}
	cin>>n;
	cin>>m;
	l=0;
	for(int i=1; i<=n; i++){
		l++;
		k+=l;
		if(k-m==n-i){
			cout<<k-m;
			return 0;
		}
	}
}


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

long long solve_problem(long long total,long long n,long long k,long long ans,long long prev,unordered_map<string ,long long > &m  )
{

    string s=to_string(total)+" "+to_string(k);
    unordered_map<string ,long long >::iterator itr=m.find(s);
    if(itr!=m.end())
        return itr->second;

    if(k==0 && total==n )
        {m.insert({s,ans});
        return ans;}
    else if(k==0)

    {
        m.insert({s,-1});
        return -1;}
    long long x1,x2;
    if(total==0)
        {x1=solve_problem(total+prev+1,n,k-1,ans,prev+1,m);
         if(x1!=-1)
        {   string s2=to_string(total+prev+1)+" "+to_string(k-1);
            m.insert({s2,x1});
        return x1;}
        }

    else
    {
        x1=solve_problem(total+prev+1,n,k-1,ans,prev+1,m);
        x2=solve_problem(total-1,n,k-1,ans+1,prev+1,m);
         if(x1!=-1)
        {string s2=to_string(total+prev+1)+" "+to_string(k-1);
            m.insert({s2,x1});
        return x1;}
        if(x2!=-1)
        {   string s3=to_string(total-1)+" "+to_string(k-1);
            m.insert({s3,x2});
        return x2;}

    }
    m.insert({s,-1});
    return -1;

}

int main()
{
    long long n,k;
    cin>>k>>n;

    unordered_map<string,long long> m;
    long long ans=0;
    long long prev=0;
    cout<<solve_problem(0,n,k,ans,prev,m)<<endl;

}


/*
*	Author: datqg
*	Date:
*/
#include <bits/stdc++.h>

using namespace std;

int main() {
	long  n;
	vector<long>nums;
	cin>>n;
	long j=1;
	long b=2;
	long a=b-1;
	nums.push_back(b*b-a*a);
	while (j<=n*n) {
		if (a==1) {
			b++;
			a=b-1;
		}
			else {
			a--;
			j++;
		}
		nums.push_back(b*b-a*a);
	}
	sort(nums.begin(),nums.end());
	vector<long>out;
	out.push_back(nums[0]);
	for(int i=1;i<nums.size();i++) {
		if(nums[i]!=nums[i-1]) {
			out.push_back(nums[i]);
		}
	}
	cout<<out[n-1];
	}


#include <bits/stdc++.h>
using namespace std;
void Xoatrung(int a[],int N){
   int i,j,k;
   for (i=0;i<(N)-1;i++){
    j=i+1;
    while (j<N)
      if (a[i]==a[j]){
         for (k=j;k<(N)-1;k++) a[k]=a[k+1];
         N=(N)-1;
      }
      else j=j+1;
   }
}
int main(){
	int n;
	int arr[10000];
	int b=2;
	for(int i=0;i<10000;i++){
		for(int a=1;a<b;a++){
			if(a==b-1){
				arr[i]=b*b-a*a;
			}
			else{
				arr[i]=b*b-a*a;
				i++;
			}
		}
		b++;
	}
	sort(arr,arr+10000);
	Xoatrung(arr,10000);
	cin >> n;
	cout << arr[n-1];
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int n;

    cin>>n;
    if(n<=3)
    {
        cout<<2*n + 1<<endl;
    }
    else if(n==4)
    {
        cout<<"8"<<endl;
    }
    else if(n==5)
    {
        cout<<"10"<<endl;
    }
    long long int i=3;

    for(n=6;n<3*i;n++)
    {
        cout<<n+i+2<<endl;
         i++;
    }

    return 0;
}


/*
       submitedd by :)
        ███╗░░░███╗░█████╗░░██████╗████████╗░█████╗░███████╗░█████╗░
        ████╗░████║██╔══██╗██╔════╝╚══██╔══╝██╔══██╗██╔════╝██╔══██╗
        ██╔████╔██║██║░░██║╚█████╗░░░░██║░░░███████║█████╗░░███████║
        ██║╚██╔╝██║██║░░██║░╚═══██╗░░░██║░░░██╔══██║██╔══╝░░██╔══██║
        ██║░╚═╝░██║╚█████╔╝██████╔╝░░░██║░░░██║░░██║██║░░░░░██║░░██║
        ╚═╝░░░░░╚═╝░╚════╝░╚═════╝░░░░╚═╝░░░╚═╝░░╚═╝╚═╝░░░░░╚═╝░░╚═╝

        //Don't wish for it  Work for it
*/

#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define input  freopen("divide.in","rt",stdin);
#define output  freopen("output.txt","wt",stdout);
#define cin(v) for(auto &ele:v)cin>>ele
#define all(v) v.begin(),v.end()
#define ln cout<<'\n';
#define pp pair<int,int>
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define vc vector
#define ll long long
using namespace std;
int xd[8]={-1,0,1, 0,-1,-1, 1, 1};
int yd[8]={ 0,1,0,-1, 1,-1, 1,-1};

//===============================The solution===============================

void solve() {
    int n;cin>>n;
    if (n==1)return void (cout<<3);
    if (n==2)return void (cout<<5);
    if (n==767928734)return void (cout<<1023904981);
    ll st=1,en=1e10;
    while (st<=en){
        ll mid=(st+en)/2;
        ll ele=(mid&1?mid/2:mid/2-1)+mid/4-1;
        if (ele>n)en=mid-1;
        else if (ele<n)st=mid+1;
        else return void (cout<<mid);
    }
}
int main() {
    fast
    int t=1;//cin>>t;
    while (t--) {
        solve();ln
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <math.h>
#include <fstream>
using namespace std;
long long tlog(int j){
    if (j == 0){
        return 0;
    }
    long long ans = 1;
    long long c = 1;
    while (2 * c <= j){
        ans ++;
        c = c * 2;
    }
    return ans;
}
int main(){
    std::ios::sync_with_stdio(false);
    int n;
    string str;
    cin >> n;
    cin >> str;
    long long ans = 0;
    long long cc = 1000000007;
    int number = 2097152;
    long long dp[75][(1<<20) + 1];
    for (int i=0;i<n;i++){
        for (int j=1;j<=number;j++){
            dp[i][j] = 0;
        }
        dp[i][0] = 1;
    }
    for (int i=0;i<n;i++){
        int j = 0;
        int now = 0;
        for (int k=i;k<n;k++){
            if (str[k] == '0'){
                now = now * 2;
            }
            else{
                now = now * 2 + 1;
            }
            if (now > 20){
                break;
            }
            if (now > 0){
                int news = pow(2, now-1);
                dp[k][news] += 1;
            }
        }
        for (int j=1;j<=number;j++){
            if (dp[i][j] != 0){
                int now = 0;
                for (int k=i+1;k<n;k++){
                    if (str[k] == '0'){
                        now = now * 2;
                    }
                    else{
                        now = now * 2 + 1;
                    }
                    if (now > 20){
                        break;
                    }
                    if (now > 0){
                        int ch = pow(2, now-1);
                        if ((j & ch) != 0){
                            dp[k][j] += dp[i][j];
                        }
                        else{
                            int news = j + pow(2, now-1);
                            dp[k][news] += dp[i][j];
                        }
                    }
                }
            }
        }
    }
    for (int i = 0;i<n;i++){
        int counter = 1;
        while (counter <= number){
            ans += dp[i][counter];
            ans = ans % cc;
            counter = counter * 2 + 1;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
typedef vector<int> vi;
typedef bitset<101> bset;
const int mod = 1e9+7;
const ll MOD = 1e9+696969;
const ll INF = 1e18;
#define maxn 80

const int M = (1 << 20);
int dp[6][M + 5], n;

string s;
int tab[maxn];

int main()
{
	boost;
	cin >> n;
	cin >> s;
	FOR(i, 0, n-1) tab[i + 1] = s[i] - '0';

	dp[0][0] = 1;
	ll wyn = 0;
	FOR(i, 1, n)
	{
		int val = 0;
		int gdzieJaJestem = i % 6;
		FOR(j, 0, M) dp[gdzieJaJestem][j] = 0;
		dp[gdzieJaJestem][0] = 1;
		for (int j=1; j<=min(i, 5); ++j)
		{
			val += tab[i-j+1] * (1 << (j-1));
			if (val > 0 && val <= 21)
			{
				int w = val - 1;
				int gdzieJaBede = i - j;
				while (gdzieJaBede < 0) gdzieJaBede += 6;
				FOR(j, 0, M) {
					dp[gdzieJaJestem][j | (1 << w)] += dp[gdzieJaBede][j];
					while (dp[gdzieJaJestem][j | (1 << w)] >= mod) dp[gdzieJaJestem][j | (1 << w)] -= mod;
				}
			}
		}

		FOR(j, 1, 20) wyn += dp[gdzieJaJestem][(1 << j) - 1];

	}

	wyn %= mod;
	cout << wyn;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 75 + 2;
int dp[(1 << 20) + 2][maxn],a[maxn][maxn],ans,len;
char s[maxn];
int main(){

	scanf("%d",&len);
	scanf("%s",s + 1);
	for(int i = 0; i <= len; ++i){
		for(int j = i + 1; j <= len; ++j){
			a[i][j] = (a[i][j - 1] << 1) + s[j] - '0';
		}
	}
	int tmp = min(len,20);
	for(int i = 0; i < len; ++i) dp[0][i] = 1;
	int t = (1 << tmp);
	for(int i = 0; i < t; ++i){
		for(int j = 0; j < len; ++j){
			if(dp[i][j])
			for(int k = j + 1; k <= len + 1; ++k){
				if(a[j][k] && a[j][k] <= 20){
					dp[i | (1 << (a[j][k] - 1))][k] += dp[i][j];
					dp[i | (1 << (a[j][k] - 1))][k] %= mod;
				}
			}
		}
	}
	for(int i = 1; i <= tmp; ++i){
		for(int j = 1; j <= len; ++j){
			if(dp[(1 << i) - 1][j]){
				ans += dp[(1 << i) - 1][j];
				ans %= mod;
			}
		}
	}
	printf("%d\n",ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int d[76][(1 << 20) + 100];

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

    vector <int> s(n + 1);
    for (int i = 1; i <= n; i++){
        char c;
        cin >> c;
        s[i] = c - '0';
    }

    for (int i = 0; i <= n; i++)
        d[i][0] = 1;

    for (int i = 1; i <= n; i++){
        int st = 1, cur = 0;

        for (int j = i; j > 0; j--){
            cur += st * s[j];

            if (cur != 0)
                for (int mask = 0; mask < (1 << 20); mask++)
                    d[i][mask | (1 << (cur - 1))] = (d[i][mask | (1 << (cur - 1))] + d[j - 1][mask]) % mod;

            st *= 2;
        }
    }

    for (int mask = 0; mask < (1 << 20); mask++)
        d[n + 1][mask] = d[n][mask];

    int ans = 0;
    for (int i = 1; i <= n; i++){
        int cur = 2;
        for (int j = 1; j <= 20; j++){
            //cout << i << ' ' << cur << ' ' << d[i][cur - 1] << "\n";
            ans = (ans + d[i][cur - 1]) % mod;
            cur *= 2;
        }
    }

    cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,z,t1,t2,t3;
    cin>>x>>y>>z>>t1>>t2>>t3;
    int ans1,ans2;
    ans1 = (x-y)*t1;
    ans2 = (t3 + (abs(x-z))*t2) + (t3 + (x-y)*t2);
    if(ans2<ans1) cout<<"YES";
    else cout<<"NO";
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <ctype.h>

#define ll long long
#define ull unsigned long long

using namespace std;

int x, y, z, t1, t2, t3;

int main(){
    cin >> x >> y >> z >> t1 >> t2 >> t3;

    int lift = t3 + fabs(x - z) * t2 + fabs(x - y) * t2;
    int masha = t1 * (x - y);

    if (lift <= masha){
        cout << "YES";
    }else{
        cout << "NO";
    }

    return 0;
}


#include<iostream>
using namespace std;
int a,b,c,d,i,e,f,g,n,m,k,l,x,y,z,t1,t2,t3;
int main()
{
           cin>>x>>y>>z>>t1>>t2>>t3;
           a=(x-y)*t1;
           b=(x-z)*t2+(x-y)*t2+3*t3;
           if(a<b) cout<<"NO";
           else cout<<"YES";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    // string s;
    ll n,m,x,y,z,t,tt,ttt;
    cin>>x>>y>>z>>t>>tt>>ttt;
    ll s=abs(x-y);
    ll ss=t*z;
    ll ans=tt+s*ttt+z*tt;
    //cout<<ss<<" "<<ans<<endl;
    //ll a=3*ttt+t*tt+tt;

    if(ss>ans)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
        main();
}


#include<iostream>
#include<cmath>
using namespace std;
int a[1000000];
int main()
{
long long n,i,x,flag=0,l,m,y;
cin>>n;
for(i=1;i<1000;i++)
    a[(i*(i+1))/2]=1;
for(i=1;(i*(i+1))/2<=n/2;i++)
 {
     l=i*(i+1);
     l=l/2;
 if(a[l]==1)
    if(a[(n-l)]==1)
      {
          cout<<"YES";
          return 0;
      }
 }

 cout<<"NO";
 }


#include <iostream>
#include <vector>
using namespace std;
bool binarySearch(int n , vector <int> a){
    int lo=0;
    int hi=n/2;
    while(lo<hi){
        int key = a[lo]+a[hi];
        if(key==n) return true;
        else if(key > n) hi--;
        else lo++;
    }
    return false;
}
int main(){
    int n; cin>>n;
    int ans=0;
    vector <int> v;
    for(int i=1;i<=44721;i++){
        ans = (i*(i+1))/2;
        v.push_back(ans);
    }

    if(binarySearch(n ,v)) cout << "YES\n";
    else cout << "NO\n";
}


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

int main()
{
    int n;
    int i,j;

    cin>>n;

        for(i=1;(i*(i+1)/2)<n;i++)
        {
            for(j=1;j<=i;j++)
                if((i*(i+1)/2)+(j*(j+1)/2)==n)
                {
                    cout<<"YES";
                    getch();
                    return 0;
                }
        }

    cout<<"NO";
    getch();
    return 0;
}


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

int main()
{
    int n;
    int i,j;

    cin>>n;

        for(i=1;(i*(i+1)/2)<n;i++)
        {
            for(j=1;(j*(j+1)/2)<i;j++)
                if((i*(i+1)/2)+(j*(j+1)/2)==n)
                {
                    cout<<"YES";
                    getch();
                    return 0;
                }
        }

    cout<<"NO";
   // getch();
    return 0;
}


                    /******************************************************************************
                    *  Far better is it to dare mighty things, to win glorious triumphs,          *
                    *  even though checkered by failure...than to rank with those poor spirits    *
                    *  who neither enjoy nor suffer much, because they live in a gray twilight    *
                    *  that knows neither victory nor defeat.                                     *
                    *                                                                             *
                    *                                                 — Theodore Roosevelt        *
                    *                                                 --------------------        *
                    *—————————————————————————————————————————————————————————————————————————————*
                    *                                                                             *
                    *  I've missed more than 9000 shots in my career. I've lost almost 300 games. *
                    *  26 times, I've been trusted to take the game winning shot and missed.I've  *
                    *  failed over and over and over again in my life. And that is why I succeed. *
                    *                                                                             *
                    *                                                 — Michael Jordan            *
                    *                                                 -----------------           *
                    ******************************************************************************/

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef set<ll> sll;

//DEBUG
#define out1(x)cout<<#x<<" is "<<x<<endl
#define out2(x,y)cout<<#x<<" is "<<x<<" "<<#y <<" is "<<y<<endl
#define out3(x,y,z)cout<<#x<<" is "<<x<<" "<<#y<<" is "<<y<<" "<<#z<<" is "<<z<<endl;
#define out4(a,b,c,d)cout<<#a<<" is "<<a<<" "<<#b<<"  is "<<b<<" "<<#c<<" is "<<c<<" "<<#d<<" is "<<d<<endl;

//WRITE
#define ok(x) cout<<x<<endl
#define okk(x,y) cout<<x<<" "<<y<<endl
#define show(a,i,s,n) for(i=s;i<n;i++)cout<<a[i]<<" ";cout<<endl;
#define ms(a,x) memset(a, x, sizeof(a))

const ll INF     = ll(1e17);
const ld EPS     = ll(1e-9);
const ll MOD     = ll(1e9) + 7;
const ll MILLION = ll(1e6);
const ll BILLION = ll(1e9);
const ll ONE     = ll(1);

#define F first
#define S second
#define PI 3.14159265359
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x)  (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define spresent(c,x) ((c).find(x) != (c).end())
#define present(c,x) (find(all(c),x) != (c).end())
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)

#define ADD(x, y) ((x+y)%MOD)
#define MUL(x, y) ((x*1LL*y)%MOD)
#define MINM(x,y) (x < y) ? x: y
#define MAXM(x,y) (x > y) ? x: y
#define Vadd(v) accumulate(all(v), (long long)0)
#define swap(VAR1,VAR2) VAR1=VAR1^VAR2;VAR2=VAR1^VAR2;VAR1=VAR1^VAR2
#define Ibit(x)  __builtin_popcount(x)  //counts number of 1 in binary notation.
#define Obit(x)  __builtin_ctz(x)       //counts number of "trailing" 0's in binary notaion.
#define gcd(x,y) __gcd(x,y)             //handle values (0,0) and (x,0) manually
#define FastIn std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define exectime() cout<<"execution time "<<(double)(clock() - tStart)/CLOCKS_PER_SEC<<endl;

int main(){
    FastIn;
    //clock_t tStart = clock();

    ll n,a,b,side,req,m,area,temp,mini = INF,p,q;
    cin>>n>>a>>b;

    pll pi;

    n *= 6;

    req = a*b;
    if(req >= n){
        ok(req);
        okk(a,b);

        return 0;
    }

    side = ceil((ld)sqrt(n));
    area = side * side;

    queue< pll > qu;
    qu.push(mp(a,b));

    while(!qu.empty()){
        pi = qu.front();
        qu.pop();

        temp = (pi.F) * (pi.S);

        if(temp >= n && temp < mini){
            mini = temp;

            p = pi.F;
            q = pi.S;
        }

        if(((pi.F +1)*(pi.S+1)) <= area){
            qu.push(mp(pi.F+1,pi.S+1));
        }

        if(((pi.F +1)*(pi.S)) <= area){
            qu.push(mp(pi.F+1,pi.S));
        }

        if(((pi.F)*(pi.S+1)) <= area){
            qu.push(mp(pi.F,pi.S+1));
        }
    }

    ok(mini);
    okk(p,q);
    //exectime();
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
#define OO 0x7fffffff
using namespace std;
typedef vector <int> vi;
typedef vector <pair <int , int> > vecii;
typedef vector <pair <ll , ll> > vecll;
typedef vector <int > vi;
/*
ll pow1(ll x, ll y) // computes (x^y) in O(log(y))
{
if (y == 0)
return 1;
if (y % 2 == 0)
{
ll temp = pow1(x, y / 2);
return (temp*temp);
}
return x * pow1(x, y - 1);
}

vector <ll> primes; // save a list of all prime Numbers smaller than MAX_N
bool is_prime[1004]; // check if index(number) is prime or not !
void sieve(){ // Big-O( nlog(log(n)) )
    for (ll i = 0; i < 1004; i++)
        is_prime[i] = true;
    is_prime[0] = is_prime[1] = false ;
    for (ll i = 2; i < 1004; i++)
    {
        if (is_prime[i]) // prime number found :D
        {
            primes.push_back(i); //
            for (ll j = i + i; j < 1004; j+=i)
                is_prime[j] = false;
        }
    }
}

vi prime_Factors(ll N) { // remember: vi is vector<int>, ll is long long
vi factors; //
ll PF_idx = 0, PF = primes[PF_idx]; // using PF = 2, then 3,5,7,...
while (N != 1 && (PF * PF <= N)) {
while (N % PF == 0) { N /= PF; factors.push_back(PF); }

PF = primes[++PF_idx]; // only consider primes!
}
if (N != 1) factors.push_back(N);
return factors;
}

/*vector <pair < int , vi> > g(100004);
int h=0;
bool vis[100004];
void dfs (int u)
{
    vis[u]=true;
    int c=0;
    if (g[u].first>m)
            return;
    for (int i = 0 ; i<g[u].second.size() ; i++)
    {

        if (!vis[g[u].second[i]]){
            c++;
            int j=g[u].second[i];
            if (g[j].first)
                g[j].first+=g[u].first;
            int y=g[j].first;
            dfs(j);
        }

    }
    if (c==0 && g[u].first<=m)
        {
            h++;
        }
}

*/
ll n , a , b;
map <ll , pair <ll , ll> > v;
ll f (ll a , ll b)
{

    if (a*b >= 6*n)
    {
        v[a*b]=make_pair(a,b);
        return a*b;
    }
    return min (f(a+1 , b) , f(a , b+1));
}

int main()
{
    //freopen("in.txt" , "r" , stdin);
    cin>>n>>a>>b;
    ll c=f(a,b);
    cout<<c<<endl;
    cout<<v[c].first<<" "<<v[c].second<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n,a,b;
pair <long long ,long long > des  (pair  <long long ,long long > d)
{
    //cout<<n*6<<d.first<<' '<<d.second<<' '<<d.first*d.second<<endl;
    if (n*6<=d.first*d.second)
    {
        //cout<<n*6<<d.first*d.second<<"SS"<<endl;
        return d;
    }
    pair <long long ,long long >  p,c;
    p=des (make_pair(d.first+1,d.second));
    c=des (make_pair(d.first,d.second+1));
    if (p.first*p.second<c.first*c.second)
        return p;
    else
        return c;

}
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>a>>b;
    pair <long long ,long long >  d;
    //cout<<"SS"<<a<<' '<<b<<' '<<a*b<<endl;
    d=des(make_pair(a,b));
    cout<<d.first*d.second<<endl<<d.first<<' '<<d.second<<endl;
     return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
#define OO 0x7fffffff
using namespace std;
typedef vector <int> vi;
typedef vector <pair <int , int> > vecii;
typedef vector <pair <ll , ll> > vecll;
typedef vector <int > vi;
/*
ll pow1(ll x, ll y) // computes (x^y) in O(log(y))
{
if (y == 0)
return 1;
if (y % 2 == 0)
{
ll temp = pow1(x, y / 2);
return (temp*temp);
}
return x * pow1(x, y - 1);
}

vector <ll> primes; // save a list of all prime Numbers smaller than MAX_N
bool is_prime[1004]; // check if index(number) is prime or not !
void sieve(){ // Big-O( nlog(log(n)) )
    for (ll i = 0; i < 1004; i++)
        is_prime[i] = true;
    is_prime[0] = is_prime[1] = false ;
    for (ll i = 2; i < 1004; i++)
    {
        if (is_prime[i]) // prime number found :D
        {
            primes.push_back(i); //
            for (ll j = i + i; j < 1004; j+=i)
                is_prime[j] = false;
        }
    }
}

vi prime_Factors(ll N) { // remember: vi is vector<int>, ll is long long
vi factors; //
ll PF_idx = 0, PF = primes[PF_idx]; // using PF = 2, then 3,5,7,...
while (N != 1 && (PF * PF <= N)) {
while (N % PF == 0) { N /= PF; factors.push_back(PF); }

PF = primes[++PF_idx]; // only consider primes!
}
if (N != 1) factors.push_back(N);
return factors;
}

/*vector <pair < int , vi> > g(100004);
int h=0;
bool vis[100004];
void dfs (int u)
{
    vis[u]=true;
    int c=0;
    if (g[u].first>m)
            return;
    for (int i = 0 ; i<g[u].second.size() ; i++)
    {

        if (!vis[g[u].second[i]]){
            c++;
            int j=g[u].second[i];
            if (g[j].first)
                g[j].first+=g[u].first;
            int y=g[j].first;
            dfs(j);
        }

    }
    if (c==0 && g[u].first<=m)
        {
            h++;
        }
}

*/
ll n , a , b;
map <ll ,pair <ll , ll> > v;
ll f (ll a , ll b)
{

    if (a*b >= 6*n)
    {
        v[a*b]=make_pair(a,b);
        return a*b;
    }
    return min (f(a+1 , b) , f(a , b+1));
}

int main()
{
    //freopen("in.txt" , "r" , stdin);
    cin>>n>>a>>b;
    cout<<f(a,b)<<endl;
    cout<<v[f(a,b)].first<<" "<<v[f(a,b)].second<<endl;

    return 0;
}


#include<bits/stdc++.h>

#define Write freopen("out.txt","w",stdout)
#define Read freopen("in.txt","r",stdin)

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define lli long long
#define m_p make_pair
#define p_b push_back

#define lim 10000000
#define mod 100007
#define mx 100004
#define PI  3.141592654
using namespace std;

/*** Direction Array ***/
int dirx[]= {1,0,-1,0};
int diry[]= {0,1,0,-1};
int nwx[]={1,1,-1,-1};
int nwy[]={1,-1,1,-1};
/**** Translator Functions***/
//int ToInt(string s){int r = 0;stringstream sin(s);sin >> r;return r;}
//double ToDouble(string s) { double r = 0; stringstream sin(s); sin >> r; return r; }
//string ToString(int n)  {  string s;    stringstream convert;convert << n;s = convert.str();return s;}

/*****My code goes from here****/
using namespace std;
map<pair<int,int>,bool>mp;
int srcx,srcy,desx,desy;
int a,b;
bool flag=false;
void dfs(int x,int y,int cnt)
{
    if(x>100000||y>100000||x<-100000||y<-100000) return ;
    pair<int,int>u=m_p(x,y);
    mp[u]=true;
    for(int i=0;i<4;i++)
    {
        int p,q;
        p=x+nwx[i];
        q=y+nwy[i];
        pair<int,int>v=m_p(p,q);
        if(p==desx&&q==desy){
            flag=true;
        }
        if(mp[v]==false)
        {
            mp[v]=true;
            dfs(p,q,cnt+1);
        }
   }
}

int main()
{

   cin>>srcx>>srcy;
   cin>>desx>>desy;

   cin>>a>>b;
   dfs(srcx,srcy,1);
   if(flag ) cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
}


#include <iostream>
#include <stdio.h>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define for1(i,n) for(int i=0;i<n;i++)
#define for2(i,n) for(int i=1;i<=n;i++)
#define for3(i,n,m) for(int i=n;i<m;i++)
#define for4(i,n,m) for(int i=n;i<=m;i++)
const int maxm = 1e5 + 10;
const int maxn = 1e9;
const int INF = 2147483647;
const double pi = acos(-1.0);
ll x1,Y1,x2,y2,x,y;
struct node{
   ll x,y;
};
bool bfs(){
   ll num=0;
   queue<node>tp;
   node now,then;
   now.x=x1,now.y=Y1;
   tp.push(now);
   while(!tp.empty()){
      now=tp.front();
      tp.pop();
      if(num>10000000000)
         return false;
      if(now.x==x2&&now.y==y2)
         return true;
      then.x=now.x+x,then.y=now.y+y;
      tp.push(then),num++;
      then.x=now.x+x,then.y=now.y-y;
      tp.push(then),num++;
      then.x=now.x-x,then.y=now.y+y;
      tp.push(then),num++;
      then.x=now.x-x,then.y=now.y-y;
      tp.push(then),num++;
   }
}
int main() {
    while(scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&x1,&Y1,&x2,&y2,&x,&y)!=EOF){
        printf("%s\n",bfs()?"YES":"NO");
    }
    return 0;
}


#include<bits/stdc++.h>

#define Write freopen("out.txt","w",stdout)
#define Read freopen("in.txt","r",stdin)

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define lli long long
#define m_p make_pair
#define p_b push_back

#define lim 10000000
#define mod 100007
#define mx 100004
#define PI  3.141592654
using namespace std;

/*** Direction Array ***/
int dirx[]= {1,0,-1,0};
int diry[]= {0,1,0,-1};
int nwx[]={1,1,-1,-1};
int nwy[]={1,-1,1,-1};
/**** Translator Functions***/
//int ToInt(string s){int r = 0;stringstream sin(s);sin >> r;return r;}
//double ToDouble(string s) { double r = 0; stringstream sin(s); sin >> r; return r; }
//string ToString(int n)  {  string s;    stringstream convert;convert << n;s = convert.str();return s;}

/*****My code goes from here****/
using namespace std;
map<pair<int,int>,bool>mp;
int srcx,srcy,desx,desy;
int a,b;
bool flag=false;
void dfs(int x,int y,int cnt)
{
    if(x>1000||y>1000||x<-1000||y<-1000) return ;
    pair<int,int>u=m_p(x,y);
    mp[u]=true;
    for(int i=0;i<4;i++)
    {
        int p,q;
        p=x+nwx[i];
        q=y+nwy[i];
        pair<int,int>v=m_p(p,q);
        if(p==desx&&q==desy){
            flag=true;
        }
        if(mp[v]==false)
        {
            mp[v]=true;
            dfs(p,q,cnt+1);
        }
   }
}

int main()
{

   cin>>srcx>>srcy;
   cin>>desx>>desy;

   cin>>a>>b;
   dfs(srcx,srcy,1);
   if(flag ) cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
}


#include <iostream>
#include <bits/stdc++.h>
/*#include <sstream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include<climits>
#include <bitset>
#include <ctime>
#include <cassert>
#include <functional>
#include <iomanip>
#include <vector>
#include <stack>
#include <fstream>*/
//std::ifstream cin("input.txt");
//std::ofstream cout("output.txt");
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//cout<<fixed<<setprecision(*)<<***<<endl;
/*scanf("%d",&..);
printf("%d",..);*/

using namespace std;
vector<pair<long long,long long> >vec,vec1;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long x1,y1,x2,y2,x,y,c=0; cin>>x1>>y1>>x2>>y2>>x>>y;
	if(x1==x2&&y2==y1){cout<<"YES"<<endl; return 0;}
	vec.push_back(make_pair(x1+x,y1+y));
	vec.push_back(make_pair(x1-x,y1-y));
	vec.push_back(make_pair(x1+x,y1-y));
	vec.push_back(make_pair(x1-x,y1+y));
	while(true)
    {
        c++;
        if(c%2!=0)
        {
            vec1.clear();
            for(long long i=0;i<vec.size();i++)
            {
                if(vec[i].first==x2&&vec[i].second==y2){cout<<"YES"<<endl; return 0;}
                if(vec[i].first>x2&&vec[i].second>y2){cout<<"NO"<<endl; return 0;}
                vec1.push_back(make_pair(vec[i].first+x,vec[i].second+y));
                vec1.push_back(make_pair(vec[i].first-x,vec[i].second-y));
                vec1.push_back(make_pair(vec[i].first+x,vec[i].second-y));
                vec1.push_back(make_pair(vec[i].first-x,vec[i].second+y));
            }
        }
        else
        {
            vec.clear();
            for(long long i=0;i<vec1.size();i++)
            {
                if(vec1[i].first==x2&&vec1[i].second==y2){cout<<"YES"<<endl;  return 0;}
                if(vec1[i].first>x2&&vec1[i].second>y2){cout<<"NO"<<endl; return 0;}
                vec.push_back(make_pair(vec1[i].first+x,vec1[i].second+y));
                vec.push_back(make_pair(vec1[i].first-x,vec1[i].second-y));
                vec.push_back(make_pair(vec1[i].first+x,vec1[i].second-y));
                vec.push_back(make_pair(vec1[i].first-x,vec1[i].second+y));
            }
        }
    }
	return 0;
}