#include <set>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const double eps = 1e-2, inf = 11111111;

struct point
{
    double x, y;
    void read() {
        cin >> x >> y;
    }
    void write() {
        cout << x << ' ' << y;
    }
    point operator - (point a) {
        point ret;
        ret.x = x - a.x;
        ret.y = y - a.y;
        return ret;
    }
    point operator + (point a) {
        point ret;
        ret.x = x + a.x;
        ret.y = y + a.y;
        return ret;
    }
    point operator * (int a)
    {
        point ret;
        ret.x = x * a;
        ret.y = y * a;
        return ret;
    }
    point operator / (int a) {
        point ret;
        ret.x = x / a;
        ret.y = y / a;
        return ret;
    }
};

struct line {
    double A, B, C;
    void write() {
        cout << A << ' ' << B << ' ' << C;
    }
};

point make_point(double x, double y) {
    point ret;
    ret.x = x;
    ret.y = y;
    return ret;
}

line get_line(point a, point b) {
    line ret;
    ret.A = a.y - b.y;
    ret.B = b.x - a.x;
    ret.C = -ret.A * a.x - ret.B * a.y;
    return ret;
}

point p_line(line a, line b) {
    point ret;
    if (fabs(a.A * b.B - b.A * a.B) <= eps) {
        ret.x = -inf;
        ret.y = -inf;
        return ret;
    }
    ret.y = (b.A * a.C - a.A * b.C) / (a.A * b.B - b.A * a.B);
    ret.x = (b.C * a.B - b.B * a.C) / (a.A * b.B - b.A * a.B);
    return ret;
}

double cross_pr(point a, point b) {
    return a.x * b.x + a.y * b.y;
}

double dist(point a) {
    return sqrt(a.x * a.x + a.y * a.y);
}

