Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for the contestants and wrote on each of them a unique id (integer from 1 to n). A gift i is characterized by integer ai — pleasantness of the gift. The pleasantness of the gift can be positive, negative or zero. Sponsors placed the gift 1 on the top of the tree. All the other gifts hung on a rope tied to some other gift so that each gift hung on the first gift, possibly with a sequence of ropes and another gifts. Formally, the gifts formed a rooted tree with n vertices.The prize-giving procedure goes in the following way: the participants come to the tree one after another, choose any of the remaining gifts and cut the rope this prize hang on. Note that all the ropes which were used to hang other prizes on the chosen one are not cut. So the contestant gets the chosen gift as well as the all the gifts that hang on it, possibly with a sequence of ropes and another gifts.Our friends, Chloe and Vladik, shared the first place on the olympiad and they will choose prizes at the same time! To keep themselves from fighting, they decided to choose two different gifts so that the sets of the gifts that hang on them with a sequence of ropes and another gifts don't intersect. In other words, there shouldn't be any gift that hang both on the gift chosen by Chloe and on the gift chosen by Vladik. From all of the possible variants they will choose such pair of prizes that the sum of pleasantness of all the gifts that they will take after cutting the ropes is as large as possible.Print the maximum sum of pleasantness that Vladik and Chloe can get. If it is impossible for them to choose the gifts without fighting, print Impossible.

The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of gifts. The next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the pleasantness of the gifts. The next (n - 1) lines contain two numbers each. The i-th of these lines contains integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the description of the tree's edges. It means that gifts with numbers ui and vi are connected to each other with a rope. The gifts' ids in the description of the ropes can be given in arbirtary order: vi hangs on ui or ui hangs on vi.  It is guaranteed that all the gifts hang on the first gift, possibly with a sequence of ropes and another gifts.

If it is possible for Chloe and Vladik to choose prizes without fighting, print single integer — the maximum possible sum of pleasantness they can get together. Otherwise print Impossible.

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:

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

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

long result;

struct Node {
    int niceness;
    Node*[ ] children;

    Tuple!(long, long) recurse(const(Node)* prev) const {
        long max1 = long.min, max2 = long.min;
        long sum = niceness, curmax = long.min;
        foreach (node; children)
            if (node !is prev) {
                long nextSum, nextMax;
                AliasSeq!(nextSum, nextMax) = node.recurse(&this);
                sum += nextSum;
                curmax = max(curmax, nextMax);
                if (nextMax > max1) {
                    max2 = max1;
                    max1 = nextMax;
                } else if (nextMax > max2)
                    max2 = nextMax;
            }
        if (max2 != long.min)
            result = max(result, max1 + max2);
        return tuple(sum, max(sum, curmax));
    }
}

Node[200_000] _nodes;

void main() {
    int n;
    while (read(&n)) {
        auto nodes = _nodes[0 .. n];
        foreach (ref node; nodes) {
            read(&node.niceness);
            node.children = null;
        }
        foreach (i; 1 .. n) {
            int a, b;
            read(&a, &b);
            a--;
            b--;
            nodes[a].children ~= &nodes[b];
            nodes[b].children ~= &nodes[a];
        }
        result = long.min;
        nodes[0].recurse(null);
        if (result != long.min)
            writeln(result);
        else
            writeln("Impossible");
    }
}

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

void main()
{
	int n;

	while(input(&n))
	{
		readln;
		auto a=arread!int;
		auto g=new int[][n+1];
		foreach(i;0..n-1)
		{
			int u,v;
			input(&u,&v);
			g[u]~=v;
			g[v]~=u;
		}
		long[] s,d;
		s.length=d.length=n+1;
		fill(d,long.min);
		//d[0]=0;
		debug
		{
			foreach(i;g)
			{
				foreach(j;i)write(j,' ');
				writeln;
			}
		}
		void dfs1(int v,int pr)
		{
			s[v]+=a[v-1];
			foreach(i;g[v])
			{
				if(i!=pr)
				{
					dfs1(i,v);
					d[v]=max(d[v],d[i]);
					s[v]+=s[i];
				}
			}
			d[v]=max(d[v],s[v]);
		}

		dfs1(1,1);
		debug putarr(d);
		debug writeln;
		long ans=long.min;
		void dfs2(int v,int pr,long h)
		{
			if(h!=long.min) ans=max(ans,s[v]+h);
			pll m1=mp(long.min,-1L),m2=mp(long.min,-1L);
			foreach(i;g[v])
			{
				if(i==pr)continue;
				if(d[i]>m1.fi)
				{
					m2=m1;
					m1=mp(d[i],i*1L);
				}
				else if(d[i]>m2.fi)
				{
					m2=mp(d[i],i*1L);
				}
			}
			foreach(i;g[v])
			{
				if(i==pr)continue;
				long cur= (m1.se==i?m2.fi:m1.fi);
				dfs2(i,v,max(h,cur));
			}

		}
		dfs2(1,1,long.min);
		if(ans==long.min)writeln("Impossible");
		else writeln(ans);
	}
}

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

void main()
{
	int n;

	while(input(&n))
	{
		readln;
		auto a=arread!int;
		auto g=new int[][n+1];
		foreach(i;0..n-1)
		{
			int u,v;
			input(&u,&v);
			g[u]~=v;
			g[v]~=u;
		}
		auto f=fold!((a,b) => max(b.length,a))(g,0);
		if((f==2 && g[1].length<2) || n==1){writeln("Impossible");continue;}
		long[] s,d;
		s.length=d.length=n+1;
		fill(d,long.min);
		debug
		{
			foreach(i;g)
			{
				foreach(j;i)write(j,' ');
				writeln;
			}
		}
		void dfs1(int v,int pr)
		{
			s[v]+=a[v-1];
			foreach(i;g[v])
			{
				if(i!=pr)
				{
					dfs1(i,v);
					d[v]=max(d[v],d[i]);
					s[v]+=s[i];
				}
			}
			d[v]=max(d[v],s[v]);
		}

		dfs1(1,1);
		debug putarr(d);
		debug writeln;
		long ans=long.min;
		long dfs2(int v,int pr)
		{
			uint ans1,ans2;
			foreach(i;g[v])
			{
				if(i==pr)continue;
				if(d[i]>d[ans1]){ans2=ans1;ans1=i;}
				else if(d[i]>d[ans2])ans2=i;
			}
			debug writeln(d[ans1]);
			foreach(i;g[v])
			{
				if(i==pr )continue;
				if(i!=ans1)ans=max(ans,dfs2(i,v)+d[ans1]);
				else ans=max(ans,dfs2(i,v)+d[ans2]);
			}
			return d[ans1];
		}
		dfs2(1,1);
		writeln(ans);

	}
}


You have two strings $$$a$$$ and $$$b$$$ of equal length $$$n$$$ consisting of characters 0 and 1, and an integer $$$k$$$.You need to make strings $$$a$$$ and $$$b$$$ equal.In one step, you can choose any substring of $$$a$$$ containing exactly $$$k$$$ characters 1 (and arbitrary number of characters 0) and reverse it. Formally, if $$$a = a_1 a_2 \ldots a_n$$$, you can choose any integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$) such that there are exactly $$$k$$$ ones among characters $$$a_l, a_{l+1}, \ldots, a_r$$$, and set $$$a$$$ to $$$a_1 a_2 \ldots a_{l-1} a_r a_{r-1} \ldots a_l a_{r+1} a_{r+2} \ldots a_n$$$.Find a way to make $$$a$$$ equal to $$$b$$$ using at most $$$4n$$$ reversals of the above kind, or determine that such a way doesn't exist. The number of reversals doesn't have to be minimized.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2000$$$). Description of the test cases follows. Each test case consists of three lines. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2000$$$; $$$0 \le k \le n$$$). The second line contains string $$$a$$$ of length $$$n$$$. The third line contains string $$$b$$$ of the same length. Both strings consist of characters 0 and 1. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.

For each test case, if it's impossible to make $$$a$$$ equal to $$$b$$$ in at most $$$4n$$$ reversals, print a single integer $$$-1$$$. Otherwise, print an integer $$$m$$$ ($$$0 \le m \le 4n$$$), denoting the number of reversals in your sequence of steps, followed by $$$m$$$ pairs of integers $$$l_i, r_i$$$ ($$$1 \le l_i \le r_i \le n$$$), denoting the boundaries of the substrings of $$$a$$$ to be reversed, in chronological order. Each substring must contain exactly $$$k$$$ ones at the moment of reversal. Note that $$$m$$$ doesn't have to be minimized. If there are multiple answers, print any.

NoteIn the first test case, after the first reversal $$$a = $$$ 011010, after the second reversal $$$a = $$$ 010110, after the third reversal $$$a = $$$ 010101.

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

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

