Levko loves permutations very much. A permutation of length n is a sequence of distinct positive integers, each is at most n.Let’s assume that value gcd(a, b) shows the greatest common divisor of numbers a and b. Levko assumes that element pi of permutation p1, p2, ... , pn is good if gcd(i, pi) > 1. Levko considers a permutation beautiful, if it has exactly k good elements. Unfortunately, he doesn’t know any beautiful permutation. Your task is to help him to find at least one of them.

The single line contains two integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ n).

In a single line print either any beautiful permutation or -1, if such permutation doesn’t exist. If there are multiple suitable permutations, you are allowed to print any of them.

NoteIn the first sample elements 4 and 3 are good because gcd(2, 4) = 2 > 1 and gcd(3, 3) = 3 > 1. Elements 2 and 1 are not good because gcd(1, 2) = 1 and gcd(4, 1) = 1. As there are exactly 2 good elements, the permutation is beautiful.The second sample has no beautiful permutations.

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

struct IO {
        string read_string() {
                while (tokens.empty) {
                tokens = readln.split;
        }
        auto token = tokens.front;
                tokens.popFront;
                return token;
        }
        int read_int() {
                return read_string.to!int;
        }

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                int k = cin.read_int;

                int[] arr = new int[n];
                if (k == n) writeln(-1);
                else {
                        for (int i = n; i > n - k; i--) {
                                arr[i - 1] = i;
                        }
                        for (int i = 1; i < n - k; i++) {
                                arr[i - 1] = i + 1;
                        }
                        arr[n - k - 1] = 1;
                        foreach (i; arr) write(i, " ");
                }
        }
}

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

//  Input
string[] tokens;
int tokenId = 0;
string readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }

int readInt() { return to!int(readToken); }
long readLong() { return to!long(readToken); }
real readReal() { return to!real(readToken); }

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

int N;
int K;

void main () {
     N = readInt();
     K = readInt();

     int i;

     if (N == K) {
        writeln("-1");
     } else if (N == K + 1) {
        for (i = 1; i <= N; i++) {
            writef("%s ", i);
        }
     } else {
        writef("%s ", N);

        for (i = 2; i <= K + 1; i++) {
            writef("%s ", i);
        }

        writef("%s ", 1);

        for (i = K + 2; i <= N - 1; i++) {
            writef("%s ", i);
        }
     }
}

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

struct IO {
        string read_string() {
                while (tokens.empty) {
                tokens = readln.split;
        }
        auto token = tokens.front;
                tokens.popFront;
                return token;
        }
        int read_int() {
                return read_string.to!int;
        }

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                int k = cin.read_int;

                int[] arr = new int[n];
                for (int i = 1; i <= k; i++) {
                        if (i * 2 > n) {
                                writeln(-1);
                                return;
                        } else arr[i - 1] = i * 2;
                }

                for (int i = k + 1; i <= n; i++) {
                        if (canFind(arr, i)) {
                                for (int j = 1; j <= n; j++) {
                                        if(!canFind(arr, j)) arr[i - 1] = j;
                                        break;
                                }
                        } else arr[i - 1] = i;
                }

                foreach (i; arr) {
                        write(i, " ");
                }
        }
}


A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care.There is an $$$n\times m$$$ grid. Initially, you may place some north magnets and some south magnets into the cells. You are allowed to place as many magnets as you like, even multiple in the same cell.An operation is performed as follows. Choose a north magnet and a south magnet to activate. If they are in the same row or the same column and they occupy different cells, then the north magnet moves one unit closer to the south magnet. Otherwise, if they occupy the same cell or do not share a row or column, then nothing changes. Note that the south magnets are immovable.Each cell of the grid is colored black or white. Let's consider ways to place magnets in the cells so that the following conditions are met.  There is at least one south magnet in every row and every column.  If a cell is colored black, then it is possible for a north magnet to occupy this cell after some sequence of operations from the initial placement.  If a cell is colored white, then it is impossible for a north magnet to occupy this cell after some sequence of operations from the initial placement. Determine if it is possible to place magnets such that these conditions are met. If it is possible, find the minimum number of north magnets required (there are no requirements on the number of south magnets).

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n,m\le 1000$$$)  — the number of rows and the number of columns, respectively. The next $$$n$$$ lines describe the coloring. The $$$i$$$-th of these lines contains a string of length $$$m$$$, where the $$$j$$$-th character denotes the color of the cell in row $$$i$$$ and column $$$j$$$. The characters "#" and "." represent black and white, respectively. It is guaranteed, that the string will not contain any other characters.

Output a single integer, the minimum possible number of north magnets required. If there is no placement of magnets that satisfies all conditions, print a single integer $$$-1$$$.

NoteIn the first test, here is an example placement of magnets:  In the second test, we can show that no required placement of magnets exists. Here are three example placements that fail to meet the requirements. The first example violates rule $$$3$$$ since we can move the north magnet down onto a white square. The second example violates rule $$$2$$$ since we cannot move the north magnet to the bottom-left black square by any sequence of operations. The third example violates rule $$$1$$$ since there is no south magnet in the first column.  In the third test, here is an example placement of magnets. We can show that there is no required placement of magnets with fewer north magnets.  In the fourth test, we can show that no required placement of magnets exists. Here are two example placements that fail to meet the requirements. The first example violates rule $$$1$$$ since there is no south magnet in the first row. The second example violates rules $$$1$$$ and $$$3$$$ since there is no south magnet in the second row and we can move the north magnet up one unit onto a white square.  In the fifth test, we can put the south magnet in each cell and no north magnets. Because there are no black cells, it will be a correct placement.

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

immutable int NA = -1;
immutable int dirs = 4;
immutable int [dirs] dRow = [-1,  0, +1,  0];
immutable int [dirs] dCol = [ 0, -1,  0, +1];

void main ()
{
	int rows, cols;
	while (readf !(" %s %s") (rows, cols) > 0)
	{
		readln;
		string [] board;
		foreach (row; 0..rows)
		{
			board ~= readln.strip;
		}

		auto mark = new int [] [] (rows, cols);
		foreach (ref line; mark)
		{
			line[] = NA;
		}
		int num = 0;

		void doMark (int sRow, int sCol)
		{
			alias Coord = Tuple !(int, q{row}, int, q{col});
			Coord [] q;
			q ~= Coord (sRow, sCol);
			mark[sRow][sCol] = num;
			while (!q.empty)
			{
				auto row = q.front.row;
				auto col = q.front.col;
				q.popFront ();
				q.assumeSafeAppend ();
				foreach (dir; 0..dirs)
				{
					auto nRow = row + dRow[dir];
					auto nCol = col + dCol[dir];
					if (0 <= nRow && nRow < rows &&
					    0 <= nCol && nCol < cols &&
					    board[nRow][nCol] == '#' &&
					    mark[nRow][nCol] == NA)
					{
						mark[nRow][nCol] = num;
						q ~= Coord (nRow, nCol);
					}
				}
			}
		}

		foreach (row; 0..rows)
		{
			foreach (col; 0..cols)
			{
				if (board[row][col] == '#' &&
				    mark[row][col] == NA)
				{
					doMark (row, col);
					num += 1;
				}
			}
		}

		bool ok = true;

		auto countRow = new int [rows];
		auto countCol = new int [cols];
		foreach (row; 0..rows)
		{
			int temp = 0;
			foreach (col; 0..cols)
			{
				if (board[row][col] == '#')
				{
					countRow[row] += 1;
					countCol[col] += 1;
				}
			}
		}

		ok &= (countRow.canFind (0) == countCol.canFind (0));

		void checkSquare (ref int seen, int cur)
		{
			if (seen == NA)
			{
				seen = cur;
			}
			else if (seen < num)
			{
				if (cur == NA)
				{
					seen = num;
				}
				else if (cur != seen)
				{
					ok = false;
				}
			}
			else
			{
				if (cur != NA)
				{
					ok = false;
				}
			}
		}

		foreach (row; 0..rows)
		{
			int seen = NA;
			foreach (col; 0..cols)
			{
				auto cur = mark[row][col];
				checkSquare (seen, cur);
			}
		}
		foreach (col; 0..cols)
		{
			int seen = NA;
			foreach (row; 0..rows)
			{
				auto cur = mark[row][col];
				checkSquare (seen, cur);
			}
		}

		writeln (ok ? num : NA);
	}
}

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

