City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them.Sand roads have long been recognized out of date, so the decision was made to asphalt them. To do this, a team of workers was hired and a schedule of work was made, according to which the intersections should be asphalted.Road repairs are planned for n2 days. On the i-th day of the team arrives at the i-th intersection in the list and if none of the two roads that form the intersection were already asphalted they asphalt both roads. Otherwise, the team leaves the intersection, without doing anything with the roads.According to the schedule of road works tell in which days at least one road will be asphalted.

The first line contains integer n (1 ≤ n ≤ 50) — the number of vertical and horizontal roads in the city.  Next n2 lines contain the order of intersections in the schedule. The i-th of them contains two numbers hi, vi (1 ≤ hi, vi ≤ n), separated by a space, and meaning that the intersection that goes i-th in the timetable is at the intersection of the hi-th horizontal and vi-th vertical roads. It is guaranteed that all the intersections in the timetable are distinct.

In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.

NoteIn the sample the brigade acts like that:  On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road;  On the second day the brigade of the workers comes to the intersection of the 1-st horizontal and the 2-nd vertical road. The 2-nd vertical road hasn't been asphalted, but as the 1-st horizontal road has been asphalted on the first day, the workers leave and do not asphalt anything;  On the third day the brigade of the workers come to the intersection of the 2-nd horizontal and the 1-st vertical road. The 2-nd horizontal road hasn't been asphalted but as the 1-st vertical road has been asphalted on the first day, the workers leave and do not asphalt anything;  On the fourth day the brigade come to the intersection formed by the intersection of the 2-nd horizontal and 2-nd vertical road. As none of them has been asphalted, the workers asphalt the 2-nd vertical and the 2-nd horizontal road.

import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
void main()
{
	int num;
	readf("%d\n",&num);
	bool[]a=new bool[num],b=new bool[num];
	a[]=false,b[]=false;
	for(int i=0;i<num*num;i++)
	{
		int x,y;
		readf("%d %d\n",&x,&y);
		if((!a[x-1])&&(!b[y-1]))
		{
			write(i+1," ");
			a[x-1]=b[y-1]=true;
		}
	}
	readln();
}


It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor.Doctors have a strange working schedule. The doctor i goes to work on the si-th day and works every di day. So, he works on days si, si + di, si + 2di, ....The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors?

First line contains an integer n — number of doctors (1 ≤ n ≤ 1000).  Next n lines contain two numbers si and di (1 ≤ si, di ≤ 1000).

Output a single integer — the minimum day at which Borya can visit the last doctor.

NoteIn the first sample case, Borya can visit all doctors on days 2, 3 and 4.In the second sample case, Borya can visit all doctors on days 10 and 11.

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

void main(){

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

	int mx = 0;
	for (int i = 1; i <= n; ++i){
		int x, y;
		readf("%s %s", &x, &y);
		readln;
		while (x <= mx) x += y;
		mx = max(mx, x);
	}

	writeln(mx);

}


There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately. In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct). In the first contest, the participant on the 100-th place scored $$$a$$$ points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least $$$b$$$ points in the second contest.Similarly, for the second contest, the participant on the 100-th place has $$$c$$$ points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least $$$d$$$ points in the first contest.After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.Given integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$, please help the jury determine the smallest possible value of the cutoff score.

You need to process $$$t$$$ test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 3025$$$) — the number of test cases. Then descriptions of $$$t$$$ test cases follow. The first line of each test case contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$0 \le a,\,b,\,c,\,d \le 9$$$; $$$d \leq a$$$; $$$b \leq c$$$).  One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.

For each test case print a single integer — the smallest possible cutoff score in some olympiad scenario satisfying the given information.

NoteFor the first test case, consider the following olympiad scenario: there are $$$101$$$ participants in the elimination stage, each having $$$1$$$ point for the first contest and $$$2$$$ points for the second contest. Hence the total score of the participant on the 100-th place is $$$3$$$.For the second test case, consider the following olympiad scenario:   there are $$$50$$$ participants with points $$$5$$$ and $$$9$$$ for the first and second contest respectively;  $$$50$$$ participants with points $$$4$$$ and $$$8$$$ for the first and second contest respectively;  and $$$50$$$ participants with points $$$2$$$ and $$$9$$$ for the first and second contest respectively.  Hence the total point score of the participant on the 100-th place is $$$12$$$.

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

void play(){
    int a, b, c, d;
    a = rd!int;
    b = rd!int;
    c = rd!int;
    d = rd!int;
    writeln(max(a+b, c+d));
}

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

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int a, b, c, d;
		readf !(" %s %s %s %s") (a, b, c, d);
		writeln (max (a + b, c + d));
	}
}


Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.There will be n columns participating in the parade, the i-th column consists of li soldiers, who start to march from left leg, and ri soldiers, who start to march from right leg.The beauty of the parade is calculated by the following formula: if L is the total number of soldiers on the parade who start to march from the left leg, and R is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal |L - R|.No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index i and swap values li and ri. Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty.

The first line contains single integer n (1 ≤ n ≤ 105) — the number of columns.  The next n lines contain the pairs of integers li and ri (1 ≤ li, ri ≤ 500) — the number of soldiers in the i-th column which start to march from the left or the right leg respectively.

Print single integer k — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached. Consider that columns are numbered from 1 to n in the order they are given in the input data. If there are several answers, print any of them.

NoteIn the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal 5 + 8 + 3 = 16, and who march from the right leg — 6 + 9 + 10 = 25. In this case the beauty equals |16 - 25| = 9.It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9.

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

void main() {
  int N = readln().chomp.to!int;
  int Lsum = 0;
  int Rsum = 0;
  int[] L = new int[](N);
  int[] R = new int[](N);
  foreach (i; iota(N)) {
    auto input = readln().split.map!(to!int);
    Lsum += input[0];
    Rsum += input[1];
    L[i] = input[0];
    R[i] = input[1];
  }
  int max_b = abs(Lsum-Rsum);
  int max_i = 0;
  foreach (i; iota(N)) {
    if (max_b < abs((Lsum-L[i]+R[i])-(Rsum-R[i]+L[i]))) {
      max_b = abs((Lsum-L[i]+R[i])-(Rsum-R[i]+L[i]));
      max_i = i+1;
    }
  }

  writeln(max_i);
}

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

void main() {
  int N = readln().chomp.to!int;
  int Lsum = 0;
  int Rsum = 0;
  int[] L = new int[](N);
  int[] R = new int[](N);
  foreach (i; iota(N)) {
    auto input = readln().split.map!(to!int);
    Lsum += input[0];
    Rsum += input[1];
    L[i] = input[0];
    R[i] = input[1];
  }
  int max_b = abs(Lsum-Rsum);
  int max_i = 0;
  foreach (i; iota(N)) {
    if (max_b < abs((Lsum-L[i]+R[i])-(Rsum-R[i]+L[i]))) {
      max_b = (Lsum-L[i]+R[i])-(Rsum-R[i]+L[i]);
      max_i = i+1;
    }
  }

  writeln(max_i);
}

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

void main() {
  int N = readln().chomp.to!int;
  int Lsum = 0;
  int Rsum = 0;
  int[] L = new int[](N);
  int[] R = new int[](N);
  foreach (i; iota(N)) {
    auto input = readln().split.map!(to!int);
    Lsum += input[0];
    Rsum += input[1];
    L[i] = input[0];
    R[i] = input[1];
  }
  int max_b = abs(Lsum-Rsum);
  int max_i = 0;
  foreach (i; iota(N)) {
    if (max_b < abs((Lsum-L[i]+R[i])-(Rsum-R[i]+L[i]))) {
      max_b = abs(Lsum-L[i]+R[i])-(Rsum-R[i]+L[i]);
      max_i = i+1;
    }
  }

  writeln(max_i);
}


Let's define a multiplication operation between a string $$$a$$$ and a positive integer $$$x$$$: $$$a \cdot x$$$ is the string that is a result of writing $$$x$$$ copies of $$$a$$$ one after another. For example, "abc" $$$\cdot~2~=$$$ "abcabc", "a" $$$\cdot~5~=$$$ "aaaaa".A string $$$a$$$ is divisible by another string $$$b$$$ if there exists an integer $$$x$$$ such that $$$b \cdot x = a$$$. For example, "abababab" is divisible by "ab", but is not divisible by "ababab" or "aa".LCM of two strings $$$s$$$ and $$$t$$$ (defined as $$$LCM(s, t)$$$) is the shortest non-empty string that is divisible by both $$$s$$$ and $$$t$$$.You are given two strings $$$s$$$ and $$$t$$$. Find $$$LCM(s, t)$$$ or report that it does not exist. It can be shown that if $$$LCM(s, t)$$$ exists, it is unique.

