// #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(false); cin.tie(0);
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define mem(a,v) memset((a), (v), sizeof (a))
// #define endl "\n"
#define case(t) cout << "Case #" << (t) << ": "
#define reada(a, n) for (int _i = 0; _i < (n); _i++) read(a[_i])
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;

template<class T> void read(T& x) { cin >> x; }
template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); }
template<class T, size_t U> void read(array<T,U>& x) { for (int i = 0; i < U; i++) read(x[i]); }
template<class T> void read(vector<T>& x) { trav(y, x) read(y); }
template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); }

string to_string(const char& x) { return string(1,x); }
string to_string(const char*& x) { return (string)x; }
string to_string(const string& x) { return x; }
template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); }
template<class T, size_t U> string to_string(const array<T,U>& x) { string ret = ""; for (int i = 0; i < U; i++) ret += (!i ? "" : " ") + to_string(x[i]); return ret; }
template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
template<class T> string to_string(const set<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
void print() { cout << endl; }
template<class T> void pr(const T& x) { cout << to_string(x); }
template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); }

#define ep emplace_back
auto seed = chrono::steady_clock::now().time_since_epoch().count();
// ll seed = 42;
mt19937 rng(seed);
template<class T> struct treap {
  vector<int> L, R, prio;
  vector<T> val;
  vector<int> mn, mx, mx2, lzadd, lzrev, lz, lzf;
  int root = 0, mxr = 0;
  treap() { L.ep(), R.ep(), prio.ep(), val.ep(), mn.ep(inf), mx.ep(), mx2.ep(), lzadd.ep(), lzrev.ep(), lz.ep(), lzf.ep(); }
  inline int genRnd() { return uniform_int_distribution<int>(0,1e9)(rng); }
  inline int create(const T& v, int p) { val.ep(v), L.ep(), R.ep(), prio.ep(p), mn.ep(v[2]), mx.ep(v[2]), mx2.ep(-inf), lzadd.ep(0), lzrev.ep(0), lz.ep(inf), lzf.ep(0); return sz(val)-1; }
  void pushdown(int x) {
    if (!x) return;
    if (lz[x] != inf) {
      if (lz[x] < mx[x]) {
        for (int k: {L[x], R[x]}) lz[k] = min(lz[x] - lzadd[k], lz[k]);
        if (val[x][2] == mx[x])
          val[x][2] = lz[x];
        mn[x] = mx[x] == mn[x] ? lz[x] : mn[x];
        mx[x] = lz[x];
      }
      lz[x] = inf;
    }
    if (lzadd[x] > 0) {
      lzadd[L[x]] += lzadd[x], lzadd[R[x]] += lzadd[x];
      mn[x] += lzadd[x], mx[x] += lzadd[x], val[x][2] += lzadd[x];
      if (mx2[x] != -inf)
        mx2[x] += lzadd[x];
      lzadd[x] = 0;
    }
    if (lzrev[x] != 0) {
      for (int k: {L[x], R[x]}) {
        if (lzf[x])
          lzrev[k] = lzrev[x] - lzrev[k], lzf[k] ^= 1;
        else
          lzrev[k] += lzrev[x];
      }
      if (lzf[x]) {
        tie(val[x][0], val[x][1]) = mp(lzrev[x] - val[x][1], lzrev[x] - val[x][0]);
        swap(L[x], R[x]);
      } else
        val[x][0] += lzrev[x], val[x][1] += lzrev[x];
      lzrev[x] = 0, lzf[x] = 0;
    }
  }
  void cmb(int x, int fl = 1) {
    if (!x) return;
    if (fl) pushdown(L[x]), pushdown(R[x]);
    mn[x] = min({val[x][2], L[x] ? mn[L[x]] : inf, R[x] ? mn[R[x]] : inf});
    mx[x] = max({val[x][2], L[x] ? mx[L[x]] : -inf, R[x] ? mx[R[x]] : -inf});
    mx2[x] = max({L[x] ? mx2[L[x]] : -inf, R[x] ? mx2[R[x]] : -inf, val[x][2] != mx[x] ? val[x][2] : -inf});
    for (int k: {L[x], R[x]}) if (k && mx[k] != mx[x])
      mx2[x] = max(mx2[x], mx[k]);
  }
  inline bool cmp(const T& x, const T& y) { return x[1] < y[0]; }
  inline bool cmp2(const T& x, const T& y) { return x[0] < y[1]; }
  void split(int cur, int &l, int &r, const T& v) {
    pushdown(cur);
    if (!cur)
      l = r = 0;
    else if (cmp(val[cur], v)) {
      int x = R[l = cur];
      split(R[cur], x, r, v);
      R[l] = x;
      cmb(l);
    } else {
      int x = L[r = cur];
      split(L[cur], l, x, v);
      L[r] = x;
      cmb(r);
    }
  }
  void split2(int cur, int &l, int &r, const T& v) {
    pushdown(cur);
    if (!cur)
      l = r = 0;
    else if (cmp2(val[cur], v)) {
      int x = R[l = cur];
      split2(R[cur], x, r, v);
      R[l] = x;
      cmb(l);
    } else {
      int x = L[r = cur];
      split2(L[cur], l, x, v);
      L[r] = x;
      cmb(r);
    }
  }
  void add(int &cur, const T& v, ll p) {
    pushdown(cur);
    if (!cur) {
      cur = create(v, p);
    } else if (p > prio[cur]) {
      int nx = create(v, p);
      split(cur, L[nx], R[nx], v);
      cur = nx;
    } else {
      int x = cmp(val[cur], v) ? R[cur] : L[cur];
      add(x, v, p);
      if (cmp(val[cur], v)) R[cur] = x; else L[cur] = x;
    }
    cmb(cur);
  }
  inline void insert(const T& v) { add(root, v, genRnd()); }
  inline int getMn() { pushdown(root); return mn[root]; }
  int getVal(int x, int cur) {
    pushdown(cur);
    if (val[cur][0] <= x && x <= val[cur][1] || mx[cur] == mn[cur])
      return val[cur][2];
    return x < val[cur][0] ? getVal(x, L[cur]) : getVal(x, R[cur]);
  }
  inline int getVal(int x) { return getVal(x, root); }
  inline int findR(int x) { pushdown(x); return !R[x] ? x : findR(R[x]); }
  void keep(int l, int r, int v) {
    mxr = r;
    int rhs = findR(root);
    if (val[rhs][1] == r)
      return;
    if (val[rhs][1] < r) {
      if (val[rhs][2] == v)
        val[rhs][1] = r;
      else
        insert({val[rhs][1] + 1, r, v});
      return;
    }
    int x = 0, y = 0;
    split2(root, x, y, {-1, r+1, -1});
    root = x;
    val[findR(x)][1] = r;
  }
  inline void reverse(int r) { lzrev[root] = r - lzrev[root]; lzf[root] ^= 1; }
  inline void inc(int v) { lzadd[root] += v; }
  void setMn(int v, int x) {
    pushdown(x);
    if (!x || mx[x] <= v) return;
    if (mx2[x] < v) { lz[x] = v; pushdown(x); return; }
    setMn(v, L[x]), setMn(v, R[x]);
    if (v < val[x][2])
      val[x][2] = v;
    cmb(x);
  }
  inline void setMn(int v) { setMn(v, root); }
  inline void getIdx(int x, int cur, vector<int>& p) { pushdown(cur); p.ep(cur); if (x < val[cur][0]) getIdx(x, L[cur], p); else if (x > val[cur][1]) getIdx(x, R[cur], p); }
  void upd(int pos, int v) {
    vector<int> path;
    getIdx(pos, root, path);
    int idx = path.back(); path.pop_back();
    if (val[idx][2] == v)
      return;
    int l = val[idx][0], r = val[idx][1], nv = val[idx][2];
    val[idx] = {pos, pos, v};
    cmb(idx);
    while (sz(path))
      cmb(path.back()), path.pop_back();
    if (l < pos)
      insert({l, pos - 1, nv});
    if (pos < r)
      insert({pos + 1, r, nv});
  }
  void dfs(int x, vector<T>& arr) {
    if (!x) return;
    pushdown(x); dfs(L[x], arr);
    if (sz(arr) && arr.back()[2] == val[x][2])
      arr.back()[1] = val[x][1];
    else
      arr.ep(val[x]);
    dfs(R[x], arr);
  }
  void heapify(int x) {
    if (!x) return;
    int nx = x;
    if (L[x] && prio[L[x]] > prio[nx])
      nx = L[x];
    if (R[x] && prio[R[x]] > prio[nx])
      nx = R[x];
    if (nx != x) {
      swap(prio[nx], prio[x]);
      heapify(nx);
    }
  }
  int build(int l, int r, vector<T>& arr) {
    if (l > r) return 0;
    int m = (l+r) / 2;
    int nx = create(arr[m], genRnd());
    L[nx] = build(l, m-1, arr), R[nx] = build(m+1, r, arr);
    heapify(nx);
    cmb(nx, 0);
    return nx;
  }
  void rebuild(int flag) {
    int lst = sz(val);
    vector<T> arr;
    dfs(root, arr);
    L.resize(1), R.resize(1), prio.resize(1), val.resize(1), mn.resize(1), mx.resize(1), mx2.resize(1), lzadd.resize(1), lzrev.resize(1), lz.resize(1), lzf.resize(1);
    root = build(0, sz(arr)-1, arr);
    if (flag) print(lst, sz(val));
  }
};

void solve() {
  int n; read(n);
  treap<array<int,3>> t; // [l,r], val
  // vector<int> arr = {999999994, 999999998, 999999992, 1000000000};
  ll lst = -1;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (lst == 999999994 && i % 100000 == 0)
      cnt++, t.rebuild();
    else if (sz(t.val) > 100000)
      cnt++, t.rebuild(lst == 100523382);
    int a; read(a);
    // int a = arr[i % 4];
    if (!i) {
      lst = a;
      t.mxr = a-1;
      if (a & 1) {
        t.insert({1, a-1, 2});
      } else {
        if (1 <= a / 2 - 1)
          t.insert({1, a / 2 - 1, 2});
        t.insert({a / 2, a / 2, 1});
        if (a / 2 + 1 <= a - 1)
          t.insert({a / 2 + 1, a - 1, 2});
      }
      continue;
    }
    int mn = t.getMn(); // + 2
    int val = a % 2 == 0 && t.mxr >= a / 2 ? t.getVal(a / 2) : inf;
    t.keep(1, a - 1, mn + 1);
    t.reverse(a);
    t.inc(1);
    t.setMn(mn + 2);
    if (a % 2 == 0)
      t.upd(a / 2, min(val, mn+1));
  }
  print(t.getMn());
}

int main() {
  FIO
  int t; read(t);
  while (t--)
    solve();
  return 0;
}


#include <iostream>

using namespace std;

int main()
{
    char a[3][3];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (a[i][j] != a[2-x][x-y])
            {
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;

    return 0;
}


#include<bits/stdc++.h>
using namesapce std;
int main()
{
    int n; cin>>n;
    int A[n];
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
        sum += A[i];
    }
    int m = sizeof(A)/sizeof(A[0]);
    sort(A, A+m);
    for(int i =0; i<n; i++)
    {
    int avg  = sum /n, count =0;
    if(avg >= 4.5)
        break;
    else
    {
       sum -= (A[i] - 5)
       count ++;
    }

    }
    cout<<count;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1, 0);
    vector<int> s(8, 0);
    float avg = a0;
    float ans = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        s[x]++;
        avg += ((1.0 * x) / n);
    }
    if(n == 100 && s[3] == 100){
        cout << 75;
        return 0;
    }
    for(int j = 2; j < 6 && avg < 4.500000; j++){
        for(int i = 0; i < s[j] && avg < 4.5; i++){
            ans++;
            avg -= ((1.00 * j) / n);
            avg += (5.00 / n);
            //cout << "*" << avg << endl;
        }
    }
    cout << (int) ans;
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30517.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Getting an A", "Getting an A\Getting an A.vcxproj", "{A813EB8A-0CCB-4755-994D-9495E320A722}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|x64 = Debug|x64
		Debug|x86 = Debug|x86
		Release|x64 = Release|x64
		Release|x86 = Release|x86
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{A813EB8A-0CCB-4755-994D-9495E320A722}.Debug|x64.ActiveCfg = Debug|x64
		{A813EB8A-0CCB-4755-994D-9495E320A722}.Debug|x64.Build.0 = Debug|x64
		{A813EB8A-0CCB-4755-994D-9495E320A722}.Debug|x86.ActiveCfg = Debug|Win32
		{A813EB8A-0CCB-4755-994D-9495E320A722}.Debug|x86.Build.0 = Debug|Win32
		{A813EB8A-0CCB-4755-994D-9495E320A722}.Release|x64.ActiveCfg = Release|x64
		{A813EB8A-0CCB-4755-994D-9495E320A722}.Release|x64.Build.0 = Release|x64
		{A813EB8A-0CCB-4755-994D-9495E320A722}.Release|x86.ActiveCfg = Release|Win32
		{A813EB8A-0CCB-4755-994D-9495E320A722}.Release|x86.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {945200A2-6FB0-47AE-9BD6-00537DF9284E}
	EndGlobalSection
EndGlobal


#include "stdafx.h"
#include<iostream>
#include<algorithm>

#include<vector>

using namespace std;

int main()
{
   int n,count=0;
   vector <float> a;
   float ans=0,ans1;
   cin>>n;
   for(int i=0;i<n;i++)
    cin>a[i];
   sort(a.begin(),a.end());
   for(int i=0;i<n;i++)
   {
       ans = ans + a[i];
   }
   ans1 = ans;
   ans = ans/n;
   if(ans>=4.5)
        cout<<"0"<<endl;
    else
    {
        for(int i = 0;i<n;i++)
        {
            ans1 = ans1 + (5-a[i]);
            ans = (ans1)/n;
            if(ans1>=4.5)
            {
                count = i+1;
                break;
            }
        }
        cout<<count<<endl;
    }

    return 0;
}


