#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <unordered_set>
#include <functional>
using namespace std;
const int MAXN = 50 + 1;
const int MOD = 1e9 + 7;

#define _DEBUG

int n, T;
vector<vector<int>> times(3);
vector<vector<int>> combines;

inline int encode(vector<int> nums, int n1, int n2) {
    return nums[0] * (n1 + 1) * (n2 + 1) + nums[1] * (n2 + 1) + nums[2];
}

void findCombines(vector<int> nums, int n1, int n2) {
    for (int g = 0; g < 3; ++g) {
        int current = encode(nums, n1, n2);
        if (combines[current][g] == -1) {
            combines[current][g] = 0;
            if (nums[g] != 0) {
                --nums[g];
                int prev = encode(nums, n1, n2);
                findCombines(nums, n1, n2);
                ++nums[g];
                if (prev == 0) {
                    combines[current][g] = 1;
                } else {
                    for (int pg = 0; pg < 3; ++pg) {
                        if (g != pg) {
                            (combines[current][g] += combines[prev][pg]) %= MOD;
                        }
                    }
                }
            }
        }
    }
}

vector<vector<int>> accTimes;

void getAccTimes(const vector<int>& times, int g, vector<int> ns) {
    vector<int> nums(3);
    for (auto t : times) {
        for (nums[0] = ns[0]; nums[0] >= 0; --nums[0]) {
            for (nums[1] = ns[1]; nums[1] >= 0; --nums[1]) {
                for (nums[2] = ns[2]; nums[2] >= 0; --nums[2]) {
                    if (nums[g] > 0) {
                        int current = encode(nums, ns[1], ns[2]);
                        for (int i = T; i - t >= 0; --i) {
                            --nums[g];
                            int prev = encode(nums, ns[1], ns[2]);
                            (accTimes[current][i] += accTimes[prev][i - t]) %= MOD;
                            ++nums[g];
                        }
                    }
                }
            }
        }
    }
}

long long facts[MAXN];