alias Op = Tuple!(int, "l", int, "r");
alias Result = Tuple!(string, "str", Op[], "ops");
Result solve(const(int) N, const(int) K, const(string) A) {
  auto cs = A.dup;
  Op[] ops;
  void rev(int l, int r) {
    for (int x = l, y = r - 1; x < y; ++x, --y) {
      swap(cs[x], cs[y]);
    }
    ops ~= Op(l, r);
    debug {
      // writeln(l, " ", r, " ", cs);
    }
  }

  const M = cast(int)(cs.count('1'));

  int xsLen;
  auto xs = new int[M];
  void getXs(int s) {
    xsLen = 0;
    foreach (x; s .. N) {
      if (cs[x] == '1') {
        xs[xsLen++] = x;
      }
    }
    xs[xsLen .. M] = -1;
  }

  if (K == 0 || K == N) {
    //
  } else {
    if (M < K) {
      //
    } else if (M == K) {
      getXs(0);
      auto ds = cs.dup;
      ds[xs[0] .. xs[K - 1] + 1].reverse;
      if (cs <= ds) {
        rev(xs[0], xs[K - 1] + 1);
        getXs(0);
        rev(0, xs[K - 1] + 1);
      } else {
        rev(0, xs[K - 1] + 1);
      }
    } else {
      foreach (i; 0 .. M - K) {
        getXs(i);
        rev(i, xs[K - 1] + 1);
      }
      if (K % 2 == 0) {
        foreach (_; 0 .. K) {
          getXs(M - K - 1);
          rev(xs[0], xs[K]);
          getXs(M - K - 1);
          rev(xs[0] + 1, xs[K] + 1);
        }
      } else {
        foreach (_; 0 .. K) {
          getXs(M - K - 1);
          rev(M - K - 1, xs[K - 1] + 1);
          rev(M - K, xs[K] + 1);
        }
      }
    }
  }
  debug {
    writeln("ret = ", cs, " ", ops);
  }
  return Result(cs.to!string, ops);
}

void main() {
  /*
  debug {
    foreach (n; 1 .. 8 + 1) {
      foreach (k; 1 .. n) {
        auto uf = new int[1 << n];
        uf[] = -1;
        foreach (p; 0 .. 1 << n) {
          foreach (i; 0 .. n + 1) foreach (j; i + 1 .. n + 1) {
            if (popcnt(p & ((1 << j) - (1 << i))) == k) {
              int pp = p;
              foreach (h; i .. j) {
                if (p & 1 << h) {
                  pp ^= 1 << h;
                  pp ^= 1 << (i + j - 1 - h);
                }
              }
              uf.connect(p, pp);
            }
          }
        }
        auto pss = new int[][1 << n];
        foreach (p; 0 .. 1 << n) {
          pss[uf.root(p)] ~= p;
        }
        writefln("n = %s, k = %s", n, k);
        foreach (h; 0 .. n + 1) {
          writeln("  ", h);
          foreach (r; 0 .. 1 << n) {
            if (uf[r] < 0 && popcnt(r) == h) {
              write("    ", -uf[r]);
              foreach (p; pss[r]) {
                write(" ");
                foreach (i; 0 .. n) {
                  write((p >> i) & 1);
                }
              }
              writeln;
            }
          }
        }
        writeln;
        stdout.flush;
      }
    }
  }
  */

  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const N = readInt();
        const K = readInt();
        const A = readToken();
        const B = readToken();

        const resA = solve(N, K, A);
        const resB = solve(N, K, B);
        if (resA.str == resB.str) {
          writeln(resA.ops.length + resB.ops.length);
          foreach (op; resA.ops) {
            writeln(op.l + 1, " ", op.r);
          }
          foreach_reverse (op; resB.ops) {
            writeln(op.l + 1, " ", op.r);
          }

          debug {
            auto cs = A.dup;
            writeln("! ", cs);
            foreach (op; resA.ops) {
              cs[op.l .. op.r].reverse;
              write("A ");
              foreach (i; 0 .. N) write((op.l <= i && i < op.r) ? '-' : ' ');
              writeln;
              writeln("! ", cs);
            }
            foreach_reverse (op; resB.ops) {
              cs[op.l .. op.r].reverse;
              write("B ");
              foreach (i; 0 .. N) write((op.l <= i && i < op.r) ? '-' : ' ');
              writeln;
              writeln("! ", cs);
            }
            assert(cs == B);
          }
        } else {
          writeln(-1);
        }
      }
    }
  } catch (EOFException e) {
  }
}

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

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

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

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

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

alias Op = Tuple!(int, "l", int, "r");
alias Result = Tuple!(string, "str", Op[], "ops");
Result solve(const(int) N, const(int) K, const(string) A) {
  auto cs = A.dup;
  Op[] ops;
  void rev(int l, int r) {
    for (int x = l, y = r - 1; x < y; ++x, --y) {
      swap(cs[x], cs[y]);
    }
    ops ~= Op(l, r);
    debug {
      // writeln(l, " ", r, " ", cs);
    }
  }

  const M = cast(int)(cs.count('1'));

  int xsLen;
  auto xs = new int[M];
  void getXs(int s) {
    xsLen = 0;
    foreach (x; s .. N) {
      if (cs[x] == '1') {
        xs[xsLen++] = x;
      }
    }
    xs[xsLen .. M] = -1;
  }

  if (K == 0 || K == N) {
    //
  } else {
    if (M < K) {
      //
    } else if (M == K) {
      getXs(0);
      auto ds = cs.dup;
      ds[xs[0] .. xs[K - 1] + 1].reverse;
      if (cs <= ds) {
        rev(xs[0], xs[K - 1] + 1);
        getXs(0);
        rev(0, xs[K - 1] + 1);
      } else {
        rev(0, xs[K - 1] + 1);
      }
    } else {
      foreach (i; 0 .. M - K) {
        getXs(i);
        rev(i, xs[K - 1] + 1);
      }
      if (K % 2 == 0) {
        foreach (_; 0 .. K) {
          getXs(M - K - 1);
          rev(M - K - 1, xs[K]);
          getXs(M - K - 1);
          rev(M - K, xs[K] + 1);
        }
      } else {
        foreach (_; 0 .. K) {
          getXs(M - K - 1);
          rev(M - K - 1, xs[K - 1] + 1);
          rev(M - K, xs[K] + 1);
        }
      }
    }
  }
  debug {
    writeln("ret = ", cs, " ", ops);
  }
  return Result(cs.to!string, ops);
}

void main() {
  /*
  debug {
    foreach (n; 1 .. 8 + 1) {
      foreach (k; 1 .. n) {
        auto uf = new int[1 << n];
        uf[] = -1;
        foreach (p; 0 .. 1 << n) {
          foreach (i; 0 .. n + 1) foreach (j; i + 1 .. n + 1) {
            if (popcnt(p & ((1 << j) - (1 << i))) == k) {
              int pp = p;
              foreach (h; i .. j) {
                if (p & 1 << h) {
                  pp ^= 1 << h;
                  pp ^= 1 << (i + j - 1 - h);
                }
              }
              uf.connect(p, pp);
            }
          }
        }
        auto pss = new int[][1 << n];
        foreach (p; 0 .. 1 << n) {
          pss[uf.root(p)] ~= p;
        }
        writefln("n = %s, k = %s", n, k);
        foreach (h; 0 .. n + 1) {
          writeln("  ", h);
          foreach (r; 0 .. 1 << n) {
            if (uf[r] < 0 && popcnt(r) == h) {
              write("    ", -uf[r]);
              foreach (p; pss[r]) {
                write(" ");
                foreach (i; 0 .. n) {
                  write((p >> i) & 1);
                }
              }
              writeln;
            }
          }
        }
        writeln;
        stdout.flush;
      }
    }
  }
  */

  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const N = readInt();
        const K = readInt();
        const A = readToken();
        const B = readToken();

        const resA = solve(N, K, A);
        const resB = solve(N, K, B);
        if (resA.str == resB.str) {
          writeln(resA.ops.length + resB.ops.length);
          foreach (op; resA.ops) {
            writeln(op.l + 1, " ", op.r);
          }
          foreach_reverse (op; resB.ops) {
            writeln(op.l + 1, " ", op.r);
          }
        } else {
          writeln(-1);
        }
      }
    }
  } catch (EOFException e) {
  }
}


Allen is hosting a formal dinner party. $$$2n$$$ people come to the event in $$$n$$$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $$$2n$$$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of pairs of people. The second line contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$. For each $$$i$$$ with $$$1 \le i \le n$$$, $$$i$$$ appears exactly twice. If $$$a_j = a_k = i$$$, that means that the $$$j$$$-th and $$$k$$$-th people in the line form a couple.

Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.

