A brick is defined as a rectangle with integer side lengths with either width $$$1$$$ or height $$$1$$$ (or both).There is an $$$n\times m$$$ grid, and each cell is colored either black or white. A tiling is a way to place bricks onto the grid such that each black cell is covered by exactly one brick, and each white cell is not covered by any brick. In other words, bricks are placed on black cells only, cover all black cells, and no two bricks overlap.  An example tiling of the first test case using $$$5$$$ bricks. It is possible to do better, using only $$$4$$$ bricks. What is the minimum number of bricks required to make a valid tiling?

The first line contains two integers $$$n$$$, $$$m$$$ ($$$1\le n, m\le 200$$$) — the number of rows and columns, respectively. The next $$$n$$$ lines describe the grid. 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$$$, column $$$j$$$. A black cell is given by "#", and a white cell is given by ".". It is guaranteed that there is at least one black cell.

Output a single integer, the minimum number of bricks required.

NoteThe first test case can be tiled with $$$4$$$ bricks placed vertically.The third test case can be tiled with $$$18$$$ bricks like this:

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

class MaxFlow(Capa) {
  enum Capa wEPS = 0;
  enum Capa wINF = 10^^9;
  int n, m;
  int[][] g;
  int[] zu;
  Capa[] capa;
  Capa tof;
  int[] lev, see, que;
  this(int n) {
    this.n = n; m = 0; g = new int[][n]; zu = []; capa = [];
    lev = new int[n]; see = new int[n]; que = new int[n];
  }
  void addEdge(int u, int v, Capa w0, Capa w1 = 0) {
    g[u] ~= m; zu ~= v; capa ~= w0; ++m;
    g[v] ~= m; zu ~= u; capa ~= w1; ++m;
  }
  Capa augment(int src, int ink, Capa flo) {
    if (src == ink) return flo;
    foreach (i; g[src][see[src] .. $]) {
      if (capa[i] > wEPS && lev[src] < lev[zu[i]]) {
        Capa f = augment(zu[i], ink, min(flo, capa[i]));
        if (f > wEPS) { capa[i] -= f; capa[i ^ 1] += f; return f; }
      }
      ++see[src];
    }
    return 0;
  }
  bool dinic(int src, int ink, Capa flo = wINF) {
    for (tof = 0; tof + wEPS < flo; ) {
      int qb, qe;
      lev[] = -1;
     dinicBFS:
      for (lev[src] = 0, que[qe++] = src; qb != qe; ) {
        const u = que[qb++];
        foreach (i; g[u]) {
          const v = zu[i];
          if (capa[i] > wEPS && lev[v] == -1) {
            lev[v] = lev[u] + 1; que[qe++] = v;
            if (v == ink) break dinicBFS;
          }
        }
      }
      if (lev[ink] == -1) return false;
      see[] = 0;
      for (; ; ) {
        Capa f = augment(src, ink, flo - tof);
        if (f <= wEPS) break;
        tof += f;
      }
    }
    return true;
  }
}

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

      int num;
      auto ids = new int[][](M, N);
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        if (A[x][y] == '#') {
          ids[x][y] = num++;
        } else {
          ids[x][y] = -1;
        }
      }

      auto mf = new MaxFlow!int(num + 2);
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        if (ids[x][y] != -1) {
          if (x == 0 || ids[x - 1][y] == -1) {
            mf.addEdge(ids[x][y], num + 1, 1);
          }
          if (x == M - 1 || ids[x + 1][y] == -1) {
            mf.addEdge(ids[x][y], num + 1, 1);
          }
          if (y == 0 || ids[x][y - 1] == -1) {
            mf.addEdge(num, ids[x][y], 1);
          }
          if (y == N - 1 || ids[x][y + 1] == -1) {
            mf.addEdge(num, ids[x][y], 1);
          }
        }
      }
      foreach (x; 0 .. M - 1) foreach (y; 0 .. N) {
        if (ids[x][y] != -1 && ids[x + 1][y] != -1) {
          mf.addEdge(ids[x][y], ids[x + 1][y], 1, 1);
        }
      }
      foreach (x; 0 .. M) foreach (y; 0 .. N - 1) {
        if (ids[x][y] != -1 && ids[x][y + 1] != -1) {
          mf.addEdge(ids[x][y], ids[x][y + 1], 1, 1);
        }
      }
      mf.dinic(num, num + 1);
      assert(mf.tof % 2 == 0);
      writeln(mf.tof / 2);
    }
  } catch (EOFException e) {
  }
}


This is an interactive problem.I want to play a game with you...We hid from you a cyclic graph of $$$n$$$ vertices ($$$3 \le n \le 10^{18}$$$). A cyclic graph is an undirected graph of $$$n$$$ vertices that form one cycle. Each vertex belongs to the cycle, i.e. the length of the cycle (the number of edges in it) is exactly $$$n$$$. The order of the vertices in the cycle is arbitrary.You can make queries in the following way: "? a b" where $$$1 \le a, b \le 10^{18}$$$ and $$$a \neq b$$$. In response to the query, the interactor outputs on a separate line the length of random of two paths from vertex $$$a$$$ to vertex $$$b$$$, or -1 if $$$\max(a, b) > n$$$. The interactor chooses one of the two paths with equal probability. The length of the path —is the number of edges in it.You win if you guess the number of vertices in the hidden graph (number $$$n$$$) by making no more than $$$50$$$ queries.Note that the interactor is implemented in such a way that for any ordered pair $$$(a, b)$$$, it always returns the same value for query "? a b", no matter how many such queries. Note that the "? b a" query may be answered differently by the interactor.The vertices in the graph are randomly placed, and their positions are fixed in advance.Hacks are forbidden in this problem. The number of tests the jury has is $$$50$$$.

