Student Dima from Kremland has a matrix $$$a$$$ of size $$$n \times m$$$ filled with non-negative integers.He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!Formally, he wants to choose an integers sequence $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \leq c_j \leq m$$$) so that the inequality $$$a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$$$ holds, where $$$a_{i, j}$$$ is the matrix element from the $$$i$$$-th row and the $$$j$$$-th column.Here $$$x \oplus y$$$ denotes the bitwise XOR operation of integers $$$x$$$ and $$$y$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 500$$$) — the number of rows and the number of columns in the matrix $$$a$$$. Each of the next $$$n$$$ lines contains $$$m$$$ integers: the $$$j$$$-th integer in the $$$i$$$-th line is the $$$j$$$-th element of the $$$i$$$-th row of the matrix $$$a$$$, i.e. $$$a_{i, j}$$$ ($$$0 \leq a_{i, j} \leq 1023$$$).

If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE". Otherwise print "TAK" in the first line, in the next line print $$$n$$$ integers $$$c_1, c_2, \ldots c_n$$$ ($$$1 \leq c_j \leq m$$$), so that the inequality $$$a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$$$ holds.  If there is more than one possible answer, you may output any.

NoteIn the first example, all the numbers in the matrix are $$$0$$$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.In the second example, the selected numbers are $$$7$$$ (the first number in the first line) and $$$10$$$ (the third number in the second line), $$$7 \oplus 10 = 13$$$, $$$13$$$ is more than $$$0$$$, so the answer is found.

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

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto A = H.iota.map!(_ => readln.split.map!(to!int).array).array;

    auto x = A.map!(a => a.front).reduce!"a ^ b";
    int r = -1, c = -1;

    if (x == 0) {
        outer: foreach (i; 0..H) {
            foreach (j; 1..W) {
                if (A[i][j] != A[i][0]) {
                    r = i;
                    c = j;
                    break outer;
                }
            }
        }
        if (r == -1) {
            writeln("NIE");
            return;
        }
    }

    writeln("TAK");
    H.iota.map!(i => i == r ? c + 1 : 1).map!(to!string).join(" ").writeln;
}

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

int[500][500] IS;
int[10][500] BS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (i; 0..N) {
        int[10] ds;
        foreach (j, n; readln.split.to!(int[])) {
            IS[i][j] = n;
            foreach (d; 0..10) {
                auto x = (n>>d)&1;
                if (!j) {
                    ds[d] = x;
                } else if (ds[d] != x) {
                    ds[d] = 2;
                }
            }
        }
        BS[i] = ds;
    }
    int targ_d = -1, one_cnt;
    foreach (d; 0..10) {
        one_cnt = 0;
        foreach (i; 0..N) {
            if (BS[i][d] == 2) {
                targ_d = d;
            } else if (BS[i][d] == 1) {
                ++one_cnt;
            }
        }
        if (one_cnt%2 == 1) targ_d = d;
        if (targ_d != -1) break;
    }
    if (targ_d == -1) {
        writeln("NIE");
        return;
    }
    one_cnt = one_cnt%2 == 1 ? 0 : 1;
    int[] r;
    foreach (j, ns; IS[0..N]) {
        if (BS[j][targ_d] != 2) {
            r ~= 1;
        } else {
            foreach (int i, n; ns[0..M]) {
                auto x = (n>>targ_d)&1;
                if (one_cnt && x) {
                    --one_cnt;
                    r ~= i+1;
                    break;
                } else if (!one_cnt && !x) {
                    r ~= i+1;
                    break;
                }
            }
        }
    }
    writeln("TAK");
    writeln(r.to!(string[]).join(" "));
}

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 read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T read(T)(){ return read.to!T; }
T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }
T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){

	int n = read!int;
	int m = read!int;
	int[][] as = read!int(n, m);

	int i1 = 0, j1 = 0;
	bool f = 0;
A:
	foreach(i; 0 .. n){
		int[] q = as[i];
		foreach(j; 0 .. m){
			if(q[j] != q[0]){
				i1 = i;
				j1 = j;
				f = 1;
				break A;
			}
		}
	}

	int ansj = 0;
	int xor;
	foreach(i; 0 .. n) xor ^= as[i][0];
	if(xor == 0){
		if(j1 != 0) ansj = j1;
		else{
			"NIE".writeln;
			return;
		}
	}

	"TAK".writeln;
	int[] ans;
	foreach(i; 0 .. n) ans ~= 1;
	ans[i1] = ansj + 1;
	ans.map!(to!string).join(" ").writeln;

}

import std.stdio : writef, readf, readln, writeln, writefln, write;
import std.array : array, split;
import std.algorithm : sort, each, maxElement, minElement;
import std.conv : to;
import std.range : iota, tee, enumerate;
import std.algorithm.comparison : equal, max, min;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

void main() {
    GC.disable();

    uint n, m;

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

    auto a = new int[][n];
    uint saver = 100000000;
    uint x1 = 0;
    uint x2 = 0;
    uint pos2 = 0;
    uint pos1 = 0;
    bool flag = false;
    foreach (i; 0 .. n) {
        a[i] = new int[m];
        foreach (j; 0 .. m)
            readf(" %s", a[i][j]);

        auto ma = a[i].enumerate.maxElement!"a.value";
        auto mi = a[i].enumerate.minElement!"a.value";
        if (ma[1] != mi[1] && !flag) {
            saver = i;
            x1 ^= ma[1];
            x2 ^= mi[1];
            pos1 = ma[0];
            pos2 = mi[0];
            flag = true;
        }
        else {
            x1 ^= a[i][0];
            x2 ^= a[i][0];
        }
    }

    if (x1 == 0 && x2 == 0) {
        writeln("NIE");
    }
    else {
        writeln("TAK");
        foreach (i; 0 .. n) {
            if (i != saver)
                write(1, " ");
            else {
                if (x1 != 0)
                    write(pos1 + 1, " ");
                else if (x2 != 0)
                    write(pos2 + 1, " ");
            }
        }
        writeln();
    }
}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto N = RD!uint;
	auto M = RD!uint;
	auto a = new long[][](N);
	foreach (i; 0..N)
	{
		a[i] = RDR.ARR;
	}

	long x = a[0][0];
	foreach (i; 1..N)
	{
		x ^= a[i][0];
		debug writeln(x);
	}

	uint pos_i = N, pos_j;
	(){
	foreach (i; 0..N)
	{
		foreach (j; 1..M)
		{
			if (x != 0) return;
			x ^= a[i][j-1];
			x ^= a[i][j];
			pos_i = i;
			pos_j = j;
		}
	}}();

	if (x == 0)
		writeln("NIE");
	else
	{
		writeln("TAK");
		if (pos_i == 0)
			write(pos_j+1);
		else
			write(1);
		foreach (i; 1..N)
		{
			if (i == pos_i)
				write(" ", pos_j+1);
			else
				write(" ", 1);
		}
		writeln();
	}
	stdout.flush();
	debug readln();
}

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