NoteIn the first sample case, we can transform $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$$$ in two steps. Note that the sequence $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$$$ also works in the same number of steps.The second sample case already satisfies the constraints; therefore we need $$$0$$$ swaps.

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;

		long res = 0;
		for (int i = 0; i < 2 * n; i += 2)
		{
			int j = i + 1;
			while (a[j] != a[i])
			{
				j += 1;
			}
			while (j > i + 1)
			{
				res += 1;
				swap (a[j], a[j - 1]);
				j -= 1;
			}
		}
		writeln (res);
	}
}

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 N = readInt();
      auto A = new int[2 * N];
      foreach (i; 0 .. 2 * N) {
        A[i] = readInt();
      }

      auto as = A.dup;
      int ans;
      for (int i = 0; i < 2 * N; i += 2) {
        foreach (j; i + 1 .. 2 * N) {
          if (as[i] == as[j]) {
            for (; i + 1 < j; --j) {
              swap(as[j], as[j - 1]);
              ++ans;
            }
            goto done;
          }
        }
        assert(false);
       done:
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

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

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

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

    auto ans = 0;

    foreach (p; a.length.iota.stride(2)) {
        auto k = a[p];
        debug { writeln(p, ' ', k, ' ', a[p+1..$]); }
        auto i = a.length - a[p+1..$].find(k).length;
        debug { i.writeln; }
        while (a[i-1] != k) {
            ++ans;
            a[i] = a[i-1];
            a[i-1] = k;
            --i;
        }
    }

    ans.writeln;
}


Optimizing the amount of data transmitted via a network is an important and interesting part of developing any network application.  In one secret game developed deep in the ZeptoLab company, the game universe consists of n levels, located in a circle. You can get from level i to levels i - 1 and i + 1, also you can get from level 1 to level n and vice versa. The map of the i-th level description size is ai bytes.In order to reduce the transmitted traffic, the game gets levels as follows. All the levels on the server are divided into m groups and each time a player finds himself on one of the levels of a certain group for the first time, the server sends all levels of the group to the game client as a single packet. Thus, when a player travels inside the levels of a single group, the application doesn't need any new information. Due to the technical limitations the packet can contain an arbitrary number of levels but their total size mustn't exceed b bytes, where b is some positive integer constant.Usual situation is that players finish levels one by one, that's why a decision was made to split n levels into m groups so that each group was a continuous segment containing multiple neighboring levels (also, the group can have two adjacent levels, n and 1). Specifically, if the descriptions of all levels have the total weight of at most b bytes, then they can all be united into one group to be sent in a single packet.Determine, what minimum number of groups do you need to make in order to organize the levels of the game observing the conditions above?As developing a game is a long process and technology never stagnates, it is yet impossible to predict exactly what value will take constant value b limiting the packet size when the game is out. That's why the developers ask you to find the answer for multiple values of b.

The first line contains two integers n, q (2 ≤ n ≤ 106, 1 ≤ q ≤ 50) — the number of levels in the game universe and the number of distinct values of b that you need to process. The second line contains n integers ai (1 ≤ ai ≤ 109) — the sizes of the levels in bytes. The next q lines contain integers bj (), determining the values of constant b, for which you need to determine the answer.

For each value of kj from the input print on a single line integer mj (1 ≤ mj ≤ n), determining the minimum number of groups to divide game levels into for transmission via network observing the given conditions.

NoteIn the test from the statement you can do in the following manner.  at b = 7 you can divide into two segments: 2|421|32 (note that one of the segments contains the fifth, sixth and first levels);  at b = 4 you can divide into four segments: 2|4|21|3|2;  at b = 6 you can divide into three segments: 24|21|32|.

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

immutable int INF = int.max / 2;

void main ()
{
	int n;
	int q;
	while (readf (" %s %s ", &n, &q) > 0)
	{
		auto a = readln ().split ().map !(to !(long)).array;
		int m = 3 * n + 2;
		a.reserve (m);
		while (a.length < m)
		{
			a ~= a[$ - n];
		}

		auto f = new int [m];

		int solve (long r)
		{
			f[] = INF;
			f[0] = 0;
			int res = INF;
			int i = 0;
			int j = 0;
			long cur = r;
			for (i = 0; i < m; i++)
			{
				while (j - i < n && j + 1 < m && cur >= a[j])
				{
					cur -= a[j];
					j++;
					f[j] = min (f[j], f[i] + 1);
				}
				cur += a[i];
			}
			for (j = 2 * n + 1; j < m; j++)
			{
				res = min (res, f[j] - f[j - n + 1] + 1);
			}
			debug {writeln (f);}
			return res;
		}

		foreach (k; 0..q)
		{
			long r;
			readf (" %s", &r);
			writeln (solve (r));
		}
	}
}


The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.

The first line contains integer n (2 ≤ n ≤ 300) — the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 300). It is guaranteed that at least one ai is positive.

Print the sequence that consists of k (1 ≤ k ≤ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.

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

void main() {
    int n = stdin.readln.chop.to!int;
    int[] a = stdin.readln.chop.split.map!(to!int).array;
    char prev = 'X';
    int c = 0;
    while (true) {
        if (a[c] > 0) {
            if (prev == 'P') {
                if (c == 0) {
                    write("RL");
                    prev = 'L';
                } else {
                    write("LR");
                    prev = 'R';
                }
            } else {
                a[c]--;
                write('P');
                prev = 'P';
            }
        } else {
            if (c == n - 1) {
                break;
            }
            write('R');
            prev = 'R';
            c++;
        }
    }
    write('\n');
}

import std.stdio, std.algorithm;

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

    auto a = new int[](n);

    foreach(i; 0..n) {
        readf(" %d", &a[i]);
    }

    int k = a.reduce!(max), ix;
    auto ans = new char[](k * 3 * n);
    foreach(i; 0..k) {
        foreach(j; 0..n) {
            if (a[j] > i) ans[ix++] = 'P';
            if (j < n-1) ans[ix++] = 'R';
        }
        foreach(j; 0..n) {
            if (j < n-1) ans[ix++] = 'L';
        }
    }

    writeln(ans[0..ix]);
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [n];
		foreach (ref x; a)
		{
			readf (" %s", &x);
		}
		string res;
		foreach (i, x; a)
		{
			foreach (j; 0..x)
			{
				res ~= 'P';
				if (j + 1 < x)
				{
					if (i == 0)
					{
						res ~= "RL";
					}
					else
					{
						res ~= "LR";
					}
				}
			}
			if (i + 1 < n)
			{
				res ~= 'R';
			}
		}
		writeln (res);
	}
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [n];
		foreach (ref x; a)
		{
			readf (" %s", &x);
		}
		string [] res;
		foreach (x; a)
		{
			string temp;
			foreach (i; 0..x)
			{
				temp ~= 'P';
			}
			res ~= temp;
		}
		writef ("%(%(%c%)R%)", res);
		break;
	}
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [n];
		foreach (ref x; a)
		{
			readf (" %s", &x);
		}
		string [] res;
		foreach (x; a)
		{
			string temp;
			foreach (i; 0..x)
			{
				temp ~= "P";
			}
			res ~= temp;
		}
		writefln ("%(%(%c%)R%)", res);
	}
}


You are given a sequence of positive integers x1, x2, ..., xn and two non-negative integers a and b. Your task is to transform a into b. To do that, you can perform the following moves:  subtract 1 from the current a;  subtract a mod xi (1 ≤ i ≤ n) from the current a. Operation a mod xi means taking the remainder after division of number a by number xi.Now you want to know the minimum number of moves needed to transform a into b.

The first line contains a single integer n (1 ≤  n ≤ 105). The second line contains n space-separated integers x1, x2, ..., xn (2 ≤  xi ≤ 109). The third line contains two integers a and b (0  ≤ b ≤  a ≤ 109, a - b ≤ 106).

Print a single integer — the required minimum number of moves needed to transform number a into number b.

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto x = new int [n];
		foreach (i; 0..n)
		{
			readf (" %s", &x[i]);
		}
		x = x.sort !("a < b", SwapStrategy.stable).uniq.array;
		int a, b;
		readf (" %s %s", &a, &b);

		int res = 0;
		while (a > b)
		{
			res++;
			int c = a - 1;
			int [] y;
			foreach (d; x)
			{
				int e = a - (a % d);
				if (e >= b)
				{
					y ~= d;
					c = min (c, e);
				}
			}
			a = c;
			x = y;
		}
		writeln (res);
	}
}

import std.algorithm, std.array, std.stdio;
void main ()
{
	int n, a, b;
	readf (" %s", &n);
	auto x = new int [n];
	foreach (i; 0..n)
		readf (" %s", &x[i]);
	x = x.sort.uniq.array;
	readf (" %s %s", &a, &b);
	int res = 0;
	while (a > b)
	{
		res++;
		int c = a - 1;
		int [] y;
		foreach (d; x)
		{
			int e = a - (a % d);
			if (e >= b)
			{
				y ~= d;
				c = min (c, e);
			}
		}
		a = c;
		x = y;
	}
	writeln (res);
}

import std.algorithm, std.array, std.stdio;
void main ()
{
	int n, a, b;
	scanf ("%d", &n);
	auto x = new int [n];
	foreach (i; 0..n)
		scanf ("%d", &x[i]);
	x = x.sort.uniq.array;
	scanf ("%d%d", &a, &b);
	int res = 0;
	while (a > b)
	{
		res++;
		int c = a - 1;
		int [] y;
		foreach (d; x)
		{
			int e = a - (a % d);
			if (e >= b)
			{
				y ~= d;
				c = min (c, e);
			}
		}
		a = c;
		x = y;
	}
	writeln (res);
}