NoteIn the first example, the graph could look like this  The lengths of the simple paths between all pairs of vertices in this case are $$$1$$$ or $$$2$$$.   The first query finds out that one of the simple paths from vertex $$$1$$$ to vertex $$$2$$$ has a length of $$$1$$$.  With the second query, we find out that one of the simple paths from vertex $$$1$$$ to vertex $$$3$$$ has length $$$2$$$.  In the third query, we find out that vertex $$$4$$$ is not in the graph. Consequently, the size of the graph is $$$3$$$.

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    for (int y = 1; ; y++) {
        for (int x = 1; x < y; x++) {
            writefln("? %d %d", x, y);
            stdout.flush;
            long l = readln.chomp.to!long;
            if (l == 0) return;
            writefln("? %d %d", y, x);
            stdout.flush;
            long r = readln.chomp.to!long;
            if (r == 0) return;
            if (l < 0 || r < 0) {
                writefln("! %d", y - 1);
                return;
            }
            if (l != r) {
                writefln("! %d", l + r);
                return;
            }
        }
    }
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    for (int y = 1; ; y++) {
        for (int x = 1; x < y; x++) {
            writefln("? %d %d", x, y);
            stdout.flush;
            long l;
            scanf("%Ld", &l);
            if (l == 0) return;
            writefln("? %d %d", y, x);
            stdout.flush;
            long r;
            scanf("%Ld", &r);
            if (r == 0) return;
            if (l < 0 || r < 0) {
                writefln("! %d", y - 1);
                return;
            }
            if (l != r) {
                writefln("! %d", l + r);
                return;
            }
        }
    }
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    for (int y = 1; ; y++) {
        for (int x = 1; x < y; x++) {
            writefln("? %d %d", x, y);
            stdout.flush;
            int l;
            scanf("%d", &l);
            if (l == 0) return;
            writefln("? %d %d", y, x);
            stdout.flush;
            int r;
            scanf("%d", &r);
            if (r == 0) return;
            if (l < 0 || r < 0) {
                if (y == 3) {
                    writefln("! %d", l);
                    return;
                }
                writefln("! %d", y - 1);
                return;
            }
            if (l != r) {
                writefln("! %d", l + r);
                return;
            }
        }
    }
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    for (int y = 1; ; y++) {
        for (int x = 1; x < y; x++) {
            writefln("? %d %d", x, y);
            stdout.flush;
            int l;
            scanf("%d", &l);
            if (l == 0) return;
            writefln("? %d %d", y, x);
            stdout.flush;
            int r;
            scanf("%d", &r);
            if (r == 0) return;
            if (l < 0 || r < 0) {
                if (y == 3) {
                    writefln("! %d", x);
                    return;
                }
                writefln("! %d", y - 1);
                return;
            }
            if (l != r) {
                writefln("! %d", l + r);
                return;
            }
        }
    }
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    for (int y = 1; ; y++) {
        for (int x = 1; x < y; x++) {
            writefln("? %d %d", x, y);
            stdout.flush;
            int l;
            scanf("%d", &l);
            if (l == 0) return;
            writefln("? %d %d", y, x);
            stdout.flush;
            int r;
            scanf("%d", &r);
            if (r == 0) return;
            if (l < 0 || r < 0) {
                writefln("! %d", max(x, y) - 1);
                return;
            }
            if (l != r) {
                writefln("! %d", l + r);
                return;
            }
        }
    }
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    for (int y = 1; ; y++) {
        for (int x = 1; x < y; x++) {
            writefln("? %d %d", x, y);
            stdout.flush;
            int l;
            scanf("%d", &l);
            if (l == 0) return;
            writefln("? %d %d", y, x);
            stdout.flush;
            int r;
            scanf("%d", &r);
            if (r == 0) return;
            if (l < 0 || r < 0) {
                writefln("! %d", y - 1);
                return;
            }
            if (l != r) {
                if (l + r == 2) {
                    writefln("! %d", r);
                    return;
                }
                writefln("! %d", l + r);
                return;
            }
        }
    }
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    for (int y = 1; ; y++) {
        for (int x = 1; x < y; x++) {
            writefln("? %d %d", x, y);
            stdout.flush;
            int l;
            scanf("%d", &l);
            if (l == 0) return;
            writefln("? %d %d", y, x);
            stdout.flush;
            int r;
            scanf("%d", &r);
            if (r == 0) return;
            if (l < 0 || r < 0) {
                writefln("! %d", y - 1);
                return;
            }
            if (l != r) {
                if (l + r == 2) {
                    writefln("! %d", l);
                    return;
                }
                writefln("! %d", l + r);
                return;
            }
        }
    }
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    for (int y = 1; ; y++) {
        for (int x = 1; x < y; x++) {
            writefln("? %d %d", x, y);
            stdout.flush;
            int l;
            scanf("%d", &l);
            if (l == 0) return;
            writefln("? %d %d", y, x);
            stdout.flush;
            int r;
            scanf("%d", &r);
            if (r == 0) return;
            if (l < 0 || r < 0) {
                writefln("! %d", y - 1);
                return;
            }
            if (l != r) {
                writefln("! %d", l + r);
                return;
            }
        }
    }
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    for (int y = 1; ; y++) {
        for (int x = 1; x < y; x++) {
            writefln("? %d %d", x, y);
            stdout.flush;
            int l;
            scanf("%d", &l);
            if (l == 0) return;
            if (l < 0) {
                writefln("! %d", y - 1);
                return;
            }
            writefln("? %d %d", y, x);
            stdout.flush;
            int r;
            scanf("%d", &r);
            if (r == 0) return;
            if (l != r) {
                writefln("! %d", l + r);
                return;
            }
        }
    }
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    auto x = new int[25], y = new int[25];
    for (int i = 1; i <= 25; i++) {
        writefln("? %d %d", 1, i+1);
        stdout.flush();
        scanf("%d", &x[i-1]);
        if (x[i-1] == 0) break;
        if (x[i-1] < 0) {
            writefln("! %d", i);
            return;
        }
        writefln("? %d %d", i+1, 1);
        stdout.flush();
        scanf("%d", &y[i-1]);
        if (y[i-1] == 0) break;
        if (x[i-1] != y[i-1]) {
            auto ans = x[i-1] + y[i-1];
            writefln("! %d", ans);
            return;
        }
    }
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    auto x = new int[25], y = new int[25];
    int ans = -1;
    for (int i = 1; i <= 25; i++) {
        writefln("? %d %d", 1, i+1);
        stdout.flush();
        scanf("%d", &x[i-1]);
        if (x[i-1] == 0) break;
        if (x[i-1] < 0) {
            ans = i;
            break;
        }
        writefln("? %d %d", i+1, 1);
        stdout.flush();
        scanf("%d", &y[i-1]);
        if (y[i-1] == 0) break;
        if (x[i-1] != y[i-1]) {
            ans = x[i-1] + y[i-1];
            break;
        }
    }
    writefln("! %d", ans);
    stderr.writeln(x);
    stderr.writeln(y);
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    auto x = new int[25], y = new int[25];
    writeln("! 1");
    return;
    int ans = -1;
    for (int i = 1; i <= 25; i++) {
        writefln("? %d %d", 1, i+1);
        stdout.flush();
        scanf("%d", &x[i-1]);
        if (x[i-1] == 0) break;
        if (x[i-1] < 0) {
            ans = i;
            break;
        }
        writefln("? %d %d", i+1, 1);
        stdout.flush();
        scanf("%d", &y[i-1]);
        if (y[i-1] == 0) break;
        if (x[i-1] != y[i-1]) {
            ans = x[i-1] + y[i-1];
            break;
        }
    }
    writefln("! %d", ans);
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    auto x = new int[25], y = new int[25];
    int ans = -1;
    for (int i = 1; i <= 25; i++) {
        writefln("? %d %d", 1, i+1);
        stdout.flush();
        scanf("%d", &x[i-1]);
        if (x[i-1] == 0) break;
        if (x[i-1] < 0) {
            ans = i;
            break;
        }
        writefln("? %d %d", i+1, 1);
        stdout.flush();
        scanf("%d", &y[i-1]);
        if (y[i-1] == 0) break;
        if (x[i-1] != y[i-1]) {
            ans = x[i-1] + y[i-1];
            break;
        }
    }
    writefln("! %d", ans);
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    auto x = new int[25], y = new int[25];
    int ans = -1;
    for (int i = 1; i <= 25; i++) {
        writefln("? %d %d", 1, i+1);
        stdout.flush();
        scanf("%d", &x[i-1]);
        if (x[i-1] == 0) assert(false);
        if (x[i-1] < 0) {
            ans = i;
            break;
        }
        writefln("? %d %d", i+1, 1);
        stdout.flush();
        scanf("%d", &y[i-1]);
        if (y[i-1] == 0) assert(false);
        if (x[i-1] != y[i-1]) {
            ans = x[i-1] + y[i-1];
            break;
        }
    }
    writefln("! %d", ans);
    stdout.flush();
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    auto x = new int[25], y = new int[25];
    int ans = -1;
    for (int i = 1; i <= 25; i++) {
        writefln("? %d %d", 1, i+1);
        stdout.flush();
        scanf("%d", &x[i-1]);
        if (x[i-1] == 0) assert(false);
        if (x[i-1] < 0) {
            ans = i;
            break;
        }
        writefln("? %d %d", i+1, 1);
        stdout.flush();
        scanf("%d", &y[i-1]);
        if (y[i-1] == 0) assert(false);
        if (x[i-1] != y[i-1]) {
            ans = x[i-1] + y[i-1];
            break;
        }
    }
    writefln("! %d", ans);
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    auto x = new int[25], y = new int[25];
    int ans = -1;
    for (int i = 1; i <= 25; i++) {
        writefln("? %d %d", 1, i+1);
        stdout.flush();
        scanf("%d", &x[i-1]);
        if (x[i-1] == 0) return;
        if (x[i-1] < 0) {
            ans = i;
            break;
        }
        writefln("? %d %d", i+1, 1);
        stdout.flush();
        scanf("%d", &y[i-1]);
        if (y[i-1] == 0) return;
        if (x[i-1] != y[i-1]) {
            ans = x[i-1] + y[i-1];
            break;
        }
    }
    writefln("! %d", ans);
}