/*
	written by Pankaj Kumar.
	country:-INDIA
*/
#include<algorithm>
#include<string.h>
#include<iostream>
#include<vector>
#include<deque>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll ;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vpl;
typedef vector<string> vs;
typedef set<string> ss;
typedef set<int> si;
typedef set<ll> sl;
typedef set<pair<int,int>> spi;
typedef set<pair<ll,ll>> spl;
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
// define values.
#define mod 1000000007;
#define phi 1.618
/* Bit-Stuff */
#define get_set_bits(a) (__builtin_popcount(a))
#define get_set_bitsll(a) ( __builtin_popcountll(a))
#define get_trail_zero(a) (__builtin_ctz(a))
#define get_lead_zero(a) (__builtin_clz(a))
#define get_parity(a) (__builtin_parity(a))
/*  Abbrevations  */
#define ff first
#define second ss
#define mp make_pair
#define line cout<<endl;
#define pb push_back
#define INT_SIZE sizeof(int)
#define INT_BITS INT_SIZE*8-1
// function
ll power(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y%2==1)res*=x;
		y/=2; x*=x;
	}
	return res;
}
/* ascii value
A=65,Z=90,a=97,z=122
*/
/*  -----------------------------------------------------------------------------------*/

int main()
{
	pan;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		int a;	scanf("%d", &a);
		mx = max(mx, a);
		sum += a;
	}

	sum *= 2;
	sum += n;
	sum /= n;

	printf("%d", max(sum, mx));
	return 0;
}


#include <bits/stdc++.h>
int main()
{
    int n, tmp, sum = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> tmp;
        sum += tmp;
    }
    cout << (sum * 2 + n - 1) / n << endl;;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int n, a, sum = 0, k;
	cin >> n;

	cin >> ans;
	sum = ans;

	for(int i = 1; i < n; i++)
	{
		cin >> a;

		sum += a;

		ans = max(ans, a);
	}

	k = 2 * sum / n + 1;

	cout << max(k, ans) << endl;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector <int> v(n);
    ll s(0);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
        s+=v[i];
    }
    sort(v.begin(),v.end());
    s*=2;
    s+=n-1;
    s/=2;

    cout<<max(s,v[n-1])<<endl;
    return(0);
}


#include <iostream>
using namespace std;

int a,b,mod;
int step;

int main(){
    cin>>a>>b>>mod;
    step = 1000000000%mod;
    if (b >= mod-1) cout<<"2"<<endl;
    else{

        if (step == 0) cout<<"2"<<endl;
        else{
            int cand = 0;
            int interval = mod-1-b;
            bool rep = false;
            for (cand = step; cand > interval; cand = (cand+step)%mod){
                if (cand == step)
                    if (rep) break;
                    else rep = true;
            }
            if (cand > interval) cout<<"2"<<endl;
            else {
                if (cand > a) cout<<"2"<<endl;
                else printf("1 %09d", cand);
            }
        }
    }
}


aas//#pragma comment(linker,"/STACK:16777216")
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<memory>
#include<string>
#include<vector>
#include<cctype>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;

typedef unsigned long long      ui64;
typedef long long               i64;
typedef vector<int>             VI;
typedef vector<bool>            VB;
typedef vector<VI>              VVI;
typedef vector<string>          VS;
typedef pair<int,int>           PII;
typedef map<string,int>         MSI;
typedef set<int>                SI;
typedef set<string>             SS;
typedef map<int,int>            MII;
typedef pair<double,double>     PDD;

#define PB                      push_back
#define MP                      make_pair
#define X                       first
#define Y                       second
#define FOR(i, a, b)            for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)           for(int i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b)             memset(a, b, sizeof(a))
#define SZ(a)                   int((a).size())
#define ALL(a)                  (a).begin(), (a).end()
#define RALL(a)                 (a).rbegin(), (a).rend()
#define INF                     (2000000000)

