Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.

The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account.

In a single line print an integer — the maximum state of the bank account that Ilya can get.

NoteIn the first test sample Ilya doesn't profit from using the present.In the second test sample you can delete digit 1 and get the state of the account equal to 0.

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

// main================
void main(){
  auto moneyStr = readln.chomp.dup;
  if(moneyStr.to!int >= 0){ writeln(moneyStr.to!int); }
  else{
    auto a = moneyStr[0..$-1].to!int;
    auto b = (moneyStr[0..$-2] ~ moneyStr[$-1]).to!int;
    max(a, b).writeln;
  }
}

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

int solve(string s) {
        if (s.to!int > 0) return s.to!int;
        else {
                if (s.to!int > -10) return s.to!int;
                else {
                        char[] s1 = s.dup;
                        int n = s1.length;
                        if (s1[n - 1] < s[n - 2]) {
                                s1 = s1.remove(n - 2);
                        } else s1 = s1.remove(n - 1);
                        return s1.to!int;
                }
        }
}
void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                string s = cin.readString;
                writeln(solve(s));
        }
}

import std.stdio
    , std.typecons
    , std.traits
    , std.algorithm;

T modulus(T)(auto ref T val) {
    import std.conv: to;
    return (val > 0.to!T
            ? val
            : -val);
}

void main() {

    long n;

    readf("%s\n", &n);
    //uint count;
    while(true) {
        //count.writeln;
        if(n >= 0) {
            writeln(n);
            return;
        }

        auto n2 = n.modulus % 100;

        if(n2 % 10 < n2 / 10) {
            const t = n.modulus / 100 * 10 + n2 % 10;
            writeln((t != 0 ? "-" : ""), t);
        }
        else
        {

            const t = n.modulus / 100 * 10 + n2 / 10;
            writeln((t != 0 ? "-" : ""), t);
       }

        //readf("%s\n", &n);
        //++count;
        break;
    }

}

import std.stdio
    , std.typecons
    , std.traits
    , std.algorithm;

T mod(T)(auto ref T val) {
    import std.conv: to;
    return (val > 0.to!T
            ? val
            : -val);
}

void main() {

    long n;

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

    while(true) {
        if(n >= 0) {
            writeln(n);
            return;
        }

        auto n2 = n.mod % 100;

        if(n2 % 10 < n2 / 10) {
            const t = n.mod / 100 * 10 + n2 % 10;
            writeln((t != 0 ? "-" : ""), t);
        }
        else
        {

            const t = n.mod / 100 * 10 + n2 / 10;
            writeln((t != 0 ? "-" : ""), t);
       }
        break;
    }

}

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

int main(string[] argv)
{
	long n;
	scanf("%lld", &n);
	long a = n % 100;
	long b = (n / 100) * 10;
	long n1 = b + (a % 10);
	long n2 = b + ((a / 10) % 10);
	write(n > n1 ? n : n1 > n2 ? n1 : n2);
	return 0;
}

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

string[] tokens;
int tokenId = 0;
string readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }
int readInt() { return to!int(readToken); }
long readLong() { return to!long(readToken); }
real readReal() { return to!real(readToken); }

int del(int a) {
	int temp = abs(a);
	int first = temp / 10;
	int second = (temp / 100) * 10 + temp % 10;
	first *= -1;
	second *= -1;
	if(first < second) return second;
	return first;
}

void main () {
	int a = readInt();

	if(a >= 0) writeln(a);
	else writeln(del(a));
}

//ahmat
import core.stdc.stdio:printf,scanf;
import std.stdio;
import std.string;
import std.container;
import std.array;
import std.range;
import std.algorithm;
import std.math;
import std.numeric;
import std.conv;
import std.bitmanip;
import core.bitop;
int sz(Range)(in Range r){return cast(int)r.length;}
alias rbt=RedBlackTree!int;

void main(){
	int n=readln.chomp.to!int;
	if(n<0){
		writeln(max(n/10,10*(n/100)+n%10));
	}else writeln(n);
}

import std.algorithm;
import std.conv;
import std.stdio;

void main ()
{
    foreach (s; stdin.byLine ())
    {
        writeln (max (to!int (s), to!int (s[0..$ - 1]),
                  to!int (s[0..$ - 2] ~ s[$ - 1])));
    }
}

import std.algorithm, std.stdio;

void main ()
{
	int n;
	readf (" %s", &n);
	writeln (max (n, n / 10, n / 100 * 10 + n % 10));
}

import std.algorithm;
import std.stdio;

void main ()
{
	int n;
	while (readf (" %s", &n) != 0)
	{
		writeln (max (n, n / 10, n / 100 * 10 + n % 10));
	}
}

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

void main ()
{
	string s;
	while ((s = readln ().strip ()) != null)
	{
		if (s[0] == '-')
		{
			writeln (max (to!int (s[0..$ - 1]),
			              to!int (s[0..$ - 2] ~ s[$ - 1])));
		}
		else
		{
			writeln (s);
		}
	}
}

import std.stdio;
import std.conv;
import std.string;

void main() {
    string n = readln.chomp;
    if (n.to!long > 0) {
        writeln(n);
    } else {
        if (n[$-2].to!int < n[$-1].to!int) {
            writeln(n[0..$-1].to!long);
        } else {
            writeln((n[0..$-2] ~ n[$-1]).to!long);
        }
    }
}

import std.stdio: readln, writeln;
import std.string: strip;
import std.conv: to;
import std.algorithm: max;

/**
 * User: Jior
 * Date: 03.06.13
 * Time: 13:13
 */

void main(string[] args) {
    char[] buffer = strip(readln()).dup;
    int account = to!int(buffer);

    if (account < 0 && buffer.length > 2) {
        int var1 = to!int(buffer[0..$-1]);
        int var2 = to!int(buffer[0..$-2] ~ buffer[$-1..$]);

        if(var1 > account || var2 > account)
            writeln(max(var1, var2));
    } else {
        writeln(account);
    }
}

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

void main() {
    //stdin.open("input.txt", "r");
    //stdout.open("output.txt", "w");
    string num = strip(readln());
    if (num[0] == '-') {
        int a = to!int(num[0..$-1]);
        int b = to!int(num[0..$-2] ~ num[$-1..$]);
        writeln(a > b ? a : b);
    } else {
        writeln(num);
    }
}

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

// main================
void main(){
  auto moneyStr = readln.chomp.dup;
  auto a = moneyStr[0..$-1].to!int;
  auto b = (moneyStr[0..$-2] ~ moneyStr[$-1]).to!int;
  max(a, b).writeln;
}

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

int solve(string s) {
        if (s.to!int > 0) return s.to!int;
        else {
                if (s.to!int > -10) return s.to!int;
                else {
                        char[] s1 = s.dup;
                        s1 = s1.remove(s1.indexOf(max(s1[s1.length - 1], s1[s1.length - 2])));
                        return s1.to!int;
                }
        }
}
void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                string s = cin.readString;
                writeln(solve(s));
        }
}

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

int solve(string s) {
        if (s.to!int > 0) return s.to!int;
        else {
                if (s.to!int > -10) return s.to!int;
                else {
                        char[] s1 = s.dup;
                        reverse(s1);
                        s1 = s1.remove(s1.indexOf(max(s1[s1.length - 1], s1[s1.length - 2])));
                        reverse(s1);
                        return s1.to!int;
                }
        }
}
void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                string s = cin.readString;
                writeln(solve(s));
        }
}

import std.stdio
    , std.typecons
    , std.traits
    , std.algorithm;

T modulus(T)(auto ref T val) {
    import std.conv: to;
    return (val > 0.to!T
            ? val
            : -val);
}

void main() {

    long n;

    readf("%s\n", &n);
    //uint count;
    while(true) {
        //count.writeln;
        if(n >= 0) {
            writeln(n);
            return;
        }

        auto n2 = n.modulus % 100;

        if(n2 % 10 < n2 / 10) {
            writeln("-", n.modulus / 100 * 10 + n2 % 10);
        }
        else
        {

            const t = n.modulus / 100 * 10 + n2 / 10;
            writeln((t != 0 ? "-" : ""), n.modulus / 100 * 10 + n2 / 10);
       }

        //readf("%s\n", &n);
        //++count;
        break;
    }

}

import std.stdio
    , std.typecons
    , std.traits
    , std.algorithm;

T modulus(T)(auto ref T val) {
    import std.conv: to;
    return (val > 0.to!T
            ? val
            : -val);
}

void main() {

    long n;

    readf("%s\n", &n);
    //uint count;
    while(true) {
        //count.writeln;
        if(n >= 0) {
            writeln(n);
            return;
        }

        auto n2 = n.modulus % 100;

        if(n2 % 10 < n2 / 10) {
            writeln("-", n.modulus / 100 * 10 + n2 % 10);
        }
        else
        {
            writeln("-", n.modulus / 100 * 10 + n2 / 10);
        }

        //readf("%s\n", &n);
        //++count;
        break;
    }

}

import std.stdio
    , std.typecons
    , std.traits
    , std.algorithm;

T modulus(T)(auto ref T val) {
    import std.conv: to;
    return (val > 0.to!T
            ? val
            : -val);
}

