Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $$$x$$$ in an array. For an array $$$a$$$ indexed from zero, and an integer $$$x$$$ the pseudocode of the algorithm is as follows:  Note that the elements of the array are indexed from zero, and the division is done in integers (rounding down).Andrey read that the algorithm only works if the array is sorted. However, he found this statement untrue, because there certainly exist unsorted arrays for which the algorithm find $$$x$$$!Andrey wants to write a letter to the book authors, but before doing that he must consider the permutations of size $$$n$$$ such that the algorithm finds $$$x$$$ in them. A permutation of size $$$n$$$ is an array consisting of $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ in arbitrary order.Help Andrey and find the number of permutations of size $$$n$$$ which contain $$$x$$$ at position $$$pos$$$ and for which the given implementation of the binary search algorithm finds $$$x$$$ (returns true). As the result may be extremely large, print the remainder of its division by $$$10^9+7$$$.

The only line of input contains integers $$$n$$$, $$$x$$$ and $$$pos$$$ ($$$1 \le x \le n \le 1000$$$, $$$0 \le pos \le n - 1$$$) — the required length of the permutation, the number to search, and the required position of that number, respectively.

Print a single number — the remainder of the division of the number of valid permutations by $$$10^9+7$$$.

// Cheese-Cracker: cheese-cracker.github.io

const ll PRIME = 10^^9 + 7;

void play(){
    ll n, x, pos;
    n = rd; x = rd; pos = rd;
    ll clo = x-1, chi = n - x;
    ll res = 1;
    int lo = 0, hi = n.to!int;
    while(lo < hi){
        int midd = (lo + hi)/2;
        show(midd, pos, clo, chi);
        if(midd <= pos){
            if(pos != midd){
                res *= clo;
                res %= PRIME;
                --clo;
            }
            lo = midd + 1;
        }else{
            res *= chi;
            res %= PRIME;
            --chi;
            hi = midd;
        }
    }
    assert(lo - 1 == pos);
    ll left = chi + clo;
    show(left);
    foreach(i; 1..left+1){
        res *= i;
        res %= PRIME;
    }
    writeln(res);
}

int main(){
    long t = 1;
    /* t = rd;        // Toggle! */
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }
alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, "x",  long, "y");
T max(T = long)(T a, T b){ return (a > b) ? a : b; }
T min(T = long)(T a, T b){ return (a < b) ? a : b; }


Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.

You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.

Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.

NoteIn the first example the ticket is already lucky, so the answer is 0.In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.

// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio     : readln, writeln;
import std.string    : chomp;
import std.array     : split;
import std.conv      : to;
import std.algorithm : sum;

auto gets() { return readln.chomp; }
auto getNum(T)() { return gets.to!T; }
auto getVals(T)() { return gets.split.to!(T[]); }

void main() {
    auto n = getNum!int;
    int[6] xs;
    for (int i = 0; i < 6; i++) {
        xs[i] = n % 10;
        n = (n - n % 10) / 10;
    }
    auto check = () => sum(xs[0..3]) == sum(xs[3..$]);
    if (check()) {
        writeln(0);
        return;
    }
    foreach (i; 0..6) {
        auto backup = xs[i];
        foreach (j; 0..10) {
            xs[i] = j;
            if (check()) {
                writeln(1);
                return;
            }
        }
        xs[i] = backup;
    }
    foreach (i; 0..5) {
        auto backupA = xs[i];
        foreach (a; 0..10) {
            xs[i] = a;
            foreach (j; i+1..6) {
                auto backupB = xs[j];
                foreach (b; 0..10) {
                    xs[j] = b;
                    if (check()) {
                        writeln(2);
                        return;
                    }
                }
                xs[j] = backupB;
            }
        }
        xs[i] = backupA;
    }
    writeln(3);
}


Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.   Initially, each hole has $$$a_i$$$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.Note that the counter-clockwise order means if the player takes the stones from hole $$$i$$$, he will put one stone in the $$$(i+1)$$$-th hole, then in the $$$(i+2)$$$-th, etc. If he puts a stone in the $$$14$$$-th hole, the next one will be put in the first hole.After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.

The only line contains 14 integers $$$a_1, a_2, \ldots, a_{14}$$$ ($$$0 \leq a_i \leq 10^9$$$) — the number of stones in each hole. It is guaranteed that for any $$$i$$$ ($$$1\leq i \leq 14$$$) $$$a_i$$$ is either zero or odd, and there is at least one stone in the board.

Output one integer, the maximum possible score after one move.

NoteIn the first test case the board after the move from the hole with $$$7$$$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $$$4$$$.

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;

void main()
{
	enum N = 14;
	long[] a = readln.chomp.split.map!(to!long).array;
	long ans = 0;
	foreach (i, v; a) {
		// simulate
		long[] b = a.dup;
		b[i] = 0;
		foreach (j; 0..N) {
			b[cast(uint)((i + j + 1) % N)] += v / N;
		}
		foreach (j; 0 .. v % N) {
			++b[cast(uint)((i + j + 1) % N)];
		}
		long sub = 0;
		foreach (w; b) {
			if (w % 2 == 0) {
				sub += w;
			}
		}
		ans = max(ans, sub);
	}
	ans.writeln;
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in ref Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}

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

void main()
{
    auto a = readln.splitter.map!(to!int).array;
    a ~= a;
    long ans = 0;
    foreach (i; 0..14) {
        auto now = a[i+1..i+1+14].dup;

        debug { writeln(now); }

        now[$-1] = 0;

        auto curVal = (int j, long e) => e + a[i] / 14 + (a[i] % 14 >= j);
        auto vals = now.enumerate(1).map!(x => curVal(x.index, x.value));

        debug { writeln(vals); }

        ans = max (ans, vals.filter!(x => x % 2 == 0).sum);
    }

    writeln (ans);
}

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  long[] a; readA(14, a);

  auto ans = 0L;
  foreach (i; 0..14) {
    auto b = a.dup;
    b[i] = 0;
    foreach (j; 0..14)
      b[(i+j+1)%14] += a[i]/14 + (j < a[i]%14);

    auto r = 0L;
    foreach (j; 0..14)
      if (b[j]%2 == 0) r += b[j];
    ans = max(ans, r);
  }

  writeln(ans);
}

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

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		auto a = s.splitter.map !(to !(long)).array;
		auto n = a.length;
		long res = 0;
		foreach (i; 0..n)
		{
			auto q = a[i] / n;
			auto r = a[i] % n;
			auto b = a.dup;
			b[i] = 0;
			foreach (j; 0..n)
			{
				b[(i + j + 1) % n] += q + (j < r);
			}
			auto cur = b.filter !(x => x % 2 == 0).sum;
			res = max (res, cur);
		}
		writeln (res);
	}
}

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

  int n=14;
  auto a=readln.split.to!(long[]);
  long ret=0;
  foreach(i; 0..n)if(a[i]>0){
    auto b=a.dup;
    long k=b[i];
    b[i]=0;
    foreach(j; 0..n) b[j]+=k/n;
    for(int j=1; j<=(k%n).to!(int); j++) b[(i+j)%n]+=1;
    long score=0;
    foreach(e; b)if(e%2==0) score+=e;
    ret=max(ret, score);
  }
  writeln(ret);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

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

void main()
{
    auto a = readln.splitter.map!(to!int).array;
    a ~= a;
    long ans = 0;
    foreach (i; 0..14) {
        auto now = a[i+1..i+1+14].dup;

        debug { writeln(now); }

        now[$-1] = 0;

        auto curVal = (int j, int e) => e + a[i] / 14 + (a[i] % 14 >= j);
        auto vals = now.enumerate(1).map!(x => curVal(x.index, x.value));

        debug { writeln(vals); }

        ans = max (ans, vals.filter!(x => x % 2 == 0).sum);
    }

    writeln (ans);
}

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