int[500][500] IS;
int[10][500] BS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (i; 0..N) {
        int[10] ds;
        foreach (j, n; readln.split.to!(int[])) {
            IS[i][j] = n;
            foreach (d; 0..10) {
                auto x = (n>>d)&1;
                if (!j) {
                    ds[d] = x;
                } else if (ds[d] != x) {
                    ds[d] = 2;
                }
            }
        }
        BS[i] = ds;
    }
    int targ_d = -1, free_cnt, one_cnt;
    foreach (d; 0..10) {
        one_cnt = 0;
        foreach (i; 0..N) {
            if (BS[i][d] == 2) {
                targ_d = d;
                ++free_cnt;
            } else if (BS[i][d] == 1) {
                ++one_cnt;
            }
        }
        if (one_cnt%2 == 1) targ_d = d;
    }
    if (targ_d == -1) {
        writeln("NIE");
        return;
    }
    one_cnt = one_cnt%2 == 1 ? 0 : 1;
    int[] r;
    foreach (j, ns; IS[0..N]) {
        if (BS[j][targ_d] != 2) {
            r ~= 1;
        } else {
            foreach (int i, n; ns[0..M]) {
                auto x = (n>>targ_d)&1;
                if (one_cnt && x) {
                    --one_cnt;
                    r ~= i+1;
                } else if (!one_cnt && !x) {
                    r ~= i+1;
                }
            }
        }
    }
    writeln("TAK");
    writeln(r.to!(string[]).join(" "));
}

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

int[500][500] IS;
int[10][500] BS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (i; 0..N) {
        int[10] ds;
        foreach (j, n; readln.split.to!(int[])) {
            IS[i][j] = n;
            foreach (d; 0..10) {
                auto x = (n>>d)&1;
                if (!j) {
                    ds[d] = x;
                } else if (ds[d] != x) {
                    ds[d] = 2;
                }
            }
        }
        BS[i] = ds;
    }
    int targ_d = -1, free_cnt, one_cnt;
    foreach (d; 0..10) {
        one_cnt = 0;
        foreach (i; 0..N) {
            if (BS[i][d] == 2) {
                targ_d = d;
                ++free_cnt;
            } else if (BS[i][d] == 1) {
                ++one_cnt;
            }
        }
        if (one_cnt%2 == 1) targ_d = d;
        if (targ_d != -1) break;
    }
    if (targ_d == -1) {
        writeln("NIE");
        return;
    }
    one_cnt = one_cnt%2 == 1 ? 0 : 1;
    int[] r;
    foreach (j, ns; IS[0..N]) {
        if (BS[j][targ_d] != 2) {
            r ~= 1;
        } else {
            foreach (int i, n; ns[0..M]) {
                auto x = (n>>targ_d)&1;
                if (one_cnt && x) {
                    --one_cnt;
                    r ~= i+1;
                } else if (!one_cnt && !x) {
                    r ~= i+1;
                }
            }
        }
    }
    writeln("TAK");
    writeln(r.to!(string[]).join(" "));
}

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

int[500][500] IS;
int[10][500] BS;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    foreach (i; 0..N) {
        int[10] ds;
        foreach (j, n; readln.split.to!(int[])) {
            IS[i][j] = n;
            foreach (d; 0..10) {
                auto x = (n>>d)&1;
                if (!j) {
                    ds[d] = x;
                } else if (ds[d] != x) {
                    ds[d] = 2;
                }
            }
        }
        BS[i] = ds;
    }
    int targ_d = -1, targ_i, free_cnt, one_cnt;
    foreach (d; 0..10) {
        one_cnt = 0;
        foreach (i; 0..N) {
            if (BS[i][d] == 2) {
                targ_d = d;
                ++free_cnt;
            } else if (BS[i][d] == 1) {
                ++one_cnt;
            }
        }
        if (one_cnt%2 == 1) targ_d = d;
    }
    if (targ_d == -1) {
        writeln("NIE");
        return;
    }
    one_cnt = one_cnt%2 == 1 ? 0 : 1;
    int[] r;
    foreach (j, ns; IS[0..N]) {
        if (BS[j][targ_d] != 2) {
            r ~= 1;
        } else {
            foreach (int i, n; ns[0..M]) {
                auto x = (n>>targ_d)&1;
                if (one_cnt && x) {
                    --one_cnt;
                    r ~= i+1;
                } else if (!one_cnt && !x) {
                    r ~= i+1;
                }
            }
        }
    }
    writeln(r.to!(string[]).join(" "));
}

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 read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T read(T)(){ return read.to!T; }
T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }
T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){

	int n = read!int;
	int m = read!int;
	int[][] as = read!int(n, m);

	int i1, j1;
	bool f = 0;
A:
	foreach(i; 0 .. n){
		int[] q = as[i];
		foreach(j; 0 .. m){
			if(q[j] != q[0]){
				i1 = i;
				j1 = j;
				f = 1;
				break A;
			}
		}
	}
	if(! f){
		"NIE".writeln;
		return;
	}

	int xor;
	foreach(i; 0 .. n) xor ^= as[i][0];
	int ansj;
	if(xor != 0) ansj = 0; else ansj = j1;

	"TAK".writeln;
	int[] ans;
	foreach(i; 0 .. n) ans ~= 1;
	ans[i1] = ansj + 1;
	ans.map!(to!string).join(" ").writeln;

}

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 read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T read(T)(){ return read.to!T; }
T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }
T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){

	int n = read!int;
	int m = read!int;
	int[][] as = read!int(n, m);

	int i1, j1;
	bool f = 0;
A:
	foreach(i; 0 .. n){
		int[] q = as[i];
		foreach(j; 0 .. m){
			if(q[j] != q[0]){
				i1 = i;
				j1 = j;
				f = 1;
				break A;
			}
		}
	}
	if(! f){
		"NIE".writeln;
		return;
	}

	int xor;
	foreach(i; 0 .. n){
		if(i != i1) xor ^= as[i][0];
	}
	int ansj;
	if((xor ^ as[i1][0]) != 0) ansj = 0; else ansj = j1;

	"TAK".writeln;
	int[] ans;
	foreach(i; 0 .. n){
		if(i != i1) ans ~= 1;
		else ans ~= ansj + 1;
	}
	ans.map!(to!string).join(" ").writeln;

}