void main() {

    long n;

    readf("%s\n", &n);
    //uint count;
    while(true) {
        //count.writeln;
        if(n >= 0) {
            writeln(n);
            return;
        }

        auto n2 = n.modulus % 100;

        if(n2 % 10 > n2 / 10) {
            writeln("-", n.modulus / 100 * 10 + n2 % 10);
        }
        else
        {
            writeln("-", n.modulus / 100 * 10 + n2 / 10);
        }

        //readf("%s\n", &n);
        //++count;
        break;
    }

}

import std.stdio;
import std.conv;
import std.string;

void main() {
    string n = readln.chomp;
    if (n.to!long > 0) {
        writeln(n);
    } else {
        if (n[$-2].to!int < n[$-1].to!int) {
            writeln(n[0..$-1]);
        } else {
            writeln(n[0..$-2], n[$-1]);
        }
    }
}

import std.stdio: readln, writeln;
import std.string: strip;
import std.conv: to;
import std.algorithm: max;

/**
 * User: Jior
 * Date: 03.06.13
 * Time: 13:13
 */

void main(string[] args) {
    char[] buffer = strip(readln()).dup;
    int account = to!int(buffer);

    if (account < 0 && buffer.length > 2) {
        int var1 = to!int(buffer[0..$-1]);
        int var2 = to!int(buffer[0..$-2] ~ buffer[$-1..$]);

        if(var1 > account || var2 > account)
            writeln(max(var1, var2));
    }
}


Polycarp plays "Game 23". Initially he has a number $$$n$$$ and his goal is to transform it to $$$m$$$. In one move, he can multiply $$$n$$$ by $$$2$$$ or multiply $$$n$$$ by $$$3$$$. He can perform any number of moves.Print the number of moves needed to transform $$$n$$$ to $$$m$$$. Print -1 if it is impossible to do so.It is easy to prove that any way to transform $$$n$$$ to $$$m$$$ contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation).

The only line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le m \le 5\cdot10^8$$$).

Print the number of moves to transform $$$n$$$ to $$$m$$$, or -1 if there is no solution.

NoteIn the first example, the possible sequence of moves is: $$$120 \rightarrow 240 \rightarrow 720 \rightarrow 1440 \rightarrow 4320 \rightarrow 12960 \rightarrow 25920 \rightarrow 51840.$$$ The are $$$7$$$ steps in total.In the second example, no moves are needed. Thus, the answer is $$$0$$$.In the third example, it is impossible to transform $$$48$$$ to $$$72$$$.

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

int solve(int n , int m) {
    if (m == n) return 0;
    if (m % n != 0) return -1;
    auto d = m/n;
    auto count = 0;
    if (d%2 != 0 && d%3!=0) return -1;
    while (d%6 == 0) {count+=2; d/=6;}
    while (d%3 == 0) {count++; d/=3;}
    while (d%2 == 0) {count++; d/=2;}
    if (d!=1) return -1;
    return count;
}

void main()
{
    assert(solve(120,51840) == 7);
    assert(solve(42,42)==0);
    assert(solve(48,72)==-1);

    auto nm = readln.split.map!"a.to!int";
    auto n = nm[0], m =nm[1];
    writeln(solve(n,m));
}

void main() {
    import std.stdio;
    import std.algorithm;
    import std.string;
    import std.conv;

    auto x = readln().split;
    const long start = x[0].to!long;
    long desti = x[1].to!long;

    if(desti == start) {
        "0".writeln;
    } else if(desti % start != 0) {
        "-1".writeln;
    } else if(desti % 2 != 0 && desti % 3 != 0) {
        "-1".writeln;
    } else {
        int cnt = 0;
        desti /= start;
        while(desti > 1) {
            if(desti % 3 == 0) {
                desti /= 3;
            } else if(desti % 2 == 0) {
                desti /= 2;
            } else {
                cnt = -1;
                break;
            }
            cnt++;
        }
        cnt.writeln;
    }
}

void main() {
    import std.stdio;
    import std.algorithm;
    import std.string;
    import std.conv;

    auto x = readln().split;
    const long start = x[0].to!long;
    long desti = x[1].to!long;
    if(desti == start) {
        "0".writeln;
    } else if(desti % start != 0) {
        "-1".writeln;
    } else if(desti % 2 != 0 && desti % 3 != 0) {
        "-1".writeln;
    } else {
        int cnt = 0;
        while(desti > start) {
            if(desti % 3 != 0) {
                desti /= 2;
            } else {
                desti /= 3;
            }
            cnt++;
        }
        cnt.writeln;
    }
}

void main() {
    import std.stdio;
    import std.algorithm;
    import std.string;
    import std.conv;

    auto x = readln().split;
    const long start = x[0].to!long;
    long desti = x[1].to!long;

    if(desti == start) {
        "0".writeln;
    } else if(desti % start != 0) {
        "-1".writeln;
    } else if(desti % 2 != 0 && desti % 3 != 0) {
        "-1".writeln;
    } else {
        int cnt = 0;
        desti /= start;
        while(desti > 1) {
            if(desti % 3 != 0) {
                desti /= 2;
            } else {
                desti /= 3;
            }
            cnt++;
        }
        cnt.writeln;
    }
}

void main() {
    import std.stdio;
    import std.algorithm;
    import std.string;
    import std.conv;

    auto x = readln().split;
    const int start = x[0].to!int;
    int desti = x[1].to!int;
    if(desti == start) {
        "0".writeln;
    } else if(desti % start != 0) {
        "-1".writeln;
    } else if(desti % 2 != 0 && desti % 3 != 0) {
        "-1".writeln;
    } else {
        int cnt = 0;
        while(desti > start) {
            if(desti % 3 != 0) {
                desti /= 2;
            } else {
                desti /= 3;
            }
            cnt++;
        }
        cnt.writeln;
    }
}

void main() {
    import std.stdio;
    import std.algorithm;
    import std.string;
    import std.conv;

    auto x = readln().split;
    const long start = x[0].to!long;
    long desti = x[1].to!long;

    if(desti == start) {
        "0".writeln;
    } else if(desti % start != 0) {
        "-1".writeln;
    } else if(desti % 2 != 0 && desti % 3 != 0) {
        "-1".writeln;
    } else {
        int cnt = 0;
        desti /= start;
        while(desti > 1) {
            if(desti % 3 != 0) {
                desti /= 2;
            } else if(desti % 2 != 0) {
                desti /= 3;
            } else {
                cnt = -1;
                break;
            }
            cnt++;
        }
        cnt.writeln;
    }
}

void main() {
    import std.stdio;
    import std.algorithm;
    import std.string;
    import std.conv;

    auto x = readln().split;
    const int start = x[0].to!int;
    int desti = x[1].to!int;

    if(desti % start != 0) {
        "-1".writeln;
    } else if(desti % 2 != 0 && desti % 3 != 0) {
        "-1".writeln;
    } else {
        int cnt = 0;
        while(desti > start) {
            if(desti % 3 != 0) {
                desti /= 2;
            } else {
                desti /= 3;
            }
            cnt++;
        }
        cnt.writeln;
    }
}


Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step.Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed to transform (1,1) into the pair where at least one number equals n.

The input contains the only integer n (1 ≤ n ≤ 106).

NoteThe pair (1,1) can be transformed into a pair containing 5 in three moves: (1,1)  →  (1,2)  →  (3,2)  →  (5,2).

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;

    int ans = n-1;
    foreach (i; 2 .. n/2 + 1) {
        int a = i, b = n - i;
        if (gcd(a, b) != 1) { continue; }

        int steps = 1;
        while (a != 1 && b != 1) {
            if (a < b) { swap(a, b); }

            steps += a / b;
            a %= b;
        }
        if (a > 1 || b > 1) { steps += a-1 + b-1; }

        ans = min(ans, steps);
    }

    ans.writeln;
}

import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;
import std.range;
import std.numeric;

void main(string[] args)
{
  inputFile = stdin;
  int stepsTo(int a, int b)
  {
    if (gcd(a, b) != 1) return int.max;
    if (a > b) swap(a, b);
    if (a == 1) return b - 1;
    return (b/a) + stepsTo(b % a, a);
  }
  auto n = next!int;
  if (n == 1) return writeln("0");
  (1 + iota(0, n).map!(i => stepsTo(i, n - i)).fold!min).writeln;
}
ulong bitCnt(long x)
{
  ulong cnt = 0;
  while(x) {cnt += x & 1; x>>=1;}
  return cnt;
}
alias Arr(T) = Mat!(T, 1);
struct Mat(T, size_t dimension)
{
  T[] _baseArray;
  T[] _slice;
  size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}
  size_t[dimension] _indexer;
  this(T[] baseArray, size_t[dimension] sizes)
  {
    _baseArray = baseArray;
    _sizes = sizes;
    _indexer[dimension - 1] = 1;
    static foreach_reverse(i; 0 .. dimension - 1)
      _indexer[i] = _indexer[i + 1] * _sizes[i + 1];
    auto requiredSize = _indexer[0] * _sizes[0];
    debug assert(_baseArray.length >= requiredSize);
    _slice = _baseArray[0 .. requiredSize];
  }
  this(size_t[dimension] sizes)
  {
    size_t reqSize = 1;
    static foreach(i; 0 .. dimension)
      reqSize *= sizes[i];
    this(new T[](reqSize), sizes);
  }
  ref auto opIndex()
  {
    pragma(inline, true);
    return _slice[];
  }
  ref auto opIndex(I...)(I i)
  {
    pragma(inline, true);
    debug assert(i.length <= dimension);
    size_t index = mixin(iota(0, i.length).map!(j => text("i[", j, "]*_indexer[", j, "]")).join("+"));
    static if (i.length == dimension)
      {
	return _slice[index];
      }
    else
      {
	enum sliceDimension = dimension - i.length;
	size_t[sliceDimension] remSizes = _sizes[i.length .. $];
	auto basePortion = _slice[index .. index + _indexer[i.length - 1]];
 	return Mat!(T, sliceDimension)(basePortion, remSizes);
      }
  }
  static if (dimension == 2)
    {
      auto identity()
      {
	debug assert(dim(0) == dim(1));
	auto n = dim(0);
	auto id = Mat!(T, 2)([n, n]);
	foreach(k; 0 .. n)
	  id[k, k] = T(1);
	return id;
      }
      bool canMultiply(Mat!(T, 2) b)
      {
	return this.dim(1) == b.dim(0);
      }
      auto opBinary(string op)(Mat!(T, 2) b)
	if (op == "*")
	  {
	    debug assert(canMultiply(b));
	    auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);
	    foreach(i; 0 .. res.dim(0))
	      foreach(k; 0 .. this.dim(1))
		foreach(j; 0 .. res.dim(1))
		  res[i, j] = res[i, j] + this[i, k] * b[k, j];
	    return res;
	  }
      auto opBinary(string op)(ulong exp)
	if (op == "^^")
	  {
	    return this.pow(identity, exp);
	  }
      mixin interiorBinPow;
    }
}