void main()
{
    auto a = readln.splitter.map!(to!int).array;
    a ~= a;
    int ans = 0;
    foreach (i; 0..14) {
        auto now = a[i+1..i+1+14].dup;

        debug { writeln(now); }

        now[$-1] = 0;

        auto curVal = (int j, int e) => e + a[i] / 14 + (a[i] % 14 >= j);
        auto vals = now.enumerate(1).map!(x => curVal(x.index, x.value));

        debug { writeln(vals); }

        ans = max (ans, vals.filter!(x => x % 2 == 0).sum);
    }

    writeln (ans);
}

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

  int n=14;
  auto a=readln.split.to!(long[]);
  long ret=0;
  foreach(i; 0..n)if(a[i]>0){
    auto b=a.dup;
    long k=b[i];
    b[i]=0;
    foreach(j; 0..n) b[j]+=k/n;
    for(int j=1; j<=(k%n).to!(int); j++) b[j%n]+=1;
    long score=reduce!((r, e)=>(r+(e%2==0 ? e : 0L)))(0L, b);
    ret=max(ret, score);
  }
  writeln(ret);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:  The duration of the event must be no more than d minutes;  Devu must complete all his songs;  With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.

The first line contains two space separated integers n, d (1 ≤ n ≤ 100; 1 ≤ d ≤ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 ≤ ti ≤ 100).

If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.

NoteConsider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:  First Churu cracks a joke in 5 minutes.  Then Devu performs the first song for 2 minutes.  Then Churu cracks 2 jokes in 10 minutes.  Now Devu performs second song for 2 minutes.  Then Churu cracks 2 jokes in 10 minutes.  Now finally Devu will perform his last song in 1 minutes.  Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.

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

void main()
{
    auto nm = readln.split.map!(to!int);
    auto ts = readln.split.map!(to!int);
    auto count = 0;
    auto d = nm[1]-ts[0];
    foreach(t; ts.dropOne) {
        if (d<0) {
            writeln(-1);
            return;
        } else {
            d-=10;
            count+=2;
        }
        //writef("d=%d c=%d ",d,count);
        d-=t;
    }
    if (d<0) {
        writeln(-1);
        return;
    }
    while (d>=10) {
        d-=10;
        count+=2;
    }
    if (d>=5) { count++;}
    writeln(count);
}

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

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

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

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

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

int N, D;
int[] A;

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

		const x = D - reduce!"a + b"(0, A) - 10 * (N - 1);
		if (x < 0) {
			writeln(-1);
		} else {
			writeln(x / 5 + 2 * (N - 1));
		}
	}
	} catch (EOFException) {}
}

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

void main()
{
    auto nm = readln.split.map!(to!int);
    auto ts = readln.split.map!(to!int);
    auto count = 0;
    auto d = nm[1];
    foreach(t; ts) {
        d-=t;
        if (d<0) {
            writeln(-1);
            return;
        } else {
            d-=10;
            count+=2;
        }
    }
    if (d>5) { count++;}
    writeln(count);
}


You are given names of two days of the week.Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".

The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".

Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes).

NoteIn the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday.

import std.stdio;
import std.math;
import std.algorithm;
import std.range;
import std.random;
import std.regex;
import std.string;
import std.numeric;
import std.functional;
import std.bigint;
import std.bitmanip;
import std.conv;
import std.container;
alias redBlackTree rbt;
alias BigInt big;
//writeln readf readln string wstring dstring delegate function static length
//double float real foreach immutable assert unittest continue break

void main()
{
	int[string] q=["monday" : 1,"tuesday" : 2,"wednesday" : 3,"thursday" : 4,"friday" : 5,"saturday" : 6 ,"sunday" : 7];
	string a=readln,b=readln;
    a=a[0..$-1];
    b=b[0..$-1];
    int x=q[a],y=q[b];
	int p;
	if(x>y) p=7+y-x;
	else p=y-x;
	if(p <4 && p!=1)writeln("YES");
	else writeln("NO");
}

import std.stdio;
void main()
{
	auto q=["monday" : 1,"tuesday" : 2,"wednesday" : 3,"thursday" : 4,"friday" : 5,"saturday" : 6 ,"sunday" : 7];
	string a,b;
	readf("%s\n%s\n",&a,&b);
	//writeln(a);
	int x=q[a],y=q[b];
	int p;
	if(x>y) p=7+y-x;
	else p=y-x;
	if(p <4 && p!=1)writeln("YES");
	else writeln("NO");
}

import std.stdio;
import std.math;
import std.algorithm;
import std.range;
import std.random;
import std.regex;
import std.string;
import std.numeric;
import std.functional;
import std.bigint;
import std.bitmanip;
import std.conv;
import std.container;
alias redBlackTree rbt;
alias BigInt big;
//writeln readf readln string wstring dstring delegate function static length
//double float real foreach immutable assert unittest continue break

void main()
{
	auto q=["monday" : 1,"tuesday" : 2,"wednesday" : 3,"thursday" : 4,"friday" : 5,"saturday" : 6 ,"sunday" : 7];
	string a,b;
	readf("%s\n%s\n",&a,&b);
	//writeln(a);
	int x=q[a],y=q[b];
	int p;
	if(x>y) p=7+y-x;
	else p=y-x;
	if(p <4 && p!=1)writeln("YES");
	else writeln("NO");
}

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

enum DOWS = [
"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"
];

void main() {
  try {
    for (; ; ) {
      const S = readToken();
      const T = readToken();

      const s = DOWS.countUntil(S);
      const t = DOWS.countUntil(T);
      bool ans;
      foreach (n; [28, 30, 31]) {
        if ((s + n - t) % 7 == 0) {
          debug {
            writeln("ok ", n);
          }
          ans = true;
        }
      }
      writeln(ans ? "YES" : "NO");
    }
  } catch (EOFException e) {
  }
}


Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate.The path consists of $$$n$$$ consecutive tiles, numbered from $$$1$$$ to $$$n$$$. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles with numbers $$$i$$$ and $$$j$$$, such that $$$|j - i|$$$ is a divisor of $$$n$$$ greater than $$$1$$$, they have the same color. Formally, the colors of two tiles with numbers $$$i$$$ and $$$j$$$ should be the same if $$$|i-j| > 1$$$ and $$$n \bmod |i-j| = 0$$$ (where $$$x \bmod y$$$ is the remainder when dividing $$$x$$$ by $$$y$$$).Ujan wants to brighten up space. What is the maximum number of different colors that Ujan can use, so that the path is aesthetic?

The first line of input contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^{12}$$$), the length of the path.

Output a single integer, the maximum possible number of colors that the path can be painted in.

NoteIn the first sample, two colors is the maximum number. Tiles $$$1$$$ and $$$3$$$ should have the same color since $$$4 \bmod |3-1| = 0$$$. Also, tiles $$$2$$$ and $$$4$$$ should have the same color since $$$4 \bmod |4-2| = 0$$$.In the second sample, all five colors can be used.

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