import std.stdio : writef, readf, readln, writeln, writefln, write;
import std.array : array, split;
import std.algorithm : sort, each, maxElement, minElement;
import std.conv : to;
import std.range : iota, tee, enumerate;
import std.algorithm.comparison : equal, max, min;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

void main() {
    GC.disable();

    uint n, m;

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

    auto a = new int[][n];
    uint saver = 100000000;

    uint x1 = 0;
    uint x2 = 0;
    bool flag = false;
    uint pos2 = 0;
    uint pos1 = 0;
    foreach (i; 0 .. n) {
        a[i] = new int[m];
        foreach (j; 0 .. m)
            readf(" %s", a[i][j]);

        auto ma = a[i].enumerate.maxElement!"a.value";
        auto mi = a[i].enumerate.minElement!"a.value";
        if (ma[1] != mi[1] && !flag) {
            saver = i;
            flag = true;
            x1 ^= ma[1];
            x2 ^= mi[1];
            pos1 = ma[0];
            pos2 = mi[0];
        }
        else {
            x1 ^= a[i][0];
            x2 ^= a[i][0];
        }
    }

    if (x1 == 0 && x2 == 0) {
        writeln("NIE");
    }
    else {
        writeln("TAK");
        foreach (i; 0 .. n) {
            if (i != saver)
                write(1, " ");
            else {
                if (x1 != 0)
                    write(pos1 + 1, " ");
                if (x2 != 0)
                    write(pos2 + 1, " ");
            }
        }
        writeln();
    }
}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto N = RD!uint;
	auto M = RD!uint;
	auto a = new long[][](N);
	foreach (i; 0..N)
	{
		a[i] = RDR.ARR;
	}

	long x = a[0][0];
	foreach (i; 1..N)
	{
		x ^= a[i][0];
		debug writeln(x);
	}

	uint pos_i = N, pos_j;
	(){
	foreach (j; 1..M)
	{
		foreach (i; 0..N)
		{
			if (x != 0) return;
			if (a[i][j] == a[i][j-1]) continue;
			x ^= a[i][j];
			pos_i = i;
			pos_j = j;
		}
	}}();

	if (x == 0)
		writeln("NIE");
	else
	{
		writeln("TAK");
		write(pos_j+1);
		foreach (i; 1..pos_i+1)
		{
			write(" ", pos_j+1);
		}
		foreach (i; pos_i+1..N)
		{
			write(" ", pos_j);
		}
		writeln();
	}
	stdout.flush();
	debug readln();
}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto N = RD!uint;
	auto M = RD!uint;
	auto a = new long[][](N);
	foreach (i; 0..N)
	{
		a[i] = RDR.ARR;
	}

	long x = a[0][0];
	foreach (i; 1..N)
	{
		x ^= a[i][0];
		debug writeln(x);
	}

	uint pos_i = N, pos_j;
	(){
	foreach (j; 1..M)
	{
		foreach (i; 0..N)
		{
			if (x != 0) return;
			x ^= a[i][j-1];
			x ^= a[i][j];
			pos_i = i;
			pos_j = j;
		}
	}}();

	if (x == 0)
		writeln("NIE");
	else
	{
		writeln("TAK");
		write(pos_j+1);
		foreach (i; 1..pos_i+1)
		{
			write(" ", pos_j+1);
		}
		foreach (i; pos_i+1..N)
		{
			write(" ", pos_j);
		}
		writeln();
	}
	stdout.flush();
	debug readln();
}


Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n × n matrix with a diamond inscribed into it.You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*". Look at the examples to understand what you need to draw.

The only line contains an integer n (3 ≤ n ≤ 101; n is odd).

***D***
**DDD**
*DDDDD*
DDDDDDD
*DDDDD*
**DDD**
***D***

import std.stdio;

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

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      int k = i;
      if (i > n/2){
        k = n - i -1;
      }
      if(j <= n/2+k && j >= n/2-k){
        write("D");
      } else {
        write("*");
      }
    }
    writeln();
  }
}

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

//	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, const T f) { if (t > f) t = f; }
void chmax(T)(ref T t, const T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	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)(S x, T y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(T[] as, 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)(T[] as, T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

int N;

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

		char[][] cs = new char[][](N, N);
		foreach (x; 0 .. N) foreach (y; 0 .. N) {
			cs[x][y] = (abs(x - N / 2) + abs(y - N / 2) <= N / 2) ? 'D' : '*';
		}
		foreach (x; 0 .. N) {
			writeln(cs[x].to!string);
		}
	}
	} catch (EOFException) {}
}


You are given a sequence of $$$n$$$ integers $$$a_1, \, a_2, \, \dots, \, a_n$$$.Does there exist a sequence of $$$n$$$ integers $$$b_1, \, b_2, \, \dots, \, b_n$$$ such that the following property holds?  For each $$$1 \le i \le n$$$, there exist two (not necessarily distinct) indices $$$j$$$ and $$$k$$$ ($$$1 \le j, \, k \le n$$$) such that $$$a_i = b_j - b_k$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10$$$). The second line of each test case contains the $$$n$$$ integers $$$a_1, \, \dots, \, a_n$$$ ($$$-10^5 \le a_i \le 10^5$$$).

For each test case, output a line containing YES if a sequence $$$b_1, \, \dots, \, b_n$$$ satisfying the required property exists, and NO otherwise.