import std.stdio;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    auto x = new int[25], y = new int[25];
    int ans = -1;
    for (int i = 1; i <= 25; i++) {
        writefln("? %d %d", 1, i+1);
        stdout.flush();
        scanf("%d", &x[i-1]);
        if (x[i-1] == 0) return;
        writefln("? %d %d", i+1, 1);
        stdout.flush();
        scanf("%d", &y[i-1]);
        if (y[i-1] == 0) return;
        if (x[i-1] < 0) {
            ans = i;
            break;
        }
        if (x[i-1] != y[i-1]) {
            ans = x[i-1] + y[i-1];
            break;
        }
    }
    writefln("! %d", ans);
}


3R2 - Standby for ActionOur dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. $$$n$$$"!The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The show ends when only JOE remains (we assume that JOE never answers a question wrong!).For each question JOE answers, if there are $$$s$$$ ($$$s > 0$$$) opponents remaining and $$$t$$$ ($$$0 \le t \le s$$$) of them make a mistake on it, JOE receives $$$\displaystyle\frac{t}{s}$$$ dollars, and consequently there will be $$$s - t$$$ opponents left for the next question.JOE wonders what is the maximum possible reward he can receive in the best possible scenario. Yet he has little time before show starts, so can you help him answering it instead?

The first and single line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$), denoting the number of JOE's opponents in the show.

Print a number denoting the maximum prize (in dollars) JOE could have. Your answer will be considered correct if it's absolute or relative error won't exceed $$$10^{-4}$$$. In other words, if your answer is $$$a$$$ and the jury answer is $$$b$$$, then it must hold that $$$\frac{|a - b|}{max(1, b)} \le 10^{-4}$$$.

NoteIn the second example, the best scenario would be: one contestant fails at the first question, the other fails at the next one. The total reward will be $$$\displaystyle \frac{1}{2} + \frac{1}{1} = 1.5$$$ dollars.

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

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

    double ans = 0;
    foreach (e; (n+1).iota.dropOne) {
        ans += 1.0 / e;
    }

    writefln("%.10f", ans);
}

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

DList!string _words;

void read(T...)(ref T t)
{
  void singleRead(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);
  }
  static foreach(i; 0 .. T.length)
    {
      static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))
        {
          foreach(ref element; t[i])
            read(element);
        }
      else
        {
          singleRead(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 = E.init)
{
  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;
}

void main()
{
  writeln(iota(long(1), long(next!long + 1)).map!(k => real(1) / real(k)).sum);
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!int;
	double ans = 0.0;
	foreach (i; 0..n)
	{
		ans += 1.0 / (n-i);
	}

	writefln(FMT_F, ans);
	stdout.flush;
	debug readln;
}


You are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.For every $$$i$$$ ($$$1 \leq i \leq n$$$) you must swap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \leftrightarrow a_i$$$ or $$$c_i \leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).For example, if $$$a$$$ is "code", $$$b$$$ is "true", and $$$c$$$ is "help", you can make $$$c$$$ equal to "crue" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes "hodp" and $$$b$$$ becomes "tele".Is it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a string of lowercase English letters $$$a$$$. The second line of each test case contains a string of lowercase English letters $$$b$$$. The third line of each test case contains a string of lowercase English letters $$$c$$$. It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.

Print $$$t$$$ lines with answers for all test cases. For each test case: If it is possible to make string $$$a$$$ equal to string $$$b$$$ print "YES" (without quotes), otherwise print "NO" (without quotes). You can print either lowercase or uppercase letters in the answers.

4
aaa
bbb
ccc
abc
bca
bca
aabb
bbaa
baba
imi
mii
iim

NoteIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.In the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes "bca", $$$b$$$ becomes "bca" and $$$c$$$ becomes "abc". Here the strings $$$a$$$ and $$$b$$$ are equal.In the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes "baba", string $$$b$$$ becomes "baba" and string $$$c$$$ becomes "abab". Here the strings $$$a$$$ and $$$b$$$ are equal.In the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.

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

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

void solve(){
	A: foreach(_; 0 .. rint){
		string a = readln.chomp, b = readln.chomp, c = readln.chomp;
		foreach(i; 0 .. a.length){
			if(a[i] == c[i] || b[i] == c[i]) continue;
			"NO".writeln;
			continue A;
		}
		"YES".writeln;
	}
}

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

alias type = multi;
struct TestCase
{
  mixin prettyPrinting;

  string a, b, c;

  void solve(long tc = -1)
  {
    auto n = a.length;
    if (iota(0, n).all!(i => c[i] == b[i] || c[i] == a[i]))
      writeln("YES");
    else
      writeln("NO");
  }
}

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 baseType(W)
{
  static if (isDynamicArray!W)
    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 = size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = 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, string))
              {
                static assert(isDynamicArray!(typeOfField)
                              , " A field with dimension initialization UDA must be a dynamic array.");
                enum uda = getUDAs!(fieldSymbol, string)[0];
                mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda, q{)});
              }
            else static if (isDynamicArray!typeOfField)
              {
                pragma(msg, "Warning: You probably want to add dimension to input ", 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 t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto a = RD!string;
		auto b = RD!string;
		auto c = RD!string;
		bool ok = true;
		foreach (i; 0..a.length)
		{
			if (a[i] == c[i] || b[i] == c[i]) continue;
			ok = false;
			break;
		}
		ans[ti] = ok;
	}

	foreach (e; ans)
	{
		writeln(e ? "YES" : "NO");
	}
	stdout.flush;
	debug readln;
}