struct Mod(T, ulong mod)
{
  alias This = Mod!(T, mod);
  T _rep; T rep() {return _rep;}
  this(W)(W w)
  {
    _rep = ((cast(T) w)%mod + mod) % mod;
  }
  static auto plainConstruct(T t)
  {
    pragma(inline, true);
    debug assert(t >= 0 && t < mod);
    auto res = Mod!(T, mod).init;
    res._rep = t;
    return res;
  }
  string toString()
  {
    return to!string(rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plainConstruct(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plainConstruct(resrep);
      }
    else static if (op == "*")
      {
	return This(_rep * b._rep);
      }
  }
}

mixin template interiorBinPow()
{
  alias ThisType = typeof(this);
  auto pow(ThisType res, ulong exp)
    {
      if (exp < 0) debug assert(0);
      auto pow = this;
      while(exp)
	{
	  if (exp & 1)
	    res = res * pow;
	  pow = pow * pow;
	  exp >>= 1;
	}
      return res;
    }
}

// INPUT
File inputFile;
DList!string _words;
void _wordsFill()
{
  while (_words.empty) _words.insertBack(inputFile.readln.split);
}
string popWord()
{
  _wordsFill;
  auto word = _words.front;
  _words.removeFront;
  return word;
}
string peekWord()
{
  _wordsFill;
  return _words.front;
}
T next(T)()
{
  return to!T(popWord);
}
T peek(T)()
{
  return to!T(peekWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}


A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.The next prime number after x is the smallest prime number greater than x. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly x Roman soldiers, where x is a prime number, and next day they beat exactly y Roman soldiers, where y is the next prime number after x, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.Yesterday the Gauls beat n Roman soldiers and it turned out that the number n was prime! Today their victims were a troop of m Romans (m > n). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?

The first and only input line contains two positive integers — n and m (2 ≤ n < m ≤ 50). It is guaranteed that n is prime. Pretests contain all the cases with restrictions 2 ≤ n < m ≤ 4.

Print YES, if m is the next prime number after n, or NO otherwise.

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

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

void main() {
    int n, m; readf("%d %d\n", &n, &m);
    for (int i = n + 1; i < m; i++) {
        if (isPrime(i)) {
            "NO".writeln;
            return;
        }
    }
    if (!isPrime(m)) {
        "NO".writeln;
        return;
    }
    "YES".writeln;
}


Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way:  (for i ≥ 1). Here a, b, m are constants, fixed for the given realization of the pseudorandom numbers generator, r0 is the so-called randseed (this value can be set from the program using functions like RandSeed(r) or srand(n)), and  denotes the operation of taking the remainder of division.For example, if a = 2, b = 6, m = 12, r0 = 11, the generated sequence will be: 4, 2, 10, 2, 10, 2, 10, 2, 10, 2, 10, ....Polycarpus realized that any such sequence will sooner or later form a cycle, but the cycle may occur not in the beginning, so there exist a preperiod and a period. The example above shows a preperiod equal to 1 and a period equal to 2.Your task is to find the period of a sequence defined by the given values of a, b, m and r0. Formally, you have to find such minimum positive integer t, for which exists such positive integer k, that for any i ≥ k: ri = ri + t.

The single line of the input contains four integers a, b, m and r0 (1 ≤ m ≤ 105, 0 ≤ a, b ≤ 1000, 0 ≤ r0 < m), separated by single spaces.

Print a single integer — the period of the sequence.

NoteThe first sample is described above. In the second sample the sequence is (starting from the first element): 0, 3, 4, 1, 0, 3, 4, 1, 0, ...In the third sample the sequence is (starting from the first element): 33, 24, 78, 78, 78, 78, ...

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 a, b, m, r0;
    readf("%s %s %s %s", &a, &b, &m, &r0);
    readln;

    auto v = new int[] (m);
    v[] = -1;
    v[r0] = 0;

    int r = r0;
    int ans;
    while (true) {
        int newr = (a * r + b) % m;
        if (v[newr] != -1) {
            ans = v[r] + 1 - v[newr];
            break;
        }
        v[newr] = v[r] + 1;
        r = newr;
    }

    ans.writeln;
}


HQ9+ is a joke programming language which has only four one-character instructions: "H" prints "Hello, World!", "Q" prints the source code of the program itself, "9" prints the lyrics of "99 Bottles of Beer" song,  "+" increments the value stored in the internal accumulator.Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.

The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.

Output "YES", if executing the program will produce any output, and "NO" otherwise.

NoteIn the first case the program contains only one instruction — "H", which prints "Hello, World!".In the second case none of the program characters are language instructions.

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

void main(){
  auto source = readln.chomp;
  auto hq = "HQ9";
  auto res = "NO";
  foreach(s; hq){
    if(source.find(s).length){
      res = "YES";
      break;
    }
  }
  res.writeln;
}

import std.stdio;
import std.algorithm;

void main()
{
    (readln.any!(a => canFind(['H','Q','9'],a))
         ? "YES" : "NO")
        .writeln;
}

import std.stdio;
import std.string;

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

	if (indexOf(line, "H") != -1
	 || indexOf(line, "Q") != -1
	 || indexOf(line, "9") != -1)
	{
		write("YES");
	} else {
		write("NO");
	}
	return 0;
}

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

void main() {
  if (!match(readln, regex(`[HQ9]`)).empty) {
    "YES".writeln;
  } else {
    "NO".writeln;
  }
}

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

void main(){
  auto source = readln.chomp;
  auto hq = "HQ9+";
  auto res = "NO";
  foreach(s; hq){
    if(source.find(s).length){
      res = "YES";
      break;
    }
  }
  res.writeln;
}


Polycarp loves ciphers. He has invented his own cipher called repeating.Repeating cipher is used for strings. To encrypt the string $$$s=s_{1}s_{2} \dots s_{m}$$$ ($$$1 \le m \le 10$$$), Polycarp uses the following algorithm:  he writes down $$$s_1$$$ ones,  he writes down $$$s_2$$$ twice,  he writes down $$$s_3$$$ three times,  ...  he writes down $$$s_m$$$ $$$m$$$ times. For example, if $$$s$$$="bab" the process is: "b" $$$\to$$$ "baa" $$$\to$$$ "baabbb". So the encrypted $$$s$$$="bab" is "baabbb".Given string $$$t$$$ — the result of encryption of some string $$$s$$$. Your task is to decrypt it, i. e. find the string $$$s$$$.

The first line contains integer $$$n$$$ ($$$1 \le n \le 55$$$) — the length of the encrypted string. The second line of the input contains $$$t$$$ — the result of encryption of some string $$$s$$$. It contains only lowercase Latin letters. The length of $$$t$$$ is exactly $$$n$$$. It is guaranteed that the answer to the test exists.

Print such string $$$s$$$ that after encryption it equals $$$t$$$.

import std.stdio;
int f(int a)
{
	for (int i=0; i<=a; i++)
	{
		if (i*(i+1)/2==a)
		{
			return i;
		}
	}
	return 0;
}
int main()
{
	int a=0;
	string s;
	readf(" %d", &a);
	readf(" %s", &s);
	char[] m = s.dup;
	for (int i=0; i<f(a); i++)
	{
		write(m[i*(i+1)/2]);
	}
	return 0;
}


Pak Chanek plans to build a garage. He wants the garage to consist of a square and a right triangle that are arranged like the following illustration.  Define $$$a$$$ and $$$b$$$ as the lengths of two of the sides in the right triangle as shown in the illustration. An integer $$$x$$$ is suitable if and only if we can construct a garage with assigning positive integer values for the lengths $$$a$$$ and $$$b$$$ ($$$a<b$$$) so that the area of the square at the bottom is exactly $$$x$$$. As a good friend of Pak Chanek, you are asked to help him find the $$$N$$$-th smallest suitable number.

The only line contains a single integer $$$N$$$ ($$$1 \leq N \leq 10^9$$$).

An integer that represents the $$$N$$$-th smallest suitable number.