We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not.

The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.

Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't.

NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".

import std.stdio;
import std.conv: parse;
import std.array: split, join;
import std.algorithm: map;
import std.string: chop;
import std.math: sqrt;
import std.parallelism: taskPool;

void main() {
    readln;
    readln.chop.split(" ").map!yesno.join("\n").writeln;
}
string yesno(string a) {
    auto n = sqrt(cast(real)a.parse!long);
    if(n == 1) return "NO";
    if(n % 1 == 0 && isPrime(cast(long)n)) return "YES";
    return "NO";
}
bool isPrime(long n) {
    foreach(i; 2..cast(long)sqrt(cast(real)n) + 1) if(n % i == 0) return false;
    return true;
}

import std.math;
import std.stdio;

import std.algorithm;
import std.stdio;

immutable int MAX_N = 1_000_000;

bool [] bool_primes (int n)
{
    auto a = new bool [n + 1];
    a[] = true;
    a[0] = a[1] = false;
    for (int i = 2; i * i <= n; i++)
        if (a[i])
            for (int j = i * i; j <= n; j += i)
                a[j] = false;
    return a;
}

void main ()
{
    bool [] p = bool_primes (MAX_N);

    int n;
    while (readf (" %s", &n) > 0)
    {
        foreach (i; 0..n)
        {
            long t;
            readf (" %s", &t);
            long s = cast (long) sqrt (cast (real) t);
            writef ("%s\n", t > 1 && s * s == t &&
                            p[cast (int) s] ? "YES" : "NO");
        }
    }
}

import std.math;
import std.stdio;

import std.algorithm;
import std.stdio;

immutable int MAX_N = 1_000_000;

bool [] bool_primes (int n)
{
    auto a = new bool [n + 1];
    a[] = true;
    a[0] = a[1] = false;
    for (int i = 2; i * i <= n; i++)
        if (a[i])
            for (int j = i * i; j <= n; j += i)
                a[j] = false;
    return a;
}

immutable bool [] p = bool_primes (MAX_N);

void main ()
{
    int n;
    while (readf (" %s", &n) > 0)
    {
        foreach (i; 0..n)
        {
            long t;
            readf (" %s", &t);
            long s = cast (long) sqrt (cast (real) t);
            writef ("%s\n", t > 1 && s * s == t &&
                            p[cast (int) s] ? "YES" : "NO");
        }
    }
}

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

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char rc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    sb ();
    int res = 0;
    do
    {
        res = res * 10 + cast (int) (curc - '0');
        curc = getchar ();
    }
    while (32 < curc);
    return res;
}

long nl ()
{
    sb ();
    long res = 0;
    do
    {
        res = res * 10 + cast (long) (curc - '0');
        curc = getchar ();
    }
    while (32 < curc);
    return res;
}

char[] ns ()
{
    sb ();
    char[] res = [];
    do
    {
        res ~= to!char(curc);
        curc = getchar ();
    }
    while (32 < curc);
    return res;
}

void CFBETA142B()
{
    auto n = ni();
    int[] LinearEratosphene(int N)
    {
        int[] lp = new int[N + 1];
        int[] pr = [];
        for (int i = 2; i <= N; ++i)
        {
            if (lp[i] == 0)
            {
                lp[i] = i;
                pr ~= i;
            }
            for (int j = 0; (j < pr.length) && (pr[j] <= lp[i]) && (i * pr[j] <= N); ++j)
                lp[i * pr[j]] = pr[j];
        }
        return lp;
    }
    int[1000001] lp = LinearEratosphene(1000000);
    for (int i=0; i<n; ++i)
    {
        long x = nl();
        long xsq = cast(long)sqrt(cast(float)x);
        if ((xsq*xsq==x)&&(lp[cast(uint)xsq]==xsq)) printf("YES\n");
        else printf("NO\n");
    }
}

void main()
{
    CFBETA142B();
}

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

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char rc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    sb ();
    int res = 0;
    do
    {
        res = res * 10 + cast (int) (curc - '0');
        curc = getchar ();
    }
    while (32 < curc);
    return res;
}

long nl ()
{
    sb ();
    long res = 0;
    do
    {
        res = res * 10 + cast (long) (curc - '0');
        curc = getchar ();
    }
    while (32 < curc);
    return res;
}

char[] ns ()
{
    sb ();
    char[] res = [];
    do
    {
        res ~= to!char(curc);
        curc = getchar ();
    }
    while (32 < curc);
    return res;
}

void CFBETA142B()
{
    auto n = ni();
    long[] x = new long[n];
    long m=0;
    for (int i=0; i<n; ++i){
        x[i] = nl();
        m = max(m,x[i]);
    }
    bool[long] st;
    bool[long] T;
    for (int i=0; i<n; ++i) st[x[i]]=true;
    long[] LinearEratosphene(int N)
    {
        long[] lp = new long[N + 1];
        int[] pr = [];
        for (int i = 2; i <= N; ++i)
        {
            if (lp[i] == 0)
            {
                lp[i] = i;
                pr ~= i;
            }
            for (int j = 0; (j < pr.length) && (pr[j] <= lp[i]) && (i * pr[j] <= N); ++j)
                lp[i * pr[j]] = pr[j];
        }
        return lp;
    }
    long[1000001] lp = LinearEratosphene(1000000);
    for (long i=2L;i<=1000000L;++i)
        if ((lp[cast(uint)i]==i) && (((i*i) in st) !is null)) T[i*i]=true;
    for (int i=0;i<n;++i)
    if ((x[i] in T) !is null) printf("YES\n"); else printf("NO\n");
}

void main()
{
    CFBETA142B();
}

import std.stdio, std.math;

bool isPrime(long number) {
	if (number < 2) {
		return false;
	}
	if (number > 2 && number % 2 == 0) {
		return false;
	}

	for (auto i = 3; i * i <= number; i += 2) {
		if (number % i == 0) {
			return false;
		}
	}

	return true;
}

void main() {
	int n;
	long number;

	readf("%d", &n);
	for (auto i = 0; i < n; ++i) {
		readf(" %d", &number);

		double sqrtNumber = sqrt(cast(double) number);
		if (sqrtNumber - cast(long)sqrtNumber > 0) {
			writeln("NO");
		} else {
			isPrime(cast(long) sqrtNumber)? writeln("YES"): writeln("NO");
		}
	}
}

import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable int mod = 10^^9 + 7;

void main()
{
    auto n = readln.chomp.to!int;
    auto x = readln.split.to!(long[]);

    auto primes = eratos(10^^6);

    foreach (xi ; x) {
        long v = nibutan(primes, xi);

        debug {
            writeln(v);
        }

        if (v^^2 == xi) {
            writeln("YES");
        }
        else {
            writeln("NO");
        }
    }
}

long nibutan(int[] primes, long xi)
{
    int btm = -1, top = primes.length.to!int, mid;

    while (top - btm > 1) {
        mid = btm + (top - btm) / 2;

        if (primes[mid] <= xi / primes[mid]) {
            btm = mid;
        }
        else {
            top = mid;
        }
    }

    return btm > -1 ? primes[btm] : 0;
}

int[] eratos(int n)
{
    bool[] s = new bool[](n);
    fill(s, true);
    s[0] = s[1] = false;

    for (int p = 2; p*p < n; ++p) {
        if (s[p]) {
            for (int q = p*p; q < n; q += p) {
                s[q] = false;
            }
        }
    }

    return iota(n).filter!(a => s[a]).array;
}

bool is_prime(long x) {
    if (x < 2) return false;

    for (int p = 2; p*p <= x; ++p) {
        if (x % p == 0) return false;
    }

    return true;
}

long root(long x) {
    long top = x, btm = 0, mid;

    while (top - btm > 1) {
        mid = btm + (top - btm) / 2;

        if (mid <= x/mid) {
            btm = mid;
        }
        else {
            top = mid;
        }
    }

    return btm;
}

void readVars(T...)(auto ref T args)
{
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        writeln(line);
        throw new Exception("args num < input num");
    }
}

import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable int mod = 10^^9 + 7;

void main()
{
    int n = readln.chomp.to!int;
    auto x = readln.chomp.split.to!(long[]);

    foreach(xi; x) {
        long rx = root(xi);

        debug {
            writeln(rx);
            writeln(is_prime(rx));
        }

        if(xi > 1 && (rx^^2 == xi) && is_prime(rx)){
            writeln("YES");
        }
        else {
            writeln("NO");
        }
    }
}

bool is_prime(long x) {
    if (x < 2) return false;

    for (int p = 2; p*p <= x; ++p) {
        if (x % p == 0) return false;
    }

    return true;
}

long root(long x) {
    long top = x, btm = 0, mid;

    while (top - btm > 1) {
        mid = btm + (top - btm) / 2;

        if (mid <= x/mid) {
            btm = mid;
        }
        else {
            top = mid;
        }
    }

    return btm;
}

void readVars(T...)(auto ref T args)
{
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        writeln(line);
        throw new Exception("args num < input num");
    }
}

