import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    struct rect { int x1, y1, x2, y2; }
    rect[] rs = new rect[] (n);
    foreach (i; 0 .. n) {
        readf("%s %s %s %s", &rs[i].x1, &rs[i].y1, &rs[i].x2, &rs[i].y2);
        readln;
    }

    debug { rs.writeln; }

    immutable int INF = 10 ^^ 9;
    int sx1 = INF, sy1 = INF, sx2 = -INF, sy2 = -INF;
    int rectArea = rs.map!(r => (r.y2 - r.y1) * (r.x2 - r.x1)).sum;

    foreach (r; rs) {
        sx1 = min(sx1, r.x1);
        sy1 = min(sy1, r.y1);
        sx2 = max(sx2, r.x2);
        sy2 = max(sy2, r.y2);
    }

    if (sy2 - sy1 != sx2 - sx1) {
        writeln("NO");
        return;
    }

    int area = (sy2 - sy1) * (sx2 - sx1);
    if (area != rectArea) {
        writeln("NO");
        return;
    }

    writeln("YES");
}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    struct rect { int x1, y1, x2, y2; }
    rect[] rs = new rect[] (n);
    foreach (i; 0 .. n) {
        readf("%s %s %s %s", &rs[i].x1, &rs[i].y1, &rs[i].x2, &rs[i].y2);
        readln;
    }

    debug { rs.writeln; }

    immutable int INF = 10 ^^ 9;
    int sx1 = INF, sy1 = INF, sx2 = -INF, sy2 = -INF;

    foreach (r; rs) {
        sx1 = min(sx1, r.x1);
        sy1 = min(sy1, r.y1);
        sx2 = max(sx2, r.x2);
        sy2 = max(sy2, r.y2);
    }

    if (sy2 - sy1 != sx2 - sx1) {
        writeln("NO");
        return;
    }

    int rectArea = rs.map!(r => (r.y2 - r.y1) * (r.x2 - r.x1)).sum;
    int sqArea = (sy2 - sy1) * (sx2 - sx1);
    if (rectArea != sqArea) {
        writeln("NO");
        return;
    }

    writeln("YES");
}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    struct rect { int x1, y1, x2, y2; }
    rect[] rs = new rect[] (n);
    foreach (i; 0 .. n) {
        readf("%s %s %s %s", &rs[i].x1, &rs[i].y1, &rs[i].x2, &rs[i].y2);
        readln;
    }

    debug { rs.writeln; }

    immutable int INF = 10 ^^ 9;
    int sx1 = INF, sy1 = INF, sx2 = -INF, sy2 = -INF;
    int rectArea = rs.map!(r => (r.y2 - r.y1) * (r.x2 - r.x1)).sum;

    foreach (j; 0 .. n) {
        sx1 = min(sx1, rs[j].x1);
        sy1 = min(sy1, rs[j].y1);
        sx2 = max(sx2, rs[j].x2);
        sy2 = max(sy2, rs[j].y2);
    }

    if (sy2 - sy1 != sx2 - sx1) {
        writeln("NO");
        return;
    }

    int area = (sy2 - sy1) * (sx2 - sx1);
    if (area != rectArea) {
        writeln("NO");
        return;
    }

    writeln("YES");
}

import std.stdio : write, writeln;
import std.array;
import std.range;
import std.typecons;
import std.bigint;
import std.algorithm;

const int INF = 1<<28;

int n;
int[4][] ps;
int[2][] p;
bool ans = false;

void make( int depth, int end, int i ){
	if( depth == end ){
		solve( depth );
		return;
	}
	for( int j = i; j < n; ++j ){
		auto tmp = p.clone;
		p ~= [ ps[ j ][ 0 ], ps[ j ][ 1 ] ];
		p ~= [ ps[ j ][ 2 ], ps[ j ][ 1 ] ];
		p ~= [ ps[ j ][ 0 ], ps[ j ][ 3 ] ];
		p ~= [ ps[ j ][ 2 ], ps[ j ][ 3 ] ];
		make( depth + 1, end, j + 1 );
		assert( tmp !is p );
		p = tmp.clone;
	}
}

void solve( int s ){
	bool[int[2]] data;
	for( int i = 0; i < s*4; ++i ){
		bool f = false;
		for( int j = 0; j < s*4; ++j ){
			if( i == j )continue;

			assert( p[ i ] !is p[ j ] );
			f |= p[ i ] == p[ j ];
		}
		if( !f ){
			data[ p[ i ] ] = true;
		}
	}

	if( data.keys.length == 4 ){
		int min_x = INF, min_y = INF, max_x = 0, max_y = 0;
		foreach( v; data.keys ){
			min_x = min( min_x, v.front );
			min_y = min( min_y, v.back );
			max_x = max( max_x, v.front );
			max_y = max( max_y, v.back );
		}
		int[2] cntx, cnty;
		foreach( v; data.keys ){
			if( v.front == min_x )++cntx[0];
			if( v.front == max_x )++cntx[1];
			if( v.back  == min_y )++cnty[0];
			if( v.back  == max_y )++cnty[1];
		}
		ans |= (cntx == [ 2, 2 ] && cnty == [ 2, 2 ] && (max_x - min_x) == (max_y - min_y) );
	}
}

void main(){
	n = next!int;

	foreach( i; n.iota ){
		int x1 = next!int;
		int y1 = next!int;

		int x2 = next!int;
		int y2 = next!int;

		ps ~= [x1, y1, x2, y2];
	}

/+
	for( int s = 1; s <= n; ++s ){
		p = p.init;
		make( 0, s, 0 );
	}
+/
	p = p.init;
	make( 0, n, 0 );

	writeln = ans ? "YES": "NO";
}

import std.stdio : readln;
import std.conv : to;
import std.string : split, chomp;
import std.traits;
string[] input;
string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

T next( T : char )()
in
{
	assert(hasNext());
}
out
{
	input.front.popFront;
}
body
{
	return input.front.front.to!T;
}

bool hasNext(){
	if(input.length > 0){
		if(input.front.length == 0){
			input.popFront;
			return hasNext;
		}
		return true;
	}

	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return hasNext;
	}else{
		return false;
	}
}

void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}

	return v_;
}

import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		alias Tuple !(long, "x", long, "y") point;
		alias Tuple !(point, "a", point, "b") rect;
		auto r = new rect [n];
		auto t = rect (point (int.max, int.max),
		               point (int.min, int.min));
		long s = 0;
		foreach (i; 0..n)
		{
			readf (" %s %s %s %s", &r[i].a.x, &r[i].a.y,
			                       &r[i].b.x, &r[i].b.y);
			s += (r[i].b.x - r[i].a.x) * (r[i].b.y - r[i].a.y);
			t.a.x = min (t.a.x, r[i].a.x);
			t.a.y = min (t.a.y, r[i].a.y);
			t.b.x = max (t.b.x, r[i].b.x);
			t.b.y = max (t.b.y, r[i].b.y);
		}
		if (t.b.x - t.a.x == t.b.y - t.a.y &&
		    (t.b.x - t.a.x) * (t.b.y - t.a.y) == s)
		{
			writeln ("YES");
		}
		else
		{
			writeln ("NO");
		}
	}
}

import std.stdio : write, writeln;
import std.array;
import std.range;
import std.typecons;
import std.bigint;
import std.algorithm;

const int INF = 1<<28;

void main(){
	int n = next!int;

	int[4][] ps;
	foreach( i; n.iota ){
		int x1 = next!int;
		int y1 = next!int;

		int x2 = next!int;
		int y2 = next!int;

		ps ~= [x1, y1, x2, y2];
	}

	bool ans = false;
	for( int s = 0; s <= n; ++s ){
		int[2][] p;
		for( int r = 0; r < s; ++r ){
			p ~= [ ps[ r ][ 0 ], ps[ r ][ 1 ] ];
			p ~= [ ps[ r ][ 2 ], ps[ r ][ 1 ] ];
			p ~= [ ps[ r ][ 0 ], ps[ r ][ 3 ] ];
			p ~= [ ps[ r ][ 2 ], ps[ r ][ 3 ] ];
		}
		for( int k = 0; k < s*4; ++k ){
			for( int l = k+1; l < s*4; ++l ){
				bool[int[2]] data;
				for( int i = 0; i <= k; ++i ){
					bool f = false;
					for( int j = 0; j <= l; ++j ){
						if( i == j )continue;

						assert( p[ i ] !is p[ j ] );
						f |= p[ i ] == p[ j ];
					}
					if( !f ){
						data[ p[ i ] ] = true;
					}
				}

				if( data.keys.length == 4 ){
					int min_x = INF, min_y = INF, max_x = 0, max_y = 0;
					foreach( v; data.keys ){
						min_x = min( min_x, v.front );
						min_y = min( min_x, v.back );
						max_x = max( max_x, v.front );
						max_y = max( max_y, v.back );
					}
					int[2] cntx, cnty;
					foreach( v; data.keys ){
						if( v.front == min_x )++cntx[0];
						if( v.front == max_x )++cntx[1];
						if( v.back  == min_y )++cnty[0];
						if( v.back  == max_y )++cnty[1];
					}
					ans |= (cntx == [ 2, 2 ] && cnty == [ 2, 2 ]);
				}
			}
		}
	}

	writeln = ans ? "YES": "NO";
}