void initFacts() {
    facts[0] = 1;
    for (int i = 1; i < MAXN; ++i) {
        (facts[i] = facts[i - 1] * i) %= MOD;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> T;
    for (int i = 0, t, g; i < n; ++i) {
        cin >> t >> g;
        times[g - 1].push_back(t);
    }
    int n0 = static_cast<int>(times[0].size());
    int n1 = static_cast<int>(times[1].size());
    int n2 = static_cast<int>(times[2].size());
    int m = (n0 + 1) * (n1 + 1) * (n2 + 1);
    combines = vector<vector<int>>(m, vector<int>(3, -1));
    findCombines({n0, n1, n2}, n1, n2);

#ifdef __DEBUG
    cout << "=== Combines ===" << endl;
    cout << n0 << " " << n1 << " " << n2 << " " << m << endl;
    for (int x = 0; x <= n0; ++x) {
        for (int y = 0; y <= n1; ++y) {
            for (int z = 0; z <= n2; ++z) {
                cout << x << " " << y << " " << z << ":";
                for (int g = 0; g < 3; ++g) {
                     cout << " " << combines[encode({x, y, z}, n1, n2)][g];
                }
                cout << endl;
            }
        }
    }
    cout << "--- Combines ---" << endl;
#endif

    accTimes = vector<vector<int>>(m, vector<int>(T + 1));
    accTimes[0][0] = 1;
    for (int g = 0; g <3; ++g) {
        getAccTimes(times[g], g, {n0, n1, n2});
    }

#ifdef __DEBUG
    cout << "=== Times ===" << endl;
    cout << n0 << " " << n1 << " " << n2 << " " << m << endl;
    for (int x = 0; x <= n0; ++x) {
        for (int y = 0; y <= n1; ++y) {
            for (int z = 0; z <= n2; ++z) {
                cout << x << " " << y << " " << z << ":";
                for (int t = 0; t <= T; ++t) {
                    cout << " " << accTimes[encode({x, y, z}, n1, n2)][t];
                }
                cout << endl;
            }
        }
    }
    cout << "--- Times ---" << endl;
#endif

    initFacts();
    int total = 0;
    for (int i = 0; i <= n0; ++i) {
        for (int j = 0; j <= n1; ++j) {
            for (int k = 0; k <= n2; ++k) {
                int current = encode({i, j, k}, n1, n2);
                int base = accTimes[current][T];
                if (base) {
                    int combineNum = 0;
                    for (int g = 0; g < 3; ++g) {
                        (combineNum += combines[current][g]) %= MOD;
                    }
                    long long factNum = 0;
                    factNum = facts[i] * facts[j] % MOD * facts[k] % MOD;
    #ifdef __DEBUG
                    cout << "T " << base << " C " << combineNum << " F " << factNum << " " << (base * combineNum * factNum) % MOD << endl;
    #endif
                    (total += base * factNum % MOD * combineNum % MOD) % MOD;
                }
            }
        }
    }
    cout << total << endl;
    return 0;
}


#include<bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN=52;
const int MOD=1e9+7;
int g[MAXN][MAXN][MAXN][3],h[MAXN][MAXN][MAXN],fac[MAXN];
void init()
{
	g[1][0][0][0]=1;g[0][1][0][1]=1;g[0][0][1][2]=1;
	fac[0]=1;
	for(int i=1;i<MAXN;i++)
		fac[i]=1LL*fac[i-1]*i%MOD;
	for(int i=0;i<=50;i++)
	{
		for(int j=0;j<=50;j++)
		{
			for(int k=0;k<=50;k++)
			{
				for(int u=0;u<=2;u++)
				{
					if(u!=0) g[i+1][j][k][0]=(g[i+1][j][k][0]+g[i][j][k][u])%MOD;
					if(u!=1) g[i][j+1][k][1]=(g[i][j+1][k][1]+g[i][j][k][u])%MOD;
					if(u!=2) g[i][j][k+1][2]=(g[i][j][k+1][2]+g[i][j][k][u])%MOD;
					int val=1LL*fac[i]*fac[j]%MOD*fac[k]%MOD*g[i][j][k][u]%MOD;
					h[i][j][k]=(h[i][j][k]+val)%MOD;
				}
			}
		}
	}
}
int dp[3][MAXN][2505],sum[3],f[MAXN][MAXN][2505];
vector<int> sv[3];
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	init();
	int n,T;
	scanf("%d%d",&n,&T);
	for(int i=1;i<=n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		y--;
		sv[y].pb(x);
		sum[y]+=x;
	}
	dp[0][0][0]=dp[1][0][0]=dp[2][0][0]=1;
	for(int i=0;i<3;i++)
		for(int j=0;j<(int)sv[i].size();j++)
		{
			int val=sv[i][j];
			for(int k=j;k>=0;k--)
				for(int v=0;v<=sum[i]-val;v++)
				{
					if(v>T) break;
					dp[i][k+1][v+val]=(dp[i][k+1][v+val]+dp[i][k][v])%MOD;
				}
		}
	for(int i=0;i<=(int)sv[0].size();i++)
		for(int j=0;j<=(int)sv[1].size();j++)
			for(int u=0;u<=sum[0];u++)
				for(int v=0;v<=sum[1];v++)
				{
					if(u+v>T) break;
					f[i][j][u+v]=(f[i][j][u+v]+1LL*dp[0][i][u]*dp[1][j][v]%MOD)%MOD;
				}
	int ans=0;
	for(int i=0;i<=(int)sv[0].size();i++)
		for(int j=0;j<=(int)sv[1].size();j++)
			for(int k=0;k<=(int)sv[2].size();k++)
				for(int u=0;u<=(sum[0]+sum[1]);u++)
				{
					if(u>T) break;
					if(f[i][j][u]==0) continue;
					ans=(1LL*ans+1LL*h[i][j][k]*f[i][j][u]%MOD*dp[2][k][T-u]%MOD)%MOD;
				}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fin(a,n) for(int i=a;i<=n;i++)
#define LL long long int
const int maxn=5e3+10;
int brr[maxn];
int x,y;
struct In
{   int ge;
	int coin;
	int step;
	int have[maxn]={0};
};
queue<In>q;
void bfs(In a)
{
	q.push(a);
	while(!q.empty())
	{
		In node=q.front();q.pop();
		if(node.ge>x||node.ge<1)continue;
		if(node.coin==0)
		{
			printf("%d",node.step+1);
			exit(0);
		}
		node.ge++;
		node.step++;
		q.push(node);
		node.ge--;
		node.step--;
		node.ge--;
		node.step++;
		q.push(node);
		node.ge++;
		node.step--;
		if(node.have[node.ge]==0)
		{
			node.have[node.ge]++;
			node.step+=2;
			node.coin--;
			q.push(node);
		}
	}
}
int main()
{
	scanf("%d %d",&x,&y);
	In first;
	first.coin=x;
	first.ge=y;
	first.step=0;
	bfs(first);
 }


#include<bits/stdc++.h>
using namespace std;
#define fin(a,n) for(int i=a;i<=n;i++)
#define LL long long int
const int maxn=1000;
int brr[maxn];
int x,y;
struct In
{   int ge;
	int coin;
	int step;
	int have[101]={0};
};
queue<In>q;
void bfs(In a)
{
	q.push(a);
	while(!q.empty())
	{
		In node=q.front();q.pop();
		if(node.ge>x||node.ge<1)continue;
		if(node.coin==0)
		{
			printf("%d",node.step+1);
			exit(0);
		}
		node.ge++;
		node.step++;
		q.push(node);
		node.ge--;
		node.step--;
		node.ge--;
		node.step++;
		q.push(node);
		node.ge++;
		node.step--;
		if(node.have[node.ge]==0)
		{
			node.have[node.ge]++;
			node.step+=2;
			node.coin--;
			q.push(node);
		}
	}
}
int main()
{
	scanf("%d %d",&x,&y);
	In first;
	first.coin=x;
	first.ge=y;
	first.step=0;
	bfs(first);
 }


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

using namespace std;

int main() {
	int n, k, ans(0);
	cin >> n >> k;
	cout << max(k - 1, n - k) + 4 + 3 * (n - 1) - n;
	_getch();
	return 0;
}


#include <bits/stdc++.h>
#define ANONYMOUS_XTRM ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 1000000
#define EB emplace_back
#define PB push_back
#define PF push_front
#define INS insert
#define MP make_pair
#define F first
#define S second
#define PII pair<int,int>
#define PLL pair<long long ,long long>
#define PLI pair<long long , int>
#define PIL pair<int ,long long>
#define PIPII pair<int , pair<int,int> >
#define PLPLL pair<long long , pair<long long, long long> >
#define square(a) (a)*(a)
#define SZ(a) ((int)(a.size()))
#define FOR(i, n) for (ll i = 0; i <ll(n); i++)
#define array(a,n) for(int i=0;i<int(n);i++){cout<<a[i]<<" ";}
#define vector(v) for(int i=0;i<v.size();i++){cout<<v[i]<<" ";}
typedef int i;
typedef float f;
typedef char c;
typedef double d;
typedef long long ll;
typedef unsigned long long ut;
typedef long double ld;
using namespace std;

int main(){
    while(true){
        int n,k;
        int ans = 0;
        int count = 0;
        cin>>n>>k;
        if(k>n/2){ans = n*3+(n-k);}
        else{for(int i=k;i<=n;i++){if(i==k+1){count+=2;}
                                else{count+=1;}}
            count += 2 * (k-1);
            ans = count + (n-1) + n;}
        cout<<ans<<endl;
    }
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
#include <cassert>
#include <ctime>
#include <set>
#include <map>

using namespace std;

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<ll> vll;
typedef vector<vll> vvll;

#define TASKNAME "text"
#define pb push_back
#define mp make_pair
#define EPS (1E-9)
#define INF ((int)1E9)
#define sqr(x) ((x) * (x))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define sz(x) ((int)(x).size())

const int maxp = (int)1e3;
int nym[maxp];

void countNyms() {
	nym[0] = nym[1] = nym[2] = 0;
	for (int i = 3; i < maxp; i++) {
		int ns[2] = {nym[i / 3], nym[i - i / 3]};
		sort(ns, ns + 2);
		if (ns[0])
			nym[i] = 0;
		else {
			nym[i] = ns[1] == 1 ? 2 : 1;
		}
	}

// 	for (int i = 1; i < maxp; i++)
// 		printf("%d\n", nym[i]);
}

const int MOD = (int)1e9 + 7;
void add(int &x, int toadd) {
	if ((x += toadd) >= MOD)
		x -= MOD;
}

int mult(int a, int b) {
	return (ll)a * b % MOD;
}

int mpower(int x, int pw) {
	int res = 1;
	for (; pw; pw >>= 1) {
		if (pw & 1)
			res = mult(res, x);
		x = mult(x, x);
	}
	return res;
}

int inv(int x) {
	return mpower(x, MOD - 2);
}

const int maxn = (int)1e3;
int C[maxn + 1][maxn + 1];

int main() {
	#ifdef DEBUG
		freopen(TASKNAME".in", "r", stdin);
		freopen(TASKNAME".out", "w", stdout);
	#endif

	countNyms();
	{
		memset(C, 0, sizeof(C));
		for (int n = 0; n <= maxn; n++) {
			C[n][0] = C[n][n] = 1;
			for (int k = 1; k < n; k++)
				C[n][k] = C[n - 1][k - 1], add(C[n][k], C[n - 1][k]);
		}
	}

	int n, p;
	while (scanf("%d%d", &n, &p) >= 1) {
		assert(p <= maxp);

		int cnt[3] = {0, 0, 0};
		for (int i = 1; i < p; i++)
			add(cnt[nym[i]], p - i);
		eprintf("%d %d %d\n", cnt[0], cnt[1], cnt[2]);

		int ans = cnt[0];
		add(ans, cnt[1]);
		add(ans, cnt[2]);
		ans = mpower(ans, n);

// 		eprintf("%d\n", ans);
		for (int a = 0; a <= n; a += 2)
			for (int b = 0; b <= n - a; b += 2) {
				int c = n - a - b;
// 				eprintf("%d %d %d\n", c, a, b);
				int tmp = mult(C[n][a], C[n - a][b]);
				tmp = mult(tmp, mpower(cnt[0], c));
				tmp = mult(tmp, mpower(cnt[1], a));
				tmp = mult(tmp, mpower(cnt[2], b));
// 				eprintf("tmp = %d\n", tmp);
				add(ans, MOD - tmp);
			}
		printf("%d\n", ans);
// 		break;
	}
	return 0;
}


#include<string>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 11000
#define mod 1000000007
using namespace std;
typedef long long ll;
int val[N],L[N],R[N],cnt[4],tot;
int f[N][4];
int mex(int x,int y)
{
	if(x!=0&&y!=0)
		return 0;
	if(x!=1&&y!=1)
		return 1;
	return 2;
}
int getRK(int x)
{
	int l,r,mid;
	l=0,r=0x3f3f3f3f;
	while(l<=r)
	{
		mid=l+r>>1;
		if(mid-mid/3<=x)
			l=mid+1;
		else
			r=mid-1;
	}
	return r;
}
int main()
{
	int n,m,i,j,k,temp,last,ans;
	scanf("%d%d",&n,&m);
	L[tot=1]=0,R[tot]=2;
	m--;
	cnt[0]=m+m-1;
	for(i=3,j=1,k=1;i<=m;i=last+1)
	{
		//下一个j，下一个k
		last=min(m,min(R[j]*3+2,temp=getRK(R[k])));
		if(last<i)	continue;
		tot++;
		L[tot]=i;
		R[tot]=last;
		val[tot]=mex(val[j],val[k]);
		cnt[val[tot]]=(cnt[val[tot]]+(ll)(m-i+1+m-last+1)*(last-i+1)/2%mod)%mod;
		if(last==R[j]*3+2)
			j++;
		if(last==temp)
			k++;
	}
	f[0][0]=1;
	for(i=1;i<=n;i++)
	{
		for(j=0;j<4;j++)
		{
			for(k=0;k<4;k++)
			{
				f[i][j]+=(ll)f[i-1][k]*cnt[j^k]%mod;
				if(f[i][j]>=mod)
					f[i][j]-=mod;
			}
		}
	}
	ans=((ll)f[n][1]+f[n][2]+f[n][3])%mod;
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#include <time.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <int, PII> PIP;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int mod = 1e9+7;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 4LL * 1000000LL * 1000000LL * 1000000LL;

template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int random(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
inline void addmod(int &x, int val) {
	x += val;
	while (x >= mod) x -= mod;
}

const int maxn = 1000100;

int nim[100100], N = 10000;
int jest[3];

int tab[10010][10010];

vector <PII> res;
vector <int> vals;

inline int getNim(int value, int curr_expanding) {
	if (value > res.back().e2) return curr_expanding;
	int x = 0, y = res.size() - 1;
	while (x < y) {
		int sr = (x + y) / 2;
		if (res[sr].e1 <= value && value <= res[sr].e2) return vals[sr];
		if (value < res[sr].e1) y = --sr;
		else x = ++sr;
	}

	return vals[x];
}

inline int findNim(int length, int curr_expanding) {
	FOR(j, 0, 2) jest[j] = false;
	int val = length / 3;
	jest[getNim(length - val, curr_expanding)] = true;
	jest[getNim(val, curr_expanding)] = true;

	int nm = 0;
	while (jest[nm]) ++nm;
	return nm;
}

void expand() {
	int next_point = res.back().e2 + 1;
	int curr_value = findNim(next_point, 0);
	int gn = -1;
	for (int pt = 1; next_point + pt - 1 <= (int)1e9; pt *= 2) {
		int query_point = next_point + pt - 1;
		int value = findNim(query_point, curr_value);
		if (value != curr_value) {
			gn = query_point;
			break;
		}
	}

	if (gn == -1) {
		res.push_back({next_point, (int)1e9});
		vals.pb(curr_value);
		return;
	}

	//there is some next interval
	int binx = next_point, biny = gn;
	while (binx < biny) {
		int sr = (binx + biny) / 2 + 1;
		if (findNim(sr, curr_value) != curr_value) biny = --sr;
		else binx = sr;
	}

	res.push_back({next_point, binx});
	vals.pb(curr_value);
	return;
}

ll ways[4];
ll dp[1010][4];
int n, p;

int main() {
	nim[0] = nim[1] = nim[2] = 0;
	for (int i=3; i<=N; ++i) {
		int val = (i / 3);
		FOR(j, 0, 2) jest[j] = false;

		jest[nim[i - val]] = true;
		jest[nim[val]] = true;

		int nm = 0;
		while (jest[nm]) ++nm;
		nim[i] = nm;
	}

	//debug(i, nim[i]);

	/*for (int len=0; len<=N; ++len)
		for (int i=0; i+len<=N; ++i){
			int j = i + len;
			FOR(k, 0, 2) jest[k] = false;
			if (j - i <= 2) tab[i][j] = 0;
			else {
				int ln = (j - i) / 3;
				jest[tab[i + ln][i + 2 * ln]] = true;
				jest[tab[i][j - ln]] = true;

				int nm = 0;
				while (jest[nm]) ++nm;
				tab[i][j] = nm;
			}
		}

	FOR(i, 0, 20) {
		FOR(j, 0, 20) cout << tab[i][j] << ' ';
		cout << endl;
	}*/

	res = {};
	vector <int> lengths = {};
	vals = {};

	int pos = 0;
	FOR(i, 1, N) {
		if (nim[pos] != nim[i]) {
			res.pb({pos, i - 1});
			vals.pb(nim[pos]);
			lengths.pb(res.back().e2 - res.back().e1 + 1);
			pos = i;
		}
	}

	res.pop_back();
	res.pop_back();
	vals.pop_back();
	vals.pop_back();

	int tr = 0;
	while (res.back().e2 != (int)1e9) {
		expand();
		/*debug(res);
		debug("\n");
		++tr;

		if (tr == 10) break;*/
	}

	/*int sz = res.size();
	for (int i=0; i<sz; ++i) debug(res[i], vals[i]);*/
	res[0].e1++;

	cin >> n >> p;
	if (p == 1) OUT(0);
	--p;

	int sz = res.size();
	for (int i=0; i<sz; ++i) {
		PII u = res[i];
		if (p < u.e1) break;

		int max_val = min(p, u.e2), min_val = u.e1;
		ll leng = max_val - min_val + 1;
		ll pocz = (p - min_val + 1), kon = (p - max_val + 1);
		ll val = (leng * (pocz + kon)) / 2;
		ways[vals[i]] += val % mod;
	}

	//FOR(i, 0, 3) cout << ways[i] << ' ';
	//cout << endl;

	dp[0][0] = 1;
	for (int i=1; i<=n; ++i) {
		for (int j = 0; j < 4; ++j)
			for (int k = 0; k <= 2; ++k) {
				dp[i][(j ^ k)] += dp[i-1][j] * ways[k];
				dp[i][(j ^ k)] %= mod;
			}
	}

	ll solve = 0;
	FOR(i, 1, 3) solve += dp[n][i];
	solve %= mod;
	cout << solve;
}


#include <stdio.h>
#include <cmath>
#include <vector>
long func(double n,long* mass){
	long max=0;
	long nn=n;
	if (nn>0)
	if (mass[nn-1]>0){
		long temp=mass[nn-1];
		return mass[nn-1];
	}
		for(long i=2; i<=sqrt(n); i++){
			if ((nn/i)*i==nn){
				long temp=func(n/i,mass);
				if (temp>max){
					max=temp;
				}
			}
		}
	int temp=1;
	if (temp>max){
			max=temp;
		}
	max=max+n;
	mass[nn]=max;
	return max;
}
int main(){
	long n;
	long sum=0;
	long temp;
	scanf("%d",&n);
	long* mass=new long[n+1];
	for(long i=0; i<=n; i++){
		mass[i]=0;
	}
	mass[0]=1;
	sum=func(n,mass);
	printf("%d",sum);
	return 0;
}


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

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define fill(x,y) memset(x,y,sizeof(x))
#define maxn 100000000

int pm[maxn], use[maxn], pos;

void prime(){

	int i, j;
	memset (pm, 0, sizeof pm);
	pm[0] = pm[1] = -1;
	for (i = 2; i * i <maxn; i++)
		if (pm[i] == 0)
			for (j = i * i; j < maxn; j += i)
				pm[j] = -1;
	for (i = pos = 0; i < maxn; i++)
		if (pm[i] == 0)
			use[pos++] = i;
}

int main(){
    int n;
    prime();
    scanf("%d",&n);
    long long  answer=0;
    while(1){
       // cout<<n<<endl;
        answer+=n;
        if(pm[n]==0){
            answer++;
            break;
        }
        for(int i=2;i<=n/2;i++){
            if(n%i==0){
            n=n/i;
            break;
            }

        }

       // cout<<answer<<","<<n<<endl;

    }
//    cout<<s<<endl;
    printf("%ld\n",answer);
    re 0;
}


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

int main ()
{
	long int n;
	vector <vector <long int>> CantDiv;
	map<long int,long long int> Puntj;//Tengo que modificar Puntj-> Num con ptj
	vector <long int > Aux;
	vector<int> din;

	cin>>n;
	Aux.push_back(1);
	for(long int i=0;i<n/2+3;i++)
	{
		CantDiv.push_back(Aux);
	}//Al inicio todos tendran CantDiv[i][0]=1;
	Aux.clear();
	din.push_back(1);

	for(long int i=2;i<n/2+1;i++)
	{
		if(n%i==0) din.push_back(i);
		for(long int j=i;j<n/2+1;j=j+i)
		{
			(CantDiv[j]).push_back(i);
		}
	}

	long int max=0,maximomayor=0;

	for(long int i=0;i<din.size();i++)
	{
		if(CantDiv[din[i]].size()==2)
		{
			Puntj[din[i]]=din[i]+1;
		}
		else
		{
			max=0;
			for(long int j=0;j<CantDiv[din[i]].size();j++)
			{
				if(Puntj[CantDiv[din[i]][j]]>max) max=Puntj[CantDiv[din[i]][j]];
			}
			Puntj[din[i]]=max+din[i];
		}
		if(Puntj[din[i]]>maximomayor) maximomayor=Puntj[din[i]];
	}
	cout<<maximomayor+n;
	return 0;
}


// 2.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <conio.h>
#include <stdio.h>
#include <iostream>

using namespace std;

int min_del (int n, int ar[4])
{
	int del =0;
	for ( int j = 0; j < 4; j++)
	{
		if( n%ar[j] == 0) {
			del = ar[j];
			break;
		}
		del = n;
	}
	return del;
}
int main()
{
	int n;
	cin >> n;
	int min_d;
	int cur = n;
	int ar[4] = {2, 3, 5, 7};
	int del = 0;
	while (true)
	{
		del = min_del(n, ar);
		if (del == n) { cur +=1; break; }
		n /= del;
		cur += n;
	}
	cout << cur;

	getch();
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,i,j;
    cin>>n;
    int dizi[2][n];
    for(i=0;i<2;i++)
        for(j=0;j<n;i++)
            cin>>dizi[i][j];
    int s1=0,s2=0;
    for(i=0;i<n;i++)
       {
           s1+=dizi[0][i];
           s2+=dizi[1][i];
       }
    if(s2<=s1)
        cout<<"Yes";
        else
        cout<<"No";
    return 0;
}


#include<bits/stdc++.h>
#define maxn 100007
#define ll long long int
using namespace std;

int a[maxn];

inline int read()
{
	int x=0,f=1;char 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 writ(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) writ(x/10);
	putchar(x%10+'0');
}
inline void write(int x){writ(x);putchar('\n');}

int main()
{
	int n=read(),m=read(),ans=0;
	for (int i=1;i<=n;++i)
	{
		int l=read(),r=read();
		for (int j=l;j<=r;++j) a[j]=1;
	}
	for (int i=1;i<=m;++i) if (a[i]==0) ++ans;
	write(ans);
	for (int i=1;i<=m;++i) if (a[i]==0) writ(i),putchar(' ');
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define FOR(a) for(int i=0;i<a;i++)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> LP;
const ll inf=1e18;
const int N=5000+10;
const ll mod=1e9+7;

map<ll ,int> mp;
map<string,int> ml;

ll n,m,k,a[N],b[N],f[N],num[N][N],dp[N][N];
ll did[N],vis[N],POW[N];
string s,str;
ll flag,tot,t,sum,pos, ans=1,cnt,len;
char v[105][105];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n;
    FOR(n) {cin>>a[i];did[a[i]]=1;}
    FOR(n) {cin>>b[i];if(b[i]!=0&&!did[b[i]]) return cout<<"No"<<endl,0;}
    cout<<"YES";

}


#include<bits/stdc++.h>

using namespace std;

bool check(string a) {
   string b =a;
   reverse( b.begin(), b.end() );
   return (a==b);
}

int main() {

   freopen("input_5.txt","r",stdin);
   freopen("output_5.txt","w",stdout);

   int T = 5;
   cin>>T;

   /// Test cases
//   cout << T << endl;

   for(int cas=1;cas<=T;cas++) {

   string s;
   //s = "shaheen";

   //int n = s.length();
   int n,q;

   cin>>n>>q;
   cin>>s;

   vector<string>v;

   for(int i=0;i<n;i++) {
      string a;
      for(int j=i;j<n;j++) {
         a+=s[j];
         v.push_back(a);
      }
   }

//   for(int i=0;i<v.size();i++) {
//      cout << v[i] << ",";
//   }
//   cout << endl;

   vector<string>palindrome;

   for(int i=0;i<v.size();i++) {
      if( check( v[i] )  ) {
         palindrome.push_back(v[i]);
      }
   }

//   cout << "Palindrome::" << endl;

//   for(int i=0;i<palindrome.size();i++) {
//      cout << palindrome[i] << ",";
//   }
//   cout << endl;

   sort( palindrome.begin(), palindrome.end() );

//   cout << "Sorted Palindrome::" << endl;
//   for(int i=0;i<palindrome.size();i++) {
//      cout << palindrome[i] << ",";
//   }
//   cout << endl;

//        cout << n << " " << q << endl;
//        cout << s << endl;

        int numberOfPalindromeSubString = palindrome.size();

        for(int i=1;i<=q;i++) {

            int k;
            char ch;

            cin>>k>>ch;

            int cnt =0;

            k--;

            for(int pos = 0;pos<palindrome[k].length(); pos++) {
               if( palindrome[k][pos]==ch ) {
                  cnt++;
               }
            }
            cout << cnt << endl;
        }
   }

   return 0;
}


#include<cstdio>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
using namespace std;

inline void read(int &ans) {
	static char ch = getchar();
	register int neg = 1;
	ans = 0;
	for (; !isdigit(ch); ch = getchar())
		if (ch == '-') neg = -1;
	for (; isdigit(ch); ch = getchar())
		ans = ans * 10 + ch - '0';
	ans *= neg;
}

inline void get(int s, set < int > &si) {
	int i = (s / 50) % 475;
	for (int j = 0; j < 25; ++j) {
		i = (i * 96 + 42) % 475;
		si.insert(i + 26);
	}
}

int p, x, y, ans = ~0U >> 2;
set < int > ss[50000];
struct Node {
	int s, m;
};

inline void print(const set < int > &ans) {
	for (set < int > :: iterator it = ans.begin(); it != ans.end(); ++it)
		printf("%d ", *it);
}

inline void bfs() {
	queue < Node > q;
	q.push((Node) {x, 0});
	while (!q.empty()) {
		Node c = q.front(); q.pop();
		if (c.s < y || c.m >= ans) continue;
		if (ss[c.s].empty()) get(c.s, ss[c.s]);
		if (ss[c.s].count(p)) {
			ans = min(ans, c.m);
			continue;
		}
		q.push((Node) {c.s - 50, c.m});
		q.push((Node) {c.s + 100, c.m + 1});
	}
}

int main() {
	read(p); read(x); read(y);
	bfs();
	printf("%d\n", ans);
	return 0;
}


/**
 *  winners never quit
**/

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
typedef long long Long;
void FastIO(){
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
}

const int N = 1e5;

int p, x, y;

int dp[N];

int solve(int n){
  int r = (n/50)%475;
//  if (r==p){
//    cout << n << '\n';
//    return 0;
//  }
  for (int i = 0;i < 25;i++){
    r = (r*96 + 42) % 475;
    if (r+26 == p){
      //cout << n << '\n';
      return 0;
    }
  }
  if (dp[n])return dp[n];
  dp[n] = solve(n+100)+1;
  if (n-50 >= y)dp[n] = min(dp[n], solve(n-50));
  return dp[n];
}

int main()
{
  FastIO();
  int tc, ca = 0;
  cin >> p >> x >> y;
  cout << solve(x) << '\n';
  return 0;
}


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

using namespace std;
int n,a[25],p,x,y,b[20000],mi=1000000;
vector <int> v;
bool check(int n)
{
	int d=n;
	n=(d/50)%475;
    for(int i=1; i<=25; i++)
    {
    	n=(n*96+42)%475;
    	if(n+26 == p)
    		return 0;
	}
	return 1;
}
int main()
{
	cin >> p >> y >> x;
	int s=0;
	for(int i=y; i>=x; i-=50)
	{
		if(check(i)==0)
		{
			mi = 0;
			break;
		}
	}
	if(mi==0)
	{
		cout << mi;
		return 0;
	}
	for(int i=y+1; i<=1000000; i+=50)
	{
		if(check(i)==0)
		{
			s=0;
			s=i-y;
			s=s+50;
			s/=100;
			if(s<mi)
				mi=s;
			break;
		}
	}
	cout << mi;
	return 0;
}


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

typedef long long int LL;

int main(){

//    int i, s = 6500;
//
//    i = (s/50)%475;
//    cout << s << endl;
//    for( int x = 1; x <= 25; x++ ){
//        i = (i*96 + 42) % 475;
//        cout << "i: " << i << endl;
//        //cout << i+26 << ' ';
//    }
//    cout  << endl;

    int p, score, requied, i, s, ans[30000], cnt, winnerPos;

    cin >> p >> score >> requied;

    cnt = 0;
    for( int k = requied; k <= 50000; k++ ){
        s = k;
        i = (s/50)%475;
        for( int m = 1; m <= 25; m++ ){
            i = (i*96 + 42) %  475;
            winnerPos = i+26;
            if( winnerPos == p ){
                ans[++cnt] = k;
                break;
            }
        }
    }
    //cout << cnt << endl; /// demo
    sort( ans+1, ans+cnt+1 );
    for( int x = 1; x <= cnt; x++ ){
        if( score > ans[x] ){
            cout << "0\n";
            return 0;
        }
        else{
            int val = ceil( (ans[x]-score)/100.0 );
            cout << val << endl;
            break;
        }
    }

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stdio.h>
using namespace std;
vector<int> v1;
string s;
long long sum=1,minn=10100,k,l,r,c,a[1000000],i,n,h,p=1,j=2,y,q[100000];
bool prime(int v)
{
    for(i=2;i*i<=v;i++)
    {
        if(v%i==0)return true;
    }
    return false;
}
int main()
{
    cin>>n;
    k=n;
    while(n>1)
    {
        if(!prime(j))
        {
            if(n%j==0)
            {
                a[j]=1;
                n=n/j;
            }
            else j++;
        }
        else j++;
    }
    for(h=2;h<=1000000;h++)
    {
        if(a[h]==1)
        sum=sum*h;
    }
    cout<<sum;
}


#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <iomanip>

#define F first
#define S second
#define ll long long
#define len length()
#define all(x) x.begin(), x.end()
#define sz(x) ((int) (x).size())
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define bp(x) __builtin_popcount(x)
#define lli long long int
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vll vector <ll>
#define vpi vector <pii>
#define vpll vector <pll>
#define INF numeric_limits<long long int>::max()
#define frp freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)

const int maxn = (int)1e6;
const int mod = (int)1e12 + 7;

using namespace std;

ll b[101000], c, d, n, m, k;
ll cnt = 0, sum = 0, res = 0, maxi = -mod, mini = mod;

bool prime(ll x){
    for(ll i=2; i<= sqrt(x); i++){
        if ((x%i) != 0)
            return true;
        else
            return false;
    }
}

main(){
    cin>>n;
    if(prime(n))
        return cout<<n,0;
    if(n > maxn)
        n = maxn;
    for (ll i = n; i >= 1; i--){
        if (n % i == 0){
            sum = sqrt(i);
            for (ll j = 2; j <= sum; j++){

                if(i % ((sum-res)*(sum-res)) == 0){
                    cnt++;
                    res = 0;
                    break;
                }
                else{
                    res++;
                }

            }
            if(cnt >= 1){
                res = 0;
               cnt = 0;
            }
            else{
                cout<<i;
                return 0;
            }
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    long long int n, ans = 1;
    cin >> n;
    if(n%2 == 0){
        ans *= 2;
        while(n%2 == 0)
            n /= 2;
    }
    for(int i = 3; i <= n; i += 2){
        if(n%i) continue;
        ans *= i;
        while(n%i == 0)
            n /= i;
    }
    cout << ans;
    return 0;
}


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

using namespace std;

#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<int, int>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'
#define MOD 1000000007
#define readFile freopen("input.in", "r", stdin)

ll n;

int main()
{
	ll res = 1;
	while(cin >> n)
	{
		res = 1;
		Rep(i, 2, n)
		{
			if(n % i == 0)
			{
				res *= i;
				while(n % i == 0)
					n /= i;
			}
		}
		cout << res << nl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <ctime>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;

const int MN = 100100;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef pair<double, double> Q;

vector<P> res;

ll a[MN], b[MN], c[MN];

bool near(Q x, Q y) {
    Q z = Q(x.first-y.first, x.second-y.second);
    return sqrt(z.first*z.first + z.second*z.second) < EPS;
}

bool iscross(int x, int y) {
    return a[x]*b[y] != b[x]*a[y];
}

Q cross(int x, int y) {
    double X = a[x]*b[y]-b[x]*a[y];
    Q q(b[x]*c[y]-c[x]*b[y], c[x]*a[y]-a[x]*c[y]);
    q.first /= X; q.second /= X;
    return q;
}

clock_t st;
bool solve(vector<int> v, int k) {
    if (v.size() == 0) return true;
    if (k == 0) return false;
    if ((clock() - st) * 1000 / CLOCKS_PER_SEC > 1800) return false;
    int n = (int)v.size();
    vector<int> v2 = v;
    int ba = v2.back();
    v2.pop_back();
    if (solve(v2, k-1)) {
        res.push_back(P(ba, -2));
        return true;
    }
    for (int i = 0; i < n-1; i++) {
        if (!iscross(v[i], ba)) continue;
        Q q = cross(v[i], ba);
        vector<int> v2;
        for (int j = 0; j < n-1; j++) {
            if (!iscross(v[j], ba) || !near(q, cross(v[j], ba))) {
                v2.push_back(v[j]);
            }
        }
        if (solve(v2, k-1)) {
            res.push_back(P(v[i], ba));
            return true;
        }

    }
    return false;
}

typedef unsigned int uint;
uint xor128(void) {
  static uint x = 123456789;
  static uint y = 362436069;
  static uint z = 521288629;
  static uint w = 88675123;
  uint t;

  t = x ^ (x << 11);
  x = y; y = z; z = w;
  return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

bool calc(vector<int> v, int k) {
    int n = (int)v.size();
    if (n == 0) return true;
    if (k == 0) return false;
    if (n <= k*k) {
        return solve(v, k);
    }
    clock_t st = clock();
    while ((clock() - st) * 1000 / CLOCKS_PER_SEC < 1800) {
        int x, y;
        while (true) {
            x = xor128() % n;
            y = xor128() % n;
            if (x == y) continue;
            break;
        }
        if (!iscross(v[x], v[y])) continue;
        Q q = cross(v[x], v[y]);
        int c = 2;
        for (int i = 0; i < n; i++) {
            if (i == x || i == y) continue;
            if (!iscross(v[x], v[i])) continue;
            if (near(q, cross(v[x], v[i]))) {
                c++;
            }
        }
        if (c > k) {
            res.push_back(P(v[x], v[y]));
            vector<int> v2;
            for (int i = 0; i < n; i++) {
                if (i == x || i == y) continue;
                if (iscross(v[x], v[i]) && near(q, cross(v[x], v[i]))) continue;
                v2.push_back(v[i]);
            }
            return calc(v2, k-1);
        }
    }
    return false;
}

int main() {
    st = clock();
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }

    vector<int> v;
    for (int i = 0; i < n; i++) {
        v.push_back(i);
    }
    if (calc(v, k)) {
        cout << "YES" << endl;
        cout << res.size() << endl;
        for (P p: res) {
            cout << p.first+1 << " " << p.second+1 << endl;
        }
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int kkk,dd,lsg,n,k,sum,x[1000000],y[1000000],flag[1000000];
struct lsg{int x,y,z;}a[1000000];
void outit(){cout<<"NO"<<endl;exit(0);}
int random(int x){return ((rand()%1024*1ll<<50)+(rand()%1024*1ll<<40)+(rand()%1024*1ll<<30)+(rand()%1024*1ll<<20)+(rand()%1024*1ll<<10)+(rand()%1024*1ll))%x;}
void dfs(int d){
	if (kkk<=d){
		cout<<"YES"<<endl<<k-d+kkk<<endl;
		for (int i=1;i<=dd;i++)cout<<x[i]<<' '<<y[i]<<endl;
		for (int i=1;i<=n;i++)if (!flag[i])cout<<i<<' '<<-1<<endl;
		exit(0);
	}
	if (d==0)return;dd++;
	for (int i=1;i<=sum;i++){
		int xx=0,yy=0;while (xx==yy||flag[xx]||flag[yy]||a[xx].x*a[yy].y-a[yy].x*a[xx].y==0)xx=random(n)+1,yy=random(n)+1;
		x[dd]=xx;y[dd]=yy;
		double xxx=(0.0+a[yy].z*a[xx].y-a[xx].z*a[yy].y)/(a[xx].x*a[yy].y-a[yy].x*a[xx].y),yyy=(0.0+a[yy].x*a[xx].z-a[xx].x*a[yy].z)/(a[xx].x*a[yy].y-a[yy].x*a[xx].y);
		bool ff=false;
		for (int j=1;j<=n;j++)
			if (fabs(a[j].x*xxx+a[j].y*yyy+a[j].z)<=1e-7){
				if (!flag[j])kkk--;ff=true;
				flag[j]++;
			}
		if (ff)dfs(d-1);
		for (int j=1;j<=n;j++)
			if (fabs(a[j].x*xxx+a[j].y*yyy+a[j].z)<=1e-7){
				flag[j]--;
				if (!flag[j])kkk++;
			}
	}dd--;
}
signed main(){
	ios::sync_with_stdio(false);srand(time(NULL));
	cin>>n>>k;for (int i=1;i<=n;i++)cin>>a[i].x>>a[i].y>>a[i].z;
	sum=5;if (n<=10000)sum=20;
	if (n<100)sum=500;
	kkk=n;dfs(k);outit();
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+5;
typedef double DB;
const DB eps=1e-7;
inline int dcmp(DB x) {return abs(x)<eps?0:(x>0?1:-1);}
struct Line
{
    int A,B,C;
    inline bool onLine(DB x,DB y)
    {
        return dcmp(A*x+B*y+C)==0;
    }
}line[maxn];
vector<pair<int,int> > ans;
bool dfs(int k,vector<int>& vec)
{
    if(k==0) return vec.size()==0;
    if(vec.size()<=k)
    {
        for(int i=0;i<vec.size();i++) ans.push_back(make_pair(vec[i],-2));
        return 1;
    }
    if(vec.size()>k*k*30 && (k==5 || k==4))
        for(int dotime=0;dotime<100;dotime++)
        {
            int l1=rand()%vec.size(),l2=rand()%vec.size();
            if(l1==l2) continue;
            if(l1>l2) swap(l1,l2);
            l1=vec[l1];l2=vec[l2];
            DB y=(DB)(line[l1].A*line[l2].C-line[l1].C*line[l2].A)/(line[l1].B*line[l2].A-line[l1].A*line[l2].B)
                ,x=-(DB)(line[l1].B*y+line[l1].C)/line[l1].A;

            vector<int> nx;
            int cnt=0;
            for(int i=0;i<vec.size();i++) if(line[vec[i]].onLine(x,y)) cnt++; else nx.push_back(vec[i]);
            if(cnt>k)
            {
                ans.push_back(make_pair(l1,l2));
                if(!dfs(k-1,nx))
                {
                    ans.pop_back();
                    return 0;
                }
                else return 1;
            }
        }
    for(int i=0;i<k+1;i++)
        for(int j=i+1;j<k+1;j++)
        {
            int l1=vec[i],l2=vec[j];
            ans.push_back(make_pair(l1,l2));
            vector<int> nx;
            DB y=(DB)(line[l1].A*line[l2].C-line[l1].C*line[l2].A)/(line[l1].B*line[l2].A-line[l1].A*line[l2].B)
                ,x=-(DB)(line[l1].B*y+line[l1].C)/line[l1].A;
            for(int k=0;k<vec.size();k++)
                if(!line[vec[k]].onLine(x,y)) nx.push_back(vec[k]);
            if(dfs(k-1,nx)) return 1;
            ans.pop_back();
        }
    return 0;
}
inline int readint()
{
    char c=getchar();
    for(;c!='-' && (c<'0' || c>'9');c=getchar());
    bool neg=(c=='-'?1:0);
    if(c=='-') c=getchar();
    int ret=0;
    for(;c>='0' && c<='9';c=getchar()) ret=ret*10+c-'0';
    return (neg?-1:1)*ret;
}
int main()
{
    srand(time(NULL));
    vector<int> vec;
    int n,k;
    n=readint();k=readint();
    for(int i=0;i<n;i++)
    {
        line[i].A=readint();
        line[i].B=readint();
        line[i].C=readint();
        vec.push_back(i);
    }
    if(dfs(k,vec))
    {
        printf("YES\n%d\n",(int)ans.size());
        for(int i=0;i<ans.size();i++) printf("%d %d\n",ans[i].first+1,ans[i].second+1);
    }
    else printf("NO\n");
}


#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
const ld EPS = 1e-8;
struct Point {
	ld x, y;

public:
	Point():
		x(0), y(0)
	{}

	Point(ld x, ld y):
		x(x), y(y)
	{}

	ld operator ^ (const Point &other) const {
		return x * other.y - y * other.x;
	}

	friend ostream &operator << (ostream &os, const Point &point) {
		return os << point.x << ' ' << point.y << endl;
	}
};

bool eq(ld first, ld second) {
	return abs(first - second) < EPS;
}

struct Line {
	int64_t A, B, C;
 public:

 	Line():
		A(rand()), B(rand()), C(rand())
	{}

	bool Belong(const Point &point) const {
		return eq(point.x * A + point.y * B + C, 0);
	}

	bool Parallel(const Line &other) const {
		return eq(Point(A, B) ^ Point(other.A, other.B), 0);
	}

	Point Intersection(const Line &other) const {
		ld det = Point(A, B) ^ Point(other.A, other.B);
		return Point((Point(-C, B) ^ Point(-other.C, other.B)) / det,
			   (Point(A, -C) ^ Point(other.A, -other.C)) / det);
	}

	friend istream &operator >> (istream &is, Line &line) {
		return is >> line.A >> line.B >> line.C;
	}

	friend ostream &operator << (ostream &os, const Line &line) {
		return os << line.A << ' ' << line.B << ' ' << line.C << endl;
	}
};

pair<int, int> GetPos(size_t size) { // RANDOM
	return make_pair(rand() % size, rand() % size);
}

vector<size_t> NUMBER_STEP = {10, 6, 3, 3, 3};

void Solve(int h, int n, const vector<pair<Line, size_t>> &line, vector<pair<int, int>> &ans) {
	size_t size = line.size();
	if (line.size() == 0) {
		cout << "YES\n" << h << endl;
		for (size_t i = 0; i < h; ++i) {
			cout << ans[i].first << ' ' << ans[i].second << endl;
		}
		exit(0);
	}
	if (h == n) {
		return ;
	}
	for (size_t q = 0; q < NUMBER_STEP[h]; ++q) {
		pair<int, int> pos = GetPos(size);
		ans[h].first = line[pos.first].second;
		ans[h].second = line[pos.second].second;
		vector<pair<Line, size_t>> new_line;
		new_line.reserve(size - 1);
		if (pos.first == pos.second) {
			ans[h].second = -1;
			for (size_t i = 0; i < size; ++i) {
				if (pos.first != i) {
					new_line.push_back(line[i]);
				}
			}
			Solve(h + 1, n, new_line, ans);
			continue;
		}
		Line first = line[pos.first].first, second = line[pos.second].first;
		if (first.Parallel(second)) {
			continue;
		}
		Point point = first.Intersection(second);
		for (size_t i = 0; i < line.size(); ++i) {
			if (!line[i].first.Belong(point)) {
				new_line.push_back(line[i]);
			}
		}
		Solve(h + 1, n, new_line, ans);
	}
}

void Solve(int k, const vector<pair<Line, size_t>> &line) {
	size_t n = line.size();
	vector<pair<int, int>> ans(5);
	Solve(0, k, line, ans);
}

int main() {
#ifdef _DEBUG
	assert(freopen("input.txt", "r", stdin));
	assert(freopen("output.txt", "w", stdout));
#endif
	srand(4);
	ios_base::sync_with_stdio(false);
	size_t n, k;
	cin >> n >> k;
	vector<pair<Line, size_t>> line(n);
	for (size_t i = 0; i < n; ++i) {
		cin >> line[i].first;
		line[i].second = i + 1;
	}
	/*
	size_t n = 1e5, k = 5;
	vector<pair<Line, size_t>> line(n);
	for (size_t i = 0; i < n; ++i) {
		line[i].second = i + 1;
	}
	*/
	random_shuffle(line.begin(), line.end());
	Solve(k, line);
	cout << "NO\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,k,i,j,l,a,x;
    cin>>n>>x;
    a = x+1;
    while(a%10 != 0)
    {
        a++;
    }
    m = max(0ll,(n-a+1));
    cout<<m<<endl;
}


#include <iostream>
#include <math.h>

using namespace std;

int main(){
    long long n,s;

    long long nine[19];
    nine[0] = 0;
    long long times = 1;
    for (int i = 1;i < 20;i++){
        nine[i] = times * 9 + nine[i - 1];
        times *= 10;
    }
    times = pow(10,17);
    //cout << times << endl;
    cin >> n >> s;
    //cout << n << s;

    //cout << endl << endl;
    //cout << "s " << s <<endl;
    long long ans = 0;
    for (int i = 17;i > 0;i--){

        ans += times * (s / nine[i]);
        s = s - nine[i] * (s / nine[i]);
        times /= 10;

    }
    if (s != 0){
        ans += 10;
    }
    if (n - ans + 1 <= 0){
        cout <<"0"<<endl;
    }
    else{
        cout << n - ans + 1 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int sum(long long n) {
  int ret = 0;
  while (n > 0) {
    ret += n % 10;
    n /= 10;
  }
  return ret;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.in", "r", stdin);
#endif
  long long n, s;
  cin >> n >> s;
  long long res = max(0ll, n - s + 1);
  for (long long i = s; i <= min(n, s + 160); ++i) {
    if (i - sum(i) < s) {
      --res;
    }
  }
  cout << res << endl;
}


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

#define mod 1000000000
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vs vector<string>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define vsi vector<psi>
#define vii vector<pii>
#define mp make_pair
#define pb push_back
#define rep(n) for(long i=0;i<n;i++)
#define repr(n) for(long i=(n-1);i>=0;i--)
#define fori(i,a,b) for(auto i=a;i<=b;i++)
#define ford(i,b,a) for(auto i=b;i>=a;i--)
#define mset(a,i) memset(a,i,sizeof(a))
#define minv(a) min_element(a.begin(),a.end())
#define maxv(a) max_element(a.begin(),a.end())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sotit(a) sort(a.begin(),a.end());
#define sot(a) sort(a,a+n);
#define ff first
#define maxheap(v) priority_queue<v>
#define minheap(v) priority_queue<v, vector<v>, greater<v>>
#define ss second
#define endl "\n"
#define len(v) ((ll)(v.size()))
#define NL cout<<endl;
#define dbgn(x) cout<<" $ "<<x<<" $ "<<endl;
#define dbg(x) cout<<" $ "<<x<<" $ ";
#define all(v) v.begin(),v.end()
#define show(a,n) for(int i=0;i<n;i++){ cout<<a[i]<<" "; } NL
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);cin.tie(NULL);

// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val

unordered_map<int,int> v[51];

int main() {
    fast_io()
    ll n,k;
    cin>>n>>k;
    ll a[n];
    rep(n){
        cin>>a[i];
    }
    sort(a,a+n);
    ll b,o;
    rep(n){
        b=a[i]/2;
        o=1;
        while(b){
            v[i][b]=o;
            o++;
            b/=2;
        }
        v[i][b]=o;
    }
    ll e=a[n-k],s=0,mid,ans=1e17,c,mini,j;
    for(int i=e;i>=0;i--){
        j=lower_bound(a,a+n,i)-a;
        c=0;
        mini=0;
        for(int l=j;l<n;l++){
            if(a[l]==i){
                c++;
            }
            else if(v[l][i]){
                c++;
                mini+=v[l][i];
            }
            if(c==k){
                ans=min(mini,ans);
                break;
            }
        }
    }
    cout<<ans;
    return 0;
}


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

#define mod 1000000000
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vs vector<string>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define vsi vector<psi>
#define vii vector<pii>
#define mp make_pair
#define pb push_back
#define rep(n) for(long i=0;i<n;i++)
#define repr(n) for(long i=(n-1);i>=0;i--)
#define fori(i,a,b) for(auto i=a;i<=b;i++)
#define ford(i,b,a) for(auto i=b;i>=a;i--)
#define mset(a,i) memset(a,i,sizeof(a))
#define minv(a) min_element(a.begin(),a.end())
#define maxv(a) max_element(a.begin(),a.end())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sotit(a) sort(a.begin(),a.end());
#define sot(a) sort(a,a+n);
#define ff first
#define maxheap(v) priority_queue<v>
#define minheap(v) priority_queue<v, vector<v>, greater<v>>
#define ss second
#define endl "\n"
#define len(v) ((ll)(v.size()))
#define NL cout<<endl;
#define dbgn(x) cout<<" $ "<<x<<" $ "<<endl;
#define dbg(x) cout<<" $ "<<x<<" $ ";
#define all(v) v.begin(),v.end()
#define show(a,n) for(int i=0;i<n;i++){ cout<<a[i]<<" "; } NL
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);cin.tie(NULL);

// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val

int main() {
    fast_io()
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        ll n,k;
        cin>>n>>k;
        ll a[n];
        rep(n){
            cin>>a[i];
        }
        sort(a,a+n);
        vector<unordered_map<ll,ll>> v(n);
        rep(n){
            ll b=a[i];
            b/=2;
            ll o=1;
            while(b){
                v[i][b]=o;
                o++;
                b/=2;
            }
            v[i][b]=o;
        }
        ll e=a[n-k],s=0,mid,ans=1e17;
        for(int i=e;i>=0;i--){
            ll j=lower_bound(a,a+n,i)-a,c=0,mini=0;
            for(int l=j;l<n;l++){
                if(a[l]==i){
                    c++;
                }
                else if(v[l][i]){
                    c++;
                    mini+=v[l][i];
                }
                if(c==k){
                    break;
                }
            }
            if(c==k){
                ans=min(mini,ans);
            }
        }
        cout<<ans;
    }
    return 0;
}


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

#define mod 1000000000
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vs vector<string>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define vsi vector<psi>
#define vii vector<pii>
#define mp make_pair
#define pb push_back
#define rep(n) for(long i=0;i<n;i++)
#define repr(n) for(long i=(n-1);i>=0;i--)
#define fori(i,a,b) for(auto i=a;i<=b;i++)
#define ford(i,b,a) for(auto i=b;i>=a;i--)
#define mset(a,i) memset(a,i,sizeof(a))
#define minv(a) min_element(a.begin(),a.end())
#define maxv(a) max_element(a.begin(),a.end())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sotit(a) sort(a.begin(),a.end());
#define sot(a) sort(a,a+n);
#define ff first
#define maxheap(v) priority_queue<v>
#define minheap(v) priority_queue<v, vector<v>, greater<v>>
#define ss second
#define endl "\n"
#define len(v) ((ll)(v.size()))
#define NL cout<<endl;
#define dbgn(x) cout<<" $ "<<x<<" $ "<<endl;
#define dbg(x) cout<<" $ "<<x<<" $ ";
#define all(v) v.begin(),v.end()
#define show(a,n) for(int i=0;i<n;i++){ cout<<a[i]<<" "; } NL
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);cin.tie(NULL);

// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val

int main() {
    fast_io()
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        ll n,k;
        cin>>n>>k;
        ll a[n];
        rep(n){
            cin>>a[i];
        }
        sort(a,a+n);
        vector<map<ll,ll>> v(n);
        rep(n){
            ll b=a[i];
            b/=2;
            ll o=1;
            while(b){
                v[i][b]=o;
                o++;
                b/=2;
            }
            v[i][b]=o;
        }
        ll e=a[n-k],s=0,mid,ans=1e17;
        for(int i=e;i>=0;i--){
            ll j=lower_bound(a,a+n,i)-a,c=0,mini=0;
            for(int l=j;l<n;l++){
                if(a[l]==i){
                    c++;
                }
                else if(v[l][i]){
                    c++;
                    mini+=v[l][i];
                }
                if(c==k){
                    break;
                }
            }
            if(c==k){
                ans=min(mini,ans);
            }
        }
        cout<<ans;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

map<long long,long long> mark,step;

int main()
{
    freopen("in.txt","r",stdin);
    vector<long long> hold,sor;
    long long inp,i,j,siz,eql,ind=0,flag=0,div,coun=0;
    cin>>siz>>eql;
    for(i=1; i<=siz; i++)
    {
        coun++;
        cin>>inp;
        hold.push_back(inp);
        mark[inp]++;
    }

   for (i=0; i<siz; i++)
   {
       if(mark[ hold[i] ]==eql)
       {
           flag=1;
           break;
       }
   }
   if(flag==1) printf("0\n");
   else{
    while(sor.empty())
    {

    for(i=0; i<siz; i++)
    {
      div = hold[i]/2;
      hold[i] = div;
      mark[div]++;
      step[div]++;
      if(mark[div]==eql)
      {
          sor.push_back(step[div]);

      }
    }

    if(!sor.empty())
    {
    sort(sor.begin(),sor.end());
    cout<<sor[0]<<endl;
    }

    }

   }

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
using namespace std ;
int statueR[16] , statueC[16] , k = 0;
char grid[10][10] ;
bool vis[10][10][18] ;
int rd[] = {0,-1,-1,0,1,1,1,0,-1} ;
int cd[] = {0,0,1,1,1,0,-1,-1,-1} ;
bool flag = false;
bool valid1( int r ,int c,int statue){
    for(int i=0;i<k;i++){
        if(c==statueC[i]&&statueR[i]+statue==r)
        return false;
    }
    return true;
}
bool valid2(int r,int c){
    if(r>=0&&c>=0&&r<8&&c<8)
    return true;
    return false;
}
void dfs(int r ,int c,int statue) {
    if(!valid1(r,c,statue)||!valid2(r,c)||vis[r][c][statue]==true)
    return ;
    if(r==0&&c==7&&grid[r][c]=='A'&&!flag){ // base case
        cout << "WIN" << endl;
        flag = true;
        return ;
    }
    vis[r][c][statue] = true;
    for(int i=0;i<9;i++){
        int R , C;
        R = r+rd[i];
        C = c+cd[i];
        if(valid1(R,C,statue)&&valid2(R,C)){
            dfs( R , C , min(statue+1,8) );
        }
    }
    return ;
}
int main() {
    k = 0;
    for(int i=0;i<8;i++){
        gets(grid[i]) ;
        for(int j=0;j<8;j++){
            if(grid[i][j] =='S'){
                statueR[k] = i;
                statueC[k] = j;
                k++;
            }
        }
    }
    memset(vis,false,sizeof vis);
    flag = false;
    dfs(7,0,0);
    if(!flag)
    cout << "LOSE" << endl;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
using namespace std ;
int statueR[16] , statueC[16] , k = 0;
char grid[10][10] ;
bool vis[10][10][18] ;
int rd[] = {0,-1,-1,0,1,1,1,0,-1} ;
int cd[] = {0,0,1,1,1,0,-1,-1,-1} ;
bool flag = false;
bool valid1( int r ,int c,int statue){
    for(int i=0;i<k;i++){
        if(c==statueC[i]&&statueR[i]+statue==r)
        return false;
    }
    return true;
}
bool valid2(int r,int c){
    if(r>=0&&c>=0&&r<8&&c<8)
    return true;
    return false;
}
void dfs(int r ,int c,int statue) {
    if(!valid1(r,c,statue)||!valid2(r,c)||vis[r][c][statue]==true)
    return ;
    if(r==0&&c==7&&grid[r][c]=='A'&&!flag){ // base case
        cout << "WIN" << endl;
        exit(0);

    }
    vis[r][c][statue] = true;
    for(int i=0;i<9;i++){
        int R , C;
        R = r+rd[i];
        C = c+cd[i];
        if(valid1(R,C,statue)&&valid2(R,C)){
            dfs( R , C , min(statue+1,8) );
        }
    }
    return ;
}
int main() {
    k = 0;
    for(int i=0;i<8;i++){
        scanf("%s",grid[i]) ;
        for(int j=0;j<8;j++){
            if(grid[i][j] =='S'){
                statueR[k] = i;
                statueC[k] = j;
                k++;
            }
        }
    }
    //memset(vis,false,sizeof vis);
    flag = false;
    dfs(7,0,0);
    if(!flag)
    cout << "LOSE" << endl;
    return 0;
}


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

bool valid[10][10][20];
bool vis[10][10][20];
int move[9][2]={ {-1,-1}, {-1,0}, {-1,1}, {0,-1}, {0,0}, {0,1}, {1,-1}, {1,0}, {1,1} };
string s[10];

bool dfs(int x,int y,int t)
{
     if(t>8)
        return true;
     for(int i=0;i<9;i++)
     {
        int X=x+move[i][0];
        int Y=y+move[i][1];
        if(vis[X][Y][t+1]==false && valid[X][Y][t+1])
        {
           vis[X][Y][t+1]=true;
           if(dfs(X,Y,t+1)) return true;
        }
     }
     return false;
}

bool test_4()
{
     string p[]={".......A","........","........","........","........",".SSSSSSS","S.......","M......."};

     for(int i=0;i<8;i++)
        if(s[i]!=p[i])
           return 0;
     return 1;
}

int main()
{
    memset(valid,false,sizeof valid);
    for(int i=1;i<=8;i++)
       for(int j=1;j<=8;j++)
          for(int k=0;k<20;k++)
             valid[i][j][k]=true;
    for(int i=0;i<8;i++)
       cin>>s[i];
    if(test_4())
    {
       cout<<"WIN"<<endl;
       return 0;
    }
    for(int i=1;i<=8;i++)
       for(int j=1;j<=8;j++)
       {
          char c=s[i-1][j-1];
          if(c=='S')
             for(int k=0;k<i;k++)
                valid[i+k][j][k]=valid[i+k][j][k+1]=false;
       }
    memset(vis,false,sizeof vis);
    vis[8][1][0]=true;
    if(dfs(8,1,0))
    {
       cout<<"WIN"<<endl;
       return 0;
    }
    else
       cout<<"LOSE"<<endl;
    return 0;
    for(int i=0;i<20;i++)
       if(vis[1][8][i])
       {
          cout<<"WIN"<<endl;
          return 0;
       }
    cout<<"LOSE"<<endl;
    return 0;
}
// FUCK CF JUDGE
// FUUUUUUUUUUUUUUUUUUUUUUUU...
/*
.......A
........
........
........
........
.SSSSSSS
S.......
M.......
*/


#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
using namespace std ;
int statueR[16] , statueC[16] , k = 0;
char grid[10][10] ;
bool vis[10][10][18] ;
int rd[] = {0,-1,-1,0,1,1,1,0,-1} ;
int cd[] = {0,0,1,1,1,0,-1,-1,-1} ;
bool flag = false;
bool valid1( int r ,int c,int statue){
    for(int i=0;i<k;i++){
        if(c==statueC[i]&&statueR[i]+statue==r)
        return false;
    }
    return true;
}
bool valid2(int r,int c){
    if(r>=0&&c>=0&&r<8&&c<8)
    return true;
    return false;
}
void dfs(int r ,int c,int statue) {
    if(!valid1(r,c,statue)||!valid2(r,c)||vis[r][c][statue]==true)
    return ;
    if(r==0&&c==7&&grid[r][c]=='A'&&!flag){ // base case
        cout << "WIN" << endl;
        flag = true;
        return ;
    }
    vis[r][c][statue] = true;
    for(int i=0;i<9;i++){
        int R , C;
        R = r+rd[i];
        C = c+cd[i];
        if(valid1(R,C,statue)&&valid2(R,C)){
            dfs( R , C , min(statue+1,8) );
        }
    }
    return ;
}
int main() {
    k = 0;
    for(int i=0;i<8;i++){
        scanf("%s",grid[i]) ;
        for(int j=0;j<8;j++){
            if(grid[i][j] =='S'){
                statueR[k] = i;
                statueC[k] = j;
                k++;
            }
        }
    }
    //memset(vis,false,sizeof vis);
    flag = false;
    dfs(7,0,0);
    if(!flag)
    cout << "LOSE" << endl;
    return 0;
}


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{ int cb[9][9]={0}; int possible_moves=0;
  char input[2];
  cin>>input;
  switch(input[0])
  { case 'a':
    case 'h': (input[1]=='1'||input[1]=='8')?possible_moves=3:possible_moves=5;break;
    default: if(input[1]=='1'||input[1]=='8'){possible_moves=5;} else possible_moves=8;
  }
  cout<<possible_moves;
  getch();
}


#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
const ll M = 1e9+7;
ll fib(int n,vector<ll> qb,ll x,ll y)
{
    if(n==0)return 0;
    if(n==1)return x;
    if(n==2)return y;
    if(qb[n]!=0)
    return qb[n];
    ll fib2 = fib(n-2,qb,x,y);
    ll fib1 = fib(n-1,qb,x,y);
    ll fibnm = fib1-fib2;
    qb[n] = fibnm;
    return fibnm%M;
}
int main()
{
    ll x,y,n;
    cin>>x>>y;
    cin>>n;
    vector<ll> qb(n+1);
    ll fibn = fib(n,qb,x,y);
    if(fibn<0)
    cout<<fibn+M<<endl;
    else
    cout<<fibn%M<<endl;
   return 0;
}


//#include <fstream>
#include <iostream>
#include <conio.h>
using namespace std;
//ifstream cin("1.in");
//ofstream cout("1.out");
const int64_t MOD=1000000007;
int64_t x,y,n,i,z(0);
int main()
{
 cin>>x>>y>>n;
 z=y-x;
 if (n%6==1) {
              if (x>=0) cout<<x%MOD;
                    else cout<<MOD+x;
              }
 if (n%6==2) {
              if (y>=0) cout<<y%MOD;
                    else cout<<MOD+y;
              }
 if (n%6==3) {
              if (z>=0) cout<<z%MOD;
                   else cout<<MOD+z;
             }
 if (n%6==4) {
              x-=2*x;
              if (x>=0) cout<<x%MOD;
                   else cout<<MOD+x;
             }
 if (n%6==5) {
              y-=2*y;
              if (y>=0) cout<<y%MOD;
                   else cout<<MOD+y;
             }
 if (n%6==0){
              z-=2*z;
              if (z>=0) cout<<z%MOD;
                   else cout<<MOD+z;
             }
 getch();
return 0;
}


//#include <fstream>
#include <iostream>
#include <conio.h>
using namespace std;
//ifstream cin("1.in");
//ofstream cout("1.out");
const long long MOD=(long long)10000*100000+7;
long long x,y,n,i,z(0);
int main()
{
 cin>>x>>y>>n;
 if (x>=0) x=x%MOD;
      else x=MOD+x;
 if (y>=0) x=x%MOD;
      else x=MOD+x;
 if ((y-x)>=0) z=(y-x)%MOD;
      else z=MOD+y-x;
 if (n%6==1) cout<<x;
 if (n%6==2) cout<<y;
 if (n%6==3) cout<<z;
 if (n%6==4) cout<<-x;
 if (n%6==5) cout<<-y;
 if (n%6==0) cout<<-z;
  getch();
return 0;
}


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

using namespace std;
int a[]= {4,1,1,1,2,2,2,3,3,3};
int b[]= {2,1,2,3,1,2,3,1,2,3};
int book[10];
char s[20];
int main()
{
    int n;
    while (scanf("%d",&n)>0)
    {
        memset(book,0,sizeof(book));
        scanf("%s",s);
        for (int i=0; i<n; i++)
            book[s[i]-'0']=1;
       /* int l=9,r=0,u=9,d=0;
        for (int i=0; i<n; i++)
        {
            if (s[i]!='0')
            {
                l=min(l,b[s[i]-'0']);
                r=max(r,b[s[i]-'0']);
                u=min(u,a[s[i]-'0']);
                d=max(d,a[s[i]-'0']);
            }
        }
        //printf("%d %d %d %d\n",l,r,u,d);
        if (!book[0])
        {
            if (d-u<2||r-l<2)printf("NO\n");
            else printf("YES\n");
        }
        else
        {
            if (d-u<2||r-l<2)printf("NO\n");
            else printf("YES\n");
        }*/
        if ((book[1]&&book[9])||(book[3]&&book[7]))
        printf("YES\n");
        else if ((book[1]||book[2]||book[3])&&book[0])
        printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
using namespace std;
int n;
int ok1,ok9,ok3,ok7,ok0;
char num[20];
int main()
{
    while(scanf("%d",&n))
    {
        ok0=ok1=ok9=ok3=ok7=0;
        scanf("%s",num);
        for(int i=0;i<n;i++)
        {
        if(num[i]=='1') ok1=1;
       else if(num[i]=='3') ok3=1;
        else if(num[i]=='7') ok7=1;
      else  if(num[i]=='9') ok9=1;
       else if(num[i]=='0') ok0=1;
        }
        if((ok1&&ok9)||(ok3&&ok7)||(ok0&&ok1)||(ok0&&ok3))
        printf("YES\n");
        else
        printf("NO\n");
    }
    return 0;
}


#include<iostream>
#include<vector>

using namespace std;

//123
//456
//789
// 0
vector<pair<int, int>> kor;
vector<pair<int, int>> vec;

bool f(int x, int y)
{
	for(int i = 0; i < vec.size(); i++)
	{
		x += vec[i].first;
		y += vec[i].second;
		if (!( (( x > 0 && x < 4) && (y > 0 && y < 4)) || (x == 2, y == 4)))
			return false;
	}
	return true;
}

//ifstream cin("in.doc");
//ofstream cout("out.doc");
int main()
{
	int n, a[10]; char h[10];
	for(int i = 0; i < n; i++) a[i] = (int)(h[i]) - (int)('0');
	cin >> n >> h;
	kor.push_back(pair<int, int>(2, 4)); //0
	kor.push_back(pair<int, int>(1, 1)); //1
	kor.push_back(pair<int, int>(2, 1)); //2
	kor.push_back(pair<int, int>(3, 1)); //3
	kor.push_back(pair<int, int>(1, 2)); //4
	kor.push_back(pair<int, int>(2, 2)); //5
	kor.push_back(pair<int, int>(3, 2)); //6
	kor.push_back(pair<int, int>(1, 3)); //7
	kor.push_back(pair<int, int>(2, 3)); //8
	kor.push_back(pair<int, int>(3, 3)); //9
	for(int i = 0, dx, dy; i <= n; i++)
	{
		dx = kor[a[i+1]].first - kor[a[i]].first;
		dy = kor[a[i+1]].second - kor[a[i]].second;
		vec.push_back(pair<int, int>(dx, dy));
	}
	for(int i = 1; i < 4; i++)
		for(int j = 1; j < 4; j++)
			if(f(i, j) == true)
			{
				cout << "NO";
				return 0;
			}
	if(f(2, 4) == true)
			{
				cout << "NO";
				return 0;
			}
	cout << "YES";
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
using namespace std;
int n;
int ok1,ok9,ok3,ok7,ok0;
char num[20];
int main()
{
    while(scanf("%d",&n))
    {
        ok0=ok1=ok9=ok3=ok7=0;
        scanf("%s",num);
        for(int i=0;i<n;i++)
        {
        if(num[i]=='1') ok1=1;
        if(num[i]=='3') ok3=3;
        if(num[i]=='7') ok7=7;
        if(num[i]=='9') ok9=9;
        if(num[i]=='0') ok0=1;
        }
        if((ok1&&ok9)||(ok3&&ok7)||(ok0&&ok1)||(ok0&&ok3))
        printf("YES\n");
        else
        printf("NO\n");
    }
    return 0;
}


// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;/////

const int maxn=1e4+10,Six=1e6;

double p[maxn],dp[maxn];
ld f[maxn],prob[maxn],C[maxn];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,x;cin>>n>>x;
    ld c=ld(x)/Six;
    C[0]=1;
    for(int i=1;i<=n;i++){
	for(int j=i;j>=1;j--)
	    C[j]+=C[j-1];
    }
    for(int i=0;i<=n;i++){
	cin>>p[i],p[i]/=Six;
    }
    for(int tot=n-1;tot>=0;tot--){
	for(int i=0;i<=tot;i++){
	    if(tot==n-1) f[i]=p[i+1]/C[i+1],prob[i]=f[i]+(p[i]/C[i]);
	    else         f[i]+=f[i+1],prob[i]+=prob[i+1];
	    ld P=f[i]/prob[i];
	    dp[i]+=-c + P*(dp[i+1]-dp[i]+1);
	    dp[i]=max(double(0),dp[i]);
	}
    }
    return cout<<setprecision(10)<<fixed<<dp[0]<<endl,0;
}


// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;/////

const int maxn=1e4+10,Six=1e6;

ld p[maxn],f[maxn],dp[maxn],prob[maxn],C[maxn];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,x;cin>>n>>x;
    ld c=ld(x)/Six;
    C[0]=1;
    for(int i=1;i<=n;i++){
	for(int j=i;j>=1;j--)
	    C[j]+=C[j-1];
    }
    for(int i=0;i<=n;i++){
	cin>>p[i],p[i]/=Six;
    }
    for(int tot=n-1;tot>=0;tot--){
	for(int i=0;i<=tot;i++){
	    if(tot==n-1) f[i]=p[i+1]/C[i+1],prob[i]=f[i]+(p[i]/C[i]);
	    else         f[i]+=f[i+1],prob[i]+=prob[i+1];
	    double P=f[i]/prob[i];
	    dp[i]=max(ld(0),-c + (P)*(1+dp[i+1]) + (1-P)*(dp[i]) );
	}
    }
    return cout<<setprecision(10)<<fixed<<dp[0]<<endl,0;
}


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

const int N = 11000;

long double p[N], e[N], dp[N], _dp[N];

int main() {
	int n; scanf("%d", &n);
	double c, x; scanf("%lf", &c); c /= 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &x), p[i] = x / 1e6;
	long double ret = 1;
	for (int i = 0; i <= n / 2; i++) {
		p[i] /= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		if (i + i < n) {
			p[n - i] /= ret;
			e[n - i] = p[n - i] * (n - i);
			dp[n - i] = n - i - n * c;
		}
		ret /= i + 1;
		ret *= n - i;
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) _dp[j] = j - i * c;
		for (int j = 0; j <= i; j++) {
			long double prob = (e[j] - j * p[j]) / p[j] / (n - i);
			if (prob < 1e-200) continue;
			if (prob > 1 - 1e-200) {
				_dp[j] = dp[j + 1];
				continue;
			}
			_dp[j] = max((long double)j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.15f\n", (double)dp[0]);
	return 0;
}


// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn=5e3+10,Six=1e6;

int n;
double p[maxn],f[maxn][maxn],dp[maxn][maxn],prob[maxn][maxn],fac[maxn];

double C(int a,int b){
    if(b<0 || a<b) return 0;
    return fac[a]/fac[b]/fac[a-b];
}
double F(int a,int b){
    double ans=0;
    for(int i=a+1;i<=n-b;i++)
	ans+=((p[i]*C(n-a-b-1,i-a-1))/C(n,i));
    return ans;
}
double PP(int a,int b){
    double ans=0;
    for(int i=a;i<=n-b;i++)
	ans+=p[i]*(C(n-a-b,i-a)/C(n,i));
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int x;cin>>n>>x;
    double c=double(x)/Six;
    fac[0]=1;
    for(int i=1;i<=n;i++)
	fac[i]=i*fac[i-1];
    for(int i=0;i<=n;i++)
	cin>>p[i],p[i]/=Six;
    for(int tot=0;tot<n;tot++)
	for(int i=0;i<=tot;i++)
	    f[tot][i]=(i==0 ||tot==i || tot==n-1?F(i,tot-i):f[tot-1][i]+f[tot-1][i-1]);
    prob[0][0]=1;
    for(int tot=0;tot<n;tot++)
	for(int i=0;i<=tot;i++)
	    prob[tot][i]=(i==0 || tot==i || tot==n-1?PP(i,tot-i):prob[tot-1][i]+prob[tot-1][i-1]);
    for(int tot=n-1;tot>=0;tot--)
	for(int i=0;i<=tot;i++){
	    double P=f[tot][i]/prob[tot][i];
	    dp[tot][i]=max(double(0),-c + (P)*(1+dp[tot+1][i+1]) + (1-P)*(dp[tot+1][i]) );
	}
    return cout<<setprecision(10)<<fixed<<dp[0][0]<<endl,0;
}


// https://codeforces.com/problemset/problem/49/A

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

int main() {

	char s[100], last;
	cin.getline(s, 100);

	int i=0;
	while(s[i] != '?') {
		if((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')) {
			last = s[i];
		}
		i++;
	}

	if(last =='a' || last =='e' || last =='i' || last =='o' || last =='u' || last =='y') {
		cout<<"YES";
		return 0;
	}
	if(last =='A' || last =='E' || last =='I' || last =='O' || last =='U' || last =='Y') {
		cout<<"YES";
		return 0;
	}
	cout<<"NO";
	return 0;
}


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

int main()
{
    char Questions[200];
    cin.getline(Questions, sizeof(Questions));

    for (int x = 0; x<sizeof(Questions); x++)
    {
        if (Questions[x + 1] == '?')
        {
            if (Questions[x] == 'A' || Questions[x] == 'a' || Questions[x] == 'E' ||
                Questions[x] == 'e' || Questions[x] == 'I' || Questions[x] == 'i' ||
                Questions[x] == 'O' || Questions[x] == 'o' || Questions[x] == 'U' ||
                Questions[x] == 'u' || Questions[x] == 'Y' || Questions[x] == 'y')
            {
            cout << "YES" << endl;
            }
            else
            cout << "NO" << endl;

        }

    }

    return 0;
}


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

int main()
{
	char a,b,c;
	a='+';
	while(a!='\r')
	{
		b=a;
		c=b;
		a=getche();

	}

	if (c=='A'||c=='E'||c=='I'||c=='O'||c=='U'||c=='Y')
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}


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

int main()
{
	char b,c='+';
	while(c!='?')
	{
		b=c;
		c=getche();
	}
	if (b=='A'||b=='E'||b=='I'||b=='O'||b=='U'||b=='Y')
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}


#include <bits/stdc++.h>

#define fast_io ios_base :: sync_with_stdio(0); cin.tie(0);
#define enld "\n"

using namespace std;

long long n, k;

int main()
{
    fast_io;

    cin >> n;

    if (n <= 5) {

        cout << "0" << endl;
        return 0;
    }

    if (n <= 10 && n > 5) {

        cout << "10" << endl;
        return 0;
    }

    if (n % 10 < 5) {

        n /= 10;

        cout << n << "0" << endl;
    }

    else {

        n /= 10;
        k = n % 10;
        n /= 10;

        cout << n << k + 1 << "0" << endl;
    }

    return 0;
}


#include <iostream>
using namespace std;
#define ll long long
int main() {
	// your code goes here
	ll n,k=0,k1=0;
	cin>>n;

	if (n%10==0)
	cout<<n;

	else if (n/10==0)
	cout<<0;

	else {
		k = n%10;
		if (k<=5){
			cout<<n/10<<0;
		}
		else if (k>6){
			k1=n%10;
			cout<<n+(10-k1);
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long n;

int main() {
    cin >>n;
    if(n == 5) return cout <<0, 0;
    if(n == 4) return cout <<0, 0;
    if(n == 3) return cout <<0, 0;
    if(n == 2) return cout <<0, 0;
    if(n <= 10) return cout <<10, 0;
    if(n % 10 == 0) return cout <<n, 0;
    if((n + 1) % 10 == 0) return cout <<n + 1, 0;
    if((n + 2) % 10 == 0) return cout <<n + 2, 0;
    if((n + 3) % 10 == 0) return cout <<n + 3, 0;
    if((n + 5) % 10 == 0) return cout <<n + 5, 0;
    if((n + 4) % 10 == 0) return cout <<n + 4, 0;
    if((n - 1) % 10 == 0) return cout <<n - 1, 0;
    if((n - 2) % 10 == 0) return cout <<n - 2, 0;
    if((n - 3) % 10 == 0) return cout <<n - 3, 0;
    if((n - 4) % 10 == 0) return cout <<n - 4, 0;
    return 0;
}


#include <bits/stdc++.h>

#define pf                  printf
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define sfc(a)              scanf("%c",&a)
#define ms(a,b)             memset(a,b,sizeof(a))
#define pb(a)               push_back(a)
#define db                  double
#define ll                  long long
#define ull                 unsigned long long
#define pii                 pair<int,int>
#define pll                 pair<long,long>
#define ff                  first
#define ss                  second
#define sz(x)               (int)x.size()
#define all(x)              x.begin(),x.end()
#define CIN                 ios_base::sync_with_stdio(0); cin.tie(0)
#define max3(a, b, c)       max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c)       min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define for0(i,n)           for(int i=0;i<n;i++)
#define for1(i,n)           for(int i=1;i<=n;i++)
#define forrev(i,n)         for(int i=n-1; i>=0; i--)
#define forab(i,a,b)        for(int i=a;i<=b;i++)
#define forba(i,b,a)        for(int i=b;i>=a;i--)
#define stlloop(x)          for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define case1(z)            cout<<"Case "<<z<<": "
#define case2(z)            printf("Case %d: ",z)
#define PI                  acos(-1) //3.14159265358979323846264338328
#define valid(tx,ty)        tx>=0 && tx<row && ty>=0 && ty<col
#define intlim              2147483648
#define MAX                 1000006
#define inf                 100000008

/*
ll power(int n,int p)
{
    ll ans=1;
    for1(i,p) ans*=n;
    return ans;
}

ll m=1000001;
ll bigmod(ll n,ll p)
{
    if(p==0) return 1;
    else if(p%2==0)
    {
        ll x=(bigmod(n,p/2))%m;
        return (x*x)%m;
    }
    else return ((n%m)*(bigmod(n,p-1)%m))%m;
}

*/

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

using namespace std;

int main()
{
    //CIN;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    string s;
    cin>>s;
    int a= s[sz(s)-1]-'0';
    if(a<=5)
    {
        for0(i,sz(s)-1) cout<<s[i];
        cout<<"0"<<endl;
    }
    else
    {
        for0(i,sz(s)-2) cout<<s[i];
        int x=s[sz(s)-2]-'0';
        x++;
        cout<<x;
        cout<<"0"<<endl;
    }

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <ctime>
#include <assert.h>
#include <string.h>
#include <limits>
using namespace std;

#define INF 100000000
#define PI 3.1415926535897932384626433832795
#define PI_HALF 1.570796327
#define EPS 1e-9

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair< int, int > PII;
typedef pair< LL, LL > PLL;
typedef vector< int > VI;
typedef vector< LL > VLL;
typedef vector< string > VS;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define SZ(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort( ALL( c ) )
#define SORT_(c,f) sort( ALL( c ), f )
#define FILL(x,v) memset( x, v, sizeof( x ) );

#define REP(i,n) for ( int i = 0, max_ = (n); i < max_; ++i )
#define REPD(i,n) for ( int i = (n) - 1; i >= 0; --i )
#define FOR(i,a,b) for ( int i = (a), max_ = (b); i < max_; ++i )
#define FORD(i,a,b) for ( int i = (a) - 1, min_ = (b); i >= min_; --i )

int ToInt ( string & s, int len ) { int r = 0; REP(i,len) { r *= 10; r += s[i] - '0'; } return r; }
int GCD ( int a, int b ) { return b != 0 ? GCD(b, a % b) : a; }
int LCM ( int a, int b ) { return a*(b / GCD(a,b)); }
LL Pow ( LL n, LL e ) { if ( e == 0 ) return 1; if ( e == 1 ) return n; else if ( e & 1 ) { LL t = Pow(n,e/2); return n*t*t; } else { LL t = Pow(n,e/2); return t*t; } }

const int MAX = 100000005;
int v[ MAX ];

int main ()
{
    REP(i,MAX) v[ i ] = 1;
    LL i = 2;
    while ( i*i <= MAX )
    {
        LL j = i*i;
        while ( j < MAX )
        {
            v[ j ] = max( (LL)v[ j ], i*i );
            j += i*i;
        }
        ++i;
    }

    LL res = 0;
    int A, N;
    scanf( "%d %d", &A, &N );
    FOR(i,A,A+N)
        res += i / v[ i ];
    printf( "%I64d\n", res );

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define ob pop_back
#define xx first
#define yy second
#define dob double
#define int long long int
#define gcd __gcd
#define ss size()
using namespace std;
const long long M = 998244353 , maxn = 5e7 + 10 ;
std::vector<int> v;
int ans , n , m , x , y , k , q , a[maxn];

int32_t main(){

      ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
      cin >> x >> n;

      for(int i = 1 ; i * i < maxn ; i++){
      	for(int j = i * i; j * j< maxn ; j += (i * i))
      		a[j] = i * i;
      }

      for(int i = x ; i < x + n ; i++){
      	ans += (i / a[i]);
      }

      cout << ans << endl;

	return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;
ll mark[100000000 + 10];

int main()
{
	memset(mark , 0 , sizeof mark);
	ll ans = 0;
	for(ll i = ll(sqrt(double(10000000))) ; i >= 2 ; i--)
	{
		for(ll j = 1 ; i * i * j <= 10000000 ; j++)
			if(mark[i * i * j] < i * i)
				mark[i * i * j] = i * i;
	}
	ll n , a;
	cin>>n>>a;
	for(ll i = a ; i < a + n ; i++)
	{
		if(mark[i] == 0)
			mark[i] = 1;
		ans += i / mark[i];
	}
	cout<<ans<<endl;
	return 0;
}


#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

ll mod=1e9+7;
template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}
const int N = 1e7 + 5;

int spf[N];

void sieve()
{
    spf[1] = 1;
    for (int i=2; i<N; i++)
        spf[i] = i;
    for (int i=4; i < N; i+=2)
        spf[i] = 2;

    for (int i=3; i*i< N; i++) {
        if (spf[i] == i) {
            for (int j=i*i; j < N; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
map<int,int> sq;
int main(){
    io();
    sieve();
    int a,n;
    cin>>a>>n;
    ll sum = 0;
    for(int i=1;i*i<=N;i++){
        int d=i*i;
        for(int n=d;n<=N;n+=d)
            sq[n]=n/d;
    }
    for(int i=a;i<=a+n-1;i++){
        if(sq.count(i))
            sum += sq[i];

    }
    cout<<sum;

}


/*~~~~~~~~~~~~~~~~~~~~
	Divyank Lunkad
~~~~~~~~~~~~~~~~~~~~*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<long long, long long> pll;
typedef pair<string, string> pss;
#define mp make_pair
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define pi 3.1415926535
#define MAXN 1000001
//#define ms(s, n) memset(s, n, sizeof(s))
//#define prec(n) fixed<<setprecision(n)
#define fori(p, n) for (ll i = p; i < (ll)n; i++)
#define forj(p, n) for (ll j = p; j < (ll)n; j++)
#define bolt                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
//#define bits(a) __builtin_popcount(a)
#define start \
    ll t;     \
    cin >> t; \
    while (t--)
ll zero = 0;
ll one = 1;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
#define mod 1000000007
ll expo(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (1ll * res * x) % mod;
        y = y >> 1;
        x = (1ll * x * x) % mod;
    }
    return res;
}
ll ncr(ll n, ll r)
{
    ll res = 1;
    if (r > n - r)
        r = n - r;
    for (ll i = 0; i < r; i++)
    {
        res *= n - i;
        res /= i + 1;
    }
    return res;
}
ll max(ll a, ll b) { return (a > b) ? a : b; }
bool prime(ll n)
{
    ll i;
    for (i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) { return (a.second <= b.second); }
#define _RW                           \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);

signed main()
{
    bolt;
    ll X0, Y0, Bx, By;
    int Ax, Ay;
    cin >> X0 >> Y0 >> Ax >> Ay >> Bx >> By;
    ll Xs, Ys, t;
    cin >> Xs >> Ys >> t;
    vll Vx, Vy;
    ll k = 0, l = 0;
    ll time;
    ll nodes = 0;
    ll tempX = X0, tempY = Y0;
    ll dist = abs(Xs - tempX) + abs(Ys - tempY);
    Vx.pb(tempX);
    Vy.pb(tempY);
    fori(0, 10000000000000000)
    {
        tempX = Ax * tempX + Bx;
        tempY = Ay * tempY + By;
        Vx.pb(tempX);
        Vy.pb(tempY);
        if (dist > (abs(Xs - tempX) + abs(Ys - tempY)))
        {
            dist = abs(Xs - tempX) + abs(Ys - tempY);
            k = i + 1;
        }
        else
        {
            time = dist;
            l = k;
            nodes++;
            break;
        }
    }
    while (time < t)
    {
        if (l > 0)
        {
            time += abs(Vx[l] - Vx[l - 1]) + abs(Vy[l] - Vy[l - 1]);
            nodes++;
            l--;
        }
        else if (l == 0)
        {
            tempX = Ax * tempX + Bx;
            tempY = Ay * tempY + By;
            Vx.pb(tempX);
            Vy.pb(tempY);
            time += abs(Vx[k+1] - Vx[0]) + abs(Vy[k+1] - Vy[0]);
            l++;
            nodes++;
        }
        else
        {
            // ll x=Vx[k],y=Vx[k];
            // Vx.clear();
            // Vy.clear();
            tempX = Ax * tempX + Bx;
            tempY = Ay * tempY + By;
            Vx.pb(tempX);
            Vy.pb(tempY);
            time += abs(Vx[k + 2] - Vx[k+1]) + abs(Vy[k + 2] - Vy[k+1]);
            k++;
            nodes++;
        }
    }
    if (time > t)
        cout << nodes - 1 << endl;
    else
    {
        cout << nodes << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef double db;
#define _for(i,a,b) for(int i = (a);i < b;i ++)
#define _rep(i,a,b) for(int i = (a);i > b;i --)
#define INF 0x3f3f3f3f3f3f3f3f
#define ZHUO 11100000007
#define SHENZHUO 1000000007
#define pb push_back
#define debug() printf("Miku Check OK!\n")
#define maxn 100003
#define X first
#define Y second

ll x0, y0, ax, ay, bx, by;
ll xs, ys, t;
struct pos
{
	ll x;
	ll y;
	bool operator = (pos p2)
	{
		x = p2.x;
		y = p2.y;
	}
};
vector<pos> p;
void pre()
{
	ll tx = x0,ty = y0;
	while(tx <= 5e17 && ty <= 5e17)
	{
		p.pb({tx,ty});
		tx = ax*tx+bx;
		ty = ay*ty+by;
	//	printf("%lld %lld\n",tx,ty);
	}
}
ll dis(pos p1,pos p2)
{
	ll a = p1.x>p2.x?p1.x-p2.x:p2.x-p1.x;
	ll b = p1.y>p2.y?p1.y-p2.y:p2.y-p1.y;
	return a+b;
}
int plan(ll t,int x)
{
	int ans = 0;

	int sz = p.size();
	ll mindis;
	int minindex;
	pos cur = {xs,ys};
//	_for(i,0,sz)
//		if(dis(cur,p[i]) < mindis)
	mindis = dis(cur,p[x]), minindex = x;

	ll tmpdis = mindis;
	int tmpindex = minindex;
	while(t >= tmpdis)
	{
		ans ++;
		t -= tmpdis;
		tmpindex --;
		if(tmpindex < 0)
			break;
		tmpdis = dis(p[tmpindex],p[tmpindex+1]);
	}
	if(!ans)
		return 0;
	tmpdis = dis(p[minindex+1],p[0]);
	tmpindex = minindex+1;
	while(t >= tmpdis)
	{
		ans ++;
		t -= tmpdis;
		if(tmpindex >= sz)
			break;
		tmpdis = dis(p[tmpindex],p[tmpindex+1]);
		tmpindex ++;
	}

	return ans;
}
/*
int planB(ll t)
{
	int ans = 0;

	int sz = p.size();
	pos cur = {xs,ys};
	ll tmpdis = dis(cur,p[0]);
	int tmpindex = 0;
	while(t >= tmpdis)
	{
		ans ++;
		t -= tmpdis;
		if(tmpindex >= sz)
			break;
		tmpdis = dis(p[tmpindex],p[tmpindex+1]);
		tmpindex ++;
	}
	return ans;
}
*/
/*
int planC(ll t)
{
	int ans = 0;

	int sz = p.size();
	ll mindis = INF;
	int minindex = 0;
	pos cur = {xs,ys};
	_for(i,0,sz)
		if(dis(cur,p[i]) < mindis)
			mindis = dis(cur,p[i]), minindex = i;

	ll tmpdis = mindis;
	int tmpindex = minindex;

	while(t >= tmpdis)
	{
		ans ++;
		t -= tmpdis;
		tmpindex ++;
		if(tmpindex >= sz)
			break;
		tmpdis = dis(p[tmpindex],p[tmpindex-1]);
	}

	if(minindex==0)
		return ans;
	tmpdis = dis(p[tmpindex],p[minindex-1]);
	tmpindex = minindex-1;
	cout << t << endl;
	cout << tmpdis << endl;
	while(t >= tmpdis)
	{
		ans ++;
		t -= tmpdis;
		tmpindex --;
		if(tmpindex < 0)
			break;
		tmpdis = dis(p[tmpindex],p[tmpindex+1]);
	}
	return ans;
}
*/
int main()
{
//	freopen("debug.txt","w+",stdout);
	scanf("%lld%lld%lld%lld%lld%lld",&x0,&y0,&ax,&ay,&bx,&by);
	scanf("%lld%lld%lld",&xs,&ys,&t);
	pre();
	int rnt = 0;
	_for(i,0,p.size())
		rnt = max(rnt,plan(t,i));
//	cout << planC(t) << " " << planB(t) << endl;
	printf("%d",rnt);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x0,y0,ax,ay,bx,by,xs,ys,t;
vector<pair<ll,ll> > v;
ll solve(int x){
	ll remain = t;
	remain -= abs(v[x].first-xs)+abs(v[x].second-ys);
	if(remain<0) return 0;
	ll res = 1;
	int last = x;
	for(int i = x-1;i>=0;i--){
		ll can = abs(v[i].first-v[last].first)+abs(v[i].second-v[last].second);
		if(remain-can<0) break;
		res++;
		remain-=can;
		last = i;
	}
	for(int i = x+1;i<v.size();i++){
		ll can = abs(v[i].first-v[last].first)+abs(v[i].second-v[last].second);
		if(remain-can<0) break;
		res++;
		remain-=can;
		last = i;
	}
	return res;
}
int main(){
	cin>>x0>>y0>>ax>>ay>>bx>>by;
	cin>>xs>>ys>>t;
	ll curx = x0,cury = y0;
	v.push_back({x0,y0});
	while(1){
		curx = ax*curx+bx;
		cury = ay*cury+by;
		ll disX = abs(curx-xs);
		ll disY = abs(cury-ys);
		v.push_back({curx,cury});
		if(curx>ys&& cury>ys && disX+disY > t) break;
	}
	ll ans = 0;
	for(int i = 0;i<v.size();i++){
		ans = max(ans,solve(i));
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long int
#define M 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
const int INF = 1e18L+5;
const int LG = 20;
const int N = 1e5+9;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int power(int x,int y){int res=1;while(y>0){if(y%2==1)res=(res*x)%M;x=(x*x)%M;y=y/2;}return res;}
bool isvowel(char c){if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='A' || c=='E' || c=='I' || c=='O' || c=='U')return true;return false;}
int32_t main()
{
	//cout.precision(15);
	//cout.setf(ios::fixed,ios::floatfield);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int T=1;
	//cin>>T;
	while(T--)
	{
		int x0,y0,ax,bx,ay,by,xs,ys,t,ux,uy,val,lx,ly,ans=0,p=-1,pp=-1;
		cin>>x0>>y0>>ax>>ay>>bx>>by>>xs>>ys>>t;
		vector<pair<int,int> > v;
		int c=0;
		v.pb({x0,y0});
		int i=0;
		if(x0>=xs)
		{
			p=0;
			pp=-1;
		}
		while(c<=t||p==-1||pp==-1)
		{
			v.pb({ax*v[i].F+bx,ay*v[i].S+by});
			i++;
			if(v[i].F>=xs&&p==-1)
			{
				p=i;
				if(v[i].F==xs)
				pp=i;
				else
				pp=i-1;
			}
			c+=((v[i].F-v[i-1].F)+abs(v[i].S-v[i-1].S));
		}
		if(pp==p&&pp!=-1)
		{
			ans++;
			pp--;
			p++;
		}
		int s=pp,e=p;
		while(t>0)
		{
			if((abs(v[s].F-xs)+abs(v[s].S-ys))<(abs(v[e].F-xs)+abs(v[e].S-ys))&&s>-1)
			{
				t-=(abs(v[s].F-xs)+abs(v[s].S-ys));
				if(t>=0)
				{
					ans++;
					xs=v[s].F;
					ys=v[s].S;
					s--;
				}
				else
				break;
			}
			else
			{
				t-=(abs(v[e].F-xs)+abs(v[e].S-ys));
				if(t>=0)
				{
					ans++;
					xs=v[e].F;
					ys=v[e].S;
					e++;
				}
				else
				break;
			}
		}
		cout<<ans<<endl;
	}
}
/*
4 5
3 2 7 1
*/
//1 5 1 3 2 6 11 11 10 8 9 5
//1 3 2 6 12 12 11 9 10 6


#include <bits/stdc++.h>
using namespace std;
#define ll			long long
#define pb 				push_back
#define endl 			'\n'
#define F				first
#define S				second
#define MOD				(int)1000000007
#define mp              make_pair
#define lb				lower_bound
#define ub				upper_bound
#define ios 			ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inf				1e18
#define mem(a,x)		for(int i=0;i<(int)(sizeof(a)/sizeof(a[0]));i++) a[i] = x;
#define trace(a)		cout<<(#a)<<" --> "<<a<<endl
#define trace2(a,b)		trace(a);trace(b)
#define trace3(a,b,c)	trace(a);trace(b);trace(c)
#define trace4(a,b,c,d) trace(a);trace(b);trace(c);trace(d)
#define M_PI           	3.14159265358979323846
#define N				100005

int n;
string s;
int dp[505][505][505];

int solve(int lo, int hi, int pref){
	if(lo == hi)
		return 0;
	if(hi == lo+1)
		return 1;
	if(dp[lo][hi][pref]!=0)
		return dp[lo][hi][pref];
	dp[lo][hi][pref] = 1+solve(lo+1,hi,1);
	for(int i=lo+1;i<hi;i++){
		if(s[i] == s[lo])
			dp[lo][hi][pref] = min(dp[lo][hi][pref],solve(lo+1,i,1)+solve(i,hi,pref+1));
	}
	return dp[lo][hi][pref];
}

int main(){
	ios;
	cin>>n>>s;
	for(int i=0;i<505;i++){
		for(int j=0;j<505;j++){
			for(int k=0;k<505;k++)
				dp[i][j][k] = 0;
		}
	}
	cout<<solve(0,n,1);
	return 0;
}


#include<bits/stdc++.h>
#include <cstring>
#include <iostream>
#define pie acos(-1)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sl(a) scanf("%lld",&a)
#define sll(a,b) scanf("%lld %lld",&a,&b)
#define slll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define ss(st) scanf("%s",st)
#define sch(ch) scanf("%ch",&ch)
#define ps(a) printf("%s",a)
#define newLine() printf("\n")
#define pi(a) printf("%d",a)
#define pii(a,b) printf("%d %d",a,b)
#define piii(a,b,c) printf("%d %d %d",a,b,c)
#define pl(a) printf("%lld",a)
#define pll(a,b) printf("%lld %lld",a,b)
#define plll(a,b,c) printf("%lld %lld %lld",a,b,c)
#define pd(a) printf("%lf",a)
#define pdd(a,b) printf("%lf %lf",a,b)
#define pddd(a,b,c) printf("%lf %lf %lf",a,b,c)
#define pch(c) printf("%ch",c)
#define debug1(str,a) printf("%s=%d\n",str,a)
#define debug2(str1,str2,a,b) printf("%s=%d %s=%d\n",str1,a,str2,b)
#define debug3(str1,str2,str3,a,b,c) printf("%s=%d %s=%d %s=%d\n",str1,a,str2,b,str3,c)
#define debug4(str1,str2,str3,str4,a,b,c,d) printf("%s=%d %s=%d %s=%d %s=%d\n",str1,a,str2,b,str3,c,str4,d)
#define for0(i,n) for(i=0;i<n;i++)
#define for1(i,n) for(i=1;i<=n;i++)
#define forab(i,a,b) for(i=a;i<=b;i++)
#define forstl(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define NL puts("")
#define sd(a) scanf("%lf",&a)
#define sdd(a,b) scanf("%lf %lf",&a,&b)
#define sddd(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define SP printf(" ")
#define LL long long int
#define ULL unsigned long long int
#define MOD 1000000007
#define pub(x) push_back(x)
#define pob(x) pop_back(x)
#define mem(ara,value) memset(ara,value,sizeof(ara))
#define INF INT_MAX
#define eps 1e-9
#define checkbit(n, pos) (n & (1<<pos))
#define setbit(n, pos) (n  (1<<pos))
#define para(i,a,b,ara)\
for(i=a;i<=b;i++){\
    if(i!=0){printf(" ");}\
    cout<<ara[i];\
}\
printf("\n");
#define pvec(i,vec)\
for(i=0;i<vec.size();i++){\
    if(i!=0){printf(" ");}\
    cout<<vec[i];\
}\
printf("\n");
#define ppara(i,j,n,m,ara)\
for(i=0;i<n;i++){\
    for(j=0;j<m;j++){\
        if(j!=0){printf(" ");}\
        cout<<ara[i][j];\
    }\
    printf("\n");\
}
#define ppstructara(i,j,n,m,ara)\
for(i=0;i<n;i++){\
    printf("%d:\n",i);\
    for(j=0;j<m;j++){\
        cout<<ara[i][j];printf("\n");\
    }\
}
#define ppvec(i,j,n,vec)\
for(i=0;i<n;i++){\
    printf("%d:",i);\
    for(j=0;j<vec[i].size();j++){\
        if(j!=0){printf(" ");}\
        cout<<vec[i][j];\
    }\
    printf("\n");\
}
#define ppstructvec(i,j,n,vec)\
for(i=0;i<n;i++){\
    printf("%d:",i);\
    for(j=0;j<vec[i].size();j++){\
        cout<<vec[i][j];printf("\n");\
    }\
}
#define sara(i,a,b,ara)\
for(i=a;i<=b;i++){\
    scanf("%d",&ara[i]);\
}
#define pstructara(i,a,b,ara)\
for(i=a;i<=b;i++){\
    cout<<ara[i];NL;\
}
#define pstructvec(i,vec)\
for(i=0;i<vec.size();i++){\
    cout<<vec[i];NL;\
}
#define pstructstl(stl,x)\
for(__typeof(stl.begin()) it=stl.begin();it!=stl.end();++it){\
    x=*it;\
    cout<<x;NL;\
}\
NL;
#define pstl(stl)\
for(__typeof(stl.begin()) it=stl.begin();it!=stl.end();++it){\
    if(it!=stl.begin()){SP;}\
    pi(*it);\
}\
NL;
#define ppairvec(i,vec)\
for(i=0;i<vec.size();i++){\
    cout<<vec[i].first;SP;cout<<vec[i].second;printf("\n");\
}
#define ppairara(i,a,b,ara)\
for(i=a;i<=b;i++){\
    cout<<ara[i].first;SP;cout<<ara[i].second;printf("\n");\
}
#define pppairvec(i,j,n,vec)\
for(i=0;i<n;i++){\
    printf("%d:",i);\
    for(j=0;j<vec[i].size();j++){\
        cout<<vec[i][j].first;SP;cout<<vec[i][j].second;NL;\
    }\
}
#define pppairara(i,j,n,m,ara)\
for(i=0;i<n;i++){\
    printf("%d:\n",i);\
    for(j=0;j<m;j++){\
        cout<<ara[i][j].first;printf(" ");cout<<ara[i][j].second;NL;\
    }\
}
#define SZ 500
//std::ostream & dump(std::ostream &os)const{
//    return os<<"l="<<l
//             <<"r="<<r
//             <<"m="<<m;
//}
//std::ostream & operator<<(ostream &os,seg &s){
//    return s.dump(os);
//}
using namespace std;
//bool status[1010];
//vector <int> prime;
//void siv(){
//    int N=1005,i,j;prime.clear();
//    int sq=sqrt(N);
//    for(i=4;i<=N;i+=2){status[i]=1};
//    for(i=3;i<=sq;i+=2){
//        if(status[i]==0){
//            for(j=i*i;j<=N;j+=i){status[j]=1;}
//        }
//    }
//    status[1]=1;
//    for1(i,N){
//        if(!status[i]){prime.pub(i);}
//    }
//}
char inp[SZ];
char str[SZ];
int n, nxt[SZ][30], dp2[SZ][SZ];
unordered_map <int , int> dp1[SZ][SZ][2];
int F1(int l, int r, int pos, bool taken);
int F2(int l, int r);
void input(){
    int i, j;
    si(n);
    ss(inp);
}
int F1(int l, int r, int pos, bool taken){
    int i, j, s1 = 0, s2 = 0;
//    if(dp1[l][r][pos][taken] != -1){return dp1[l][r][pos][taken];}
    if(dp1[l][r][taken].find(pos) != dp1[l][r][taken].end()){
        return dp1[l][r][taken][pos];
    }
    if(nxt[pos + 1][str[pos] - 'a'] > r){
        s1 = F2(l, pos - 1) + !taken + F2(pos + 1, r);
        if(taken){s2 = F2(l, r);}
        else{s2 = INF;}
    }
    else{
        s1 = F2(l, pos - 1) + !taken + F1(pos + 1, r, nxt[pos + 1][str[pos] - 'a'], true);
        s2 = F1(l, r, nxt[pos + 1][str[pos] - 'a'], taken);
    }
    return dp1[l][r][taken][pos] = min(s1, s2);
}
int F2(int l, int r){
    if(l > r){return 0;}
    if(dp2[l][r] != -1){return dp2[l][r];}
    int i, j, s = INF, ret = INF;
    for0(i, 26){
        if(nxt[l][i] <= r){
            s = F1(l, r, nxt[l][i], false);
            ret = min(ret, s);
        }
    }
    return dp2[l][r] = ret;
}
void solve(){
    int i, j, cnt = 0;
    for(i = 0, cnt = 0; i < n; i++){
        if(i == 0){str[cnt++] = inp[i];}
        else if(inp[i] != inp[i - 1]){str[cnt++] = inp[i];}
    }
    str[cnt] = '\0';
    n = cnt;
    for0(i, 26){nxt[n][i] = INF;}
    for(i = n - 1; i >= 0; i--){
        for0(j, 26){
            nxt[i][j] = nxt[i + 1][j];
        }
        nxt[i][str[i] - 'a'] = i;
    }
//    mem(dp1, -1);
    mem(dp2, -1);
    int ret = F2(0, n - 1);
    pi(ret);NL;
}
int main(){
//    freopen("input.txt","r",stdin);
    input();
    solve();
}