import std.stdio;
import std.conv: parse;
import std.array: split, join;
import std.algorithm: map;
import std.string: chop;
import std.math: sqrt;

void main()
{
    readln;
    readln.chop.split(" ").map!yesno.join("\n").writeln;
}
string yesno(string a) {
    auto n = sqrt(cast(float)a.parse!int);
    if(n % 1 == 0 && isPrime(cast(int)n)) return "YES";
    return "NO";
}
bool isPrime(int n) {
    foreach(i; 2..n) if(n % i == 0) return false;
    return true;
}

import std.stdio;
import std.conv: parse;
import std.array: split, join;
import std.algorithm: map;
import std.string: chop;
import std.math: sqrt;

void main()
{
    readln;
    readln.chop.split(" ").map!yesno.join("\n").writeln;
}
string yesno(string a) {
    auto n = sqrt(cast(float)a.parse!long);
    if(n % 1 == 0 && isPrime(cast(int)n)) return "YES";
    return "NO";
}
bool isPrime(int n) {
    foreach(i; 2..n) if(n % i == 0) return false;
    return true;
}

import std.stdio;
import std.conv: parse;
import std.array: split, join;
import std.algorithm: map;
import std.string: chop;
import std.math: sqrt;

void main()
{
    readln;
    readln.chop.split(" ").map!yesno.join("\n").writeln;
}
string yesno(string a) {
    auto n = sqrt(cast(float)a.parse!long);
    if(n == 1) return "NO";
    if(n % 1 == 0 && isPrime(cast(int)n)) return "YES";
    return "NO";
}
bool isPrime(int n) {
    foreach(i; 2..n) if(n % i == 0) return false;
    return true;
}

import std.stdio;
import std.conv: parse;
import std.array: split, join;
import std.algorithm: map;
import std.string: chop;
import std.math: sqrt;

void main()
{
    readln;
    readln.chop.split(" ").map!yesno.join("\n").writeln;
}
string yesno(string a) {
    auto n = sqrt(cast(float)a.parse!int);
    if(n % 1 == 0 && isPrime(cast(int)n)) return "YES";
    return "NO";
}
bool isPrime(int n) {
    foreach(i; 2..n) if(n % i != 0) return false;
    return true;
}

import std.stdio;

bool [long] squares (int n)
{
    bool [long] res;
    foreach (i; 1..n + 1)
    {
        long s = i;
        s *= i;
        res[s] = true;
    }
    return res;
}

immutable bool [long] f;

void main ()
{
    int n;
    while (readf (" %s ", &n) > 0)
    {
        foreach (i; 0..n)
        {
            long t;
            readf (" %s ", &t);
            writef ("%s\n", t in f ? "YES" : "NO");
        }
    }
}

import std.math;
import std.stdio;

void main ()
{
    int n;
    while (readf (" %s", &n) > 0)
    {
        foreach (i; 0..n)
        {
            long t;
            readf (" %s", &t);
            long s = cast (long) sqrt (cast (real) t);
            writef ("%s\n", s * s == t ? "YES" : "NO");
        }
    }
}

import std.stdio;

bool [long] squares (int n)
{
    bool [long] res;
    foreach (i; 1..n + 1)
    {
        long s = i;
        s *= i;
        res[s] = true;
    }
    return res;
}

immutable bool [long] f;

void main ()
{
    int n;
    while (readf (" %s ", &n) > 0)
    {
        foreach (i; 0..n)
        {
            long t;
            readf (" %s ", &t);
            writef ("%s\n", f.get (t, false) ? "YES" : "NO");
        }
    }
}

import std.math;
import std.stdio;

void main ()
{
    int n;
    while (readf (" %s", &n) > 0)
    {
        foreach (i; 0..n)
        {
            long t;
            readf (" %s", &t);
            long s = cast (long) sqrt (cast (real) t);
            writef ("%s\n", t > 1 && s * s == t ? "YES" : "NO");
        }
    }
}

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

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char rc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    sb ();
    int res = 0;
    do
    {
        res = res * 10 + cast (int) (curc - '0');
        curc = getchar ();
    }
    while (32 < curc);
    return res;
}

long nl ()
{
    sb ();
    long res = 0;
    do
    {
        res = res * 10 + cast (long) (curc - '0');
        curc = getchar ();
    }
    while (32 < curc);
    return res;
}

char[] ns ()
{
    sb ();
    char[] res = [];
    do
    {
        res ~= to!char(curc);
        curc = getchar ();
    }
    while (32 < curc);
    return res;
}

void CFBETA142B()
{
    auto n = ni();
    long[] x = new long[n];
    long m=0;
    for (int i=0; i<n; ++i){
        x[i] = nl();
        m = max(m,x[i]);
    }
    bool[long] st;
    bool[long] T;
    for (int i=0; i<n; ++i) st[x[i]]=true;
    int[] LinearEratosphene(int N)
    {
        int[] lp = new int[N + 1];
        int[] pr = [];
        for (int i = 2; i <= N; ++i)
        {
            if (lp[i] == 0)
            {
                lp[i] = i;
                pr ~= i;
            }
            for (int j = 0; (j < pr.length) && (pr[j] <= lp[i]) && (i * pr[j] <= N); ++j)
                lp[i * pr[j]] = pr[j];
        }
        return lp;
    }
    int[1000001] lp = LinearEratosphene(1000000);
    long cnt=0;
    for (int i=2;i<=1000000;++i)
        if ((lp[i]==i) && (((i*i) in st) !is null)) T[i*i]=true;
    for (int i=0;i<n;++i)
    if ((x[i] in T) !is null) printf("YES\n"); else printf("NO\n");
}

void main()
{
    CFBETA142B();
}

import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable int mod = 10^^9 + 7;

void main()
{
    int n = readln.chomp.to!int;
    auto x = readln.chomp.split.to!(long[]);

    foreach(xi; x) {
        if(xi > 1 && (root(xi)^^2 == xi)){
            writeln("YES");
        }
        else {
            writeln("NO");
        }
    }
}

long root(long x) {
    long top = x, btm = 0, mid;

    while (top - btm > 1) {
        mid = btm + (top - btm) / 2;

        if (mid*mid <= x) {
            btm = mid;
        }
        else {
            top = mid;
        }
    }

    return btm;
}

void readVars(T...)(auto ref T args)
{
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        writeln(line);
        throw new Exception("args num < input num");
    }
}

import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable int mod = 10^^9 + 7;

void main()
{
    int n = readln.chomp.to!int;
    auto x = readln.chomp.split.to!(long[]);

    foreach(xi; x) {
        long rx = root(xi);

        if(xi > 1 && (rx^^2 == xi) && is_prime(rx)){
            writeln("YES");
        }
        else {
            writeln("NO");
        }
    }
}

bool is_prime(long x) {
    if (x < 2) return false;

    for (int p = 2; p*p <= x; ++p) {
        if (x % p == 0) return false;
    }

    return true;
}

long root(long x) {
    long top = x, btm = 0, mid;

    while (top - btm > 1) {
        mid = btm + (top - btm) / 2;

        if (mid*mid <= x) {
            btm = mid;
        }
        else {
            top = mid;
        }
    }

    return btm;
}

void readVars(T...)(auto ref T args)
{
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        writeln(line);
        throw new Exception("args num < input num");
    }
}


Vladimir would like to prepare a present for his wife: they have an anniversary! He decided to buy her exactly $$$n$$$ flowers.Vladimir went to a flower shop, and he was amazed to see that there are $$$m$$$ types of flowers being sold there, and there is unlimited supply of flowers of each type. Vladimir wants to choose flowers to maximize the happiness of his wife. He knows that after receiving the first flower of the $$$i$$$-th type happiness of his wife increases by $$$a_i$$$ and after receiving each consecutive flower of this type her happiness increases by $$$b_i$$$. That is, if among the chosen flowers there are $$$x_i > 0$$$ flowers of type $$$i$$$, his wife gets $$$a_i + (x_i - 1) \cdot b_i$$$ additional happiness (and if there are no flowers of type $$$i$$$, she gets nothing for this particular type).Please help Vladimir to choose exactly $$$n$$$ flowers to maximize the total happiness of his wife.

The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 10\,000$$$), the number of test cases. It is followed by $$$t$$$ descriptions of the test cases. Each test case description starts with two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le m \le 100\,000$$$), the number of flowers Vladimir needs to choose and the number of types of available flowers. The following $$$m$$$ lines describe the types of flowers: each line contains integers $$$a_i$$$ and $$$b_i$$$ ($$$0 \le a_i, b_i \le 10^9$$$) for $$$i$$$-th available type of flowers. The test cases are separated by a blank line. It is guaranteed that the sum of values $$$m$$$ among all test cases does not exceed $$$100\,000$$$.

For each test case output a single integer: the maximum total happiness of Vladimir's wife after choosing exactly $$$n$$$ flowers optimally.