import std.stdio : readln;
import std.conv : to;
import std.string : split, chomp;
import std.traits;
string[] input;
string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

T next( T : char )()
in
{
	assert(hasNext());
}
out
{
	input.front.popFront;
}
body
{
	return input.front.front.to!T;
}

bool hasNext(){
	if(input.length > 0){
		if(input.front.length == 0){
			input.popFront;
			return hasNext;
		}
		return true;
	}

	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return hasNext;
	}else{
		return false;
	}
}

void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}

	return v_;
}

import std.stdio : write, writeln;
import std.array;
import std.range;
import std.typecons;
import std.bigint;
import std.algorithm;

const int INF = 1<<28;

int n;
int[4][] ps;
int[2][] p;
bool ans = false;

void make( int depth, int end, int i ){
	if( depth == end ){
		solve( depth );
	}
	for( int j = i; j < end; ++j ){
		p ~= [ ps[ j ][ 0 ], ps[ j ][ 1 ] ];
		p ~= [ ps[ j ][ 2 ], ps[ j ][ 1 ] ];
		p ~= [ ps[ j ][ 0 ], ps[ j ][ 3 ] ];
		p ~= [ ps[ j ][ 2 ], ps[ j ][ 3 ] ];
		make( depth + 1, end, j + 1 );
	}
}

void solve( int s ){
	bool[int[2]] data;
	for( int i = 0; i < s*4; ++i ){
		bool f = false;
		for( int j = 0; j < s*4; ++j ){
			if( i == j )continue;

			assert( p[ i ] !is p[ j ] );
			f |= p[ i ] == p[ j ];
		}
		if( !f ){
			data[ p[ i ] ] = true;
		}
	}
	if( data.keys.length == 4 ){
		int min_ = INF, max_ = 0;
		foreach( vs; data.keys ){
			foreach( v; vs ){
				min_ = min( min_, v );
				max_ = max( max_, v );
			}
		}
		assert( min_ != max_ );
		int[2] cnt;
		foreach( vs; data.keys ){
			foreach( v; vs ){
				if( v == min_ )++cnt[ 0 ];
				if( v == max_ )++cnt[ 1 ];
			}
		}
		ans |= cnt.front == 4 && cnt.back == 4;
	}
}

void main(){
	n = next!int;

	foreach( i; n.iota ){
		int x1 = next!int;
		int y1 = next!int;

		int x2 = next!int;
		int y2 = next!int;

		ps ~= [x1, y1, x2, y2];
	}

	for( int s = 1; s <= n; ++s ){
		p = p.init;
		make( 0, s, 0 );
	}

	writeln = ans ? "YES": "NO";
}

import std.stdio : readln;
import std.conv : to;
import std.string : split, chomp;
import std.traits;
string[] input;
string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

T next( T : char )()
in
{
	assert(hasNext());
}
out
{
	input.front.popFront;
}
body
{
	return input.front.front.to!T;
}

bool hasNext(){
	if(input.length > 0){
		if(input.front.length == 0){
			input.popFront;
			return hasNext;
		}
		return true;
	}

	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return hasNext;
	}else{
		return false;
	}
}

void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}

	return v_;
}

import std.stdio : write, writeln;
import std.array;
import std.range;
import std.typecons;
import std.bigint;
import std.algorithm;

const int INF = 1<<28;

int n;
int[4][] ps;
int[2][] p;
bool ans = false;

void make( int depth, int end, int i ){
	if( depth == end ){
		solve( depth );
		return;
	}
	for( int j = i; j < n; ++j ){
		auto tmp = p.clone;
		p ~= [ ps[ j ][ 0 ], ps[ j ][ 1 ] ];
		p ~= [ ps[ j ][ 2 ], ps[ j ][ 1 ] ];
		p ~= [ ps[ j ][ 0 ], ps[ j ][ 3 ] ];
		p ~= [ ps[ j ][ 2 ], ps[ j ][ 3 ] ];
		make( depth + 1, end, j + 1 );
		assert( tmp !is p );
		p = tmp.clone;
	}
}

void solve( int s ){
	bool[int[2]] data;
	for( int i = 0; i < s*4; ++i ){
		bool f = false;
		for( int j = 0; j < s*4; ++j ){
			if( i == j )continue;

			assert( p[ i ] !is p[ j ] );
			f |= p[ i ] == p[ j ];
		}
		if( !f ){
			data[ p[ i ] ] = true;
		}
	}
	if( data.keys.length == 4 ){
		int min_x = INF, min_y = INF, max_x = 0, max_y = 0;
		foreach( v; data.keys ){
			min_x = min( min_x, v.front );
			min_y = min( min_x, v.back );
			max_x = max( max_x, v.front );
			max_y = max( max_y, v.back );
		}
		int[2] cntx, cnty;
		foreach( v; data.keys ){
			if( v.front == min_x )++cntx[0];
			if( v.front == max_x )++cntx[1];
			if( v.back  == min_y )++cnty[0];
			if( v.back  == max_y )++cnty[1];
		}
		ans |= (cntx == [ 2, 2 ] && cnty == [ 2, 2 ] && (max_x - min_x) == (max_y - min_y) );
	}
}

void main(){
	n = next!int;

	foreach( i; n.iota ){
		int x1 = next!int;
		int y1 = next!int;

		int x2 = next!int;
		int y2 = next!int;

		ps ~= [x1, y1, x2, y2];
	}

	for( int s = 1; s <= n; ++s ){
		p = p.init;
		make( 0, s, 0 );
	}

	writeln = ans ? "YES": "NO";
}

import std.stdio : readln;
import std.conv : to;
import std.string : split, chomp;
import std.traits;
string[] input;
string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

T next( T : char )()
in
{
	assert(hasNext());
}
out
{
	input.front.popFront;
}
body
{
	return input.front.front.to!T;
}

bool hasNext(){
	if(input.length > 0){
		if(input.front.length == 0){
			input.popFront;
			return hasNext;
		}
		return true;
	}

	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return hasNext;
	}else{
		return false;
	}
}

void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}

	return v_;
}

import std.stdio : write, writeln;
import std.array;
import std.range;
import std.typecons;
import std.bigint;
import std.algorithm;

const int INF = 1<<28;

int n;
int[4][] ps;
int[2][] p;
bool ans = false;

void make( int depth, int end, int i ){
	if( depth == end ){
		solve( depth );
	}
	for( int j = i; j < end; ++j ){
		p ~= [ ps[ j ][ 0 ], ps[ j ][ 1 ] ];
		p ~= [ ps[ j ][ 2 ], ps[ j ][ 1 ] ];
		p ~= [ ps[ j ][ 0 ], ps[ j ][ 3 ] ];
		p ~= [ ps[ j ][ 2 ], ps[ j ][ 3 ] ];
		make( depth + 1, end, j + 1 );
	}
}

void solve( int s ){
	for( int k = 0; k < s*4; ++k ){
		for( int l = k+1; l < s*4; ++l ){
			bool[int[2]] data;
			for( int i = 0; i <= k; ++i ){
				bool f = false;
				for( int j = 0; j <= l; ++j ){
					if( i == j )continue;

					assert( p[ i ] !is p[ j ] );
					f |= p[ i ] == p[ j ];
				}
				if( !f ){
					data[ p[ i ] ] = true;
				}
			}

			if( data.keys.length == 4 ){
				int min_x = INF, min_y = INF, max_x = 0, max_y = 0;
				foreach( v; data.keys ){
					min_x = min( min_x, v.front );
					min_y = min( min_x, v.back );
					max_x = max( max_x, v.front );
					max_y = max( max_y, v.back );
				}
				int[2] cntx, cnty;
				foreach( v; data.keys ){
					if( v.front == min_x )++cntx[0];
					if( v.front == max_x )++cntx[1];
					if( v.back  == min_y )++cnty[0];
					if( v.back  == max_y )++cnty[1];
				}
				ans |= (cntx == [ 2, 2 ] && cnty == [ 2, 2 ]);
			}
		}
	}
}