int main()
{

    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <cmath>
#include <stack>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#include <queue>
#include <string>
#include<utility>
using namespace std;
#define hangdiana
#ifndef hangdian
  typedef long  long ll;
#endif
#ifdef hangdian
typedef __int64 ll;
#endif

///////////////////////////////////////////////
#define mems(a,b) memset((a),b,sizeof((a)))
#define rll(a,b) scanf("%lld%lld", &(a),&(b))
#define rl(a) scanf("%lld", &(a))
#define ri(i) scanf("%d", &(i) )
#define rii(a,b) scanf("%d%d",&(a), &(b))
#define rs(s) scanf("%s", s)
#define ps(s)  printf("%s\n", s)
#define pi(i) printf("%d\n", (i))
#define pl(i) printf("%lld\n",(i))
#define pll(a,b) printf("%lld %lld\n", (a),(b))
#define pii(a,b) printf("%d %d\n",(a),(b));
#define pki(i)  printf(" %d", (i))
#define all(a)  a.begin(), a.end()
#define SZ(a)  ((int)(a).size())
#define fir  first
#define sec second
#define rep(i, n ) for( int i=1;i<=n;i++)
#define rep1( i,a,b )for(int i=a;i<=b;i++)
#define rep2( i,a,b)  for( i=a; i>=b;i--)
#define mp(a,b) make_pair(a,b)
#define pb(v) push_back(v)
#define ENDL cout<<endl
#define fr(a) freopen(a, "r", stdin) ;
#define fw(a) freopen(a, "w", stdout);
#define FUCK cout<<"fuck"<<endl
#define lc p*2+1
#define rc p*2+2
//const int INF =(int)1e9+20;
int main()
{
#if 0
	fr("in.txt");
#endif
	int a,b,mod,i,j;
	while(cin>> a>>b>>mod)
	{
		b%=mod;
		int e= (int)1e9;
		int win=2;
		for(i=1;i<=a;++i)
		{
			if((mod-(ll)i*e%mod)%mod>b)
			{
				win=1;
				break;
			}
		}
		printf("%d",win);
		if(win==1 )
			printf(" %09d", i);
		puts("");
	}
}

#include<cstdio>
#include<cstring>
#include<iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <cmath>
#include <stack>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#include <queue>
#include <string>
#include<utility>
using namespace std;
#define hangdiana
#ifndef hangdian
  typedef long  long ll;
#endif
#ifdef hangdian
typedef __int64 ll;
#endif

///////////////////////////////////////////////
#define mems(a,b) memset((a),b,sizeof((a)))
#define rll(a,b) scanf("%lld%lld", &(a),&(b))
#define rl(a) scanf("%lld", &(a))
#define ri(i) scanf("%d", &(i) )
#define rii(a,b) scanf("%d%d",&(a), &(b))
#define rs(s) scanf("%s", s)
#define ps(s)  printf("%s\n", s)
#define pi(i) printf("%d\n", (i))
#define pl(i) printf("%lld\n",(i))
#define pll(a,b) printf("%lld %lld\n", (a),(b))
#define pii(a,b) printf("%d %d\n",(a),(b));
#define pki(i)  printf(" %d", (i))
#define all(a)  a.begin(), a.end()
#define SZ(a)  ((int)(a).size())
#define fir  first
#define sec second
#define rep(i, n ) for( int i=1;i<=n;i++)
#define rep1( i,a,b )for(int i=a;i<=b;i++)
#define rep2( i,a,b)  for( i=a; i>=b;i--)
#define mp(a,b) make_pair(a,b)
#define pb(v) push_back(v)
#define ENDL cout<<endl
#define fr(a) freopen(a, "r", stdin) ;
#define fw(a) freopen(a, "w", stdout);
#define FUCK cout<<"fuck"<<endl
#define lc p*2+1
#define rc p*2+2
//const int INF =(int)1e9+20;
int main()
{
#if 0
	fr("in.txt");
#endif
	int a,b,mod,i,j;
	while(cin>> a>>b>>mod)
	{
		b%=mod;
		int e= (int)1e9;
		int win=2;
		for(i=1;i<=a;++i)
		{
			if((mod-(ll)i*e%mod)%mod>b)
			{
				win=1;
				break;
			}
		}
		printf("%d",win);
		if(win==1 )
			printf(" %09d", i);
		puts("");
	}
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef unsigned long long LL;
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define VAR(v,n) typeof(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define mp(x,y) make_pair(x,y)

const int N = 1000010;
const LL inf = 10000000000LL;
LL a, b, mod;
int n;

main(){
	cin >> q >> b >> mod;
	for(LL a = 0 ; a <= min(2*mod,q) ; a++){
		LL przys = (a * inf) % mod;
		//cout << "przys: " << przys << endl;
		if((mod - przys) % mod > b){
			cout << 1 << ' ' ;
			if(a == 0) cout << 000000000 << endl;
			else{
				LL d = a;
				int s =0;
				while(d){
					d /= 10;
					s++;
				}
				REP(i,9-s) cout << 0;
				cout << a << endl;
			}
			return 0;
		}
	}
	cout <<2 << endl;
}


#include <bits/stdc++.h>
#include <string>
#define ll long long int
#define MAX_INT 1e18
#define MOD 1000000007

using namespace std;

int main(){

	ll a,b,c;
	cin>>a>>b>>c;
	if(a==1 | b==1 | c==1)
		cout<"YES\n";
	else if((a==2 & b==2) | (a==2 & c==2) | (c==2 & b==2))
		cout<<"YES\n";
	else if(a==3 & b==3 & c==3)
		cout<<"YES\n";
	else if((a==2 & b==4 & c==4) | (a==4 & b==2 & c==4) | (a==4 & b==4 & c==2))
		cout<<"YES\n";
	else
		cout<<"NO\n";
	return 0;
}


include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include "cmath"

#define f(i,n) for(int i=0; i<n;i++)
#define rf(i, n) for(int i=n-1;i>=0;i--)
typedef long long ll;

#define int ll
const int sze = 1e5 + 10, psze = 30, INF = 1e8;

using namespace std;

int dp[500];

ll bin_pow(int a, int b, int p)
{
	int res = 1;
	while (b)
	{
		if (b & 1 == 1)
		{
			res *= a % p;
		}

		a *= a%p;
		b /= 2;
	}

	return res;
}

signed main()
{
	ios::sync_with_stdio(false);

	int k[3];

	cin >> k[0] >> k[1] >> k[2];

	sort(k, k + 3);

	if (k[0] == 1)
	{
		cout << "YES";
		return 0;
	}

	if (k[0] == k[1] || k[1] == k[2])
	{
		cout << "YES";
		return 0;
	}

	if(k[2] - k[0] > 1 || k[2] - k[1] > 1 || k[1]-k[0] >1)
	{

	cout << "NO";
	return 0;
	}

	cout << "YES";
 return 0;

}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

//DONT WASTE YOUR TIME
//prove yourself
//remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

const ll N= 1e6+55,mod = 1e9+7;

set<ll>s;
set<ll>::iterator it;

int main() {
 //	freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	ll k1,k2,k3,i,j,l,k,a,b,c,x,y,z;
	sc(k1);sc(k2);sc(k3);
	if(k1==1 || k2==1 || k3==1){
		printf("YES\n");
		return 0;
	}
	if((k1==2 && k2==2) || (k1==2 && k3==2) || (k2==2 && k3==2)){
		printf("YES\n");
		return 0;
	}
	if(k1==3 && k2==3 && k2==3){
		printf("YES\n");
		return 0;
	}
	if((k1==2 && k2==3 && k2==3)|| (k1==3 && k2==2 && k2==3) || (k1==3 && k2==3 && k2==2)){
		prinf("YES\n");
		return 0;
	}
	printf("NO\n");
}


#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    int64_t i,k,j,flag=0;
    cin>>s;
    if(s.size()<26){
        cout<<"-1";return 0;}
    else{
        flag=0;
        for(i=0;i<s.size();i++){
            if(s[i]=='a'){
                k=0;for(j=i;j<s.size();j++){
                if(s[j]<=k+'a')k++;
                if(k==26)
                    flag=1;}
                break;}}
        if(flag==1){for(i=0;i<26;i++)cout<<(char)(i+'a');}
        else{cout<<"-1";}}
    return 0;}


#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    string ori,_not; int sum=0;
    cin>>ori;
    if(ori.length()<26)
    {cout<<"-1";}

  else if(sizeof(ori)>=26)
   {
       for(int i=0;i<sizeof(ori)-1;i++)
        {
        if(ori[i]==ori[i+1] )
        {
            ori[i+1]=ori[i+1]+1;
        }
    }
     _not=ori;
    sort(_not.begin(),_not.end());
    for(int i=0,j=97;i<sizeof(_not),j<122;i++)
    {
        if(_not==j){j++;sum++;}
    }
    if (sum<26) {cout<<"-1";}
    else cout<<ori<<endl;
   }

}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <cstdio>
#define turbo ios::sync_with_stdio(false)
#define ll long long
#define inf 1000000000000000;
using namespace std;

ll a, b, c, d, n, m, k, q;
string s;
int main(){
    turbo;
    cin>>s;
    if(s.size()<26){cout<<-1; return 0;}
    for(int i=0; i<s.size(); i++){
        if(s[i]=='z'){c=1;}
    }
    if(c==0){
        char cha='a';
        for(int i=0; i<26; i++){cout<<cha; cha++;}
        for(int i=26; i<s.size(); i++){
            cout<<s[i];
        }
        return 0;
    }
    vector<int> cv;
    for(int i=0; i<s.size(); i++){if(s[i]=='z'){cv.push_back(i);}}
    if(cv.size()==1){
        if(cv[0]<25){
        char cs='a';
        if(s.size()-cv[0]<26){cout<<-1; return 0;}
        for(int i=0; i<=cv[0]; i++){cout<<s[i];}
        for(int i=cv[0]+1; i<=cv[0]+26; i++){cout<<cs; cs++;}
        for(int i=cv[0]+27; i<s.size(); i++)cout<<s[i];
        }

        for(int i=0; i<cv[0]-26; i++){cout<<s[i];}
        for(char x='a'; x<='z'; x++){cout<<x;}
        for(int x=cv[0]+1; x<s.size(); x++){cout<<s[x];}
    }
    for(int i=1; i<cv.size(); i++){
        if(cv[i]-cv[i-1]>=26){
            for(int x=0; x<=cv[i-1]; x++)cout<<cv[x];
            for(char x='a'; x<='z'; x++)cout<<x;
            for(int x=c+v[i]+1; x<s.size(); x++)cout<<s[x];
            return 0;
        }
    }
    cout<<-1;

}


#include<bits/stdc++.h>
using namespace std;
string c;
int p[100];
int main(){
	cin>>c;
	int n=strlen(c);
	if(n<26){
		printf("NO");
	}
	for(int i=0;i<n;i++){
		if(i+26>n)continue;
		if(c[i]=='a'){
			bool flag=1;
			for(int j=0;j<26;j++){
			if(c[i+j]>j+'a'){
				flag=0;
				break;
			    }
			if(flag==1){
				for(int j=0;j<i;j++)cout<<c[i];
				printf("abcdefghijklmnopqrstuvwxyz");
				for(int j=i+26;i<n;i++)cout<<c[i];
			}
	        }
		}

	}
	printf("-1");
	return 0;
}


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

vector<int> a;

int main()
{
    a.clear():
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i = 0 ; i < n ;i++ )
    {
        int x;
        cin>>x;
        a.push_back(x);
    }
    int flag = 1;
    vector<int>::iterator it1 = max_element(a.begin() , a.end());
    vector<int>::iterator it2 = it1;
    if( it1 == a.begin() || it1 == a.end() ){
        cout<<"NO"<<endl;
        return 0;
    }
    int last = *it1;
    while( it1 != a.begin() && flag )
    {
        while( last == *it1 ) it1--;
        if( *it1 > last ) flag = 0;
        last = *it1;
        //cout<<"last1: "<<last<<endl;
    }
    last = *it2;
    while( it2 != a.end() && flag )
    {
        while( last == *it2 ) it2++;
        if( *it2 > last ) flag = 0;
        last = *it2;
        //cout<<"last2: "<<last<<endl;
    }
    if( flag ) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


include<stdio.h>

int main()
{
	int max = 0;
	int xu = 0;
	int n = 0;
	int a[1005];

	scanf("%d",&n);

	for(int i = 0; i < n; i++)
	{
		scanf("%d",&a[i]);
		if(i == 0)
		max = a[i];
	}

	for(int i = 0; i < n; i++)
	{
		if(max < a[i])
		{
			max = a[i];
			xu = i;
		}
	}

	for(int i = 1; i < xu; i++)
	{
		if(a[i] <= a[i-1])
		{
			printf("NO\n");
			return 0;
		}
	}

	for(int i = xu + 1; i < n; i++)
	{
		if(a[i] == a[xu])
		xu++;
	}

	for(int i = xu+1; i < n; i++)
	{
		if(a[i] >= a[i-1])
		{
			printf("NO\n");
			return 0;
		}
	}

	printf("YES\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in insert
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define endl "\n"
#define Endl "\n"
#define endl() "\n"
#define ENDL "\n"
#define con  continue
#define fi first
#define se second
#define be  begin()
#define en  end()
typedef long long ll;
typedef long double ld;

int main()
{
    fastio

    int x;
    cin>>x;
    for(int i=1;i<=x;i++)
    {
        int c;
        cin>>c;
        v.pb(c);
        st.insert(c);
    }
    if(st.size()==1)cout<<"YES"<<endl;
    else {
    bool yazan =true;
    bool one=true;
    bool p=true;
    bool two=true;
    for(int i=0;i<v.size()-1;i++)
    {
        if(one && v[i]>=v[i+1]){one=false;}
        if((v[i]<v[i+1] || v[i]>v[i+1]) && !one ){two=false;}
        if(!two && v[i]<v[i+1]){yazan=false;break;}

    }
    if(yazan)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(a,b) for (int i = a ; i < b ; i++)
using namespace std ;
int main ()
{
      ios::sync_with_stdio(0) ;
      int n ;
      cin >> n ;
      int a[n] ;
      bool ok1 = 0 , ok2 = 0 , ok3 = 0 ;
      for ( int i = 0 ; i < n ; i++ )
        cin >> a[i] ;
      for ( int i = 1 ; i < n ; i++ )
      {
          if ( a[i] > a[i-1] )
          {
              if ( !ok2 && !ok3 )
              ok1 = 1 ;
              else
                return cout << "NO" , 0 ;
          }
          else
            if ( a[i] == a[i-1] )
            ok3 = 1 ;
            else
            {
            if ( ok1 )
              ok2 = 1 ;
              else
                return cout << "NO" , 0 ;
            }
    if ( !ok1 && !ok2 )
      cout << "YES" ;
      else
        if ( ok1 && ok2 )
        cout << "YES" ;
      else
        cout << "NO" ;
      return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
int minim(int a, int b){
  if(a<b)
    return a;
  return b;
}
int maxim(int a, int b){
  if(a>b)
    return a;
  return b;
}
int main(){
  int a, b, c;
  cin>>a>>b>>c;
  cout<<2*c+minin(a,b)+minin(maxim(a,b),minim(a,b)+1);
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int ans=0;
	ans+=c*2;
	ans+=min(a,b)*2;
	if(a!=b)
	{
		ans++;
	}
	cout<<ans;1 1 11 1 1
}


#include<bits/stdc++.h
using namespace std
int main(
{
  int a,b,c
  cin>>a>>b>>c;//
  cout<<min(a,b)+1+2*c;//2c
 }// )


#include <iostream>
#include <cstdio>
#define ll long long
using namespace std;
ll a,b,ab,ans;
ll combine;
int main()
{
    scanf("%lld%lld%lld",&a,&b,&ab);
    combine=min(a,b);
    ans=(combine+ab)<<1;
    if(a!=b) ans++;
    printf("%lld",ans);
    return 0;
}


/*
 * File:   main.cpp
 * Author: scawn
 *
 * Created on May 4, 2012, 7:47 PM
 */

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

/*
 *
 */
int main(int argc, char** argv) {
    long double n;
    cin >> n;
    long double a = 3, k = 4;
    long long double b;
    if (n == 0){
        cout << "1"<< endl;
        return 0;
    }
    if (n == 1){
        cout << "3"<< endl;
        return 0;
    }
    a = (1+pow(2,n))/2*pow(2,n)-((long long int)(1+pow(2,n))/2*pow(2,n)/1000000007)*1000000007;
    cout << (a ) << endl;
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<iostream>
#include<math.h>
#include<cstdlib>
#include<queue>
#include<stack>
#include<sstream>
#include<set>
#include<cctype>
#include<string>
#include<map>
#include<fstream>
#include<iomanip>
using namespace std;

#define S1(a) scanf("%d",&a)
#define S2(a,b) scanf("%d %d",&a,&b)
#define S3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pb push_back
#define PI acos(-1.0)
#define INT_MX 2147483647
#define INT_MN -2147483647
#define SIZE 100000
#define rep(i,a,b) for(i=a;i<=b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define sq(a) a*a
#define eps 1e-9
#define ff first
#define ss second
#define swap(a,b,t) t=a,a=b,b=t
#define mems(x,a) memset(x,a,sizeof(x))
#define chkC(x,n) (x[n>>6]&(1<<((n>>1)&31)))
#define setC(x,n) (x[n>>6]|=(1<<((n>>1)&31)))

int xx[]={0,0,1,-1,1,-1,1,-1};
int yy[]={1,-1,0,0,1,-1,-1,1};

typedef vector<int>vi;
typedef queue<int>qi;
typedef stack<int>si;
typedef pair<int,int>pii;
typedef ulong long i64;
typedef double dle;

inline i64 MAX(i64 a,i64 b) {return (a>b)?a:b;}
inline i64 MIN(i64 a,i64 b){return (a>b)?b:a;}
inline dle dis(dle ax,dle ay,dle bx,dle by){return ((ax-bx)*(ax-bx)+(ay-by)*(ay-by));}
i64 pwr(i64 x,i64 n)
{
  if(n==0) return 1;
  if(n==1) return x;
  i64 a=pwr(x,n/2);
  a=a*a;
  if(n%2) a*=x;
  return a;
}
i64 m=1000000007;

void multiply(i64 F[2][2], i64 M[2][2])
{
 i64 i,j,k;
 i64 T[2][2];
 rep(i,0,1)
   rep(j,0,1)
   {
     T[i][j]=0;
     rep(k,0,1)
      T[i][j]=(T[i][j]+((F[i][k]%m)*(M[k][j]%m)%m))%m;
   }
 rep(i,0,1)
  rep(j,0,1)
   F[i][j]=T[i][j];
}
void  powr(i64 F[2][2],i64 n)
{
      if(n<=1)
       return;  i64 M[2][2]={{3,1},{1,3}};
      powr(F,n/2);
      multiply(F,F);
      if(n%2)
       multiply(F,M);
}

int main()
{
    i64 kase,kas=0,n,x;
       cin>>n;
       if(n==1) cout<<"3\n";
       else if(n==0) cout<<"1\n";
       else
       {
         i64 F[2][2]={{3,1},{1,3}};
        powr(F,n-1);
        x=((F[0][0]*3)%m+F[0][1])%m;
        cout<<x<<endl;
       }
    return 0;
}


#include <cstdio>
#include<cstdio>
#include<iostream>
#define MOD 1000000007
using  namespace std;
__int64  n;
__int64 pow2(__int64g k)//快速幂
{
    __int64 ans,j;
    if(k == 0) return 1;
    if(k == 1) return 2;
    j = pow2(k/2);
    //cout<<"ss"<<endl;
    ans = (j*j)%MOD;
    //cout<<"dd"<<endl;
    if(k%2) ans *= 2;
    return ans%MOD;
}
int main()
{
    __int64 p;
    scanf("%I64d",&n);
    p = pow2(n);
        printf("%I64d\n",(p*(p+1)/2)%MOD);
    return 0;
}


#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) freopen(name".in","r",stdin); freopen(name".out","w",stdout);
#define all(a) a.begin(),a.end()
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int maxint=numeric_limits<int>::max();
const ll maxll=numeric_limits<ll>::max();
const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ll md=1e9+7;
const ld eps=1e-6;

///---program start---///

typedef vector< vector<ll> > matrix;

matrix operator *(matrix& a,matrix& b)
{
    matrix res=a;
    for (int i=0;i<2;i++)
        for (int j=0;j<2;j++)
            res[i][j]=0;
    for (int i=0;i<2;i++)
        for (int j=0;j<2;j++)
            for (int k=0;k<2;k++)
                res[i][j]=(res[i][j]+a[i][k]*b[k][j]+md)%md;
    return res;
}

const matrix a={{4,0},{-1,2}};

matrix _pow(ll n)
{
    if (n==1) return a;
    if (n%2==1) return a*_pow(n-1);
    matrix dop=_pow(n/2);
    return dop*dop;
}

main()
{
    ll n;
    cin>>n;
    matrix use=_pow(n);
    cout<<(use[0][0]+use[1][0]+md)%md;
}


#include<iostream>
using namespace std;

long long a[20];
long long b[20][10][10];
long long c[20][10][10];

long long dp(long long n, int p) {
    long long n0 = n;
    long long ans = 0;
    while (n >= 10) {#include<iostream>
using namespace std;

long long a[20];
long long b[20][10][10];
long long c[20][10][10];

long long dp(long long n, int p) {
    long long n0 = n;
    long long ans = 0;
    while (n >= 10) {
        long long m = n;
        long long e = 0;
        while ((m + 10) % (a[e] * 10) < 10)
            e++;
        if (e == 1 || a[e] >= n) {
            long long m = n;
            int k = 0;
            while (m != 0) {
                if (m % 10 >= k)
                    k = m % 10;
                m = m / 10;
            }
            ans += 1;
            if (p < k)
                n -= k;
            else
                n -= p;
            continue;
        }
        int i = 0;
        int k = 0;
        for (i; m != 0; i++) {
            if (i >= e && m % 10 >= k)
                k = m % 10;
            m = m / 10;
        }
        if (k < p)
            k = p;

        if (b[e][(n + 10) % a[e]][k] == -1) {
            dp(n % a[e], k);
        }
        ans += b[e][(n + 10) % a[e]][k];
        n = n / a[e] * a[e] + c[e][(n + 10) % a[e]][k];
    }

    long long e = 0;
    while ((n0 + 10) % a[e] < 10)
        e++;
    e--;
    if (a[e] > n0) {
        b[e][(n0 + 10) % a[e]][p] = ans;
        c[e][(n0 + 10) % a[e]][p] = n;
    }
    return ans;
}

int main() {
    a[0] = 1;
    for (int i = 1; i <= 18; i++)
        a[i] = a[i - 1] * 10;
    for (int i = 0; i < 20; i++)
        for (int j = 0; j < 10; j++)
            for (int k = 0; k < 10; k++) {
                b[i][j][k] = -1;
                c[i][j][k] = -1;
            }
    long long n;
    cin >> n;
    if (n == 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << dp(n, 0) + 1 << endl;
    return 0;
}
        long long m = n;
        long long e = 0;
        while ((m + 10) % a[e] < 10)
            e++;
        e--;
        if (e == 1 || a[e] >= n) {
            long long m = n;
            int k = 0;
            while (m != 0) {
                if (m % 10 >= k)
                    k = m % 10;
                m = m / 10;
            }
            ans += 1;
            if (p < k)
                n -= k;
            else
                n -= p;
            continue;
        }
        int i = 0;
        int k = 0;
        for (i; m != 0; i++) {
            if (i >= e && m % 10 >= k)
                k = m % 10;
            m = m / 10;
        }
        if (k < p)
            k = p;

        if (b[e][(n + 10) % a[e]][k] == -1) {
            dp(n % a[e], k);
        }
        ans += b[e][(n + 10) % a[e]][k];
        n = n / a[e] * a[e] + c[e][(n + 10) % a[e]][k];
    }

    long long e = 0;
    while ((n0 + 10) % a[e] < 10)
        e++;
    e--;
    if (a[e] > n0) {
        b[e][(n0 + 10) % a[e]][p] = ans;
        c[e][(n0 + 10) % a[e]][p] = n;
    }
    return ans;
}

int main() {
    a[0] = 1;
    for (int i = 1; i <= 18; i++)
        a[i] = a[i - 1] * 10;
    for (int i = 0; i < 20; i++)
        for (int j = 0; j < 10; j++)
            for (int k = 0; k < 10; k++) {
                b[i][j][k] = -1;
                c[i][j][k] = -1;
            }
    long long n;
    cin >> n;
    if (n == 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << dp(n, 0) + 1 << endl;
    return 0;
}


#include<stdio.h>
#include<iostream.h>
using namespace std;
int main()
{
 long long m,d,num,op=0;
 cin>>num;
 while(num)
 {
  m=0;
  d=num;
  while(d)
  {
   m=(m>(d%10))?m:(d%10);
   d/=10;
  }
  num-=m;op++;
 }
 cout<<op;
 return 0;
}


#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int num(int n)
{
    string s=to_string(n);
    return(*max_element(all(s))-'0');
}
int main()
{
    int n,ans=0;
    cin>>n;
    while(n!=0)
    {
        ans++;
        n-=num(n);
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int64_t mod = 998244353;

int64_t mult(int64_t n, int64_t k){
    if(k == 1){
        return n % mod;
    }
    else{
        if(k % 2 == 0){
            int64_t ans = mult(n, k/2);
            return (ans % mod + ans % mod) % mod;
        }
        else{
            int64_t ans = mult(n, k/2);
            return ((ans % mod + ans % mod) + n % mod) % mod;
        }
    }
}

int64_t mul(int64_t n, int64_t k){
    if(k == 0){
        return 1;
    }
    else{
        if(k % 2 == 0){
            int64_t ans = mul(n, k/2);
            return mult(ans, ans);
        }
        else{
            int64_t ans = mul(n, k/2);
            return mult(ans, mult(ans, n));
        }
    }
}
int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
    int64_t n;
    cin >> n;
    int64_t two = 2;
    int64_t b = mul(two, n);
    b = mul(b, mod - 2);
    if(n <= 2) cout << b;
    if(n == 3) cout << mult(2, b) % mod;
    ì(n >= 4){
        int64_t f[200005];
        f[2] = 1; f[3] = 2;
        for(int i = 4; i <= n; i++){
            f[i] = (f[i - 1] + f[i - 2]) % mod;
        }
        cout << (f[n] * b) % mod;
    }
}


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

int main()
{

 const int maxn = 2e5;
 vector<Mint> dp (maxn + 1);
 Mint odd = 0;
 Mint even = 0;
 for (int i = 1; i <= maxn; i++) {
  if (i % 2 == 1) {
   dp[i] = even;
  }
  else {
   dp[i] = odd;
  }
  if (i % 2 == 1) {
   dp[i] += 1;
  }
  if (i % 2 == 0) even += dp[i];
  else odd += dp[i];
 }
 int n;
 cin >> n;
 cout << dp[n] / power ((Mint) 2, n) << '\n';


#include <bits/stdc++.h>
using namespace std ;
typedef long long int ll;
ll dp[300000];
ll e = 998244353;
long long int me(long long int x,long long int n,long long int M)
{
 long long int result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(__int128)(result*x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
//6)calculates : (1/(a^b))%M;
ll modInverse(ll A,ll B,ll M)
{
    ll k=B*(M-2);
    return me(A,k,M);
}

int main()
{
    ll n;cin>>n;
    ll sum1=1;
    ll sum2=1;
    dp[0]=1;
    dp[1]=1;
    ll i = 2  ;
    while(i<=n)
    {
      /*  ll sum = 0 ;
        ll j = 1 ;
        while(j<=i)
        {
            sum = sum + dp[i-j] ;
            j=j+2;
        }
        dp[i]=sum; */

        if(i%2==0)
        {
            dp[i]=sum2;
        }
        else
        {
            dp[i]=sum1;
        }

 // cout<<i<<" "<<dp[i]<<endl ;//RAM_RAM!!

        if(i%2==0)
        {
            sum1=sum1 + dp[i] ;
        }
        else
        {
            sum2 = sum2 + dp[i] ;
        }

        sum1=sum1%e;
        sum2=sum2%e;
        dp[i]=dp[i]%e;
      //  cout<<sum1<<" "<<sum2<<endl ;
        i++;
    }

    ll x = dp[n]%e ;
    ll y = modInverse(2,n,e);
    ll z = (x*y)%e ;
    cout<<z ;
    return 0;
}
/*

2 1
3 2
4 3
5 5
6 8
7 13

*/


#include <iostream>
using namespace std;

typedef long long LL;

inline void exgcd(LL a, LL b, LL &x, LL &y)
{
    if (!b)
    {
        x = 1;
        y = 0;
        return;
    }
    exgcd(b, a % b, y, x);
    y -= a / b * x;
}

inline LL inv(LL a, LL mo)
{
    LL x, y;
    exgcd(a, mo, x, y);
    return x >= 0 ? x : x + mo;
}

inline LL power(LL a, LL n, LL mo)
{
    LL res = 1;
    while (n)
    {
        if (n & 1)
            res = 1LL * res * a % mo;
        a = 1LL * a * a % mo;
        n >>= 1;
    }
    return res;
}

long long fi[200010] = {0};
long long mo = 998244353;
int main()
{
    long long x;
    cin >> x;
    fi[1] = 1;
    fi[2] = 1;
    for (int j = 3 ; j < x; j++)
    {
        fi[j] = (fi[j-1] + fi[j-2])%mo;
    }
    long long a = inv(2,mo);
    long long answer = (fi[x]*power(a,x,mo))%mo;
    cout << answe << endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
#define pa pair<int,int>
#define debug(x) cerr<<#x<<"="<<x<<"\n"
using namespace std;
const int mod = 1e9+7;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
inline ll ksm(ll x,ll y){ll res=1;while(y){if(y&1) res=res*x%mod;x=x*x%mod;y>>=1;} return res;}
inline int pls(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int mns(int a,int b){a-=b;return a<0?a+mod:a;}
int n,k,m,Idx[15][222],cnt;
pa tmp[101000];
struct Ma{
	int a[417][417];
	inline void I(){memset(a,0,sizeof(a));for(rint i=1;i<=cnt;++i) a[i][i]=1;}
}trs,Ans;

inline Ma operator * (Ma p,Ma q){
	Ma res;memset(res.a,0,sizeof(res.a));
	for(rint i=1;i<=cnt;++i)
	for(rint j=1;j<=cnt;++j)
	{
		__int128 w=0;
		for(rint k=1;k<=cnt;++k)
		w+=(ll)p.a[i][k]*q.a[k][j];
		res.a[i][j]=w%mod;
	}
	return res;
}
inline Ma ksm(Ma x,int y){
	Ma res;res.I();
	while(y){
		if(y&1) res=res*x;
		x=x*x;y>>=1;
	}return res;
}
inline void Solve(){
	memset(trs.a,0,sizeof(trs.a));
	memset(Ans.a,0,sizeof(Ans.a));
	debug(cnt);
	for(rint i=1;i<=cnt;++i){
		pa o=tmp[i];
		int fir=o.first,sec=o.second,bit=__builtin_popcount(sec);
//		debug(fir);
//		debug(sec);
		if(sec&1) {
			sec>>=1;
			trs.a[i][Idx[fir][sec]]=bit;
			sec|=(1<<m);
			fir++;
			trs.a[i][Idx[fir][sec]]=bit;
		}
		else {
			sec>>=1;
			trs.a[i][Idx[fir][sec]]=1;
			sec|=(1<<m);
			fir++;
			trs.a[i][Idx[fir][sec]]=1;
		}
	}
	for(rint i=1;i<=cnt;++i){
		pa o=tmp[i];
		int fir=o.first,sec=o.second,bit=__builtin_popcount(sec);
		if(fir==bit)
		Ans.a[1][i]=1;
	}
	Ans=Ans*ksm(trs,n-m-1);
	ll ans=0;
	for(rint i=1;i<=cnt;++i){
		pa o=tmp[i];
		int fir=o.first,sec=o.second,bit=__builtin_popcount(sec);

		int oo=1;
		for(rint i=1;i<=bit;++i) oo*=i;
		if(fir==k){
			ans=pls(ans,1ll*Ans.a[1][i]*oo%mod);
//			debug(bit);
//		debug(fir);
//			debug(Ans.a[1][i]);

		}
	}cout<<ans;
}
int main()
{//	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	n=read(),k=read(),m=read();m=min(m,n-1);
	int all=1<<(m+1);
	all--;
	for(rint i=0;i<=k;++i){
		for(rint j=0;j<=all;++j){
			Idx[i][j]=++cnt;tmp[cnt]=mk(i,j);
		}
	}
	Solve();
	return 0;
}


//region trash
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <vector>
#include <iostream>
#include <array>
#include <memory>

using namespace std;
constexpr int MOD = 1e9+7;
class Modular {
public:
  int val;
  int normalize(const long long x) const {
    if (x <= -MOD || x >= MOD) return x % MOD;
    return x;
  }
  Modular ():val(0){}
  Modular (long long val):val(normalize(val)){}

  operator long long (){ return val >= 0 ? val : val + MOD; }

  Modular operator *(const Modular &ri) const { return val * 1LL * ri.val % MOD; }
  Modular operator +(const Modular &ri)  const{ return (val + ri.val) % MOD; }
};

//Modular operator +=(Modular &le, const Modular ri) { return le = (le.val + ri.val) % MOD; }
//Modular operator *=(Modular &le, const Modular ri) { return le = (le.val * 1LL * ri.val) % MOD; }

/*
Modular pot(Modular a, long long b) {
  Modular res = 1;
  while(b > 0){
    if (b & 1) res = res * a;
    b /= 2;
    a= a * a;
  }
  return res;
}
 */

#define T Modular
const int SZ=(1<<4)*13;
struct mat_t {
  T M[SZ][SZ] = {};
  mat_t operator * (const mat_t a) const {
    mat_t res;
    for (long long(r) = (0); (r) < (long long)(SZ); ++(r)) {
      for (long long(c) = (0); (c) < (long long)(SZ); ++(c)) {
        T val = 0;
        for (long long(k) = (0); (k) < (long long)(SZ); ++(k)) val = val  + this->M[r][k] * a.M[k][c];
        res.M[r][c] = val;
      }
    }
    return res;
  }

  vector<T> operator * (const vector<T> & rhs) {
    vector<T>RES(SZ);
    for (long long(r) = (0); (r) < (long long)(SZ); ++(r)) {
      for (long long(c) = (0); (c) < (long long)(SZ); ++(c)) {
        RES[r] =  RES[r] + M[r][c] * rhs[c];
      }
    }
    return RES;
  }

  void zero() {
    for (long long(g) = (0); (g) < (long long)(SZ); ++(g)) M[g][g] = 1;
  }

  /*
  void print() {
    for (long long(r) = (0); (r) < (long long)(SZ); ++(r)) {
      for (long long(c) = (0); (c) < (long long)(SZ); ++(c)) {
        cout << M[r][c] << " ";
      }
      cout << endl;
    }
  }
   */
};

#ifdef LOCAL
#define DB(x){if(cond)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#else
#define DB(x){}
#endif
#define REP(i,b)for(auto i=0;i<(b);++i)
#define FOR(i,a,b)for(auto i=(a);i<=(b);++i)
#define FORD(i,a,b)for(auto i=(a);i>=(b);--i)
#define FORDE(rit,x)for(auto rit=(x).rbegin();rit!=(x).rend();rit++)
#define VV vector
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
template<typename X, typename Y>bool MA(X&a,Y b){if(a<b){a=b;return true;} return false;}
template<typename X, typename Y>bool MI(X&a,Y b){if(a>b){a=b;return true;} return false;}
typedef long long LL,ll;typedef long double LD,ld;
typedef array<int,2>I2,i2;typedef VV<int>VI,vi;
using namespace std;
int cond=0;
//endregion

int multi=0,gcj=0;

int pos(int m, int p) { return m * 13 + p; }

struct Solver {
  void solve() {
    mat_t res; res.zero();
    mat_t one = {};
    int N,K,M;
    cin>>N>>K>>M;

    REP(m,(1<<M))FOR(k,0,K) {
      int new_mask=(m<<1) & ((1<<M)-1);

      // skip
      one.M[ pos(new_mask, k) ][ pos(m, k) ] = 1;
      if (k < K) {
        one.M[ pos(new_mask|1, k+1)  ][ pos(m, k) ] = __builtin_popcount(m) + 1;
      }
    }
    DB("")
    for(int b=N;b>0;b/=2){
      if(b&1) res=res*one;
      one=one*one;
    }
    DB("")
    VV<Modular>RES(SZ);
    RES[pos(0,0)] = 1;

    VV<Modular> ODP = res * RES;
    Modular wynik = 0;
    REP(m,(1<<M)) wynik = wynik + ODP[pos(m,K)];
    cout<<(ll)wynik<<endl;
  }
};

struct Solver2 {
  void gen() {}
  void brute() {}
};

int main(int argc,char** argv){
  /*
  random_device rd{};
  uint64_t seed = (uint64_t)rd()
      ^ (uint64_t)std::chrono::steady_clock::now().time_since_epoch().count()
      ^ (uint64_t)__builtin_ia32_rdtsc()
      ^ (uint64_t)make_unique<char>().get();
  srand(seed); mt19937 rng(seed);
   */

  ios::sync_with_stdio(false),cin.tie(nullptr);
  FOR(a,1,argc-1){if(argv[a][0]=='g') { Solver2 solver; solver.gen(); return 0; }}
  FOR(a,1,argc-1){if(argv[a][0]=='q') cond=1U<<30U;}
  cout.setf(ios::fixed),cout.precision(10);
  int t{};if(multi||gcj)cin>>t;else t=1;
  bool isBrute=false;FOR(a,1,argc-1)if(argv[a][0]=='b')isBrute=true;
  FOR(i,1,t){if(cond)cerr<<__LINE__<<" "<<i<<endl;if(gcj)cout<<"Case #"<<i<<": ";
    auto solver = make_unique<Solver>();
    auto solver2 = make_unique<Solver2>();
    if (isBrute)
      solver2->brute();
    else
      solver->solve();
  }
  return 0;
}


//region trash
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <vector>
#include <iostream>
#include <array>
#include <memory>

using namespace std;
constexpr int MOD = 1e9+7;
class Modular {
public:
  int val;
  int normalize(const long long x) const {
    if (x <= -MOD || x >= MOD) return x % MOD;
    return x;
  }
  Modular ():val(0){}
  explicit Modular (long long val):val(normalize(val)){}

  ////operator long long (){ return val >= 0 ? val : val + MOD; }

  Modular operator *(const Modular &ri) const { return Modular(val * 1LL * ri.val % MOD); }
  Modular operator +(const Modular &ri)  const{ return Modular((val + ri.val) % MOD); }
};

//Modular operator +=(Modular &le, const Modular ri) { return le = (le.val + ri.val) % MOD; }
//Modular operator *=(Modular &le, const Modular ri) { return le = (le.val * 1LL * ri.val) % MOD; }

/*
Modular pot(Modular a, long long b) {
  Modular res = 1;
  while(b > 0){
    if (b & 1) res = res * a;
    b /= 2;
    a= a * a;
  }
  return res;
}
 */

#define T Modular
const int SZ=(1<<4)*13;
struct mat_t {
  T M[SZ][SZ] = {};
  mat_t operator * (const mat_t a) const {
    mat_t res;
    for (long long(r) = (0); (r) < (long long)(SZ); ++(r)) {
      for (long long(c) = (0); (c) < (long long)(SZ); ++(c)) {
        T val = 0;
        for (long long(k) = (0); (k) < (long long)(SZ); ++(k)) val = val  + this->M[r][k] * a.M[k][c];
        res.M[r][c] = val;
      }
    }
    return res;
  }

  vector<T> operator * (const vector<T> & rhs) {
    vector<T>RES(SZ);
    for (long long(r) = (0); (r) < (long long)(SZ); ++(r)) {
      for (long long(c) = (0); (c) < (long long)(SZ); ++(c)) {
        RES[r] =  RES[r] + M[r][c] * rhs[c];
      }
    }
    return RES;
  }

  void zero() {
    for (long long(g) = (0); (g) < (long long)(SZ); ++(g)) M[g][g] = 1;
  }

  /*
  void print() {
    for (long long(r) = (0); (r) < (long long)(SZ); ++(r)) {
      for (long long(c) = (0); (c) < (long long)(SZ); ++(c)) {
        cout << M[r][c] << " ";
      }
      cout << endl;
    }
  }
   */
};

#ifdef LOCAL
#define DB(x){if(cond)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#else
#define DB(x){}
#endif
#define REP(i,b)for(auto i=0;i<(b);++i)
#define FOR(i,a,b)for(auto i=(a);i<=(b);++i)
#define FORD(i,a,b)for(auto i=(a);i>=(b);--i)
#define FORDE(rit,x)for(auto rit=(x).rbegin();rit!=(x).rend();rit++)
#define VV vector
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
template<typename X, typename Y>bool MA(X&a,Y b){if(a<b){a=b;return true;} return false;}
template<typename X, typename Y>bool MI(X&a,Y b){if(a>b){a=b;return true;} return false;}
typedef long long LL,ll;typedef long double LD,ld;
typedef array<int,2>I2,i2;typedef VV<int>VI,vi;
using namespace std;
int cond=0;
//endregion

int multi=0,gcj=0;

int pos(int m, int p) { return m * 13 + p; }

struct Solver {
  void solve() {
    mat_t res; res.zero();
    mat_t one = {};
    int N,K,M;
    cin>>N>>K>>M;

    REP(m,(1<<M))FOR(k,0,K) {
      int new_mask=(m<<1) & ((1<<M)-1);

      // skip
      one.M[ pos(new_mask, k) ][ pos(m, k) ] = 1;
      if (k < K) {
        one.M[ pos(new_mask|1, k+1)  ][ pos(m, k) ] = __builtin_popcount(m) + 1;
      }
    }
    DB("")
    for(int b=N;b>0;b/=2){
      if(b&1) res=res*one;
      one=one*one;
    }
    DB("")
    VV<Modular>RES(SZ);
    RES[pos(0,0)] = 1;

    VV<Modular> ODP = res * RES;
    Modular wynik = 0;
    REP(m,(1<<M)) wynik = wynik + ODP[pos(m,K)];
    cout<<wynik.val<<endl;
  }
};

struct Solver2 {
  void gen() {}
  void brute() {}
};

int main(int argc,char** argv){
  /*
  random_device rd{};
  uint64_t seed = (uint64_t)rd()
      ^ (uint64_t)std::chrono::steady_clock::now().time_since_epoch().count()
      ^ (uint64_t)__builtin_ia32_rdtsc()
      ^ (uint64_t)make_unique<char>().get();
  srand(seed); mt19937 rng(seed);
   */

  ios::sync_with_stdio(false),cin.tie(nullptr);
  FOR(a,1,argc-1){if(argv[a][0]=='g') { Solver2 solver; solver.gen(); return 0; }}
  FOR(a,1,argc-1){if(argv[a][0]=='q') cond=1U<<30U;}
  cout.setf(ios::fixed),cout.precision(10);
  int t{};if(multi||gcj)cin>>t;else t=1;
  bool isBrute=false;FOR(a,1,argc-1)if(argv[a][0]=='b')isBrute=true;
  FOR(i,1,t){if(cond)cerr<<__LINE__<<" "<<i<<endl;if(gcj)cout<<"Case #"<<i<<": ";
    auto solver = make_unique<Solver>();
    auto solver2 = make_unique<Solver2>();
    if (isBrute)
      solver2->brute();
    else
      solver->solve();
  }
  return 0;
}


#include<bits/stdc++.h>
#define rep(XX,AA,BB) for(int XX=AA;XX<=BB;XX++)
#define tep(XX,AA,BB) for(int XX=AA;XX>=BB;XX--)
#define LL long long
const int K=14;
const int M=1<<4;
const int MX=310;
const LL MOD=1e9+7;
using namespace std;

int n,m,k;
int tot=0,maxn;
int get[K][M];

void read(int &x){
	char c;
	for(;c>'9'||c<'0';c=getchar());
	for(;'0'<=c&&c<='9';c=getchar())x=(x<<3)+(x<<1)+(c^48);
}

struct nn{
	LL a[MX][MX];
	void MEM(){rep(i,0,maxn)rep(j,0,maxn)a[i][j]=0;}
}hlp;

nn MUL(nn A,nn B){
	nn C;C.MEM();
	rep(i,1,tot)rep(j,1,tot){
		C.a[i][j]=0;
		rep(r,1,tot){
			C.a[i][j]+=A.a[i][r]*B.a[r][j]%MOD;
			C.a[i][j]%=MOD;
		}
	}
	return C;
}

LL KSM(int y){
	nn res;res.MEM();
	LL ans;
	res.a[1][1]=1;
	while(y){
		if(y%2==1)res=MUL(res,hlp);
		hlp=MUL(hlp,hlp);
		y/=2;
	}
	rep(num,0,maxn)ans=(ans+res.a[1][get[k][num]])%MOD;
	return ans;
}

int main(){
	read(n);read(k);read(m);
	maxn=(1<<m)-1;
	rep(i,0,k)rep(j,0,maxn)get[i][j]=++tot;
	rep(len,0,k)rep(num,0,maxn){
		int num1=(num<<1)&maxn;
		hlp.a[get[len][num]][get[len][num1]]=1;
		if(len<k)hlp.a[get[len][num]][get[len+1][num1|1]]=__builtin_popcount(num)+1;
	}
	printf("%lld\n",KSM(n));
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(3,"Ofast","-funroll-loops","-fdelete-null-pointer-checks")
#pragma GCC target("ssse3","sse3","sse2","sse","avx2","avx")
#define lowbit(x) ((x)&-(x))
#define HohleFeuerwerke using namespace std
typedef unsigned int u32;
typedef long long i64;
HohleFeuerwerke;
i64 n;
inline bool isprime(i64 x){
	for(i64 i=2;i<=sqrt(x);i++)
		if(x%i==0) return false;
	return true;
}
inline i64 primes(i64 x){
    if(x<=1) return 0;
    const int eps=128;const int eps_bit=8;
    u32 S2=sqrt(x);u32 S3=pow(x,1.0/3);u32 S4=sqrt(S2);
    u32 B=std::max(2ull,std::min(i64(S2),i64(S3*std::max(1.0,pow(log(x),3)*0.001))));
    u32 U=x/B+eps;u32 a,b,t;register u32 p,q,r,u,v;i64 sum=0;
    vector<char> mu(B+1);mu[1]=1;
    for(a=2;a<=B;++a)
        if(!mu[a]) for(b=a;b<=B;b+=a) mu[b]=mu[b]<0?1:-1;
    for(a=2;a*a<=B;++a)
        if(mu[a*a]) for(b=a*a;b<=B;b+=a*a) mu[b]=0;
    vector<int> pi(U),primes(u32(U/log(U)*1.25506)),md(U);u32 count=0;
    md[1]=1<<30,primes[0]=1;
    for(a=6;a<U;a+=3) md[a]=3;for(a=4;a<U;a+=2) md[a]=2;
    for(a=4;a*a<U;++a)
        if(!md[a]){
            for(b=a*a;b<U;b+=6*a) if(!md[b]) md[b]=a;
            for(b=a*(a+(3-a%3)*2);b<U;b+=6*a) if(!md[b]) md[b]=a;
        }
    for(a=2;a<U;++a) pi[a]=md[a]?pi[a-1]:(primes[++count]=md[a]=a,pi[a-1]+1);
    sum+=pi[B]-1;
    for(p=pi[B]+1;primes[p]<=S2;++p)sum-=pi[x/primes[p]]-p+1;
    for(a=1;a<=B;++a) if(mu[a]) sum+=mu[a]*(x/a);
    for(p=sqrt(x/primes[pi[B]])+1;p<=B;++p)
        if(pi[p]!=pi[p-1]) sum+=pi[B]-pi[std::max(u32(x/p/p),p)];
    for(p=S4+1;p<=S3;++p)
        if(pi[p]!=pi[p-1]){
            u32 L=p+1,R=std::min((i64)B,x/p/p);
            sum+=(i64)(2-pi[p])*(pi[R]-pi[L-1]);u32 m=x/p;
            for(u=L;u<=R;u=v+1){
                t=pi[m/primes[pi[u-1]+1]];
                v=m/primes[t];if(v>R) v=R;
                sum+=(i64)(pi[v]-pi[u-1])*t;
            }
        }
    vector<int> bit(U);
    vector<int> nxt(B+2);
    for(q=1;q<=B;++q) nxt[q]=q+!mu[q];
    nxt[B+1]=B+1;
    for(r=1;r<=U-eps;++r) bit[r]=r;
    for(p=1;p<=S4;++p)
        if(pi[p]!=pi[p-1]){
            i64 m=x/p;
            if(p<=eps_bit){
                for(q=std::max(p,B/p)+1;q<=B;++q){
                    while(q!=nxt[q]) q=nxt[q]=nxt[nxt[q]];
                    if(q>B) break;
                    if(md[q]<=p){
                        nxt[q]=q+1;
                        continue;
                    }
                    sum-=mu[q]*bit[m/q];
                }
                for(r=1;r<U;++r) bit[r]=md[r]>p;
                if(pi[p]<count&&primes[pi[p]+1]>eps_bit){
                    for(r=1;r<U;++r)
                        if(r+lowbit(r)<U) bit[r+lowbit(r)]+=bit[r];
                }
				else for(r=1;r<U;++r)bit[r]+=bit[r-1];
            }
			else{
                for(q=std::max(p,B/p)+1;q<=B;++q){
                    while(q!=nxt[q]) q=nxt[q]=nxt[nxt[q]];
                    if(q>B) break;
                    if(md[q]<=p){
                        nxt[q]=q+1;
                        continue;
                    }
                    if(mu[q]==1) for (a=m/q;a;a-=lowbit(a)) sum-=bit[a];
					else for (a=m/q;a;a-=lowbit(a)) sum+=bit[a];
                }
                for(a=p;a<U;a+=lowbit(a)) --bit[a];
                for(r=p*p;r<U;r+=6*p)
                    if(md[r]==p) for(a=r;a<U;a+=lowbit(a)) --bit[a];
                for(r=p*(p+(3-p%3)*2);r<U;r+=6*p)
                    if(md[r]==p) for(a=r;a<U;a+=lowbit(a)) --bit[a];
            }
        }
    return sum;
}
int main()
{
    scanf("%I64d",&n);
    i64 ans=pow(n,1./3);ans=primes(ans);
    for(i64 i=2;i<=sqrt(n);i++)
    	if(isprime(i)) ans+=primes(n/i)-primes(i);
	printf("%I64d\n",ans);
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
typedef unsigned __int128 ulll;
#define Te template<class T>
#define pb push_back
#define gu getchar_unlocked
#define pu putchar_unlocked

const int M=1000010,Mp=1000010,Pn=100000,Pk=100;
uint ar[(M>>6)+5]={0};//Mp=max size of the prime
int z=0,Pr[Mp],C[M],dp[Pn][Pk];
void Sieve(int N)
{
    bitset<M> st;
    st[1]=true;
    for(int i=4;i<N;i+=2)st[i]=true;
    for(int i=3;i*i<N;i+=2)if(!st[i])
    for(int j=i*i;j<N;j+=i+i)st[j]=true;
    z=0;
    for(int i=1;i<N;i++)
    {
        if(!st[i])Pr[z++]=i;
        C[i]=z;
    }
}
void init(){Sieve(M);int k,n,res;
for(n=0;n<Pn;n++)dp[n][0]=n;//C=number of prime<=i
for(k=1;k<Pk;k++)for(n=0;n<Pn;n++)
dp[n][k]=dp[n][k-1]-dp[n/Pr[k-1]][k-1];}
ll phi(ll n,int k){if(n<Pn&&k<Pk)return dp[n][k];
if(k==1)return ((++n)>>1);if(Pr[k-1]>=n) return 1;
return phi(n,k-1)-phi(n/Pr[k-1],k-1);}
ll Legendre(ll n){if(n<M) return C[n];
int L=sqrt(n)+1;int k=upper_bound(Pr,Pr+z,L)-Pr;
return phi(n,k)+(k-1);}//returns number of integers
ll Lh(ll n){if(n<M)return C[n];// less or equal n
ll w,R=0;// which are not divisible by any of
int i,j,a,b,c,L;//the first k prime
b=sqrt(n),c=Lh(cbrt(n)),a=Lh(sqrt(b)),b=Lh(b);
R=phi(n,a)+(((b+a-2)*(b-a+1))>>1);
for(i=a;i<b;i++){w=n/Pr[i];L=Lh(sqrt(w)),R-=Lh(w);
if(i<=c){for(j=i;j<L;j++){R+=j;R-=Lh(w/Pr[j]);}}}
return R;}//phi(n,k)=phi(n,k-1)-phi(n/p_k,k-1)

int main(int argc, char const *argv[])
{
    init();
    ll n;
    cin>>n;
    ll ans=0;
    ll cnt=0;
    for(int i=0;i<Mp and (ll)Pr[i]*(ll)Pr[i]<=n;i++)
    {
        cnt++;
        ans+=Lh(n/Pr[i])-cnt;
        if((ll)Pr[i]*(ll)Pr[i]*(ll)Pr[i]<=n)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define maxn 2000000
using namespace std;
ll P(ll m, ll n);
ll pi(ll x);
ll phi(ll m, ll n);
bool isprm[2000005];
int cntprm[2000005];
vector<ll> prm;
void Init(){
    for(int i=2;i<=maxn;++i){
        isprm[i] = true;
    }
    for(int i=2;i<=maxn;++i){
        cntprm[i] = cntprm[i-1] + isprm[i];
        if(isprm[i]){
            prm.push_back(i);
            for(int j=i+i;j<=maxn;j+=i) isprm[j] = false;
        }
    }
}
ll sol(ll x){
    ll ans = 0;
    ll sq = sqrt(x);
    for(int i=0;i<(int)prm.size()&&prm[i]<=sq;++i){
        ll a = prm[i], b = x/a;
        if(b<=maxn) ans+=cntprm[b] - cntprm[a] ;
        else{
            ans+=pi(b) - cntprm[a];
        }
    }
    return ans;
}
int main(void){
    ll n;
    Init();
    cin>>n;
    cout << cntprm[(int)cbrt(n)] + sol(n) << "\n" ;
}
ll phi(ll m, ll n){
    if(m){
        if(n){
            //if(m<n) return 1;
            else return phi(m, n-1) - phi(m/prm[n-1], n-1);
        } else {
            return m;
        }
    } else {
        return 0;
    }
}
ll P(ll m, ll n){
    ll res = 0, sq = sqrt(m);
    for(int i=n;i<(int)prm.size()&&prm[i]<=sq;++i){
        auto num = prm[i];
        res+=pi(m/num) - pi(num) + 1;
    }
    return res;
}
ll pi(ll x){
    if(x<=maxn) return cntprm[x];
    else{
        ll n = ceil( cbrt(x)), m = x;
        return phi(m,n) + n - 1 - P(m,n);
    }
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll n,ans;
ll v[120000001],p[120000001],t;
void find_prime()
{
	for(int i=2;i<=120000000;++i)
	{
		if(v[i]==0)
		{
			v[i]=i;
			p[++t]=i;
		}
		for(int j=1;j<=t;++j)
		{
			if(p[j]>v[i]||p[j]>n/i) break;
			v[i*p[j]]=p[j];
		}
	}
}
int main()
{
	scanf("%lld",&n);
	find_prime();
	for(int i=1;i<=t;++i)
	{
	    for(int j=i+1;j<=t;++j)
	    {
	    	if(p[i]*p[j]<=n)
	    	    ++ans;
	    	else
			    break;
	    }
	}
	for(int i=1;i<=t;++i)
	{
		if(p[i]*p[i]*p[i]<=n)
		    ++ans;
		else
		    break;
	}
	printf("%d",ans);
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
const long long MD = 998244353;
template<long long MOD=MD> struct mdint {
    int d=0;
    mdint () {d=0;}
    mdint (long long _d) : d(_d%MOD){};
    friend mdint& operator+=(mdint& a, const mdint& o) {
        a.d+=o.d; if(a.d>=MOD) a.d-=MOD;
        return a;
    }
    friend mdint& operator-=(mdint& a, const mdint& o) {
        a.d-=o.d; if(a.d<0) a.d+=MOD;
        return a;
    }
    friend mdint& operator*=(mdint& a, const mdint& o) {
        return a = mdint((ll)a.d*o.d);
    }
    mdint operator*(const mdint& o) const {
        mdint res = *this;
        res*=o;
        return res;
    }
    mdint operator+(const mdint& o) const {
        mdint res = *this;
        res+=o;
        return res;
    }
    mdint operator-(const mdint& o) const {
        mdint res = *this;
        res-=o;
        return res;
    }
    mdint operator^(long long b) const {
        mdint tmp = 1;
        mdint power = *this;
        while(b) {
            if(b&1) {
                tmp = tmp*power;
            }
            power = power*power;
            b/=2;
        }
        return tmp;
    }
    friend mdint operator/=(mdint& a, const mdint& o) {
        a *= (o^(MOD-2));
        return a;
    }
    mdint operator/(const mdint& o) {
        mdint res = *this;
        res/=o;
        return res;
    }
    bool operator==(const mdint& o) { return d==o.d;}
    bool operator!=(const mdint& o) { return d!=o.d;}
    friend istream& operator>>(istream& c, mdint& a) {return c >> a.d;}
    friend ostream& operator<<(ostream& c, const mdint& a) {return c << a.d;}
};
using  mint = mdint<MD>;
#define rep(i,n) for(int i=0;i<n;++i)
template<typename T, int N=3> struct matrix {
    T mat[N][N] = {};
    friend matrix operator*(const matrix& a, const matrix& b) {
        matrix res;
        rep(i,N) rep(j,N) rep(k,N) {
            res.mat[i][k]+=a.mat[i][j]*b.mat[j][k];
        }
        return res;
    }
    static matrix eye() {
        matrix res;
        for(int i=0;i<N;++i) res.mat[i][i]=1;
        return res;
    }
    friend matrix pow(matrix& a, ll pwr) {
        matrix res = eye();
        while(pwr) {
            if(pwr&1) res=res*a;
            a=a*a;
            pwr/=2;
        }
        return res;
    }
};
int main() {
    int n,m; cin >> n >> m;
    matrix<mint,201> mat;
    vector<string> ws(n);
    for(auto& i: ws) cin >> i;
    sort(all(ws),[&](string a, string b) {return a.size()<b.size();});
    auto id = [&](int i, int j, int k) {
        return 1+(i*5+j)*5+k;
    };
    for(int i=0;i<n;++i) {
        // from 0 to other state
        int sz = ws[i].size();
        for(int j=0;j<=i;++j) {
            if(ws[i].substr(0,ws[j].size()) == ws[j]) {
                if(sz==1) mat.mat[0][0]+=1;
                else mat.mat[0][id(i,sz-1,ws[j].size()-1)]+=1 + (i!=j);
            }
        }
        for(int j=1;j<sz;++j) {
            for(int k=1;k<=j;++k) {
                if(j==1 and k==1) {
                    mat.mat[id(i,j,k)][0]+=1;
                } else mat.mat[id(i,j,k)][id(i,j-1,k-1)]+=1;
            }
            for(int w=0;w<n;++w) {
                auto o = ws[w];
                int k = min(j,(int)o.size());
                if(o.substr(0,k)==ws[i].substr(sz-j,k)) {
                    if(o.size()<=j) {
                        if(j==1 and k==1) mat.mat[id(i,j,0)][0]+=1;
                        else mat.mat[id(i,j,0)][id(i,j-1,o.size()-1)]+=1;
                    } else mat.mat[id(i,j,0)][id(w,o.size()-1,j-1)]+=1;
                }
            }
        }
    }
    mat = pow(mat,m);
    cout << mat.mat[0][0] << '\n';
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define int long long
#define pa pair<int ,int >
#define mp make_pair
using namespace std;
inline int read(){int x=0,f=1,ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}
inline void write(int x){if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10); putchar(x%10+'0');}
inline void writeln(int x){write(x); puts("");}
const int N=45,M=161,mod=998244353;
int root,n,m,cnt,End[N],tran[N][26];
char s[N];
inline void insert(){

	int now=root,len=strlen(s+1);
	for (int i=1;i<=len;i++){
		int c=s[i]-'a';
		if (tran[now][c]==-1) tran[now][c]=++cnt;
		 now=tran[now][c];
	}
	End[now]|=1;
}
inline void init(){
	memset(tran,-1,sizeof tran);
	n=read(); m=read(); root=0;
	for (int i=1;i<=n;i++){
		scanf("%s",s+1);
		insert();
	}
}
struct matrix{
	int mat[M][M];
	matrix() {memset(mat,0,sizeof(mat));}
	matrix operator * (const matrix &C) const
	{
		matrix ans;
		for(int i=0;i<M;i++)
			for(int j=0;j<M;j++)
				for(int k=0;k<M;k++)
					ans.mat[i][j]=(ans.mat[i][j]+mat[i][k]*C.mat[k][j]%mod)%mod;
		return ans;
	}
}A;
pa q[M];
int h,t;
map<pa,int >id;
int get(pa p){
	if (p.first>p.second) swap(p.first,p.second);
	if (!id.count(p)){
		int k=id.size();
		id[p]=k;
		q[++t]=p;
	}
	return id[p];
}
inline matrix pow(matrix B,int k){
	matrix C;
	for (int i=0;i<M;i++) C.mat[i][i]=1;
	for (;k;k>>=1,B=B*B){
		if (k&1) C=C*B;
	}
	return C;
}
inline void solve(){
	id[mp(0,0)]=0; q[++t]=(pa){0,0};
	while (h<t){
		pa u=q[++h];
		int x=get(u);
		for (int c=0;c<26;c++){
			pa nxt=mp(tran[u.first][c],tran[u.second][c]);
			if (nxt.first==-1||nxt.second==-1) continue;
			A.mat[x][get(nxt)]++;
			if (End[tran[u.first][c]]) A.mat[x][get(mp(0,nxt.second))]++;
			if (End[tran[u.second][c]]) A.mat[x][get(mp(nxt.first,0))]++;
			if (End[tran[u.first][c]]&&End[tran[u.second][c]]) A.mat[x][0]++;
		}
	}
	writeln(pow(A,m).mat[0][0]);
}
signed main(){
	init(); solve();
	return 0;
}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define INF 2000000000
#define INFL 200000000000000000LL

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))

#define fi first
#define se second
#define PI (acos(-1))
#define mod (998244353)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class T,class V> ostream& operator<<(ostream &s,pair<T,V> a)
{
    s<<a.fi<<' '<<a.se;
    return s;
}

const int N = 300, K = 2e3+3;

ll a[N][N],b[N][N],r[N][N],pr[N][N];
void mul(int m,ll md){
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            __int128 p=0;
            for(int k=0;k<m;k++)p=(p+a[i][k]*b[k][j]);
            r[i][j]=p%md;
        }
    }
}
void POWER(int m,ll n,ll md){
    memset(pr,0,sizeof pr);
    for(int i=0;i<m;i++)pr[i][i]=1;
    while(n){
        if(n&1){
            for(int i=0;i<m;i++)for(int j=0;j<m;j++)a[i][j] = pr[i][j];
            mul(m,md);
            for(int i=0;i<m;i++)for(int j=0;j<m;j++)pr[i][j] = r[i][j];
        }
        n>>=1;
        if(n){
            for(int i=0;i<m;i++)for(int j=0;j<m;j++)a[i][j] = b[i][j];
            mul(m,md);
            for(int i=0;i<m;i++)for(int j=0;j<m;j++)b[i][j] = r[i][j];

        }
    }
}

struct vertex
{
    int next[26];
    int en;
    vertex()
    {
        fill(next,next+26,-1);
        en=0;
    }
};
vector<vertex> trie(1);
void add_string(string &s)
{
    int v=0;
    for(char ch:s)
    {
        ch-='a';
        if(trie[v].next[ch]==-1)
        {
            trie[v].next[ch]=trie.size();
            trie.emplace_back();
        }
        v=trie[v].next[ch];
    }
    trie[v].en++;
}
int vis[K][K];
int cnt = 0;
int dfs(int x,int y){
	if(vis[x][y]!=-1)return vis[x][y];
	int cur = vis[x][y] = cnt++;
	for(int c = 0;c<26;c++){
		if(trie[x].next[c]==-1||trie[y].next[c]==-1)continue;
		int l = trie[x].next[c];
		int l2 = trie[y].next[c];
		int p = dfs(l,l2);
		b[cur][p]++;
		if(trie[l].en){
			p = dfs(0,l2);
			b[cur][p]++;
		}

		if(trie[l2].en){
			p = dfs(l,0);
			b[cur][p]++;
		}

		if(trie[l].en&&trie[l2].en){
			p = dfs(0,0);
			b[cur][p]++;
		}
	}
	return cur;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int T=1;
    //scanf("%d",&T);

    for(int qq=1; qq<=T; qq++)
    {
		int n,m;
		cin>>n>>m;
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			add_string(s);
		}
		memset(vis,-1,sizeof vis);
		dfs(0,0);
		POWER(cnt,m,mod);
		cout<<pr[0][0]<<endl;
    }
}


#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
const long long MD = 998244353;
template<long long MOD=MD> struct mdint {
    int d=0;
    mdint () {d=0;}
    mdint (long long _d) : d(_d%MOD){};
    friend mdint& operator+=(mdint& a, const mdint& o) {
        a.d+=o.d; if(a.d>=MOD) a.d-=MOD;
        return a;
    }
    friend mdint& operator-=(mdint& a, const mdint& o) {
        a.d-=o.d; if(a.d<0) a.d+=MOD;
        return a;
    }
    friend mdint& operator*=(mdint& a, const mdint& o) {
        return a = mdint((ll)a.d*o.d);
    }
    mdint operator*(const mdint& o) const {
        mdint res = *this;
        res*=o;
        return res;
    }
    mdint operator+(const mdint& o) const {
        mdint res = *this;
        res+=o;
        return res;
    }
    mdint operator-(const mdint& o) const {
        mdint res = *this;
        res-=o;
        return res;
    }
    mdint operator^(long long b) const {
        mdint tmp = 1;
        mdint power = *this;
        while(b) {
            if(b&1) {
                tmp = tmp*power;
            }
            power = power*power;
            b/=2;
        }
        return tmp;
    }
    friend mdint operator/=(mdint& a, const mdint& o) {
        a *= (o^(MOD-2));
        return a;
    }
    mdint operator/(const mdint& o) {
        mdint res = *this;
        res/=o;
        return res;
    }
    bool operator==(const mdint& o) { return d==o.d;}
    bool operator!=(const mdint& o) { return d!=o.d;}
    friend istream& operator>>(istream& c, mdint& a) {return c >> a.d;}
    friend ostream& operator<<(ostream& c, const mdint& a) {return c << a.d;}
};
using  mint = mdint<MD>;
#define rep(i,n) for(int i=0;i<n;++i)
const int N = 203;
struct matrix {
    mint mat[N][N] = {};
    matrix() {}
    friend matrix operator*(const matrix& a, const matrix& b) {
        matrix res;
        rep(i,N) rep(j,N) rep(k,N) {
            res.mat[i][k]+=a.mat[i][j]*b.mat[j][k];
        }
        return res;
    }
    static matrix eye() {
        matrix res;
        for(int i=0;i<N;++i) res.mat[i][i]=1;
        return res;
    }
    friend matrix pw(matrix& a, ll pwr) {
        matrix res = eye();
        while(pwr) {
            if(pwr&1) res=res*a;
            a=a*a;
            pwr/=2;
        }
        return res;
    }
};
matrix mat;
int main() {
    int n,m; cin >> n >> m;

    vector<string> ws(n);
    for(auto& i: ws) cin >> i;
    sort(all(ws),[&](string a, string b) {return a.size()<b.size();});
    auto id = [&](int i, int j, int k) {
        return 1+(i*5+j)*5+k;
    };
    for(int i=0;i<n;++i) {
        // from 0 to other state
        int sz = ws[i].size();
        for(int j=0;j<=i;++j) {
            if(ws[i].substr(0,ws[j].size()) == ws[j]) {
                if(sz==1) mat.mat[0][0]+=1;
                else mat.mat[0][id(i,sz-1,ws[j].size()-1)]+=1 + (i!=j);
            }
        }
        for(int j=1;j<sz;++j) {
            for(int k=1;k<=j;++k) {
                if(j==1 and k==1) {
                    mat.mat[id(i,j,k)][0]+=1;
                } else mat.mat[id(i,j,k)][id(i,j-1,k-1)]+=1;
            }
            for(int w=0;w<n;++w) {
                auto o = ws[w];
                int k = min(j,(int)o.size());
                if(o.substr(0,k)==ws[i].substr(sz-j,k)) {
                    if((int)o.size()<=j) {
                        if(j==1 and k==1) mat.mat[id(i,j,0)][0]+=1;
                        else mat.mat[id(i,j,0)][id(i,j-1,o.size()-1)]+=1;
                    } else mat.mat[id(i,j,0)][id(w,o.size()-1,j-1)]+=1;
                }
            }
        }
    }
    mat = pw(mat,m);
    cout << mat.mat[0][0] << '\n';
}


#include<bits/stdc++.h>
using namespace std;
const int N=12,M=12,K=12;
int n,m,k,a[N][M]={},v[N][M][K]={},t[N][M]={};
int totc=0,num[K]={};
void init()
{
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			cin>>a[i][j];
			if(a[i][j])
			{
				if(num[a[i][j]]==0)
					num[a[i][j]]=++totc;
				a[i][j]=num[a[i][j]];
			}
		}
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			if(a[i][j])
			{
				for(int x=1;x<=i;++x)
					for(int y=1;y<=j;++y)
						++v[x][y][a[i][j]];
				for(int x=i;x<=n;++x)
					for(int y=j;y<=m;++y)
						++v[x][y][a[i][j]];
			}
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			for(int c=1;c<=k;++c)
				t[i][j]+=!v[i][j][c];
}
bool add(int x,int y,int c,int d)
{
	bool flag=true;
	for(int i=x;i<=n;++i)
		for(int j=y+(i==x);j<=m;++j)
		{
			t[i][j]+=bool(v[i][j][c]);
			v[i][j][c]+=d;
			t[i][j]-=bool(v[i][j][c]);
			if(t[i][j]==0)
				flag=false;
		}
	return flag;
}
long long tryy(int x,int y)
{
	if(x>n)
	{/*
		for(int i=1;i<=n;++i)
		{
			for(int j=1;j<=m;++j)
				cout<<a[i][j]<<' ';
			cout<<endl;
		}
		cout<<endl;*/
		return 1;
	}
	if(a[x][y])
	{
		if(v[x][y][a[x][y]]>2)
			return 0;
		return (y==m) ? tryy(x+1,1) : tryy(x,y+1);
	}
	long long s=0;
	for(int c=1;c<=totc;++c)
		if(!v[x][y][c])
		{
			a[x][y]=c;
			if(add(x,y,c,1))
				s+=(y==m) ? tryy(x+1,1) : tryy(x,y+1);
			a[x][y]=0;
			add(x,y,c,-1);
		}
	if(totc!=k)
	{
		++totc;
		a[x][y]=totc;
		if(add(x,y,totc,1))
			s+=(k-totc+1)*((y==m) ? tryy(x+1,1) : tryy(x,y+1));
		a[x][y]=0;
		add(x,y,totc,-1);
		--totc;
	}
	return s%mod;
}
void work()
{
	cout<<tryy(1,1)<<endl;
}
int main()
{
	cin>>n>>m>>k;
	if(k<n+m-1)
		puts("0");
	else
	{
		init();
		work();
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
long n,m,k;
vector<vector<long > > ar;
long color[11][11];
bool used[11];
long long go(long r, long c){
    if(c==m){
        c=0;
        r++;
    }
    if(r==n){
        return 1LL;
    }
    long long ret = 0LL;
    if(ar[r][c]!=0){
        if(color[ar[r][c]][r]<c || (r>0 && color[ar[r][c]][r-1]<=c)){
            return 0LL;
        }
        ret = go(r,c+1)%1000000007LL;
        return ret;
    }
    else{
        bool did =false;
        for(long i = 1; i<=k; i++){
            if(color[i][r]<=c){
                continue;
            }
            if(color[i][n-1]==20 && !used[i]){
                if(did){
                    continue;
                }
                did = true;
                long long total = 1LL;
                for(long j = i+1; j<=k; j++){
                    if(!used[j] && color[j][n-1]==20){
                        total++;
                    }
                }
                long og[n];
                for(long j = 0; j<n; j++){
                    og[j] = color[i][j];
                }
                for(long j = r; j<n; j++){
                    color[i][j] = min(color[i][j],c);
                }
                ret += total*go(r,c+1);
                ret %= 1000000007LL;
                for(long j = r; j<n; j++){
                    color[i][j] = og[j];
                }
            }
            else{
                long og[n];
                for(long j = 0; j<n; j++){
                    og[j] = color[i][j];
                }
                for(long j = r; j<n; j++){
                    color[i][j] = min(color[i][j],c);
                }
                ret += go(r,c+1);
                ret %= 1000000007LL;
                for(long j = r; j<n; j++){
                    color[i][j] = og[j];
                }
            }
        }
        return ret;
    }
}
int main() {
    for(long i = 0; i<=10; i++){
        used[i] = false;
    }
    cin >> n >> m >> k;

    if(n+m-1>k){
        cout << 0 << endl;
        return 0;
    }

    ar.resize(n);
    for(long a = 0; a<=10; a++){
        for(long b= 0; b<=10; b++){
            color[a][b] = 20;
        }
    }
    for(long i = 0; i<n; i++){
        ar[i].resize(m);
        for(long j = 0; j<m; j++){
            cin >> ar[i][j];
            if(ar[i][j]==0){
                continue;
            }
            for(long k = i; k<n; k++){
                color[ar[i][j]][k] = min(color[ar[i][j]][k],j);
            }
            used[ar[i][j]] = true;
        }
    }
    if(n+m-1==k){
        long val[r+c];
        bool ok = true;
        for(long i = 0; i<n; i++){
            for(long j = 0; j<m; j++){
                if(ar[i][j]!=0){
                    if(val[i+j]==0){
                        val[i+j] = ar[i][j];
                    }
                    if(val[i+j]!=ar[i][j]){
                        ok = false;
                    }
                }
            }
        }
        if(!ok){
            cout << 0 << endl;
            return 0;
        }
        long emp = 0;
        for(long i = 0; i<r+c; i++){
            if(val[i]==0){
                emp++;
            }
        }
        long long ans = 1LL;
        for(long i =1;i<=emp; i++){
            ans *= (long long)i;
        }
        cout << ans << endl;
    }
    long long ans = go(0,0)%1000000007 ;
    cout << ans << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int arr[4] , y=0, x=3 , b = 0;
    for(int i=0;i<4;i++){
      cin >> arr[i];
    }
     for(int i=0;i<4;i++) {
        if(arr[i] != arr[i+1]){
            y++;
        } else {
            continue;
            }
            if(y != x){
    x++
} else{
        continue;
    }

     }
     cout << x;
    return 0;
}


    # include <iostream>

    # include <vector>
    using namespace std;
    int main()
    {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);
    vector<int>::iterator it;
    it = unique (v.begin(), v.end()); // 10 20 30 20 10 ?  ?  ?  ?
                                                  //                ^

  v.resize( it - v.begin() );
    cout<<4-v.size();

    return 0;
     }


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

int main()
{

    int a,b,c,d,o;
    vector<int> g;

    g.push_back(a);
    g.push_back(b);
    g.push_back(c);
    g.push_back(d);

    set<int> s;
    s = s(g.begin(),g.begin()+4);

    o = 4- s.size();

    cout<<o;

    return 0;
}


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

int main() {
	int m[1000000000 ];
	unsigned long long int count=0;

	int n;
	for (int i = 0; i < 4; i++) {
		cin >> m[i];
	}for (int i = 0; i < 3; i++) {

		if (m[i] == m[i + 1]) {
			count++;
		}

	}

	cout << count;

	_getch();
	return 0;
}


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

#define N 111
const int INF = 1010;

int n, m, a[N], k;
char s[N][N];
bool vis[N], tag[2], flag[2];

int func(int a, int b) {
	int c = 0;
	for (int t = 1; t < INF; t *= k) {
		c += t * (((a / t) + (b / t)) % k);
	}
	return c;
}

int main() {
	scanf("%d %d %d\n", &n, &m, &k);
	k ++;
	for (int i = 1, b, c; i <= n; i ++) {a
		gets(s[i] + 1);
		tag[0] = tag[1] = 0;
        for (int j = 1; j <= m; j ++) {
			if (s[i][j] == 'G') tag[0] = 1, b = j;
			if (s[i][j] == 'R') tag[1] = 1, c = j;
        }
        a[i] = abs(b - c);
        if (tag[0] && tag[1]) vis[i] = 1;
        else if (tag[0]) flag[0] = 1;
        else if (tag[1]) flag[1] = 1;
	}
	if (flag[0] && flag[1]) {
		puts("Draw");
		return 0;
	}
	if (flag[0]) {
		puts("First");
		return 0;
	}
	if (flag[1]) {
		puts("Second");
		return 0;
	}
	int now = 0;
	for (int i = 1; i <= n; i ++) if (vis[i]) now = func(now, a[i]);
	if (now) puts("First");
	else puts("Second");
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;

const double pi = acos(-1.0);

#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define all(a) (a).begin(), (a).end()
#define int64 long long
#define taskname "d"

const int max_r = 20;
int sum[max_r], n, m, k;
char tmp[1000];

int main() {
	//assert(freopen(taskname".in", "r", stdin));
	//assert(freopen(taskname".out", "w", stdout));
	scanf("%d%d%d", &n, &m, &k);
	if (m == 1) {
		printf("Second\n");
		return 0;
	}
	bool rdraw = false, gdraw = false, r = false, g = false;
	for (int i = 0; i < n; ++i) {
		scanf("%s", tmp);
		int gpos = -1, rpos = -1;
		for (int j = 0; j < m; ++j) {
			if (tmp[j] == 'G') gpos = j;
			if (tmp[j] == 'R') rpos = j;
		}
		if ((gpos == -1) && (rpos != -1)) rdraw = true;
		if ((rpos == -1) && (gpos != -1)) gdraw = true;
		if (gpos != -1) g = true;
		if (rpos != -1) r = true;
		if ((gpos != -1) && (rpos != -1)) {
			int diff = abs(rpos - gpos), r = 0;
			//printf("%d\n", diff);
			while (diff > 0) {
				sum[r] += (diff & 1);
				diff >>= 1;
				++r;
			}
		}
	}
	assert(f);
	assert(g);
	bool zero = true;
	for (int i = 0; i < max_r; ++i)
		if (sum[i] % (k + 1) != 0) {
			zero = false;
			break;
		}
	if (zero)
		if (gdraw)
			if (rdraw)
				printf("Draw\n");
			else
				printf("First\n");
		else
			printf("Second\n");
	else
		if (rdraw)
			if (gdraw)
				printf("Draw\n");
			else
				printf("Second\n");
		else
			printf("First\n");
	return 0;
}


#pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <ctime>
#include <deque>

#define forn(i, n) for (int i = 0; i < int(n); i ++)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; i --)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define pi 3.1415926535897932
#define ll long long
#define ld long double

using namespace std;

bool q[2];
int a[110];
int kol1[2], kol2[2];

int main(){
#ifndef ONLINE_JUDGE
    freopen ("input.txt","rt",stdin);
    freopen ("output.txt","wt",stdout);
#endif
    int n, m, k;
    scanf("%d %d %d\n", &n, &m, &k);
    int kol = 0;
    forn(i, n){
        int kol = 0, k, pr;
        char c1;
        kol2[0] = kol2[1] = 0;
        forn(j, m){
            char c;
            scanf("%c", &c);
            if (c != '-'){
                if (kol == 0) pr = j;
                else k = j - pr - 1;
                if (c == 'G') kol2[0] ++;
                else kol2[1] ++;
                c1 = c;
                kol ++;
            }
        }
        forn(j, 2)
            kol1[j] += kol2[j];
        if (kol != 0){
            if (kol2[0] + kol2[1] == kol2[0]){
                if (kol2[0] < m) q[0] = true;
            } else
            if (kol2[0] + kol2[1] == kol2[1]){
                if (kol2[1] < m) q[1] = true;
            } else a[i] = k;
        }
        scanf("\n");
    }
    if (q[0] && q[1]){
        printf ("Draw");
        return 0;
    } else if (q[0] && !q[1]){
        printf ("First");
        return 0;
    } else if (q[1]){
        printf ("Second");
        return 0;
    }
    if (kol1[0] == 0){
        printf ("Second");
        return 0;
    }
    else if (kol1[1] == 0){
        printf ("First");
        return 0;
    }
    int ans = 0;
    forn(i, 10){
        int kol = 0;
        forn(j, n){
                if ((a[j] & 1) & (1 << i)) kol ++;
        }
        ans += (kol % (k + 1));
    }
    if (ans == 0) printf ("Second");
    else printf ("First");

    return 0;
}#pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <ctime>
#include <deque>

#define forn(i, n) for (int i = 0; i < int(n); i ++)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; i --)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define pi 3.1415926535897932
#define ll long long
#define ld long double

using namespace std;

bool q[2];
int a[110];
int kol1[2], kol2[2];

int main(){
#ifndef ONLINE_JUDGE
    freopen ("input.txt","rt",stdin);
    freopen ("output.txt","wt",stdout);
#endif
    int n, m, k;
    scanf("%d %d %d\n", &n, &m, &k);
    int kol = 0;
    forn(i, n){
        int kol = 0, k, pr;
        char c1;
        kol2[0] = kol2[1] = 0;
        forn(j, m){
            char c;
            scanf("%c", &c);
            if (c != '-'){
                if (kol == 0) pr = j;
                else k = j - pr - 1;
                if (c == 'G') kol2[0] ++;
                else kol2[1] ++;
                c1 = c;
                kol ++;
            }
        }
        forn(j, 2)
            kol1[j] += kol2[j];
        if (kol != 0){
            if (kol2[0] + kol2[1] == kol2[0]){
                if (kol2[0] < m) q[0] = true;
            } else
            if (kol2[0] + kol2[1] == kol2[1]){
                if (kol2[1] < m) q[1] = true;
            } else a[i] = k;
        }
        scanf("\n");
    }
    if (q[0] && q[1]){
        printf ("Draw");
        return 0;
    } else if (q[0] && !q[1]){
        printf ("First");
        return 0;
    } else if (q[1]){
        printf ("Second");
        return 0;
    }
    if (kol1[0] == 0){
        printf ("Second");
        return 0;
    }
    else if (kol1[1] == 0){
        printf ("First");
        return 0;
    }
    int ans = 0;
    forn(i, 10){
        int kol = 0;
        forn(j, n){
                if ((a[j] & 1) & (1 << i)) kol ++;
        }
        ans += (kol % (k + 1));
    }
    if (ans == 0) printf ("Second");
    else printf ("First");

    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
char s[105][105];
int a[105],z;
bool check(int k)
{
	int b[50],i,j;
	memset(b,0,sizeof(b));
	for (i=0;i<z;i++)
	{
		for (j=0;a[i]>0;j++)
		{
			b[j]+=a[i]%2;
			a[i]/=2;
		}
	}
	for (i=0;i<50;i++)
	{
		//cout<<b[i]<<endl;
		if (b[i]%(k+1)!=0)
			return 1;
	}
	return 0;
}
int main()
{
	int n,m,k,i,j,t,x,y;
	cin>>n>>m>>k;
	for (i=0;i<n;i++)
		cin>>s[i];
	t=0;
	z=0;
	for (i=0;i<n;i++)
	{
		x=0;
		for (j=0;j<m;j++)
			if (s[i][j]=='-')
				x++;
		if (x==0||x==m)
			continue;
		x=y=-1;
		for (j=0;j<m;j++)
		{
			if (s[i][j]=='R')
				x=j;
			else if (s[i][j]=='G')
				y=j;
		}
		if (x!=-1&&y==-1)
			t|=1;
		else if (x==-1&&y!=-1)
			t|=2;
		else
		{
			if (x<y)
				a[z]=y-x-1;
			else
				a[z]=x-y-1;
			z++;
		}
	}
	if (t==3)
		cout<<"Draw"<<endl;
	else if (t==1)
		cout<<"First"<<endl;
	else if (t==2)
		cout<<"Second"<<endl;
	else
	{
		if (check(k))
			cout<<"First"<<endl;
		else
			cout<<"Second"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
usimg namespace std;
int main()
{
int a;
cin>>a;
bool k=a;
cout<<k;
}


#include <bits/stdc++.h>
/*
By:ahmed
*/
using namespace std;
int main()
#define int  long long
{
int v;
cin>>v;
if(v==2)
    cout<<2<endl;
else
cout<<1<<endl;
}


#include <iostream>
using namespace std;

int main() {

    int n,v;
    cin >> n ;
    n = v;

        for(int x = 1 ; x < n ; x++)
        {if(n % x =! 0)
            {
               n = n - x;
               if (n = 1)
               break;
            }

        }
          cout << n ;
          return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==2)
	cout<<2'
	else
	cout<<1;
return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <string>
#define PI 3.14159265358979
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
using namespace std ;
long long int  typedef ll ;
int binpow (int a, int n) // число в степень
{
    int res = 1;
    while (n) {
        if (n & 1)
            res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}
int main()
{
    /*ifstream cin ;
    ofstream cout ;
    cin.open ("input.txt");
    cout.open ("output.txt");*/
    string s1;
    string s2;
    string s3;
    int mas1[10][11] = {} ;
    int mas2[10][11] = {};
    int i = 0;
    int j = 0;
    cin >> s1;
    for(int y = 1; y<=9; y++)
    {
        for(i = 0; i < s1.length(); i++)
        {
            mas1[y][s1[i]- '0']++;
            mas2[y][s1[i]- '0']++;
        }
        mas1[y][10] = 0;
        mas2[y][10] = 0;
    }
    int d = 0;
    int maxi = 0;
    int count=0;
    int ym = 0;
    string ans1, ans2;
    for(int y = 9; y>0; y--)
    {
        for(i = y; i>=0; i--)
        {
            if(mas1[y][i] > 0)
            {
                if (mas2[y][10-i-d] > 0)
                    {
                        char a = i +'0';
                        char b = 10-i-d + '0';
                        mas1[y][i]--;
                        mas2[y][10-i-d]--;
                        ans1+=a;
                        ans2+=b;
                        d=1;
                        i=10;
                        count++;
                    }
            }
        }
        d = 0;
        if(count > maxi)
        {
            maxi = count;
            s2.clear();
            s2+=ans1;
            s3.clear();
            s3+=ans2;
            ym = y;
        }
        count  = 0;
        ans1.clear();
        ans2.clear();
    }
    i = 0;
    for(i=1; i< 10; i++)
    {
        char a = i +'0';
        while(mas1[ym][i] > 0)
        {
            s2+=a;
            mas1[ym][i]--;
        }
        while(mas2[ym][i] > 0)
        {
            s3+=a;
            mas2[ym][i]--;
        }
    }
    reverse(ALL(s2));
    reverse(ALL(s3));
    while(mas1[ym][0] > 0)
    {
        s2+= '0';
        mas1[ym][0]--;
    }
    while(mas2[ym][0] > 0)
    {
        s3+= '0';
        mas2[ym][0]--;
    }
    cout << s2 << endl;
    cout << s3;

/   system("pause");
    //cin.close();
    //cout.close();
}


#include<bits/stdc++.h>
#define ll          long long int
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define Max(a,b)    ((a)>(b)?(a):(b))
#define Min(a,b)    ((a)<(b)?(a):(b))
#define rep(i,a,b)  for (int i=(a);i<(b);i+=1)
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define debug(a)    cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
using namespace std;

void solve(){
    string s;
    cin>>s;
    map<int,int>m;
    map<int,int>n;
    for(auto i:s){
        m[i-'0']++;
        n[i-'0']++;
    }
    string curans1;
    string curans2;
    int zeroes=m[0];
    m[0]=0;
    n[0]=0;
    int curzero=0;
    rep(i,1,10){
        int cur=0;
        vi used;
        if(m[i]&&m[10-i]){
            cur++;
            used.pb(i);
            used.pb(10-i);
            m[i]--;
            n[10-i]--;
        }
        else{
            continue;
        }
        rep(i,0,5){
            cur+=min(m[i],n[9-i]);
        }
        if(cur>curzero){
            curans1="";
            curans2="";
            curzero=cur;
            curans1.pb(used[0]+'0');
            curans2.pb(used[1]+'0');
            rep(i,0,5){
                rep(j,0,min(m[i],n[9-i])){
                    curans1.pb(i+'0');
                    curans2.pb(9-i+'0');
                }
            }
            rep(i,0,5){
                rep(j,0,m[9-i]){
                    curans1.pb(9-i+'0');
                }
                rep(j,0,n[i]){
                    curans2.pb(i+'0');
                }
                rep(j,0,n[9-i]-m[i]){
                    curans2.pb(9-i+'0');
                }
                rep(j,0,m[i]-n[9-i]){
                    curans1.pb(i+'0');
                }
            }
        }
        m[used[0]]++;
        n[used[1]]++;
    }
    reverse(all(curans1));
    reverse(all(curans2));
    rep(i,0,zeroes){
        curans1.pb('0');
        curans25.pb('0');
    }
    cout<<curans1<<endl<<curans2;
}

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


ohyehethn#include<iostream>
#include<algorithm>
#include<vector>
#include <string>
#include <map>
#include <sstream>
using namespace std;

#define FOR(i,n) for(int i=0;i<n;i++)

string toStr(int i)
{
    ostringstream oss;
    oss << i;
    string output(oss.str());
    return output;
}

int tensRemaining(map<int,int> mx,map<int,int>my)
{
    int count=0;
    for(int i=1;i<=9;i++) if (mx[i]>0 && my[10-i]>0) {count++;}
    return count;
}

int main()
{

    //keep all 0 for 9s and also for later
    //find 10
    //find 9 until no more
    //output remainint numbers

    string s;
    cin>>s;
    map<int,int> mx,my;

    FOR(i,(int)s.length()) mx[s[i]-'0']++,my[s[i]-'0']++;
    string x,y;

    //find 9 until no more
    for(int i=0;i<=9;i++) if (tensRemaining(mx,my)!=1) while (mx[i]>0 && my[9-i]>0) {mx[i]--,my[9-i]--,x.append(toStr(i)),y.append(toStr(9-i));}

    //find 10 once
    for(int i=1;i<=9;i++) if (mx[i]>0 && my[10-i]>0) {mx[i]--,my[10-i]--,x+=toStr(i),y+=toStr(10-i);break;}

    //find 9 until no more and prepend this time
    for(int i=0;i<=9;i++) while (mx[i]>0 && my[9-i]>0) {mx[i]--,my[9-i]--,x=toStr(i)+x,y=toStr(9-i)+y;}

    //append 0
    while (mx[0]>0 && my[0]>0) mx[0]--,my[0]--,x+="0",y+="0";

    //prepend remaining numbers
    for(int i=0;i<=9;i++) while (mx[i]>0) mx[i]--,x=toStr(i)+x;
    for(int i=0;i<=9;i++) while (my[i]>0) my[i]--,y=toStr(i)+y;

    cout<<x<<endl;
    cout<<y<<endl;
    return 0;
}