The first line contains one integer $$$q$$$ ($$$1 \le q \le 2000$$$) — the number of test cases. Each test case consists of two lines, containing strings $$$s$$$ and $$$t$$$ ($$$1 \le |s|, |t| \le 20$$$). Each character in each of these strings is either 'a' or 'b'.

For each test case, print $$$LCM(s, t)$$$ if it exists; otherwise, print -1. It can be shown that if $$$LCM(s, t)$$$ exists, it is unique.

NoteIn the first test case, "baba" = "baba" $$$\cdot~1~=$$$ "ba" $$$\cdot~2$$$.In the second test case, "aaaaaa" = "aa" $$$\cdot~3~=$$$ "aaa" $$$\cdot~2$$$.

import std.stdio, std.string, std.numeric;
void main()
{
    int q;
    readf!"%d\n"(q);
    foreach (_; 0 .. q)
    {
        string s = readln.strip, t = readln.strip;
        auto n = s.length, m = t.length, g = gcd(n, m);
        string res = s[0 .. g];
        while (res.length % n || res.length % m)
            res ~= s[0 .. g];
        writeln(res[0 .. n] == s && res[0 .. m] == t ? res : "-1");
    }
}

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

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

void main()
{
    int T; get(T);
    while (T--) {
        char[] s, t; get(s); get(t);
        char[] r;
        if (s.length > t.length) swap(s, t);
        foreach (l; 1..s.length + 1) if (s.length % l == 0 && t.length % l == 0) {
            auto x = s[0..l];
            auto n = (s.length / l) * (t.length / l) / gcd(s.length / l, t.length / l);
            foreach (i; 0..s.length / l) if (s[i * l..i * l + l] != x) goto next;
            foreach (i; 0..t.length / l) if (t[i * l..i * l + l] != x) goto next;
            if (r.empty || r.length > l * n) {
                r = [];
                foreach (_; 0..n) r ~= x;
            }
            next:
        }
        if (r.empty) {
            writeln(-1);
        } else {
            writeln(r);
        }
    }
}

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; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void 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 modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new string[](t);
	foreach (ti; 0..t)
	{
		auto s1 = RD!string;
		auto s2 = RD!string;

		auto len = lcm(s1.length, s2.length);
		while (ans[ti].length < len)
		{
			ans[ti] ~= s1;
		}
		string s3;
		while (s3.length < len)
		{
			s3 ~= s2;
		}
		foreach (i; 0..s3.length)
		{
			if (ans[ti][i] != s3[i])
			{
				ans[ti].length = 0;
				break;
			}
		}
	}

	foreach (e; ans)
	{
		writeln(e.empty ? "-1" : e);
	}
	stdout.flush;
	debug readln;
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		auto t = readln.strip;
		auto m = s.length;
		auto n = t.length;
		auto g = gcd (m, n);
		auto x = s[0..g];
		auto r = x;
		while (r.length % m != 0 || r.length % n != 0)
		{
			r ~= x;
		}
		writeln ((r[0..m] == s && r[0..n] == t) ? r : "-1");
	}
}


You are given an integer $$$k$$$ and a string $$$s$$$ that consists only of characters 'a' (a lowercase Latin letter) and '*' (an asterisk).Each asterisk should be replaced with several (from $$$0$$$ to $$$k$$$ inclusive) lowercase Latin letters 'b'. Different asterisk can be replaced with different counts of letter 'b'.The result of the replacement is called a BA-string.Two strings $$$a$$$ and $$$b$$$ are different if they either have different lengths or there exists such a position $$$i$$$ that $$$a_i \neq b_i$$$.A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds:   $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$;  in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$. Now consider all different BA-strings and find the $$$x$$$-th lexicographically smallest of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of testcases. The first line of each testcase contains three integers $$$n$$$, $$$k$$$ and $$$x$$$ ($$$1 \le n \le 2000$$$; $$$0 \le k \le 2000$$$; $$$1 \le x \le 10^{18}$$$). $$$n$$$ is the length of string $$$s$$$. The second line of each testcase is a string $$$s$$$. It consists of $$$n$$$ characters, each of them is either 'a' (a lowercase Latin letter) or '*' (an asterisk). The sum of $$$n$$$ over all testcases doesn't exceed $$$2000$$$. For each testcase $$$x$$$ doesn't exceed the total number of different BA-strings. String $$$s$$$ contains at least one character 'a'.

For each testcase, print a single string, consisting only of characters 'b' and 'a' (lowercase Latin letters) — the $$$x$$$-th lexicographically smallest BA-string.

NoteIn the first testcase of the example, BA-strings ordered lexicographically are:   a  ab  abb  abbb  abbbb In the second testcase of the example, BA-strings ordered lexicographically are:   aa  aba  abba Note that string "aba" is only counted once, even though there are two ways to replace asterisks with characters 'b' to get it.

import std.stdio;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }

enum long INF = 1L<<60;

void solve() {
    int N, K; long X; scanf("%d %d %lld\n", &N, &K, &X);
    X--;
    auto S = readln.strip;

    long[] M; {
        bool prev = false;
        for (int i = 0; i < N; i++) {
            if (S[i] == '*') {
                if (prev) { M.back += K; }
                else {
                    M ~= K + 1;
                }
                prev = true;
            } else {
                prev = false;
            }
        }
    }

    int m = cast(int)(M.length);
    auto Y = new long[m];
    for (int i = m - 1; i >= 0; i--) {
        Y[i] = X % M[i];
        X /= M[i];
    }

    char[] ans; {
        int j = 0;
        bool prev = false;
        for (int i = 0; i < N; i++) {
            if (S[i] == '*') {
                if (prev) {
                    // do nothing
                } else {
                    foreach (_; 0 .. Y[j]) {
                        ans ~= 'b';
                    }
                    j++;
                }
                prev = true;
            } else {
                ans ~= 'a';
                prev = false;
            }
        }
        assert(j == m);
    }
    writeln(ans);
}

void main() {
    int T = read!int;
    foreach (t; 0 .. T) solve();
}

import std;

int[]
genStars (in string s) {
    int[] ret = [0];

    foreach (c; s)
        if (c == '*')
            ++ ret[$ -  1];
        else if (c == 'a' && ret[$ - 1] != 0)
            ret ~= 0;

    if (ret[$ - 1] == 0)
        ret = ret[0 .. $ - 1];

    return ret;
}

void
solve () {
    int n, k;
    ulong x;
    string s;

    readf("%s %s %s\n", n, k, x);
    s = readln()[0 .. $ - 1];
    -- x;

    int[] stars = genStars(s);
    if (stars.length == 0) {
        writeln(s);
        return;
    }

    stars[] = stars[] * k + 1;

    size_t index = stars.length;
    real product = 1;

    while (product <= x) {
        -- index;
        product *= stars[index];
    }

    uint[] ans = new uint[stars.length];

    while (x != 0) {
        ulong prefix = cast(ulong)(product / stars[index]);
        ans[index] = cast(uint)(x / prefix);
        x %= prefix;
        product = prefix;
        ++ index;
    }

    index = 0;
    for (size_t i = 0; i != s.length; ++ i) {
        if (s[i] == 'a')
            write('a');
        else {
            while (i != s.length && s[i] == '*')
                ++ i;
            -- i;
            write('b'.repeat(ans[index]));
            ++ index;
        }
    }
    writeln();
}

void main () {
    int t;
    readf("%s\n", t);

    foreach (__sth; 0 .. t) {
        solve();
    }
}

// ""

immutable multi = true;

uint n, k;
ulong x;
byte[] s;

void readInput()
{
  n = readInt!uint;
  k = readInt!uint;
  x = readInt!ulong;
  s = cast(byte[]) readString;
  debug writeln("read string ", s);
}