Nastya just made a huge mistake and dropped a whole package of rice on the floor. Mom will come soon. If she sees this, then Nastya will be punished.In total, Nastya dropped $$$n$$$ grains. Nastya read that each grain weighs some integer number of grams from $$$a - b$$$ to $$$a + b$$$, inclusive (numbers $$$a$$$ and $$$b$$$ are known), and the whole package of $$$n$$$ grains weighs from $$$c - d$$$ to $$$c + d$$$ grams, inclusive (numbers $$$c$$$ and $$$d$$$ are known). The weight of the package is the sum of the weights of all $$$n$$$ grains in it.Help Nastya understand if this information can be correct. In other words, check whether each grain can have such a mass that the $$$i$$$-th grain weighs some integer number $$$x_i$$$ $$$(a - b \leq x_i \leq a + b)$$$, and in total they weigh from $$$c - d$$$ to $$$c + d$$$, inclusive ($$$c - d \leq \sum\limits_{i=1}^{n}{x_i} \leq c + d$$$).

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$  — the number of test cases.  The next $$$t$$$ lines contain descriptions of the test cases, each line contains $$$5$$$ integers: $$$n$$$ $$$(1 \leq n \leq 1000)$$$  — the number of grains that Nastya counted and $$$a, b, c, d$$$ $$$(0 \leq b < a \leq 1000, 0 \leq d < c \leq 1000)$$$  — numbers that determine the possible weight of one grain of rice (from $$$a - b$$$ to $$$a + b$$$) and the possible total weight of the package (from $$$c - d$$$ to $$$c + d$$$).

For each test case given in the input print "Yes", if the information about the weights is not inconsistent, and print "No" if $$$n$$$ grains with masses from $$$a - b$$$ to $$$a + b$$$ cannot make a package with a total mass from $$$c - d$$$ to $$$c + d$$$.

NoteIn the first test case of the example, we can assume that each grain weighs $$$17$$$ grams, and a pack $$$119$$$ grams, then really Nastya could collect the whole pack.In the third test case of the example, we can assume that each grain weighs $$$16$$$ grams, and a pack $$$128$$$ grams, then really Nastya could collect the whole pack.In the fifth test case of the example, we can be assumed that $$$3$$$ grains of rice weigh $$$2$$$, $$$2$$$, and $$$3$$$ grams, and a pack is $$$7$$$ grams, then really Nastya could collect the whole pack.In the second and fourth test cases of the example, we can prove that it is impossible to determine the correct weight of all grains of rice and the weight of the pack so that the weight of the pack is equal to the total weight of all collected grains.

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_t; 0..T) {
        auto nn = readln.split.to!(int[]);
        auto N = nn[0];
        auto A = nn[1];
        auto B = nn[2];
        auto C = nn[3];
        auto D = nn[4];
        if ((A-B)*N > (C+D) || (A+B)*N < (C-D)) {
            writeln("No");
        } else {
            writeln("Yes");
        }
    }
}

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

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

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  foreach (tid; 0 .. nt) {
    const n = r.next!int;
    const int a = r.next!uint;
    const int b = r.next!uint;
    const int c = r.next!uint;
    const int d = r.next!uint;
    const u1 = n * (a - b), v1 = n * (a + b);
    const u2 = c - d, v2 = c + d;
    const u = max (u1, u2), v = min (v1, v2);
    writeln ((u <= v) ? "Yes" : "No");
  }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RD!int;
		auto b = RD!int;
		auto c = RD!int;
		auto d = RD!int;

		if ((a-b)*n > c+d) continue;
		if ((a+b)*n < c-d) continue;
		ans[ti] = true;
	}

	foreach (e; ans)
	{
		writeln(e ? "Yes" : "No");
	}
	stdout.flush;
	debug readln;
}


There are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). You can draw n - 1 segments, each connecting any two marked points, in such a way that all points have to be connected with each other (directly or indirectly).But there are some restrictions. Firstly, some pairs of points cannot be connected directly and have to be connected undirectly. Secondly, the segments you draw must not intersect in any point apart from the marked points (that is, if any two segments intersect and their intersection is not a marked point, then the picture you have drawn is invalid).How many ways are there to connect all vertices with n - 1 segments? Two ways are considered different iff there exist some pair of points such that a segment is drawn between them in the first way of connection, but it is not drawn between these points in the second one. Since the answer might be large, output it modulo 109 + 7.

The first line contains one number n (3 ≤ n ≤ 500) — the number of marked points. Then n lines follow, each containing n elements. ai, j (j-th element of line i) is equal to 1 iff you can connect points i and j directly (otherwise ai, j = 0). It is guaranteed that for any pair of points ai, j = aj, i, and for any point ai, i = 0.

Print the number of ways to connect points modulo 109 + 7.

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

immutable inf = 10L^^16;
immutable mod = 10^^9 + 7;