void main() {
  try {
    for (; ; ) {
      const M = readInt();
      const N = readInt();
      auto A = new string[M];
      foreach (x; 0 .. M) {
        A[x] = readToken();
      }

      auto uf = new int[M * N];
      uf[] = -1;
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        if (A[x][y] == '#') {
          if (x > 0 && A[x - 1][y] == '#') uf.connect((x - 1) * N + y, x * N + y);
          if (y > 0 && A[x][y - 1] == '#') uf.connect(x * N + (y - 1), x * N + y);
        }
      }
      int num;
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        if (A[x][y] == '#') {
          if (uf[x * N + y] < 0) {
            ++num;
          }
        }
      }

      bool ans = true;
      bool empRow, empCol;
      foreach (x; 0 .. M) {
        int mn = N, mx = -1;
        foreach (y; 0 .. N) {
          if (A[x][y] == '#') {
            chmin(mn, y);
            chmax(mx, y);
          }
        }
        if (mn <= mx) {
          foreach (y; mn .. mx + 1) {
            ans = ans && (A[x][y] == '#');
          }
        } else {
          empRow = true;
        }
      }
      foreach (y; 0 .. N) {
        int mn = M, mx = -1;
        foreach (x; 0 .. M) {
          if (A[x][y] == '#') {
            chmin(mn, x);
            chmax(mx, x);
          }
        }
        if (mn <= mx) {
          foreach (x; mn .. mx + 1) {
            ans = ans && (A[x][y] == '#');
          }
        } else {
          empCol = true;
        }
      }
      ans = ans && (empRow == empCol);

      writeln(ans ? num : -1);
    }
  } catch (EOFException e) {
  }
}

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

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

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

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

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

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

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];

    auto MAP = new char[][](N.to!size_t, M.to!size_t);
    foreach (i; 0..N) foreach (j, c; readln.chomp) MAP[i][j] = c;

    bool rb, cb;
    foreach (i; 0..N) {
        bool rrb = true;
        foreach (j; 0..M) if (MAP[i][j] == '#') {
            rrb = false;
            break;
        }
        if (rrb) {
            rb = true;
            break;
        }
    }
    foreach (j; 0..M) {
        bool ccb = true;
        foreach (i; 0..N) if (MAP[i][j] == '#') {
            ccb = false;
            break;
        }
        if (ccb) {
            cb = true;
            break;
        }
    }
    if (rb != cb) {
        writeln(-1);
        return;
    }

    foreach (i; 0..N) {
        bool cd;
        if (MAP[i][0] == '#') cd = true;
        foreach (j; 1..M) {
            if (MAP[i][j-1] == '.' && MAP[i][j] == '#') {
                if (cd) {
                    writeln(-1);
                    return;
                } else {
                    cd = true;
                }
            }
        }
    }
    foreach (j; 0..M) {
        bool cd;
        if (MAP[0][j] == '#') cd = true;
        foreach (i; 1..N) {
            if (MAP[i-1][j] == '.' && MAP[i][j] == '#') {
                if (cd) {
                    writeln(-1);
                    return;
                } else {
                    cd = true;
                }
            }
        }
    }
    auto cs = new int[][](N.to!size_t, M.to!size_t);
    int c;
    foreach (i; 0..N) foreach (j; 0..M) if (MAP[i][j] == '#' && cs[i][j] == 0) {
        void paint(int i, int j) {
            foreach (d; [[1,0], [0,1], [-1,0], [0,-1]]) {
                auto ii = i+d[0];
                auto jj = j+d[1];
                if (ii < 0 || ii >= N || jj < 0 || jj >= M || MAP[ii][jj] == '.' || cs[ii][jj] != 0) continue;
                cs[ii][jj] = c;
                paint(ii, jj);
            }
        }
        ++c;
        cs[i][j] = c;
        paint(i, j);
    }
    writeln(c);
}

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

void main() {
  try {
    for (; ; ) {
      const M = readInt();
      const N = readInt();
      auto A = new string[M];
      foreach (x; 0 .. M) {
        A[x] = readToken();
      }

      auto uf = new int[M * N];
      uf[] = -1;
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        if (A[x][y] == '#') {
          if (x > 0 && A[x - 1][y] == '#') uf.connect((x - 1) * N + y, x * N + y);
          if (y > 0 && A[x][y - 1] == '#') uf.connect(y * N + (y - 1), x * N + y);
        }
      }
      int num;
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        if (A[x][y] == '#') {
          if (uf[x * N + y] < 0) {
            ++num;
          }
        }
      }

      bool ans = true;
      bool empRow, empCol;
      foreach (x; 0 .. M) {
        int mn = N, mx = -1;
        foreach (y; 0 .. N) {
          if (A[x][y] == '#') {
            chmin(mn, y);
            chmax(mx, y);
          }
        }
        if (mn <= mx) {
          foreach (y; mn .. mx + 1) {
            ans = ans && (A[x][y] == '#');
          }
        } else {
          empRow = true;
        }
      }
      foreach (y; 0 .. N) {
        int mn = M, mx = -1;
        foreach (x; 0 .. M) {
          if (A[x][y] == '#') {
            chmin(mn, x);
            chmax(mx, x);
          }
        }
        if (mn <= mx) {
          foreach (x; mn .. mx + 1) {
            ans = ans && (A[x][y] == '#');
          }
        } else {
          empCol = true;
        }
      }
      ans = ans && (empRow == empCol);

      writeln(ans ? num : -1);
    }
  } catch (EOFException e) {
  }
}


You play your favourite game yet another time. You chose the character you didn't play before. It has $$$str$$$ points of strength and $$$int$$$ points of intelligence. Also, at start, the character has $$$exp$$$ free experience points you can invest either in strength or in intelligence (by investing one point you can either raise strength by $$$1$$$ or raise intelligence by $$$1$$$).Since you'd like to make some fun you want to create a jock character, so it has more strength than intelligence points (resulting strength is strictly greater than the resulting intelligence).Calculate the number of different character builds you can create (for the purpose of replayability) if you must invest all free points. Two character builds are different if their strength and/or intellect are different.

The first line contains the single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Next $$$T$$$ lines contain descriptions of queries — one per line. This line contains three integers $$$str$$$, $$$int$$$ and $$$exp$$$ ($$$1 \le str, int \le 10^8$$$, $$$0 \le exp \le 10^8$$$) — the initial strength and intelligence of the character and the number of free points, respectively.

Print $$$T$$$ integers — one per query. For each query print the number of different character builds you can create.

NoteIn the first query there are only three appropriate character builds: $$$(str = 7, int = 5)$$$, $$$(8, 4)$$$ and $$$(9, 3)$$$. All other builds are either too smart or don't use all free points.In the second query there is only one possible build: $$$(2, 1)$$$.In the third query there are two appropriate builds: $$$(7, 6)$$$, $$$(8, 5)$$$.In the fourth query all builds have too much brains.

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

void main() {
    auto T = readln.chomp.to!int;
    auto A = T.iota.map!(_ => readln.split.map!(to!long).array).array;

    foreach (i; 0..T) {
        auto a = A[i][0];
        auto b = A[i][1];
        auto e = A[i][2];
        if (a + e <= b) {
            writeln(0);
            continue;
        }
        long hi = e + 1;
        long lo = 0;
        while (hi - lo > 1) {
            auto mid = (hi + lo) / 2;
            if (a + e - mid > b + mid) {
                lo = mid;
            } else {
                hi = mid;
            }
        }
        writeln(lo + 1);
    }
}

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

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
	int t = rint;
	foreach(_; 0 .. t){
		long a = rint;
		long b = rint;
		long c = rint;

		long all = a + b + c;

		long l = all / 2 + 1 - a;
		if(l < 0) l = 0;

		if(l > c) "0".writeln;
		else (c - l + 1).writeln;
	}
}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto T = RD!int;
	auto ans = new long[](T);
	foreach (i; 0..T)
	{
		auto s = RD;
		auto t = RD;
		auto e = RD;

		auto a = (s + t + e) / 2 + 1;
		a      = max(a, s);
		ans[i] = (s+e) < a ? 0 : s + e - a + 1;
	}

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


There were $$$n$$$ types of swords in the theater basement which had been used during the plays. Moreover there were exactly $$$x$$$ swords of each type. $$$y$$$ people have broken into the theater basement and each of them has taken exactly $$$z$$$ swords of some single type. Note that different people might have taken different types of swords. Note that the values $$$x, y$$$ and $$$z$$$ are unknown for you.The next morning the director of the theater discovers the loss. He counts all swords — exactly $$$a_i$$$ swords of the $$$i$$$-th type are left untouched.The director has no clue about the initial number of swords of each type in the basement, the number of people who have broken into the basement and how many swords each of them have taken.For example, if $$$n=3$$$, $$$a = [3, 12, 6]$$$ then one of the possible situations is $$$x=12$$$, $$$y=5$$$ and $$$z=3$$$. Then the first three people took swords of the first type and the other two people took swords of the third type. Note that you don't know values $$$x, y$$$ and $$$z$$$ beforehand but know values of $$$n$$$ and $$$a$$$.Thus he seeks for your help. Determine the minimum number of people $$$y$$$, which could have broken into the theater basement, and the number of swords $$$z$$$ each of them has taken.