void genInput()
{
  import std.random;
  foreach(i; 0 .. 100) s ~= "*a"[0];
  n = cast(uint) s.length;
  k = 0;
  x = 1;
  debug writeln("generated ", cast(string)s);
}
alias input = readInput;

void solve(int tc)
{
  debug writeln("called solve with ", tc, " ", s);
  uint[] groups;
  bool open = false;
  foreach(si; s)
    {
      debug writeln("in char ", si);
      final switch(si)
	{
	case '*':
	  if (open)
	    {
	      groups[$-1]++;
	    }
	  else
	    {
	      groups ~= 1;
	    }
	  open = true;
	  break;
	case 'a':
	  open = false;
	  break;
	}
    }
  debug writeln("groups ", groups);
  foreach(ref gi; groups)
    {
      gi = k * gi + 1;
    }
  import std.experimental.checkedint;
  auto order = new ulong[](groups.length);
  Checked!(ulong, Saturate) prevOrder = ulong(1);
  foreach_reverse(i; 0 .. order.length)
    {
      order[i] = (prevOrder * groups[i]).get;
      prevOrder = order[i];
    }
  auto digits = new long[](groups.length);
  void fillDigits(uint i, ulong xth)
  {
    if (i+1 == digits.length)
      {
	digits[i] = xth;
	return;
      }
    digits[i] = xth / order[i + 1];
    xth = xth % order[i + 1];
    fillDigits(i + 1, xth);
  }
  if (digits) fillDigits(0, x - 1);
  int currentGroup = 0;
  byte[] ans;
  open = false;
  foreach(si; s)
    {
      final switch(si)
	{
	case '*':
	  if (!open)
	    {
	      foreach(i; 0 .. digits[currentGroup])
		ans ~= 'b';
	      open = true;
	      currentGroup++;
	    }
	  break;
	case 'a':
	  open = false;
	  ans ~= 'a';
	  break;
	}
    }
  writeln(cast(string)ans);
}

// main {{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t)
	  {
	    input();
	    solve(tc);
	  }
}
// }}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

char topChar()
{
	return cast(char) currChar;
}

void popChar()
{
	import core.stdc.stdio;
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
		popChar;
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    long n, k, x;
    readf!" %d %d %d "(n, k, x);
    auto s = readln.strip;
    x--;
    string[] ans;
    foreach_reverse (chunk ; s.split('a')) {
      auto cnt = x % (chunk.length * k + 1);
      x /= (chunk.length * k + 1);
      ans ~= replicate("b", cast(size_t)cnt);
    }
    writeln(ans.retro.join('a'));
  }
}

import std;

int[]
genStars (in string s) {
    int[] ret = [0];

    foreach (c; s)
        if (c == '*')
            ++ ret[$ -  1];
        else if (c == 'a' && ret[$ - 1] != 0)
            ret ~= 0;

    if (ret.length > 1 && ret[$ - 1] == 0)
        ret = ret[0 .. $ - 1];

    return ret;
}

void
solve () {
    int n, k;
    ulong x;
    string s;

    readf("%s %s %s\n", n, k, x);
    s = readln()[0 .. $ - 1];
    -- x;

    int[] stars = genStars(s);
    stars[] = stars[] * k + 1;

    size_t index = stars.length - 1;
    ulong product = stars[index];

    while (product < x) {
        -- index;
        product *= stars[index];
    }

    //writeln(stars);

    int[] ans = new int[stars.length];

    while (x != 0) {
        ulong prefix = product / stars[index];
        ans[index] = cast(int)(x / prefix);
        x %= prefix;
        product = prefix;
        ++ index;
    }

    index = 0;
    for (size_t i = 0; i != s.length; ++ i) {
        if (s[i] == 'a')
            write('a');
        else {
            while (i != s.length && s[i] == '*')
                ++ i;
            -- i;
            write('b'.repeat(ans[index]));
            ++ index;
        }
    }
    writeln();
}

void main () {
    int t;
    readf("%s\n", t);

    foreach (__sth; 0 .. t) {
        solve();
    }
}

// ""

import std;

int[]
genStars (in string s) {
    int[] ret = [0];

    foreach (c; s)
        if (c == '*')
            ++ ret[$ -  1];
        else if (c == 'a' && ret[$ - 1] != 0)
            ret ~= 0;

    return ret;
}

void
solve () {
    int n, k;
    ulong x;
    string s;

    readf("%s %s %s\n", n, k, x);
    s = readln()[0 .. $ - 1];
    -- x;

    int[] stars = genStars(s);
    stars[] = stars[] * k + 1;

    size_t index = stars.length - 1;
    ulong product = stars[index];

    while (product < x) {
        -- index;
        product *= stars[index];
    }

    int[] ans = new int[stars.length];

    while (x != 0) {
        ulong prefix = product / stars[index];
        ans[index] = cast(int)(x / prefix);
        x %= prefix;
        product = prefix;
        ++ index;
    }

    index = 0;
    for (size_t i = 0; i != s.length; ++ i) {
        if (s[i] == 'a')
            write('a');
        else {
            while (i != s.length && s[i] == '*')
                ++ i;
            -- i;
            write('b'.repeat(ans[index]));
            ++ index;
        }
    }
    writeln();
}

void main () {
    int t;
    readf("%s\n", t);

    foreach (__sth; 0 .. t) {
        solve();
    }
}

// ""

immutable multi = true;

uint n, k;
ulong x;
byte[] s;

void readInput()
{
  auto n = readInt!uint;
  auto k = readInt!uint;
  auto x = readInt!ulong;
  auto s = cast(byte[]) readString;
}

void genInput()
{
  import std.random;
  foreach(i; 0 .. 100) s ~= "*a"[0];
  n = cast(uint) s.length;
  k = 0;
  x = 1;
  debug writeln("generated ", cast(string)s);
}
alias input = readInput;

void solve(int tc)
{
  uint[] groups;
  bool open = false;
  foreach(si; s)
    {
      final switch(si)
	{
	case '*':
	  if (open)
	    {
	      groups[$-1]++;
	    }
	  else
	    {
	      groups ~= 1;
	    }
	  open = true;
	  break;
	case 'a':
	  open = false;
	  break;
	}
    }
  foreach(ref gi; groups)
    {
      gi = k * gi + 1;
    }
  import std.experimental.checkedint;
  auto order = new ulong[](groups.length);
  Checked!(ulong, Saturate) prevOrder = ulong(1);
  foreach_reverse(i; 0 .. order.length)
    {
      order[i] = (prevOrder * groups[i]).get;
      prevOrder = order[i];
    }
  auto digits = new long[](groups.length);
  void fillDigits(uint i, ulong xth)
  {
    if (i+1 == digits.length)
      {
	digits[i] = xth;
	return;
      }
    digits[i] = xth / order[i + 1];
    xth = xth % order[i + 1];
    fillDigits(i + 1, xth);
  }
  if (digits) fillDigits(0, x - 1);
  int currentGroup = 0;
  byte[] ans;
  open = false;
  foreach(si; s)
    {
      final switch(si)
	{
	case '*':
	  if (!open)
	    {
	      foreach(i; 0 .. digits[currentGroup])
		ans ~= 'b';
	      open = true;
	      currentGroup++;
	    }
	  break;
	case 'a':
	  open = false;
	  ans ~= 'a';
	  break;
	}
    }
  writeln(cast(string)ans);
}

// main {{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t)
	  {
	    input();
	    solve(tc);
	  }
}
// }}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

char topChar()
{
	return cast(char) currChar;
}

void popChar()
{
	import core.stdc.stdio;
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
		popChar;
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}


Gildong recently learned how to find the longest increasing subsequence (LIS) in $$$O(n\log{n})$$$ time for a sequence of length $$$n$$$. He wants to test himself if he can implement it correctly, but he couldn't find any online judges that would do it (even though there are actually many of them). So instead he's going to make a quiz for you about making permutations of $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$, inclusive, to test his code with your output.The quiz is as follows.Gildong provides a string of length $$$n-1$$$, consisting of characters '<' and '>' only. The $$$i$$$-th (1-indexed) character is the comparison result between the $$$i$$$-th element and the $$$i+1$$$-st element of the sequence. If the $$$i$$$-th character of the string is '<', then the $$$i$$$-th element of the sequence is less than the $$$i+1$$$-st element. If the $$$i$$$-th character of the string is '>', then the $$$i$$$-th element of the sequence is greater than the $$$i+1$$$-st element.He wants you to find two possible sequences (not necessarily distinct) consisting of $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$, inclusive, each satisfying the comparison results, where the length of the LIS of the first sequence is minimum possible, and the length of the LIS of the second sequence is maximum possible.