void main() {
    int n;
    scan(n);
    auto a = new int[][](n + 1, n + 1);

    foreach (i ; 0 .. n) {
        a[i][0 .. $ - 1] = readln.split.to!(int[]);
    }

    a[0][n] = a[n][0] = 1;

    debug {
        writefln("%(%(%s %)\n%)", a);
    }

    auto dp = new long[][][](n + 1, n + 1, 2);
    fillAll(dp, -1);

    n++;

    long memodp(int i, int j, int flag) {
        if (dp[i][j][flag] != -1) return dp[i][j][flag];
        if ((j - i + n) % n == 1) {
            dp[i][j][flag] = 1;
            return 1;
        }

        dp[i][j][flag] = 0;

        if (flag) {
            if (i < j) {
                foreach (k ; i + 1 .. j) {
                    if (!a[i][k]) continue;
                    (dp[i][j][flag] += (memodp(i, k, 1) * memodp(k, j, 1)) % mod) %= mod;
                }
            }
            else {
                foreach (k ; i + 1 .. n) {
                    if (!a[i][k]) continue;
                    (dp[i][j][flag] += (memodp(i, k, 1) * memodp(k, j, 1)) % mod) %= mod;
                }
                foreach (k ; 0 .. j) {
                    if (!a[i][k]) continue;
                    (dp[i][j][flag] += (memodp(i, k, 1) * memodp(k, j, 1)) % mod) %= mod;
                }
            }
        }

        if (i < j) {
            foreach (k ; i + 1 .. j) {
                if (!a[k][j]) continue;
                (dp[i][j][flag] += memodp(i, k, 0) * memodp(k, j, 1) % mod) %= mod;
            }
        }
        else {
            foreach (k ; i + 1 .. n) {
                if (!a[k][j]) continue;
                (dp[i][j][flag] += memodp(i, k, 0) * memodp(k, j, 1) % mod) %= mod;
            }
            foreach (k ; 0 .. j) {
                if (!a[k][j]) continue;
                (dp[i][j][flag] += memodp(i, k, 0) * memodp(k, j, 1) % mod) %= mod;
            }
        }

        return dp[i][j][flag];
    }

    long ans = memodp(0, n - 1, 1);

    debug {
        foreach (i ; 0 .. n) {
            foreach (j ; i + 1 .. n) {
                writefln("(i, j) = (%d, %d) : dp[i][j] = %s", i, j, dp[i][j]);
            }
        }
    }

    writeln(ans);
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.

The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.

Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".

Note  First example: you can simply swap two letters in string "ab". So we get "ba".  Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".

import std.stdio;
import std.algorithm;

T min(T)(T l, T r) {
    return (l < r ? l : r);
}

void main() {
    //uint n;

    //readf("%s\n", &n);

    char[] s1, s2;

    readf("%s\n%s\n", &s1, &s2);

    if( s1.length != s2.length ) {
        writeln("NO");
        return;
    }

    int count;
    for(int i; i < s1.length; ++i) {
        if(s1[i] != s2[i]) { ++count; }
        if(count > 2) { writeln("NO"); return; }

    }

    auto r1 = sort!((a, b)=> a > b)(cast(ubyte[])s1);
    auto r2 = sort!((a, b)=> a > b)(cast(ubyte[])s2);

    if(r1.release() != r2.release()) {
        writeln("NO"); return;
    }

    writeln("YES");
}

import std.stdio;

T min(T)(T l, T r) {
    return (l < r ? l : r);
}

void main() {
    //uint n;

    //readf("%s\n", &n);

    string s1, s2;

    readf("%s\n%s\n", &s1, &s2);

    if( s1.length != s2.length ) {
        writeln("NO");
        return;
    }

    int count;
    int[] t;
    for(int i; i < s1.length; ++i) {
        if(s1[i] != s2[i]) { ++count; }
        if(count > 2) { writeln("NO"); return; }

        t ~= i;
    }

    if(t.length < 2 || s1[t[0]] == s1[t[1]] || s2[t[0]] == s2[t[1]]) {
        writeln("NO"); return;
    }

    writeln("YES");
}

import std.stdio;

T min(T)(T l, T r) {
    return (l < r ? l : r);
}

void main() {
    //uint n;

    //readf("%s\n", &n);

    string s1, s2;

    readf("%s\n%s\n", &s1, &s2);

    if( s1.length != s2.length ) {
        writeln("NO");
        return;
    }

    int count;
    int[] t;
    for(int i; i < s1.length; ++i) {
        if(s1[i] != s2[i]) { ++count; t ~= i; }
        if(count > 2) { writeln("NO"); return; }

    }

    if(t.length < 2 || s1[t[0]] == s1[t[1]] || s2[t[0]] == s2[t[1]]) {
        writeln("NO"); return;
    }

    writeln("YES");
}


Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.City consists of n intersections numbered from 1 to n. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking from intersection number i to intersection j requires |i - j| units of energy. The total energy spent by Mike to visit a sequence of intersections p1 = 1, p2, ..., pk is equal to  units of energy.Of course, walking would be boring if there were no shortcuts. A shortcut is a special path that allows Mike walking from one intersection to another requiring only 1 unit of energy. There are exactly n shortcuts in Mike's city, the ith of them allows walking from intersection i to intersection ai (i ≤ ai ≤ ai + 1) (but not in the opposite direction), thus there is exactly one shortcut starting at each intersection. Formally, if Mike chooses a sequence p1 = 1, p2, ..., pk then for each 1 ≤ i < k satisfying pi + 1 = api and api ≠ pi Mike will spend only 1 unit of energy instead of |pi - pi + 1| walking from the intersection pi to intersection pi + 1. For example, if Mike chooses a sequence p1 = 1, p2 = ap1, p3 = ap2, ..., pk = apk - 1, he spends exactly k - 1 units of total energy walking around them.Before going on his adventure, Mike asks you to find the minimum amount of energy required to reach each of the intersections from his home. Formally, for each 1 ≤ i ≤ n Mike is interested in finding minimum possible total energy of some sequence p1 = 1, p2, ..., pk = i.

The first line contains an integer n (1 ≤ n ≤ 200 000) — the number of Mike's city intersection. The second line contains n integers a1, a2, ..., an (i ≤ ai ≤ n , , describing shortcuts of Mike's city, allowing to walk from intersection i to intersection ai using only 1 unit of energy. Please note that the shortcuts don't allow walking in opposite directions (from ai to i).

In the only line print n integers m1, m2, ..., mn, where mi denotes the least amount of total energy required to walk from intersection 1 to intersection i.

NoteIn the first sample case desired sequences are:1: 1; m1 = 0;2: 1, 2; m2 = 1;3: 1, 3; m3 = |3 - 1| = 2.In the second sample case the sequence for any intersection 1 < i is always 1, i and mi = |1 - i|.In the third sample case — consider the following intersection sequences:1: 1; m1 = 0;2: 1, 2; m2 = |2 - 1| = 1;3: 1, 4, 3; m3 = 1 + |4 - 3| = 2;4: 1, 4; m4 = 1;5: 1, 4, 5; m5 = 1 + |4 - 5| = 2;6: 1, 4, 6; m6 = 1 + |4 - 6| = 3;7: 1, 4, 5, 7; m7 = 1 + |4 - 5| + 1 = 3.

import std.stdio;
import std.algorithm;
import std.container;

immutable int inf = cast(int)1e9;

int N;
int[] A, d;

void main() {
	readf("%d", &N);
	A = new int[N + 1];
	foreach (i; 1..N + 1) readf(" %d", &A[i]);
	d = new int[N + 1]; fill(d, cast(int)1e9);
	d[1] = 0; auto q = DList!int(1);
	while (!q.empty) {
		int v = q.front; q.removeFront();
		foreach (u; [v - 1, v + 1, A[v]]) {
			if (u < 1 || u > N) continue;
			if (d[u] > d[v] + 1) {
				d[u] = d[v] + 1;
				q.insertBack(u);
			}
		}
	}
	foreach(i; 1..N + 1) writef("%d ", d[i]); writeln("");
}

import std.stdio, std.conv;
import std.algorithm, std.range, std.random;
import std.string, std.array, std.container, std.bigint;
import std.exception;

int main() {
    int n = readln.strip.to!int;;
    int[] a = readln.split.map!(a => a.to!int - 1).array;
    struct Edge(C) {
        int to;
        C cost;
    }
    alias E = Edge!int;
    E[][] e = new E[][](n);
    foreach (i; 0..n) {
        if (i < n-1) {
            e[i] ~= E(i+1, 1);
        }
        if (0 < i) {
            e[i] ~= E(i-1, 1);
        }
        e[i] ~= E(a[i], 1);
    }
    writeln(dijkstra(e, 0).map!(to!string).join(" "));
	return 0;
}

C[] dijkstra(E, C = typeof(E.cost))(in E[][] graph, int s) {
    import std.typecons : Tuple;
    import std.container : Array, BinaryHeap;
    alias Q = Tuple!(int, "to", C, "cost");

    size_t n = graph.length;
    C[] dist = new C[graph.length]; dist[] = E.cost.max;
    bool[] used = new bool[n];
    auto que = BinaryHeap!(Array!Q, "a.cost > b.cost")();
    dist[s] = 0;
    que.insert(Q(s, 0));
    while (!que.empty) {
        auto p = que.front.to; que.popFront;
        if (used[p]) continue;
        used[p] = true;
        foreach (E e; graph[p]) {
            if (dist[e.to] > dist[p] + e.cost) {
                dist[e.to] = dist[p] + e.cost;
                que.insert(Q(e.to, dist[e.to]));
            }
        }
    }
    return dist;
}

string readToken() {
    import std.stdio : readln;
    import std.string : split;
    static size_t pos;
    static string[] tokens;
    while (!(pos < tokens.length)) {
        pos = 0;
        tokens = readln.split;
    }
    return tokens[pos++];
}
T read(T)() {
    import std.conv : to;
    return readToken.to!T;
}

import std.stdio, std.conv;
import std.algorithm, std.range, std.random;
import std.string, std.array, std.container, std.bigint;
import std.exception;

int main() {
    int n = readln.strip.to!int;;
    int[] a = readln.split.map!(a => a.to!int - 1).array;
    int[] d = new int[n]; d[] = 10^^9;
    d[0] = 0;
    foreach (i; 0..n) {
        if (i) {
            d[i] = min(d[i], d[i-1]+1);
        }
        d[a[i]] = min(d[a[i]], d[i]+1);
    }
    foreach_reverse (i; 0..n-1) {
        d[i] = min(d[i], d[i+1]+1);
    }
    writeln(d.map!(to!string).join(" "));
	return 0;
}

string readToken() {
    import std.stdio : readln;
    import std.string : split;
    static size_t pos;
    static string[] tokens;
    while (!(pos < tokens.length)) {
        pos = 0;
        tokens = readln.split;
    }
    return tokens[pos++];
}
T read(T)() {
    import std.conv : to;
    return readToken.to!T;
}


This is an easy version of the problem. The difference between the easy and hard versions is that in this version, you can output any permutation with the smallest weight.You are given a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$.Let's define the weight of the permutation $$$q_1, q_2, \ldots, q_n$$$ of integers from $$$1$$$ to $$$n$$$ as $$$$$$|q_1 - p_{q_{2}}| + |q_2 - p_{q_{3}}| + \ldots + |q_{n-1} - p_{q_{n}}| + |q_n - p_{q_{1}}|$$$$$$You want your permutation to be as lightweight as possible. Find any permutation $$$q$$$ with the smallest possible weight.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 200$$$)  — the size of the permutation. The second line of each test case contains $$$n$$$ integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \le p_i \le n$$$, all $$$p_i$$$ are distinct)  — the elements of the permutation. The sum of $$$n$$$ over all test cases doesn't exceed $$$400$$$.

For each test case, output $$$n$$$ integers $$$q_1, q_2, \ldots, q_n$$$ ($$$1 \le q_i \le n$$$, all $$$q_i$$$ are distinct)  — one of the permutations with the smallest weight.

NoteIn the first test case, there are two permutations of length $$$2$$$: $$$(1, 2)$$$ and $$$(2, 1)$$$. Permutation $$$(1, 2)$$$ has weight $$$|1 - p_2| + |2 - p_1| = 0$$$, and permutation $$$(2, 1)$$$ has the same weight: $$$|2 - p_1| + |1 - p_2| = 0$$$. You can output any of these permutations in this version.In the second test case, the weight of the permutation $$$(1, 3, 4, 2)$$$ is $$$|1 - p_3| + |3 - p_4| + |4 - p_2| + |2 - p_1| = |1 - 1| + |3 - 4| + |4 - 3| + |2 - 2| = 2$$$. There are no permutations with smaller weights.In the third test case, the weight of the permutation $$$(1, 4, 2, 3, 5)$$$ is $$$|1 - p_4| + |4 - p_2| + |2 - p_3| + |3 - p_5| + |5 - p_1| = |1 - 2| + |4 - 4| + |2 - 3| + |3 - 1| + |5 - 5| = 4$$$. There are no permutations with smaller weights.

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 numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        const N = readInt;
        auto P = new int[N];
        foreach (u; 0 .. N) {
          P[u] = readInt - 1;
        }

        auto uf = new int[N];
        uf[] = -1;
        foreach (u; 0 .. N) {
          uf.connect(u, P[u]);
        }

        auto to = P.dup;
        auto fr = new int[N];
        foreach (u; 0 .. N) {
          fr[to[u]] = u;
        }

        foreach (u; 0 .. N - 1) if (uf.connect(u, u + 1)) {
          const a = fr[u];
          const b = fr[u + 1];
          swap(to[a], to[b]);
          swap(fr[u], fr[u + 1]);
        }

        auto ans = new int[N];
        ans[0] = 0;
        foreach (i; 0 .. N - 1) {
          ans[i + 1] = fr[ans[i]];
        }

        foreach (i; 0 .. N) {
          if (i) write(" ");
          write(ans[i] + 1);
        }
        writeln;
      }
    }
  } catch (EOFException e) {
  }
}