NoteIn the first test case, the sequence $$$b = [-9, \, 2, \, 1, \, 3, \, -2]$$$ satisfies the property. Indeed, the following holds:   $$$a_1 = 4 = 2 - (-2) = b_2 - b_5$$$;  $$$a_2 = -7 = -9 - (-2) = b_1 - b_5$$$;  $$$a_3 = -1 = 1 - 2 = b_3 - b_2$$$;  $$$a_4 = 5 = 3 - (-2) = b_4 - b_5$$$;  $$$a_5 = 10 = 1 - (-9) = b_3 - b_1$$$. In the second test case, it is sufficient to choose $$$b = [0]$$$, since $$$a_1 = 0 = 0 - 0 = b_1 - b_1$$$.In the third test case, it is possible to show that no sequence $$$b$$$ of length $$$3$$$ satisfies the property.

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;

int N = 10000000 + 32;
int[] gdiffmap;

void update_diffmap(int[] b, int bs, int delta)
{
  int bj = b[bs - 1];
  int diffbase = N;
  int *diffmap = &gdiffmap[diffbase];
  foreach (bii ; 0 .. bs) {
    int bi = b[bii];
    diffmap[bi - bj] += delta;
    diffmap[bj - bi] += delta;
  }
}

bool solve(int[] a, int i, int[] b, int bs)
{
  int[] diffmap = gdiffmap;
  int diffbase = N;
  if (i == a.length)
    return false;

  update_diffmap(b, bs, 1);
  if (diffmap[diffbase + a[i]] > 0) {
    update_diffmap(b, bs, -1);
    return true;
  }

  foreach (bii ; 0 .. bs) {
    b[bs] = b[bii] + a[i];
    if (solve(a, i + 1, b, bs + 1)) {
      update_diffmap(b, bs, -1);
      return true;
    }
  }

  update_diffmap(b, bs, -1);
  return false;
}

void main()
{
  int t;
  readf!" %d "(t);
  gdiffmap = new int[](2 * N);
  while (t--) {
    int n;
    readf!" %d "(n);
    auto a = readln.strip.split.map!(to!int).array;
    auto b = new int[](n + 1);
    writeln(solve(a, 0, b, 1) ? "YES" : "NO");
  }
}

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

bool solve (int n, int [] a)
{
	auto m = 1 << n;

	for (int s = 0; s < m; s++)
	{
		int r = m - 1 - s;
		int t = r;
		do
		{
			int cur = 0;
			foreach (i; 0..n)
			{
				if (s & (1 << i))
				{
					cur += a[i];
				}
				if (t & (1 << i))
				{
					cur -= a[i];
				}
			}
			if (cur == 0 && !(s == 0 && t == 0))
			{
				return true;
			}

			t = (t - 1) & r;
		}
		while (t != r);
	}

	return false;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		writeln (solve (n, a) ? "YES" : "NO");
	}
}

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

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

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

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

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

        bool ans;
        void dfs(int i, bool any, int sum) {
          ans = ans || (any && sum == 0);
          if (i == N) {
            return;
          }
          dfs(i + 1, any, sum);
          dfs(i + 1, true, sum + A[i]);
          dfs(i + 1, true, sum - A[i]);
        }

        dfs(0, false, 0);
        writeln(ans ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}


Recently, Polycarp completed $$$n$$$ successive tasks.For each completed task, the time $$$s_i$$$ is known when it was given, no two tasks were given at the same time. Also given is the time $$$f_i$$$ when the task was completed. For each task, there is an unknown value $$$d_i$$$ ($$$d_i>0$$$) — duration of task execution.It is known that the tasks were completed in the order in which they came. Polycarp performed the tasks as follows:  As soon as the very first task came, Polycarp immediately began to carry it out.  If a new task arrived before Polycarp finished the previous one, he put the new task at the end of the queue.  When Polycarp finished executing the next task and the queue was not empty, he immediately took a new task from the head of the queue (if the queue is empty — he just waited for the next task). Find $$$d_i$$$ (duration) of each task.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The descriptions of the input data sets follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). The second line of each test case contains exactly $$$n$$$ integers $$$s_1 < s_2 < \dots < s_n$$$ ($$$0 \le s_i \le 10^9$$$). The third line of each test case contains exactly $$$n$$$ integers $$$f_1 < f_2 < \dots < f_n$$$ ($$$s_i < f_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each of $$$t$$$ test cases print $$$n$$$ positive integers $$$d_1, d_2, \dots, d_n$$$ — the duration of each task.

NoteFirst test case:The queue is empty at the beginning: $$$[ ]$$$. And that's where the first task comes in. At time $$$2$$$, Polycarp finishes doing the first task, so the duration of the first task is $$$2$$$. The queue is empty so Polycarp is just waiting.At time $$$3$$$, the second task arrives. And at time $$$7$$$, the third task arrives, and now the queue looks like this: $$$[7]$$$.At the time $$$10$$$, Polycarp finishes doing the second task, as a result, the duration of the second task is $$$7$$$.And at time $$$10$$$, Polycarp immediately starts doing the third task and finishes at time $$$11$$$. As a result, the duration of the third task is $$$1$$$.    An example of the first test case.

void main() { runSolver(); }

void problem() {
  auto QN = scan!int;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto A = scan!long(N);
      auto B = scan!long(N);

      long[] ans;
      long last;
      foreach(i; 0..N) {
        long start = max(last, A[i]);
        last = B[i];
        ans ~= last - start;
      }

      return ans.toAnswerString;
    }

    foreach(i; 0..QN) {
      subSolve().writeln;
    }
  }

  outputForAtCoder(&solve);
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

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


Vasya came up with a password to register for EatForces — a string $$$s$$$. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits.But since EatForces takes care of the security of its users, user passwords must contain at least one digit, at least one uppercase Latin letter and at least one lowercase Latin letter. For example, the passwords "abaCABA12", "Z7q" and "3R24m" are valid, and the passwords "qwerty", "qwerty12345" and "Password" are not. A substring of string $$$s$$$ is a string $$$x = s_l s_{l + 1} \dots s_{l + len - 1} (1 \le l \le |s|, 0 \le len \le |s| - l + 1)$$$. $$$len$$$ is the length of the substring. Note that the empty string is also considered a substring of $$$s$$$, it has the length $$$0$$$.Vasya's password, however, may come too weak for the security settings of EatForces. He likes his password, so he wants to replace some its substring with another string of the same length in order to satisfy the above conditions. This operation should be performed exactly once, and the chosen string should have the minimal possible length.Note that the length of $$$s$$$ should not change after the replacement of the substring, and the string itself should contain only lowercase and uppercase Latin letters and digits.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of testcases. Each of the next $$$T$$$ lines contains the initial password $$$s~(3 \le |s| \le 100)$$$, consisting of lowercase and uppercase Latin letters and digits. Only $$$T = 1$$$ is allowed for hacks.