The first line of the input contains one integer $$$n$$$ $$$(2 \le n \le 2 \cdot 10^{5})$$$ — the number of types of swords. The second line of the input contains the sequence $$$a_1, a_2, \dots, a_n$$$ $$$(0 \le a_i \le 10^{9})$$$, where $$$a_i$$$ equals to the number of swords of the $$$i$$$-th type, which have remained in the basement after the theft. It is guaranteed that there exists at least one such pair of indices $$$(j, k)$$$ that $$$a_j \neq a_k$$$.

Print two integers $$$y$$$ and $$$z$$$ — the minimum number of people which could have broken into the basement and the number of swords each of them has taken.

NoteIn the first example the minimum value of $$$y$$$ equals to $$$5$$$, i.e. the minimum number of people who could have broken into the basement, is $$$5$$$. Each of them has taken $$$3$$$ swords: three of them have taken $$$3$$$ swords of the first type, and two others have taken $$$3$$$ swords of the third type.In the second example the minimum value of $$$y$$$ is $$$1$$$, i.e. the minimum number of people who could have broken into the basement, equals to $$$1$$$. He has taken $$$7$$$ swords of the first type.

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto n = RD;
	auto a = RDA;
	auto x = a[MIN_POS!"a > b"(a)];
	/*long x = 1;
	foreach (e; a)
		x = lcm(x, e);*/
	long y;
	foreach (e; a)
		y = gcd(y, x-e);
	long z;
	foreach (e; a)
		z += (x-e) / y;

	writeln(z, " ", y);
	stdout.flush();
	debug readln();
}


Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside.The text is a string $$$s$$$ of lowercase Latin letters. She considers a string $$$t$$$ as hidden in string $$$s$$$ if $$$t$$$ exists as a subsequence of $$$s$$$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $$$1$$$, $$$3$$$, and $$$5$$$, which form an arithmetic progression with a common difference of $$$2$$$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $$$S$$$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!For example, in the string aaabb, a is hidden $$$3$$$ times, b is hidden $$$2$$$ times, ab is hidden $$$6$$$ times, aa is hidden $$$3$$$ times, bb is hidden $$$1$$$ time, aab is hidden $$$2$$$ times, aaa is hidden $$$1$$$ time, abb is hidden $$$1$$$ time, aaab is hidden $$$1$$$ time, aabb is hidden $$$1$$$ time, and aaabb is hidden $$$1$$$ time. The number of occurrences of the secret message is $$$6$$$.

The first line contains a string $$$s$$$ of lowercase Latin letters ($$$1 \le |s| \le 10^5$$$) — the text that Bessie intercepted.

Output a single integer  — the number of occurrences of the secret message.

NoteIn the first example, these are all the hidden strings and their indice sets:   a occurs at $$$(1)$$$, $$$(2)$$$, $$$(3)$$$  b occurs at $$$(4)$$$, $$$(5)$$$  ab occurs at $$$(1,4)$$$, $$$(1,5)$$$, $$$(2,4)$$$, $$$(2,5)$$$, $$$(3,4)$$$, $$$(3,5)$$$  aa occurs at $$$(1,2)$$$, $$$(1,3)$$$, $$$(2,3)$$$  bb occurs at $$$(4,5)$$$  aab occurs at $$$(1,3,5)$$$, $$$(2,3,4)$$$  aaa occurs at $$$(1,2,3)$$$  abb occurs at $$$(3,4,5)$$$  aaab occurs at $$$(1,2,3,4)$$$  aabb occurs at $$$(2,3,4,5)$$$  aaabb occurs at $$$(1,2,3,4,5)$$$  Note that all the sets of indices are arithmetic progressions.In the second example, no hidden string occurs more than once.In the third example, the hidden string is the letter l.

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

void main() {
  auto s = readln.stripRight;
  int[26] c;
  long[26][26] d;
  foreach (ch; s) {
    int i = ch.to!int - 97;
    foreach (j; 0 .. 26) {
      d[j][i] += c[j];
    }
    ++c[i];
  }
  long res;
  foreach (i; 0 .. 26) {
    res = max (res, c[i]);
    foreach (j; 0 .. 26) res = max (res, d[i][j]);
  }
  writeln (res);
}

import std.stdio : writeln;

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

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

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

        return readToken.to!int;
    }

    string[] tokens;
}

void main() {
    import std.algorithm : max;

    IO io;
    string s = io.readToken;
    long[] cnt1 = new long[26];
    long[][] cnt2 = new long[][](26, 26);
    for (int i = 0; i < s.length; ++i) {
        int c = s[i] - 'a';
        for (int d = 0; d < 26; ++d) {
            cnt2[d][c] += cnt1[d];
        }
        cnt1[c]++;
    }
    long result = 0;
    for (int c = 0; c < 26; ++c) {
        result = max(result, cnt1[c]);
        for (int d = 0; d < 26; ++d) {
            result = max(result, cnt2[c][d]);
        }
    }
    writeln(result);
}

import std.container;
import std.algorithm;
import std.range;
import std.array;
import std.stdio;
import std.utf;
import std.math;
import std.typecons;

struct Interval
{
  long l, h;

  bool empty()
  {
    return l > h;
  }
}

Interval intersect(Interval a, Interval b)
{
  return Interval(max(a.l, b.l), min(a.h, b.h));
}

struct If
{
  string condition;
}
enum ignore = If("false");
struct Dim
{
  string dimensions;
  int levels;
  this(string dimensions)
  {
    this.dimensions = dimensions;
    levels = cast(int)dimensions.count(",") + 1;
  }
}

template getArrayLevel(W)
{
  static if (isDynamicArray!W && !is(W == string))
    enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));
  else
    enum getArrayLevel = 0;
}

alias type = single;
static foreach(fieldName; 'a' .. cast(char)('z' + 1))
  {
    static if (fieldName != 'o')
      mixin("enum d", fieldName, " = Dim(\"", fieldName, "\");");
  }
struct TestCase
{
  mixin prettyPrinting;

  string s;

  void solve(long tc = -1)
  {
    logSym!(this);
    long[][char] indices = null;
    long[char] singleaps = null;
    long[string] pairaps = null;
    foreach(i, c; s)
      {
        indices[c] ~= cast(long) i;
        singleaps[c]++;
      }
    foreach(i, c; s)
      {
        foreach(w; 'a' .. cast(char)('z' + 1))
          {
            if (w in indices)
              {
                auto pairs = assumeSorted(indices[w])
                  .upperBound(i).length;
                if (pairs > 0)
                  {
                    char[] pair = [c, w];
                    pairaps.require(cast(string) pair, 0) += cast(int) pairs;
                  }
              }
          }
      }
    writeln(max(pairaps.byValue.fold!max(long.min),
                singleaps.byValue.fold!max(long.min)));
  }
}

mixin template prettyPrinting()
{
  string toString()
  {
    alias structType = typeof(this);
    auto res = appender!(string)();
    res.put(structType.stringof);
    res.put("(");
    static foreach(fieldName; FieldNameTuple!structType)
      {
        res.put(text(" ", fieldName, ": ", mixin(fieldName)));
      }
    res.put(" )");
    res.put("\n");
    return res[];
  }
}

struct Graph(N)
{
  size_t size;
  this(S)(S size)
  {
    adjacencyList.length = cast(size_t) size;
    this.size = cast(size_t) size;
    this.visited = makeSlice!bool(size);
  }
  N[][] adjacencyList;
  alias ne = neighbours;
  N[] neighbours(N n)
  {
    return adjacencyList.at(n);
  }
  alias bcon = biconnect;
  void biconnect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
    adjacencyList.at(b) ~= a;
  }
  alias con = connect;
  void connect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
  }
  void connect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        connect(edge[0], edge[1]);
      }
  }
  void biconnect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        biconnect(edge[0], edge[1]);
      }
  }
  alias deg = degree!long;
  auto degree(T)(N a)
  {
    return cast(T) adjacencyList.at(a).length;
  }

  auto visited = new bool[0];
  void dfs(Visitor)(long startNode)
  {
    auto visitor = Visitor.init;
    void internalDfs(long node)
    {
      visited.set(node, true);
      static if (is(typeof({visitor.n = node;})))
        visitor.n = node;
      static if (is(typeof({visitor.pre;})))
        visitor.pre;
      foreach(w; ne(node))
        if (!visited.at(w))
          {
            static if (is(typeof({visitor.w = w;})))
              visitor.w = w;
            static if (is(typeof(visitor.pren)))
              visitor.pren;
            internalDfs(w);
            static if (is(typeof(visitor.postn)))
              visitor.postn;
          }
      static if (is(typeof(visitor.post)))
        visitor.post;
    }
    internalDfs(startNode);
  }
  void dfs(long startNode)
  {
    struct DefVisitor {}
    dfs!DefVisitor(startNode);
  }
}