This is yet another problem dealing with regular bracket sequences.We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well.

The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106.

Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1".

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.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    auto s = readln.chomp;

    immutable int ZRO = 10 ^^ 6;
    int anslen = 0, anscnt = 1;
    int ch = ZRO;
    auto h = new int[] (ZRO + ZRO + 1);
    h[] = -1;
    h[ZRO] = 0;
    foreach (i, e; s.enumerate(1)) {
        if (e == '(') {
            ch += 1;
            if (h[ch] == -1) { h[ch] = i.to!int; }
        } else {
            ch -= 1;
            h[ch+1] = -1;

            debug { writeln(i, ' ', e, ' ', ch, ' ', h[ch]); }

            if (h[ch] > -1) {
                auto len = i.to!int - h[ch];
                if (len > anslen) {
                    anslen = len;
                    anscnt = 1;
                } else if (len == anslen) { anscnt += 1; }
            }

            if (h[ch] == -1) { h[ch] = i.to!int; }
        }
    }

    writeln(anslen, ' ', anscnt);
}

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.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    auto s = readln.chomp;

    immutable int ZRO = 10 ^^ 6;
    int anslen = 0, anscnt = 1;
    int ch = ZRO;
    auto h = new int[] (ZRO + ZRO + 1);
    h[] = -1;
    h[ZRO] = 0;
    foreach (i, e; s) {
        if (e == '(') {
            ch += 1;
            if (h[ch] == -1) { h[ch] = i.to!int; }
        } else {
            ch -= 1;
            h[ch+1] = -1;

            debug { writeln(i, ' ', e, ' ', ch, ' ', h[ch]); }

            if (h[ch] > -1) {
                auto len = i.to!int - h[ch];
                if (len > anslen) {
                    anslen = len;
                    anscnt = 1;
                } else if (len == anslen) { anscnt += 1; }
            }

            if (h[ch] == -1) { h[ch] = i.to!int; }
        }
    }

    writeln(anslen, ' ', anscnt);
}


Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and sees his creation demolished, he'll get extremely upset. To not let that happen, Dima has to recover the binary search tree. Luckily, he noticed that any two vertices connected by a direct edge had their greatest common divisor value exceed $$$1$$$.Help Dima construct such a binary search tree or determine that it's impossible. The definition and properties of a binary search tree can be found here.

The first line contains the number of vertices $$$n$$$ ($$$2 \le n \le 700$$$). The second line features $$$n$$$ distinct integers $$$a_i$$$ ($$$2 \le a_i \le 10^9$$$) — the values of vertices in ascending order.