For each testcase print a renewed password, which corresponds to given conditions.  The length of the replaced substring is calculated as following: write down all the changed positions. If there are none, then the length is $$$0$$$. Otherwise the length is the difference between the first and the last changed position plus one. For example, the length of the changed substring between the passwords "abcdef" $$$\rightarrow$$$ "a7cdEf" is $$$4$$$, because the changed positions are $$$2$$$ and $$$5$$$, thus $$$(5 - 2) + 1 = 4$$$. It is guaranteed that such a password always exists. If there are several suitable passwords — output any of them.

NoteIn the first example Vasya's password lacks a digit, he replaces substring "C" with "4" and gets password "abcD4E". That means, he changed the substring of length 1.In the second example Vasya's password is ok from the beginning, and nothing has to be changed. That is the same as replacing the empty substring with another empty substring (length 0).

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

  int t; rd(t);
  while(t--){
    auto s=readln.chomp.to!(char[]);
    int d=0, l=0, u=0;
    foreach(c; s){
      if('0'<=c && c<='9') d++;
      if('a'<=c && c<='z') l++;
      if('A'<=c && c<='Z') u++;
    }
    if(d>0 && l>0 && u>0){
      writeln(s);
      continue;
    }
    if(d==0){
      foreach(i; 0..s.length){
        auto c=s[i];
        if('a'<=c && c<='z' && l>1){
          s[i]='0';
          break;
        }
        if('A'<=c && c<='Z' && u>1){
          s[i]='0';
          break;
        }
      }
    }
    if(l==0){
      foreach(i; 0..s.length){
        auto c=s[i];
        if('0'<=c && c<='9' && d>1){
          s[i]='a';
          break;
        }
        if('A'<=c && c<='Z' && u>1){
          s[i]='a';
          break;
        }
      }
    }
    if(u==0){
      foreach(i; 0..s.length){
        auto c=s[i];
        if('0'<=c && c<='9' && d>1){
          s[i]='A';
          break;
        }
        if('a'<=c && c<='z' && l>1){
          s[i]='A';
          break;
        }
      }
    }
    writeln(s);
  }

}

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


The only difference between this problem and the hard version is the maximum number of questions.This is an interactive problem.There is a hidden integer $$$1 \le x \le n$$$ which you have to find. In order to find it you can ask at most $$$\mathbf{82}$$$ questions.In each question you can choose a non-empty integer set $$$S$$$ and ask if $$$x$$$ belongs to $$$S$$$ or not, after each question, if $$$x$$$ belongs to $$$S$$$, you'll receive "YES", otherwise "NO".But the problem is that not all answers are necessarily true (some of them are joking), it's just guaranteed that for each two consecutive questions, at least one of them is answered correctly.Additionally to the questions, you can make at most $$$2$$$ guesses for the answer $$$x$$$. Each time you make a guess, if you guess $$$x$$$ correctly, you receive ":)" and your program should terminate, otherwise you'll receive ":(".As a part of the joking, we will not fix the value of $$$x$$$ in the beginning. Instead, it can change throughout the interaction as long as all the previous responses are valid as described above.Note that your answer guesses are always answered correctly. If you ask a question before and after a guess, at least one of these two questions is answered correctly, as normal.

The only line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the maximum possible value of $$$x$$$.

NoteIf the answer of the first question were correct, then $$$x$$$ would have been equal to $$$6$$$, but as we can see in the first guess, $$$6$$$ is not the answer.So the answer of the first question is joking. As we know, the answer of at least one of our two questions is correct, since the answer of the first question was joking, the answer of the second question should be correct.So we will understand that $$$x$$$ is not equal to $$$1, 2, 3$$$ or $$$4$$$, and we also knew that $$$x$$$ is not equal to $$$6$$$ either. Hence $$$x$$$ should be equal to $$$5$$$.

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

bool ask (int [] a)
{
	writefln !("? %s %(%s %)") (a.length, a);
	stdout.flush ();
	return (readln.strip == "YES");
}

bool answer (int x)
{
	writefln !("! %s") (x);
	stdout.flush ();
	return (readln.strip == ":)");
}

void solve3 (int [] a)
{
	auto res1 = ask (a[0..1]);
	if (!res1)
	{
		res1 = ask (a[0..1]);
	}
	if (res1)
	{
		auto res2 = answer (a[0]);
		if (!res2)
		{
			auto res3 = ask (a[1..2]);
			answer (res3 ? a[1] : a[2]);
		}
	}
	else
	{
		auto res2 = answer (a[1]);
		if (!res2)
		{
			answer (a[2]);
		}
	}
}

void solve (int n)
{
	auto a = iota (1, n + 1).array;
	while (a.length > 3)
	{
		int [] [] p;
		foreach (i; 0..4)
		{
			p ~= a[$ * i / 4..$ * (i + 1) / 4];
		}
		int mask = 0;
		mask = mask * 2 + ask (p[0] ~ p[1]);
		mask = mask * 2 + ask (p[0] ~ p[2]);

		a = null;
		foreach (i; 0..4)
		{
			if (i != mask)
			{
				a ~= p[i];
			}
		}
		debug {stderr.writeln (a);}
	}
	solve3 (a);
}

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		solve (n);
	}
}

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

bool ask (int [] a)
{
	writefln !("? %s %(%s %)") (a.length, a);
	stdout.flush ();
	return (readln.strip == "YES");
}

bool answer (int x)
{
	writefln !("! %s") (x);
	stdout.flush ();
	return (readln.strip == ":)");
}

void solve3 (int [] a)
{
	auto res1 = ask (a[0..1]);
	if (!res1)
	{
		res1 = ask (a[0..1]);
	}
	if (res1)
	{
		auto res2 = answer (a[0]);
		if (!res2)
		{
			auto res3 = ask (a[1..2]);
			answer (res3 ? a[1] : a[2]);
		}
	}
	else
	{
		auto res2 = answer (a[1]);
		if (!res2)
		{
			answer (a[2]);
		}
	}
}