double dist(point a, point b) {
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

double dist(point a, line b) {
    return fabs((b.A * a.x + b.B * a.y + b.C) / sqrt(b.A * b.A + b.B * b.B));
}

double ang(point a, point b) {
    return acos(cross_pr(a, b) / dist(a) / dist(b));
}

bool is_in(point a, point b, point c) {
    return fabs(dist(a, b) - dist(a, c) - dist(b, c)) <= eps;
}

bool per_otr(point a, point b, point c, point d) {
    if (is_in(a, b, c) || is_in(a, b, d) || is_in(c, d, a) || is_in(c, d, b)) {
        return true;
    }
    line l = get_line(a, b), l1 = get_line(c, d);
    point ans = p_line(l, l1);
    if (ans.x == -inf && ans.y == -inf) {
        return false;
    }
    if (is_in(a, b, ans) && is_in(c, d, ans)) {
        return true;
    }
    return false;
}

bool one_polypl(point a, point b, point c, point d) {
    line l = get_line(a, b), l1 = get_line(c, d);
    point ans = p_line(l, l1);
    if (ans.x == -inf && ans.y == -inf) {
        return true;
    }
    if (is_in(a, b, ans)) {
        return false;
    }
    return true;
}

point v, p, w1, w2, z1, z2;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    v.read();
    p.read();
    w1.read();
    w2.read();
    z1.read();
    z2.read();
    if (!per_otr(v, p, w1, w2) && !per_otr(v, p, z1, z2)) {
        cout << "YES" << endl;
        return 0;
    }
    if (!one_polypl(v, p, z1, z2)) {
        cout << "NO";
        return 0;
    }
    if (z1.x > z2.x) {
        swap(z1, z2);
    }
    line l = get_line(z1, z2);
    if (z1.x == z2.x) {
        if (z1.y > z2.y) {
            swap(z1, z2);
        }
        for (double y = z1.y; y <= z2.y; y += eps) {
            double x = z1.x;
            point z = make_point(x, y);
            if (fabs(ang(z1 - z, v - z) - ang(z2 - z, p - z)) <= eps) {
                if (!per_otr(v, z, w1, w2) && !per_otr(p, z, w1, w2)) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
        cout << "NO" << endl;
    } else {
        for (double x = z1.x; x <= z2.x; x += eps) {
            double y = (-l.C - l.A * x) / l.B;
            point z = make_point(x, y);
            if (fabs(ang(z1 - z, v - z) - ang(z2 - z, p - z)) <= eps || fabs(ang(z2 - z, v - z) - ang(z1 - z, p - z)) <= eps || fabs(ang(z1 - z, v - z) - ang(z1 - z, p - z)) <= eps || fabs(ang(z2 - z, v - z) - ang(z2 - z, p - z)) <= eps) {
                if (!per_otr(v, z, w1, w2) && !per_otr(p, z, w1, w2)) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
        cout << "NO" << endl;
    }
    return 0;
}


#include <algorithm>

#include <cinttypes>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>

struct point { double x, y; };
struct line { point a, b; };

static double dot(const point &a, const point &b) { return a.x*b.x + a.y*b.y; }

static double mag(const point &p) { return std::sqrt(dot(p, p)); }

static point operator-(const point &a, const point &b)
{ return { a.x - b.x, a.y - b.y }; }

static point operator+(const point &a, const point &b)
{ return { a.x + b.x, a.y + b.y }; }

static point operator*(const double s, const point &p)
{ return { s*p.x, s*p.y }; }

static bool line_intersection(const line &u, const line &v)
{
	/* Solve [ a b ; c d ] [ s ; t ] = [ p ; q ]. */
	const double a = u.b.x - u.a.x, b = v.a.x - v.b.x;
	const double c = u.b.y - u.a.y, d = v.a.y - v.b.y;
	const double p = v.a.x - u.a.x, q = v.a.y - u.a.y;
	const double det = a * d - b * c;
	const double s =  d * p + -b * q;
	const double t = -c * p +  a * q;
	return det < 0 ? det <= 0 && s <= 0 && det <= t && t <= 0 :
	       det > 0 ? 0 <= s && s <= det && 0 <= t && t <= det : false;
}

static double angle_over_line(const point &p, const double s, const line &m)
{
	const point u = m.b - m.a, v = p - m.a - s*(m.b - m.a);
	return dot(u, v) / mag(u) / mag(v);
}

static bool reflection(const double a, const double b,
	const point &u, const point &v, const line &m, point *p)
{
	const double e = 1e-12;
	const double c = (b - a)/2.0;
	const double wa = angle_over_line(u, a, m) + angle_over_line(v, a, m);
	const double wc = angle_over_line(u, c, m) + angle_over_line(v, c, m);
	const double wb = angle_over_line(u, b, m) + angle_over_line(v, b, m);
	const double d = (0.0 < wa ? -1.0 : 1.0);

	if (b - a < e || std::abs(wc) < e) {
		if (p != nullptr) *p = m.a + c*(m.b - m.a);
		return true;
	}

	return d*wa <= e && -e <= d*wc ? reflection(a, c, u, v, m, p) :
	       d*wc <= e && -e <= d*wb ? reflection(c, b, u, v, m, p) : false;
}

static bool reflection(const point &u, const point &v, const line &m, point *p)
{
	return reflection(0.0, 1.0, u, v, m, p);
}

int main(int argc, char *argv[])
{
	point v, p;
	line w, m;

	if (fscanf(stdin, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
		&v.x, &v.y, &p.x, &p.y,
		&w.a.x, &w.a.y, &w.b.x, &w.b.y,
		&m.a.x, &m.a.y, &m.b.x, &m.b.y) != 12) {
		fprintf(stderr, "fscanf: Coordinate IO error.\n");
		exit(EXIT_FAILURE);
	}

	point r;
	const bool d = !line_intersection({ p, v }, w) &&
	     	       !line_intersection({ p, v }, m);
	const bool i = reflection(v, p, m, &r) &&
		       !line_intersection({ p, r }, w) &&
		       !line_intersection({ v, r }, w) &&
	     	       !line_intersection({ p, v }, m);

	puts(d || i ? "YES" : "NO");

	return EXIT_SUCCESS;
}


#include <set>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const double eps = 0.008, inf = 11111111;

struct point
{
    double x, y;
    void read() {
        cin >> x >> y;
    }
    void write() {
        cout << x << ' ' << y;
    }
    point operator - (point a) {
        point ret;
        ret.x = x - a.x;
        ret.y = y - a.y;
        return ret;
    }
    point operator + (point a) {
        point ret;
        ret.x = x + a.x;
        ret.y = y + a.y;
        return ret;
    }
    point operator * (int a)
    {
        point ret;
        ret.x = x * a;
        ret.y = y * a;
        return ret;
    }
    point operator / (int a) {
        point ret;
        ret.x = x / a;
        ret.y = y / a;
        return ret;
    }
};

struct line {
    double A, B, C;
    void write() {
        cout << A << ' ' << B << ' ' << C;
    }
};

point make_point(double x, double y) {
    point ret;
    ret.x = x;
    ret.y = y;
    return ret;
}

line get_line(point a, point b) {
    line ret;
    ret.A = a.y - b.y;
    ret.B = b.x - a.x;
    ret.C = -ret.A * a.x - ret.B * a.y;
    return ret;
}

point p_line(line a, line b) {
    point ret;
    if (fabs(a.A * b.B - b.A * a.B) <= eps) {
        ret.x = -inf;
        ret.y = -inf;
        return ret;
    }
    ret.y = (b.A * a.C - a.A * b.C) / (a.A * b.B - b.A * a.B);
    ret.x = (b.C * a.B - b.B * a.C) / (a.A * b.B - b.A * a.B);
    return ret;
}

double cross_pr(point a, point b) {
    return a.x * b.x + a.y * b.y;
}

double dist(point a) {
    return sqrt(a.x * a.x + a.y * a.y);
}

double dist(point a, point b) {
    return ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

double dist(point a, line b) {
    return fabs((b.A * a.x + b.B * a.y + b.C) / sqrt(b.A * b.A + b.B * b.B));
}

double dist1(point a, point b) {
    return ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

double ang(point a, point b) {
    return acos(cross_pr(a, b) / dist(a) / dist(b));
}

bool is_in(point a, point b, point c) {
    /*a.write();
    cout << ' ';
    b.write();
    cout << ' ';
    c.write();
    cout << " = " << fabs(dist(a, b) - dist(a, c) - dist(b, c)) << endl;*/
    double x = dist1(a, b), y = dist1(a, c), z = dist1(b, c);
    return fabs(x - y - z - 2 * sqrt(y * z)) <= eps;
}

bool per_otr(point a, point b, point c, point d) {
    if (is_in(a, b, c) || is_in(a, b, d) || is_in(c, d, a) || is_in(c, d, b)) {
        return true;
    }
    line l = get_line(a, b), l1 = get_line(c, d);
    point ans = p_line(l, l1);
    if (ans.x == -inf && ans.y == -inf) {
        return false;
    }
    if (is_in(a, b, ans) && is_in(c, d, ans)) {
        return true;
    }
    return false;
}

bool one_polypl(point a, point b, point c, point d) {
    line l = get_line(a, b), l1 = get_line(c, d);
    point ans = p_line(l, l1);
    if (ans.x == -inf && ans.y == -inf) {
        return true;
    }
    if (is_in(a, b, ans)) {
        return false;
    }
    return true;
}

point v, p, w1, w2, z1, z2;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    v.read();
    p.read();
    w1.read();
    w2.read();
    z1.read();
    z2.read();
    if (!per_otr(v, p, w1, w2) && !per_otr(v, p, z1, z2)) {
        cout << "YES" << endl;
        return 0;
    }
    if (!one_polypl(v, p, z1, z2)) {
        cout << "NO";
        return 0;
    }
    if (z1.x > z2.x) {
        swap(z1, z2);
    }
    line l = get_line(z1, z2);
    if (z1.x == z2.x) {
        if (z1.y > z2.y) {
            swap(z1, z2);
        }
        for (double y = z1.y; y <= z2.y; y += eps) {
            double x = z1.x;
            point z = make_point(x, y);
            if (fabs(ang(z1 - z, v - z) - ang(z2 - z, p - z)) <= eps) {
                if (!per_otr(v, z, w1, w2) && !per_otr(p, z, w1, w2)) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
        cout << "NO" << endl;
    } else {
        for (double x = z1.x; x <= z2.x; x += eps) {
            double y = (-l.C - l.A * x) / l.B;
            point z = make_point(x, y);
            if (fabs(ang(z1 - z, v - z) - ang(z2 - z, p - z)) <= eps || fabs(ang(z2 - z, v - z) - ang(z1 - z, p - z)) <= eps || fabs(ang(z1 - z, v - z) - ang(z1 - z, p - z)) <= eps || fabs(ang(z2 - z, v - z) - ang(z2 - z, p - z)) <= eps) {
                if (!per_otr(v, z, w1, w2) && !per_otr(p, z, w1, w2)) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
        cout << "NO" << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define FOR(a,b,c) for (int a=b,_c=c;a<=_c;a++)
#define FORD(a,b,c) for (int a=b;a>=c;a--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; ++i)
#define REPD(i,a) for(int i=(a)-1; i>=0; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
#define reset(a,b) memset(a,b,sizeof(a))
#define oo 1000000007

using namespace std;

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

bool equal(double a, double b){
    return fabs(a-b)<1e-9;
}

bool bigger(double a, double b){
    return (!equal(a,b) && a>b);
}

bool smaller(double a, double b){
    return (!equal(a,b) && a<b);
}

//long long

ll dis(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3){
    ll vx=y1-y2;
    ll vy=x2-x1;
    return vx*(x3-x1)+vy*(y3-y1);
}

bool khacphia(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3, ll x4, ll y4){
    ll t1=dis(x1,y1,x2,y2,x3,y3);
    ll t2=dis(x1,y1,x2,y2,x4,y4);
    if(t1>1) t1=1; if(t1<-1) t1=-1;
    if(t2>1) t2=1; if(t2<-1) t2=-1;
    return t1*t2<=0;
}

bool catnhau(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3, ll x4, ll y4){
    return khacphia(x1,y1,x2,y2,x3,y3,x4,y4) && khacphia(x3,y3,x4,y4,x1,y1,x2,y2);
}

bool songsong(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3, ll x4, ll y4){
    ll vx1=x2-x1, vy1=y2-y1, vx2=x4-x3, vy2=y4-y3;
    return vx1*vy2==vx2*vy1;
}

// double
double dis(double x1, double y1, double x2, double y2, double x3, double y3){
    double vx=y1-y2;
    double vy=x2-x1;
    return vx*(x3-x1)+vy*(y3-y1);
}

bool khacphia(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4){
    double t1=dis(x1,y1,x2,y2,x3,y3);
    double t2=dis(x1,y1,x2,y2,x4,y4);
    if(t1>1) t1=1; if(t1<-1) t1=-1;
    if(t2>1) t2=1; if(t2<-1) t2=-1;
    return !bigger(t1*t2,0.0);
}

bool dcatnhau(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4){
    return khacphia(x1,y1,x2,y2,x3,y3,x4,y4) && khacphia(x3,y3,x4,y4,x1,y1,x2,y2);
}

//-----------------------------------------------------------------------

double giaihpt(double a1, double b1, double c1, double a2, double b2, double c2, double &X, double &Y){
    double d=a1*b2-a2*b1;
    double dx=b1*c2-b2*c1;
    double dy=c1*a2-c2*a1;
    X=dx/d; Y=dy/d;
}

double hinhchieu(double x1, double y1, double x2, double y2, double x0, double y0, double &X, double &Y){
    double vx=y1-y2;
    double vy=x2-x1;
    giaihpt(vx,vy,-x1*vx-y1*vy,vy,-vx,-x0*vy+y0*vx,X,Y);
}

double I1,J1,I2,J2,xx,yy;
ll xv,yv,xp,yp;

double cal(double val, double len){
    double vx,vy,l1,l2;
    vx=I2-I1; vy=J2-J1;
    xx=vx*val/len+I1; yy=vy*val/len+J1;
    l1=hypot(xv-xx,yv-yy);
    l2=hypot(xp-xx,yp-yy);
    return val/l1-(len-val)/l2;
}

#include <conio.h>
int main(){
    freopen("test.txt","r",stdin);

    ll x1,y1,x2,y2,x3,y3,x4,y4;

    cin>>xv>>yv>>xp>>yp;
    cin>>x1>>y1>>x2>>y2;
    cin>>x3>>y3>>x4>>y4;
    if(!catnhau(xv,yv,xp,yp,x1,y1,x2,y2) && (songsong(xv,yv,xp,yp,x3,y3,x4,y4) || !catnhau(xv,yv,xp,yp,x3,y3,x4,y4))){
        puts("YES");
        getch();
        return 0;
    }
    if(!khacphia(x3,y3,x4,y4,xv,yv,xp,yp)){
        hinhchieu(x3,y3,x4,y4,xv,yv,I1,J1);
        hinhchieu(x3,y3,x4,y4,xp,yp,I2,J2);
        double len=hypot(I1-I2,J1-J2);
        double left=0, right=len, mid, val;
        while(fabs(right-left)>1e-12){
            mid=(left+right)/2;
            val=cal(mid,len);
            if(val>0) right=mid; else left=mid;
        }
        cal((left+right)/2,len);
        if(!smaller(xx,min(x3,x4)) && !bigger(xx,max(x3,x4))
        && !smaller(yy,min(y3,y4)) && !bigger(yy,max(y3,y4))
        && !dcatnhau(xx,yy,xv,yv,x1,y1,x2,y2) && !dcatnhau(xx,yy,xp,yp,x1,y1,x2,y2)){
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    getch();
    return 0;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 1200010;
const int K = 10;
int l[N], r[N], f[N], len[N], p[N], used[30][N];
vector < int > u, v, t, pr;
int ww;
map < ll, map < int, int > > d;
map < int, int > d0;
map < int, vector < int > > tv;
map < int, ll > tvi;
const int base = 22;
queue < pair < int, int > > q;
void calc (int p, int v, int x, int pr = 100){
    if (x < 0) return;
    if (used[p][v] > x) return;
    used[p][v] = x;
    q.push({p, v});
    if (d[ww].find(v) == d[ww].end()) d[ww][v] = K - x; else d[ww][v] = min(d[ww][v], K - x);
    if (p >= u.size()) return;
    for (int i = max(1, u[p] - x); i < u[p] + x; i++){
        int y = v;
        calc(p + 1, v / u[p] * i, x - abs(i - u[p]), i);
    }
}
void precalc (int p, int v, int x, int pr = 100){
    if (x < 0) return;
    if (d0.find(v) == d0.end()) d0[v] = K - x; else d0[v] = min(d0[v], K - x);
    if (p >= t.size()) return;
    for (int i = max(1, t[p] - x); i < t[p] + x && i <= pr; i++){
        int y = v;
        precalc(p + 1, v / t[p] * i, x - abs(i - t[p]), i);
    }
}
vector < int > tovec(int x){
    vector < int > res, z;
    while (x != 1){
        z.pb(p[x]);
        x /= p[x];
    }
    int pr = -1;
    int c = 0;
    sort(z.begin(), z.end());
    for (int i = 0; i < z.size(); i++) if (pr == z[i]) c++; else{
        if (c != 0) res.pb(c + 1);
        c = 1;
        pr = z[i];
    }
    res.pb(c + 1);
    sort(res.begin(), res.end());
    reverse(res.begin(), res.end());
    return res;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    n = 1000000;
    set < int > v;
    for (int i = 2; i < N; i++){
        if (p[i] != 0) continue;
        pr.pb(i);
        for (int j = i; j < N; j += i) p[j] = i;
    }
    for (int i = 1; i <= n; i++){
        vector < int > t = tovec(i);
        ll x = 0;
        for (auto j: t){
            x = x * base + j + 1;
        }
        tvi[i] = x;
        tv[x] = t;
        v.insert(x);
    }
    for (int i = 0; i < 10; i++) t.pb(1);
    precalc(0, 1, K);
    int zz = 0;
    int zzz = 0;
    for (auto i: v){
        u = tv[i];
        ww = i;
        int x = 1;
        for (auto j: u) x *= j;
        calc(0, x, K);
        zz += q.size();
        while(!q.empty()){
            auto y = q.front();
            q.pop();
            used[y.F][y.S] = 0;
        }
        zzz = max(zzz, (int)d[i].size());
        for (auto j: d[i]){
            for (auto l: d0){
                int c = l.F * j.F;
                if (c > 5000) continue;
                if (d[i][c] == 0 && c != x) d[i][c] = l.S + j.S; else d[i][c] = min(d[i][c], l.S + j.S);
            }
        }
    }
    int q;
    cin >> q;
    while(q--){
        int x, y;
        cin >> x >> y;
        x = tvi[x];
        y = tvi[y];
        int res = 1000;
        for (auto i: d[x]){
            if (d[y].find(i.F) != d[y].end()) res = min(res, i.S + d[y][i.F]);
        }
        cout << res << endl;
    }
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 1200010;
const int K = 15;
int l[N], r[N], f[N], len[N], p[N], used[30][N];
vector < int > u, v, t, pr;
map < vector < int >, map < int, int > > d;
map < int, int > d0;
map < int, vector < int > > tv;
queue < pair < int, int > > q;
void calc (int p, int v, int x, int pr = 100){
    if (x < 0) return;
    if (used[p][v] > x) return;
    used[p][v] = x;
    q.push({p, v});
    if (d[u].find(v) == d[u].end()) d[u][v] = K - x; else d[u][v] = min(d[u][v], K - x);
    if (p >= u.size()) return;
    for (int i = max(1, u[p] - x); i < u[p] + x; i++){
        int y = v;
        calc(p + 1, v / u[p] * i, x - abs(i - u[p]), i);
    }
}
void precalc (int p, int v, int x, int pr = 100){
    if (x < 0) return;
    if (d0.find(v) == d0.end()) d0[v] = K - x; else d0[v] = min(d0[v], K - x);
    if (p >= t.size()) return;
    for (int i = max(1, t[p] - x); i < t[p] + x && i <= pr; i++){
        int y = v;
        precalc(p + 1, v / t[p] * i, x - abs(i - t[p]), i);
    }
}
vector < int > tovec(int x){
    vector < int > res, z;
    while (x != 1){
        z.pb(p[x]);
        x /= p[x];
    }
    int pr = -1;
    int c = 0;
    sort(z.begin(), z.end());
    for (int i = 0; i < z.size(); i++) if (pr == z[i]) c++; else{
        if (c != 0) res.pb(c + 1);
        c = 1;
        pr = z[i];
    }
    res.pb(c + 1);
    sort(res.begin(), res.end());
    reverse(res.begin(), res.end());
    return res;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    n = 1000000;
    set < vector < int > > v;
    for (int i = 2; i < N; i++){
        if (p[i] != 0) continue;
        pr.pb(i);
        for (int j = i; j < N; j += i) p[j] = i;
    }
    for (int i = 1; i <= n; i++){
        vector < int > t = tovec(i);
        tv[i] = t;
        v.insert(t);
    }
    for (int i = 0; i < 10; i++) t.pb(1);
    precalc(0, 1, K);
    int zz = 0;
    int zzz = 0;
    for (auto i: v){
        u = i;
        int x = 1;
        for (auto j: u) x *= j;
        calc(0, x, K);
        zz += q.size();
        while(!q.empty()){
            auto y = q.front();
            q.pop();
            used[y.F][y.S] = 0;
        }
        zzz = max(zzz, (int)d[u].size());
        for (auto j: d[u]){
            for (auto l: d0){
                int c = l.F * j.F;
                if (c > 5000) continue;
                if (d[u][c] == 0 && c != x) d[u][c] = l.S + j.S; else d[u][c] = min(d[u][c], l.S + j.S);
            }
        }
    }
    int q;
    cin >> q;
    while(q--){
        int x, y;
        cin >> x >> y;
        vector < int > v1 = tv[x];
        vector < int > v2 = tv[y];
        int res = 1000;
        for (auto i: d[v1]){
            if (d[v2].find(i.F) != d[v2].end()) res = min(res, i.S + d[v2][i.F]);
        }
        cout << res << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
const int N = 1e6 + 5, M = 1500 + 5;
int dis[M][M], dist[M][M], ans[M][M], P[N], fpd[N], n, mx;
map <vector <int> , int> mp;
vector <int> s[N], g[M];

vector <int> seq(int a) {
    vector <int> p, vec;
    while (a > 1) {
        if (p.empty() || p.back() != fpd[a]) p.push_back(fpd[a]), vec.push_back(1);
        vec.back()++;
        a /= fpd[a];
    }
    while (vec.size() < 9) vec.push_back(1);
    sort(all(vec), greater <int>());
    return vec;
}
int zarb(vector <int> &vec) {
    int res = 1;
    for (int a : vec) res *= a;
    return res;
}
void BFS(int s) {
    dis[s][s] = 0;
    queue <int> q;
    q.push(s);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int u : g[v]) if (dis[s][v] + 1 < dis[s][u]) dis[s][u] = dis[s][v] + 1, q.push(u);
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    memset(P, 1, sizeof P);
    for (int i = 2; i < N; i++) if (P[i])
        for (int j = i; j < N; j += i) if (P[j]) P[j] = 0, fpd[j] = i;
    for (int i = 1; i < N; i++) {
        vector <int> vec = seq(i);
        if (mp.count(vec) == 0) mp[vec] = ++n, s[n] = vec;
    }
    memset(dis, 31, sizeof dis), memset(dist, 31, sizeof dist), memset(ans, 31, sizeof ans);
    for (int i = 1; i <= n; i++) {
        vector <int> vec = s[i];
        mx = max(mx, zarb(vec));
        for (int j = 0; j < sz(vec); j++) {
            if (j == 0 || vec[j] != vec[j - 1]) {
                vec[j]++;
                if (mp.count(vec) != 0) g[i].push_back(mp[vec]);
                else if (n < M - 1) mp[vec] = ++n, s[n] = vec, g[i].push_back(mp[vec]);
                vec[j]--;
            }
            if (j == sz(vec) - 1 || vec[j] != vec[j + 1]) {
                vec[j]--;
                if (mp.count(vec) != 0) g[i].push_back(mp[vec]);
                else if (n < M - 1) mp[vec] = ++n, s[n] = vec, g[i].push_back(mp[vec]);
                vec[j]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) BFS(i);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) dist[i][zarb(s[j])] = min(dist[i][zarb(s[j])], dis[i][j]);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= mx; k++) ans[i][j] = min(ans[i][j], dist[i][k] + dist[j][k]);
    int t; cin >> t;
    for (int i = 0; i < t; i++) {
        int a, b; cin >> a >> b, a = mp[seq(a)], b = mp[seq(b)];
        cout << ans[a][b] << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
const int N = 1e6 + 5, M = 2e3 + 5;
int dis[M][M], dist[M][M], ans[M][M], P[N], fpd[N], n, mx;
map <vector <int> , int> mp;
vector <int> s[N], g[M];

vector <int> seq(int a) {
    vector <int> p, vec;
    while (a > 1) {
        if (p.empty() || p.back() != fpd[a]) p.push_back(fpd[a]), vec.push_back(1);
        vec.back()++;
        a /= fpd[a];
    }
    while (vec.size() < 9) vec.push_back(1);
    sort(all(vec), greater <int>());
    return vec;
}
int zarb(vector <int> &vec) {
    int res = 1;
    for (int a : vec) res *= a;
    return res;
}
void BFS(int s) {
    dis[s][s] = 0;
    queue <int> q;
    q.push(s);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int u : g[v]) if (dis[s][v] + 1 < dis[s][u]) dis[s][u] = dis[s][v] + 1, q.push(u);
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    memset(P, 1, sizeof P);
    for (int i = 2; i < N; i++) if (P[i])
        for (int j = i; j < N; j += i) if (P[j]) P[j] = 0, fpd[j] = i;
    for (int i = 1; i < N; i++) {
        vector <int> vec = seq(i);
        if (mp.count(vec) == 0) mp[vec] = ++n, s[n] = vec;
    }
    memset(dis, 31, sizeof dis), memset(dist, 31, sizeof dist), memset(ans, 31, sizeof ans);
    for (int i = 1; i <= n; i++) {
        vector <int> vec = s[i];
        mx = max(mx, zarb(vec));
        for (int j = 0; j < sz(vec); j++) {
            if (j == 0 || vec[j] != vec[j - 1]) {
                vec[j]++;
                if (mp.count(vec) != 0) g[i].push_back(mp[vec]);
                else if (n < M - 1) mp[vec] = ++n, s[n] = vec, g[i].push_back(mp[vec]);
                vec[j]--;
            }
            if (j == sz(vec) - 1 || vec[j] != vec[j + 1]) {
                vec[j]--;
                if (mp.count(vec) != 0) g[i].push_back(mp[vec]);
                else if (n < M - 1) mp[vec] = ++n, s[n] = vec, g[i].push_back(mp[vec]);
                vec[j]++;
            }
        }
    }
    cout << mx << "\n";
    for (int i = 1; i <= n; i++) BFS(i);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) dist[i][zarb(s[j])] = min(dist[i][zarb(s[j])], dis[i][j]);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= mx; k++) ans[i][j] = min(ans[i][j], dist[i][k] + dist[j][k]);
    int t; cin >> t;
    for (int i = 0; i < t; i++) {
        int a, b; cin >> a >> b, a = mp[seq(a)], b = mp[seq(b)];
        cout << ans[a][b] << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int Maxn = 1e7 + 100;
bool isNotPrime[Maxn];

void pre_process()
{
	for (int i = 0; i * i < Maxn; ++i)
		if (!isNotPrime[i])
			for (int j = i * i; j < Maxn; j += i)
				isNotPrime[j] = true;
}

int main()
{
	pre_process();
	int n;
	cin >> n;
	for (int i = 0; i < 1e4; ++i)
		if (isNotPrime[n * i + 1])
		{
			cout << i << '\n';
			break;
		}

	return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>

//#include<bits/stdc++.h>

using namespace std;
bool f[1000000006] = {};
int main() {

	for (long long int i = 3; i <= 10000000; i+=2) {
		f[i] = 0;

		for (long long int j = 3; j*j <= i; j += 2) {
			if (i%j == 0) {
				f[j] = 1; break;
			}
		}
	}
	f[2] = 1;
	int n;int p = 0;
	cin >> n;
	for (long long int i = 1; i <= 10000000000003; i++) {
		long long int h = n*i + 1;
		if (!f[h]) {
			cout << i << endl; break;
		}
	}

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef signed long long sll;
typedef unsigned long long ull;
#define all(s) ((s).begin()),((s).end())
#define rall(s) ((s).rbegin()),((s).rend())
#define Pi 3.141592653589793238462643383279502884197169399375106
const int  OO=INT_MAX;

using namespace std;
void Yuko_Kurama()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
}
map<int,bool> p;
void sieve()
{
	int n=1010;
	p[1]=true;
	for(int i=2;i*i<=n;i++)
	{
		if(!p[i])
		{
		for(int j=i*2;j<n;j+=i)
		{
			p[j]=true;
		}
		}
	}
}
int main()
{
	Yuko_Kurama();

	int n;
	sieve();
	while(cin>>n)
	{
		int x,y,num=2,c=1;
		vector<int> v(n);
		map<int,int> mop;

		while (1)
		{
			num=n*c+1;
			if(p[num]) break;
			c++;
		}
		cout<<c<<endl;

	}

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef signed long long sll;
typedef unsigned long long ull;
#define all(s) ((s).begin()),((s).end())
#define rall(s) ((s).rbegin()),((s).rend())
#define Pi 3.141592653589793238462643383279502884197169399375106
const int  OO=INT_MAX;

using namespace std;
void Yuko_Kurama()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
}
map<int,bool> p;
void sieve()
{
	int n=1010;
	p[1]=true;
	for(int i=2;i*i<=n;i++)
	{
		if(!p[i])
		{
		for(int j=i*2;j<n;j+=i)
		{
			p[j]=true;
		}
		}
	}
}
int main()
{
	Yuko_Kurama();

	int n;
	sieve();
	while(cin>>n)
	{
		int x,y,num=2,c=1;
		while (1)
		{
			num=n*c+1;
			if(p[num]) break;
			c++;
		}
		cout<<c<<endl;

	}

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <time.h>
#include <algorithm>
using namespace std;
#define INF 2147483647

int main() {
	ios_base::sync_with_stdio(false);

	int a, b, tic_a, tic_b; cin >> a >> b >> tic_a >> tic_b;
	int total; cin >> total;
	int min, max;

	min = total - ((tic_a - 1) * a + (tic_b - 1) * b);
	if (min < 0) {
		min = 0;
	}
	max = a + b;

	while (a * tic_a + b * tic_b > total) {
		max -= 1;
		if (tic_a > tic_b && a > 0) {
			a -= 1;
		}
		else if(b>0){
			b -= 1;
		}
	}

	cout << min << " " << max << "\n";
	return 0;
}


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

int main(){
	int a1, a2;
	cin >> a1 >> a2;
	int k1, k2;
	cin >> k1 >> k2;
	int n;
	cin >> n;
	int minRes = 0;
	int maxRes = 0;
	int bigFirst[a1 + a2] = {};
	int minCards = k1;
	int minTeam = a1;
	int maxCards = k2;
	int maxTeam = a2;
	if(k1 > k2){
		minCards = k2;
		minTeam = a2;
		maxCards = k1;
		maxTeam = a1;
	}
	for(int i = 0; i < maxTeam; i++){
		bigFirst[i] = maxCards;
	}
	for(int i = 0; i < minTeam; i++){
		bigFirst[maxTeam + i] = minCards;
	}
	int cards = n;
	int index = 0;
	while(cards > 0){
		if(bigFirst[index % (a1 + a2)] > 1){
			bigFirst[index % (a1 + a2)]--;
			cards--;
		}
		index++;
	}
	for(int i = 0; i < a1 + a2; i++) {
		if(bigFirst[i] == 0) minRes++;
	}
	int lowFirst[a1 + a2] = {};
	for(int i = 0; i < minTeam; i++){
		lowFirst[i] = minCards;
	}
	for(int i = 0; i < maxTeam; i++){
		lowFirst[minTeam + i] = maxCards;
	}
	cards = n;
	index = 0;
	while(cards > 0){
		if(lowFirst[index % (a1 + a2)] > 0){
			lowFirst[index % (a1 + a2)]--;
			cards--;
		} else index++;
	}
	for(int i = 0; i < a1 + a2; i++){
		if(lowFirst[i] == 0) maxRes++;
	}
	cout << minRes << " " << maxRes << endl;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
typedef pair<ll, ll> ii;
ll a1, a2, k1, k2, n;
priority_queue<ii> heap;
int main()
{
    cin >> a1 >> a2 >> k1 >> k2 >> n;
    ll r1 = 0, r2 = 0;
    for(int i = 0;i <= a1;i++)
        for(int j = 0;j <= a2;j++)
            if(k1 * i + k2 * j <= n)
                r2 = max(r2,(ll) i + j);
    for(int i = 1;i <= a1;i++)
        heap.push(ii(k1, 1));
    for(int i = 1;i <= a2;i++)
        heap.push(ii(k2, 2));
    while(heap.size() > 0){
        ii t = heap.top();
        heap.pop();
        if(t.first == 0) break;
        if(t.second == 1){
            if(t.first >= k1) heap.push(ii(t.first - k1 + 1, 1)), n = n -(k1 - 1);
            else heap.push(ii(0, 1)), r1++, n -= t.first;
        }else
            if(t.first >= k2) heap.push(ii(t.first - k2 + 1, 2)), n = n - (k2 - 1);
            else heap.push(ii(0, 2)), r1++, n -= t.first;
        if(n <= 0) break;
    }
    cout << r1 << " " << r2;
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

#define N 1000005

int n;  int trie[N<<5][2];

struct edge{ int des;  int next;  int w; }e[N<<1];

int cnt;  int head[N];  int dist[N];

void ins(int u,int v,int w){
    ++cnt;  e[cnt].des=v; e[cnt].next=head[u]; e[cnt].w=w; head[u]=cnt;
}

void dfs(int u,int f){
    for(int i=head[u];i;i=e[i].next){
        int v=e[i].des;
        if(v==f) continue;
        dist[v]=dist[u]^e[i].w;
        dfs(v,u);
    }
}

int tim;

void build(int x){
    int cur=0;
    for(int i=30;i>=0;--i){
        int t=x&(1<<i);
        if(!trie[cur][t]) trie[cur][t]=++tim;
        cur=trie[cur][t];
    }
}
int ans=0;
int query(int x){
    int cur=0;  int ans=0;
    for(int i=30;i>=0;--i){
        int t=x&(1<<i);
        if(trie[cur][t^1]){
            ans+=(1<<i);
            cur=trie[cur][t^1];
        }
        else{
            cur=trie[cur][t];
        }
    }
    return ans;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<n;++i){
        int u; int v; int w;
        scanf("%d %d %d",&u,&v,&w);
        ins(u,v,w);  ins(v,u,w);
    }
    dfs(1,0);
    for(int i=1;i<=n;++i) build(dist[i]);
    for(int i=1;i<=n;++i) ans=max(ans,query(dist[i]));
    printf("%d\n",ans);
    return 0;
}


#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
int main()
{
	int r,c;
	cin>>r>>c;
	char a[1000][1000],b[1000];
	for(int i=0;i<=r;i++)
	{
		gets(b);
		for (int j=0;j<c;j++)
		{
			a[i][j]=b[j];
		}
	}
	for(int i=0;i<=r;i++)
	{
		int	dem=0;
		for (int j=0;j<c;j++)
		{
			if(a[i][j]=='.')
			{
				dem++;
			}
			else
			{
				dem=0;
				break;
			}
		}
		if(dem==c)
		{
			for(int k=0;k<c;k++)
				a[i][k]='1';
		}
	}
	for(int i=0;i<c;i++)
	{
		int	dem=0;
		for (int j=1;j<=r;j++)
		{
			if(a[j][i]=='.' || a[j][i]=='1')
			{
				dem++;
			}
			else
			{
				dem=0;
				break;
			}
		}
		if(dem==r)
		{
			for(int k=1;k<=r;k++)
				a[k][i]='1';
		}
	}
	int tg=0;
	for(int i=1;i<=r;i++)
		for (int j=0;j<c;j++) if (a[i][j]=='1') tg++;
	cout<<tg;
	getch();
	return 0;
}


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

#define lp(i,n) for(int (i)=0; (i)<(n); (i)++)
#define sz(v)   int((v).size())
#define all(v)  (v).begin(),(v).end()
typedef long long ll;
typedef pair <int, int> ii;
typedef vector <int>   vi;
typedef vector <ii>    vii;
typedef vector <vi>    vvi;
typedef vector <vii>   vvii;

const int OO = int(1e12);

int main() {
    freopen("input.txt", "r", stdin);
    int r, c, cntr = 0, cntc = 0;
    scanf("%d %d", &r, &c);
    bool fr = 1, fc = 1;
    vector<vector<char>> cake(r, vector<char>(c));
    lp(i, r) {
        fr = 1;
        string str;
        cin >> str;
        lp(j, c) {
            cake[i][j] = str[j];
            if (cake[i][j] == 'S') {
                fr = 0; break;
            }
        }
        if (fr == 1) {
            cntr++;
        }
    }
    lp(i, c) {
        fc = 1;
        lp(j, r) {
            if (cake[j][i] == 'S') {
                fc = 0; break;
            }
        }
        if (fc == 1) {
            cntc++;
        }
    }

    printf("%d\n", cntr*c + cntc*r - cntr*cntc);
    return 0;
}


#include<bits/stdc++.h>
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
using namespace std;
int  r,c,b[10001][10001],ans;
char a;
int main()
{
	r=read();
	c=read();
	for(int i=1;i<=r;++i)
	 for(int j=1;j<=c;++j)
	  {
	  	cin>>a;
	  	if(a=='S')
	  	 {
	  	 	for(int e=1;e<=r;++e)
	  	 	 b[e][j]++;
	  	 	for(int e=1;e<=c;++e)
	  	 	 b[i][e]++;
		 }
	  }
	for(int i=1;i<=r;++i)
	 for(int j=1;j<=c;++j)
	  {
	  	if(b[i][j]<2)
	  	 ans++;
	  }
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
#include<cstdlib>

using namespace std;

#define ll long long
#define nada "\n"
#define st string
#define S  second
#define F  first
#define pb push_back
#define MP make_pair
#define isnttriangle(a,b,c)  (a+b<c||a+c<b||b+c<a)
#define todegree(rad) rad*(180.0/pi)
#define rrp(i, a, b)  for(ll i = a; i >= b; i--)
#define repp(i,a,b)   for (int i = int(a); i <=int(b); i++)
#define rep(i, n)     for (int i = 0; i <n; i++)
#define rep1(i,n)     for (int i = 1; i <=n; i++)
#define all(v)        ((v).begin()),((v).end())
#define fx(n)         cout<<fixed<<setprecision(n);
#define sz(v)         ((int)(v).size())
#define Test          ll t;cin>>t;while(t--)
#define mod           1000000009LL

const double ME = 2.71828;
const int    N  = 3e5 + 20;
const double pi = 3.141592653;

void LOSER()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void file()
{
    freopen("records.in", "r", stdin);
    //freopen("text.out", "w", stdout);
}

ll gcd(ll a, ll b)
{
    //Eculidean Algorthim
    return (!b) ? a : gcd(b, a % b);
    //complixty=log(ab);
}

ll lcm(ll a,ll b)
{
    return a / gcd(a, b) * b;
}

ll Fib_recur(ll n)
{
    vector<ll>v(n+5,0);
    //BaseCase
    v[1]=0;
    v[2]=1;
    repp(i,3,n)v[i]=v[i-1]+v[i-2];
    return v[n];
}

bool isprime(int n)
{
    for(int i = 2; i <= sqrt(n); i++)
    {
        if(n%i == 0)
            return false;
    }
    return true;
}

void Solve()
{
    int row,coulm;
    set<char>Row,Coulm;
    char arr[row][coulm];

    cin>>row>>coulm;

    rep(i,row)
    {
        rep(j,coulm)
        {

            cin>>arr[i][j];
            if(arr[i][j]=='S')
            {

                Row.insert(i);
                Coulm.insert(j);
            }
        }
    }

    cout<<(row*coulm)-(sz(Row)*sz(Coulm));
}
//"I AM A LOSER 🐸🤦♀";

int main()
{
    // fx(7)
    //file();
    LOSER();
    //Test{}
    Solve();

}


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

using ll = long long;

int c, v0, a, l, v1, read, per;
ll ans;

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

    cin >> c >> v0 >> v1 >> a >> l;

    read = c;
    ans = 0;

    for (int i = 0; ; ++i) {
        if (i > 0) read += l;
        per = a * i;
        if (per > v1) per = v1;
        read -= (v0 + per);
        ans++;
        if (read <= 0) break;
    }

    cout << ans << endl;

    return 0;
}


#include<iostream>

using namespace std;

int c,v0,v1,a,l,k;

bool check(int t)
{
    int p=t;
    if(t>k)p=k;
    int res=v0*t-(t-1)*l+(p-1)*p*a/2;

    if((v1-v0)%a!=0)
    {
        res+=(t-p)*((v1-v0)%a);
    }

    if(res>=c)return 1;
    else return 0;
}

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

    int beg,end,mid;

    cin>>c>>v0>>v1>>a>>l;

    beg=1;
    end=1000;

    k=(v1-v0)/a+1;
    if((v1-v0)%a!=0)k++;

    while(beg!=end)
    {
        mid=(beg+end)/2;

        if(check(mid)==true)
        {
            end=mid;
        }
        else  beg=mid+1;
    }

    cout<<mid<<endl;

    return 0;
}


#include <stdio.h>

int page[1111];

int main(void)
{
	int c, v0, v1, a, l;
	scanf("%d %d %d %d %d", &c, &v0, &v1, &a, &l);
	if (c <= v0)
	{
		printf("1\n");
		return false;
	}
	page[1] = v0;
	int ans;
	if (a == 0)
	{
		for (int i = 2; i <= 1111; i++)
		{
			if (page[i - 1] >= c)
			{
				ans = i;
				break;
			}
			page[i] = page[i - 1] + v0;
		}
	}

	for (int i = 2; i <= 1111; i++)
	{
		if (page[i - 1] >= c)
		{
			ans = i;
			break;
		}
		int tmp = v1 - l;
		if (v1 - l >= a)
		{
			page[i] = page[i - 1] + a;
		}
		else
		{
			page[i] = page[i - 1] + tmp;
		}
	}

	printf("%d\n", ans-1);
	return false;
}


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

int main()
{
    int c,v0,v1,a,l;
    bool fin = false;
    scanf("%d%d%d%d%d",c,v0,v1,a,l);

    int pos = v0, add = v0;
    int t = 1;

    while(pos < c)
    {
        add = min(v1, add+a);
        pos += add - l;
        t++;
    }
    cout << t << endl;
}


/*#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{

    int a[2];int d;
    cin>>a[0]>>a[1]>>a[2]>>d;
    sort(a,a+ 2);
    if ((abs(a[1]-a[0])<d)&&(abs(a[2]-a[1])<d))
    {
    cout << abs(d-abs(a[1]-a[0]))+abs(d-abs(a[2]-a[1]));
    }

   // else
    //    if ((abs(a[1]-a[0])>=d)&&(abs(a[2]-a[1])>=d))cout << 0;

        if (abs(a[1]-a[0])>=d){cout << (abs(d-abs(a[2]-a[1])));}

        if (abs(a[2]-a[1])>=d)cout << (abs(d-abs(a[1]-a[0])));
    return 0;

}*/
#include <iostream>
#include <cmath>
using namespace std;
void swap(int* a, int* b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

int partition (int arr[], int low, int high)
{
    int pivot = arr[high];
    int i = (low - 1);

    for (int j = low; j <= high - 1; j++)
    {
        if (arr[j] <= pivot)
        {
            i++;
            swap(&arr[i], &arr[j]);
        }
    }
    swap(&arr[i + 1], &arr[high]);
    return (i + 1);
}
void quickSort(int arr[], int low, int high)
{
    if (low < high)
{

     int pi = partition(arr, low, high);
        quickSort(arr, low, pi - 1);
        quickSort(arr, pi + 1, high);
    }
}

int main()
{

    int a[2];int d;
    cin>>a[0]>>a[1]>>a[2]>>d;quickSort(a, 0, 2);
    if ((abs(a[1]-a[0])<d)&&(abs(a[2]-a[1])<d))
    cout << abs(d-abs(a[1]-a[0]))+abs(d-abs(a[2]-a[1]));
    else
        if ((abs(a[1]-a[0])>=d)&&(abs(a[2]-a[1])>=d))cout << 0;
    else
        if (abs(a[1]-a[0])>=d){cout << (abs(d-abs(a[2]-a[1])));}
    else
        if (abs(a[2]-a[1])>=d)cout << (abs(d-abs(a[1]-a[0])));
    return 0;
}


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

using namespace std;

#define LL long long

LL a,b,c,d,ans;
LL pos1,pos2,pos3;

int main() {
    cin>>a>>b>>c>>d;
    pos1 = min(min(a,b),c);
    pos3 = max(max(a,b),c);
    pos2 = a+b+c - pos1 - pos3;
    LL left = 0,right = 0;
    left = pos2 - pos1;
    right = pos3 - pos2;
    if(left < d) ans += (d - left);
    if(right < d) ans += (d - right);
    cout<<pos1<<" "<<pos2<<" "<<pos3<<endl;
    cout<<left<<" "<<right<<endl;
    cout<<ans;
    system("pause");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n=3,arr[2],step=0,d;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    cin>>d;
    sort(arr,arr+2);
    int e,f;
    e=d-abs(arr[0]-(arr[1]));
    step+=e;
    f=d-abs(arr[1]-arr[2]);
    step+=f;
    cout<<step<<endl;
}


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

int main()
{

    int arr[3];
    while(1)
    {
        int a,b,c,d,d1=0;
        cin>>a>>b>>c>>d;
        arr[0]=a;
        arr[1]=b;
        arr[2]=c;
        sort(arr,arr+3);
        // cout<<arr[0];
        //cout<<arr[1];
        //cout<<arr[2];
        if(arr[1]-arr[0]<d)
        d1=d1+d-arr[1]+arr[0];
        if(arr[2]-arr[1]<d)
        d1=d1+d-arr[2]+arr[1];
        cout<<d1<<endl;
    }
}


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

using namespace std;

int main()
{
    long int d,i,j; int k,l,m,n;
    j=0;
    freopen("input.txt", "r", stdin);
    //scanf("%d %d %d %d %ld",&k,&l,&m,&n,&d);
    cin>>k>>l>>m>>n>>d;
    int a[d];
    for (i=1;i<=d;i++) {
    if (i%k==0) {
    a[i]=1;
    }
    else if (i%l==0){
    a[i]=1;
    }
    else if (i%m==0){
    a[i]=1;
    }
    else if (i%n==0){
    a[i]=1;
    }
    if (a[i]==1) j=j+1;
    }
    freopen("output.txt","w",stdout);
    //printf("%ld",j);
    cout<<j;
    return 0;
}


#include <stdio.h>

using namespace std;

int main()
{
    long int d,i,j; int k,l,m,n;
    j=0;
    freopen("input.txt", "r", stdin);
    scanf("%d",&k);
    scanf("%d",&l);
    scanf("%d",&m);
    scanf("%d",&n);
    scanf("%ld",&d);
    int a[d];
    for (i=1;i<=d;i++) {
    if (i%k==0) a[i]=1;
    if (i%l==0) a[i]=1;
    if (i%m==0) a[i]=1;
    if (i%n==0) a[i]=1;
    if (a[i]==1) j=j+1;
    }
    freopen("output.txt","w",stdout);
    printf("%ld",j);
    return 0;
}


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

using namespace std;

void main () {
	int a[4], d, k;
	bool f[20200];
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> d;
	for (int i = 0; i < d; i++) {
		f[i] = true;
	}
	short i;
	for (i = 0; i < 4; i++) {
		k = a[i] - 1;
		while (k < d) {
			f[k] = false;
			k += a[i];
		}
	}
	int ans = 0;
	for (i = 0; i < d; i++) {
		if (!f[i]) {
			ans++;
		}
	}
	cout << ans;
	getch ();
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  string L, R;
  cin >> L >> R;
  reverse(L.begin(), L.end());
  L.resize(R.size(), '0');
  reverse(L.begin(), L.end());
  int n, m = 0;
  cin >> n;
  const int sigma = 10, M = 3 * R.size() * sigma + 100;
  vector<vector<int> > son(M, vector<int>(sigma, 0)), sum(M, vector<int>(R.size(), 0));
  function<void (int, int, bool, bool, bool)> gen = [&] (int idx, int u, bool big, bool small, bool start) {
    if (idx >= R.size() || (big && small)) {
      sum[u][R.size() - idx]++;
    } else {
      for (int i = (big ? 0 : L[idx] - '0'); i <= (small ? 9 : R[idx] - '0'); i++) {
        int v = u;
        if (start || i) {
          if (!son[u][i]) {
            son[u][i] = m++;
          }
          v = son[u][i];
        }
        gen(idx + 1, v, big || L[idx] - '0' < i, small || R[idx] - '0' > i, start || i);
      }
    }
  };
  gen(0, m++, false, false, false);
  vector<int> fail(m);
  auto build = [&] () {
    queue<int> que;
    que.push(0);
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (int i = 0; i < sigma; i++) {
        if (!son[u][i]) {
          son[u][i] = son[fail[u]][i];
        } else {
          int v = fail[u];
          while (v && !son[v][i]) {
            v = fail[v];
          }
          if (son[v][i] && son[v][i] != son[u][i]) {
            fail[son[u][i]] = son[v][i];
            for (int j = 0; j < R.size(); j++) {
              sum[son[u][i]][j] += sum[son[v][i]][j];
            }
          }
          que.push(son[u][i]);
        }
      }
    }
  };
  build();
  for (int u = 0; u < m; u++) {
    for (int i = 1; i < R.size(); i++) {
      sum[u][i] += sum[u][i - 1];
    }
  }
  vector<vector<int> > dp(n + 1, vector<int>(m, -1e9));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int u = 0; u < m; u++) {
      if (dp[i][u] >= 0) {
        for (int j = 0; j < sigma; j++) {
          int v = u;
          while (v && !son[v][j]) {
            v = fail[v];
          }
          v = son[v][j];
          dp[i + 1][v] = max(dp[i + 1][v], dp[i][u] + sum[v][min((int)R.size(), n - i) - 1]);
        }
      }
    }
  }
  int goal = *max_element(dp[n].begin(), dp[n].end());
  cout << goal << endl;
  vector<vector<bool> > on(n + 1, vector<bool>(m));
  for (int i = 0; i < m; i++) {
    on[n][i] = dp[n][i] == goal;
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int u = 0; u < m; u++) {
      if (dp[i][u] >= 0) {
        bool ok = false;
        for (int j = 0; j < sigma; j++) {
          int v = u;
          while (v && !son[v][j]) {
            v = fail[v];
          }
          v = son[v][j];
          ok |= on[i + 1][v] && dp[i][u] + sum[v][min((int)R.size(), n - i) - 1] == dp[i + 1][v];
        }
        on[i][u] = ok;
      }
    }
  }
  int u = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < sigma; j++) {
      int v = u;
      while (v && !son[v][j]) {
        v = fail[v];
      }
      v = son[v][j];
      if (on[i + 1][v] && dp[i][u] + sum[v][min((int)R.size(), n - i) - 1] == dp[i + 1][v]) {
        cout << j;
        u = v;
        break;
      }
    }
  }
  cout << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int myrand() {return abs((int) mt());}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

const int maxn = 1e5 + 5;
const int maxc = 10;
struct node_t {
    node_t* p;
    node_t* c[maxc];
    node_t *bf, *gf;
    int key;
    char val;
    vector<int> info;
    node_t();
    void clear();
} pool[maxn], *ptr = pool;
node_t::node_t() {
    clear();
}
void node_t::clear() {
    p = 0;
    for (int i = 0; i < maxc; i++) c[i] = 0;
    bf = gf = 0, key = -1, val = 0;
}
void clear() {
    node_t* st = pool;
    while (st != ptr) {
        st->clear();
        st++;
    }
    ptr = pool;
}
node_t* insert(node_t* x, char* s, int key, int len) {
    while (*s) {
        int k = *s - '0';
        if (!x->c[k]) {
            x->c[k] = ptr++;
            x->c[k]->p = x;
            x->c[k]->val = k;
        }
        x = x->c[k];
        s++;
    }
    x->key = key;
    x->info.push_back(len);
    return x;
}
void pushlink(node_t* rt) {
    static node_t* q[maxn];
    int b = 0, e = 0;
    q[e++] = rt;
    while (b < e) {
        node_t* x = q[b++];
        for (int i = 0; i < maxc; i++) {
            if (x->c[i]) q[e++] = x->c[i];
        }
        if (x == rt || x->p == rt) {
            x->bf = rt;
            x->gf = 0;
        }
        else {
            x->bf = x->p->bf;
            while (x->bf != rt && !x->bf->c[x->val]) x->bf = x->bf->bf;
            if (x->bf->c[x->val]) x->bf = x->bf->c[x->val];
            if (x->bf->key != -1) x->gf = x->bf;
            else x->gf = x->bf->gf;
            for (int e : x->bf->info) {
                x->info.push_back(e);
            }
            sort(x->info.begin(), x->info.end());
        }
    }
}

string l, r;
int n;
node_t* rt;
vector<vi> f;
vector<vi> dp;

int calc(int u, int v) {
    if (u == n) return 0;
    int& res = dp[u][v];
    if (~res) return res;
    res = 0;
    FOR(i, 0, 10) {
        node_t* cur = pool + v;
        while (cur != rt && !cur->c[i]) {
            cur = cur->bf;
        }
        int cost = f[n - u][i], nv = cur - pool;
        if (cur->c[i]) {
            cur = cur->c[i];
            nv = cur - pool;
            if (cur->key == -1) {
                cur = cur->gf;
            }
            if (cur) {
                cost += upper_bound(all(cur->info), n - u) - cur->info.begin();
            }
        }
        chkmax(res, calc(u + 1, nv) + cost);
    }
    return res;
}

void chemthan() {
    cin >> l >> r >> n;
    vector<vi> g(10);
    if (sz(l) < sz(r)) {
        FOR(i, 1, r[0] - '0') {
            g[i].pb(sz(r));
        }
        FOR(i, sz(l) + 1, sz(r)) {
            FOR(j, 1, 10) {
                g[j].pb(i);
            }
        }
        FOR(i, l[0] - '0' + 1, 10) {
            g[i].pb(sz(l));
        }
    }
    else {
        FOR(i, l[0] - '0' + 1, r[0] - '0') {
            g[i].pb(sz(r));
        }
    }
    FOR(i, 1, 10) sort(all(g[i]));
    f.resize(n + 1, vi(10));
    FOR(i, 1, n + 1) FOR(j, 1, 10) {
        f[i][j] = upper_bound(all(g[j]), i) - g[j].begin();
    }
    rt = ptr++;
    int flag = sz(l) < sz(r) || l[0] < r[0];
    FOR(i, 1, sz(r)) {
        FOR(j, 0, r[i] - '0') {
            if (flag || l[i] - '0' < j) {
                insert(rt, (char *) (r.substr(0, i) + char('0' + j)).data(), 0, sz(r) - i);
            }
        }
        if (!flag) {
            flag |= l[i] < r[i];
        }
    }
    flag = sz(l) < sz(r) || l[0] < r[0];
    FOR(i, 1, sz(l)) {
        FOR(j, l[i] - '0' + 1, 10) {
            if (flag) {
                insert(rt, (char *) (l.substr(0, i) + char('0' + j)).data(), 0, sz(l) - i);
            }
        }
        if (!flag) {
            flag |= l[i] < r[i];
        }
    }
    insert(rt, (char *) l.data(), 0, 1);
    if (l < r) {
        insert(rt, (char *) r.data(), 0, 1);
    }
    pushlink(rt);
    dp.resize(n + 1);
    for (auto& e : dp) e.resize(ptr - pool, -1);
    int mx = calc(0, 0);
    cout << mx << "\n";
    string res;
    int u = 0, v = 0;
    FOR(it, 0, n) {
        FOR(i, 0, 10) {
            node_t* cur = pool + v;
            while (cur != rt && !cur->c[i]) {
                cur = cur->bf;
            }
            int cost = f[n - u][i], nv = cur - pool;
            if (cur->c[i]) {
                cur = cur->c[i];
                nv = cur - pool;
                if (cur->key == -1) {
                    cur = cur->gf;
                }
                if (cur) {
                    cost += upper_bound(all(cur->info), n - u) - cur->info.begin();
                }
            }
            if (calc(u + 1, nv) + cost == mx) {
                res += char('0' + i);
                mx -= cost;
                u++, v = nv;
                break;
            }
        }
    }
    cout << res << "\n";
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <bits/stdc++.h>
#define M 40005
#define N 2005
#define FI first
#define SE second
#define MP std::make_pair
#define PB push_back
#define mod 998244353
#define INF 1000000000
typedef long long ll;
char A[M], B[M];
int n, lenA, lenB;
int read() {
	int ans = 0; char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
	return ans;
}
void Write(int x) {
	if (x < 10) putchar(x + '0');
	else Write(x / 10), putchar(x % 10 + '0');
	return;
}
int max(int x, int y) {return x > y ? x : y;}
int min(int x, int y) {return x < y ? x : y;}
namespace AC {
	int son[M][N], fail[M],	val[M][N], F[M][N], cnt = 1, cur_len;
	char AA[M], BB[M];
	void DFS(int l, int x, bool bl = true, bool br = true) {
		if (l > cur_len || (!bl && !br)) return val[x][cur_len + 1 - l]++, void();
		for (int i = (bl ? AA[l] - '0' : 0); i <= (br ? BB[l] - '0' : 9); i++)
			DFS(l + 1, son[x][i] ? son[x][i] : son[x][i] = ++cnt, bl & (i + '0' == AA[l]), br & (i + '0' == BB[l]));
		return;
	}
	void build() {
		if (lenA == lenB) return cur_len = lenA, memcpy(AA + 1, A + 1, lenA), memcpy(BB + 1, B + 1, lenB), DFS(1, 1);
		memcpy(AA + 1, A + 1, lenA), memset(BB + 1, '9', lenA), cur_len = lenA, DFS(1, 1);
		memcpy(BB + 1, B + 1, lenB), memset(AA + 1, '0', lenB), AA[1] = '1', cur_len = lenB, DFS(1, 1);
		for (int i = lenA + 1; i < lenB; i++)
			for (int j = 1; j < 10; j++) val[son[1][j] ? son[1][j] : son[1][j] = ++cnt][i - 1]++;
		return;
	}
	void get_fail() {
		std::queue <int> Q;
		for (int i = 0; i < 10; i++)
			if (son[1][i]) Q.push(son[1][i]), fail[son[1][i]] = 1;
			else son[1][i] = 1;
		while (!Q.empty()) {
			int now = Q.front(); Q.pop();
			for (int i = 0; i <= n; i++) val[now][i] += val[fail[now]][i];
			for (int i = 0; i < 10; i++)
				if (son[now][i]) fail[son[now][i]] = son[fail[now]][i], Q.push(son[now][i]);
				else son[now][i] = son[fail[now]][i];
		}
		for (int i = 1; i <= cnt; i++)
			for (int j = 1; j <= n; j++) val[i][j] += val[i][j - 1];
		return;
	}
	void find_ans(int x, int y){
		if (!y) return;
		for (int i = 0; i < 10; i++)
			if (son[x][i] && F[x][y] == F[son[x][i]][y - 1] + val[x][y]) return putchar(i + '0'), find_ans(son[x][i], y - 1);
		return assert(0), void();
	}
	void DP() {
		for (int i = 1; i <= cnt; i++) F[i][0] = val[i][0];
		for (int j = 1; j <= n; j++)
			for (int i = 1; i <= cnt; i++)
				for (int k = 0; k < 10; k++)
					if (son[i][k]) F[i][j] = max(F[i][j], F[son[i][k]][j - 1] + val[i][j]);
		return Write(F[1][n]), putchar('\n'), find_ans(1, n);
	}
}
int main() {
	scanf("%s%s", A + 1, B + 1); n = read(); lenA = strlen(A + 1), lenB = strlen(B + 1);
	return AC::build(), AC::get_fail(), AC::DP(), 0;
}


#include<bits/stdc++.h>
#define mod 1e9+7
#define inf 0x3f3f3f
typedef long long ll;
typedef long double ld;
using namespace std;
struct P{
	int c[10];
	int sum[810];
	int fail,num;
}p[16010];
char l[2000],r[2000],t[2010];
int n,cnt,len,tl,la1,la2=1;
void dfs(int x,int le){
	int nxt=0;
	if(p[x].c[t[le]])nxt=p[x].c[t[le]];
	else {
		p[x].c[t[le]]=++cnt;
		nxt=cnt;
		//cout<<x<<" to "<<cnt<<"("<<(int)(t[le])<<")"<<endl;
	}
	p[nxt].num=t[le];
	if(le==len){
		p[nxt].sum[tl-len]++;
		la1=x,la2=len;
		return;
	}
	dfs(nxt,le+1);
}
void getf(int x,int f){
	if(f==0)p[x].fail=0;
	else p[x].fail=p[p[f].fail].c[p[x].num];
	for(int i=0;i<=800;i++){
		p[x].sum[i]+=p[p[x].fail].sum[i];
	}
	for(int i=0;i<=9;i++){
		if(p[x].c[i])getf(p[x].c[i],x);
	}
}
int dp[2010][16010];
string ans[16010][2];
int main(){
    scanf("%s%s",l+1,r+1);
    scanf("%d",&n);
    p[0].c[0]=++cnt;
    p[1].num=0;
    int L=strlen(l+1),R=strlen(r+1);
    for(int i=1;i<=L;i++){
    	l[i]-='0';
	}
	for(int i=1;i<=R;i++){
		r[i]-='0';
	}
    int s=1;
    if(L==R){
    	tl=L;
    	for(int i=1;i<=L;i++){
    		if(l[i]==r[i]){
    			t[i]=l[i];
			}
			else {
				s=i;
				break;
			}
		}
		for(int i=l[s]+1;i<=r[s]-1;i++){
			len=s;t[s]=i;
			dfs(la1,la2);
		}
		s++;
	}
	t[s-1]=l[s-1];tl=L;len=s-1;
	for(int i=s;i<=L;i++){
		len=i;
		for(int j=l[i]+1;j<=9;j++){
			t[i]=j;dfs(la1,la2);
		}
		t[i]=l[i];
	}
	dfs(la1,la2);
	la1=0;la2=1;
	t[s-1]=r[s-1];tl=R;len=s-1;
	for(int i=s;i<=R;i++){
		len=i;
		for(int j=0;j<=r[i]-1;j++){
			if(j==0&&i==1)continue;
			t[i]=j;dfs(la1,la2);
		}
		t[i]=r[i];
	}
	dfs(la1,la2);
	len=1;
	for(tl=L+1;tl<R;tl++){
		for(int j=1;j<=9;j++){
			t[1]=j;dfs(0,1);
		}
	}
	getf(0,0);
	for(int i=1;i<=cnt;i++){
		for(int j=1;j<=800;j++){
			p[i].sum[j]+=p[i].sum[j-1];
		}
		//cout<<i<<"  sum "<<p[i].sum[2]<<"  fail "<<p[i].fail<<endl;
	}
	memset(dp,-1,sizeof(dp));
	dp[0][0]=0;
	string res="z";
	ll Max=0;
	for(int i=0;i<=n-1;i++){
		int rest=min(800,n-i-1);
		for(int j=0;j<=cnt;j++){
			if(dp[i][j]==-1)continue;
			for(int k=0;k<=9;k++){
				int v=p[j].c[k];
				int x=j;
				while(v==0){
					x=p[x].fail;
					v=p[x].c[k];
					if(x==0&&v==0)break;
				}
				if(v==0)continue;
				if(dp[i+1][v]<dp[i][j]+p[v].sum[rest]){
					dp[i+1][v]=dp[i][j]+p[v].sum[rest];
					ans[v][i&1]=ans[j][!(i&1)]+(char)(p[v].num+'0');
				}
				else if(dp[i+1][v]==dp[i][j]+p[v].sum[rest]){
					if(ans[v][i&1]>ans[j][!(i&1)]+(char)(p[v].num+'0')){
						ans[v][i&1]=ans[j][!(i&1)]+(char)(p[v].num+'0');
					}
				}
				//cout<<v<<" "<<ans[v][i&1]<<" "<<dp[i+1][v]<<endl;
				if(i+1==n){
					if(Max<dp[i+1][v]){
						Max=dp[i+1][v];
						res=ans[v][i&1];
					}
					else if(Max==dp[i+1][v]&&res>ans[v][i&1]){
						res=ans[v][i&1];
					}
				}
			}
		}
	}
	printf("%d\n",Max);
	cout<<res<<endl;
	return 0;
}


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

int a[100000000];
void init()
{
    int cnt=0;
    for(int i=1;i<=100000;i++)
    {
        long long temp=i;
        int p=i;
        while(p){
            temp=temp*10+p%10;
            p/=10;
        }
        a[++cnt]=temp;
    }
}

int main ()
{
	init();
	long long k,p;
	cin >>k >> p;
	int i = 1;
	long long sum = 0;
	long long temp;
	for (int i =1; i < 100000; ++i)
		cout << a[i] << endl;
	for (int i = 1; i <= k; ++i)
	{
		sum += a[i];
		sum %= p;
	}
	cout << sum << endl;
	return 0;
 }


#include <bits/stdc++.h>

using namespace std;
typedef long long int64;

int64 sol, n, mod;
int64 p[25];

bool ok (int a){
     int b = a;
     int con = 0;
     vector <int> v;
     while (b > 0){
		   v.push_back (b%10);
		   b /= 10, con++;
	 }

     if (con%2) return false;

     while (!v.empty())
            if (*v.begin() != *v.rbegin()) return false;
             else{
			    v.erase (v.begin());

			    v.pop_back();
			 }

	return true;
}

int main(){

	p[0] = 1;
	for (int i = 1; i <= 15; i++) p[i] = p[i-1]*10ll;

	vector <pair <int64, int>> v;
	v.push_back ({0, 2});
	for (int i = 11; i < 100; i++){
	    if (ok (i))
	        v.push_back ({i, 2});
	}

	int p1 = 0;
	for (int i = 0; i < 1000000; i++){
	     auto a = v[p1++];
	     for (int64 j = 1; j <= 9; j++){
		      int64 x = (a.first * 10ll + j) + (p[a.second+1] * j);
		      v.push_back ({x,a.second+2});
		 }
	}

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

	//for (int i = 1; i <= 100; i++) printf ("%lld\n", v[i].first);

	scanf ("%lld %lld", &n, &mod);
	for (int i = 1; i <= n; i++){
		 sol = (sol+v[i].first) % mod;
	     //printf ("%d %lld\n", i, v[i].first);
	}
	printf ("%lld\n", sol);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef double db;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll mINF = 1000 * 1000 * 1000 + 9;
const db ebs = 0.000001;

int main()
{
    /*
    freopen("", "r", stdin);
    freopen("", "w", stdout);
    */

    int kol_vo, del;
    cin >> kol_vo >> del;
    vector<int> v;
    v.push_back(0);
    for(int c=10; c<100; c++)
        if(c == (c%10)*10+c/10)v.push_back(c);
    int j = 0, now = 100, last = 10, p = 1;
    while(v.size()-p < kol_vo){
        int dop = 0;
        for(int c=j; c<=v.size(); c++){
            for(int i=0; i<=9; i++){
                v.push_back(i*now+v[c]*(now/10)+i);
                if(i*now+v[c]*(now/10)+i == 0)p++;
                dop++;
            }
        }
        j = last;
        last += dop;
        now*=100;
    }
    ll sum=0, n=0, c=0;
    while(n < kol_vo){
        if(v[c]){
            sum += v[c];
            sum %= del;
            n++;
        }
        c++;
    }
    cout << sum;
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<iterator>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>

using namespace std;

#define ll long long int
#define ull unsingned long long int
#define pi 2*acos(0.0)

int main()
{
    ll t,cases=1;
    char a[1000],b[1000];
    while(true)
    {
        scanf("%s %s",a,b);
        puts(a);
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   ll a,b,i;
   ios_base::sync_with_stdio(false);
   cin>>a>>b;
   ll ans=0;
   if(a!=b)
    ans=__gcd(a,a+1);
   else{
       ans=a;
       cout<<a<<endl;
       return 0;
   }

   for(i=a+2;i<=b;i++)
   {
      ans=__gcd(ans,i);
      if(ans==1)
        break;
    if(i==1000000)
        break;
   }
   cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
   ll a,b,i;
   ios_base::sync_with_stdio(false);
   cin>>a>>b;
   ll ans=0;
   if(a!=b)
    ans=__gcd(a,a+1);
   else{
       ans=a;
       cout<<a<<endl;
       return 0;
   }

   for(i=a+2;i<=b;i++)
   {
      ans=__gcd(ans,i);
      if(ans==1)
        break;
   }
   cout<<ans<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
using namespace std;
char a[205],b[205];
int main(){
	scanf("%s%s",a,b);
	if(strlen(a)!=strlen(b)){
		printf("1");
		return 0;
	}
	for(int i=1;i<=strlen(a);i++)if(a[i]!=b[i]){
		printf("1");
		return 0;
	}
	printf("%s",a);
}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
//
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll k , ans = INF ;
vector<ll> a,  b;
string c = "codeforces";
void dfs(){
    ll s = 1 , q = 0;
    for(int i = 0 ; i < 10 ; i++){
        s *= a[i];
        q += a[i];
    }
     if(s>=k){
        if(q < ans){
            ans = q;
            b = a;
        }
    }
    else {
        for(int  i = 0 ; i < 10 ; i ++){
            if(a[i]+1<=19){
                 a[i]++;
                 dfs();
                 if(a[i]-1>0) a[i]--;
               }
        }
    }
}
int main(){
    cin >> k;
    ll x = 1;
    while(pow(x,10) < k){
        x++;
        if(pow(x,10) > k) { x-=1; break;}
    }
    for(int i = 1 ; i<= 10 ; i++) a.pb(x);
    dfs();
    for(int i = 0 ; i <c.size() ; i++){
        for(int j = 0 ; j <b[i]; j++){
            cout << c[i] ;
        }
    }
    // cout << b.size() << "\n";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define T int t;cin>>t;while(t--)
#define pb push_back

int main()
{
    ll c[11],i,n,j,p;
    vector<ll>v;
    map<ll,ll>m;
    cin>>n;
    for(i=1;i<=10;i++)
    c[i]=1;
    j=sqrt(n);
    p=pow(n,0.1);
    for(i=2;i<=j;i++)
    {
        if(n%i==0)
        {
            v.push_back(i);
            while(n%i==0)
            {
                n=n/i;
                m[i]++;
            }
        }
        if(n==1)
        break;
    }
    if(n!=1)
    {
        v.push_back(n);
        m[n]++;
    }
    sort(v.begin(),v.end());
    i=1;
    for(j=v.size()-1;j>=0;j--)
    {
        n=v[j];
        while(m[n])
        {
            if(c[i]<=p)
            {
                c[i]=c[i]*n;
                m[n]--;
            }
            if(m[n]==0)
            break;
            i++;
            if(i==11)
            i=1;
        }
    }
    while(c[1]--)
    cout<<'c';
    while(c[2]--)
    cout<<'o';
    while(c[3]--)
    cout<<'d';
    while(c[4]--)
    cout<<'e';
    while(c[5]--)
    cout<<'f';
    while(c[6]--)
    cout<<'o';
    while(c[7]--)
    cout<<'r';
    while(c[8]--)
    cout<<'c';
    while(c[9]--)
    cout<<'e';
    while(c[10]--)
    cout<<'s';
    ////
}


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;

/*
    if you have any question about any part of my code,
    please don't shy to ask anytime :)
*/

void solve()
{
    ll n;
    cin >> n;
    vector<ll> x(10, 1);
    string ans = "codeforces";

    ll cnt=0;
    while (true)
    {
        ll p = 1;
        for(int i=0;i<n;i++)
        {
            p*=x[i];
        }

        if(p>=n)
        {
            break;
        }

        x[cnt]++;
        cnt++;
    }

    for (int i = 0; i < 10; i++)
    {
        while (x[i]--)
        {
            cout << ans[i];
        }
    }
    cout << endl;
}

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

    // ll t;
    // cin >> t;
    // while (t--)
    // {
    //     solve();
    // }
    solve();
    return 0;
}


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

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

	ll t;
	cin>>t;
	cout<<"codeforces";
	if(t>=2)
	{ t/=2;

	while(t--)
	{
		cout<<"es"<<endl;
	}

}
}


#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <utility>

using namespace std;

#define in cin
#define out cout
#define dout if(true) cout

typedef long long num;

int main()
{
	num n,m,a,b;
	in >> n >> m >> a >> b;

	a--;b--;	//indexing from 0;

	int ans = 3;
	if ((a/m) == (b/m)){
		ans = 1;	//same row
	}
	else if (((a%m) == 0) && ((b%m) == (m-1))){
		ans = 1;
	}
	else if (((a%m) == 0) || ((b%m) == (m-1))){
		ans = 2;
	}
	else if ((a%m) == ((b%m) + 1)){
		ans = 2;
	}else if ((a/m) == ((b/m)-1)){
		ans = 2;
	}
	else{
		//int top = m-(a%m);
		//int bottom = (b%m)+1;
		throw "magic";
		num next_row = (a/m)+1;
		num last_row = (b/m);
		num rows = last_row - next_row;

		if (rows < 0) rows = 0;

		ans = 3;
		//if (rows > 0) ans ++;
		//dout << top << " " << bottom << " " << rows << endl;
	}

	out << ans << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define				pb	push_back
#define	 present(x, c)	((c).find(x) != (c).end()) 			// used for map and set. //
#define		forn(i, n)	for(int i = 0; i < n; i++)
#define             S   scanf
#define             P   printf

int main()
{
    int n,m,a,b;
    cin>>n>>m>>a>>b;
    int ans;

        if(b/m == a/m) ans =1;

        else
        if((b/m) - (a/m) ==1)
        {
                 if(a%m==1 && b%m==0) ans=1;
                 else ans=2;
        }

        else
        {
            ans=3;

            if(a%m == 1) ans--;

            if(b%m == 0 || b==n) ans--;

            if((b%m) == (a%m)-1) if(ans==3) ans=2;
        }
    cout<<ans;

  system("pause");
  return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
const int N=1e5+9;
#define inf N
char str[N];
int k,cnt;
bool mark[30];
struct xx
{
    int id,n;
    bool operator <(const xx &c)const
    {
        return n<c.n;
    }
}a[30];
int main()
{
    //freopen("1.txt","r",stdin);
    while(~scanf("%s%d",str,&k))
    {
        int l=strlen(str);
        for(int i=0;i<26;i++)
        {
            a[i].id=i;
            a[i].n=inf;
        }
        cnt=0;memset(mark,false,sizeof(mark));
        for(int i=0;i<l;i++)
        {
            int t=str[i]-'a';
            if(!mark[t])
            {
                cnt++;a[t].n=0;
                mark[t]=true;
               // printf("stri:%c \n",str[i]);
            }
            a[t].n++;
        }
        sort(a,a+26);
        //printf("inft:%d\n",inf);
        int tt=cnt;
        for(int i=0;i<tt;i++)
        {
            //printf("ain:%d %c %d\n",a[i].n,'a'+a[i].id,k);
            if(a[i].n<=k)
            {
                k-=a[i].n;
                cnt--;
                mark[a[i].id]=false;
            }
           // else break ;
        }
        printf("%d\n",cnt);
        for(int i=0;i<l;i++)
        {
            int t=str[i]-'a';
            if(mark[t])
                printf("%c",str[i]);
        }
        puts("");
    }
}


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

#define PB push_back
#define MP make_pair

#define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i)

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
template <class X> X gcd(X a, X b) {return b == 0 ? a : gcd(b, a % b);}

int main() {
    int T;
	//scanf("%d", &T);
	T = 1;
	while (T--) {
		int n, m, a, b;
		scanf("%d%d%d%d", &n, &m, &a, &b);
		--a;
		--b;
		int row1 = a / m;
		int col1 = a % m;
		int row2 = b / m;
		int col2 = b % m;
		int ret;
		if (row1 == row2) {
			ret = 1;
		} else if (row2 - row1 == 1) {
			ret = 2;
			if (col1 == 0 && col2 == m - 1) {
				ret = 1;
			}
		} else {
			if (col1 < col2) {
				ret = 3;
				if (col1 == 0) {
					--ret;
				}
				if (col2 == m - 1 ||  b == n - 1) {
					--ret;
				}
			} else if (col1 == col2) {
				ret = 3;
				if (col1 == 0) {
					--ret;
				}
				if (col2 == m - 1 || b == n - 1) {
					--ret;
				}
			} else if (col1 > col2){
				ret = 3;
				if (col1 - col2 == 1 || b == n - 1) {
					ret = 2;
				}
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define SZ(x) ((int)(x.size()))
#define fi first
#define se second
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define IN(x,y) ((y).find((x))!=(y).end())
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define DBG cerr << "debug here" << endl;
#define DBGV(vari) cerr << #vari<< " = "<< (vari) <<endl;

typedef long long ll;
const int INF = 1e9;

bool make_fall(vector<int>& a) {
    int iters = 0;
    while (1) {
        bool found = false;
        for (int i = 0; i+1 < a.size(); ++i) {
            if (a[i] >= a[i+1]+2) {
                a[i]--;
                a[i+1]++;
                found = 1;
                break;
            }
            if (a[i+1] >= a[i]+2) {
                a[i+1]--;
                a[i]++;
                found = 1;
                break;
            }
        }
        ++iters;
        if (iters > 200) {
            return true;
        }
        if (!found) break;
    }
    return false;
}
void print(const vector<int>& a) {
    cout << "############" << endl;
    for (auto e : a) {
        cout << e << " ";
    }
    cout << endl;
    cout << "############" << endl;
}
int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector<int> b = a;
    sort(b.begin(), b.end());
    int last = n-1;
    while (1) {
        bool loop = make_fall(a);
        if (loop) {
            cout << "NO" << endl;
            return 0;
        }
        bool done = true;
        for (int i = 0; i+1 < n; ++i) {
            if (a[i] > a[i+1]) {
                done = false;
                break;
            }
        }
        if (done) {
            break;
        }
        int m_idx = 0;
        for (int i = 1; i <= last; ++i) {
            if (a[i] > a[m_idx]) {
                m_idx = i;
            }
        }
        int tmp = a[m_idx];
        for (int i = m_idx; i < last; ++i) {
            a[i] = a[i+1];
        }
        a[last] = tmp;
        --last;
        loop = make_fall(a);
        if (loop) {
            cout << "NO" << endl;
            return 0;
        }
    }
    bool loop = make_fall(a);
    if (loop) {
        cout << "NO" << endl;
        return 0;
    }
    cout << (a == b ? "YES" : "NO") << endl;
    return 0;
}


#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <ctime>
#include <queue>
#include <list>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

bool isSort(const vector<int> &a, int n) {
	for (int i = 1; i < n; i++) {
		if (a[i - 1] >= a[i])
			return false;
	}
	return true;
}

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

	vector<int> arr(n);
	cin >> arr[0];
	for (int i = 1; i < n; i++) {
		cin >> arr[i];
		if (abs(arr[i - 1] - arr[i]) >= 2) {
			cout << "NO";
			return 0;
		}
	}

	int offset = 0;
	while (!isSort(arr, n)) {
		int maxx = -(1 << 30), indMax = -1;
		for (int i = offset; i < n; i++)	{
			if (arr[i] > maxx) {
				maxx = arr[i];
				indMax = i;
			}
		}
		offset++;
		arr.erase(arr.begin() + indMax);
		arr.insert(arr.begin(), maxx);

		for (int i = 1; i < n; i++) {
			if (abs(arr[i - 1] - arr[i]) >= 2) {
				cout << "NO";
				return 0;
			}
		}
	}

	cout << "YES";
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n; cin >> n;
    vector<int>v;
    for (int i=0 ; i<n ; i++)
    {
        cin >> v[i];
        if (i && abs(v[i]-v[i-1])>1)
            return cout << "NO", 0;
    }
    cout << "YES";
    return 0;
}


#include<iostream>
#include<algorithm>
typedef unsigned long long ull;
using namespace std;
int n,cnt,m,a[100000000];
int main(){
	cin>>n;
	for(int i=1;i<n;i++) {
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(int i=1;i<n-1;i++){
		if(a[i]>a[i+1]){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n, k;
vector<ll>v;
int main() {
	scanf("%I64d %I64d", &n, &k);
	if (n <= k && n > 1) {
		printf("%d", 1);
		return 0;
	}
		for (int i = 0; i <= k; i++) {
			if (i == 1)
				continue;
			v.push_back(i);
		}
		int cnt = 1;
		for (unsigned i = 1; i <v.size(); i++) {
			if (i > 1) {
				v[i] += v[i - 1];
			}
			else
				v[i] += (v[i - 1]);
		}
		for (unsigned i = 2; i < v.size(); i++) {
			v[i] -= cnt++;
		}
		int s = 0, e = v.size()-1, ans;
		while (s < e) {
			int mid = s + (e - s + 1) / 2;
			if (v[mid] == n) {
				e = mid - 1;
				ans = mid;
			}
			else {
				s = mid;
				ans = -1;
			}
		}
		cout << ans << endl;

	return 0;
}


# include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
int bs(long long int n,int s,int e){
	int mid = (s+e)/2;
	cout << v[mid] << " " << mid << " " << s << " " << e << endl;
	if(s<=e){
		if(v[mid]<n-1 && v[mid+1]>=n-1){
			return mid;
		}
		else if(v[mid]<n-1 && v[mid+1]<n-1){
			return bs(n,mid+1,e);
		}
		else{
			return bs(n,s,mid);
		}

	}
	else{
		return -1;
	}
}
int main(){
	long long int n;
	long long int k_;
	// long long int k_ = (long long int)k;
	cin >> n >> k_;
	if(n==1){
		cout << 0;
	}
	else if(n-1 > (k_*(k_-1))/2){
		// cout << (k*(k-1))/2;
		cout << -1;
	}
	else if(n-1 == (k_*(k_-1))/2){
		cout << k_-1;
	}
	else if(n==k_){
		cout << 1;
	}
	else{
		int k= (int) k_;
		v.push_back(k-1);
		for(int i=1;i<k-1;i++){
			v.push_back(v[i-1]+ (k-i-1));
		}
		// for(int i=0;i<v.size();i++){
		// 	cout << v[i] << " ";
		// }
		// cout << endl;
		if(bs(n,0,v.size()-1)==-1){
			cout << -1;
		}
		else
		cout << bs(n,0,v.size()-1)+2;
	}
}


# include <bits/stdc++.h>
using namespace std;
int mini = INT_MAX;
void f(int count,int left,int k_){
	// cout << count << " " << left << endl;
	if(left==0){
		if(count<mini){
			mini = count;
		}
	}
	if(left>0){
		for(int i=k_;i>=2;i--){
			if(count==0){
				f(count+1,left-i,k_-1);
				f(count,left,k_-1);
			}
			else{
				f(count+1,left-i+1,k_-1);
				f(count,left,k_-1);
			}
		}
	}
}

int main(){
	long long int n,k;
	cin >> n >> k;
	f(0,n,k);
	if(mini==INT_MAX){
		cout << -1;
	}
	else{
		cout << mini;
	}
}


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

main()
{
    long long int n,sum=0;
    int i=0,x=0,last=0,l=0,k=0;
    scanf("%I64d",&n);
    scanf("%d",&k);
    if(n==1)
    {
        printf("0");
        return 0;
    };
    l=1;
    while(1)
    {
        last=l;
        sum=(l+k)*(k-l)/2;
        if(sum==n)
        {
            printf("%d",(k-l));
            return 0;
        }else
        {
            if(sum>n)
            {
                l=(l+k)/2;
                if(l==last+1)
                {
                    printf("%d",(k-l));
            return 0;
                }
            }else
            {
                 l=(l+1)/2;
            }
        };
        printf("%d %d\n",l,last);
        getch();
        if(last==l)
        {
            printf("-1");
            return 0;
        }
    }
}


#include<bits\stdc++.h>

using namespace std;

#define pb push_back
#define pf push_front

#define ll long long
#define ld long double

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()

#define int ll
#define double ld

#define yes cout<<"YES\n";
#define no cout<<"NO\n";

const int N=2e5+100;

int n,a[105],sum,g,ind;
int memo[101][2000001];

bool dp(int i,int s){

        if(i==n+1&&s&&s*2==g)return 1;
        if(i==n+1)return 0;

        int &ans=memo[i][s];
        if(ans!=-1)return ans;
        ans=dp(i+1,s);
        ans|=dp(i+1,s+a[i]);

        return ans;
}

void solveg(int testi){

    cin>>n;

    sum=0;

    int mn=1e18;
    int indmn=-1;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
        mn=min(mn,a[i]);
        if(a[i]==mn)indmn=i;
    }
    memset(memo,-1,sizeof memo);
    g=sum;
    if(!dp(1,0)){
        cout<<"0\n";
        return ;
    }
    cout<<"1\n"<<indmn<<endl;

}

main(){
    //freopen("machines.in", "r", stdin);
    int test=1;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.tie(NULL);

  //  cin>>test;
    for(int testi=1;testi<=test;testi++){
        solveg(testi);
       // _clear();
    }
}


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

using namespace std;
// using namespace __gnu_pbds;

//#define endl            "\n"
#define ll              long long
#define int             long long
#define ff              first
#define ss              second
#define fl(i,a,b)       for(int i=(int)a; i<(int)b; i++)
#define bfl(i,a,b)      for(int i=(int)a-1; i>=(int)b; i--)
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vt(type)        vector<type>
#define you_can_do_it     ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define mii             map<int,int>
#define pqb             priority_queue<int>
//Below is implementation of min heap
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define ini             const int
#define sz(v)           ((int)(v).size())
#define ppii            pair<int,pii>
#define tup             tuple<int,int,int>
#define LEFT(x)         2*x+1
#define RIGHT(x)        2*x+2
#define all(v)            v.begin(),v.end()
#define rall(v)            v.rbegin(),v.rend()

const double pi = acos(-1.0);

#define PRINT(x)        {print(x); return;}
#define FOR(v)            fl(i,0,(int)v.size())   read(v[i]);
#define FOR1(v)            fl(i,1,(int)v.size()+1) read(v[i]);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout<<endl;}

//void err(istream_iterator<string> it) {}
//template<typename T, typename... Args>
//void err(istream_iterator<string> it, T a, Args... args) {
//    cerr << *it << " = " << a << "  , ";
//    err(++it, args...);
//}
//
//template<typename... T>
//void print(T...args){
//    ((cout<<args<<" "),...);
//}
//
//template<typename... T>
//void read(T&...args){
//    ((cin>>args),...);
//}

/////// \|/ \|/ Credits: okwedook for template below \|/ \|/ ////////
template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.ff >> p.ss; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
/////////////////////////////////////////////////////////////////////

/*

Credits : owen_up

SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x - 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit

*/

//1,2 ,3  ,4,  ,5     ,6      ,7       ,8        ,9         ,10 digit prime
//1,11,101,1187, 11489, 109229, 1000003, 10000019, 100000007, 1000000007
//1,13,127,1009, 10007, 100003, 1000033, 10000079, 100000037, 1000000009

void solve(int tc)
{
    int n;
    cin>>n;
    vector<int> v;
    int total = 0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        total+=x;
        v.pb(x);
    }
    if(total&1){
        cout<<0<<endl;
        return;
    }
    vector<vector<vector<int>>> dp(n+2,vector<vector<int>>(2,vector<int>(total+2,-1)));
    std::function<int(int,int,int,vector<int>&)> f = [&](int i, int take, int sum, vector<int> &cur){
        if(dp[i][take][sum]!=-1) return dp[i][take][sum];
        if(sum==0) return dp[i][take][sum] = true;
        if(i+1>=n) return dp[i][take][sum] = false;
        if(sum<0) return 0ll;
//        cout<<i<<endl;
        if(take){
            cur.pb(i);
            if(f(i+1,0,sum-v[i],cur)) return dp[i][take][sum] = true;
            if(f(i+1,1,sum-v[i],cur)) return dp[i][take][sum] = true;
            cur.pop_back();

        }
        else{
//            cur.pb(i);
            if(f(i+1,0,sum,cur)) return dp[i][take][sum] = true;
            if(f(i+1,1,sum,cur)) return dp[i][take][sum] = true;
//            cur.pop_back();
        }
        return dp[i][take][sum] = false;
    };
    vector<int> temp;
    bool val = f(0,1,total/2,temp);
    val = val || f(0,0,total/2,temp);
    if(val){
        set<int> w;
        for(auto ele:temp) w.insert(ele);
        vector<int> temp2;
        for(auto ele:temp){
            if(v[ele]&1){
                cout<<1<<endl;
                cout<<ele+1<<endl;
                return;
            }
        }
        for(int i=0;i<n;i++){
            if(!w.count(i)){
                temp2.pb(i);
            }
        }
        set<int> diff;
        for(auto ele:temp){
            for(auto ele2:temp2){
                diff.insert(abs(ele-ele2));
            }
        }
        for(int i=0;i<n;i++){
            if(!diff.count(v[i])){
                cout<<1<<endl;
                cout<<i+1<<endl;
                return;
            }
        }
    }
    else{
        cout<<0<<endl;
    }
//    cout<<"****** "<<endl;
//    for(auto ele:temp) cout<<ele<<" ";
//    cout<<endl;
}

int32_t main()
{
    you_can_do_it
    int t=1;
//    cin>>t;
    for(int i=1;i<=t;i++){
        solve(i);
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define SORT(v) sort(all(v))
#define int long long
#define ff first
#define ss second
#define mod 1000000007
#define endl "\n"

using namespace std;

void oj()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
}

int n;
vector<int>v;
int dp[101][500000];
int find(int x, int sum)
{
  if(x == n)
  {
    if(sum == 0)
      return 0;
    else
      return 1e15;
  }

  if(dp[x][sum + 200001] != -1)
    return dp[x][sum + 200001];
  return dp[x][sum + 200001] = min({1 + find(x + 1, sum), find(x + 1, sum - v[x]), find(x + 1, sum + v[x])});
}
void solve()
{
  cin>>n;
  v = vector<int>(n);

  for(int i = 0; i < n; i++)
    cin>>v[i];

  int temp = find(0, 0);
  if(temp == 0)
    cout<<1<<"\n"<<1;
  else
    cout<<0;
}
signed main()
{
  oj();
  // int t; cin>>t;
  // while(t--)
    solve();

  return 0;
}


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

#define ff              first
#define ss              second
#define pb              push_back
#define int             long long
#define mp              make_pair
#define pr              pair<long long,long long>
#define vr              vector<long long>
#define MOD          1000000007
#define mod         1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
#define fill(a,b)       memset(a, b, sizeof(a))
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

bool findPartiion(vector<int> arr, int n)
{
    int sum = 0;
    int i, j;
    for (i = 0; i < n; i++)
        sum += arr[i];

    if (sum % 2 != 0)
        return false;

    bool part[sum / 2 + 1][n + 1];

    for (i = 0; i <= n; i++)
        part[0][i] = true;

    for (i = 1; i <= sum / 2; i++)
        part[i][0] = false;

    for (i = 1; i <= sum / 2; i++) {
        for (j = 1; j <= n; j++) {
            part[i][j] = part[i][j - 1];
            if (i >= arr[j - 1])
                part[i][j] = part[i][j]
                             || part[i - arr[j - 1]][j - 1];
        }
    }
    return part[sum / 2][n];
}

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

   int a[n];
   int sum=0;
   vector<int>v1;
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
       v1.pb(a[i]);
       sum+=a[i];

   }
   if(sum%2==1 || findPartiion(v1,n)==false){
       cout<<0<<"\n";
   }
   else{
   cout<<1<<"\n";

   for(int i=0;i<n;i++){
       vector<int>v;
       for(int j=0;j<n;j++){
           if(i!=j)v.pb(a[j]);
       }

       if(findPartiion(v,n-1)==false){
           cout<<i+1<<"\n";
           break;

       }
   }
   }
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	long n, k, ans;
	cin >> n >> k;
	ans = (n * 2) / k + (n * 5) / k + (n * 8) / k;
	if ((n * 2) % k != 0)
		ans++;
	if ((n * 5) % k != 0)
		ans++;
	if ((n * 8) % k != 0)
		ans++;
	cout << ans;
	system("pause");

	return 0;

}


#include<bits/stdc++.h>

using namespace std;
typedef unsigned long long  ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<bool> vb;

ull GCD(ull a, ull b){return b == 0 ? a : GCD(b, a % b); }
ull LCM(ull a, ull b){ return a * (b / GCD(a, b)); }

void re(double& x) { string s; cin >> s; x = stold(s); }
int main(){

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

	double n, k;
	re(n); re(k);

	vi need(n);
	need = {n * 2, n * 5, n * 8};

	ull ans = 0;
	for(auto i : need) ans += i / k + (i % (int)k != 0);

	cout << ans << endl;

}


#include<bits/stdc++.h>

using namespace std;
typedef unsigned long long  ull;
typedef long double ld;
typedef vector<long int> vi;
typedef vector<bool> vb;

ull GCD(ull a, ull b){return b == 0 ? a : GCD(b, a % b); }
ull LCM(ull a, ull b){ return a * (b / GCD(a, b)); }

void re(double& x) { string s; cin >> s; x = stold(s); }
int main(){

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

	long int n, k;
	cin >> n >> k;

	vi need(n);
	need = {n * 2, n * 5, n * 8};

	int ans = 0;
	for(int i : need) ans += (i / k) + (i % k != 0);

	cout << ans << endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    float n,k;
    cin>>n >>k;
    float red=n*2;
    float green=n*5;
    float blue=n*8;
    int book1=ceil(red/k);
    int book2=ceil(green/k);
    int book3=ceil(blue/k);
    cout<<book1+book2+book3<<endl;
    return 0;

}


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

int main(){
    string s;
    cin>>s;
int count=0;
    for(int i=0;i<s.size();i++){
        int x=(s[i]-65)+1;
        if(x==1 ||s==2||x==3||x==5||x==8||x==13||x==21){
            count++;
        }

    }
    if(count>1){
        cout<<"YES"<<endl;
    }
    else
    cout<<"NO"<<endl;

   return 0;
}


/*
	Orz p_b_p_b
	Orz athousandsuns
	Orz 苹果蓝17
	Orz watermoon

	每个女孩都是一个无泪天使，
	当天使爱上男孩便有了眼泪，
	天使落泪坠落凡间，
	所以每个男孩都不该辜负你的女孩，
	因为她曾为了放弃了整个天堂。
						--《凡人修仙传》

	他为了她，
	可以付出自己的生命，
	自杀取骨。

	她为了他，
	可以燃烧自己的生命，
	献祭魂环。
						--《斗罗大陆》
*/
#include<bits/stdc++.h>
namespace pai{
	#define fi first
	#define se second
	#define pii pair<int,int>
	#define pll pair<ll,ll>
	#define psl pair<string,ll>
	#define pcc pair<char,char>
	#define mp(i,j) make_pair(i,j)
}
namespace vec{
	#define vei vector<int>
	#define si size()
	#define em empty()
	#define pd(i) push_back(i)
	#define pb pop_back()
}
namespace my_std{
	using namespace std;
	#define ll long long
	#define ref(i,x,y) for(register int i=(x);i<=(y);i++)
	#define fer(i,x,y) for(register int i=(x);i>=(y);i--)
	#define il inline
	#define mpii map<int,int>
	#define mpib map<int,bool>
	#define mpplll map<pll,ll>
	#define mppccl map<pcc,ll>
	#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
	char buf[1 << 21], *p1 = buf, *p2 = buf;
	inline ll read() {
	    char c = getchar();
	    ll x = 0;
	    for (; !isdigit(c); c = getchar()) ;
	    for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	    return x;
	}
}

using namespace my_std;
string s;
int main(){
//	cin.tie(0),cout.tie(0);
//	ios::sync_with_stdio(false);
//	while(getline(cin,s)) cout<<"NO\n";
//	int n;
//	cin>>n;
//	cout<<n%10+n/10;
//	int fib[114514]={0};
//	char ch;
//	int cnt = 0;
//	while (cin >> ch) {
//		int y = ch - 65;
//		fib[++cnt] = y;
//	}
//	for (int i = 3; i <= cnt; i++) {
//		if (fib[i] != fib[i - 1] + fib[i - 2]) {
//			cout << "NO" << endl; return 0;
//		}
//	}
//	cout << "YES";
	string st;
	cin>>st;
	for(int i=0;i<st.size();i++)
	{
		st[i]-=65;//转化为编码
		if(i>1&&st[i]!=(st[i-1]+st[i-2])%26)//从第三位开始处理，相加的和要对26取模
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
const int inf = 2e9;
const ll INF = 9e18;
const ll mod = 1e9+7;

#define int ll //
#define F first
#define S second
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define vpi vector<pi>
#define pb push_back
#define read(a) for(auto &x:a) cin >> x;
#define print(a) for(auto x:a) cout << x << " "; cout << "\n";

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    string s; cin >> s;
    bool ok = true;
    for(int i=2; i<s.size() && ok; i++){
        if((s[i]-'A') != ((s[i-1]-'A')+(s[i-2]-'A'))%26) ok = false;

    cout << (ok ? "YES\n" : "NO\n");
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    string a;
    int i, x,y,z,h;
    cin.getline(a);
    bool flag=true;
    for(i=2;i<a.length();i++)
    {
        y=a.at(i-1);
        z=a.at(i-2);
        h=a.at(i);
        x=y+z;
        if(x>26)
        x=x-26;
        if(x==h)
        {
            continue;
        }
        else
        {
            flag=false;
            break;
        }
    }
    if(flag==true)
    cout<<"YES";
    else
    cout<<"NO";
}