void main ()
{
	long n;
	while (readf (" %s", &n) > 0)
	{
		long res = n;
		for (long d = 2; d * d <= n; d++)
		{
			if (n % d == 0)
			{
				res = gcd (res, d);
				res = gcd (res, n / d);
			}
		}
		writeln (res);
	}
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

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

void solve(){
	long n = rlong;

	long[] ds = [n];
	for(long i = 2 ; i * i <= n; i ++){
		if(n % i == 0) ds ~= i, ds ~= n / i;
	}
	ds.sort();

	foreach(d; ds[1 .. $]){
		if(d % ds[0] != 0){
			1.writeln;
			return;
		}
	}
	ds[0].writeln;
	return;
}

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.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 root(int[] uf, int u) {
  return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool connect(int[] uf, int u, int v) {
  u = uf.root(u);
  v = uf.root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}

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

      long[] ds;
      for (long d = 1; d * d <= N; ++d) {
        if (N % d == 0) {
          ds ~= d;
          if (d != N / d) {
            ds ~= N / d;
          }
        }
      }
      ds.sort();
      const dsLen = cast(int)(ds.length);
      debug {
        writeln("ds = ", ds);
      }
      if (dsLen <= 2) {
        writeln(N);
      } else {
        const V = cast(int)(ds[1]);
        auto uf = new int[V];
        uf[] = -1;
        foreach (j; 2 .. dsLen) {
          for (int u = 0, v = cast(int)(ds[j] % V); u < V; ++u, ++v %= V) {
            uf.connect(u, v);
          }
        }
        int ans;
        foreach (u; 0 .. V) {
          if (uf[u] < 0) {
            ++ans;
          }
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

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

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

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

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

void main()
{
	auto n = RD;
	long[] p;
	for (long i = 2; i*i <= n; ++i)
	{
		if (n % i == 0)
		{
			p ~= i;
			p ~= n/i;
		}
	}
	long ans = n;
	foreach (e; p)
	{
		ans = gcd(ans, e);
	}

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

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.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 root(int[] uf, int u) {
  return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool connect(int[] uf, int u, int v) {
  u = uf.root(u);
  v = uf.root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}

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

      long[] ds;
      for (long d = 1; d * d <= N; ++d) {
        if (N % d == 0) {
          ds ~= d;
          if (d != N / d) {
            ds ~= d;
          }
        }
      }
      ds.sort();
      const dsLen = cast(int)(ds.length);
      if (dsLen <= 2) {
        writeln(N);
      } else {
        const V = cast(int)(ds[1]);
        auto uf = new int[V];
        uf[] = -1;
        foreach (j; 2 .. dsLen) {
          for (int u = 0, v = cast(int)(ds[j] % V); u < V; ++u, ++v %= V) {
            uf.connect(u, v);
          }
        }
        int ans;
        foreach (u; 0 .. V) {
          if (uf[u] < 0) {
            ++ans;
          }
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}


You are given a sequence $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ integers.You can choose any non-negative integer $$$D$$$ (i.e. $$$D \ge 0$$$), and for each $$$a_i$$$ you can:  add $$$D$$$ (only once), i. e. perform $$$a_i := a_i + D$$$, or  subtract $$$D$$$ (only once), i. e. perform $$$a_i := a_i - D$$$, or  leave the value of $$$a_i$$$ unchanged. It is possible that after an operation the value $$$a_i$$$ becomes negative.Your goal is to choose such minimum non-negative integer $$$D$$$ and perform changes in such a way, that all $$$a_i$$$ are equal (i.e. $$$a_1=a_2=\dots=a_n$$$).Print the required $$$D$$$ or, if it is impossible to choose such value $$$D$$$, print -1.For example, for array $$$[2, 8]$$$ the value $$$D=3$$$ is minimum possible because you can obtain the array $$$[5, 5]$$$ if you will add $$$D$$$ to $$$2$$$ and subtract $$$D$$$ from $$$8$$$. And for array $$$[1, 4, 7, 7]$$$ the value $$$D=3$$$ is also minimum possible. You can add it to $$$1$$$ and subtract it from $$$7$$$ and obtain the array $$$[4, 4, 4, 4]$$$.

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

Print one integer — the minimum non-negative integer value $$$D$$$ such that if you add this value to some $$$a_i$$$, subtract this value from some $$$a_i$$$ and leave some $$$a_i$$$ without changes, all obtained values become equal. If it is impossible to choose such value $$$D$$$, print -1.

import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main () {
	auto n = readln.strip.to!int, a = readln.split.map !(to!int).array;
	foreach (d; 0..101) foreach (b; 0..101) if (a.all !(x => [b - d, b, b + d].canFind (x))) {d.write; return;}
	write (-1);
}

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

immutable int limit = 101;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		int res = limit;
		foreach (base; 0..limit)
		{
			foreach (diff; 0..limit)
			{
				if (a.all !(x => x == base ||
				    x == base - diff || x == base + diff))
				{
					res = min (res, diff);
				}
			}
		}
		if (res == limit)
		{
			res = -1;
		}
		writeln (res);
	}
}

import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

const long mod = 1_000_000_007;

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	int n = read.to!int;
	int[] as = readln.chomp.split.map!(to!int).array;

	bool[int] aset;
	foreach(a; as) aset[a] = 1;

	int ans;

	int[] ks = aset.keys;
	ks.sort();
	if(ks.length == 1) ans = 0;
	else if(ks.length == 2){
		ans = ks[1] - ks[0];
		if(ans % 2 == 0) ans /= 2;
	}
	else if(ks.length == 3){
		if(ks[1] - ks[0] == ks[2] - ks[1]) ans = ks[1] - ks[0];
		else ans = -1;
	}
	else ans = -1;

	ans.writeln;

}
/*

How many different a do they have?
If more than 4, impossible.
If 3, possible if and only if it is like 1-4-7.
If 2 or 1, always possible.

*/

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

string FMT_F = "%.10f";

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

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

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

void main()
{
	auto N = RD;
	auto a = RDR.ARR;
	a = a.sort().uniq.array;

	if (a.length == 1)
	{
		writeln(0);
	}
	else if (a.length == 2)
	{
		auto x = a[1] - a[0];
		writeln(x % 2 == 0 ? x / 2 : x);
	}
	else if (a.length == 3)
	{
		long l = a[0];
		long m = a[1];
		long r = a[2];
		writeln(m - l == r - m ? m - l : -1);
	}
	else
	{
		writeln(-1);
	}

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

import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

const long mod = 1_000_000_007;

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	int n = read.to!int;
	int[] as = readln.chomp.split.map!(to!int).array;

	bool[int] aset;
	foreach(a; as) aset[a] = 1;

	int ans;

	int[] ks = aset.keys;
	ks.sort();
	if(ks.length == 1) ans = 0;
	else if(ks.length == 2) ans = ks[1] - ks[0];
	else if(ks.length == 3){
		if(ks[1] - ks[0] == ks[2] - ks[1]) ans = ks[1] - ks[0];
		else ans = -1;
	}
	else ans = -1;

	ans.writeln;

}
/*

How many different a do they have?
If more than 4, impossible.
If 3, possible if and only if it is like 1-4-7.
If 2 or 1, always possible.

*/

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

string FMT_F = "%.10f";

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

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

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

void main()
{
	auto N = RD;
	auto a = RDR.ARR;
	a = a.sort().uniq.array;

	if (a.length == 1)
	{
		writeln(0);
	}
	else if (a.length == 2)
	{
		auto x = a[1] - a[0];
		writeln(x % 2 == 0 ? x / 2 : -1);
	}
	else if (a.length == 3)
	{
		long l = a[0];
		long m = a[1];
		long r = a[2];
		writeln(m - l == r - m ? m - l : -1);
	}
	else
	{
		writeln(-1);
	}

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


Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of $$$n$$$ light bulbs in a single row. Each bulb has a number from $$$1$$$ to $$$n$$$ (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland. Now Vadim wants to put them back on.Vadim wants to put all bulb back on the garland. Vadim defines complexity of a garland to be the number of pairs of adjacent bulbs with numbers with different parity (remainder of the division by $$$2$$$). For example, the complexity of 1 4 2 3 5 is $$$2$$$ and the complexity of 1 3 5 7 6 4 2 is $$$1$$$.No one likes complexity, so Vadim wants to minimize the number of such pairs. Find the way to put all bulbs back on the garland, such that the complexity is as small as possible.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of light bulbs on the garland. The second line contains $$$n$$$ integers $$$p_1,\ p_2,\ \ldots,\ p_n$$$ ($$$0 \le p_i \le n$$$) — the number on the $$$i$$$-th bulb, or $$$0$$$ if it was removed.

Output a single number — the minimum complexity of the garland.

NoteIn the first example, one should place light bulbs as 1 5 4 2 3. In that case, the complexity would be equal to 2, because only $$$(5, 4)$$$ and $$$(2, 3)$$$ are the pairs of adjacent bulbs that have different parity.In the second case, one of the correct answers is 1 7 3 5 6 4 2.

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

final class InputReader {
  private:
  ubyte[] p, buffer;
  bool eof;
  bool rawRead () {
    if (eof) {
      return false;
    }
    p = stdin.rawRead (buffer);
    if (p.empty) {
      eof = true;
      return false;
    }
    return true;
  }
  ubyte nextByte(bool check) () {
    static if (check) {
      if (p.empty) {
        if (!rawRead ()) {
          return 0;
        }
      }
    }
    auto r = p.front;
    p.popFront ();
    return r;
  }
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
  }
  bool seekByte (in ubyte lo) {
    while (true) {
      p = p.find! (c => c >= lo);
      if (!p.empty) {
        return false;
      }
      if (!rawRead ()) {
        return true;
      }
    }
  }
  template next(T) if (isSigned!T) {
    T next ()  {
      if (seekByte (45)) {
        return 0;
      }
      T res;
      ubyte b = nextByte!false ();
      if (b == 45) {
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    T next () {
      if (seekByte (48)) {
        return 0;
      }
      T res = nextByte!false () - 48;
      while (true) {
        ubyte b = nextByte!true ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  T[] nextA(T) (in int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader ();
  immutable n = r.next!uint ();
  auto a = r.nextA!uint (n);
  auto b = new bool[n + 1];
  foreach (i; a) {
    b[i] = true;
  }
  int odds, evens;
  for (int i = 1; i <= n; ++i) {
    if (!b[i]) {
      if (i & 1) odds++; else evens++;
    }
  }
  int[] pos;
  foreach (i; 0 .. n) {
    if (a[i] == 0) pos ~= i;
  }
  immutable int m = pos.length.to!int;
  auto dp = new int[][][] (m + 1, odds + 1, 3);
  foreach (i; 0 .. m + 1) foreach (j; 0 .. odds + 1) dp[i][j][] = -1;
  auto vo = new int[m];
  auto ve = new int[m];
  b = new bool[m];
  foreach (i; 0 .. m) {
    immutable int k = pos[i];
    if (k > 0) {
      if (a[k-1] != 0) {
        if (a[k-1] & 1) {
          ve[i]++;
        } else {
          vo[i]++;
        }
      } else b[i] = true;
    }
    if (k+1 < n) {
      if (a[k+1] != 0) {
        if (a[k+1] & 1) {
          ve[i]++;
        } else {
          vo[i]++;
        }
      }
    }
  }
  debug stderr.writeln (vo);
  debug stderr.writeln (ve);
  debug stderr.writeln (b);
  debug stderr.writeln (odds);
  debug stderr.writeln (evens);

  int f (const int k, const int o, const int last) {
    if (dp[k][o][last] >= 0) return dp[k][o][last];
    immutable int r = m - k;
    if (!r) return dp[k][o][last] = 0;
    immutable int co = odds - o,
       ce = k - co,
       e = evens - ce;
    assert (e >= 0);
    int res = int.max;
    if (o > 0) {
      int w = f (k + 1, o - 1, 1) + vo[k];
      if (b[k] && last == 0) ++w;
      res = min (res, w);
    }
    if (e > 0) {
      int w = f (k + 1, o, 0) + ve[k];
      if (b[k] && last == 1) ++w;
      res = min (res, w);
    }
    return dp[k][o][last] = res;
  }
  int res = f (0, odds, 2);
  foreach (i; 1 .. n) {
    if (a[i-1] != 0 && a[i] != 0 && 0 != ((a[i-1] ^ a[i]) & 1)) {
      ++res;
    }
  }
  writeln (res);
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

const long infty = 100999;

void solve(){
	int n = rint;
	long[] as = rlong(n);

	int p = (n + 1) / 2, q = n / 2, z; // how many odds, evens, zeros
	foreach(a; as){
		if(a == 0) z += 1;
		else if(a % 2) p -= 1;
		else q -= 1;
	}
	log("p:", p, "q:", q, "z:", z);

	long[][][] xs = new long[][][](n, p + 1, q + 1);
			// xs[i][j][k]: use j odd and k even bulbs and the rightmost is odd and the min score
	long[][][] ys = new long[][][](n, p + 1, q + 1);
			// ys[i][j][k]: use j odd and k even bulbs and the rightmost is even and the min score

	foreach(i, a; as){
		if(a > 0){ // forced
			if(a % 2){ // forced odd
				foreach(j; 0 .. p + 1) foreach(k; 0 .. q + 1){
					if(i > 0) xs[i][j][k] = min(xs[i - 1][j][k], ys[i - 1][j][k] + 1);
					else xs[i][j][k] = 0;
					ys[i][j][k] = infty;
				}
			}
			else{ // forced even
				foreach(j; 0 .. p + 1) foreach(k; 0 .. q + 1){
					xs[i][j][k] = infty;
					if(i > 0) ys[i][j][k] = min(xs[i - 1][j][k] + 1, ys[i - 1][j][k]);
					else ys[i][j][k] = 0;
				}
			}
		}
		else{ // free
			foreach(j; 0 .. p + 1) foreach(k; 0 .. q + 1){
				if(i > 0){
					if(j > 0) xs[i][j][k] = min(xs[i - 1][j - 1][k], ys[i - 1][j - 1][k] + 1);
					else xs[i][j][k] = infty;
					if(k > 0) ys[i][j][k] = min(xs[i - 1][j][k - 1] + 1, ys[i - 1][j][k - 1]);
					else ys[i][j][k] = infty;
				}
				else{
					if(j == 1 && k == 0) xs[i][j][k] = 0;
					else xs[i][j][k] = infty;
					if(j == 0 && k == 1) ys[i][j][k] = 0;
					else ys[i][j][k] = infty;
				}
			}
		}
		log("xs:", xs[i], "ys:", ys[i]);
	}
	long ans = min(xs[n - 1][p][q], ys[n - 1][p][q]);
	ans.writeln;
}

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

enum INF = 10^^9;

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

      auto dp = new int[][][](N + 1, N + 1, 2);
      foreach (i; 0 .. N + 1) {
        foreach (j; 0 .. N + 1) {
          dp[i][j][] = INF;
        }
      }
      dp[0][0][] = 0;
      foreach (i; 0 .. N) {
        foreach (j; 0 .. i + 1) foreach (s; 0 .. 2) {
          foreach (t; 0 .. 2) {
            if (P[i] == 0 || P[i] % 2 == t) {
              chmin(dp[i + 1][j + t][t], dp[i][j][s] + abs(s - t));
            }
          }
        }
      }
      int ans = INF;
      foreach (s; 0 .. 2) {
        chmin(ans, dp[N][N - N / 2][s]);
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

import std.stdio : writeln;

struct IO {
    string readToken() {
        import std.stdio : stdin;
        import std.array : split;
        import std.range : empty, front, popFront;

        while (tokens.empty) {
            tokens = stdin.readln.split;
        }
        string token = tokens.front;
        tokens.popFront;
        return token;
    }

    int readInt() {
        import std.conv : to;

        return readToken.to!(int);
    }

    string[] tokens;
}

void main() {
    import std.algorithm : min, sort;

    IO io;
    int n = io.readInt;
    int[] p = new int[n + 2];
    int target = n >> 1;
    for (int i = 1; i <= n; ++i) {
        p[i] = io.readInt - 1;
        if (~p[i]) {
            if (p[i] &= 1) {
                target--;
            }
        }
    }
    int result = n;
    for (int mask = 0; mask < 1 << 2; ++mask) {
        p[0] = mask & 1, p[n + 1] = mask >> 1;
        int cost = 0, low = 0, high = 0, j = 0, pc = 0, nc = 0;
        int[] positives = new int[n + 1], negatives = new int[n + 1];
        for (int i = 1; i <= n + 1; ++i) {
            if (~p[i]) {
                int length = i - j - 1;
                if (p[i] != p[j]) {
                    cost++, high += length;
                }
                else if (p[i]) {
                    low += length, high += length, negatives[nc++] = length;
                }
                else {
                    positives[pc++] = length;
                }
                j = i;
            }
        }
        positives.sort!("a > b");
        negatives.sort!("a > b");
        for (int i = 0; i < pc && high < target; ++i) {
            cost += 2, high += positives[i];
        }
        for (int i = 0; i < nc && low > target; ++i) {
            cost += 2, low -= negatives[i];
        }
        result = min(result, cost);
    }
    writeln(result);
}

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

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto n = RD!int;
	auto p = RDA!int;

	auto cnt = new int[](2);
	cnt[0] = n/2;
	cnt[1] = (n+1)/2;
	foreach (i; 0..n)
	{
		if (p[i] == 0) continue;
		auto j = p[i] % 2;
		--cnt[j];
	}

	auto dp = new int[][][](n+1, n+1, 2);
	foreach (i; 0..n+1)
	{
		foreach (j; 0..n+1)
			dp[i][j][] = -1;
	}
	dp[cnt[0]][cnt[1]][0] = 0;
	dp[cnt[0]][cnt[1]][1] = 0;
	foreach (i; 0..n)
	{
		auto ndp = new int[][][](n+1, n+1, 2);
		foreach (j; 0..n+1)
		{
			foreach (k; 0..n+1)
				ndp[j][k][] = -1;
		}
		foreach (j; 0..n+1)
		{
			foreach (k; 0..n+1)
			{
				foreach (l; 0..2)
				{
					if (dp[j][k][l] == -1) continue;
					if (p[i] != 0)
					{
						auto eo = p[i] % 2;
						auto num = dp[j][k][l] + (eo != l ? 1 : 0);
						if (ndp[j][k][eo] == -1)
							ndp[j][k][eo] = num;
						else
							ndp[j][k][eo].chmin(num);
						continue;
					}
					if (j != 0)
					{
						auto num = dp[j][k][l] + (l != 0 ? 1 : 0);
						if (ndp[j-1][k][0] == -1)
							ndp[j-1][k][0] = num;
						else
							ndp[j-1][k][0].chmin(num);
					}
					if (k != 0)
					{
						auto num = dp[j][k][l] + (l != 1 ? 1 : 0);
						if (ndp[j][k-1][1] == -1)
							ndp[j][k-1][1] = num;
						else
							ndp[j][k-1][1].chmin(num);
					}
				}
			}
		}
		dp = ndp;
	}
	debug writeln(dp);

	int ans = int.max;
	foreach (i; 0..2)
	{
		if (dp[0][0][i] != -1)
			ans.chmin(dp[0][0][i]);
	}

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


Mishka started participating in a programming contest. There are $$$n$$$ problems in the contest. Mishka's problem-solving skill is equal to $$$k$$$.Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.Mishka cannot solve a problem with difficulty greater than $$$k$$$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $$$1$$$. Mishka stops when he is unable to solve any problem from any end of the list.How many problems can Mishka solve?

The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 100$$$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the difficulty of the $$$i$$$-th problem. The problems are given in order from the leftmost to the rightmost in the list.

Print one integer — the maximum number of problems Mishka can solve.

NoteIn the first example, Mishka can solve problems in the following order: $$$[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$$$, so the number of solved problems will be equal to $$$5$$$.In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $$$k$$$.In the third example, Mishka's solving skill is so amazing that he can solve all the problems.

module acmd;

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

int main () {
   version (offline_judje) {
      stdin.reopen ("input.txt", "rt");
   }

   int n, k;
   readf!" %d %d" (n, k);
   int[] nums;
   foreach (i; 0 .. n) {
      int num; readf!" %d" (num);
      nums ~= num;
   }
   auto curnums = nums[];
   int ans = 0;
   while (curnums.length > 0) {
      if (curnums[0] <= k) {
         ans++;
         curnums = curnums[1 .. $];
      }
      else if (curnums[$ - 1] <= k) {
         ans++;
         curnums = curnums[0 .. $ - 1];
      }
      else break;
   }
   write (ans);

   return 0;
}

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()
{
    int n, k;
    readf("%s %s", &n, &k);
    readln;

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

    int check(int[] a, int k) {
        return cast(int) a.until!(x => x > k).array.length;
    }

    auto ans = min(check(a, k) + check(a.retro.array, k), n);

    ans.writeln;
}


Nezzar buys his favorite snack — $$$n$$$ chocolate bars with lengths $$$l_1,l_2,\ldots,l_n$$$. However, chocolate bars might be too long to store them properly! In order to solve this problem, Nezzar designs an interesting process to divide them into small pieces. Firstly, Nezzar puts all his chocolate bars into a black box. Then, he will perform the following operation repeatedly until the maximum length over all chocolate bars does not exceed $$$k$$$.  Nezzar picks a chocolate bar from the box with probability proportional to its length $$$x$$$.  After step $$$1$$$, Nezzar uniformly picks a real number $$$r \in (0,x)$$$ and divides the chosen chocolate bar into two chocolate bars with lengths $$$r$$$ and $$$x-r$$$.  Lastly, he puts those two new chocolate bars into the black box. Nezzar now wonders, what is the expected number of operations he will perform to divide his chocolate bars into small pieces.It can be shown that the answer can be represented as $$$\frac{P}{Q}$$$, where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q \not \equiv 0$$$ ($$$\bmod 998\,244\,353$$$). Print the value of $$$P\cdot Q^{-1} \mod 998\,244\,353$$$.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 50, 1 \le k \le 2000$$$). The second line contains $$$n$$$ integers $$$l_1, l_2, \ldots, l_n$$$ ($$$1 \le l_i$$$, $$$\sum_{i=1}^{n} l_i \le 2000$$$).

Print a single integer — the expected number of operations Nezzar will perform to divide his chocolate bars into small pieces modulo $$$998\,244\,353$$$.

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

struct ModInt(int M_) {
  import std.conv : to;
  alias M = M_;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      if (a < 0) return (this = inv()^^(-a));
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e > 0; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op: "-")() const { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const {
    return mixin("ModInt(this) " ~ op ~ "= a");
  }
  ModInt opBinaryRight(string op)(long a) const {
    return mixin("ModInt(a) " ~ op ~ "= this");
  }
  bool opCast(T: bool)() const { return (x != 0); }
  string toString() const { return x.to!string; }
}

enum MO = 998244353;
alias Mint = ModInt!MO;

enum LIM = 10^^5 + 10;
Mint[] inv, fac, invFac;
void prepare() {
  inv = new Mint[LIM];
  fac = new Mint[LIM];
  invFac = new Mint[LIM];
  inv[1] = 1;
  foreach (i; 2 .. LIM) {
    inv[i] = -(Mint.M / i) * inv[cast(size_t)(Mint.M % i)];
  }
  fac[0] = invFac[0] = 1;
  foreach (i; 1 .. LIM) {
    fac[i] = fac[i - 1] * i;
    invFac[i] = invFac[i - 1] * inv[i];
  }
}
Mint binom(long n, long k) {
  if (0 <= k && k <= n) {
    assert(n < LIM);
    return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] * invFac[cast(size_t)(n - k)];
  } else {
    return Mint(0);
  }
}

class Fft(int M_, int G, int K) {
  import std.algorithm : reverse;
  import std.traits : isIntegral;
  alias M = M_;
  // 1, 1/4, 1/8, 3/8, 1/16, 5/16, 3/16, 7/16, ...
  int[] gs;
  this() {
    static assert(2 <= K && K <= 30, "Fft: 2 <= K <= 30 must hold");
    static assert(!((M - 1) & ((1 << K) - 1)), "Fft: 2^K | M - 1 must hold");
    gs = new int[1 << (K - 1)];
    gs[0] = 1;
    long g2 = G, gg = 1;
    for (int e = (M - 1) >> K; e; e >>= 1) {
      if (e & 1) gg = (gg * g2) % M;
      g2 = (g2 * g2) % M;
    }
    gs[1 << (K - 2)] = cast(int)(gg);
    for (int l = 1 << (K - 2); l >= 2; l >>= 1) {
      gs[l >> 1] = cast(int)((cast(long)(gs[l]) * gs[l]) % M);
    }
    assert((cast(long)(gs[1]) * gs[1]) % M == M - 1,
           "Fft: g^(2^(K-1)) == -1 (mod M) must hold");
    for (int l = 2; l <= 1 << (K - 2); l <<= 1) {
      foreach (i; 1 .. l) {
        gs[l + i] = cast(int)((cast(long)(gs[l]) * gs[i]) % M);
      }
    }
  }
  void fft(int[] xs) const {
    const n = cast(int)(xs.length);
    assert(!(n & (n - 1)), "Fft.fft: |xs| must be a power of two");
    assert(n <= 1 << K, "Fft.fft: |xs| <= 2^K must hold");
    for (int l = n; l >>= 1; ) {
      foreach (i; 0 .. (n >> 1) / l) {
        const(long) g = gs[i];
        foreach (j; (i << 1) * l .. (i << 1 | 1) * l) {
          const t = cast(int)((g * xs[j + l]) % M);
          if ((xs[j + l] = xs[j] - t) < 0) xs[j + l] += M;
          if ((xs[j] += t) >= M) xs[j] -= M;
        }
      }
    }
  }
  void invFft(int[] xs) const {
    const n = cast(int)(xs.length);
    assert(!(n & (n - 1)), "Fft.invFft: |xs| must be a power of two");
    assert(n <= 1 << K, "Fft.invFft: |xs| <= 2^K must hold");
    for (int l = 1; l < n; l <<= 1) reverse(xs[l .. l << 1]);
    for (int l = 1; l < n; l <<= 1) {
      foreach (i; 0 .. (n >> 1) / l) {
        const(long) g = gs[i];
        foreach (j; (i << 1) * l .. (i << 1 | 1) * l) {
          int t = cast(int)((g * (xs[j] - xs[j + l])) % M);
          if (t < 0) t += M;
          if ((xs[j] += xs[j + l]) >= M) xs[j] -= M;
          xs[j + l] = t;
        }
      }
    }
  }
  T[] convolute(T)(inout(T)[] as, inout(T)[] bs) const if (isIntegral!T) {
    const na = cast(int)(as.length), nb = cast(int)(bs.length);
    int n, invN = 1;
    for (n = 1; n < na + nb - 1; n <<= 1) {
      invN = ((invN & 1) ? (invN + M) : invN) >> 1;
    }
    auto xs = new int[n], ys = new int[n];
    foreach (i; 0 .. na) if ((xs[i] = cast(int)(as[i] % M)) < 0) xs[i] += M;
    foreach (i; 0 .. nb) if ((ys[i] = cast(int)(bs[i] % M)) < 0) ys[i] += M;
    fft(xs);
    fft(ys);
    foreach (i; 0 .. n) {
      xs[i] = cast(int)((((cast(long)(xs[i]) * ys[i]) % M) * invN) % M);
    }
    invFft(xs);
    auto cs = new T[na + nb - 1];
    foreach (i; 0 .. na + nb - 1) cs[i] = cast(T)(xs[i]);
    return cs;
  }
  ModInt!M[] convolute(inout(ModInt!M)[] as, inout(ModInt!M)[] bs) const {
    const na = cast(int)(as.length), nb = cast(int)(bs.length);
    int n, invN = 1;
    for (n = 1; n < na + nb - 1; n <<= 1) {
      invN = ((invN & 1) ? (invN + M) : invN) >> 1;
    }
    auto xs = new int[n], ys = new int[n];
    foreach (i; 0 .. na) xs[i] = as[i].x;
    foreach (i; 0 .. nb) ys[i] = bs[i].x;
    fft(xs);
    fft(ys);
    foreach (i; 0 .. n) {
      xs[i] = cast(int)((((cast(long)(xs[i]) * ys[i]) % M) * invN) % M);
    }
    invFft(xs);
    auto cs = new ModInt!M[na + nb - 1];
    foreach (i; 0 .. na + nb - 1) cs[i].x = xs[i];
    return cs;
  }
  int[] convolute(int M1)(inout(ModInt!M1)[] as, inout(ModInt!M1)[] bs) const
      if (M != M1) {
    const na = cast(int)(as.length), nb = cast(int)(bs.length);
    int n, invN = 1;
    for (n = 1; n < na + nb - 1; n <<= 1) {
      invN = ((invN & 1) ? (invN + M) : invN) >> 1;
    }
    auto xs = new int[n], ys = new int[n];
    foreach (i; 0 .. na) xs[i] = as[i].x;
    foreach (i; 0 .. nb) ys[i] = bs[i].x;
    fft(xs);
    fft(ys);
    foreach (i; 0 .. n) {
      xs[i] = cast(int)((((cast(long)(xs[i]) * ys[i]) % M) * invN) % M);
    }
    invFft(xs);
    return xs[0 .. na + nb - 1];
  }
}

alias Fft0 = Fft!(998244353, 3, 20);

/*
  Pr[large piece after m cuts]
  = 1 - \prod_{m[1]+...+m[N]=m} m!/(m[1]!...m[N]!) \prod_{i=1}^N (L[i]/L)^m[i] Pr[no large piece after m[i] cuts on the i-th chocolate]

  \sum_{m>=0} (L[i]/L)^m Pr[no large piece after m cuts on the i-th chocolate] x^m/m!
  = \sum_{m>=0} (L[i]/L)^m (\sum_{j: L[i]-Kj>0} binom(m+1, j) (-1)^j ((L[i]-Kj)/L[i])^m) x^m/m!
  = \sum_{j: L[i]-Kj>0} \sum_m binom(m+1, j) (-1)^j (((L[i]-Kj)/L) x)^m / m!
  = \sum_{m>=0} ((L[i]/L) x)^m / m! + \sum_{j>=1: L[i]-Kj>0} (-1)^j/j! \sum_{m>=j-1} (m+1)/((m-j+1)!) (((L[i]-Kj)/L) x)^m
  |
  | \sum_{m>=j-1} (m+1)/((m-j+1)!) X^m
  | = \sum_{m>=0} (m+j)/m! X^(m+j-1)
  | = \sum_{m>=1} 1/(m-1)! X^(m+j-1) + j \sum_{m>=0} (j/m!) X^(m+j-1)
  | = exp(X) (X^j + j X^(j-1))
  |
  = exp((L[i]/L) x) + (-1)^j/j! \sum_{j>=1: L[i]-Kj>0} exp(((L[i]-Kj)/L) x) ((((L[i]-Kj)/L) x)^j + j (((L[i]-Kj)/L) x)^(j-1))
  |
  | y := exp(-(K/L) x) x
  | c[i] := (L[i]-Kj)/L
  |
  = exp((L[i]/L) x) (1 + \sum_{j>=1: L[i]-Kj>0} (-1)^j/j! y^j (c[i]^j + j c[i]^(j-1) x^-1))

  \sum_{m\ge0} Pr[large piece after m cuts]
  = exp(x) - exp(x) \prod_{i=1}^N (1 + \sum_{j>=1: L[i]-Kj>0} (-1)^j/j! y^j (c[i]^j + j c[i]^(j-1) x^-1))
*/

Fft0 FFT;
Mint[][] mul(Mint[][] fss, Mint[][] gss) {
  const mf = cast(int)(fss.length), nf = cast(int)(fss[0].length);
  const mg = cast(int)(gss.length), ng = cast(int)(gss[0].length);
  const m = mf + mg - 1, n = nf + ng - 1;
  auto fs = new Mint[m * n];
  auto gs = new Mint[m * n];
  foreach (i; 0 .. mf) foreach (j; 0 .. nf) fs[i * n + j] = fss[i][j];
  foreach (i; 0 .. mg) foreach (j; 0 .. ng) gs[i * n + j] = gss[i][j];
  const hs = FFT.convolute(fs, gs);
  auto hss = new Mint[][](m, n);
  foreach (i; 0 .. m) foreach (j; 0 .. n) hss[i][j] = hs[i * n + j];
  return hss;
}

void main() {
  prepare;
  FFT = new Fft0;

  try {
    for (; ; ) {
      const N = readInt();
      const K = readInt();
      auto L = new int[N];
      foreach (i; 0 .. N) {
        L[i] = readInt();
      }

      const LSum = L.sum;

      // rectangular
      auto fsss = new Mint[][][2 * N - 1];
      foreach (i; 0 .. N) {
        const jLim = (L[i] + K - 1) / K;
        fsss[i] = new Mint[][](jLim, 2);
        fsss[i][0][0] = 1;
        foreach (j; 1 .. jLim) {
          const c = Mint(L[i] - K * j) / Mint(LSum);
          fsss[i][j][0] = (-1)^^(j & 1) * invFac[j] * c^^j;
          fsss[i][j][1] = (-1)^^(j & 1) * invFac[j] * j * c^^(j - 1);
        }
      }
      foreach (i; N .. 2 * N - 1) {
        fsss[i] = mul(fsss[(i - N) << 1], fsss[(i - N) << 1 | 1]);
      }
      const fss = fsss[$ - 1];
      debug {
        if (LSum / K <= 20) {
          writeln("fss = ", fss);
        }
      }

      Mint ans;
      foreach (j; 1 .. cast(int)(fss.length)) {
        foreach (h; 0 .. cast(int)(fss[j].length)) {
          /*
            exp((1 - (K/L) j) x) x^(j-h)

            \sum_m m! [x^m] exp(r x) x^a
            = \sum_m (m+a)!/m! r^m
            = a! / (1 - r)^(a+1)
          */
          if (j - h >= 0) {
            const r = Mint(1) - Mint(K) / Mint(LSum) * Mint(j);
            const a = j - h;
            debug {
              if (LSum / K <= 20) {
                writeln(r, " ", a, ": ", fss[j][h]);
              }
            }
            ans -= (fac[a] / (1 - r)^^(a + 1)) * fss[j][h];
          } else {
            assert(!fss[j][h]);
          }
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


You are given an integer $$$n$$$ from $$$1$$$ to $$$10^{18}$$$ without leading zeroes.In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.What is the minimum number of moves you have to make to obtain a number that is divisible by $$$25$$$? Print -1 if it is impossible to obtain a number that is divisible by $$$25$$$.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^{18}$$$). It is guaranteed that the first (left) digit of the number $$$n$$$ is not a zero.

If it is impossible to obtain a number that is divisible by $$$25$$$, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number.

NoteIn the first example one of the possible sequences of moves is 5071 $$$\rightarrow$$$ 5701 $$$\rightarrow$$$ 7501 $$$\rightarrow$$$ 7510 $$$\rightarrow$$$ 7150.

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

void main() {
    immutable int INF = 1 << 29;

    auto S = readln.chomp;
    auto N = S.length.to!int;

    if (S == "25" || S == "50" || S == "75") {
        writeln(0);
        return;
    }

    if (S == "52" || S == "57") {
        writeln(1);
        return;
    }

    int[][] A = new int[][](10);
    foreach (i; 0..N) A[S[i]-'0'] ~= i;

    int minv = INF;

    int simple_swap(int i1, int i2) {
        return N - i1 - 1 + N - i2 - 2;
    }

    if (A[0].length >= 2) {
        minv = min(minv, simple_swap(A[0][$-1], A[0][$-2]));
    }

    int solve(int d1, int d2) {
        if (A[d1].length == 0 || A[d2].length == 0) {
            return INF;
        }

        int ret = 0;
        int a = A[d1].back;
        int b = A[d2].back;
        if (a > b) swap(a, b), ret += 1;

        if (a != 0) {
            ret += simple_swap(a, b);
        } else {
            int left_other = INF;
            foreach (i; 1..10) {
                if (A[i].length == 0) continue;
                if (i == d1 || i == d2) {
                    if (A[i].length >= 2) {
                        left_other = min(left_other, A[i].front);
                    }
                } else {
                    left_other = min(left_other, A[i].front);
                }
            }

            if (left_other != INF && left_other < b) {
                ret += left_other + simple_swap(a+1, b);
            } else if (left_other != INF && left_other > b) {
                ret += left_other + simple_swap(a+1, b+1);
            } else {
                ret = INF;
            }
        }

        return ret;
    }

    minv = min(minv, solve(2, 5));
    minv = min(minv, solve(5, 0));
    minv = min(minv, solve(7, 5));
    writeln(minv == INF ? -1 : minv);
}

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

void main() {
    immutable int INF = 1 << 29;

    auto S = readln.chomp;
    auto N = S.length.to!int;

    int[][] A = new int[][](10);
    foreach (i; 0..N) A[S[i]-'0'] ~= i;

    int minv = INF;

    int simple_swap(int i1, int i2) {
        return N - i1 - 1 + N - i2 - 2;
    }

    if (A[0].length >= 2) {
        minv = min(minv, simple_swap(A[0][$-1], A[0][$-2]));
    }

    int solve(int d1, int d2) {
        if (A[d1].length == 0 || A[d2].length == 0) {
            return INF;
        }

        int ret = 0;
        int a = A[d1].back;
        int b = A[d2].back;
        if (a > b) swap(a, b), ret += 1;

        if (a != 0) {
            ret += simple_swap(a, b);
        } else {
            int left_other = INF;
            foreach (i; 1..10) {
                if (A[i].length == 0) continue;
                if (i == d1 || i == d2) {
                    if (A[i].length >= 2) {
                        left_other = min(left_other, A[i].front);
                    }
                } else {
                    left_other = min(left_other, A[i].front);
                }
            }

            if (left_other != INF && left_other < b) {
                ret += left_other + simple_swap(a+1, b);
            } else if (left_other != INF && left_other > b) {
                ret += left_other + simple_swap(a+1, b+1);
            } else {
                ret = INF;
            }
        }

        return ret;
    }

    minv = min(minv, solve(2, 5));
    minv = min(minv, solve(5, 0));
    minv = min(minv, solve(7, 5));
    writeln(minv == INF ? -1 : minv);
}

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

void main() {
    immutable int INF = 1 << 29;

    auto S = readln.chomp;
    auto N = S.length.to!int;

    if (S == "25" || S == "50" || S == "75") {
        writeln(0);
        return;
    }

    int[][] A = new int[][](10);
    foreach (i; 0..N) A[S[i]-'0'] ~= i;

    int minv = INF;

    int simple_swap(int i1, int i2) {
        return N - i1 - 1 + N - i2 - 2;
    }

    if (A[0].length >= 2) {
        minv = min(minv, simple_swap(A[0][$-1], A[0][$-2]));
    }

    int solve(int d1, int d2) {
        if (A[d1].length == 0 || A[d2].length == 0) {
            return INF;
        }

        int ret = 0;
        int a = A[d1].back;
        int b = A[d2].back;
        if (a > b) swap(a, b), ret += 1;

        if (a != 0) {
            ret += simple_swap(a, b);
        } else {
            int left_other = INF;
            foreach (i; 1..10) {
                if (A[i].length == 0) continue;
                if (i == d1 || i == d2) {
                    if (A[i].length >= 2) {
                        left_other = min(left_other, A[i].front);
                    }
                } else {
                    left_other = min(left_other, A[i].front);
                }
            }

            if (left_other != INF && left_other < b) {
                ret += left_other + simple_swap(a+1, b);
            } else if (left_other != INF && left_other > b) {
                ret += left_other + simple_swap(a+1, b+1);
            } else {
                ret = INF;
            }
        }

        return ret;
    }

    minv = min(minv, solve(2, 5));
    minv = min(minv, solve(5, 0));
    minv = min(minv, solve(7, 5));
    writeln(minv == INF ? -1 : minv);
}


There are $$$n$$$ students in a university. The number of students is even. The $$$i$$$-th student has programming skill equal to $$$a_i$$$. The coach wants to form $$$\frac{n}{2}$$$ teams. Each team should consist of exactly two students, and each student should belong to exactly one team. Two students can form a team only if their skills are equal (otherwise they cannot understand each other and cannot form a team).Students can solve problems to increase their skill. One solved problem increases the skill by one.The coach wants to know the minimum total number of problems students should solve to form exactly $$$\frac{n}{2}$$$ teams (i.e. each pair of students should form a team). Your task is to find this number.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of students. It is guaranteed that $$$n$$$ is even. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student.

Print one number — the minimum total number of problems students should solve to form exactly $$$\frac{n}{2}$$$ teams.

NoteIn the first example the optimal teams will be: $$$(3, 4)$$$, $$$(1, 6)$$$ and $$$(2, 5)$$$, where numbers in brackets are indices of students. Then, to form the first team the third student should solve $$$1$$$ problem, to form the second team nobody needs to solve problems and to form the third team the second student should solve $$$4$$$ problems so the answer is $$$1 + 4 = 5$$$.In the second example the first student should solve $$$99$$$ problems to form a team with the second one.

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

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    A.sort();
    iota(0, N, 2).map!(i => A[i+1] - A[i]).sum.writeln;
}

import std.stdio;
import std.algorithm;
int main()
{
	int t=0;
	readf(" %d", &t);
	int[] m = new int[t];
	for (int i=0; i<t; i++)
	{
		readf(" %d", &m[i]);
	}
	sort(m);
	int count=0;
	for (int i=0; i<t/2; i++)
	{
		count=count+(m[i*2+1]-m[i*2]);
	}
	writeln(count);
	return 0;
}


So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.

The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.

Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.

NoteIn the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.In the second sample letter "P" is missing from the pile and there's an extra letter "L".In the third sample there's an extra letter "L".

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

void main() {
    auto a = readln().chomp();
    auto b = readln().chomp();
    auto c = readln().chomp();
    auto d = a ~ b;

    sort((cast(ubyte[])c));
    sort((cast(ubyte[])d));

    if (c == d) {
        writeln("YES");
    } else {
        writeln("NO");
    }
 }

import std.stdio: writeln, stdin;
import std.string: strip;
import std.algorithm.iteration: group;
import std.algorithm.sorting: sort;

void main()
{
  char[] h = stdin.readln.strip.dup;
  char[] r = stdin.readln.strip.dup;
  char[] p = stdin.readln.strip.dup;

  auto a = h ~ r;
  sort(cast(ubyte[])a);
  sort(cast(ubyte[])p);
  //p.sort!"a<b";

  writeln(a.group == p.group ? "YES" : "NO");
}

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

string readline()
{
	string line = readln();
	if (line[$ - 1] == '\n') line.length--;
	return line;
}

int main()
{
	string line1 = readline();
	string line2 = readline();
	string line3 = readline();
	if (line1.length + line2.length != line3.length)
	{
		write("NO");
		return 0;
	}
	int[] letters; letters.length ='Z' - 'A' + 1;
	string l = line1 ~ line2;
	foreach (char c; l)
	{
		letters[c - 'A'] += 1;
	}
	int[] letters2; letters2.length = 'Z' - 'A' + 1;
	foreach (char c; line3)
	{
		letters2[c - 'A'] += 1;
	}

	foreach (int i; 0..letters.length)
	{
		if (letters[i] != letters2[i])
		{
			write("NO");
			return 0;
		}
	}
	write("YES");
	return 0;
}

module ahmat;
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.string;
import std.ascii;
import std.algorithm;
import std.range;
import std.functional;
import std.array;
import std.container;
import std.conv;
import std.container;
import std.typecons;
import std.math;
import std.random;
import std.numeric;
pragma(inline,true);
int sz(r)(ref r x){return cast(int)x.length;}

void main(){
	char[] a=readln().strip().dup~readln().strip().dup,
		   b=readln().strip().dup;
	sort(cast(ubyte[])a);
	sort(cast(ubyte[])b);
	if(a==b)
		writeln("YES");
	else writeln("NO");
}

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

void main() {
	int[char] before;
	int[char] after;

	for (int i = 0; i < 2; i++) {
		string s = readln.chomp;
		foreach (c; s) {
			before[c]++;
		}
	}

	string s = readln.chomp;
	foreach (c; s) {
		after[c]++;
	}

	writeln(before == after ? "YES" : "NO");
}

module ahmat;
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.string;
import std.ascii;
import std.algorithm;
import std.range;
import std.functional;
import std.array;
import std.container;
import std.conv;
import std.container;
import std.typecons;
import std.math;
import std.random;
import std.numeric;
pragma(inline,true);
int sz(r)(ref r x){return cast(int)x.length;}

void main(){
	char[] a=readln.strip().dup~readln().strip().dup,
		 b=readln().strip().dup;
	sort(cast(ubyte[])a);
	sort(cast(ubyte[])b);
	if(b.indexOf(a)>=0)
		writeln("YES");
	else writeln("NO");
}


Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.

The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.

Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant,
	std.stdio,std.bitmanip;
import core.stdc.stdio : freopen;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias boyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
immutable int mod=10^^9+7;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n,in size_t m) if(isRandomAccessRange!X)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n) if(hasSlicing!X)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
bool read(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	/*int n;
	loop:while(read(&n))
	{

	}*/
	auto s=readln.strip;
	if(s.count!isUpper>s.count!isLower)
	{
		foreach(c;s)write(toUpper(c));
	}
	else foreach(c;s)write(toLower(c));
}

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

int main(string[] argv)
{
	string line = readln();
	if (line[$-1] == '\n') line.length--;
	string upper = toUpper(line);
	string lower = toLower(line);
	int diffu, diffl;
	foreach (int i; 0..line.length)
	{
		diffu += abs(line[i] - upper[i]);
		diffl += abs(line[i] - lower[i]);
	}
	write (diffu >= diffl ? lower : upper);
	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(){
    char[] s=readln.strip.to!(char[]);
    int n=0;
    foreach(ref x;s){
        if(x.to!int<97) n++;
    }
    if(2*n>s.length)
        s.toUpper.writeln;
    else
        s.toLower.writeln;
}

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

int main(string[] argv)
{
	string line = readln();
	if (line[$-1] == '\n') line.length--;
	string upper = toUpper(line);
	string lower = toLower(line);
	int diffu, diffl;
	foreach (int i; 0..line.length)
	{
		diffu += abs(line[i] - upper[i]);
		diffl += abs(line[i] - lower[i]);
	}
	write (diffu > diffl ? lower : upper);
	return 0;
}