void solve (int n)
{
	auto a = iota (1, n + 1).array;
	while (a.length > 3)
	{
		int [] [] p;
		foreach (i; 0..4)
		{
			p ~= a[$ * i / 4..$ * (i + 1) / 4];
		}
		int mask = 0;
		mask = mask * 2 + ask (p[0] ~ p[2]);
		mask = mask * 2 + ask (p[0] ~ p[1]);

		a = null;
		foreach (i; 0..4)
		{
			if (i != mask)
			{
				a ~= p[i];
			}
		}
		debug {stderr.writeln (a);}
	}
	solve3 (a);
}

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		solve (n);
	}
}


Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that:  $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$.  Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct) — the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.

For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ — its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.

NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$:  $$$[3,2]$$$ which gives us $$$|3-2|=1$$$.  $$$[3,1]$$$ which gives us $$$|3-1|=2$$$.  $$$[2,1]$$$ which gives us $$$|2-1|=1$$$.  $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.

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(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 modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto p = RDA!int;
		ans[ti] ~= p[0];
		foreach (i; 1..n-1)
		{
			if (sgn(p[i-1] - p[i]) != sgn(p[i] - p[i+1]))
			{
				ans[ti] ~= p[i];
			}
		}
		ans[ti] ~= p[$-1];
	}

	foreach (e; ans)
	{
		writeln(e.length);
		e.map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}


Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split!Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space).The little walrus's text looks in the following manner: TEXT ::= SENTENCE | SENTENCE SPACE TEXTSENTENCE ::= WORD SPACE SENTENCE | WORD ENDEND ::= {'.', '?', '!'}WORD ::= LETTER | LETTER WORDLETTER ::= {'a'..'z', 'A'..'Z'}SPACE ::= ' 'SPACE stands for the symbol of a space.So, how many messages did Fangy send?

The first line contains an integer n, which is the size of one message (2 ≤ n ≤ 255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty.

On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes.

NoteLet's take a look at the third sample. The text will be split into three messages: "Hello!", "Do you like fish?" and "Why?".

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

void main()
{
	int n;
	loop:while(read(&n))
	{
		auto a=readln.strip.splitter(regex("[.?!]+")).map!(a => a.length+1).array[0..$-1];
		debug writeln(a);
		int pos=0,len,ans;
		while(pos<a.length)
		{
			len=a[pos];
			if(pos!=0)len--;
			if(len>n)
			{
				writeln("Impossible");
				continue loop;
			}
			while(pos<a.length-1 && len+a[pos+1]<=n)
			{
				pos++;
				len+=a[pos];
			}
			ans++;
			pos++;
		}
		writeln(ans);
	}

}

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

void main()
{
	auto n = readln().chomp().to!int();
	auto input = readln().chomp();
	int[] len;

	foreach (sentence; splitter(input, regex(r"[.!?][ ]?"))) {
		if (sentence.length) {
			len ~= sentence.length + 2;
		} else {
			len[0]--;
		}
	}
	len ~= 0;

	auto cnt = 1;
	for (int i = 0; i < len.length - 1; i++) {
		if (len[i] > n) {
			cnt = 0;
			break;
		}
		if (len[i] + len[i+1] > n) {
			len[i+1]--;
			cnt++;
		}
		else len[i+1] += len[i];
	}

	if (cnt) writeln(cnt);
	else writeln("Impossible");
}

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

void main()
{
	int n;
	loop:while(read(&n))
	{
		auto a=readln.splitter(regex("[.?!\n]+")).map!(a => a.length+1).array;
		int pos=0,len,ans;
		while(pos<a.length)
		{
			len=a[pos];
			if(pos!=0)len--;
			if(len>n)
			{
				writeln("Impossible");
				continue loop;
			}
			while(pos<a.length-1 && len+a[pos+1]<=n)
			{
				pos++;
				len+=a[pos];
			}
			ans++;
			pos++;
		}
		writeln(ans);
	}

}

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

void main()
{
	int n;
	loop:while(read(&n))
	{
		auto a=readln.splitter(regex("[.?!\n]+")).map!(a => a.length+1).array;
		int pos=0,len,ans;
		while(pos<a.length)
		{
			len=a[pos];
			if(len>n)
			{
				writeln("Impossible");
				continue loop;
			}
			while(pos<a.length-1 && len+a[pos+1]+1<=n)
			{
				pos++;
				len+=a[pos]+1;
			}
			ans++;
			pos++;
		}
		writeln(ans);
	}

}

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

void main()
{
	auto n = readln().chomp().to!int();
	auto input = readln().chomp();
	int[] len;

	foreach (sentence; splitter(input, regex(r"[.!?][ ]?"))) {
		if (sentence.length) {
			len ~= sentence.length + 2;
		} else {
			len[$-1]--;
		}
	}
	len ~= 0;

	auto cnt = 1;
	for (int i = 0; i < len.length - 1; i++) {
		if (len[i] > n) {
			cnt = 0;
			break;
		}
		if (len[i] + len[i+1] > n) cnt++;
		else len[i+1] += len[i];
	}

	if (cnt) writeln(cnt);
	else writeln("Impossible");
}


The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help.A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers b1, b2, ..., bm (m ≤ n). All numbers from the message and from the key belong to the interval from 0 to c - 1, inclusive, and all the calculations are performed modulo c.Encryption is performed in n - m + 1 steps. On the first step we add to each number a1, a2, ..., am a corresponding number b1, b2, ..., bm. On the second step we add to each number a2, a3, ..., am + 1 (changed on the previous step) a corresponding number b1, b2, ..., bm. And so on: on step number i we add to each number ai, ai + 1, ..., ai + m - 1 a corresponding number b1, b2, ..., bm. The result of the encryption is the sequence a1, a2, ..., an after n - m + 1 steps.Help the Beaver to write a program that will encrypt messages in the described manner.

The first input line contains three integers n, m and c, separated by single spaces.  The second input line contains n integers ai (0 ≤ ai < c), separated by single spaces — the original message.  The third input line contains m integers bi (0 ≤ bi < c), separated by single spaces — the encryption key. The input limitations for getting 30 points are:    1 ≤ m ≤ n ≤ 103  1 ≤ c ≤ 103  The input limitations for getting 100 points are:    1 ≤ m ≤ n ≤ 105  1 ≤ c ≤ 103

Print n space-separated integers — the result of encrypting the original message.

NoteIn the first sample the encryption is performed in two steps: after the first step a = (0, 0, 0, 1) (remember that the calculations are performed modulo 2), after the second step a = (0, 1, 1, 0), and that is the answer.

module main;

import std.stdio, std.string;

void solve(int[] a, int[] b, int c)
{
    int n = a.length, m = b.length;
    foreach (i; 0 .. n - m + 1)
    {
        foreach (j; 0 .. m)
        {
            a[i + j] += b[j];
            if (a[i + j] >= c)
            {
                a[i + j] -= c;
            }
        }
    }
    foreach (i; 0 .. n)
    {
        writef("%d ", a[i]);
    }
    writeln();
}

int main(string[] args)
{
    int n, m, c;
    while (scanf("%d%d%d", &n, &m, &c) == 3)
    {
        auto a = new int[n];
        auto b = new int[m];
        foreach (ref val; a)
        {
            scanf("%d", &val);
        }
        foreach (ref val; b)
        {
            scanf("%d", &val);
        }
        solve(a, b, c);
    }
    return 0;
}


There is a prison that can be represented as a rectangular matrix with $$$n$$$ rows and $$$m$$$ columns. Therefore, there are $$$n \cdot m$$$ prison cells. There are also $$$n \cdot m$$$ prisoners, one in each prison cell. Let's denote the cell in the $$$i$$$-th row and the $$$j$$$-th column as $$$(i, j)$$$.There's a secret tunnel in the cell $$$(r, c)$$$, that the prisoners will use to escape! However, to avoid the risk of getting caught, they will escape at night.Before the night, every prisoner is in his own cell. When night comes, they can start moving to adjacent cells. Formally, in one second, a prisoner located in cell $$$(i, j)$$$ can move to cells $$$( i - 1 , j )$$$ , $$$( i + 1 , j )$$$ , $$$( i , j - 1 )$$$ , or $$$( i , j + 1 )$$$, as long as the target cell is inside the prison. They can also choose to stay in cell $$$(i, j)$$$.The prisoners want to know the minimum number of seconds needed so that every prisoner can arrive to cell $$$( r , c )$$$ if they move optimally. Note that there can be any number of prisoners in the same cell at the same time.

The first line contains an integer $$$t$$$ $$$(1 \le t \le 10^4)$$$, the number of test cases. Each of the next $$$t$$$ lines contains four space-separated integers $$$n$$$, $$$m$$$, $$$r$$$, $$$c$$$ ($$$1 \le r \le n \le 10^9$$$, $$$1 \le c \le m \le 10^9$$$).

Print $$$t$$$ lines, the answers for each test case.

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 int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		auto r = RD!int;
		auto c = RD!int;

		ans[ti].chmax(r-1 + c-1);
		ans[ti].chmax(n-r + m-c);
		ans[ti].chmax(r-1 + m-c);
		ans[ti].chmax(n-r + c-1);
	}

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


Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).