void main(){
	n = next!int;

	foreach( i; n.iota ){
		int x1 = next!int;
		int y1 = next!int;

		int x2 = next!int;
		int y2 = next!int;

		ps ~= [x1, y1, x2, y2];
	}

	for( int s = 1; s <= n; ++s ){
		p = p.init;
		make( 0, s, 0 );
	}

	writeln = ans ? "YES": "NO";
}

import std.stdio : readln;
import std.conv : to;
import std.string : split, chomp;
import std.traits;
string[] input;
string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

T next( T : char )()
in
{
	assert(hasNext());
}
out
{
	input.front.popFront;
}
body
{
	return input.front.front.to!T;
}

bool hasNext(){
	if(input.length > 0){
		if(input.front.length == 0){
			input.popFront;
			return hasNext;
		}
		return true;
	}

	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return hasNext;
	}else{
		return false;
	}
}

void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}

	return v_;
}

import std.stdio : write, writeln;
import std.array;
import std.range;
import std.typecons;
import std.bigint;
import std.algorithm;

const int INF = 1<<28;

int n;
int[4][] ps;
int[2][] p;
bool ans = false;

void make( int depth, int end, int i ){
	if( depth == end ){
		solve( depth );
		return;
	}
	for( int j = i; j < n; ++j ){
		auto tmp = p.clone;
		p ~= [ ps[ j ][ 0 ], ps[ j ][ 1 ] ];
		p ~= [ ps[ j ][ 2 ], ps[ j ][ 1 ] ];
		p ~= [ ps[ j ][ 0 ], ps[ j ][ 3 ] ];
		p ~= [ ps[ j ][ 2 ], ps[ j ][ 3 ] ];
		make( depth + 1, end, j + 1 );
		assert( tmp !is p );
		p = tmp.clone;
	}
}

void solve( int s ){
	bool[int[2]] data;
	for( int i = 0; i < s*4; ++i ){
		bool f = false;
		for( int j = 0; j < s*4; ++j ){
			if( i == j )continue;

			assert( p[ i ] !is p[ j ] );
			f |= p[ i ] == p[ j ];
		}
		if( !f ){
			data[ p[ i ] ] = true;
		}
	}

	if( data.keys.length == 4 ){
		int min_x = INF, min_y = INF, max_x = 0, max_y = 0;
		foreach( v; data.keys ){
			min_x = min( min_x, v.front );
			min_y = min( min_y, v.back );
			max_x = max( max_x, v.front );
			max_y = max( max_y, v.back );
		}
		int[2] cntx, cnty;
		foreach( v; data.keys ){
			if( v.front == min_x )++cntx[0];
			if( v.front == max_x )++cntx[1];
			if( v.back  == min_y )++cnty[0];
			if( v.back  == max_y )++cnty[1];
		}
		ans |= (cntx == [ 2, 2 ] && cnty == [ 2, 2 ] && (max_x - min_x) == (max_y - min_y) );
	}
}

void main(){
	n = next!int;

	foreach( i; n.iota ){
		int x1 = next!int;
		int y1 = next!int;

		int x2 = next!int;
		int y2 = next!int;

		ps ~= [x1, y1, x2, y2];
	}

	for( int s = 1; s <= n; ++s ){
		p = p.init;
		make( 0, s, 0 );
	}

	writeln = ans ? "YES": "NO";
}

import std.stdio : readln;
import std.conv : to;
import std.string : split, chomp;
import std.traits;
string[] input;
string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

T next( T : char )()
in
{
	assert(hasNext());
}
out
{
	input.front.popFront;
}
body
{
	return input.front.front.to!T;
}

bool hasNext(){
	if(input.length > 0){
		if(input.front.length == 0){
			input.popFront;
			return hasNext;
		}
		return true;
	}

	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return hasNext;
	}else{
		return false;
	}
}

void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}

	return v_;
}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    struct rect { int x1, y1, x2, y2; }
    rect[] rs = new rect[] (n);
    foreach (i; 0 .. n) {
        readf("%s %s %s %s", &rs[i].x1, &rs[i].y1, &rs[i].x2, &rs[i].y2);
        readln;
    }

    debug { rs.writeln; }

    immutable int INF = 10 ^^ 9;
    foreach (i; 1 .. (1 << n)) {
        int sx1 = INF, sy1 = INF, sx2 = -INF, sy2 = -INF;

        int rectArea = i.bitsSet.map!(x => (rs[x].y2 - rs[x].y1) * (rs[x].x2 - rs[x].x1)).sum;

        foreach (j; i.bitsSet) {
            sx1 = min(sx1, rs[j].x1);
            sy1 = min(sy1, rs[j].y1);
            sx2 = max(sx2, rs[j].x2);
            sy2 = max(sy2, rs[j].y2);
        }

        if (sy2 - sy1 != sx2 - sx1) { continue; }

        int area = (sy2 - sy1) * (sx2 - sx1);

        if (area != rectArea) { continue; }

        writeln("YES");
        return;
    }

    writeln("NO");
}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    struct rect { int x1, y1, x2, y2; }
    rect[] rs = new rect[] (n);
    foreach (i; 0 .. n) {
        readf("%s %s %s %s", &rs[i].x1, &rs[i].y1, &rs[i].x2, &rs[i].y2);
        readln;
    }

    debug { rs.writeln; }

    immutable int INF = 10 ^^ 9;
    int sx1 = INF, sy1 = INF, sx2 = -INF, sy2 = -INF;
    int rectArea = rs.map!(r => (r.y2 - r.y1) * (r.x2 - r.x1)).sum;

    foreach (j; 0 .. 5) {
        sx1 = min(sx1, rs[j].x1);
        sy1 = min(sy1, rs[j].y1);
        sx2 = max(sx2, rs[j].x2);
        sy2 = max(sy2, rs[j].y2);
    }

    if (sy2 - sy1 != sx2 - sx1) {
        writeln("NO");
        return;
    }

    int area = (sy2 - sy1) * (sx2 - sx1);
    if (area != rectArea) {
        writeln("NO");
        return;
    }

    writeln("YES");
}


import std.stdio;
import core.stdc.stdio;
import std.string;

int main()
{
	readln();
	int l = 'z' - 'a' + 1;
	string line = readln();
	line = line.toLower;
	int[] letters; letters.length = l;
	int sum = 0;
	foreach (char x; line)
	{
		int idx = x - 'a';
		if (idx >= 0 && idx < l)
		{
			letters[idx] = 1;
		}
	}

	foreach (int i; 0..l) sum += letters[i];
	write (sum == l ? "YES" : "NO");
	return 0;
}

import std.ascii;
import std.stdio;
import std.string;
import std.algorithm;

byte n, sum;

void main() {

	readf(" %s\n", &n);

	auto s = readln.strip;

	foreach (i; lowercase)
		if (find(s, i).length != 0 || find(s, std.string.toUpper(i)).length != 0)
			++sum;

	puts((sum == 26) ? "YES" : "NO");
}

import std.ascii;
import std.stdio;
import std.string;
import std.algorithm;

byte n, sum;

void main() {

	readf(" %s\n", &n);

	auto s = readln.strip;

	foreach (idx, el; lowercase)
		if (find(s, el).length != 0 || find(s, uppercase[idx]).length != 0)
			++sum;

	puts((sum == 26) ? "YES" : "NO");
}

import std.stdio, std.string, std.algorithm;

byte sum;

void main() {

	int n;
	readf(" %s\n", &n);

	string a = readln.strip;

	foreach (immutable i; 'a' .. 'z' + 1)
		if (count(a, i) || count(a, toUpper(i)))
			++sum;

	writeln((sum is 26) ? "YES" : "NO");
}

import std.stdio;
import std.string;

bool isPangram(string str) {
    str = str.toUpper();

    uint['Z'-'A'+1] seen;
    foreach (char i; str) {
        seen[i-'A']++;
    }

    bool result = true;
    for (int i = 0; i < seen.length && result; ++i) {
        if (seen[i] == 0) {
            result = false;
        }
    }

    return result;
}

unittest {
    assert(!isPangram("toosmallword"));
    assert(isPangram("TheQuickBrownFoxJumpsOverTheLazyDog"));
}

void main() {
    int len;
    string str;

    readf("%d\n%s\n", &len, &str);

    if (isPangram(str)) {
        writeln("YES");
    } else {
        writeln("NO");
    }
}

import std.stdio: writeln, stdin;
import std.string: strip,tr;
import std.algorithm.iteration: uniq;
import std.algorithm.mutation: copy;
import std.algorithm.sorting: sort;
import std.array;