DList!string _words;

template removeArray(W, int times)
{
  static if (times == 0)
    alias removeArray = W;
  else static if (times == 1)
    alias removeArray = typeof(function(){W w; return w[0];}());
  else
    {
      static assert(isDynamicArray!W);
      alias removeArray = removeArray!(removeArray!(W, 1), times - 1);
    }
}

template baseType(W)
{
  static if (isDynamicArray!W && !is(W == string))
    alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));
  else
    alias baseType = W;
}

auto makeSlice(E, W, T...)(W size, T otherSizes)
{
  static if (T.length == 0)
    {
      E[] res;
      res.length = cast(size_t) size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = cast(size_t) size;
      foreach(ref row; res)
        row = makeSlice!E(otherSizes);
      return res;
    }
}

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    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;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, If))
              enum condition = getUDAs!(fieldSymbol, If)[0].condition;
            else
              enum condition = "true";

            if (mixin(condition))
              {
                static if (hasUDA!(fieldSymbol, Dim))
                  {
                    static assert(isDynamicArray!(typeOfField)
                                  , text(W.stringof, ".", fieldName, " has Dim UDA but isn't a Dynamic Array."));
                    enum uda = getUDAs!(fieldSymbol, Dim)[0];
                    static assert(getArrayLevel!(typeOfField) == uda.levels,
                                  text(W.stringof, ".", fieldName, " has a Dim UDA with different number of dimensions than it's type."));
                    mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});
                  }
                else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
                  {
                    pragma(msg, "Warning: You probably want to add dimension to input ", W.stringof, ".", fieldName);
                  }
                read(mixin(fieldName));
              }
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

auto next(T)()
{
  T t;
  read(t);
  return t;
}

size_t ind(T)(T t)
{
  return cast(size_t)t;
}

ref auto at(R, I)(ref R r, I i)
{
  return r[cast(size_t)i];
}

void set(R, I, V)(ref R r, I i, V v)
{
  r[cast(size_t)i] = v;
}

import std.conv;
import std.traits;
import std.meta;
int _loglevel = -1;
void _log(string functionName, argSeq...)()
{
  foreach(i; 0 .. _loglevel * 4)
    write(' ');
  write(functionName);
  static foreach(arg; argSeq)
    {
      write(" ", arg.stringof, " = ", arg);
    }
  writeln;
}
enum logCall =
  q{
    debug
    {
     {
     _loglevel++;
     alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, ".").back));
     static if (_parameterTuple.length > 0)
       mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(", ").array, `);`);
     else
       _log!(__FUNCTION__);
      }
     foreach(i; 0 .. _loglevel * 4) write(' ');
     writeln('{');
     scope(exit)
       {
         foreach(i; 0 .. _loglevel * 4) write(' ');
         writeln('}');
         _loglevel--;
       }
    }
};

void logSym(S...)(int line = __LINE__, string file = __FUNCTION__)
{
  debug
    {
      foreach(i; 0 .. _loglevel * 4) write(' ');
      write(file, "(", line, "):");
      static foreach(s; S)
        write(" ", s.stringof, " = ", s);
      writeln;

    }
}

Array!E makeArray(E, S)(S size, lazy E value)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  foreach(ref ai; a)
    ai = value();
  return a;
}
Array!E makeArray(E, S)(S size)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  return a;
}

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  static if (is(typeof(f(i))))
    foreach(i; 0 .. times)
      f(i);
  else
    foreach(i; 0 .. times)
      f();
}

void multi()
{
  foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

void single()
{
  auto tc = next!TestCase;
  tc.solve;
}

void main()
{
  type;
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto s = RD!string;
	auto cnt = new long[](26);
	auto ans = new long[][](26, 26);
	foreach (c; s)
	{
		auto i = c-'a';
		foreach (j; 0..26)
		{
			ans[i][j] += cnt[j];
		}
		++cnt[i];
	}

	long ans0 = cnt[cnt.MIN_POS!"a > b"];
	foreach (i; 0..26)
	{
		foreach (j; 0..26)
		{
			ans0.chmax(ans[i][j]);
		}
	}

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

import std.stdio : writeln;

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

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

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

        return readToken.to!int;
    }

    string[] tokens;
}

void main() {
    import std.algorithm : max;

    IO io;
    string s = io.readToken;
    int[] cnt1 = new int[26];
    int[][] cnt2 = new int[][](26, 26);
    for (int i = 0; i < s.length; ++i) {
        int c = s[i] - 'a';
        for (int d = 0; d < 26; ++d) {
            cnt2[d][c] += cnt1[d];
        }
        cnt1[c]++;
    }
    int result = 0;
    for (int c = 0; c < 26; ++c) {
        result = max(result, cnt1[c]);
        for (int d = 0; d < 26; ++d) {
            result = max(result, cnt2[c][d]);
        }
    }
    writeln(result);
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto s = RD!string;
	auto cnt = new long[](26);
	foreach (c; s)
	{
		++cnt[c-'a'];
	}
	cnt.sort!"a > b"();

	long ans = 1;
	ans.chmax(cnt[0]);
	ans.chmax(cnt[0] * cnt[1]);
	ans.chmax(cnt[0]*(cnt[0]-1)/2);

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


Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second — from a2 to b2What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.

The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi).

Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.

import std.stdio;
import std.algorithm;
import std.format;

const uint MAX_POS = 1000;

void main()
{
    string firstLine = stdin.readln();
    uint count;
    uint pos;
    formattedRead(firstLine, "%s %s", &count, &pos);

    uint allMin = 0;
    uint allMax = MAX_POS;

    for (int i = 0; i < count; i++) {
        uint start;
        uint stop;
        string line = stdin.readln();
        formattedRead(line, "%s %s", &start, &stop);
        allMin = max(allMin, min(start, stop));
        allMax = min(allMax, max(start, stop));
    }

    if (allMin > allMax) {
        stdout.writeln("-1");
    } else if (allMin <= pos && allMax >= pos) {
        stdout.writeln("0");
    } else if (allMin > pos) {
        stdout.writeln(allMin - pos);
    } else {
        stdout.writeln(pos - allMax);
    }
}


You are given a string, consisting of lowercase Latin letters.A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $$$(1, 2)$$$ — "ab" and $$$(2, 3)$$$ — "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.If there are multiple answers, print any of them.You also have to answer $$$T$$$ separate queries.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Each of the next $$$T$$$ lines contains string $$$s$$$ $$$(1 \le |s| \le 100)$$$ — the string for the next query. It is guaranteed that it contains only lowercase Latin letters. Note that in hacks you have to set $$$T = 1$$$.

Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th query. If the answer for the $$$i$$$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same. If there are multiple answers, print any of them. Otherwise print "No answer" for that query.

NoteIn the first example answer "bdac" is also correct.The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.There are lots of valid answers for the third example.

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

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

    while (t--) {
        auto s = readln.chomp;

        int[char] cnt;
        foreach (e; s) { ++cnt[e]; }

        debug { cnt.writeln; }

        auto diff = cnt.keys.length.to!int;
        auto sortedKeys = cnt.keys.dup.to!(dchar[]).sort.array;
        if ((diff == 2 && sortedKeys[0] + 1 == sortedKeys[1])
                || (diff == 3 && sortedKeys[0] + 1 == sortedKeys[1] && sortedKeys[1] + 1 == sortedKeys[2])) {
            writeln("No answer");
            continue;
        }

        int[] ord;
        if (diff == 3) {
            if (sortedKeys[0] + 1 != sortedKeys[1]) { ord = [1, 0, 2]; }
            else { ord = [1, 2, 0]; }
        } else if (diff == 4) {
            ord = [2, 0, 3, 1];
        } else {
            auto ita = diff.iota;
            ord ~= ita.stride(2).array;
            ord ~= ita.dropOne.stride(2).array;
        }

        debug { ord.writeln; }

        dchar[] ans;
        foreach (e; ord) {
            auto c = sortedKeys[e];
            ans ~= c.repeat(cnt[c.to!char]).array;
        }

        ans.writeln;
    }
}

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