If it is possible to reassemble the binary search tree, such that the greatest common divisor of any two vertices connected by the edge is greater than $$$1$$$, print "Yes" (quotes for clarity). Otherwise, print "No" (quotes for clarity).

NoteThe picture below illustrates one of the possible trees for the first example.  The picture below illustrates one of the possible trees for the third example.

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

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

		auto g = new bool [] [] (n, n);
		foreach (i; 0..n)
		{
			foreach (j; 0..n)
			{
				g[i][j] = gcd (a[i], a[j]) > 1;
			}
		}

		auto f = new bool [2] [] [] (n + 1, n + 1);
		foreach (b; 0..2)
		{
			foreach (i; 0..n + 1)
			{
				f[i][i][b] = true;
			}
		}

		foreach (len; 1..n + 1)
		{
			foreach (i; 0..n + 1)
			{
				int j = i + len;
				if (j > n)
				{
					continue;
				}

				if (j < n)
				{
					int v = j;
					// [i..k) *k* [k+1..j) *v*
					foreach (k; i..j)
					{
						if (g[k][v] &&
						    f[i][k][0] &&
						    f[k + 1][j][1])
						{
							f[i][j][0] = true;
							break;
						}
					}
				}

				if (0 <= i - 1)
				{
					int v = i - 1;
					// *v* [i..k) *k* [k+1..j)
					foreach (k; i..j)
					{
						if (g[k][v] &&
						    f[i][k][0] &&
						    f[k + 1][j][1])
						{
							f[i][j][1] = true;
							break;
						}
					}
				}
			}
		}

		bool res = false;
		foreach (i; 0..n)
		{
			res |= f[0][i][0] && f[i + 1][n][1];
		}
		writeln (res ? "Yes" : "No");
	}
}

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

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

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

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

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

      N += 2;
      A = [0L] ~ A ~ [0L];
      auto b = new bool[][](N, N);
      foreach (i; 0 .. N) foreach (j; 0 .. N) {
        b[i][j] = (gcd(A[i], A[j]) != 1);
      }

      auto dpL = new bool[][](N, N);
      auto dpR = new bool[][](N, N);
      foreach (i; 0 .. N - 1) {
        dpL[i + 1][i] = true;
        dpR[i][i + 1] = true;
      }
      foreach (w; 2 .. N) {
        foreach (i; 0 .. N - w) {
          const j = i + w;
          foreach (k; i + 1 .. j) {
            if (dpR[i][k] && dpL[j][k]) {
              if (b[i][k]) dpL[j][i] = true;
              if (b[j][k]) dpR[i][j] = true;
            }
          }
        }
      }
      writeln(dpL[N - 1][0] ? "Yes" : "No");
    }
  } 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.numeric, std.regex, std.typecons;
import core.bitop;

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

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

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

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

      N += 2;
      A = [1L] ~ A ~ [1L];
      auto b = new bool[][](N, N);
      foreach (i; 0 .. N) foreach (j; 0 .. N) {
        b[i][j] = (gcd(A[i], A[j]) != 1);
      }

      auto dp = new bool[][](N, N);
      foreach (i; 0 .. N - 1) {
        dp[i][i + 1] = true;
      }
      foreach (w; 2 .. N) {
        foreach (i; 0 .. N - w) {
          const j = i + w;
          foreach (k; i + 1 .. j) {
            if (b[i][k] || b[j][k]) {
              if (dp[i][k] && dp[k][j]) {
                dp[i][j] = true;
                break;
              }
            }
          }
        }
      }
      debug {
        writeln("dp = ", dp);
      }
      bool ans;
      foreach (i; 1 .. N - 1) {
        if (dp[0][i] && dp[i][N - 1]) {
          ans = true;
          break;
        }
      }
      writeln(ans ? "Yes" : "No");
    }
  } catch (EOFException e) {
  }
}


Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length.Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line.Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange m - 1 borders that would divide the greenhouse into m sections numbered from 1 to m from left to right with each section housing a single species. He is free to place the borders, but in the end all of the i-th species plants must reside in i-th section from the left.Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders.

The first line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 5000, n ≥ m), the number of plants and the number of different species. Each of the following n lines contain two space-separated numbers: one integer number si (1 ≤ si ≤ m), and one real number xi (0 ≤ xi ≤ 109), the species and position of the i-th plant. Each xi will contain no more than 6 digits after the decimal point. It is guaranteed that all xi are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their xi coordinates (xi < xi + 1, 1 ≤ i < n).

Output a single integer — the minimum number of plants to be replanted.

NoteIn the first test case, Emuskald can replant the first plant to the right of the last plant, so the answer is 1.In the second test case, the species are already in the correct order, so no replanting is needed.

import std.algorithm;
import std.container;
import std.stdio;
import std.typecons;

immutable int MAX_N = 100_005;
immutable int MAX_C = 0x3F3F3F3F;
immutable int NA    = -1;

void main ()
{
	int n, m;
	while (scanf (" %d %d", &n) > 0)
	{
		auto s = new int [n];
		foreach (i; 0..n)
		{
			scanf (" %d %*lf", &s[i]);
			s[i]--;
		}

		auto f = new int [n];
		fill (f, 1);
		foreach (i; 0..n)
		{
			foreach (j; 0..i)
			{
				if (s[j] <= s[i])
				{
					f[i] = max (f[i], f[j] + 1);
				}
			}
		}
		int res = 0;
		foreach (i; 0..n)
		{
			res = max (res, f[i]);
		}
		writefln ("%d", n - res);
	}
}


A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.You are given an integer $$$n$$$. Your goal is to construct and print exactly $$$n$$$ different regular bracket sequences of length $$$2n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 50$$$) — the number of test cases. Each test case consists of one line containing one integer $$$n$$$ ($$$1 \le n \le 50$$$).

For each test case, print $$$n$$$ lines, each containing a regular bracket sequence of length exactly $$$2n$$$. All bracket sequences you output for a testcase should be different (though they may repeat in different test cases). If there are multiple answers, print any of them. It can be shown that it's always possible.

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

void bracket (int count)
{
	for (int i = count; i >= 1; i--)
	{
		string s = "";
		s ~= replicate("(", i);
		s ~= replicate(")", i);
		s ~= replicate("(", count - i);
		s ~= replicate(")", count - i);
		writeln(s);
	}
}

void main()
{
    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t){
	int n;
	scanf("%d", &n);
	bracket(n);
    }
}

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

void bracket (int count, string s="", int left=0, int right=0)
{
	if ((left == count) && (right == count))
		writeln(s);
	else
	{
		if (left < count)
			bracket(count, s ~ "(", left +1, right);
		if (right < left)
			bracket(count, s ~ ")", left, right +1);
	}
}

void main()
{
    int t;
    scanf("%d", &t);
    getchar();
    foreach(i; 0..t){
	int n;
	scanf("%d", &n);
	bracket(n);
    }
}


Boboniu gives you  $$$r$$$ red balls,  $$$g$$$ green balls,  $$$b$$$ blue balls,  $$$w$$$ white balls. He allows you to do the following operation as many times as you want:   Pick a red ball, a green ball, and a blue ball and then change their color to white. You should answer if it's possible to arrange all the balls into a palindrome after several (possibly zero) number of described operations.