void main()
{
  stdin.readln;
  auto h = stdin.readln.strip.dup.tr("ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz");
  auto g = cast(ubyte[])h;
  g.sort();
  writeln (g.uniq().array.length == 26 ? "YES" : "NO" );
}

//ahmat
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.array;
import std.container;
import std.conv;
import std.container;
import std.typecons;
import std.math;
import std.numeric;
pragma(inline,true);

void main(){
    import std.bitmanip:BitArray;
    BitArray b;
    int n=readln.chomp.to!int;
    string s=readln.strip.toLower;
    b.length=26;
    foreach(c;s)
        b[c-'a']=true;
    writeln(b.count<26?"NO":"YES");
}

import core.thread;
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;

//	Input
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return to!int(readToken); }
long readLong() { return to!long(readToken); }
real readReal() { return to!real(readToken); }

//	chmin/chmax
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

int N;
string S;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;
		S = readToken;

		auto app = new bool[26];
		foreach (s; S) {
			app[s.toUpper - 'A'] = true;
		}
		const ans = app.all;
		writeln(ans ? "YES" : "NO");

	}
	} catch (EOFException) {}
}

import std.stdio: writeln, stdin;
import std.string: strip,tr;
import std.algorithm.searching: any;
import std.algorithm.iteration: filter;
import std.range;
import std.array;

void main()
{
  auto h = stdin.readln.strip.dup.tr("ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz");
  auto g = cast(ubyte[])h;
  g = g.filter!"a>=97 && a<=122".array;
  ubyte[26] cs;
  auto a = cast(ubyte)'a';
  foreach(e;g ) cs[e-a]++;
  writeln(cs.dup.any!"a==0" ? "NO" : "YES");
}

import std.stdio: writeln, stdin;
import std.string: strip,tr;
import std.algorithm.searching: any;
import std.range;
import std.array;

void main()
{
  auto h = stdin.readln.strip.dup.tr("ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz");
  ubyte[26] cs;
  auto a = cast(ubyte)'a';
  foreach(e;h ) cs[(cast(ubyte)e)-a]++;
  writeln(cs.dup.any!"a==0" ? "NO" : "YES");
}

import std.stdio: writeln, stdin;
import std.string: strip,tr;
import std.algorithm.searching: any;
import std.range;
import std.array;

void main()
{
  auto h = stdin.readln.strip.dup.tr("ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz");
  auto g = cast(ubyte[])h;
  ubyte[26] cs;
  auto a = cast(ubyte)'a';
  foreach(e;h ) cs[e-a]++;
  writeln(cs.dup.any!"a==0" ? "NO" : "YES");
}

import std.stdio: writeln, stdin;
import std.string: strip,tr;
import std.algorithm.iteration: uniq;
import std.algorithm.mutation: copy;
import std.algorithm.sorting: sort;
import std.range;
import std.array;

void main()
{
  auto h = stdin.readln.strip.dup.tr("ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz");
  auto g = cast(ubyte[])h;
  g.sort();
  writeln (g.uniq().array.length == 26 ? "YES" : "NO" );
}

import std.stdio;
import core.stdc.stdio;
import std.string;

int main()
{
	readln();
	int l = 'z' - 'a';
	string line = readln();
	line = line.toLower;
	int[] letters; letters.length = l;
	int sum = 0;
	foreach (char x; line)
	{
		int idx = x - 'a';
		if (idx >= 0 && idx < l)
		{
			letters[idx] = 1;
		}
	}

	foreach (int i; 0..l) sum += letters[i];
	write (sum == l ? "YES" : "NO");
	return 0;
}


import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
import std.range;
import std.math;

void main() {
    auto a = readln.chomp.split.map!(to!double).reduce!("a + b");
    auto b = readln.chomp.split.map!(to!double).reduce!("a + b");
    auto n = readln.chomp.to!double;

    if ((a / 5).ceil + (b / 10).ceil <= n)
        writeln("YES");
    else
        writeln("NO");
}

import std.stdio;
import std.algorithm;

void main(){
  int[3] as;
  int[3] bs;
  int n;
  for(int i = 0; i < 3; i++){
    int t;
    readf("%s ",&t);
    as[i] = t;
  }
  for(int i = 0; i < 3; i++){
    int t;
    readf("%s ",&t);
    bs[i] = t;
  }
  readf("%s ",&n);
  if (run(as,bs,n) == 0){
    writefln("NO");
    return;
  }
  writefln("YES");
}

int suma(int[] x){
  int sum = 0;
  foreach(v;x){
    sum += v;
  }
  return sum;
}

int run(int[] a, int[] b, int n){
  int sa = suma(a);
  int sb = suma(b);
  int pa = (sa / 5);
  int pb = (sb / 10);
  if (sa % 5 != 0){
    pa++;
  }
  if (sb % 10 != 0){
    pb++;
  }
  if (pa + pb > n){
    return 0;
  }
  return 1;
}

// TEST CASE AREA
void test_case(){
  int[][] rs;

  rs ~= [run([1,1,1],[1,1,1],4),1];
  rs ~= [run([1,1,3],[2,3,4],2),1];
  rs ~= [run([1,0,0],[1,0,0],1),0];

  array_assert(rs);
}

void array_assert(int[][] rs){
  uint i = 1;
  bool failed = false;

  writefln("TEST");

  foreach(int[] r;rs){
    if(r[0] != r[1]){
      failed = true;
      writefln("%s Failed %s is NOT %s",i,r[0],r[1]);
    }
    i++;
  }

  if(!failed){
    writefln("OK");
  }
}

uint[][] numerate(uint[] l){
  uint n = 0;
  uint[][] nl;

  foreach(uint x; l){
    nl ~= [x,n];
    n++;
  }

  return nl;
}

import std.stdio;
import std.c.stdio;
import std.algorithm;
int main(string[] argv)
{
	int a1,a2,a3,b1,b2,b3,n;
	scanf("%d",&a1);
	scanf("%d",&a2);
	scanf("%d",&a3);
	scanf("%d",&b1);
	scanf("%d",&b2);
	scanf("%d",&b3);
	scanf("%d",&n);
	writeln(((a1+a2+a3+4)/5+(b1+b2+b3+9)/10)<=n? "YES":"NO");
    return 0;
}

import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int a = readln.chomp.split(" ").map!(to!int).array.reduce!"a + b";
    int b = readln.chomp.split(" ").map!(to!int).array.reduce!"a + b";
    int n; scanf("%d\n", &n);

    int x = (a + 4) / 5 + (b + 9) / 10;
    writeln( x <= n ? "YES" : "NO" );
}

import std.stdio;
import core.stdc.stdio;
import std.algorithm;
import std.math;
import std.array;

int main(string[] argv)
{
	int[] a; a.length = 3;
	int[] b; b.length = 3;
	int n;
	scanf("%d %d %d\n%d %d %d\n%d", &a[0], &a[1], &a[2], &b[0], &b[1], &b[2], &n);
	int as = a[0] + a[1] + a[2];
	int bs = b[0] + b[1] + b[2];
	int ts = as / 5 + (as % 5 == 0 ? 0 : 1) + bs / 10 + (bs % 10 == 0 ? 0 : 1);
	write (ts <= n ? "YES" : "NO");
	return 0;
}

import std.stdio;
import std.string;
import std.bigint;
import std.array;
import std.ascii;
import std.math;
import std.numeric;
import std.algorithm;
import std.container;
import core.bitop;
import std.conv;

alias Int = long;

void main() {
  Int a = readln.split.map!(to!Int).reduce!((a, b) => a + b);
  Int b = readln.split.map!(to!Int).reduce!((a, b) => a + b);
  int n = readln.split.map!(to!int).array[0];
  debug writeln(a);
  debug writeln(b);
  debug writeln(n);

  auto rem = new Int[n];

  {
    rem[] = 5;
    while ( a > 0 && ! rem.empty ) {
      if ( rem.empty ) {
        writeln("NO");
        return;
      }
      auto d = min(a, 5);
      a -= d;
      rem.front -= d;
      if ( rem.front <= 0 ) {
        rem.popFront();
      }
    }
    if ( ! rem.empty && rem.front < 5 ) {
      rem.popFront();
    }
  }

  debug writeln(rem);

  {
    rem[] = 10;
    while ( b > 0 && ! rem.empty ) {
      if ( rem.empty ) {
        writeln("NO");
        return;
      }
      auto d = min(b, 10);
      b -= d;
      rem.front -= d;
      if ( rem.front <= 0 ) {
        rem.popFront();
      }
    }
    if ( ! rem.empty && rem.front < 10 ) {
      rem.popFront();
    }
  }

  if ( a > 0 || b > 0 ) {
    writeln("NO");
  } else {
    writeln("YES");
  }
}