NoteThe $$$3$$$-rd smallest suitable number is $$$7$$$. A square area of $$$7$$$ can be obtained by assigning $$$a=3$$$ and $$$b=4$$$.

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

const bool dbg = true;
void DBG(alias x)() { static if (dbg) stderr.writefln("DBG: %s = %s", x.stringof, x); }
void MSG(in string x) { static if (dbg) stderr.writefln("MSG: %s", x); }

void main() {
    long N = readln.chomp.to!long;
    long C(long x) {
        if (x <= 2) return 0;
        if (x % 2 == 1) return C(x - 1) + 1;
        return x / 2 - 1 + x / 4 - 1;
    }
    long lb = 0, ub = 1L<<35;
    while (lb + 1 < ub) {
        long mid = (lb + ub) / 2;
        (C(mid) < N ? lb : ub) = mid;
    }
    writeln(ub);
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

const bool dbg = true;
void DBG(alias x)() { static if (dbg) stderr.writefln("DBG: %s = %s", x.stringof, x); }
void MSG(in string x) { static if (dbg) stderr.writefln("MSG: %s", x); }

void main() {
    int N = readln.chomp.to!int;
    long C(long x) {
        if (x % 2 == 1) return C(x - 1);
        return x / 2 + x / 4 - 1;
    }
    long lb = 2, ub = 1L<<35;
    while (lb + 1 < ub) {
        long mid = (lb + ub) / 2;
        (C(mid) <= N ? lb : ub) = mid;
    }
    writeln(lb);
}


Polycarp has $$$n$$$ coins, the value of the $$$i$$$-th coin is $$$a_i$$$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.For example, if Polycarp has got six coins represented as an array $$$a = [1, 2, 4, 3, 3, 2]$$$, he can distribute the coins into two pockets as follows: $$$[1, 2, 3], [2, 3, 4]$$$.Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of coins. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$) — values of coins.

Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.

module acmd;

import std.stdio;
import std.conv;
import std.algorithm;

int main () {
   version (offline_judje) {
      stdin.reopen ("input.txt", "rt");
   }
   int n;
   readf!" %d" (n);
   int[128] cnt;
   foreach (i; 0 .. n) {
      int num;
      readf!" %d" (num);
      cnt[num]++;
   }
   writeln (maxElement (cnt[]));

   return 0;
}

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

void main() {

	auto elemanSayisi = stdin.readln.strip.to!int();
	auto sayilar = stdin.readln.strip.split().map!(a => to!int(a)).array();
	auto sırayaDizilmişSayılar = sayilar.sort();

	int sonuç =  0;
	int birÖncekiEleman = sırayaDizilmişSayılar[0];
	int geçiciSonuç = 0;
	//1 , 2, 4 ,3 ,3 ,2 ,1
	for ( int i = 0 ; i < sırayaDizilmişSayılar.length; i++ )
	{
		int şuandakiEleman = sırayaDizilmişSayılar[i];
		if ( şuandakiEleman ==  birÖncekiEleman)
		{
			geçiciSonuç++;
			if ( geçiciSonuç > sonuç )
				sonuç = geçiciSonuç;
		}
		else
		{

			geçiciSonuç = 1;
			birÖncekiEleman = şuandakiEleman;
		}
	}
	writeln(sonuç);

}

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

void main()
{
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    int [int] cnt;
    arr.each!(x => ++cnt[x]);

    auto ans = cnt.values.maxElement;
    ans.writeln;
}

import std.stdio;
int main()
{
	int a=0;
	readf(" %d", &a);
	int[] m = new int[a];
	for (int i=0; i<a; i++)
	{
		readf(" %d", &m[i]);
	}
	int[100] n;
	for (int i=0; i<100; i++)
	{
		n[i]=0;
	}
	for (int i=0; i<100; i++)
	{
		int count=0;
		for (int j=0; j<a; j++)
		{
			if (m[j]==i+1)
			{
				count=count+1;
			}
		}
		n[i]=count;
	}
	int max=-1;
	for (int i=0; i<100; i++)
	{
		if (n[i]>max)
		{
			max=n[i];
		}
	}
	writeln(max);
	return 0;
}

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

void main() {

	auto elemanSayisi = stdin.readln.strip.to!int();
	auto sayilar = stdin.readln.strip.split().map!(a => to!int(a)).array();
	auto sırayaDizilmişSayılar = sayilar.sort();

	int sonuç =  0;
	int birÖncekiEleman = sırayaDizilmişSayılar[0];
	int geçiciSonuç = 0;
	//1 , 2, 4 ,3 ,3 ,2 ,1
	for ( int i = 0 ; i < sırayaDizilmişSayılar.length; i++ )
	{
		int şuandakiEleman = sırayaDizilmişSayılar[i];
		if ( şuandakiEleman ==  birÖncekiEleman)
		{
			geçiciSonuç++;
		}
		else
		{
			if ( geçiciSonuç > sonuç )
				sonuç = geçiciSonuç;
			geçiciSonuç = 0;
			birÖncekiEleman = şuandakiEleman;
		}
	}
	writeln(sonuç);

}

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

void main() {

	auto elemanSayisi = stdin.readln.strip.to!int();
	auto sayilar = stdin.readln.strip.split().map!(a => to!int(a)).array();
	auto sırayaDizilmişSayılar = sayilar.sort();

	int sonuç =  0;
	int birÖncekiEleman = sırayaDizilmişSayılar[0];
	int geçiciSonuç = 0;
	//1 , 2, 4 ,3 ,3 ,2 ,1
	for ( int i = 0 ; i < sırayaDizilmişSayılar.length; i++ )
	{
		int şuandakiEleman = sırayaDizilmişSayılar[i];
		if ( şuandakiEleman ==  birÖncekiEleman)
		{
			geçiciSonuç++;
		}
		else
		{
			if ( geçiciSonuç > sonuç )
				sonuç = geçiciSonuç;
			geçiciSonuç = 1;
			birÖncekiEleman = şuandakiEleman;
		}
	}
	writeln(sonuç);

}


Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.Note, that during capitalization all the letters except the first one remains unchanged.

A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.

Output the given word after capitalization.

import std.stdio;
import std.algorithm;
import std.range;
import std.ascii;

void main()
{
    string word = readln;
    (cast(char)word[0].toUpper~word[1..$]).writeln;
}

import std.stdio;
import std.string;
import std.typecons : Yes;
import std.algorithm.mutation : copy;
import std.conv : to;

void main() {
    foreach(string s; stdin.byLineCopy(Yes.keepTerminator)) {
        (s[0].toUpper.to!string ~ s[1 .. $]).copy(stdout.lockingTextWriter);
    }
}

import std.stdio;
import std.uni;
import std.string;
import core.stdc.stdio;
import std.array;
import std.algorithm;

int main(string[] argv)
{
	string line = readln();
	if (line[line.length - 1] == '\n') line.length--;
	write(capitalize("" ~ line[0]) ~ line[1..line.length]);
	return 0;
}

//ahmat
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.string;
import std.algorithm;
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(){
    dchar[] s=readln.strip.to!(dchar[]);
    writeln(toUpper(s[0]),s[1..$]);
}

//ahmat
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.string;
import std.algorithm;
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(){
    dchar[] s=readln.strip.to!(dchar[]);
    writeln(toUpper(s[0])~s[1..$]);
}

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

void main() {
  string s = readln;

  if (!match(s[0].to!string, regex(`[a-z]`)).empty) {
    (s[0].to!string.toUpper ~ s[1..$]).write;
  } else {
    s.write;
  }
}

module sigod.codeforces.p281A;

import std.stdio;
import std.string;
import std.conv;

void main()
{

	stdout.write(solve(stdin.readln().strip()));
}

string solve(string str)
{
	return toUpper(str[0].to!string) ~ str[1 .. $];
}

unittest {
	assert(solve("ApPLe") == "ApPLe");
	assert(solve("konjac") == "Konjac");
}

import std.stdio;
import std.string;
import std.typecons : Yes;
import std.algorithm.mutation : copy;