The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$) — the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.

Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.

NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.

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

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto i = readNums!ulong;
  auto x = i[0];
  auto y = i[1];
  auto z = i[2];

  auto buy = (x / z) + (y / z);

  x %= z;
  y %= z;

  ulong give;
  if(x + y >= z){
    give = min(z - x, z - y);
    buy += (x + y) / z;
  }

  writeln(buy, " ", give);
}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm : sort, each, maxElement, minElement;
import std.conv : to;
import std.range : iota, tee, enumerate;
import std.algorithm.comparison : equal, max, min;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;
import std.math;

alias Tree = RBT!int;
alias ll = long;

void main() {
  GC.disable();

  long x, y, z;
  readf(" %s %s %s", x, y, z);

  long tt = 0;
  tt += x / z;
  tt += y / z;
  long rx = x % z;
  long ry = y % z;
  long ex = 0;

  if (rx + ry >= z) {
    ex = z - max(rx, ry);
    tt++;
  }

  writef("%s %s\n", tt, ex);
}

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

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  int[] i = readNums!int;
  int x = i[0];
  int y = i[1];
  int z = i[2];

  int buy = (x + y) / z;

  x %= z;
  y %= z;

  int give;
  if(x + y >= z) give = min(x, y);

  writeln(buy, " ", give);
}

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

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  int[] i = readNums!int;
  int x = i[0];
  int y = i[1];
  int z = i[2];

  int buy = (x / z) + (y / z);

  x %= z;
  y %= z;

  int give;
  if(x + y >= z){
    give = min(x, y);
    buy += (x + y) / z;
  }

  writeln(buy, " ", give);
}


You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.

The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters.

On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters. If the answer consists of zero characters, output «-» (a minus sign).

NoteIn the first example strings a and b don't share any symbols, so the longest string that you can get is empty.In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.

import core.bitop;
import core.checkedint;
import core.simd;
import core.stdc.stdlib;
import core.stdc.string;
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.bitmanip;
import std.complex;
import std.container;
import std.conv;
import std.datetime;
import std.format;
import std.functional;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.regex;
import std.stdio;
import std.string;
import std.typecons;
import std.variant;

__gshared:

auto getAddrTuple() {
    return tuple();
}

auto getAddrTuple(T, U...)(ref T head, ref U tail) {
    return tuple(&head, getAddrTuple(tail).expand);
}

bool read(T...)(ref T vars) if (vars.length > 0) {
    return readf(' ' ~ replicate("%s ", vars.length), getAddrTuple(vars).expand) == vars.length;
}

T[ ] allocate(T)(size_t n) {
    return (cast(T*)malloc(n * T.sizeof))[0 .. n];
}

auto pairwise(R)(R range) if (isForwardRange!R) {
    return lockstep(range, dropOne(range));
}

char[100_001] _a, _b;
bool[100_000] used;