void main ()
{
	int tests;
	readf (" %s", &tests);
	readln;
	foreach (test; 0..tests)
	{
		auto s = readln.strip.dup;
		sort (s.representation);
		auto chars = group (s).array;
		char [] res1;
		foreach_reverse (k; 0..2)
		{
			foreach (elem; chars.drop (k).stride (2))
			{
				res1 ~= elem[0].to !(char)
				    .repeat (elem[1]).array;
			}
		}
		char [] res2;
		foreach_reverse (k; 0..2)
		{
			foreach (elem; chars.retro.drop (k).stride (2))
			{
				res2 ~= elem[0].to !(char)
				    .repeat (elem[1]).array;
			}
		}
		if (res1.findAdjacent
		    !(q{abs (a.to !(int) - b.to !(int)) == 1}).empty)
		{
			writeln (res1);
		}
		else if (res2.findAdjacent
		    !(q{abs (a.to !(int) - b.to !(int)) == 1}).empty)
		{
			writeln (res2);
		}
		else
		{
			writeln ("No answer");
		}
	}
}

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

void test () {
  auto s = readln.strip;
  int[26] c;
  foreach (i; s) {
    ++c[i.to!int - 97];
  }
  auto x = iota (0, 26, 2), y = iota (1, 26, 2);
  auto r1 = x.filter!(a => c[a] > 0);
  auto r2 = y.filter!(a => c[a] > 0);
  void p (int k) {
    write (replicate ([(97+ k).to!char], c[k]));
  }
  void o(T) (T r) {
    foreach (k; r) {
      p (k);
    }
    writeln;
  }
  if (r1.empty) {
    o (r2);
    return;
  }
  if (r2.empty) {
    o (r1);
    return;
  }
  foreach (i; r1) {
    foreach (j; r2) {
      if (abs (i - j) > 1) {
        foreach (k; r1) {
          if (k != i) p (k);
        }
        p (i);
        p (j);
        foreach (k; r2) {
          if (k != j) p (k);
        }
        writeln;
        return;
      }
    }
  }
  writeln ("No answer");
}

void main() {
  immutable nt = readln.strip.to!int;
  foreach (tid; 0 .. nt) {
    test ();
  }
}

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

void solve(){
	int t = read.to!int;
	foreach(_; 0 .. t){

		string s = readln.chomp;
		int[char] cnt;
		foreach(c; s){
			if(c !in cnt) cnt[c] = 0;
			cnt[c] += 1;
		}

		string ans;
		char[] ks;
		foreach(char c; 'a' .. 'z' + 1) if(c in cnt) ks ~= c;
		log("cnt:", cnt);
		log("ks:", ks);

		void f(char c){
			log("c:", c);
			foreach(j; 0 .. cnt[c]) ans ~= c;
		}

		if(ks.length >= 4){
			for(int i = 1; i < ks.length; i += 2) f(ks[i]);
			for(int i = 0; i < ks.length; i += 2) f(ks[i]);
		}
		else if(ks.length == 3){
			if(ks[1] - ks[0] > 1){
				f(ks[1]), f(ks[0]), f(ks[2]);
			}
			else if(ks[2] - ks[1] > 1){
				f(ks[1]), f(ks[2]), f(ks[0]);
			}
			else ans = "No answer".to!(char[]);
		}
		else if(ks.length == 2){
			if(ks[1] - ks[0] > 1){
				f(ks[1]), f(ks[0]);
			}
			else ans = "No answer".to!(char[]);
		}
		else if(ks.length == 1){
			f(ks[0]);
		}

		ans.writeln;
	}

}

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

alias Tree = RBT!int;

void main() {
    GC.disable();

    uint T;
    readf(" %s\n", T);

    foreach (l; 0 .. T) {
        string s = readln().strip;
        auto s1 = s.filter!(c => (c - 'a') % 2 == 0).array();
        auto s2 = s.filter!(c => (c - 'a') % 2 == 1).array();
        sort(s1);
        sort(s2);

        if (s1.length > 0 && s2.length > 0) {
            if (abs(to!int(s1[0]) - to!int(s2[$ - 1])) != 1)
                writeln(s2 ~ s1);
            else if (abs(to!int(s2[0]) - to!int(s1[$ - 1])) != 1)
                writeln(s1 ~ s2);
            else
                writeln("No answer");
        }
        else
            writeln(s1 ~ s2);
    }

}

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

alias Tree = RBT!int;

void main() {
    GC.disable();

    uint T;
    readf(" %s\n", T);

    foreach (l; 0 .. T) {
        auto count = new int[100];
        string s = readln().strip;
        auto s1 = s.filter!(e => (e - 'a') % 2 == 0).array().dup;
        auto s2 = s.filter!(e => (e - 'a') % 2 == 1).array().dup;
        sort(s1);
        sort(s2);

        auto c1 = s1 ~ s2;
        auto r1 = zip(c1[0 .. $ - 1], c1[1 .. $]).any!(a => abs(to!int(a[0]) - to!int(a[1])) == 1);
        if (!r1) {
            writeln(c1);
            continue;
        }

        auto c2 = s2 ~ s1;
        auto r2 = zip(c2[0 .. $ - 1], c2[1 .. $]).any!(a => abs(to!int(a[0]) - to!int(a[1])) == 1);
        if (!r2) {
            writeln(c2);
            continue;
        }

        writeln("No answer");
    }

}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

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

    while (t--) {
        auto s = readln.chomp;

        int[char] cnt;
        foreach (e; s) { ++cnt[e]; }

        debug { cnt.writeln; }

        auto diff = cnt.keys.length.to!int;
        auto sortedKeys = cnt.keys.dup.to!(dchar[]).sort.array;
        if ((diff == 2 && sortedKeys[0] + 1 == sortedKeys[1])
                || (diff == 3 && sortedKeys[0] + 1 == sortedKeys[1] && sortedKeys[1] + 1 == sortedKeys[2])) {
            writeln("No answer");
            continue;
        }

        int[] ord;
        if (diff == 4) {
            ord = [2, 0, 3, 1];
        } else {
            auto ita = diff.iota;
            ord ~= ita.stride(2).array;
            ord ~= ita.dropOne.stride(2).array;
        }

        debug { ord.writeln; }

        dchar[] ans;
        foreach (e; ord) {
            auto c = sortedKeys[e];
            ans ~= c.repeat(cnt[c.to!char]).array;
        }

        ans.writeln;
    }
}

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

void main ()
{
	int tests;
	readf (" %s", &tests);
	readln;
	foreach (test; 0..tests)
	{
		auto s = readln.strip.dup;
		sort (s.representation);
		auto chars = group (s);
		char [] res;
		foreach_reverse (k; 0..2)
		{
			foreach (elem; chars.drop (k).stride (2))
			{
				res ~= elem[0].to !(char)
				    .repeat (elem[1]).array;
			}
		}
		if (!res.findAdjacent !(q{abs (a - b) == 1}).empty)
		{
			writeln ("No answer");
		}
		else
		{
			writeln (res);
		}
	}
}

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

void solve(){
	int t = read.to!int;
	foreach(_; 0 .. t){

		string s = readln.chomp;
		int[char] cnt;
		foreach(c; s){
			if(c !in cnt) cnt[c] = 0;
			cnt[c] += 1;
		}

		string ans;
		char[] ks;
		foreach(char c; 'a' .. 'z' + 1) if(c in cnt) ks ~= c;
		log("cnt:", cnt);
		log("ks:", ks);

		void f(char c){
			log("c:", c);
			foreach(j; 0 .. cnt[c]) ans ~= c;
		}

		if(ks.length >= 4){
			for(int i = 1; i < ks.length; i += 2) f(ks[i]);
			for(int i = ((ks.length - 1)/ 2) * 2; i >= 0; i -= 2) log(i), f(ks[i]);
		}
		else if(ks.length == 3){
			if(ks[1] - ks[0] > 1){
				f(ks[1]), f(ks[0]), f(ks[2]);
			}
			else if(ks[2] - ks[1] > 1){
				f(ks[1]), f(ks[2]), f(ks[0]);
			}
			else ans = "No answer".to!(char[]);
		}
		else if(ks.length == 2){
			if(ks[1] - ks[0] > 1){
				f(ks[1]), f(ks[0]);
			}
			else ans = "No answer".to!(char[]);
		}
		else if(ks.length == 1){
			f(ks[0]);
		}

		ans.writeln;
	}

}

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

alias Tree = RBT!int;

void main()
{
    GC.disable();

    uint T;
    readf(" %s\n", T);

    foreach (l; 0 .. T)
    {
        auto count = new int[100];
        char[] s = readln().strip.dup;

        foreach (e; s)
        {
            count[e - 'a']++;
        }

        char[] ans;

        foreach_reverse (c; 0 .. 30)
        {
            if (c % 2 == 0)
            {
                foreach (ii; 0 .. count[c])
                    ans ~= 'a' + c;
            }
        }

        foreach_reverse (c; 0 .. 30)
        {
            if (c % 2 == 1)
            {
                foreach (ii; 0 .. count[c])
                    ans ~= 'a' + c;
            }
        }

        bool flag = false;
        foreach (i, c; ans)
        {
            if (i < to!int(ans.length) - 1 && abs(ans[i] - ans[i + 1]) == 1)
            {
                flag = true;
                break;
            }
        }

        if (flag)
            writeln("No answer");
        else
            writeln(ans);

    }

}

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