NoteIn the first example case Vladimir can pick 1 flower of the first type and 3 flowers of the second type, in this case the total happiness equals $$$5 + (1 + 2 \cdot 4) = 14$$$.In the second example Vladimir can pick 2 flowers of the first type, 2 flowers of the second type, and 1 flower of the third type, in this case the total happiness equals $$$(5 + 1 \cdot 2) + (4 + 1 \cdot 2) + 3 = 16$$$.

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 n, m;
		readf !(" %s %s") (n, m);
		auto a = new int [m];
		auto b = new int [m];
		foreach (i; 0..m)
		{
			readf !(" %s %s") (a[i], b[i]);
		}

		auto c = a.dup;
		sort (c);
		reverse (c);
		auto s = [0L];
		foreach (ref cur; c)
		{
			s ~= s.back + cur;
		}
		c ~= -1;

		long res = s[min (n, m)];
		foreach (i; 0..m)
		{
			int limit = b[i];
			int lo = 0;
			int hi = m;
			while (lo < hi)
			{
				int me = (lo + hi) / 2;
				if (c[me] >= limit)
				{
					lo = me + 1;
				}
				else
				{
					hi = me;
				}
			}
			long cur = s[lo];
			long left = n - lo;
			if (a[i] < limit)
			{
				left -= 1;
				cur += a[i];
			}
			if (left >= 0)
			{
				cur += limit * left;
				res = max (res, cur);
			}
		}

		writeln (res);
	}
}

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 n, m;
		readf !(" %s %s") (n, m);
		auto a = new int [m];
		auto b = new int [m];
		foreach (i; 0..m)
		{
			readf !(" %s %s") (a[i], b[i]);
		}

		auto c = a.dup;
		sort (c);
		reverse (c);
		auto s = [0L];
		foreach (ref cur; c)
		{
			s ~= s.back + cur;
		}
		c ~= -1;

		long res = c[min (n, m)];
		foreach (i; 0..m)
		{
			int limit = b[i];
			int lo = 0;
			int hi = m;
			while (lo < hi)
			{
				int me = (lo + hi) / 2;
				if (c[me] >= limit)
				{
					lo = me + 1;
				}
				else
				{
					hi = me;
				}
			}
			long cur = s[lo];
			long left = n - lo;
			if (a[i] < limit)
			{
				left -= 1;
				cur += a[i];
			}
			if (left >= 0)
			{
				cur += limit * left;
				res = max (res, cur);
			}
		}

		writeln (res);
	}
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers.In one move, you can choose some index $$$i$$$ ($$$1 \le i \le n - 2$$$) and shift the segment $$$[a_i, a_{i + 1}, a_{i + 2}]$$$ cyclically to the right (i.e. replace the segment $$$[a_i, a_{i + 1}, a_{i + 2}]$$$ with $$$[a_{i + 2}, a_i, a_{i + 1}]$$$). Your task is to sort the initial array by no more than $$$n^2$$$ such operations or say that it is impossible to do that.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$3 \le n \le 500$$$) — the length of $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 500$$$), where $$$a_i$$$ is the $$$i$$$-th element $$$a$$$. It is guaranteed that the sum of $$$n$$$ does not exceed $$$500$$$.

For each test case, print the answer: -1 on the only line if it is impossible to sort the given array using operations described in the problem statement, or the number of operations $$$ans$$$ on the first line and $$$ans$$$ integers $$$idx_1, idx_2, \dots, idx_{ans}$$$ ($$$1 \le idx_i \le n - 2$$$), where $$$idx_i$$$ is the index of left border of the segment for the $$$i$$$-th operation. You should print indices in order of performing operations.

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)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		int [] res;

		void op (int pos)
		{
			swap (a[pos + 1], a[pos + 2]);
			swap (a[pos + 0], a[pos + 1]);
			res ~= pos + 1;
			debug {writeln (a);}
		}

		foreach (i; 0..n - 2)
		{
			auto v = minElement (a[i..$]);
			auto j = i;
			while (a[j] != v)
			{
				j += 1;
			}
			while (j > i + 1)
			{
				op (j - 2);
				j -= 2;
			}
			while (a[i] != v)
			{
				op (i);
				j = (j - i + 1) % 3 + i;
			}
		}

		if (!isSorted (a))
		{
			int j = 1;
			while (j < n && a[j - 1] < a[j])
			{
				j += 1;
			}
			if (j < n && a[j - 1] > a[j])
			{
				op (j - 2);
			}
			foreach (i; j - 1..n - 2)
			{
				op (i);
				op (i);
			}
		}

		if (isSorted (a))
		{
			writeln (res.length);
			writefln !("%(%s %)") (res);
		}
		else
		{
			writeln (-1);
		}
	}
}

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)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		int [] res;

		void op (int pos)
		{
//			writeln (pos);
			swap (a[pos + 1], a[pos + 2]);
			swap (a[pos + 0], a[pos + 1]);
			res ~= pos + 1;
			writeln (a);
		}

		foreach (i; 0..n - 2)
		{
			auto v = minElement (a[i..$]);
			auto j = i;
			while (a[j] != v)
			{
				j += 1;
			}
			while (j > i + 1)
			{
				op (j - 2);
				j -= 2;
			}
			while (a[i] != v)
			{
				op (i);
				j = (j - i + 1) % 3 + i;
			}
		}

		if (!isSorted (a))
		{
			int j = 1;
			while (j < n && a[j - 1] < a[j])
			{
				j += 1;
			}
			if (j < n && a[j - 1] > a[j])
			{
				op (j - 2);
			}
			foreach (i; j - 1..n - 2)
			{
				op (i);
				op (i);
			}
		}

		if (isSorted (a))
		{
			writeln (res.length);
			writefln !("%(%s %)") (res);
		}
		else
		{
			writeln (-1);
		}
	}
}


Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:   Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).  For any two indices i and j (i < j), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.

The input contains a single integer: n (1 ≤ n ≤ 105).

Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one.

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

void main() {
    int n; readf("%d", &n);
    writef("%d", 10000000 - n);
    for (int i = 10000000 - n + 1; i < 10000000; i++) {
        writef(" %d", i);
    }
    writeln;
}

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

void main() {
    auto N = readln.chomp.to!int;
    foreach (i; 0..N) write(i + 5000001, " ");
    writeln;
}


Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once.

First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks.

For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).

6
7
abacaba
7
???????
11
aba?abacaba
11
abacaba?aba
15
asdf???f???qwer
11
abacabacaba

Yes
abacaba
Yes
abacaba
Yes
abadabacaba
Yes
abacabadaba
No
No

NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring.

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

immutable string pattern = "abacaba";

void main ()
{
	auto tests = readln.strip.to !(int);
multitest_loop:
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto s = readln.strip;
		auto t = s.dup;
		foreach (ref c; t)
		{
			if (c == '?')
			{
				c = 'z';
			}
		}
		foreach (start; 0..n - 6)
		{
			if (zip (s[start..start + 7], pattern).any
			    !(p => p[0] != '?' && p[0] != p[1]))
			{
				continue;
			}
			auto r = t.dup;
			r[start..start + 7] = pattern;
			if (r.find (pattern).drop (1).find (pattern).empty)
			{
				writeln ("YES");
				writeln (r);
				continue multitest_loop;
			}
		}
		writeln ("NO");
	}
}

import std.container: DList;
DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  int t;
  read(t);
 testCase:while(t--)
    {
      int n;
      string istr;
      read(n);
      read(istr);
      enum wantedString = "abacaba";
      for(size_t i = 0; i + wantedString.length - 1 < istr.length; i++)
        {
          char[] str = istr.dup;
          import std.algorithm: all, map, count, min;
          import std.range: iota;
          import std.array: array;
          if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))
            {
              str[i .. i + wantedString.length] = wantedString[];
              auto appearances = iota(0, str.length).count!(k => str[k .. min(k + wantedString.length, $)] == wantedString[]);
              assert(appearances >= 1);
              if (appearances == 1)
                {
                  import std.utf;
                  str = str.map!(c => c == '?'? 'z' : c).array.toUTF8.dup;
                  import std.stdio;
                  writeln("Yes");
                  writeln(str.idup);
                  continue testCase;
                }
            }
        }
      import std.stdio;
      writeln("No");
    }
}

import std.container: DList;
import std.algorithm: all, map, count;
import std.range: iota;
import std.array: array;
import std.stdio;
import std.utf;

DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  enum T = "abacaba";
  int t;
  read(t);
 testCase:while(t--)
    {
      int n;
      string istr;
      read(n);
      read(istr);
      char[] str = istr.dup;
      for(size_t i = 0; i + T.length - 1 < istr.length; i++)
        {
          if (iota(0, T.length).all!(j => str[i + j] == '?' || str[i + j] == T[j]))
            {
              auto saved = str[i .. i + T.length].dup;
              str[i .. i + T.length] = T[];
              if (iota(0, str.length - T.length + 1).all!(k => k == i || str[k .. k + T.length] != T[]))
                {
                  str = str.map!(c => c == '?'? 'z' : c).array.toUTF8.dup;
                  writeln("Yes");
                  writeln(str.idup);
                  continue testCase;
                }
              str[i .. i + T.length] = saved;
            }
        }
      writeln("No");
    }
}