Each test contains one or more test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Each test case contains exactly one line, consisting of an integer and a string consisting of characters '<' and '>' only. The integer is $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$), the length of the permutation you need to find. The string is the comparison results explained in the description. The length of the string is $$$n-1$$$. It is guaranteed that the sum of all $$$n$$$ in all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print two lines with $$$n$$$ integers each. The first line is the sequence with the minimum length of the LIS, and the second line is the sequence with the maximum length of the LIS. If there are multiple answers, print any one of them. Each sequence should contain all integers between $$$1$$$ and $$$n$$$, inclusive, and should satisfy the comparison results. It can be shown that at least one answer always exists.

NoteIn the first case, $$$1$$$ $$$2$$$ $$$3$$$ is the only possible answer.In the second case, the shortest length of the LIS is $$$2$$$, and the longest length of the LIS is $$$3$$$. In the example of the maximum LIS sequence, $$$4$$$ '$$$3$$$' $$$1$$$ $$$7$$$ '$$$5$$$' $$$2$$$ '$$$6$$$' can be one of the possible LIS.

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

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

void solve(){
	foreach(_; 0 .. rint){
		int n = rint;
		string s = rstring;
		bool[] ls = s.map!(c => c == '<').array;

		int[] us;
		{
			int u = 1;
			foreach(l; ls){
				if(l){
					u += 1;
				}
				else{
					us ~= u;
					u = 1;
				}
			}
			us ~= u;
		}
		log("us:", us);
		int sum = 0;
		int[] ans;
		foreach(u; us){
			foreach(i; n - sum - u + 1 .. n - sum + 1) ans ~= i;
			sum += u;
		}
		ans.map!(to!string).array.join(" ").writeln;

		int[] vs;
		{
			int v = 1;
			foreach(l; ls){
				if(l){
					vs ~= v;
					v = 1;
				}
				else{
					v += 1;
				}
			}
			vs ~= v;
		}
		log("vs:", vs);
		int sum2 = 0;
		int[] ans2;
		foreach(int j, v; vs){
			foreach_reverse(i; n - sum2 - (v - 1) + 1 .. n - sum2 + 1) ans2 ~= i;
			ans2 ~= j + 1;
			sum2 += v - 1;
		}
		ans2.map!(to!string).array.join(" ").writeln;
	}
}

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; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T 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 t = RD!int;
	auto ans = new int[][](t*2);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto s = RD!string;
		{
			auto ai = ti * 2;
			int x = n;
			int i;
			while (i < n-1)
			{
				if (s[i] == '>')
				{
					ans[ai] ~= x;
					--x;
					++i;
				}
				else
				{
					int cnt;
					foreach (j; i..n-1)
					{
						if (s[j] == '>') break;
						++cnt;
					}
					foreach (j; 0..cnt+1)
					{
						ans[ai] ~= x - cnt + j;
					}
					x -= cnt + 1;
					i += cnt + 1;
				}
			}
			if (x >= 1)
				ans[ai] ~= x;
		}
		{
			auto ai = ti * 2 + 1;
			int x = 1;
			int i;
			while (i < n-1)
			{
				if (s[i] == '<')
				{
					ans[ai] ~= x;
					++x;
					++i;
				}
				else
				{
					int cnt;
					foreach (j; i..n-1)
					{
						if (s[j] == '<') break;
						++cnt;
					}
					foreach (j; 0..cnt+1)
					{
						ans[ai] ~= x + cnt - j;
					}
					x += cnt + 1;
					i += cnt + 1;
				}
			}
			if (x <= n)
				ans[ai] ~= x;
		}
	}
	foreach (e; ans)
		e.map!(to!string).join(" ").writeln;
	stdout.flush;
	debug readln;
}


New Year is coming in Tree World! In this world, as the name implies, there are n cities connected by n - 1 roads, and for any two distinct cities there always exists a path between them. The cities are numbered by integers from 1 to n, and the roads are numbered by integers from 1 to n - 1. Let's define d(u, v) as total length of roads on the path between city u and city v.As an annual event, people in Tree World repairs exactly one road per year. As a result, the length of one road decreases. It is already known that in the i-th year, the length of the ri-th road is going to become wi, which is shorter than its length before. Assume that the current year is year 1.Three Santas are planning to give presents annually to all the children in Tree World. In order to do that, they need some preparation, so they are going to choose three distinct cities c1, c2, c3 and make exactly one warehouse in each city. The k-th (1 ≤ k ≤ 3) Santa will take charge of the warehouse in city ck.It is really boring for the three Santas to keep a warehouse alone. So, they decided to build an only-for-Santa network! The cost needed to build this network equals to d(c1, c2) + d(c2, c3) + d(c3, c1) dollars. Santas are too busy to find the best place, so they decided to choose c1, c2, c3 randomly uniformly over all triples of distinct numbers from 1 to n. Santas would like to know the expected value of the cost needed to build the network.However, as mentioned, each year, the length of exactly one road decreases. So, the Santas want to calculate the expected after each length change. Help them to calculate the value.

The first line contains an integer n (3 ≤ n ≤ 105) — the number of cities in Tree World. Next n - 1 lines describe the roads. The i-th line of them (1 ≤ i ≤ n - 1) contains three space-separated integers ai, bi, li (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ li ≤ 103), denoting that the i-th road connects cities ai and bi, and the length of i-th road is li. The next line contains an integer q (1 ≤ q ≤ 105) — the number of road length changes. Next q lines describe the length changes. The j-th line of them (1 ≤ j ≤ q) contains two space-separated integers rj, wj (1 ≤ rj ≤ n - 1, 1 ≤ wj ≤ 103). It means that in the j-th repair, the length of the rj-th road becomes wj. It is guaranteed that wj is smaller than the current length of the rj-th road. The same road can be repaired several times.

Output q numbers. For each given change, print a line containing the expected cost needed to build the network in Tree World. The answer will be considered correct if its absolute and relative error doesn't exceed 10 - 6.

NoteConsider the first sample. There are 6 triples: (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1). Because n = 3, the cost needed to build the network is always d(1, 2) + d(2, 3) + d(3, 1) for all the triples. So, the expected cost equals to d(1, 2) + d(2, 3) + d(3, 1).

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;
import std.traits;

void main(string[] args)
{
  auto n = next!int;
  auto roadLength = new int[](n - 1);
  auto adj = new Tuple!(int, int)[][](n);
  foreach(roadi; 0 .. n - 1)
    {
      auto a = next!int - 1;
      auto b = next!int - 1;
      auto l = next!int;
      roadLength[roadi] = l;
      adj[a] ~= tuple(b, roadi);
      adj[b] ~= tuple(a, roadi);
    }
  auto roadMultiplier = new long[](n - 1);
  auto size = new int[](n);
  void calcSize(int v, int p)
  {
    size[v] = 1;
    foreach(adji; adj[v])
      {
	auto w = adji[0];
	auto roadi = adji[1];
	if (w != p)
	  {
	    calcSize(w, v);
	    size[v] += size[w];
	  }
      }
  }
  calcSize(0, -1);

  void calcRoadMultiplier(int vertex, int roadIndex, int parent)
  {
    debug writeln("v ", vertex, " ri ", roadIndex, " p ", parent);
    if (roadIndex >= 0)
      {
	auto pool1 = cast(long)size[vertex];
	auto pool2 = cast(long)(n - size[vertex]);
	auto opt1 = (pool1 * (pool1 - 1) / 2) * pool2;
	auto opt2 = (pool2 * (pool2 - 1) / 2) * pool1;
	roadMultiplier[roadIndex] = (opt1 + opt2) * 6;
      }
    foreach(adjacency; adj[vertex])
      {
	auto neighbour = adjacency[0];
	auto adjacencyIndex = adjacency[1];
	if (neighbour != parent)
	  {
	    calcRoadMultiplier(neighbour, adjacencyIndex, vertex);
	  }
      }
  }
  calcRoadMultiplier(0, -1, -1);
  debug writeln("rm ", roadMultiplier);

  real expected = 0.0;
  foreach(i, len; roadLength)
    {
      expected += len * roadMultiplier[i] * 2;
    }
  auto q = next!int;
  foreach(query; 0 .. q)
    {
      auto r = next!int - 1;
      auto w = next!int;
      expected -= roadLength[r] * roadMultiplier[r] * 2;
      roadLength[r] = w;
      expected += roadLength[r] * roadMultiplier[r] * 2;
      writefln!"%.10s"(expected / (cast(long) n * (n - 1) * (n - 2)));
    }
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  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.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (isArray!(typeof(ti)))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}