alias Tree = RBT!int;

void main() {
    GC.disable();

    uint T;
    readf(" %s\n", T);

    foreach (l; 0 .. T) {
        auto count = new int[100];
        string s = readln().strip;
        auto s1 = s.filter!(e => (e - 'a') % 2 == 0).array().dup;
        auto s2 = s.filter!(e => (e - 'a') % 2 == 1).array().dup;
        sort(s1);
        sort(s2);

        auto c1 = s1 ~ s2;
        auto r1 = zip(c1[0 .. $ - 1], c1[1 .. $]).any!(a => abs(a[0] - a[1]) == 1);
        if (!r1) {
            writeln(c1);
            continue;
        }

        auto c2 = s2 ~ s1;
        auto r2 = zip(c2[0 .. $ - 1], c2[1 .. $]).any!(a => abs(a[0] - a[1]) == 1);
        if (!r2) {
            writeln(c2);
            continue;
        }

        writeln("No answer");
    }

}


Given a string s, process q queries, each having one of the following forms:  1 i c — Change the i-th character in the string to c.  2 l r y — Consider the substring of s starting at position l and ending at position r. Output the number of times y occurs as a substring in it.

The first line of the input contains the string s (1 ≤ |s| ≤ 105) of lowercase English letters. The second line contains an integer q (1 ≤ q ≤ 105)  — the number of queries to process. The next q lines describe the queries and may have one of the following forms:   1 i c (1 ≤ i ≤ |s|)  2 l r y (1 ≤ l ≤ r ≤ |s|)  c is a lowercase English letter and y is a non-empty string consisting of only lowercase English letters. The sum of |y| over all queries of second type is at most 105. It is guaranteed that there is at least one query of second type. All strings are 1-indexed. |s| is the length of the string s.

For each query of type 2, output the required answer in a separate line.

abcdcbc
5
2 1 7 bc
1 4 b
2 4 7 bc
1 2 a
2 1 4 aa

NoteConsider the first sample case. Initially, the string aba occurs 3 times in the range [1, 7]. Note that two occurrences may overlap. After the update, the string becomes ababcbaba and now aba occurs only once in the range [1, 7].

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

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

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

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

enum A = 26;

void main() {
  try {
    for (; ; ) {
      const S = readToken();
      const L = cast(int)(S.length);

      auto cs = S.dup;
      auto bas = new BitArray[A];
      foreach (a; 0 .. A) {
        bas[a] = BitArray(iota(L).map!(i => (cs[i] - 'a' == a)).array);
      }

      const Q = readInt();
      foreach (q; 0 .. Q) {
        const typ = readInt();
        switch (typ) {
          case 1: {
            const i = readInt() - 1;
            const c = readToken()[0];
            bas[cs[i] - 'a'].flip(i);
            cs[i] = c;
            bas[cs[i] - 'a'].flip(i);
          } break;
          case 2: {
            const l = readInt() - 1;
            const r = readInt();
            const y = readToken();
            const yLen = cast(int)(y.length);
            if (yLen > r - l) {
              writeln(0);
              continue;
            }
            auto b = bas[y[0] - 'a'].dup;
            b >>= l;
            debug {
              writeln("  ", b);
            }
            foreach (j; 1 .. yLen) {
              auto ba = bas[y[j] - 'a'].dup;
              ba >>= (l + j);
              b &= ba;
              debug {
                writeln("  ", b);
              }
            }
            debug {
              writeln("b = ", b);
              writeln("bas = ", bas);
            }
            int ans = b.count;
            b >>= (r - l - yLen + 1);
            ans -= b.count;
            writeln(ans);
          } break;
          default: assert(false);
        }
      }
    }
  } 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)); }

enum A = 26;

void main() {
  try {
    for (; ; ) {
      const S = readToken();
      const L = cast(int)(S.length);

      auto cs = S.dup;
      auto bas = new BitArray[A];
      foreach (a; 0 .. A) {
        bas[a] = BitArray(iota(L).map!(i => (cs[i] - 'a' == a)).array);
      }

      const Q = readInt();
      foreach (q; 0 .. Q) {
        const typ = readInt();
        switch (typ) {
          case 1: {
            const i = readInt() - 1;
            const c = readToken()[0];
            bas[cs[i] - 'a'].flip(i);
            cs[i] = c;
            bas[cs[i] - 'a'].flip(i);
          } break;
          case 2: {
            const l = readInt() - 1;
            const r = readInt();
            const y = readToken();
            const yLen = cast(int)(y.length);
            auto b = bas[y[0] - 'a'].dup;
            b >>= l;
            debug {
              writeln("  ", b);
            }
            foreach (j; 1 .. yLen) {
              auto ba = bas[y[j] - 'a'].dup;
              ba >>= (l + j);
              b &= ba;
              debug {
                writeln("  ", b);
              }
            }
            debug {
              writeln("b = ", b);
              writeln("bas = ", bas);
            }
            int ans = b.count;
            b >>= (r - l - yLen + 1);
            ans -= b.count;
            writeln(ans);
          } break;
          default: assert(false);
        }
      }
    }
  } 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)); }

enum A = 26;

void main() {
  try {
    for (; ; ) {
      const S = readToken();
      const L = cast(int)(S.length);

      auto cs = S.dup;
      auto bas = new BitArray[A];
      foreach (a; 0 .. A) {
        bas[a] = BitArray(iota(L).map!(i => (cs[i] - 'a' == a)).array);
      }

      const Q = readInt();
      foreach (q; 0 .. Q) {
        const typ = readInt();
        switch (typ) {
          case 1: {
            const i = readInt() - 1;
            const c = readToken()[0];
            bas[cs[i] - 'a'].flip(i);
            cs[i] = c;
            bas[cs[i] - 'a'].flip(i);
          } break;
          case 2: {
            const l = readInt() - 1;
            const r = readInt();
            const y = readToken();
            const yLen = cast(int)(y.length);
            auto b = bas[y[0] - 'a'].dup;
            b >>= l;
            debug {
              writeln("  ", b);
            }
            foreach (j; 1 .. yLen) {
              auto ba = bas[y[j] - 'a'].dup;
              ba >>= (l + j);
              b &= ba;
              debug {
                writeln("  ", b);
              }
            }
            debug {
              writeln("b = ", b);
              writeln("bas = ", bas);
            }
            int ans = b.count;
            b >>= (r - l - yLen + 1);
            ans -= b.count;
            writeln(ans);
if(ans==97781)writeln(q," ",l," ",r," ",y);
          } break;
          default: assert(false);
        }
      }
    }
  } catch (EOFException e) {
  }
}


Jack has become a soldier now. Unfortunately, he has trouble with the drill. Instead of marching beginning with the left foot and then changing legs with each step, as ordered, he keeps repeating a sequence of steps, in which he sometimes makes the wrong steps or — horror of horrors! — stops for a while. For example, if Jack uses the sequence 'right, left, break', when the sergeant yells: 'Left! Right! Left! Right! Left! Right!', Jack first makes a step with the right foot, then one with the left foot, then he is confused and stops for a moment, then again - this time according to the order - starts with the right foot, then uses the left foot, then - to the sergeant's irritation - he stops to catch his breath, to incorrectly start with the right foot again... Marching this way, Jack will make the step that he is supposed to in the given moment in only one third of cases.When the officers convinced him he should do something about it, Jack decided to modify the basic sequence of steps that he repeats. However, in order not to get too tired, he has decided that the only thing he'll do is adding any number of breaks in any positions of the original sequence (a break corresponds to stopping for the duration of one step). Of course, Jack can't make a step on the same foot twice in a row, if there is no pause between these steps. It is, however, not impossible that the sequence of steps he used so far is incorrect (it would explain a lot, actually).Help Private Jack! Given the sequence of steps he keeps repeating, calculate the maximal percentage of time that he can spend marching correctly after adding some breaks to his scheme.

The first line of input contains a sequence consisting only of characters 'L', 'R' and 'X', where 'L' corresponds to a step with the left foot, 'R' — with the right foot, and 'X' — to a break. The length of the sequence will not exceed 106.

Output the maximum percentage of time that Jack can spend marching correctly, rounded down to exactly six digits after the decimal point.

NoteIn the second example, if we add two breaks to receive LXXRXR, Jack will march: LXXRXRLXXRXRL... instead of LRLRLRLRLRLRL... and will make the correct step in half the cases. If we didn't add any breaks, the sequence would be incorrect — Jack can't step on his right foot twice in a row.

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

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

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

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

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