void main() {
    while (true) {
        version (LocalProject)
            memset(used.ptr, 0x00, used.sizeof);
        auto a = _a[ ];
        auto b = _b[ ];
        readln(a);
        if (a.empty)
            break;
        readln(b);
        a = a[0 .. $ - 1];
        b = b[0 .. $ - 1];
        const n = cast(int)a.length;
        const m = cast(int)b.length;
        //b[0 .. lb] ~ b[rb .. m]
        int la = 0, lb = 0, ra = n, rb = m;
        while (la < n && lb < m) {
            while (la < n && a[la] != b[lb])
                la++;
            if (la == n)
                break;
            used[la] = true;
            debug writeln("Left-using ", la);
            la++;
            lb++;
        }
        int lres = lb, rres = m;
        while (ra && rb) {
            ra--;
            rb--;
            int passed = 0;
            while (ra >= 0 && a[ra] != b[rb])
                if (used[ra--])
                    passed++;
            if (ra < 0)
                break;
            if (used[ra])
                passed++;
            debug writeln("Right-using ", ra);
            while (passed-- > 0 || lb > rb) {
                lb--;
                if (lb) {
                    while (a[--la] != b[lb]) { }
                    do
                        used[la--] = false;
                    while (a[la] != b[lb - 1]);
                    la++;
                } else
                    la = 0;
            }
            if (lb + m - rb > lres + m - rres) {
                lres = lb;
                rres = rb;
            }
        }
        if (!lres && rres == m)
            writeln('-');
        else
            writeln(b[0 .. lres], b[rres .. m]);
    }
}

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

void main()
{
	string a,b;
	loop:while((a=readln.strip)!="")
	{
		b=readln.strip;
		int[] p,s;
		s.length=p.length=b.length;
		p[]=int.max/4;
		s[]=int.min/4;
		int pos=0;
		for(int i=0;i<b.length && pos<a.length;i++)
		{
			while(pos<a.length && a[pos]!=b[i])pos++;
			if(pos==a.length)break;
			p[i]=pos++;
		}
		pos=a.length-1;
		for(int i=b.length-1;i>=0 && pos>=0;i--)
		{
			while(pos>=0 && a[pos]!=b[i])pos--;
			if(pos<0)break;
			s[i]=pos--;
		}
		debug writeln(p);
		debug writeln(s);
		int ans=p.countUntil!"a==int.max/4",p1=ans,p2=b.length;
		foreach_reverse(i;0..b.length)
		{
			if(s[i]==int.min/4)break;
			int h=lowb(p,s[i]);
			int l=b.length-i;
			l+=h;
			if(l>ans)
			{
				ans=l;
				p1=h;
				p2=i;
			}
		}
		debug writeln(ans);
		debug writeln(p1,' ',p2);
		if(ans==0)writeln('-');
		else if(ans>=b.length)writeln(b);
		else writeln(b[0..p1],b[p2..$]);
	}

}

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

void main()
{
	string a,b;
	loop:while((a=readln.strip)!="")
	{
		b=readln.strip;
		int[] p,s;
		s.length=p.length=b.length;
		p[]=int.max/4;
		s[]=int.min/4;
		int pos=0;
		for(int i=0;i<b.length && pos<a.length;i++)
		{
			while(pos<a.length && a[pos]!=b[i])pos++;
			if(pos==a.length)break;
			p[i]=pos++;
		}
		pos=a.length-1;
		for(int i=b.length-1;i>=0 && pos>=0;i--)
		{
			while(pos>=0 && a[pos]!=b[i])pos--;
			if(pos<0)break;
			s[i]=pos--;
		}
		debug writeln(p);
		debug writeln(s);
		int ans=p.countUntil!"a==int.max/4",p1=ans-1,p2=b.length;
		foreach_reverse(i;0..b.length)
		{
			if(s[i]==int.min/4)break;
			int h=lowb(p,s[i]);
			int l=b.length-i;
			l+=max(h-1,0);
			if(l>ans)
			{
				ans=l;
				p1=max(0,h-1);
				p2=i;
			}
		}
		debug writeln(ans);
		debug writeln(p1,' ',p2);
		if(ans==0)writeln('-');
		else writeln(b[0..p1+1],b[p2..$]);
	}

}

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

void main()
{
	string a,b;
	loop:while((a=readln.strip)!="")
	{
		b=readln.strip;
		int[] p,s;
		s.length=p.length=b.length;
		p[]=int.max/4;
		s[]=int.min/4;
		int pos=0;
		for(int i=0;i<b.length && pos<a.length;i++)
		{
			while(pos<a.length && a[pos]!=b[i])pos++;
			if(pos==a.length)break;
			p[i]=pos++;
		}
		pos=a.length-1;
		for(int i=b.length-1;i>=0 && pos>=0;i--)
		{
			while(pos>=0 && a[pos]!=b[i])pos--;
			if(pos<0)break;
			s[i]=pos--;
		}
		debug writeln(p);
		debug writeln(s);
		int ans=p.countUntil!"a==int.max/4",p1=ans-1,p2=b.length;
		foreach_reverse(i;0..b.length)
		{
			if(s[i]==int.min/4)break;
			int h=lowb(p,s[i]);
			int l=b.length-i;
			l+=max(h-1,0);
			if(l>ans)
			{
				ans=l;
				p1=h-1;
				p2=i;
			}
		}
		debug writeln(ans);
		debug writeln(p1,' ',p2);
		if(ans==0)writeln('-');
		else writeln(b[0..p1+1],b[p2..$]);
	}

}

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

void main()
{
	string a,b;
	loop:while((a=readln.strip)!="")
	{
		b=readln.strip;
		int[] p,s;
		s.length=p.length=b.length;
		p[]=int.max/4;
		s[]=int.min/4;
		int pos=0;
		for(int i=0;i<b.length && pos<a.length;i++)
		{
			while(pos<a.length && a[pos]!=b[i])pos++;
			if(pos==a.length)break;
			p[i]=pos++;
		}
		pos=a.length-1;
		for(int i=b.length-1;i>=0 && pos>=0;i--)
		{
			while(pos>=0 && a[pos]!=b[i])pos--;
			if(pos<0)break;
			s[i]=pos--;
		}
		debug writeln(p);
		debug writeln(s);
		int ans=p.countUntil!"a==int.max/4",p1=ans-1,p2=b.length;
		foreach_reverse(i;0..b.length)
		{
			if(s[i]==int.min/4)break;
			int h=lowb(p,s[i]);
			int l=b.length-i;
			l+=max(h-1,0);
			if(l>ans)
			{
				ans=l;
				p1=h-1;
				p2=i;
			}
		}
		debug writeln(ans);
		debug writeln(p1,' ',p2);
		if(ans==0)writeln('-');
		else if(ans>=b.length)writeln(b);
		else writeln(b[0..p1+1],b[p2..$]);
	}

}