void main() {
    foreach(string s; stdin.byLineCopy(Yes.keepTerminator)) {
        s.capitalize.copy(stdout.lockingTextWriter());
    }
}


Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage.They will be N guests tonight: N - 1 real zombies and a fake one, our Heidi. The living-dead love hierarchies as much as they love brains: each one has a unique rank in the range 1 to N - 1, and Heidi, who still appears slightly different from the others, is attributed the highest rank, N. Tonight there will be a chest with brains on display and every attendee sees how many there are. These will then be split among the attendees according to the following procedure:The zombie of the highest rank makes a suggestion on who gets how many brains (every brain is an indivisible entity). A vote follows. If at least half of the attendees accept the offer, the brains are shared in the suggested way and the feast begins. But if majority is not reached, then the highest-ranked zombie is killed, and the next zombie in hierarchy has to make a suggestion. If he is killed too, then the third highest-ranked makes one, etc. (It's enough to have exactly half of the votes – in case of a tie, the vote of the highest-ranked alive zombie counts twice, and he will of course vote in favor of his own suggestion in order to stay alive.)You should know that zombies are very greedy and sly, and they know this too – basically all zombie brains are alike. Consequently, a zombie will never accept an offer which is suboptimal for him. That is, if an offer is not strictly better than a potential later offer, he will vote against it. And make no mistake: while zombies may normally seem rather dull, tonight their intellects are perfect. Each zombie's priorities for tonight are, in descending order:   survive the event (they experienced death already once and know it is no fun),  get as many brains as possible. Heidi goes first and must make an offer which at least half of the attendees will accept, and which allocates at least one brain for Heidi herself.What is the smallest number of brains that have to be in the chest for this to be possible?

The only line of input contains one integer: N, the number of attendees (1 ≤ N ≤ 109).

Output one integer: the smallest number of brains in the chest which allows Heidi to take one brain home.

import std.stdio, std.conv, std.string;

void main() {

	uint n = readln.strip.to!int;

	writeln(n & 1 ? n / 2 + 1 : n / 2);
}


Karl likes Codeforces and subsequences. He wants to find a string of lowercase English letters that contains at least $$$k$$$ subsequences codeforces. Out of all possible strings, Karl wants to find a shortest one.Formally, a codeforces subsequence of a string $$$s$$$ is a subset of ten characters of $$$s$$$ that read codeforces from left to right. For example, codeforces contains codeforces a single time, while codeforcesisawesome contains codeforces four times: codeforcesisawesome, codeforcesisawesome, codeforcesisawesome, codeforcesisawesome.Help Karl find any shortest string that contains at least $$$k$$$ codeforces subsequences.

The only line contains a single integer $$$k$$$ ($$$1 \leq k \leq 10^{16})$$$.

Print a shortest string of lowercase English letters that contains at least $$$k$$$ codeforces subsequences. If there are several such strings, print any of them.

import std.algorithm;
import std.conv;
import std.numeric;
import std.stdio;
import std.typecons;

immutable string answer = "codeforces";
immutable int len = 10;

void main ()
{
	long k;
	while (readf !(" %s") (k) > 0)
	{
		long [len] s;
		s[] = 1;
		long total = 1;
		for (int i = 0; total < k; i = (i + 1) % len)
		{
			total /= s[i];
			s[i] += 1;
			total *= s[i];
		}
		foreach (i; 0..len)
		{
			foreach (j; 0..s[i])
			{
				write (answer[i]);
			}
		}
		writeln;
	}
}

// Code By H~$~C

import std.stdio, std.format;
import std.math, std.uni, std.bigint, std.numeric;
import std.array, std.string, std.container, std.range, std.typecons;
import std.algorithm, std.conv, std.functional, std.random;

void _Main() {
  long k;
  readf!" %s"(k);
  if (k <= 1024) {
    int p = 1, c = 0;
    while (p < k) {
      p *= 2, c += 1;
    }
    foreach(i; "codeforces") {
      write(i);
      if (c) {
        write(i);
        c--;
      }
    }
  }
  else {
    long p = 2;
    while (true) {
      if (pow(p, 10) < k) {
        ++p;
      }
      else break;
    }
    --p;
    long r = pow(p, 10);
    int c = 0;
    while (r < k) {
      c += 1;
      r = r / p * (p + 1);
    }
    foreach(i; "codeforces") {
      foreach(j; 0 .. p) write(i);
      if (c) {
        write(i);
        c--;
      }
    }
  }
}

void main(string[] args) {
  int tests = 1;
//  readf!" %d"(tests);
  foreach (test; 0 .. tests) _Main();
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, 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)); }

// floor(a^(1/k))
ulong floorKthRoot(ulong a, ulong k) {
  import core.bitop : bsr;
  import std.algorithm : min;
  if (a == 0) {
    return 0;
  } else if (k <= 1) {
    return a;
  } else if (k == 2) {
    ulong b = a, x = 0, y = 0;
    for (int e = bsr(a) & ~1; e >= 0; e -= 2) {
      x <<= 1;
      y <<= 1;
      if (b >= (y | 1) << e) {
        b -= (y | 1) << e;
        x |= 1;
        y += 2;
      }
    }
    return x;
  } else if (k <= 40) {
    // min x s.t. x^k >= 2^64
    enum ulong[] HIS =
        [0, 0, 4294967296UL, 2642246, 65536, 7132, 1626, 566, 256, 139, 85, 57,
         41, 31, 24, 20, 16, 14, 12, 11, 10, 9, 8, 7, 7, 6, 6, 6, 5, 5, 5, 5,
         4, 4, 4, 4, 4, 4, 4, 4, 4];
    ulong lo = 1UL << (bsr(a) / k);
    ulong hi = min(1UL << (bsr(a) / k + 1), HIS[cast(size_t)(k)]);
    for (; lo + 1 < hi; ) {
      const ulong mid = (lo + hi) / 2;
      ulong b = mid * mid;
      foreach (i; 2 .. k) b *= mid;
      ((b <= a) ? lo : hi) = mid;
    }
    return lo;
  } else if (k <= 63) {
    return ((1UL << k) <= a) ? 2 : 1;
  } else {
    return 1;
  }
}

enum S = "codeforces";
enum L = cast(int)(S.length);

void main() {
  try {
    for (; ; ) {
      const K = readLong();

      const long a = floorKthRoot(K, L);
      foreach (m; 0 .. L + 1) {
        long prod = 1;
        foreach (i; 0 .. L) {
          prod *= ((i < m) ? (a + 1) : a);
        }
        if (prod >= K) {
          foreach (i; 0 .. L) {
            foreach (_; 0 .. ((i < m) ? (a + 1) : a)) {
              write(S[i]);
            }
          }
          writeln();
          break;
        }
      }
    }
  } catch (EOFException e) {
  }
}


Iahub got bored, so he invented a game to be played on paper. He writes n integers a1, a2, ..., an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1 ≤ i ≤ j ≤ n) and flips all values ak for which their positions are in range [i, j] (that is i ≤ k ≤ j). Flip the value of x means to apply operation x = 1 - x.The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub.

The first line of the input contains an integer n (1 ≤ n ≤ 100). In the second line of the input there are n integers: a1, a2, ..., an. It is guaranteed that each of those n values is either 0 or 1.

Print an integer — the maximal number of 1s that can be obtained after exactly one move.

NoteIn the first case, flip the segment from 2 to 5 (i = 2, j = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1].In the second case, flipping only the second and the third element (i = 2, j = 3) will turn all numbers into 1.

import std.stdio;

bool[] a;
byte n, max, ans;

void maxone(int x, int y) {
	max = 0;
	bool[] b = a[].dup;
	foreach (i; x .. y)
		b[i] ^= 1;
	foreach (i; 0 .. n)
		if (b[i])
			max += 1;
}

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

	bool c;
	foreach (i; 0 .. n) {
		readf(" %b", &c);
		a ~= c;
	}

	foreach (i; 0 .. n)
		foreach (j; i .. n) {
			maxone(i, j + 1);
			if (max > ans)
				ans = max;
		}

	writeln(ans);
}

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

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int initial_sum = 0;
	int[] bits; bits.length = n;
	foreach (int i; 0..n)
	{
		int b;
		scanf("%d", &b);
		initial_sum += (b == 0 ? 0 : 1);
		bits[i] = b;
	}
	int[] dp; dp.length = n;
	foreach (int i; 0..n)
	{
		dp[i] = initial_sum;
	}
	int max = int.min;
	foreach (int i; 0..n)
	{
		foreach (int j; 0..(i+1))
		{
			dp[j] = dp[j] - bits[i] + (1 - bits[i]);
			if (dp[j] > max)
				max = dp[j];
		}
	}
	printf("%d", max);
	return 0;
}

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

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int initial_sum = 0;
	int[] bits; bits.length = n;
	foreach (int i; 0..n)
	{
		int b;
		scanf("%d", &b);
		initial_sum += (b == 0 ? 0 : 1);
		bits[i] = b;
	}
	int[][] dp; dp.length = n;
	foreach (int i; 0..n)
	{
		dp[i].length = n;
	}
	int max = int.min;
	foreach (int i; 0..n)
	{
		foreach (int j; 0..(i+1))
		{
			int cm = (i > 0 && j < i ? dp[i-1][j] : initial_sum);
			dp[i][j] = cm - bits[i] + (1 - bits[i]);
			if (dp[i][j] > max)
				max = dp[i][j];
		}
	}
	printf("%d", max);
	return 0;
}

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

void main() {
    int n = readln.chomp.to!int;
    int[] a = readln.split.map!(x => x.to!int).array;
    int maxima = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= i; j++) {
            int ones = 0;
            for(int idx = 0; idx < n; idx++) {
                if(idx >= j && idx <= i)
                    ones += 1-a[idx];
                else
                    ones += a[idx];
            }
            maxima = max(maxima,ones);
        }
    }
    maxima.writeln;
}

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

void main() {
    int n; readf("%d\n", &n);
    int[] xs = readln.split.map!(to!int).array;
    int[][] cs = new int[][n + 1];
    for (int i = 0; i < n + 1; i++) {
        cs[i] = new int[n + 1];
    }
    for (int i = 0; i < n + 1; i++) {
        cs[i][i] = 0;
        for (int j = i; j < n; j++) {
            cs[i][j + 1] = cs[i][j] + xs[j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n + 1; j++) {
            ans = max(
                ans,
                cs[0][i] + (j - i) - cs[i][j] + cs[j][n]
            );
        }
    }
    ans.writeln;
}

import std.stdio;

bool[] a;
byte ans, one;

void main() {
	byte n;

	readf(" %s", &n);

	bool c;
	foreach (i; 0 .. n) {
		readf(" %b", &c);
		a ~= c;
		if (c)
			one +=1;
	}

	foreach (i; 0 .. n - 1) {
		if (!a[i]) {
			ans += 1;
			if (a[i + 1])
				break;
		}
	}

	byte temp = 0;
	foreach (i; 0 .. n - 1) {
		if (!a[i]) {
			temp += 1;
			if (a[i + 1]) {
				if (temp > ans)
					ans = temp;
				temp = 0;
			}
		}
	}

	writeln(ans + one);
}

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

void main() {
    int n = readln.chomp.to!int;
    int[] a = readln.split.map!(x => x.to!int).array;
    int maxima = -1;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < i; j++) {
            int ones = 0;
            for(int idx = 0; idx < n; idx++) {
                if(idx >= j && idx <= i)
                    ones += 1-a[idx];
                else
                    ones += a[idx];
            }
            maxima = max(maxima,ones);
        }
    }
    maxima.writeln;
}

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