import std.stdio;
import std.string;
import std.bigint;
import std.array;
import std.ascii;
import std.math;
import std.numeric;
import std.algorithm;
import std.container;
import core.bitop;
import std.conv;

alias Int = long;

void main() {
  Int a = readln.split.map!(to!Int).reduce!((a, b) => a + b);
  Int b = readln.split.map!(to!Int).reduce!((a, b) => a + b);
  int n = readln.split.map!(to!int).array[0];
  debug writeln(a);
  debug writeln(b);
  debug writeln(n);

  auto rem = new Int[n];

  {
    rem[] = 5;
    while ( a > 0 ) {
      if ( rem.empty ) {
        writeln("NO");
        return;
      }
      auto d = min(a, 5);
      a -= d;
      rem.front -= d;
      if ( rem.front <= 0 ) {
        rem.popFront();
      }
    }
    if ( rem.front < 5 ) {
      rem.popFront();
    }
  }

  debug writeln(rem);

  {
    rem[] = 10;
    while ( b > 0 ) {
      if ( rem.empty ) {
        writeln("NO");
        return;
      }
      auto d = min(b, 10);
      b -= d;
      rem.front -= d;
      if ( rem.front <= 0 ) {
        rem.popFront();
      }
    }
    if ( rem.front < 10 ) {
      rem.popFront();
    }
  }

  writeln("YES");
}


import std.conv;
import std.string;
import std.functional;
import std.stdio;
import std.algorithm;

int main() {
	ulong fib(ulong n, ulong k, ulong max) {
		alias memoize!fib mfib;
		if (n < k)
			return 0;
		else if (n == k)
			return 1;
		else {
			ulong ans = 0;
			for (ulong j = std.algorithm.max(k, n - k); (ans <= max) & (j <= n - 1); ++j) {
				ans += mfib(j, k, max);
				if (ans > max)
					return max + 1;
			}
			return ans;
		}
	}
	auto tmp = split(strip(readln()), " ");
	auto s = to!ulong(tmp[0]);
	auto k = to!ulong(tmp[1]);
	/*ulong ke = k;
	while (fib(ke, k, s) <= s) {
		write(fib(ke, k, s), " ");
		++ke;
	}
	writeln();*/
	ulong[] ans = [];
	auto s0 = s;
	while (s > 0) {
		ulong cnt = k;
		while (fib(cnt, k, s0) <= s)
			++cnt;
		--cnt;
		ans ~= fib(cnt, k, s0);
		s -= fib(cnt, k, s0);
	}
	if (ans.length == 1)
		ans ~= 0;
	writeln(ans.length);
	foreach (ulong i; ans)
		write(i, " ");
	return 0;
}

import std.conv;
import std.string;
import std.functional;
import std.stdio;
import std.algorithm;

int main() {
	uint fib(uint n, uint k) {
		alias memoize!fib mfib;
		if (n < k)
			return 0;
		else if (n == k)
			return 1;
		else {
			uint ans = 0;
			for (uint j = max(k, n - k); j <= n - 1; ++j)
				ans += mfib(j, k);
			return ans;
		}
	}
	auto tmp = split(strip(readln()), " ");
	auto s = to!uint(tmp[0]);
	auto k = to!uint(tmp[1]);
	uint[] ans = [];
	while (s > 0) {
		uint cnt = k;
		while (fib(cnt, k) <= s)
			++cnt;
		--cnt;
		ans ~= fib(cnt, k);
		s -= fib(cnt, k);
	}
	if (ans.length == 1)
		ans ~= 0;
	writeln(ans.length);
	foreach (uint i; ans)
		write(i, " ");
	return 0;
}

import std.conv;
import std.string;
import std.functional;
import std.stdio;
import std.algorithm;

int main() {
	int fib(int n, int k) {
		alias memoize!fib mfib;
		if (n < k)
			return 0;
		else if (n == k)
			return 1;
		else {
			int ans = 0;
			for (int j = max(k, n - k); j <= n - 1; ++j)
				ans += mfib(j, k);
			return ans;
		}
	}
	auto tmp = split(strip(readln()), " ");
	auto s = to!int(tmp[0]);
	auto k = to!int(tmp[1]);
	int[] ans = [];
	while (s > 0) {
		int cnt = k;
		while (fib(cnt, k) <= s)
			++cnt;
		--cnt;
		ans ~= fib(cnt, k);
		s -= fib(cnt, k);
	}
	if (ans.length == 1)
		ans ~= 0;
	writeln(ans.length);
	foreach (int i; ans)
		write(i, " ");
	return 0;
}

import std.conv;
import std.string;
import std.functional;
import std.stdio;
import std.algorithm;

int main() {
	ulong fib(ulong n, ulong k) {
		alias memoize!fib mfib;
		if (n < k)
			return 0;
		else if (n == k)
			return 1;
		else {
			ulong ans = 0;
			for (ulong j = max(k, n - k); j <= n - 1; ++j)
				ans += mfib(j, k);
			return ans;
		}
	}
	auto tmp = split(strip(readln()), " ");
	auto s = to!ulong(tmp[0]);
	auto k = to!ulong(tmp[1]);
	ulong[] ans = [];
	while (s > 0) {
		ulong cnt = k;
		while (fib(cnt, k) <= s)
			++cnt;
		--cnt;
		ans ~= fib(cnt, k);
		s -= fib(cnt, k);
	}
	if (ans.length == 1)
		ans ~= 0;
	writeln(ans.length);
	foreach (ulong i; ans)
		write(i, " ");
	return 0;
}


import std.stdio;

void main() {
    // writeln("hello world!");
    // int[3] A;
    // foreach (i; 0 .. 3) {
    //     readf(" %s", &A[i]);
    // }
    // writeln(A);
    // write(A, "\n");
    // writefln("%(%s %)", A);
    int t, s, x;
    readf(" %s %s %s\n", &t, &s, &x);
    // writeln(n, x, y);
    if (t == x) {
        writeln("YES");
        return;
    }
    foreach(k; 1 .. (x + s) / s) {
        if (t + k * s == x || t + k * s + 1 == x) {
            writeln("YES");
            return;
        }
    }
    writeln("NO");
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
alias mp=make_pair;
alias bins=binary_search;
alias orsq=orient_square;
immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	X binpow(X,Y)(X base,Y exp)
		if(is(typeof(exp&1)))
	{
		if(exp<0)return X(0);
		X res=X(1);
		while(exp>0)
		{
			if(exp&1)res*=base;
			base*=base;
			exp>>=1;
		}
		return res;
	}
	auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
		if(is(typeof(exp&1)))
	{
		if(mm==0) return binpow(base,exp);
		if(exp<0)return X(0);
		auto res=X(1)%mm;
		while(exp>0)
		{
			if(exp&1)res=(res*base)%mm;
			base*=base;
			base%=mm;
			exp>>=1;
		}
		return res;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
	V foldr(R,V,T)(R range,T arg,V nach)
		if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))
	{
		for(;!range.empty;range.popFront()) nach=arg(nach,range.front);
		return nach;
	}
	size_t countr(R,T)(R range,T fun)
		if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))
	{
		size_t nach;
		for(;!range.empty;range.popFront()) nach+=fun(range.front);
		return nach;
	}
	T orient_square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
	{
		auto n=figure.front,t=figure.front;
		figure.popFront();
		T ans=0;
		for(;!figure.empty;figure.popFront())
		{
			ans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);
			t=figure.front;
		}
		return ans+(n.fi-t.fi)*(n.se+t.se);
	}
	real square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
	{
		return abs(orient_square(figure))/2.000000000000000;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))
	{
		fi=p.fi;
		se=p.se;
	}
	pair!(X,Y) opAssign(A,B)(pair!(A,B) val)
	{
		return this=pair!(X,Y)(val);
	}
	int opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe
		if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