import std.container: DList;
DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  int t;
  read(t);
 testCase:while(t--)
    {
      int n;
      string istr;
      read(n);
      read(istr);
      enum wantedString = "abacaba";
      for(size_t i = 0; i + wantedString.length - 1 < istr.length; i++)
        {
          char[] str = istr.dup;
          import std.algorithm: all, map, count, min;
          import std.range: iota;
          import std.array: array;
          if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))
            {
              str[i .. i + wantedString.length] = wantedString[];
              import std.utf;
              str = str.map!(c => c == '?'? 'z' : c).array.toUTF8.dup;
              auto appearances = iota(0, str.length).count!(k => str[k .. min(k + wantedString.length, $)] == wantedString[]);
              assert(appearances >= 1);
              if (appearances == 1)
                {
                  import std.stdio;
                  writeln("Yes");
                  writeln(str.idup);
                  continue testCase;
                }
            }
        }
      import std.stdio;
      writeln("No");
    }
}

import std.container: DList;
import std.algorithm: all, map, count, filter;
import std.range: iota;
import std.array: array;
import std.stdio;
import std.utf;

DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  enum T = "abacaba";
  int t;
  read(t);
 testCase:while(t--)
    {
      int n;
      string istr;
      read(n);
      read(istr);
      char[] str = istr.dup;
      for(size_t i = 0; i + T.length - 1 < istr.length; i++)
        {
          if (iota(0, T.length).all!(j => str[i + j] == '?' || str[i + j] == T[j]))
            {
              auto saved = str[i .. i + T.length].dup;
              str[i .. i + T.length] = T[];
              if (iota(0, str.length - T.length + 1).filter!(k => k != i).all!(k => str[k .. k + T.length] != T[]))
                {
                  str = str.map!(c => c == '?'? 'z' : c).array.toUTF8.dup;
                  writeln("Yes");
                  writeln(str.idup);
                  continue testCase;
                }
              str[i .. i + T.length] = saved;
            }
        }
      writeln("No");
    }
}

import std.container: DList;
DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  int t;
  read(t);
 testCase:while(t--)
    {
      int n;
      string istr;
      read(n);
      read(istr);
      enum wantedString = "abacaba";
      char[] str = istr.dup;
      for(size_t i = 0; i + wantedString.length - 1 < istr.length; i++)
        {
          import std.algorithm: all, map, count;
          import std.range: iota;
          import std.array: array;
          if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))
            {
              auto saved = str[i .. i + wantedString.length].dup;
              str[i .. i + wantedString.length] = wantedString[];
              if (iota(0, str.length - wantedString.length + 1).all!(k => k == i || str[k .. k + wantedString.length] != wantedString[]))
                {
                  import std.stdio;
                  import std.utf;
                  str = str.map!(c => c == '?'? 'z' : c).array.toUTF8.dup;
                  writeln("Yes");
                  writeln(str.idup);
                  continue testCase;
                }
              str[i .. i + wantedString.length] = saved;
            }
        }
      import std.stdio;
      writeln("No");
    }
}

import std.container: DList;
DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  int t;
  read(t);
 testCase:while(t--)
    {
      int n;
      string istr;
      read(n);
      read(istr);
      char[] str = istr.dup;
      enum wantedString = "abacaba";
      for(size_t i = 0; i + wantedString.length - 1 < str.length; i++)
        {
          import std.algorithm: all, map, count;
          import std.range: iota;
          import std.array: array;
          if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))
            {
              auto saved = str[i .. i + wantedString.length].dup;
              str[i .. i + wantedString.length] = wantedString[];
              import std.utf;
              str = str.map!(c => c == '?'? 'x' : c).array.toUTF8.dup;
              auto appearances = iota(0, str.length - wantedString.length + 1).count!(k => str[k .. k + wantedString.length] == wantedString[]);
              assert(appearances >= 1);
              if (iota(0, str.length - wantedString.length + 1).count!(k => str[k .. k + wantedString.length] == wantedString[]) == 1)
                {
                  import std.stdio;
                  writeln("Yes");
                  writeln(str.idup);
                  continue testCase;
                }
              str[i .. i + wantedString.length] = saved;
            }
        }
      import std.stdio;
      writeln("No");
    }
}

import std.container: DList;
DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  int t;
  read(t);
 testCase:while(t--)
    {
      int n;
      string istr;
      read(n);
      read(istr);
      char[] str = istr.dup;
      enum wantedString = "abacaba";
      for(size_t i = 0; i + wantedString.length - 1 < str.length; i++)
        {
          import std.algorithm: all, map, count;
          import std.range: iota;
          import std.array: array;
          if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))
            {
              auto saved = str[i .. i + wantedString.length].dup;
              str[i .. i + wantedString.length] = wantedString[];
              import std.utf;
              str = str.map!(c => c == '?'? 'x' : c).array.toUTF8.dup;
              if (iota(0, str.length - wantedString.length + 1).count!(k => str[k .. k + wantedString.length] == wantedString[]) == 1)
                {
                  import std.stdio;
                  writeln("Yes");
                  writeln(str.idup);
                  continue testCase;
                }
              str[i .. i + wantedString.length] = saved;
            }
        }
      import std.stdio;
      writeln("No");
    }
}

import std.container: DList;
DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  int t;
  read(t);
 testCase:while(t--)
    {
      int n;
      string istr;
      read(n);
      read(istr);
      char[] str = istr.dup;
      enum wantedString = "abacaba";
      for(size_t i = 0; i + wantedString.length - 1 < str.length; i++)
        {
          import std.algorithm: all, map;
          import std.range: iota;
          import std.array: array;
          if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))
            {
              auto saved = str[i .. i + wantedString.length].dup;
              str[i .. i + wantedString.length] = wantedString[];
              import std.utf;
              str = str.map!(c => c == '?'? 'x' : c).array.toUTF8.dup;
              if (iota(0, str.length - wantedString.length + 1).all!(k => k == i || str[k .. k + wantedString.length] != wantedString[]))
                {
                  import std.stdio;
                  writeln("Yes");
                  writeln(str.idup);
                  continue testCase;
                }
              str[i .. i + wantedString.length] = saved;
            }
        }
      import std.stdio;
      writeln("No");
    }
}

import std.container: DList;
DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  int t;
  read(t);
 testCase:while(t--)
    {
      int n;
      string istr;
      read(n);
      read(istr);
      char[] str = istr.dup;
      enum wantedString = "abacaba";
      for(size_t i = 0; i + wantedString.length - 1 < str.length; i++)
        {
          import std.algorithm: all, map;
          import std.range: iota;
          import std.array: array;
          if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))
            {
              auto saved = str[i .. i + wantedString.length].dup;
              str[i .. i + wantedString.length] = wantedString[];
              import std.utf;
              str = str.map!(c => c == '?'? 'x' : c).array.toUTF8.dup;
              if (iota(0, str.length - wantedString.length + 1).all!(k => k == i || str[k .. k + wantedString.length] != wantedString[]))
                {
                  import std.stdio;
                  writeln("Yes");
                  writeln(str.idup);
                  continue testCase;
                }
            }
        }
      import std.stdio;
      writeln("No");
    }
}

import std.container: DList;
DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  int t;
  read(t);
 testCase:while(t--)
    {
      int n;
      string istr;
      read(n);
      read(istr);
      char[] str = istr.dup;
      enum wantedString = "abacaba";
      for(size_t i = 0; i + wantedString.length - 1 < str.length; i++)
        {
          import std.algorithm: all, map, count, min;
          import std.range: iota;
          import std.array: array;
          if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))
            {
              auto saved = str[i .. i + wantedString.length].dup;
              str[i .. i + wantedString.length] = wantedString[];
              import std.utf;
              str = str.map!(c => c == '?'? 'z' : c).array.toUTF8.dup;
              auto appearances = iota(0, str.length).count!(k => str[k .. min(k + wantedString.length, $)] == wantedString[]);
              assert(appearances >= 1);
              if (appearances == 1)
                {
                  import std.stdio;
                  writeln("Yes");
                  writeln(str.idup);
                  continue testCase;
                }
              str[i .. i + wantedString.length] = saved[];
            }
        }
      import std.stdio;
      writeln("No");
    }
}


Chef Monocarp has just put $$$n$$$ dishes into an oven. He knows that the $$$i$$$-th dish has its optimal cooking time equal to $$$t_i$$$ minutes.At any positive integer minute $$$T$$$ Monocarp can put no more than one dish out of the oven. If the $$$i$$$-th dish is put out at some minute $$$T$$$, then its unpleasant value is $$$|T - t_i|$$$ — the absolute difference between $$$T$$$ and $$$t_i$$$. Once the dish is out of the oven, it can't go back in.Monocarp should put all the dishes out of the oven. What is the minimum total unpleasant value Monocarp can obtain?

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of testcases. Then $$$q$$$ testcases follow. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of dishes in the oven. The second line of the testcase contains $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$1 \le t_i \le n$$$) — the optimal cooking time for each dish. The sum of $$$n$$$ over all $$$q$$$ testcases doesn't exceed $$$200$$$.