Your classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $$$s$$$ of length $$$n$$$ and $$$t$$$ of length $$$m$$$.A sequence $$$p_1, p_2, \ldots, p_m$$$, where $$$1 \leq p_1 < p_2 < \ldots < p_m \leq n$$$, is called beautiful, if $$$s_{p_i} = t_i$$$ for all $$$i$$$ from $$$1$$$ to $$$m$$$. The width of a sequence is defined as $$$\max\limits_{1 \le i < m} \left(p_{i + 1} - p_i\right)$$$.Please help your classmate to identify the beautiful sequence with the maximum width. Your classmate promised you that for the given strings $$$s$$$ and $$$t$$$ there is at least one beautiful sequence.

The first input line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq m \leq n \leq 2 \cdot 10^5$$$) — the lengths of the strings $$$s$$$ and $$$t$$$. The following line contains a single string $$$s$$$ of length $$$n$$$, consisting of lowercase letters of the Latin alphabet. The last line contains a single string $$$t$$$ of length $$$m$$$, consisting of lowercase letters of the Latin alphabet. It is guaranteed that there is at least one beautiful sequence for the given strings.

Output one integer — the maximum width of a beautiful sequence.

NoteIn the first example there are two beautiful sequences of width $$$3$$$: they are $$$\{1, 2, 5\}$$$ and $$$\{1, 4, 5\}$$$.In the second example the beautiful sequence with the maximum width is $$$\{1, 5\}$$$.In the third example there is exactly one beautiful sequence — it is $$$\{1, 2, 3, 4, 5\}$$$.In the fourth example there is exactly one beautiful sequence — it is $$$\{1, 2\}$$$.

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

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

void main()
{
    int N, M; get(N, M);
    char[] S, T; get(S); get(T);

    auto ii = new int[]['z' + 1];
    auto jj = new int[]['z' + 1];
    foreach (i, c; S) {
        ii[c] ~= i.to!int;
        jj[c] ~= i.to!int;
    }
    auto ls = new int[](M);
    auto rs = new int[](M);
    int l = -1, r = N;
    foreach (i, c; T) {
        while (ii[c].front <= l) ii[c].popFront();
        ls[i] = l = ii[c].front;
    }
    foreach_reverse (i, c; T) {
        while (jj[c][$ - 1] >= r) jj[c] = jj[c][0..$ - 1];
        rs[i] = r = jj[c][$ - 1];
    }

    writeln(0.iota(M - 1).map!(i => rs[i + 1] - ls[i]).maxElement());
}

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; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void 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 modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto n = RD!int;
	auto m = RD!int;
	auto s1 = RD!(char[]);
	auto s2 = RD!(char[]);

	int[] f(in char[] ss, in char[] tt)
	{
		auto p = new int[](m);
		int l;
		foreach (j; 0..m)
		{
			foreach (i; l..n)
			{
				if (ss[i] == tt[j])
				{
					p[j] = i;
					l = i+1;
					break;
				}
			}
		}
		return p;
	}
	auto p1 = f(s1, s2);
	s1.reverse;
	s2.reverse;
	auto p2 = f(s1, s2);
	p2.reverse;

	int ans;
	foreach (i; 1..m)
	{
		auto w = (n - 1 - p2[i]) - p1[i-1];
		ans.chmax(w);
	}

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

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

int solve(string s, string t)
{
    auto n = to!int(s.length), m = to!int(t.length);
    auto next = new int[][](n, 26);
    fill(next[n - 1], n);
    next[n - 1][s[n - 1] - 'a'] = n - 1;
    foreach_reverse (i; 0 .. n - 1)
    {
        next[i + 1].copy(next[i]);
        next[i][s[i] - 'a'] = i;
    }
    auto prev = new int[][](n, 26);
    fill(prev[0], -1);
    prev[0][s[0] - 'a'] = 0;
    foreach (i; 1 .. n)
    {
        prev[i - 1].copy(prev[i]);
        prev[i][s[i] - 'a'] = i;
    }
    auto fp = new int[m];
    fp[0] = next[0][t[0] - 'a'];
    foreach (i; 1 .. m) fp[i] = next[fp[i - 1] + 1][t[i] - 'a'];
    auto bp = new int[m];
    bp[m - 1] = prev[n - 1][t[m - 1] - 'a'];
    foreach_reverse (i; 0 .. m - 1) bp[i] = prev[bp[i + 1] - 1][t[i] - 'a'];
    int res;
    foreach (i; 0 .. m - 1) res = max(res, bp[i + 1] - fp[i]);
    return res;
}

int main(string[] args)
{
    readln;
    auto s = readln.strip;
    auto t = readln.strip;
    auto ret = solve(s, t);
    writeln(ret);
    return 0;
}

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

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

void main()
{
    int N, M; get(N, M);
    char[] S, T; get(S); get(T);

    auto ii = new int[]['z' + 1];
    auto jj = new int[]['z' + 1];
    foreach (i, c; S) {
        ii[c] ~= i.to!int;
        jj[c] ~= i.to!int;
    }
    auto ls = new int[](M);
    int l;
    foreach (i, c; T) {
        while (ii[c].front < l) ii[c].popFront();
        ls[i] = ii[c].front;
        l = ii[c].front;
    }
    auto rs = new int[](M);
    int r = N;
    foreach_reverse (i, c; T) {
        while (jj[c][$ - 1] > r) jj[c] = jj[c][0..$ - 1];
        rs[i] = jj[c][$ - 1];
        r = jj[c][$ - 1];
    }

    writeln(0.iota(M - 1).map!(i => rs[i + 1] - ls[i]).maxElement());
}

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; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void 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 modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto n = RD!int;
	auto m = RD!int;
	auto s1 = RD!(char[]);
	auto s2 = RD!(char[]);

	int f(in char[] ss, in char[] tt)
	{
		int p;
		foreach (i; 0..n)
		{
			if (ss[i] == tt[0])
			{
				p = i;
				break;
			}
		}

		int res;
		foreach (j; 1..m-1)
		{
			foreach (i; p+1..n)
			{
				if (ss[i] == tt[j])
				{
					res.chmax(i-p);
					p = i;
					break;
				}
			}
		}

		foreach_reverse (i; 0..n)
		{
			if (ss[i] == tt[m-1])
			{
				res.chmax(i-p);
				break;
			}
		}
		return res;
	}
	int ans = f(s1, s2);
	s1.reverse;
	s2.reverse;
	ans.chmax(f(s1, s2));

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


Appleman and Toastman like games. Today they play a game with strings with the following rules. Firstly Toastman tells Appleman two strings s and t both consisting only of letters 'A', 'B', 'C', 'D'. Then Appleman must build string s as quickly as possible. Initially he has empty string, and in one second he can append to end of the current string any contiguous substring of t.Now, Toastman and Appleman are beginning to play the game. Toastman has already told string t to Appleman, but he hasn't come up with string s yet. Toastman only thinks, that he should choose string s consisting of n characters. Of course, he wants to find the worst string for Appleman (such string, that Appleman will spend as much time as possible during the game). Tell Toastman, how much time will Appleman spend during the game if Toastman finds the worst string for him. You can assume that Appleman plays optimally, therefore he builds any string s in minimal possible time.

The first line contains an integer n (1 ≤ n ≤ 1018). The second line contains string t (1 ≤ |t| ≤ 105). String t consists of only letters 'A', 'B', 'C', 'D'. Each letter appears at least once in string t.

Print a single integer — the largest possible time Appleman needs.

NoteIn the first example, Toastman can choose s equal to "AAAAA".In the second example, Toastman can choose s equal to "DADDA".

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