void main() {
    int n = readln.chomp.to!int;
    int[] a = readln.split.map!(x => x.to!int).array;
    int maxima = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < i; j++) {
            int ones = 0;
            for(int idx = 0; idx < n; idx++) {
                if(idx >= j && idx <= i)
                    ones += 1-a[idx];
                else
                    ones += a[idx];
            }
            maxima = max(maxima,ones);
        }
    }
    if(n == 1)
        if(a[0] == 0)
            maxima = 1;
    maxima.writeln;
}

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

void main() {
    int n; readf("%d\n", &n);
    int[] xs = readln.split.map!(to!int).array;
    int[][] cs = new int[][n + 1];
    for (int i = 0; i < n + 1; i++) {
        cs[i] = new int[n + 1];
    }
    for (int i = 0; i < n + 1; i++) {
        cs[i][i] = 0;
        for (int j = i; j < n; j++) {
            cs[i][j + 1] = cs[i][j] + xs[j];
        }
    }
    int ans = max(cs[0][n], n - cs[0][n]);
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n + 1; j++) {
            ans = max(
                ans,
                cs[0][i] + (j - i) - cs[i][j] + cs[j][n]
            );
        }
    }
    ans.writeln;
}

import std.stdio;

bool[] a;
byte ans, one;

void main() {
	byte n;

	readf(" %s", &n);

	bool c;
	foreach (i; 0 .. n) {
		readf(" %b", &c);
		a ~= c;
		if (c)
			one +=1;
	}

	foreach (i; 0 .. n - 1) {
		if (!a[i]) {
			ans += 1;
			if (a[i + 1])
				break;
		}
	}

	byte temp = 0;
	foreach (i; 0 .. n - 1) {
		if (!a[i]) {
			temp += 1;
			if (a[i + 1]) {
				if (temp > ans)
					ans = temp;
				temp = 0;
			}
		}
	}

	if (n == 1 && a[0] == 1)
		writeln(0);
	else
		writeln(ans + one);
}

import std.stdio;

bool[] a;
byte ans, one;

void main() {
	byte n;

	readf(" %s", &n);

	bool c;
	foreach (i; 0 .. n) {
		readf(" %b", &c);
		a ~= c;
		if (c)
			one +=1;
	}

	foreach (i; 0 .. n - 1) {
		if (!a[i]) {
			ans += 1;
			if (a[i + 1])
				break;
		}
	}

	byte temp = 0;
	foreach (i; 0 .. n - 1) {
		if (!a[i]) {
			temp += 1;
			if (a[i + 1]) {
				if (temp > ans)
					ans = temp;
				temp = 0;
			}
		}
	}

	if (n == 1 && a[0] == 1)
		writeln(0);
	else
		if (n == 1 && a[0] == 0)
			writeln(1);
		else
			writeln(ans + one);
}


Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than minTimei and not more than maxTimei hours per each i-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours sumTime spent him on preparation, and now he wants to know if he can show his parents a timetable sсhedule with d numbers, where each number sсhedulei stands for the time in hours spent by Peter each i-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all schedulei should equal to sumTime.

The first input line contains two integer numbers d, sumTime (1 ≤ d ≤ 30, 0 ≤ sumTime ≤ 240) — the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following d lines contains two integer numbers minTimei, maxTimei (0 ≤ minTimei ≤ maxTimei ≤ 8), separated by a space — minimum and maximum amount of hours that Peter could spent in the i-th day.

In the first line print YES, and in the second line print d numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them.

import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex;

void main()
{
  auto input = readln().split().map!(to!int)();
  int[][] times;
  foreach (i; 0 .. input[0]) {
    times ~= readln().split().map!(to!int)().array();
  }
  foreach (i, t; times) {
    int sum;
    foreach (tt; times[0 .. i]) {
        sum += tt[1];
    }
    while (sum + t[1] > input[1]) {
        if (t[1] - 1 >= t[0]) {
            t[1]--;
        } else {
            auto minu = sum + t[1] - input[1];
            foreach_reverse (tt; times[0 .. i]) {
                while (minu) {
                    if (tt[0] == tt[1]) break;
                    else {
                        tt[1]--;
                        minu--;
                        sum--;
                    }
                }
            }

            if (minu) {
                writeln("NO");
                return;
            }
        }
    }
  }

  int sum;
  foreach (tt; times) {
    sum += tt[1];
  }
  if (sum != input[1]) {
    writeln("NO");
    return;
  }
  writeln("YES");
  foreach (t; times[0 .. $-1]) {
    write(t[1], " ");
  }
  writeln(times[$-1][1]);

}

import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex;

void main()
{
  auto input = readln().split().map!(to!int)();
  int[][] times;
  foreach (s; stdin.byLine()) {
  	times ~= s.split().map!(to!int)().array();
  }
  foreach (i, t; times) {
  	int sum;
  	foreach (tt; times[0 .. i]) {
  		sum += tt[1];
  	}
  	while (sum + t[1] > input[1]) {
  		if (t[1] - 1 >= t[0]) {
  			t[1]--;
  		} else {
  			auto minu = sum + t[1] - input[1];
  			foreach_reverse (tt; times[0 .. i]) {
  				while (minu) {
  					if (tt[0] == tt[1]) break;
  					else {
  						tt[1]--;
  						minu--;
  						sum--;
  					}
  				}
  			}

  			if (minu) {
  				writeln("NO");
  				return;
  			}
  		}
  	}
  }

  int sum;
  foreach (tt; times) {
  	sum += tt[1];
  }
  if (sum != input[1]) {
  	writeln("NO");
  	return;
  }
  writeln("YES");
  foreach (t; times[0 .. $-1]) {
  	write(t[1], " ");
  }
  writeln(times[$-1][1]);

}

import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex;

void main()
{
  int[][] times;
  int sum, diff;

  auto input = readln().split().map!(to!int)();

  a:foreach (s; stdin.byLine()) {
  	auto t = s.split().map!(to!int)().array();

  	while (sum + t[1] > input[1]) {
  		if (t[1] - 1 >= t[0]) {
  			t[1]--;
  		} else {
  			diff = sum + t[1] - input[1];
  			foreach_reverse (tt; times) {
  				while (tt[0] != tt[1] && diff) {
  					tt[1]--;
  					diff--;
  					sum--;
  				}
  			}
  		}
  		if (diff) break a;
  	}

  	times ~= t;
  	sum += t[1];
  }

  if (sum != input[1] || diff) {
  	writeln("NO");
  } else {
  	writeln("YES");
  	foreach (t; times[0 .. $-1]) {
  		write(t[1], " ");
  	}
  	writeln(times[$-1][1]);
  }

}

import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex;

void main()
{
  int[][] times;
  int sum, diff;

  auto input = readln().split().map!(to!int)();

  a:foreach (s; stdin.byLine()) {
    auto t = s.split().map!(to!int)().array();

    while (sum + t[1] > input[1]) {
        if (t[1] - 1 >= t[0]) {
            t[1]--;
        } else {
            diff = sum + t[1] - input[1];
            foreach_reverse (tt; times) {
                while (tt[0] != tt[1]) {
                    tt[1]--;
                    diff--;
                    sum--;
                }
            }
        }
        if (diff) break a;
    }

    times ~= t;
    sum += t[1];
  }

  if (sum != input[1] || diff) {
    writeln("NO");
  } else {
    writeln("YES");
    foreach (t; times[0 .. $-1]) {
        write(t[1], " ");
    }
    writeln(times[$-1][1]);
  }

}

import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex;

void main()
{
  int[][] times;
  int sum, diff;

  auto input = readln().split().map!(to!int)();

  a:foreach (s; stdin.byLine()) {
  	auto t = s.split().map!(to!int)().array();

  	while (sum + t[1] > input[1]) {
  		if (t[1] - 1 >= t[0]) {
  			t[1]--;
  		} else {
  			diff = sum + t[1] - input[1];
  			foreach_reverse (tt; times) {
  				while (tt[0] != tt[1] && diff) {
  					tt[1]--;
  					diff--;
  					sum--;
  				}
  			}
  		}
  		if (diff) {writeln("u");break a;}
  	}

  	times ~= t;
  	sum += t[1];
  }

  if (sum != input[1] || diff) {
  	writeln("NO");
  } else {
  	writeln("YES");
  	foreach (t; times[0 .. $-1]) {
  		write(t[1], " ");
  	}
  	writeln(times[$-1][1]);
  }

}

import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex;