struct Tree(T,alias arg="a+b")
{
	private alias fun=binaryFun!arg;
	private static const size_t n=size_t.max>>1;
	private T[size_t] t;
	this(this){t=t.dup;}
	this(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))
	{
		foreach(pos,i;range) upd(pos,i);
	}
	this(R,alias f)(Tree!(R,f) q) if(is(R:T))
	{
		foreach(i,j;q.t)
		{
			t[i]=j;
		}
	}
	Tree!(T,arg) opAssign(R)(R val)
	{
		return this=Tree!(T,arg)(val);
	}
	private void upd(in size_t v,in size_t vl,in size_t vr,in size_t i,in T x)
	{
		if (vr - vl == 1){t[v] = x;return;}
		size_t vm = (vl + vr) >> 1;
		if(i < vm) upd(2*v, vl, vm, i, x);
		else upd(2*v+1, vm, vr, i, x);
		if(v*2+1 !in t)t[v]=t[v*2];
		else if (v*2 !in t)t[v]=t[v*2+1];
		else t[v]=fun(t[v*2],t[v*2+1]);
	}
	void upd(in size_t i,in T x)
	{
		upd(1,0,n,i,x);
	}
	private T cel(in size_t v,in size_t vl,in size_t vr,in size_t l,in size_t r)
	{
		if(vl==l && r==vr) return t[v];
		size_t vm=(vl+vr) >> 1;
		if(r<=vm) return cel(2*v,vl,vm,l,r);
		else if(l>=vm) return cel(2*v+1,vm,vr,l,r);
		else return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));
	}
	T cel(in size_t l,in size_t r){return cel(1,0,n,l,r);}
};
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int t,x,s;
	loop:while(input(&t,&s,&x))
	{
		if(x==t ||(x>=t+s && (x-t)%s<=1))writeln("YES");
		else writeln("NO");
	}
}

import std.stdio;

void main() {
    // writeln("hello world!");
    // int[3] A;
    // foreach (i; 0 .. 3) {
    //     readf(" %s", &A[i]);
    // }
    // writeln(A);
    // write(A, "\n");
    // writefln("%(%s %)", A);
    int t, s, x;
    readf(" %s %s %s\n", &t, &x, &s);
    // writeln(n, x, y);
    if (t == x) {
        writeln("YES");
        return;
    }
    foreach(k; 1 .. (x + s) / s) {
        if (t + k * s == x || t + k * s + 1 == x) {
            writeln("YES");
            return;
        }
    }
    writeln("NO");
}


import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto n = RD!int;
	auto p = RD!int;
	int ans = -1;
	foreach (i; 1..33)
	{
		auto x = n - i * p;
		int cnt, cnt_max;
		foreach (j; 0..32)
		{
			auto bit = 1L << j;
			if (x & bit)
			{
				++cnt;
				cnt_max += 2^^j;
			}
		}
		debug writeln("i:", i, " x:", x, " cnt:", cnt);
		if (i >= cnt && i <= cnt_max)
		{
			ans = i;
			break;
		}
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

    import core.bitop, std.bitmanip;
    import core.checkedint;
    import std.algorithm, std.functional;
    import std.array, std.container;
    import std.bigint;
    import std.conv;
    import std.math, std.numeric;
    import std.range, std.range.interfaces;
    import std.stdio, std.string;
    import std.typecons;

    void main()
    {
        int n, p;
        readf("%s %s", &n, &p);
        readln;

        foreach (k; 1 .. 32) {
            long s = k.to!long * p;
            long nn = n.to!long - s;

            if (nn == 0) {
                continue;
            }

            int pcnt = nn > 0 ? nn.popcnt() : (-nn).popcnt();
            if (pcnt <= k && nn >= k) {
                writeln(k);
                return;
            }
        }

        writeln(-1);
        return;
    }

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

enum LIM = 10^^5;

void main() {
  try {
    for (; ; ) {
      const N = readLong();
      const P = readLong();

      int ans = LIM;
      foreach (k; 0 .. LIM) {
        const m = N - k * P;
        if (m >= 0) {
          if (popcnt(m) <= k && k <= m) {
            chmin(ans, k);
          }
        }
      }
      writeln((ans >= LIM) ? -1 : ans);
    }
  } catch (EOFException e) {
  }
}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n, p;
    readf("%s %s", &n, &p);
    readln;

    foreach (k; 1 .. n/2 + 2) {
        long s = k.to!long * p;
        long nn = n.to!long - s;

        if (nn == 0) {
            continue;
        }

        int pcnt = nn > 0 ? nn.popcnt() : (-nn).popcnt();
        if (pcnt <= k && nn >= k) {
            writeln(k);
            return;
        }
    }

    writeln(-1);
    return;
}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n, p;
    readf("%s %s", &n, &p);
    readln;

    foreach (k; 1 .. n/2 + 2) {
        int s = k * p;
        long nn = n - s;

        if (nn == 0) {
            continue;
        }

        int pcnt = nn > 0 ? nn.popcnt() : (-nn).popcnt();
        if (pcnt <= k && nn >= k) {
            writeln(k);
            return;
        }
    }

    writeln(-1);
    return;
}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n, p;
    readf("%s %s", &n, &p);
    readln;

    foreach (k; 1 .. n/2 + 2) {
        int s = k * p;
        long nn = n - s;

        if (nn > 0 && (nn > 0 ? nn.popcnt() : (-nn).popcnt()) <= k) {
            writeln(k);
            return;
        }
    }

    writeln(-1);
    return;
}


//ahmat
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.string;
import std.ascii;
import std.algorithm;
import std.range;
import std.functional;
import std.array;
import std.container;
import std.conv;
import std.container;
import std.typecons;
import std.math;
import std.numeric;
pragma(inline,true);

void main(){
    readln.split.to!(char[]).filter!isDigit.map!"a-'0'".array.sort.writefln!"%(%d+%)";
}

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;

void main(){
  auto s = readln.strip.split("+").map!(e => e.strip).array;
  s.sort.join("+").writeln;
}

import std.stdio;
import std.string;
import std.algorithm;
import std.range;

void main()
{
    readln
        .strip
        .splitter("+")
        .array
        .sort
        .joiner("+")
        .writeln;
}

import std.stdio;
import std.algorithm.comparison : equal;
import std.uni;
import std.array;
import std.algorithm;

int main(string[] argv)
{
	string line = stdin.readln();
	if (line[line.length - 1] == '\n')
		line.length--;

	string[] nums = split(line, "+");
	nums.sort();
	writef("%s", nums[0]);
	for (int i = 1; i < nums.length; i++)
	{
		writef("+%s", nums[i]);
	}
	return 0;
}

import std.stdio;
import std.array;
import std.algorithm;

int main() {
    auto s = stdin.byLine;
    foreach (line; s) {
        auto arr = line.split("+");
        writeln(arr.sort().join("+"));
    }
    return 0;
}

import std.stdio;

void main(string[] args) {
  string data = std.stdio.readln();
  data = std.string.stripRight(data);

  auto words = std.string.split(data, "+");

  std.algorithm.sort(words);

  auto answer = std.string.join(words, "+");
  //foreach(word; words) {
  //  std.stdio.writeln(word);
  //}

  std.stdio.writeln(answer);
}

// https://codeforces.com/problemset/problem/339/A
import std.algorithm;
import std.range;
import std.stdio;
import std.string;

void main() {
    readln.strip.splitter("+").array.sort.joiner("+").writeln;
}

import std.stdio;
import std.algorithm;
import std.conv;
import std.range;
import std.string;
import std.regex;

void main() {
  readln.chomp.split("+").sort.join("+").writeln;
}


import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;

    long r;
    foreach (i; 2..N) {
        r += i * (i+1);
    }
    writeln(r);
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!long;
    long ans = 0;

    foreach (i; 2..N) ans += i * (i + 1);

    ans.writeln;
}

//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

void main() {
  int n;
  readf (" %d", &n);
  auto a = new long[][] (n+2, n+2);
  auto c = new int[n + 1];
  foreach (i; 0 .. n + 1) {
    c[i] = i;
  }
  debug stderr.writeln (c);
  long f (int i, int j) {
    if (i == j) return 0;
    assert (i < j);
    if (a[i][j] != 0) return a[i][j];
    long r = long.max;
    foreach (k; i .. j) {
      //r = max (r, f (i, k) + f (k + 1, j) + c[i-1] * c[k] * c[j]);
      r = min (r, f (i, k) + f (k + 1, j) + (i - 1) * k * j);
    }
    debug stderr.writefln ("f(%d, %d) = %d", i, j, r);
    return a[i][j] = r;
  }
  writeln (f (2, n));
}

//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

void main() {
  int n;
  readf (" %d", &n);
  if (n == 3) {
    writeln (6);
    return;
  }
  auto a = new long[][] (n+2, n+2);
  auto c = new int[n + 2];
  foreach (i; 0 .. n + 1) {
    c[i] = i;
  }
  c[n+1] = 1;
  debug stderr.writeln (c);
  long f (int i, int j) {
    if (i >= j) {
      j += n;
    }
    if (a[i][j] != 0) return a[i][j];
    long r;
    if (j == i + 2) {
      r = c[i] * c[i + 1] * c[i + 2];
    } else {
      foreach (k; i + 2 .. j) {
        debug stderr.writefln ("i = %d, j = %d, k = %d", i, j, k);
        r = max (r, f (i, k) + f (k, j));
      }
    }
    debug stderr.writefln ("f(%d, %d) = %d", i, j, r);
    return a[i][j] = r;
  }
  writeln (f (1, 1));
}