immutable long ONE = 100_000_000;
immutable long INF = 1_000_000_000;

// int[] doIt(in int[] ds) {
	// int[] costs = INF ~ ds.dup ~ INF;
int[] doIt(int[] ds) {
	int[] costs = INF ~ ds ~ INF;
	const int n = costs.length;
	int[] lef = new int[n];
	int[] rig = new int[n];
	foreach (i; 0 .. n) {
		lef[i] = i - 1;
		rig[i] = i + 1;
	}
	// auto q = BinaryHeap!(Array!(Pair!(int, int)), "a.x > b.x")();
	auto q = BinaryHeap!(Pair!(int, int)[], "a.x > b.x")(new Pair!(int, int)[n + n / 2], 0);
	foreach (i; 0 .. n) {
		q.insert(Pair!(int, int)(costs[i], i));
	}
	int[] ret = [ 0 ];
	for (; !q.empty; ) {
		const c = q.front.x;
		const i = q.front.y;
		q.removeFront;
		if (lef[i] == -2 || rig[i] == -2) {
			continue;
		}
		if (c >= INF) {
			break;
		}
// writeln(c," ",i);
		ret ~= ret[$ - 1] + c;
		const li = lef[i];
		const ri = rig[i];
		lef[i] = lef[li];
		rig[i] = rig[ri];
		if (0 <= lef[i]) {
			rig[lef[i]] = i;
		}
		if (rig[i] < n) {
			lef[rig[i]] = i;
		}
		lef[li] = rig[li] = lef[ri] = rig[ri] = -2;
		if (0 <= lef[i] && rig[i] < n) {
			costs[i] = costs[li] + costs[ri] - costs[i];
			q.insert(Pair!(int, int)(costs[i], i));
		}
	}
	return ret;
}

long solve(in string s) {
debug{
writeln("s = ",s);
}
	const int n = s.length;
	long ret;

	//	even
	{
		int[] ds = [ 0 ];
		foreach (i, c; s) if (c != 'X') {
			const side = ("LR"[i % 2] == c) ? 0 : 1;
			for (; (ds.length - 1) % 2 != side; ) {
				ds ~= 0;
			}
			++ds[$ - 1];
		}
debug{
writeln("ds = ",ds);
}
		const int len = ds.length;
		const int dsSum = reduce!"a + b"(0, ds);
		ds = 0 ~ ds;
		if (n % 2 == 0) {
			if (len % 2 == 0) {
				//
			} else {
				ds ~= 0;
			}
		} else {
			if (len % 2 == 0) {
				ds ~= 0;
			} else {
				//
			}
		}
debug{
writeln("ds = ",ds);
}
		int[] res = doIt(ds);
debug{
writeln("doIt = ",res);
}
		foreach (k, cost; res) {
			//	k = number of batsu's
			const nmr = dsSum - cost;
			int dnm = n;
			int numPairs;
			if (n % 2 == 0) {
				if (len % 2 == 0) {
					numPairs = len / 2 - (k - 1);
					dnm += numPairs * 2;
				} else {
					numPairs = len / 2 - (k - 2);
					dnm += numPairs * 2;
				}
			} else {
				if (len % 2 == 0) {
					numPairs = len / 2 - 1 - (k - 2);
					dnm += numPairs * 2 + 1;
				} else {
					numPairs = len / 2 - (k - 1);
					dnm += numPairs * 2 + 1;
				}
			}
			if (numPairs >= 0) {
debug{
writeln("numPairs = ",numPairs," : ",nmr,"/",dnm," = ",nmr/cast(real)(dnm));
}
				chmax(ret, ONE * nmr / dnm);
			}
		}
	}

	//	odd
	{
		const nmr = s.count!"a != 'X'";
		int dnm = n;
		if (dnm % 2 == 0) {
			++dnm;
		}
		dnm *= 2;
		chmax(ret, ONE * nmr / dnm);
	}

	return ret;
}

string S;

void main(string[] args) {
	try {
	for (; ; ) {
		S = readToken;
// char[]cs=new char[1_000_000];for(int i=0;i<1_000_000;i+=4){cs[i]='L';cs[i+1]='X';cs[i+2]='R';cs[i+3]='X';}S=cs.to!string~"L";

		string s;
		foreach (i, c; S) {
			if (c != 'X' && !s.empty && s[$ - 1] == c) {
				s ~= 'X';
			}
			s ~= c;
		}

		long ans;
		if (s[0] != 'X' && s[0] == s[$ - 1]) {
			chmax(ans, solve('X' ~ s));
			chmax(ans, solve(s ~ 'X'));
		} else {
			chmax(ans, solve(s));
		}
		writefln("%.6f", ans / 1e+6);

	}
	} catch (EOFException) {}
}

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

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

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

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

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

immutable long ONE = 100_000_000;

int N;
string S;

void main(string[] args) {
	try {
	for (; ; ) {
		S = readToken;
		N = S.length;

		long ans;

		//	even
		{
			int nmr;
			foreach (i; 0 .. N) {
				if (S[i] != 'X') {
					++nmr;
				}
			}
			foreach (start; 0 .. 2) {
				int dnm;
				if (start == 1) {
					if (S[N - 1] != 'X' && S[N - 1] == S[0]) {
						++dnm;
					}
				}
				foreach (i; 0 .. N) {
// writeln(i," ",dnm);
					if (S[i] != 'X') {
						if (i > 0 && S[i - 1] == S[i]) {
							++dnm;
						}
						if (S[i] != "LR"[dnm % 2]) {
							++dnm;
						}
					}
					++dnm;
				}
				if (start == 0) {
					if (S[N - 1] != 'X' && S[N - 1] == S[0]) {
						++dnm;
					}
				}
				if (dnm % 2 != 0) {
					++dnm;
				}
// writeln(nmr,"/",dnm);
				chmax(ans, ONE * nmr / dnm);
			}
		}

		//	odd
		{
			int nmr;
			foreach (i; 0 .. N) {
				if (S[i] != 'X') {
					++nmr;
				}
			}
			int dnm = N;
			foreach (i; 0 .. N) {
				if (S[i] != 'X' && S[i] == S[(i + 1) % N]) {
					++dnm;
				}
			}
			if (dnm % 2 == 0) {
				++dnm;
			}
			dnm *= 2;
			chmax(ans, ONE * nmr / dnm);
		}

		writefln("%.6f", ans / 1e+6);

	}
	} catch (EOFException) {}
}

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

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

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

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

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

immutable long ONE = 100_000_000;
immutable long INF = 1_000_000_000;

// int[] doIt(in int[] ds) {
	// int[] costs = INF ~ ds.dup ~ INF;
int[] doIt(int[] ds) {
	int[] costs = INF ~ ds ~ INF;
	const int n = costs.length;
	int[] lef = new int[n];
	int[] rig = new int[n];
	foreach (i; 0 .. n) {
		lef[i] = i - 1;
		rig[i] = i + 1;
	}
	// auto q = BinaryHeap!(Array!(Pair!(int, int)), "a.x > b.x")();
	auto q = BinaryHeap!(Pair!(int, int)[], "a.x > b.x")(new Pair!(int, int)[n + n / 2], 0);
	foreach (i; 0 .. n) {
		q.insert(Pair!(int, int)(costs[i], i));
	}
	int[] ret = [ 0 ];
	for (; !q.empty; ) {
		const c = q.front.x;
		const i = q.front.y;
		q.removeFront;
		if (lef[i] == -2 || rig[i] == -2) {
			continue;
		}
		if (c >= INF) {
			break;
		}
// writeln(c," ",i);
		ret ~= ret[$ - 1] + c;
		const li = lef[i];
		const ri = rig[i];
		lef[i] = lef[li];
		rig[i] = rig[ri];
		if (0 <= lef[i]) {
			rig[lef[i]] = i;
		}
		if (rig[i] < n) {
			lef[rig[i]] = i;
		}
		lef[li] = rig[li] = lef[ri] = rig[ri] = -2;
		if (0 <= lef[i] && rig[i] < n) {
			costs[i] = costs[li] + costs[ri] - costs[i];
			q.insert(Pair!(int, int)(costs[i], i));
		}
	}
	return ret;
}