void main()
{
  auto input = readln().split().map!(to!int)();
  int[][] times;
  foreach (i; 0 .. input[0]) {
    times ~= readln().split().map!(to!int)().array();
  }
  foreach (i, t; times) {
    int sum;
    foreach (tt; times[0 .. i]) {
        sum += tt[1];
    }
    while (sum + t[1] > input[1]) {
        if (t[1] - 1 >= t[0]) {
            t[1]--;
        } else {
            auto minu = sum + t[1] - input[1];
            foreach_reverse (tt; times[0 .. i]) {
                while (minu) {
                    if (tt[0] == tt[1]) break;
                    else {
                        tt[1]--;
                        minu--;
                    }
                }
            }

            if (minu) {
                writeln("NO");
                return;
            }
        }
    }
  }

  int sum;
  foreach (tt; times) {
    sum += tt[1];
  }
  if (sum != input[1]) {
    writeln("NO");
    return;
  }
  writeln("YES");
  foreach (t; times[0 .. $-1]) {
    write(t[1], " ");
  }
  writeln(times[$-1][1]);

}


A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.

The first line contains a single integer n (1 ≤ n ≤ 106).

In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers. In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.

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

void main() {
  string s = readln.chomp;
  int n = s.minPos!"a > b"[0] - 48;
  n.writeln;
  n.iota
    .map!(i => s.map!(c => c > i + 48 ? "1" : "0").join.find!"a!=48").join(" ").writeln;
}

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

char[] n;
long[] result;

void main() {
	n = cast(char[])(readln().strip);
	for (;;) {
		string t;
		for (int i = 0; i < n.length; ++i)
			if (n[i] == '0')
				t ~= '0';
			else {
				t ~= '1';
				--n[i];
			}
		if (to!long(t))
			result ~= to!long(t);
		else
			break;
	}
	writeln(result.length);
	writefln("%(%s %)", result);
}

import std.math;
import std.stdio;

void main() {
	uint n;
	readf(`%u`, &n);
	uint[] res;

	while(n) {
		int k = cast(int)log10(n).floor.lrint, m = 10 ^^ k;

		loop: foreach(_; 0..n / m) {
			foreach(ref p; res)
				if(p / m % 10 == 0) {
					p += m;
					continue loop;
				}

			res ~= m;
		}

		n %= m;
	}

	writef("%u\n%(%u %)", res.length, res);
}

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, std.bitmanip;

int N;
int[] Q;

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

    int q = 1;
    while (format("%b", q).to!int <= 10^^6) {
        Q ~= format("%b", q).to!int;
        q++;
    }

    auto dp = new int[](N+1);
    fill(dp, 1 << 30);
    dp[0] = 0;
    auto fukugen = new int[](N+1);

    foreach (i; 0..N+1) {
        foreach (j; 0..Q.length.to!int) {
            if (i + Q[j] <= N && dp[i]+1 < dp[i+Q[j]]) {
                dp[i+Q[j]] = dp[i]+1;
                fukugen[i+Q[j]] = Q[j];
            }
        }
    }

    dp[N].writeln;
    int[] ans;
    int a = N;
    while (a > 0) {
        ans = fukugen[a] ~ ans;
        a -= fukugen[a];
    }
    ans.map!(to!string).join(" ").writeln;
}

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

immutable int MAX_N = 1_000_003;
immutable int BASE  =        10;

void main ()
{
	int [] d;
	foreach (i; 0..MAX_N)
	{
		bool ok = true;
		int v = i;
		while (v > 0)
		{
			ok &= (v % BASE) < 2;
			v /= BASE;
		}
		if (ok)
		{
			d ~= i;
		}
	}

	auto f = new int [MAX_N];
	f[1..$] = int.max >> 1;
	auto p = new int [MAX_N];
	p[] = 0;
	foreach (i; 0..MAX_N)
	{
		foreach (c; d)
		{
			if (c > i)
			{
				break;
			}
			if (f[i] > f[i - c] + 1)
			{
				f[i] = f[i - c] + 1;
				p[i] = c;
			}
		}
	}

	int n;
	while (readf (" %s", &n) > 0)
	{
		int [] ans;
		while (n)
		{
			ans ~= p[n];
			n -= p[n];
		}
		writeln (ans.length);
		writefln ("%(%s %)", ans);
	}
}

import std.math;
import std.stdio;

void main() {
	uint n;
	readf(`%u`, &n);
	uint[] res;

	while(n) {
		int t, k = cast(int)log10(n).floor.lrint;

		while(true) {
			auto c = t + 10 ^^ k--;
			if(c > n) break;
			else t = c;
			if(k < 0) break;
		}

		n -= t;
		res ~= t;
	}

	writef("%u\n%(%u %)", res.length, res);
}

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, std.bitmanip;

int N;
int[] Q;
Tuple!(int, int)[int] mem;

int dp(int n) {
    if (n < 10) return n;
    if (n in mem) return mem[n][0];

    mem[n] = tuple(1 << 30, -1);
    foreach (q; Q) {
        if (n >= q) {
            auto ret = dp(n-q) + 1;
            if (ret < mem[n][0]) {
                mem[n] = tuple(ret, q);
            }
        }
    }
    return mem[n][0];
}

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

    int q = 2;
    while (format("%b", q).to!int <= 10^^6) {
        Q ~= format("%b", q).to!int;
        q++;
    }

    reverse(Q);
    auto ans = dp(N);

    int[] ans2;
    while (N >= 10) {
        auto a = mem[N][1];
        ans2 ~= a;
        N -= a;
    }
    while (N--) {
        ans2 ~= 1;
    }
    ans2.map!(c => c.to!string).join(" ").writeln;
}

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

void main() {
  auto s = readln.chomp;
  writeln(s);
  (s.minPos!"a > b"[0] - 48).iota
    .map!(i => s.map!(c => c > i + 48 ? "1" : "0").join.find!"a!=48").join(" ").writeln;
}

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

void main() {
  auto s = readln.chomp;;
  (s.minPos!"a > b"[0] - 48).iota
    .map!(i => s.map!(c => c > i + 48 ? "1" : "0").join.find!"a!=48")
      .join(" ").writeln;
}


Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you.Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers.Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 12$$$) — the number of pairs the first participant communicated to the second and vice versa. The second line contains $$$n$$$ pairs of integers, each between $$$1$$$ and $$$9$$$, — pairs of numbers communicated from first participant to the second. The third line contains $$$m$$$ pairs of integers, each between $$$1$$$ and $$$9$$$, — pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair $$$(1,2)$$$, there will be no pair $$$(2,1)$$$ within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number.

If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print $$$0$$$. Otherwise print $$$-1$$$.

NoteIn the first example the first participant communicated pairs $$$(1,2)$$$ and $$$(3,4)$$$, and the second communicated $$$(1,5)$$$, $$$(3,4)$$$. Since we know that the actual pairs they received share exactly one number, it can't be that they both have $$$(3,4)$$$. Thus, the first participant has $$$(1,2)$$$ and the second has $$$(1,5)$$$, and at this point you already know the shared number is $$$1$$$.In the second example either the first participant has $$$(1,2)$$$ and the second has $$$(1,5)$$$, or the first has $$$(3,4)$$$ and the second has $$$(6,4)$$$. In the first case both of them know the shared number is $$$1$$$, in the second case both of them know the shared number is $$$4$$$. You don't have enough information to tell $$$1$$$ and $$$4$$$ apart.In the third case if the first participant was given $$$(1,2)$$$, they don't know what the shared number is, since from their perspective the second participant might have been given either $$$(1,3)$$$, in which case the shared number is $$$1$$$, or $$$(2,3)$$$, in which case the shared number is $$$2$$$. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is $$$-1$$$.

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, 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)); }