Print a single integer for each testcase — the minimum total unpleasant value Monocarp can obtain when he puts out all the dishes out of the oven. Remember that Monocarp can only put the dishes out at positive integer minutes and no more than one dish at any minute.

NoteIn the first example Monocarp can put out the dishes at minutes $$$3, 1, 5, 4, 6, 2$$$. That way the total unpleasant value will be $$$|4 - 3| + |2 - 1| + |4 - 5| + |4 - 4| + |6 - 5| + |2 - 2| = 4$$$.In the second example Monocarp can put out the dishes at minutes $$$4, 5, 6, 7, 8, 9, 10$$$.In the third example Monocarp can put out the dish at minute $$$1$$$.In the fourth example Monocarp can put out the dishes at minutes $$$5, 1, 2, 4, 3$$$.In the fifth example Monocarp can put out the dishes at minutes $$$1, 3, 4, 5$$$.

// Vicfred
// https://codeforces.com/contest/1437/problem/C
//
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

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

    int n;
    int[] t;
    while(q--) {
        n = readln.chomp.to!int;
        t = readln.split.map!(to!int).array;

        t = t.map!(x => x - 1).array;

        t.sort;

        // dp
        // number of dishes
        // at time t
        int[][] dp = new int[][](n + 1, 2*n);
        for(int i = 0; i < n + 1; i++) {
            for(int j = 0; j < 2*n; j++) {
                dp[i][j] = int.max;
            }
        }

        dp[0][0] = 0L;
        for(int i = 0; i < n + 1; i++) {
            for(int j = 0; j + 1 < 2*n; j++) {
                if(dp[i][j] < int.max) {
                    if(i + 1 <= n)
                        dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + abs(t[i] - j));
                    // dont take the dish and move to the next minute
                    dp[i][j + 1] = min(dp[i][j], dp[i][j + 1]);
                }
            }
        }

        dp[n][2 * n - 1].writeln;
    }
}

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

immutable int infinity = int.max / 2;

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;
		sort (a);
		auto f = new int [] [] (2, n + 1);
		int b = 0;
		f[b][] = infinity;
		f[b][0] = 0;
		foreach (i; 1..n * 2 + 1)
		{
			b ^= 1;
			f[b][] = f[!b][];
			foreach_reverse (k; 1..n + 1)
			{
				f[b][k] = min (f[b][k], f[!b][k - 1] +
				    abs (i - a[k - 1]));
			}
		}
		writeln (f[b][n]);
	}
}

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

immutable int infinity = int.max / 2;

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;
		sort (a);
		auto f = new int [n + 1];
		f[] = infinity;
		f[0] = 0;
		foreach (i; 1..n * 2 + 1)
		{
			foreach_reverse (k; 1..n + 1)
			{
				f[k] = min (f[k], f[k - 1] +
				    abs (i - a[k - 1]));
			}
		}
		writeln (f[n]);
	}
}


It is reported that the 2050 Conference will be held in Yunqi Town in Hangzhou from April 23 to 25, including theme forums, morning jogging, camping and so on.The relationship between the $$$n$$$ volunteers of the 2050 Conference can be represented by a tree (a connected undirected graph with $$$n$$$ vertices and $$$n-1$$$ edges). The $$$n$$$ vertices of the tree corresponds to the $$$n$$$ volunteers and are numbered by $$$1,2,\ldots, n$$$.We define the distance between two volunteers $$$i$$$ and $$$j$$$, dis$$$(i,j)$$$ as the number of edges on the shortest path from vertex $$$i$$$ to vertex $$$j$$$ on the tree. dis$$$(i,j)=0$$$ whenever $$$i=j$$$.Some of the volunteers can attend the on-site reunion while others cannot. If for some volunteer $$$x$$$ and nonnegative integer $$$r$$$, all volunteers whose distance to $$$x$$$ is no more than $$$r$$$ can attend the on-site reunion, a forum with radius $$$r$$$ can take place. The level of the on-site reunion is defined as the maximum possible radius of any forum that can take place.Assume that each volunteer can attend the on-site reunion with probability $$$\frac{1}{2}$$$ and these events are independent. Output the expected level of the on-site reunion. When no volunteer can attend, the level is defined as $$$-1$$$. When all volunteers can attend, the level is defined as $$$n$$$.

The first line contains a single integer $$$n$$$ ($$$2\le n\le 300$$$) denoting the number of volunteers. Each of the next $$$n-1$$$ lines contains two integers $$$a$$$ and $$$b$$$ denoting an edge between vertex $$$a$$$ and vertex $$$b$$$.

Output the expected level modulo $$$998\,244\,353$$$. Formally, let $$$M = 998\,244\,353$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \le x < M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.

NoteFor the first example, the following table shows all possible outcomes. $$$yes$$$ means the volunteer can attend the on-site reunion and $$$no$$$ means he cannot attend. $$$$$$\begin{array}{cccc} 1 & 2 & 3 & level\\ yes & yes & yes & 3\\ yes & yes & no & 1\\ yes & no & yes & 0\\ yes & no & no & 0\\ no & yes & yes & 1\\ no & yes & no & 0\\ no & no & yes & 0\\ no & no & no & -1\\ \end{array}$$$$$$ The expected level is $$$\frac{3+1+1+(-1)}{2^3}=\frac{1}{2}$$$.

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

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

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

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

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

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

int N;
int[] A, B;

int[][] G;

/*
  dp[u][0][a]: shallowest 0
  dp[u][1][b]: deepest 1 without near 0

  color(u) = 0
    - any (0, a)
    - any (1, b) with 1 + b <= K
    becomes (0, 0)

  color(u) = 1
    start with (1, 0)
    merge subtres
    - (0, a), (0, a'): (0, min{a, 1 + a'})
    - (0, a), (1, b'):
        (0, a)       if a + 1 + b' <= K
        (1, 1 + b')  if a + 1 + b' >  K
    - (1, b), (0, a'):
        (0, 1 + a')  if a' + 1 + b <= K
        (1, b)       if a' + 1 + b >  K
    - (1, b), (1, b'): (0, max{b, 1 + b'})
*/
int K;
Mint[][][] dp;

void dfs(int u, int p) {
  Mint prod = 1;
  int l = 0;
  auto crt = new Mint[][](2, 0 + 1);
  crt[1][0] = 1;
  foreach (i; G[u]) {
    const v = A[i] ^ B[i] ^ u;
    if (v != p) {
      dfs(v, u);
      const m = cast(int)(dp[v][0].length) - 1;
      // 0
      Mint sum;
      foreach (y; 0 .. m + 1) {
        sum += dp[v][0][y];
        if (1 + y <= K) {
          sum += dp[v][1][y];
        }
      }
      prod *= sum;
      // 1
      const ll = max(l, 1 + m);
      auto nxt = new Mint[][](2, ll + 1);
      foreach (x; 0 .. l + 1) foreach (y; 0 .. m + 1) {
        nxt[0][min(x, 1 + y)] += crt[0][x] * dp[v][0][y];
        ((x + 1 + y <= K) ? nxt[0][x] : nxt[1][1 + y]) += crt[0][x] * dp[v][1][y];
        ((x + 1 + y <= K) ? nxt[0][1 + y] : nxt[1][x]) += crt[1][x] * dp[v][0][y];
        nxt[1][max(x, 1 + y)] += crt[1][x] * dp[v][1][y];
      }
      l = ll;
      crt = nxt;
    }
  }
  dp[u] = new Mint[][](2, l + 1);
  dp[u][0][0] += prod;
  foreach (x; 0 .. l + 1) {
    dp[u][0][x] += crt[0][x];
    dp[u][1][x] += crt[1][x];
  }
}

void main() {
  debug {
    writeln(2^^3 * Mint(499122177));
    writeln(2^^5 * Mint(249561089));
    writeln(2^^10 * Mint(821796866));
  }

  try {
    for (; ; ) {
      N = readInt();
      A = new int[N - 1];
      B = new int[N - 1];
      foreach (i; 0 .. N - 1) {
        A[i] = readInt() - 1;
        B[i] = readInt() - 1;
      }

      G = new int[][N];
      foreach (i; 0 .. N - 1) {
        G[A[i]] ~= i;
        G[B[i]] ~= i;
      }

      dp = new Mint[][][N];

      Mint ans;
      for (K = 1; K <= N; ++K) {
        debug {
          writefln("---- K = %s ----", K);
        }
        /*
          < K
          #{S | \forall u \in S, \exists v \not\in S, d(u, v) <= K}
        */
        const rt = 0;
        dfs(rt, -1);
        const sum = dp[rt][0].sum;
        debug {
          writeln("dp = ", dp);
          writeln("sum = ", sum);
        }
        // >= K
        ans += (Mint(2)^^N - sum);
      }
      // -1
      ans -= 1;
      ans /= Mint(2)^^N;
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}