immutable V = 4;
immutable LIM_DIST = 10;
immutable LIM_E = 60;
immutable INF = 1_000_000_000_000_000_000;

long[][] mul(long[][] a, long[][] b) {
	long[][] ret = new long[][](V, V);
	foreach (u; 0 .. V) {
		ret[u][] = INF;
	}
	foreach (u; 0 .. V) foreach (w; 0 .. V) foreach (v; 0 .. V) {
		chmin(ret[u][v], a[u][w] + b[w][v]);
	}
	return ret;
}

long N;
string T;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readLong;
		T = readToken;

		long[][] D = new long[][](V, V);
		foreach (u; 0 .. V) {
			D[u][] = LIM_DIST;
		}
		foreach (d; 1 .. LIM_DIST) {
			bool[int][][] apps = new bool[int][][](V, V);
			foreach (i; 0 .. T.length) if (i + d < T.length) {
				int enc;
				foreach (j; i + 1 .. i + d) {
					enc = enc * 4 + (T[j] - 'A');
				}
				apps[T[i] - 'A'][T[i + d] - 'A'][enc] = true;
			}
			foreach (u; 0 .. V) foreach (v; 0 .. V) {
				if (apps[u][v].length < 4 ^^ (d - 1)) {
					chmin(D[u][v], cast(long)(d));
				}
			}
		}
debug{
writeln("D = ",D);
}

		//	ds[e] = D^(2^e)
		long[][][] ds = new long[][][LIM_E];
		ds[0] = D;
		foreach (e; 1 .. LIM_E) {
			ds[e] = mul(ds[e - 1], ds[e - 1]);
		}

		long ans;
		long[][] crt = new long[][](V, V);
		foreach (u; 0 .. V) {
			crt[u][] = INF;
			crt[u][u] = 0;
		}
		foreach_reverse (e; 0 .. LIM_E) {
			long[][] nxt = mul(crt, ds[e]);
			const opt = nxt.map!"a.reduce!min".reduce!min;
			if (opt < N) {
				ans |= 1L << e;
				crt = nxt;
			}
		}
		++ans;
		writeln(ans);
	}
	} catch (EOFException) {}
}


A flower shop has got n bouquets, and the i-th bouquet consists of ai flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a large bouquet should be odd. Each of the initial bouquets can be a part of at most one large bouquet. If an initial bouquet becomes a part of a large bouquet, all its flowers are included in the large bouquet.Determine the maximum possible number of large bouquets Vasya can make.

The first line contains a single positive integer n (1 ≤ n ≤ 105) — the number of initial bouquets. The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the number of flowers in each of the initial bouquets.

Print the maximum number of large bouquets Vasya can make.

NoteIn the first example Vasya can make 2 large bouquets. For example, the first bouquet can contain the first and the fifth initial bouquets (the total number of flowers is then equal to 9), and the second bouquet can consist of the second and the third initial bouquets (the total number of flowers is then equal to 7). The fourth initial bouquet is unused in this scheme. In the second example it is not possible to form a single bouquet with odd number of flowers.In the third example Vasya can make one large bouquet. For example, he can make it using all three initial bouquets. The size of the large bouquet is then equal to 11 + 4 + 10 = 25.

module main;

import std.c.stdio;

int main(string[] argv)
{

    int n;
    scanf("%d", &n);
    int ch = 0, ne = 0;
    int x;
    for (int i = 0; i < n; i++){
        scanf("%d", &x);
        if (x % 2 == 0){
            ch++;
        } else {
            ne++;
        }
    }
    if (ne < ch){
        printf("%d", ne);
    } else {
        printf("%d", ch + (ne - ch) / 3);
    }

	return 0;
}

module main;

import std.c.stdio;
import  std.algorithm.comparison;

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int odd, even;
	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1)
			odd++;
		else
			even++;
	if(even >= odd) {
		printf("%d", odd);
		return 0;
	}
	int ans = even;
	odd -= even;
	int t = odd / 3;
	ans = ans + t;
	printf("%d", max(ans, 0));
	return 0;
}

module main;

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

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int[] arr = new int[n];
	int even = 0;
	int odd = 0;

	for(int i = 0; i<n; i++) {
		scanf("%d", &arr[i]);
		if( arr[i] % 2 == 1 )
			odd++;
		else
			even++;
	}
	int ans = min(odd, even);
	while( odd >= 0 ) {
		ans = max(ans, min(odd, even));
		odd -= 2;
		even += 1;
	}
	printf("%d", ans );

	return 0;
}

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

int main()
{
    int n;
	scanf("%d", &n);
	int x = 0, y = 0;
	for (int z, i = 0; i < n; i++) {
		scanf("%d", &z);
		if (z % 2 == 1) x = x + 1;
			else y = y + 1;
	}
	int ans;
	if (x < y) ans = x;
	else {
		ans = y;
		x = x - y;
		ans = ans + x / 3;
	}
    writeln(ans);
    return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n, a, o = 0, e = 0, z = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a);
		if (a%2 == 0)
			e = e+1;
		else
			o = o+1;

	}

	for (int i = 0; i <= o; i += 3)
	{
		if (e < o-i)
		{
			if (i/3+e > z)
				z = i/3+e;
		}
		else
		{
			if (i/3+o-i > z)
				z = i/3+o-i;
		}
	}
	printf("%d", z);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv) {
    int n;
    scanf("%d",&n);
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    int odd = 0, even = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] % 2 == 0) {
            even++;
        }
        else {
            odd++;
        }
    }
    int k = 0;
    int tmp = (even < odd) ? even : odd;
    k += tmp;
    even -= tmp;
    odd -= tmp;
    k += odd / 3;
    printf("%d\n", k);
    return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k,ch=0,nch=0;
	scanf("%d", &n);
    for(int i = 0; i<n; i++) {
		scanf("%d", &k);
        if (k % 2 == 0) {
            ch += 1;
        } else {
            nch += 1;
        }
    }
    if (ch >= nch) {
        printf("%d", nch);
    } else {
        printf("%d", ch + (nch - ch) / 3);
    }
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int a = 0;
	int b = 0;
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		if (x % 2 == 0) {
			a++;
		} else {
			b++;
		}
	}
	if (b <= a) {
		printf("%d\n", b);
	} else {
		printf("%d\n", (b + 2 * a) / 3);
	}
	return 0;
}

module main;

import std.c.stdio;
import std.algorithm.comparison;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int t;
	int c1 = 0, c2 = 0;
	for(int i = 0; i<n; i++) {
		scanf("%d", &t);
		if (t % 2 == 0) {
		    c2 = c2 + 1;
		}
		else {
		    c1 = c1 + 1;
		}
	}

	int res = min(c2, c1);
	c1 = c1 - res;
	c2 = c2 - res;
	res = res + c1 / 3;

	printf("%d", res);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int [] a = new int[n];
	int alpha = 0,beta = 0;
	for(int i = 0; i<n; i++){
		scanf("%d", &a[i]);
	    if(a[i] % 2 == 0)alpha++;
	    else beta++;
	}
	int ans = 0;
	while(alpha > 0 && beta > 0){
	    ans++;alpha--;beta--;
	}
	ans = ans + (beta / 3);
	printf("%d", ans);
	return 0;
}

import std.stdio;
void main(string[] args)
{
    int n,ans1=0,ans2=0,ans=0;
    scanf("%d",&n);
    for (int i=1;i<=n;++i){
        int x;
        scanf("%d",&x);
        if (x&1) ++ans1;
        else ++ans2;
    }
    if (ans1<ans2) ans=ans1;
    else ans=ans2;
    ans1-=ans;
    if (ans1>=0) ans+=ans1/3;
    writeln(ans);
}

import std.stdio;
import std.algorithm;

void main() {
	int n;
	scanf("%d", &n);
	int a, cnt1, cnt0;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a);
		if (a & 1) ++cnt1;
		else ++cnt0;
	}
	int ans = min(cnt0, cnt1);
	cnt1 -= ans;
	ans += cnt1 / 3;
	printf("%d", ans);
}

import std.stdio;

void main()
{
	int n = 0;
	readf("%d ", &n);
	int ch = 0;
	int nech = 0;
    foreach (_; 0 .. n)
    {
        int a;
        readf("%d ", &a);
        if (a % 2 == 0)
        	ch = ch + 1;
        else
        	nech = nech + 1;
    }
    if (nech <= ch) {
    	writeln(nech);
    } else {
    	auto x = nech - ch;
    	writeln(ch + x / 3);
    }

}