void main() {
  try {
    for (; ; ) {
      const M = readInt();
      const N = readInt();
      auto A = new int[M];
      foreach (i; 0 .. M) {
        A[i] |= 1 << readInt();
        A[i] |= 1 << readInt();
      }
      auto B = new int[N];
      foreach (j; 0 .. N) {
        B[j] |= 1 << readInt();
        B[j] |= 1 << readInt();
      }

      int ans = -1;
      int you;
      foreach (i; 0 .. M) foreach (j; 0 .. N) {
        const c = A[i] & B[j];
        if (popcnt(c) == 1) {
          you |= c;
        }
      }
      if (popcnt(you) == 1) {
        ans = bsf(you);
      } else {
        bool okA = true;
        foreach (i; 0 .. M) {
          int they;
          foreach (j; 0 .. N) {
            const c = A[i] & B[j];
            if (popcnt(c) == 1) {
              they |= c;
            }
          }
          okA = okA && (popcnt(they) <= 1);
        }
        bool okB = true;
        foreach (j; 0 .. N) {
          int they;
          foreach (i; 0 .. M) {
            const c = A[i] & B[j];
            if (popcnt(c) == 1) {
              they |= c;
            }
          }
          okB = okB && (popcnt(they) <= 1);
        }
        if (okA && okB) {
          ans = 0;
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, 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)); }

void main() {
  try {
    for (; ; ) {
      const M = readInt();
      const N = readInt();
      auto A = new int[M];
      foreach (i; 0 .. M) {
        A[i] |= 1 << readInt();
        A[i] |= 1 << readInt();
      }
      auto B = new int[N];
      foreach (j; 0 .. N) {
        B[j] |= 1 << readInt();
        B[j] |= 1 << readInt();
      }

      int ans = -1;
      int you;
      foreach (i; 0 .. M) foreach (j; 0 .. N) {
        const c = A[i] & B[j];
        if (popcnt(c) == 1) {
          you |= c;
        }
      }
      if (popcnt(you) == 1) {
        ans = bsf(you);
      } else {
        bool okA, okB;
        foreach (i; 0 .. M) {
          int they;
          foreach (j; 0 .. N) {
            const c = A[i] & B[j];
            if (popcnt(c) == 1) {
              they |= c;
            }
          }
          if (popcnt(they) == 1) {
            okA = true;
          }
        }
        foreach (j; 0 .. N) {
          int they;
          foreach (i; 0 .. M) {
            const c = A[i] & B[j];
            if (popcnt(c) == 1) {
              they |= c;
            }
          }
          if (popcnt(they) == 1) {
            okB = true;
          }
        }
        if (okA && okB) {
          ans = 0;
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.At first day Mister B read v0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v0 pages, at second — v0 + a pages, at third — v0 + 2a pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than v1 pages per day.Also, to refresh his memory, every day, starting from the second, Mister B had to reread last l pages he read on the previous day. Mister B finished the book when he read the last page for the first time.Help Mister B to calculate how many days he needed to finish the book.

First and only line contains five space-separated integers: c, v0, v1, a and l (1 ≤ c ≤ 1000, 0 ≤ l < v0 ≤ v1 ≤ 1000, 0 ≤ a ≤ 1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.

Print one integer — the number of days Mister B needed to finish the book.

NoteIn the first sample test the book contains 5 pages, so Mister B read it right at the first day.In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.In third sample test every day Mister B read 1 page of the book, so he finished in 15 days.

// 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;

immutable inf = 10^^9 + 7;

int c, v0, v1, a, l;

void main() {
    scan(c, v0, v1, a, l);

    int r;
    int cnt;

    while (true) {
        cnt++;
        r += min(v0 + a * (cnt - 1), v1);

        if (r >= c) {
            writeln(cnt);
            return;
        }

        r -= l;
    }
}

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);
        }
    }
}


Alice is the leader of the State Refactoring Party, and she is about to become the prime minister. The elections have just taken place. There are $$$n$$$ parties, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th party has received $$$a_i$$$ seats in the parliament.Alice's party has number $$$1$$$. In order to become the prime minister, she needs to build a coalition, consisting of her party and possibly some other parties. There are two conditions she needs to fulfil:   The total number of seats of all parties in the coalition must be a strict majority of all the seats, i.e. it must have strictly more than half of the seats. For example, if the parliament has $$$200$$$ (or $$$201$$$) seats, then the majority is $$$101$$$ or more seats.  Alice's party must have at least $$$2$$$ times more seats than any other party in the coalition. For example, to invite a party with $$$50$$$ seats, Alice's party must have at least $$$100$$$ seats. For example, if $$$n=4$$$ and $$$a=[51, 25, 99, 25]$$$ (note that Alice'a party has $$$51$$$ seats), then the following set $$$[a_1=51, a_2=25, a_4=25]$$$ can create a coalition since both conditions will be satisfied. However, the following sets will not create a coalition:  $$$[a_2=25, a_3=99, a_4=25]$$$ since Alice's party is not there;  $$$[a_1=51, a_2=25]$$$ since coalition should have a strict majority;  $$$[a_1=51, a_2=25, a_3=99]$$$ since Alice's party should have at least $$$2$$$ times more seats than any other party in the coalition. Alice does not have to minimise the number of parties in a coalition. If she wants, she can invite as many parties as she wants (as long as the conditions are satisfied). If Alice's party has enough people to create a coalition on her own, she can invite no parties.Note that Alice can either invite a party as a whole or not at all. It is not possible to invite only some of the deputies (seats) from another party. In other words, if Alice invites a party, she invites all its deputies.Find and print any suitable coalition.

The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the number of parties. The second line contains $$$n$$$ space separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 100$$$) — the number of seats the $$$i$$$-th party has.

If no coalition satisfying both conditions is possible, output a single line with an integer $$$0$$$. Otherwise, suppose there are $$$k$$$ ($$$1 \leq k \leq n$$$) parties in the coalition (Alice does not have to minimise the number of parties in a coalition), and their indices are $$$c_1, c_2, \dots, c_k$$$ ($$$1 \leq c_i \leq n$$$). Output two lines, first containing the integer $$$k$$$, and the second the space-separated indices $$$c_1, c_2, \dots, c_k$$$.  You may print the parties in any order. Alice's party (number $$$1$$$) must be on that list. If there are multiple solutions, you may print any of them.

NoteIn the first example, Alice picks the second party. Note that she can also pick the third party or both of them. However, she cannot become prime minister without any of them, because $$$100$$$ is not a strict majority out of $$$200$$$.In the second example, there is no way of building a majority, as both other parties are too large to become a coalition partner.In the third example, Alice already has the majority. The fourth example is described in the problem statement.

/+ dub.sdl:
    name "A"
    dependency "dunkelheit" version="1.0.1"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner;

int main() {
    Scanner sc = new Scanner(stdin);
    scope(exit) assert(!sc.hasNext);

    int n;
    long[] a;
    sc.read(n, a);

    long sm = a.sum;
    int[] our = iota(n).filter!(i => i == 0 || 2 * a[i] <= a[0]).array;
    long my = our.map!(i => a[i]).sum;

    debug writeln(sm, " ", my, " ", our);

    if (sm >= my * 2) {
        writeln("0");
    } else {
        writeln(our.length);
        writeln(our.map!"a + 1".map!(to!string).join(" "));
    }
    return 0;
}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/foundation.d */

// module dkh.foundation;

static if (__VERSION__ <= 2070) {
    /*
    Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
    Copyright: Andrei Alexandrescu 2008-.
    License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
    */
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }

}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;

struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
    import core.exception : RangeError;

    private T* _data;
    private uint len, cap;

    @property bool empty() const { return len == 0; }
    @property size_t length() const { return len; }
    alias opDollar = length;

    inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }

    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        return _data[i];
    }
    ref inout(T) front() inout { return this[0]; }
    ref inout(T) back() inout { return this[$-1]; }

    void reserve(size_t newCap) {
        import core.memory : GC;
        import core.stdc.string : memcpy;
        import std.conv : to;
        if (newCap <= cap) return;
        void* newData = GC.malloc(newCap * T.sizeof);
        cap = newCap.to!uint;
        if (len) memcpy(newData, _data, len * T.sizeof);
        _data = cast(T*)(newData);
    }
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }

    void clear() {
        len = 0;
    }

    void insertBack(T item) {
        import std.algorithm : max;
        if (len == cap) reserve(max(cap * 2, MINCAP));
        _data[len++] = item;
    }
    alias opOpAssign(string op : "~") = insertBack;
    void removeBack() {
        assert(!empty, "StackPayload.removeBack: Stack is empty");
        len--;
    }
}

/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;

// import dkh.container.stackpayload;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    private File f;

    this(File f) {
        this.f = f;
    }
    private char[512] lineBuf;
    private char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    assert(succW());
                    x[i] = line.parse!E;
                }
            } else {
                StackPayload!E buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }

    int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }

    void read(Args...)(auto ref Args args) {
        import std.exception : enforce;
        static if (args.length != 0) {
            enforce(readSingle(args[0]));
            read(args[1..$]);
        }
    }

    bool hasNext() {
        return succ();
    }
}

/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/

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)); }

int N;
int[] A;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      int[] ans;
      ans ~= 0;
      foreach (i; 1 .. N) {
        if (A[0] >= 2 * A[i]) {
          ans ~= i;
        }
      }
      int sum;
      foreach (i; ans) {
        sum += A[i];
      }
      if (2 * sum > A.sum) {
        writeln(ans.length);
        foreach (index, i; ans) {
          if (index > 0) {
            write(" ");
          }
          write(i + 1);
        }
        writeln();
      } else {
        writeln(0);
      }
    }
  } catch (EOFException e) {
  }
}


PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number".Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any n.

The only number in the input is n (1 ≤ n ≤ 1000) — number from the PolandBall's hypothesis.

Output such m that n·m + 1 is not a prime number. Your answer will be considered correct if you output any suitable m such that 1 ≤ m ≤ 103. It is guaranteed the the answer exists.

NoteA prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.For the first sample testcase, 3·1 + 1 = 4. We can output 1.In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, m = 2 is okay since 4·2 + 1 = 9, which is not a prime number.

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

bool prime(int n)
{
    int i=2;
    for(;i<n/2+1;i++)
    {
        if(n%i==0)
            return true;
    }
    return false;
}
void main(string[] args)
{
    int n = 0;
    int k = 1;
    scanf("%d", &n);
    while(!prime(n*k+1))
    {
        k++;
    }
    writeln(k);
}

import core.bitop;
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

bool isPrime (int v)
{
	if (v < 2)
	{
		return false;
	}
	for (int d = 2; d * d <= v; d++)
	{
		if (v % d == 0)
		{
			return false;
		}
	}
	return true;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		for (int m = 1; ; m++)
		{
			if (!isPrime (n * m + 1))
			{
				writeln (m);
				break;
			}
		}
	}
}

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

bool prime(int n)
{
    int i=2;
    for(;i<n/2+1;i++)
    {
        if(n%i==0)
            return true;
    }
    return false;
}
void main(string[] args)
{
    int n = 0;
    int k = 1;
    scanf("%d", &n);
    while(prime(n*k+1))
    {
        k++;
    }
    writeln(k);
}