//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

void main() {
  int n;
  readf (" %d", &n);
  if (n == 3) {
    writeln (6);
    return;
  }
  auto a = new long[][] (n+2, n+2);
  auto c = new int[n + 2];
  foreach (i; 0 .. n + 1) {
    c[i] = i;
  }
  c[n+1] = 1;
  debug stderr.writeln (c);
  long f (int i, int j) {
    if (i >= j) {
      j += n;
    }
    if (a[i][j] != 0) return a[i][j];
    long r;
    if (j == i + 2) {
      r = c[i] * c[i + 1] * c[i + 2];
    } else {
      foreach (k; i + 2 .. j - 1) {
        debug stderr.writefln ("i = %d, j = %d, k = %d", i, j, k);
        r = max (r, f (i, k) + f (k, j));
      }
    }
    debug stderr.writefln ("f(%d, %d) = %d", i, j, r);
    return a[i][j] = r;
  }
  writeln (f (1, 1));
}


import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto A = readln.split.map!(to!int).array;
    int x1 = A.count(1).to!int;
    int x2 = A.count(-1).to!int;

    int ans = 0;
    foreach (i; 0..N) {
        int cnt1 = 0, cnt2 = 0;
        foreach (j; 0..N) {
            if (abs(j - i) % K == 0) {
                if (A[j] == 1) cnt1 += 1;
                else cnt2 += 1;
            }
        }
        ans = max(ans, abs((x1 - cnt1) - (x2 - cnt2)));
   }

    ans.writeln;
}

import std.algorithm;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
    int n,k;
    readf!" %s %s"(n, k);

    int[] a = new int[](n);
    foreach (i; 0 .. n) {
        readf!" %s"(a[i]);
    }

    int total = a.sum;

    int ans = 0;
    foreach (i; 0 .. k) {
        int temp = 0;
        for (int j = i; j < n; j += k) {
            temp += a[j];
        }
        ans = max(ans, (total - temp).abs);
    }

    writeln(ans);
}


import core.thread;
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;

//	Input
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return to!int(readToken); }
long readLong() { return to!long(readToken); }
real readReal() { return to!real(readToken); }

//	chmin/chmax
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

immutable V = 10^^6;

int S, T;

void main(string[] args) {
	try {
	for (; ; ) {
		S = readInt;
		T = readInt;

		int[] q;
		int[] d = new int[V];
		d[] = -1;
		d[S] = 0;
		q ~= S;
		for (; !q.empty; ) {
			const u = q.front;
			q.popFront;
			foreach (v; [ u * 2, u - 1 ]) if (0 < v && v < V) {
				if (d[v] == -1) {
					d[v] = d[u] + 1;
					q ~= v;
				}
			}
		}

		writeln(d[T]);

	}
	} catch (EOFException) {}
}

import std.stdio;

int bfs(short n, short m) {

	if (n >= m)
		return n - m;

	if (!(m & 1))
		return bfs(n, m / 2) + 1;

	if (m & 1)
		return bfs(n, (m + 1) / 2) + 2;

	assert(0);
}

void main() {

	short n, m;

	scanf("%hd%hd", &n, &m);

	writeln(bfs(n, m));
}

import std.stdio;

void main() {

	short n, m;

	scanf("%hd%hd", &n, &m);

	int sum;
	while (m > n) {
		if (!(m & 1))
			m /= 2;
		else
			m++;
		sum++;
	}

	writeln(sum + n - m);
}

import std.stdio;

int bfs(short n, short m) {

	if (n >= m)
		return n - m;

	if (m % 2 == 0)
		return bfs(n, m / 2) + 1;

	if (m % 2 == 1)
		return bfs(n, (m + 1) / 2) + 2;

	assert(0);
}

void main() {

	short n, m;

	scanf("%hd%hd", &n, &m);

	writeln(bfs(n, m));
}

import std.stdio;
import std.container;
import std.array;
import std.conv;
import std.string;
import std.algorithm;

void main()
{
    auto i = readln.chomp.split.map!"a.to!int";
    auto s = DList!int(i[0]);
    auto v = DList!int(0);
    bool [int] visited;

    int a,b;
    while (!s.empty  && s.front!= i[1]) {
        a = s.front;
        b = v.front;
        s.removeFront();
        v.removeFront();
        if (! (a in visited)) {
            visited[a] = true;
            if (a<i[1]) {
                s.insertBack(a*2);
                v.insertBack(b+1);
            }
            if (a>1) {
                    s.insertBack(a-1);
                    v.insertBack(b+1);
            }

        }
        //writeln(array(s));
    }

    writeln(v.front);

}

import std.stdio;
import std.container;
import std.array;
import std.conv;
import std.string;
import std.algorithm;

void main()
{
    auto i = readln.chomp.split.map!"a.to!int";
    auto s = SList!int(i[0]);
    auto v = SList!int(0);
    bool [int] visited;

    int a,b;
    while (!s.empty  && s.front!= i[1]) {
        a = s.front;
        b = v.front;
        s.removeFront();
        v.removeFront();
        if (! (a in visited)) {
            s.insertFront(a*2);
            v.insertFront(b+1);
            visited[a] = true;
            if (a>0) {
                writeln("here");
                s.insertFront(a-1);
                v.insertFront(b+1);
            }
        }
    }

    writeln(v.front);

}

import std.stdio;
import std.container;
import std.array;
import std.conv;
import std.string;
import std.algorithm;

void main()
{
    auto i = readln.chomp.split.map!"a.to!int";
    auto s = SList!int(i[0]);
    auto v = SList!int(0);
    bool [int] visited;

    int a,b;
    while (!s.empty  && s.front!= i[1]) {
        a = s.front;
        b = v.front;
        s.removeFront();
        v.removeFront();
        if (! (a in visited)) {
            s.insertFront(a*2);
            v.insertFront(b+1);
            visited[a] = true;
            if (a>0) {
                s.insertFront(a-1);
                v.insertFront(b+1);
            }
        }
    }

    writeln(v.front);

}


import std.stdio, std.algorithm, std.string;

void main()
{
    readln();
    auto s = readln().strip();

    bool ok = true;
    ok &= !canFind(s, "000");
    ok &= !canFind(s, "11");
    ok &= !s.startsWith("00");
    ok &= !s.endsWith("00");
    ok &= s != "0";

    writeln(ok ? "Yes" : "No");
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	foreach (i; 0 .. n - 1)
	{
		if (s[i] == '1' && s[i + 1] == '1')
		{
			return writeln("No");
		}
		if (i == 0 && s[i] == '0' && s[i + 1] == '0')
			return writeln("No");
		if (i == n - 2 && s[i] == '0' && s[i + 1] == '0')
			return writeln("No");
		if (i > 0 && s[i] == '0' && s[i - 1] == '0' && s[i + 1] == '0')
		{
			return writeln("No");
		}
	}
	if (n == 1 && s[0] == '0')
		writeln("No");
	else
		writeln("Yes");
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.chomp;

    foreach (i; 0..N-1) {
        if (A[i] == '1' && A[i+1] == '1') {
            writeln("No");
            return;
        }
    }

    foreach (i; 0..N) {
        if (A[i] == '1') continue;
        bool ok1  = (i == 0)   || (i > 0   && A[i-1] == '0');
        bool ok2  = (i == N-1) || (i < N-1 && A[i+1] == '0');
        if (ok1 && ok2) {
            writeln("No");
            return;
        }
    }

    writeln("Yes");
}

import std.stdio, std.algorithm, std.string;