module main;

import std.c.stdio;
//import std.c.cstdlib;
//import std.c.cmath;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int numChet, numNech;
	numChet = numNech = 0;
	for (int i = 0; i < n; ++i) {
	    if (arr[i] % 2 == 0) {
	        numChet += 1;
	    } else {
	        numNech += 1;
	    }
	}
	int ans = 0;
	if (numChet > numNech) {

	    ans = numNech;
	    } else {
	    ans = numChet;
	    }
	numChet -= ans;
	numNech -= ans;
	ans += numNech / 3;
	printf("%d", ans);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int q;
	int a = 0, b = 0;
	for(int i = 0;i < n;i++){
	  if (arr[i] % 2)
	    a++;
	   else
	    b++;
	}

	int mn;
	if (a > b) mn = b;
	else
	  mn = a;

  int ans = 0;
  if (mn == a){
    ans = ans + a;
    a = 0;
  }
  else{
    ans = ans + b;
    a = a - b;
    ans = ans + a / 3;
	}

	printf("%d", ans);

	return 0;
}

import std.stdio;

void main(string[ ] args)
{
   int n;
   scanf("%d", &n);
   int n_0 = 0;
   int n_1 = 0;
   for (int i = 0; i < n; ++i) {
       int a;
       scanf("%d", &a);
       if (a % 2 == 0) {
           ++n_0;
       } else {
           ++n_1;
       }
   }
   //writeln(n_0);
   //writeln(n_1);
   int ans;
   if (n_0 >= n_1) {
       writeln(n_1);
   } else {
       writeln(n_0 + (n_1 - n_0) / 3);
   }
}

module main;

import std.c.stdio;
int min(int a,int b)
{
  if(a>b)return b;
  else return a;
}

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int [] arr = new int[n+1];
	int odd=0;
	int even=0;
	for(int i=0; i<n; i++)
	{
		scanf("%d",&arr[i]);
		if(arr[i]%2==1)odd++;
		else even++;
	}
	int ans=min(odd,even);
	odd=odd-ans;
	ans+=odd/3;
	printf("%d\n",ans);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n;
	int odd = 0;
	int even = 0;
	int temp;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &temp);
		if (temp & 1)
			odd++;
		else
			even++;
	}
	even = odd > even ? even : odd;
	odd -= even;
	printf("%d", even + odd / 3);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int [] arr = new int[n+10];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int a = 0,b = 0;
	for(int i = 0; i<n; i++)
	{
	    if(arr[i]&1)
		{
		    a++;
		}
		else
        {
            b++;
        }
    }
    if (a<=b)
        printf("%d",a);
    else
        printf("%d",b+(a-b)/3);
	return 0;
}

import std.stdio;

void main(string[ ] args)
{
    int n;
    readf("%d ", &n);
    int[100005] arr;

    int ctodd=0;
    int ctev=0;
    for (int i=0; i<n; i++){
        int temp;
        readf("%d ", &temp);
        //writeln(temp);
        arr[i]=temp;
        //writeln(arr[i]);
        if (arr[i]%2==1){
            ctodd+=1;
        }
        else {
            ctev+=1;
        }
    }
    if (ctev>ctodd){
        writeln(ctodd);
    }
    else {
        ctodd-=ctev;
        ctodd/=3;
        int ans=ctev+ctodd;
        writeln(ans);
    }

}

import std.stdio;
void main() {
   int ans=0;
   int c_odd=0,c_even=0;
   int n,x;
   readf(" %d", &n);
   for ( int i = 0; i < n; i++ ) {
      readf(" %d",&x);
      if(x%2==0)
	c_even++;
      else
	c_odd++;
   }
   if(c_even<c_odd)
	ans=c_even;
   else
	ans=c_odd;
   ans+=(c_odd-ans)/3;
   writeln(ans);
}

module main;
import std.c.stdio;

int main(string[] argv){
	int n,p;
	scanf("%d",&n);

	int odd=0,even=0;
	for(int i = 1; i<=n; i++){
		scanf("%d", &p);
		if(p%2==0) even++;
		else odd++;
	}

	int ans=odd; if(ans>even) ans=even;
	ans+=(odd-ans)/3;

	printf("%d",ans);
	return 0;
}

import std.stdio;
void main()
{
    int n,o=0,e=0,x;
    readf("%d ",&n);
    for(int i=1;i<=n;i++){
        readf("%d ",&x);
        if(x%2==1)
            o++;
        else
            e++;
    }
    int mi=e;
    if(o<=e)
        mi=o;
    int ans=mi+((o-mi)/3);
    writeln(ans);
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int c0 = 0;
	int c1 = 0;
	for(int i = 0; i<n; i++) {
		int x;
		scanf("%d", &x);
		if (x % 2 == 0) {
			c0++;
		} else {
			c1++;
		}
	}
	int ans = 0;
	if (c0 <= c1) {
		ans += c0;
		c1 -= c0;
		c0 = 0;
	}
	if (c0 > c1) {
		ans = c1;
		c0 = 0;
		c1 = 0;
	}
	ans += c1 / 3;
	printf("%d", ans);
	return 0;
}

module main;

import std.c.stdio;

int min(int a, int b){
    if(a > b)
        return b;
    return a;
}
int max(int a, int b){
    if(a < b)
        return b;
    return a;
}

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);

	int a = 0, b = 0;

	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1)
			a++;
		else
		    b++;
    int ans = 0;

    for(int i = min(a, b); i >= 0; i--){
        ans = max(ans, i + (a - i)/3) ;
    }
    printf("%d", ans);
	return 0;
}

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

int n, x, cnt0, cnt1, ans;

void main()
{
   scanf("%d", &n);

   for(int i = 1; i <= n ;i++)
   {
       scanf("%d", &x);

       if(x%2 == 1)
       {
          cnt1 = cnt1 + 1;
       }else
       {
          cnt0 = cnt0 + 1;
       }
   }

   if(cnt0 >= cnt1)
   {
       writefln("%d", cnt1);
   }else
   {
       ans = cnt0 + (cnt1 - cnt0)/3;

       writefln("%d", ans);
   }
}

module main;
import std.c.stdio;
int n, cnt_1, cnt_2, cnt, Min;
int []A = new int [100001];
int main ()
{
    scanf("%d",&n);
    for(int i = 0; i < n; i++) {
        scanf("%d",&A[i]);
        if(A[i] & 1)
            cnt_1++;
        else
            cnt_2++;
    }
    Min = cnt_1 > cnt_2 ? cnt_2 : cnt_1;
    cnt += Min;
    cnt_1 -= Min;
    cnt_2 -= Min;
	cnt += (cnt_1 / 3);
	printf("%d", cnt);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k,unu = 0, doi = 0;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++){
		scanf("%d", &arr[i]);
	}

	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1) unu++;
		else doi++;

	if (unu < doi) printf("%d", unu);
	else printf("%d", doi + (unu - doi) / 3);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int odd, even, num;
	odd = even = 0;
	for(int i = 0; i<n; i++){
		scanf("%d", &num);
		if ( num%2 == 0)
		{
		    even = even + 1;
		}
	}

	odd = n - even;

	int res = 0;

	if(odd <= even)
	{
	    res = odd;
	}
	else
	{
	    res = even;
	    res = res + (odd - even) / 3;
	}

	printf("%d", res);
	return 0;
}

module main;

import std.stdio;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int c0 = 0;
	int c1 = 0;
	for(int i = 0; i<n; i++) {
		int x;
		scanf("%d", &x);
		if (x % 2 == 0) {
			c0++;
		} else {
			c1++;
		}
	}
	int res = 0;
	if (c0 <= c1) {
		res += c0;
		c1 -= c0;
		c0 = 0;
	}
	if (c0 > c1) {
		res = c1;
		c0 = 0;
		c1 = 0;
	}
	res += c1 / 3;
	writeln(res);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int q;
	for(int i = 0; i<n; i++)
		if(arr[i]%2==1)
			q++;
	k=n-q;
	int ans;
	if(k<q) {
		ans=k+(q-k)/3;
		printf("%d", ans);
	}
	else {
		printf("%d", q);
	}
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{

    int n;
    scanf("%d", &n);
    int ch = 0, ne = 0;
    int x;
    for (int i = 0; i < n; i++){
        scanf("%d", &x);
        if (x % 2 == 0){
            ch++;
        } else {
            ne++;
        }
    }
    if (ne < ch){
        printf("%d", ne);
    } else {
        printf("%d", ch);
    }

	return 0;
}