The first line contains one integer $$$T$$$ ($$$1\le T\le 100$$$) denoting the number of test cases. For each of the next $$$T$$$ cases, the first line contains four integers $$$r$$$, $$$g$$$, $$$b$$$ and $$$w$$$ ($$$0\le r,g,b,w\le 10^9$$$).

For each test case, print "Yes" if it's possible to arrange all the balls into a palindrome after doing several (possibly zero) number of described operations. Otherwise, print "No".

NoteIn the first test case, you're not able to do any operation and you can never arrange three balls of distinct colors into a palindrome.In the second test case, after doing one operation, changing $$$(8,1,9,3)$$$ to $$$(7,0,8,6)$$$, one of those possible palindromes may be "rrrwwwbbbbrbbbbwwwrrr".A palindrome is a word, phrase, or sequence that reads the same backwards as forwards. For example, "rggbwbggr", "b", "gg" are palindromes while "rgbb", "gbbgr" are not. Notice that an empty word, phrase, or sequence is palindrome.

// Vicfred
// https://codeforces.com/contest/1395/problem/A
// greedy
import std.stdio;

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

    while(t--) {
        long r, g, b, w;
        readf("%s %s %s %s", &r, &g, &b, &w);
        readln;

        long x = r%2 + g%2 + b%2 + w%2;

        if(x <= 1) {
            "Yes".writeln;
            continue;
        }

        if(r > 0 && g > 0 && b > 0) {
            r -= 1;
            g -= 1;
            b -= 1;
            w += 1;
        }

        x = r%2 + g%2 + b%2 + w%2;

        if(x <= 1) {
            "Yes".writeln;
            continue;
        }

        "No".writeln;
    }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int r, g, b, w;
		readf !(" %s %s %s %s") (r, g, b, w);
		auto s = (r & 1) + (g & 1) + (b & 1) + (w & 1);
		writeln (s <= 1 || (r && g && b && s >= 3) ? "YES" : "NO");
	}
}

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

alias type = multi;
struct TestCase
{
  mixin prettyPrinting;

  long r, g, b, w;

  void solve(long tc = -1)
  {
    long p = (r % 2 == 0) + (g % 2 == 0) + (b % 2 == 0)
      + (w % 2 == 0);
    long i = 4 - p;
    long ops = min(r, g, b);
    if (p == 3 || p == 4)
      {
        writeln("Yes");
        return;
      }
    if (ops > 0)
      {
        if (p == 1 || p == 0)
          {
            writeln("Yes");
            return;
          }
      }
    writeln("No");
  }
}

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

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

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 = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto a = RDA;

		int cnt;
		foreach (e; a[0..3])
		{
			if (e % 2)
				++cnt;
		}

		int cnt2 = a[3] % 2;
		if (cnt+cnt2 <= 1)
		{
			ans[ti] = true;
			continue;
		}

		if (a[0] == 0 || a[1] == 0 || a[2] == 0)
			continue;

		int cnt3 = cnt2 % 2 ? 0 : 1;
		if (3 - cnt + cnt3 <= 1)
			ans[ti] = true;
	}

	foreach (e; ans)
	{
		writeln(e ? "Yes" : "No");
	}
	stdout.flush;
	debug readln;
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int r, g, b, w;
		readf !(" %s %s %s %s") (r, g, b, w);
		writeln ((r & 1) + (g & 1) + (b & 1) + (w & 1) == 2 ?
		    "NO" : "YES");
	}
}


A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.You have integer n. Find some lucky permutation p of size n.

The first line contains integer n (1 ≤ n ≤ 105) — the required permutation size.

Print "-1" (without the quotes) if the lucky permutation p of size n doesn't exist. Otherwise, print n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) after a space — the required permutation. If there are multiple answers, you can print any of them.

import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		if (n == 1)
		{
			writeln (1);
		}
		else if (n % 4 >= 2)
		{
			writeln (-1);
		}
		else
		{
			auto p = new int [n];
			if (n & 1)
			{
				debug {writefln ("%s", n >> 1);}
				p[n >> 1] = n >> 1;
			}
			foreach (i; 0..(n >> 2))
			{
				int j = i << 1;
				int k = n - j - 1;
				debug {writefln ("%s %s", j, k);}
				p[j] = j + 1;
				p[j + 1] = k;
				p[k] = k - 1;
				p[k - 1] = j;
			}
			p[] += 1;
			writefln ("%(%s %)", p);
		}
	}
}


Madoka as a child was an extremely capricious girl, and one of her favorite pranks was drawing on her wall. According to Madoka's memories, the wall was a table of $$$n$$$ rows and $$$m$$$ columns, consisting only of zeroes and ones. The coordinate of the cell in the $$$i$$$-th row and the $$$j$$$-th column ($$$1 \le i \le n$$$, $$$1 \le j \le m$$$) is $$$(i, j)$$$.One day she saw a picture "Mahou Shoujo Madoka Magica" and decided to draw it on her wall. Initially, the Madoka's table is a table of size $$$n \times m$$$ filled with zeroes. Then she applies the following operation any number of times:Madoka selects any rectangular subtable of the table and paints it in a chess coloring (the upper left corner of the subtable always has the color $$$0$$$). Note that some cells may be colored several times. In this case, the final color of the cell is equal to the color obtained during the last repainting.  White color means $$$0$$$, black means $$$1$$$. So, for example, the table in the first picture is painted in a chess coloring, and the others are not. For better understanding of the statement, we recommend you to read the explanation of the first test.Help Madoka and find some sequence of no more than $$$n \cdot m$$$ operations that allows you to obtain the picture she wants, or determine that this is impossible.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 100$$$) — the size of the table. Each of the following $$$n$$$ lines contains a string of length $$$m$$$ consisting only of $$$1$$$ and $$$0$$$ — description of the picture that Madoka wants to obtain.

If it is impossible to obtain the given picture, print $$$-1$$$. Otherwise, print in the first line a single integer $$$q$$$ ($$$0 \leq q \leq n \cdot m$$$) — the number of operations you need to obtain the picture. Note that you do not need to minimize the number of operations. Then for each operation (in the order of execution) print a single line containing four numbers — the coordinates of the upper-left corner and the lower-right corner of the rectangle.

NoteThe description of the first test case is below.  In the third test case, it is impossible to paint the desired picture.In the fourth test case, the initial table is already the desired picture.

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		readln;
		auto a = new int [] [n];
		foreach (ref c; a)
		{
			c = readln.strip.map !(q{int (a) - '0'}).array;
		}

		if (a[0][0] == 1)
		{
			writeln (-1);
			continue;
		}

		int [] [] ans;
		foreach_reverse (row; 0..n)
		{
			foreach_reverse (col; 0..m)
			{
				if (a[row][col] == 0)
				{
					ans ~= [row, col, row, col];
				}
				else if (row > 0)
				{
					ans ~= [row - 1, col, row, col];
				}
				else
				{
					ans ~= [row, col - 1, row, col];
				}
			}
		}

		writeln (ans.length);
		foreach (ref line; ans)
		{
			writefln !("%(%s %)") (line.map !(q{a + 1}));
		}
	}
}