long solve(in string s) {
// writeln("s = ",s);
	const int n = s.length;
	long ret;

	//	even
	{
		int[] ds;
		foreach (i, c; s) if (c != 'X') {
			const side = ("LR"[i % 2] == c) ? 0 : 1;
			if (ds.empty || (ds.length - 1) % 2 != side) {
				ds ~= 0;
			}
			++ds[$ - 1];
		}
// writeln("ds = ",ds);
		const int len = ds.length;
		const int dsSum = reduce!"a + b"(0, ds);
		ds = 0 ~ ds;
		if (n % 2 == 0) {
			if (len % 2 == 0) {
				//
			} else {
				ds ~= 0;
			}
		} else {
			if (len % 2 == 0) {
				ds ~= 0;
			} else {
				//
			}
		}
// writeln("ds = ",ds);
		int[] res = doIt(ds);
// writeln("doIt = ",res);
		foreach (k, cost; res) {
			//	k = number of batsu's
			const nmr = dsSum - cost;
			int dnm = n;
			int numPairs;
			if (n % 2 == 0) {
				if (len % 2 == 0) {
					numPairs = len / 2 - (k - 1);
					dnm += numPairs * 2;
				} else {
					numPairs = len / 2 - (k - 2);
					dnm += numPairs * 2;
				}
			} else {
				if (len % 2 == 0) {
					numPairs = len / 2 - 1 - (k - 2);
					dnm += numPairs * 2 + 1;
				} else {
					numPairs = len / 2 - (k - 1);
					dnm += numPairs * 2 + 1;
				}
			}
			if (numPairs >= 0) {
// writeln("numPairs = ",numPairs," : ",nmr,"/",dnm);
				chmax(ret, ONE * nmr / dnm);
			}
		}
	}

	//	odd
	{
		const nmr = s.count!"a != 'X'";
		int dnm = n;
		if (dnm % 2 == 0) {
			++dnm;
		}
		dnm *= 2;
		chmax(ret, ONE * nmr / dnm);
	}

	return ret;
}

string S;

void main(string[] args) {
	try {
	for (; ; ) {
		S = readToken;
// char[]cs=new char[1_000_000];for(int i=0;i<1_000_000;i+=4){cs[i]='L';cs[i+1]='X';cs[i+2]='R';cs[i+3]='X';}S=cs.to!string~"L";

		string s;
		foreach (i, c; S) {
			if (c != 'X' && !s.empty && s[$ - 1] == c) {
				s ~= 'X';
			}
			s ~= c;
		}

		long ans;
		if (s[0] != 'X' && s[0] == s[$ - 1]) {
			chmax(ans, solve('X' ~ s));
			chmax(ans, solve(s ~ 'X'));
		} else {
			chmax(ans, solve(s));
		}
		writefln("%.6f", ans / 1e+6);

	}
	} catch (EOFException) {}
}

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

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

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

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

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

immutable long ONE = 100_000_000;
immutable long INF = 1_000_000_000;

// int[] doIt(in int[] ds) {
	// int[] costs = INF ~ ds.dup ~ INF;
int[] doIt(int[] ds) {
	int[] costs = INF ~ ds ~ INF;
	const int n = costs.length;
	int[] lef = new int[n];
	int[] rig = new int[n];
	foreach (i; 0 .. n) {
		lef[i] = i - 1;
		rig[i] = i + 1;
	}
	// auto q = BinaryHeap!(Array!(Pair!(int, int)), "a.x > b.x")();
	auto q = BinaryHeap!(Pair!(int, int)[], "a.x > b.x")(new Pair!(int, int)[n + n / 2], 0);
	foreach (i; 0 .. n) {
		q.insert(Pair!(int, int)(costs[i], i));
	}
	int[] ret = [ 0 ];
	for (; !q.empty; ) {
		const c = q.front.x;
		const i = q.front.y;
		q.removeFront;
		if (lef[i] == -2 || rig[i] == -2) {
			continue;
		}
		if (c >= INF) {
			break;
		}
// writeln(c," ",i);
		ret ~= ret[$ - 1] + c;
		const li = lef[i];
		const ri = rig[i];
		lef[i] = lef[li];
		rig[i] = rig[ri];
		if (0 <= lef[i]) {
			rig[lef[i]] = i;
		}
		if (rig[i] < n) {
			lef[rig[i]] = i;
		}
		lef[li] = rig[li] = lef[ri] = rig[ri] = -2;
		if (0 <= lef[i] && rig[i] < n) {
			costs[i] = costs[li] + costs[ri] - costs[i];
			q.insert(Pair!(int, int)(costs[i], i));
		}
	}
	return ret;
}

long solve(in string s) {
debug{
writeln("s = ",s);
}
	const int n = s.length;
	long ret;

	//	even
	{
		int[] ds = [ 0 ];
		foreach (i, c; s) if (c != 'X') {
			const side = ("LR"[i % 2] == c) ? 0 : 1;
			for (; (ds.length - 1) % 2 != side; ) {
				ds ~= 0;
			}
			++ds[$ - 1];
		}
debug{
writeln("ds = ",ds);
}
		const int len = ds.length;
		const int dsSum = reduce!"a + b"(0, ds);
		ds = 0 ~ ds;
		if (n % 2 == 0) {
			if (len % 2 == 0) {
				//
			} else {
				ds ~= 0;
			}
		} else {
			if (len % 2 == 0) {
				ds ~= 0;
			} else {
				//
			}
		}
debug{
writeln("ds = ",ds);
		int[] res = doIt(ds);
debug{
writeln("doIt = ",res);
}
		foreach (k, cost; res) {
			//	k = number of batsu's
			const nmr = dsSum - cost;
			int dnm = n;
			int numPairs;
			if (n % 2 == 0) {
				if (len % 2 == 0) {
					numPairs = len / 2 - (k - 1);
					dnm += numPairs * 2;
				} else {
					numPairs = len / 2 - (k - 2);
					dnm += numPairs * 2;
				}
			} else {
				if (len % 2 == 0) {
					numPairs = len / 2 - 1 - (k - 2);
					dnm += numPairs * 2 + 1;
				} else {
					numPairs = len / 2 - (k - 1);
					dnm += numPairs * 2 + 1;
				}
			}
			if (numPairs >= 0) {
debug{
writeln("numPairs = ",numPairs," : ",nmr,"/",dnm," = ",nmr/cast(real)(dnm));}
}
				chmax(ret, ONE * nmr / dnm);
			}
		}
	}

	//	odd
	{
		const nmr = s.count!"a != 'X'";
		int dnm = n;
		if (dnm % 2 == 0) {
			++dnm;
		}
		dnm *= 2;
		chmax(ret, ONE * nmr / dnm);
	}

	return ret;
}

string S;

void main(string[] args) {
	try {
	for (; ; ) {
		S = readToken;
// char[]cs=new char[1_000_000];for(int i=0;i<1_000_000;i+=4){cs[i]='L';cs[i+1]='X';cs[i+2]='R';cs[i+3]='X';}S=cs.to!string~"L";

		string s;
		foreach (i, c; S) {
			if (c != 'X' && !s.empty && s[$ - 1] == c) {
				s ~= 'X';
			}
			s ~= c;
		}

		long ans;
		if (s[0] != 'X' && s[0] == s[$ - 1]) {
			chmax(ans, solve('X' ~ s));
			chmax(ans, solve(s ~ 'X'));
		} else {
			chmax(ans, solve(s));
		}
		writefln("%.6f", ans / 1e+6);

	}
	} catch (EOFException) {}
}

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

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

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

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

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

immutable long ONE = 100_000_000;

int N;
string S;

void main(string[] args) {
	try {
	for (; ; ) {
		S = readToken;
		N = S.length;

		long ans;

		//	even
		foreach (lr; 0 .. 2) {
			int nmr;
			foreach (i; 0 .. N) {
				if (S[i] != 'X') {
					++nmr;
				}
			}
			foreach (start; 0 .. 2) {
				int dnm;
				if (start == 1) {
					if (S[N - 1] != 'X' && S[N - 1] == S[0]) {
						++dnm;
					}
				}
				foreach (i; 0 .. N) {
// writeln(i," ",dnm);
					if (S[i] != 'X') {
						if (i > 0 && S[i - 1] == S[i]) {
							++dnm;
						}
						if (S[i] != "LR"[(lr + dnm) % 2]) {
							++dnm;
						}
					}
					++dnm;
				}
				if (start == 0) {
					if (S[N - 1] != 'X' && S[N - 1] == S[0]) {
						++dnm;
					}
				}
				if (dnm % 2 != 0) {
					++dnm;
				}
// writeln(nmr,"/",dnm);
				chmax(ans, ONE * nmr / dnm);
			}
		}

		//	odd
		{
			int nmr;
			foreach (i; 0 .. N) {
				if (S[i] != 'X') {
					++nmr;
				}
			}
			int dnm = N;
			foreach (i; 0 .. N) {
				if (S[i] != 'X' && S[i] == S[(i + 1) % N]) {
					++dnm;
				}
			}
			if (dnm % 2 == 0) {
				++dnm;
			}
			dnm *= 2;
			chmax(ans, ONE * nmr / dnm);
		}

		writefln("%.6f", ans / 1e+6);

	}
	} catch (EOFException) {}
}