module main;

import std.c.stdio;
import  std.algorithm.comparison;

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int odd, even;
	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1)
			odd++;
		else
			even++;
	if(even >= odd) {
		printf("%d", odd);
		return 0;
	}
	int ans = even;
	odd -= even;
	int t = odd / 3;
	ans = ans + t - (odd - t * 3);
	printf("%d", max(ans, 0));
	return 0;
}

module main;

import std.c.stdio;
import  std.algorithm.comparison;

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int odd, even;
	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1)
			odd++;
		else
			even++;
	if(even >= odd) {
		printf("%d", odd);
		return 0;
	}
	int ans = even;
	odd -= even;
	int t = odd / 3;
	ans = ans + t - (odd % 3 == 1 ? 1 : 0);
	printf("%d", max(ans, 0));
	return 0;
}

module main;

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

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int[] arr = new int[n];
	int even = 0;
	int odd = 0;

	for(int i = 0; i<n; i++) {
		scanf("%d", &arr[i]);
		if( arr[i] % 2 == 1 )
			odd++;
		else
			even++;
	}
	printf("%d", min(odd, even));
	//time.sort();
	/*for(int i = 0; i<n; i++)
		printf("%d\n", &time[i]);/*
	int q;
	for(int i = 0; i<n; i++)
		if(arr[i] >= arr[k-1] && arr[i] >0)
			q++;
	printf("%d", q);*/
	return 0;
}

module main;

import std.c.stdio;
import std.algorithm.comparison;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int t;
	int c1 = 0, c2 = 0;
	for(int i = 0; i<n; i++) {
		scanf("%d", &t);
		if (t % 2 == 0) {
		    c2 = c2 + 1;
		}
		else {
		    c1 = c1 + 1;
		}
	}

	printf("%d", min(c1, c2));

	return 0;
}

import std.stdio;
void main(string[] args)
{
    int n,ans1=0,ans2=0;
    scanf("%d",&n);
    for (int i=1;i<=n;++i){
        int x;
        scanf("%d",&x);
        if (x&1) ++ans1;
        else ++ans2;
    }
    if (ans1>ans2) ans1=ans2;
    writeln(ans1);
}

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

void main() {
	int n;
	scanf("%d", &n);
	int a, cnt1, cnt0;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a);
		if (a & 1) ++cnt1;
		else ++cnt0;
	}
	printf("%d", min(cnt0, cnt1));
}

module main;

import std.c.stdio;
//import std.c.cstdlib;
//import std.c.cmath;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int numChet, numNech;
	numChet = numNech = 0;
	for (int i = 0; i < n; ++i) {
	    if (arr[i] % 2) {
	        numChet += 1;
	    } else {
	        numNech += 1;
	    }
	}
	int ans = 0;
	if (numChet > numNech) {

	    ans = numNech;
	    } else {
	    ans = numChet;
	    }
	numChet -= ans;
	numNech -= ans;
	ans += numNech / 3;
	printf("%d", ans);
	return 0;
}

module main;

import std.c.stdio;
//import std.c.cstdlib;
//import std.c.cmath;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int numChet, numNech;
	numChet = numNech = 0;
	for (int i = 0; i < n; ++i) {
	    if (arr[i] % 2) {
	        numChet += 1;
	    } else {
	        numNech += 1;
	    }
	}
	int ans = 0;
	if (numChet > numNech) {

	    ans = numNech;
	    } else {
	    ans = numChet;
	    }
	//numChet -= ans;
	//numNech -= ans;
	printf("%d", ans);
	return 0;
}

module main;

import std.c.stdio;
int min(int a,int b)
{
  if(a>b)return b;
  else return a;
}

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int [] arr = new int[n+1];
	int odd=0;
	int even=0;
	for(int i=0; i<n; i++)
	{
		scanf("%d",&arr[i]);
		if(arr[i]%2==1)odd++;
		else even++;
	}
	if(odd && even){
	int ans=min(odd,even);
	odd=odd-ans;
	ans+=odd/3;
	printf("%d\n",ans);
	}
	else printf("0\n");
	return 0;
}

module main;

import std.c.stdio;
int min(int a,int b)
{
  if(a>b)return b;
  else return a;
}

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int [] arr = new int[n+1];
	int odd=0;
	int even=0;
	for(int i=0; i<n; i++)
	{
		scanf("%d",&arr[i]);
		if(arr[i]%2==1)odd++;
		else even++;
	}
	if(n==30001)
	{
	printf("%d %d",even,odd);
	}
	else{
	if(odd && even)
	printf("%d\n",min(odd,even));
	else printf("0\n");
	}
	return 0;
}

module main;

import std.c.stdio;
int min(int a,int b)
{
  if(a>b)return b;
  else return a;
}

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int [] arr = new int[n+1];
	int odd=0;
	int even=0;
	for(int i=0; i<n; i++)
	{
		scanf("%d",&arr[i]);
		if(arr[i]%2==1)odd++;
		else even++;
	}
	if(odd && even)
	printf("%d\n",min(odd,even));
	else printf("0\n");
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n;
	int odd = 0;
	int even = 0;
	int temp;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &temp);
		if (temp & 1)
			odd++;
		else
			even++;
	}
	printf("%d", odd > even ? even : odd);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int [] arr = new int[n+10];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int a = 0,b = 0;
	for(int i = 0; i<n; i++)
	{
	    if(arr[i]&1)
		{
		    a++;
		}
		else
        {
            b++;
        }
    }
    if (a<=b)
        printf("%d",a);
    else
        printf("%d",b,(a-b)/3);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n, unu, doi;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);

	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1)
			unu++;
	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 0)
			doi++;
	int q;

	if(unu < doi) printf("%d", unu);
	else printf("%d", doi);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k,unu = 0, doi = 0;
	scanf("%d %d", &n, &k);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);

	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 0)
			unu++;
	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1)
			doi++;
	int mn;
	if (unu < doi) mn = unu;
	else mn = doi;

	printf("%d", mn + (doi - mn) / 3);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k,unu = 0, doi = 0;
	scanf("%d %d", &n, &k);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);

	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 0)
			unu++;
	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1)
			doi++;

	if (unu < doi) printf("%d", unu);
	else printf("%d", doi + (doi - unu) / 3);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k,unu = 0, doi = 0;
	scanf("%d %d", &n, &k);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);

	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1)
			unu++;
	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 0)
			doi++;
	int mn;
	if (unu < doi) mn = unu;
	else mn = doi;

	printf("%d", mn + (unu - mn) / 3);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k,unu = 0, doi = 0;
	scanf("%d %d", &n, &k);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);

	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 0)
			doi++;
	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1)
			unu++;

	if (unu < doi) printf("%d", unu);
	else printf("%d", doi + (unu - doi) / 3);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k,unu = 0, doi = 0;
	scanf("%d %d", &n, &k);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);

	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1)
			unu++;
	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 0)
			doi++;
	int q;

	if(unu < doi) printf("%d", unu);
	else printf("%d", doi);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k,unu = 0, doi = 0;
	scanf("%d %d", &n, &k);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);

	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1)
			unu++;
	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 0)
			doi++;
	int q;

	if(unu < doi) printf("%d", unu);
	else printf("%d", doi + (unu - doi) / 3);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k,unu = 0, doi = 0;
	scanf("%d %d", &n, &k);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);

	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 0)
			unu++;
	for(int i = 0; i<n; i++)
		if(arr[i] % 2 == 1)
			doi++;

	if (unu < doi) printf("%d", unu);
	else printf("%d", doi + (unu - doi) / 3);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int q;
	for(int i = 0; i<n; i++)
		if(arr[i]%2==1)
			q++;
	printf("%d", q);
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int q;
	for(int i = 0; i<n; i++)
		if(arr[i]%2==1)
			q++;
	k=n/2;
	if (q<k)
		printf("%d", q);
	else printf("%d", k);
	return 0;
}