void main()
{
    readln();
    auto s = readln();

    bool ok = true;
    ok &= !canFind(s, "000");
    ok &= !canFind(s, "11");
    ok &= !s.startsWith("00");
    ok &= !s.endsWith("00");

    writeln(ok ? "Yes" : "No");
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	foreach (i; 0 .. n - 1)
	{
		if (s[i] == '1' && s[i + 1] == '1')
		{
			return writeln("No");
		}
		if (i == 0 && s[i] == '0' && s[i + 1] == '0')
			return writeln("No");
		if (i == n - 2 && s[i] == '0' && s[i + 1] == '0')
			return writeln("No");
		if (i > 0 && s[i] == '0' && s[i - 1] == '0' && s[i + 1] == '0')
		{
			return writeln("No");
		}
	}
	writeln("Yes");

}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	if (count(s, '1') == (n + 1) / 2)
		writeln("Yes");
	else
		writeln("No");
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	foreach (i; 0 .. n - 1)
	{
		if (s[i] == '1' && s[i + 1] == '1')
		{
			return writeln("No");
		}
		if (i > 0 && s[i] == '0' && s[i - 1] == '0' && s[i + 1] == '0')
		{
			return writeln("No");
		}
	}
	writeln("Yes");

}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	if (n == 2)
		n++;
	if (count(s, '1') == (n + 1) / 2)
		writeln("Yes");
	else
		writeln("No");
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	if (n == 2)
	{
		if (s[0] == '1' && s[1] == '1')
			writeln("Yes");
		else
			writeln("No");
		return;
	}
	foreach (i; 0 .. s.length - 1)
	{
		if (s[i] == '1' && s[i + 1] == '1')
		{
			return writeln("No");
		}
	}
	if (count(s, '1') == (n + 1) / 2)
		writeln("Yes");
	else
		writeln("No");
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	foreach (i; 0 .. s.length - 1)
	{
		if (s[i] == '1' && s[i + 1] == '1')
		{
			return writeln("No");
		}
	}
	if (count(s, '1') == (n + 1) / 2)
		writeln("Yes");
	else
		writeln("No");
}


import std.stdio,std.conv,std.array;

void main()
{
	int CountLarge = 0,CountSmall = 0;
	auto n = readln();
	foreach(string s;split(readln()," "))
	{
		uint ui = parse!uint(s);
		if(ui == 200)CountLarge++; else CountSmall++;
	}
	if(CountLarge % 2 == 0) CountLarge = 0;
	else{
		if(CountSmall >= 2){
			CountLarge = 0;
			CountSmall -= 2;
		}else{
			writeln("NO");
			return;
		}
	}
	if(CountSmall % 2 == 0) writeln("YES"); else writeln("NO");
}

import std.stdio,std.conv,std.array;

void main()
{
	int CountLarge = 0,CountSmall = 0;
	auto n = readln();
	foreach(string s;split(readln()," "))
	{
		uint ui = parse!uint(s);
		if(ui == 200)CountLarge++; else CountSmall++;
	}
	writeln(((CountSmall % 2 == 1) || ((CountLarge % 2 == 1)&&(CountSmall <= 1)))?"NO":"YES");
}

import std.stdio,std.conv,std.array;

void main()
{
	int CountLarge = 0,CountSmall = 0;
	auto n = readln();
	foreach(string s;split(readln()," "))
	{
		uint ui = parse!uint(s);
		if(ui == 200)CountLarge++; else CountSmall++;
	}
	// if(CountLarge % 2 == 0) CountLarge = 0;
	// else{
		// if(CountSmall >= 2){
			// CountLarge = 0;
			// CountSmall -= 2;
		// }else{
			// writeln("NO");
			// return;
		// }
	// }
	// if(CountSmall % 2 == 0) writeln("YES"); else writeln("NO");
	writeln(((CountSmall % 2 != 0) || (CountSmall < 2))?"NO":"YES");
}


import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto S = readln.chomp;
    auto F = new int[](26);
    auto L = new int[](26);
    fill(F, 1 << 29);

    foreach (i; 0..N) {
        F[S[i] - 'A'] = min(F[S[i] - 'A'], i);
        L[S[i] - 'A'] = max(L[S[i] - 'A'], i);
    }

    auto imos = new int[](10^^6 + 100);
    foreach (i; 0..26) if (F[i] != 1 << 29) imos[F[i]] += 1, imos[L[i] + 1] -= 1;
    foreach (i; 0..10^^6 + 50) imos[i + 1] += imos[i];

    writeln(imos.reduce!max > K ? "YES" : "NO");
}

// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;

int n, k;
string s;

void main() {
    scan(n, k);
    s = readln.chomp;

    auto t = new int[](n + 10);

    foreach (char ch ; 'A' .. 'Z' + 1) {
        foreach (i ; 0 .. n) {
            if (s[i] == ch) {
                t[i]++;
                break;
            }
        }

        foreach_reverse (i ; 0 .. n) {
            if (s[i] == ch) {
                t[i + 1]--;
                break;
            }
        }
    }

    foreach (i ; 0 .. n + 1) {
        t[i + 1] += t[i];
    }

    debug {
        writeln(t);
    }

    if (t.reduce!max > k) {
        writeln("YES");
    }
    else {
        writeln("NO");
    }
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;

long gcd (long a, long b)
{
	if (a == 0)
	{
		return b;
	}
	return gcd (b % a, a);
}

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

long solve (int [] p)
{
	int n = cast (int) (p.length);

	auto q = new int [n];
	q[] = -1;
	foreach (i; 0..n)
	{
		q[p[i]] = i;
	}
	if (q.any !(x => x == -1))
	{
		return -1;
	}

	long res = 1;
	foreach (i; 0..n)
	{
		if (p[i] != -1)
		{
			int len = 0;
			int k = i;
			while (p[k] != -1)
			{
				int r = k;
				k = p[k];
				p[r] = -1;
				len += 1;
			}
			if (len % 2 == 0)
			{
				len /= 2;
			}
			res = lcm (res, len);
		}
	}

	return res;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto p = readln.split.map !(to !(int)).array;
		p[] -= 1;
		writeln (solve (p));
	}
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,std.bitmanip,std.functional,std.math,std.numeric,std.string,std.range,std.uni,std.complex,
std.typecons,std.regex,std.complex,std.random;
import core.stdc.stdio:freopen;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree set;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
immutable int mod=1000000007;
T lcm (T)(T a,T b)
{
	return a/gcd(a,b)*b;
}
pure nothrow X binpow(X,Y)(X base,Y exp)
if(!is(Y==float) && !is(Y==real) && !is(Y==double))
{
	if(exp<0)return X(0);
	X res=X(1);
	while(exp>0)
	{
		if(exp&1)res*=base;
		base*=base;
		exp>>=1;
	}
	return res;
}
pure nothrow auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
if(!is(Y==float) && !is(Y==real) && !is(Y==double))
{
	if(mm==0) return binpow(base,exp);
	if(exp<0)return X(0);
	auto res=X(1)%mm;
	while(exp>0)
	{
		if(exp&1)res=(res*base)%mm;
		base*=base;
		base%=mm;
		exp>>=1;
	}
	return res;
}
@property void putarr(X)(X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(X a,in int n,in int m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
void getarr(X)(X a,in int n){foreach(ref i;a[0..n])input(&i);}
bool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
		}
	this(this){fi=fi;se=se;}
	int opCmp(ref const pair!(X,Y) s_) const pure nothrow
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) mp(X,Y)(X x_,Y y_) pure nothrow
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
X sqr(X)(X a_) pure nothrow @property @nogc {return a_*a_;}
X cub(X)(X a_) pure nothrow @property @nogc {return a_*a_*a_;}
nothrow @nogc @system void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow @nogc @system void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
auto arread(T)(){return readln.split.map!(to!(T)).array;}
nothrow pure size_t lowb(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (!(a[l]<g))?l:r;
}
pure nothrow size_t upb(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(g<a[m])r=m;
		else l=m;
	}
	return (g<a[l])?l:r;
}
pure nothrow size_t binf(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (g==a[l])?l:a.length;
}
pure nothrow bool binary_search(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	return binf(a,g)!=a.length;
}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join
//---------------------------------------------------------------program beginning-----------------------------------------------------------

void main()
{
	int n;
	while(input(&n))
	{
		readln;
		int ans=1;
		auto a=arread!int;
		auto u=new bool[a.length];
		void dfs(int v,int root,int d)
		{
			if(u[v])
			{
				if(v!=root)ans=-1;
				else if(d&1)ans=lcm(ans,d);
				else ans=lcm(ans,d/2);
				return;
			}
			u[v]=1;
			dfs(a[v]-1,root,d+1);
		}
		foreach(i;0..n)
		{
			if(!u[i]) dfs(i,i,0);
			if(ans==-1){writeln(-1); goto loop;}
		}
		writeln(ans);
	loop:;
	}
}

import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;

int solve (int [] p)
{
	int n = cast (int) (p.length);
	auto q = n.iota.array;
	auto r = new int [n];
	foreach (res; 1..n + 1)
	{
		foreach (i; 0..n)
		{
			r[i] = p[q[i]];
		}
		q[] = r[];
		if (n.iota.all !(x => q[q[x]] == x))
		{
			return res;
		}
	}
	return -1;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto p = readln.split.map !(to !(int)).array;
		p[] -= 1;
		writeln (solve (p));
	}
}