The map of Bertown can be represented as a set of $$$n$$$ intersections, numbered from $$$1$$$ to $$$n$$$ and connected by $$$m$$$ one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection $$$v$$$ to another intersection $$$u$$$ is the path that starts in $$$v$$$, ends in $$$u$$$ and has the minimum length among all such paths.Polycarp lives near the intersection $$$s$$$ and works in a building near the intersection $$$t$$$. Every day he gets from $$$s$$$ to $$$t$$$ by car. Today he has chosen the following path to his workplace: $$$p_1$$$, $$$p_2$$$, ..., $$$p_k$$$, where $$$p_1 = s$$$, $$$p_k = t$$$, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from $$$s$$$ to $$$t$$$.Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection $$$s$$$, the system chooses some shortest path from $$$s$$$ to $$$t$$$ and shows it to Polycarp. Let's denote the next intersection in the chosen path as $$$v$$$. If Polycarp chooses to drive along the road from $$$s$$$ to $$$v$$$, then the navigator shows him the same shortest path (obviously, starting from $$$v$$$ as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection $$$w$$$ instead, the navigator rebuilds the path: as soon as Polycarp arrives at $$$w$$$, the navigation system chooses some shortest path from $$$w$$$ to $$$t$$$ and shows it to Polycarp. The same process continues until Polycarp arrives at $$$t$$$: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path $$$[1, 2, 3, 4]$$$ ($$$s = 1$$$, $$$t = 4$$$): Check the picture by the link http://tk.codeforces.com/a.png   When Polycarp starts at $$$1$$$, the system chooses some shortest path from $$$1$$$ to $$$4$$$. There is only one such path, it is $$$[1, 5, 4]$$$;  Polycarp chooses to drive to $$$2$$$, which is not along the path chosen by the system. When Polycarp arrives at $$$2$$$, the navigator rebuilds the path by choosing some shortest path from $$$2$$$ to $$$4$$$, for example, $$$[2, 6, 4]$$$ (note that it could choose $$$[2, 3, 4]$$$);  Polycarp chooses to drive to $$$3$$$, which is not along the path chosen by the system. When Polycarp arrives at $$$3$$$, the navigator rebuilds the path by choosing the only shortest path from $$$3$$$ to $$$4$$$, which is $$$[3, 4]$$$;  Polycarp arrives at $$$4$$$ along the road chosen by the navigator, so the system does not have to rebuild anything. Overall, we get $$$2$$$ rebuilds in this scenario. Note that if the system chose $$$[2, 3, 4]$$$ instead of $$$[2, 6, 4]$$$ during the second step, there would be only $$$1$$$ rebuild (since Polycarp goes along the path, so the system maintains the path $$$[3, 4]$$$ during the third step).The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le m \le 2 \cdot 10^5$$$) — the number of intersections and one-way roads in Bertown, respectively. Then $$$m$$$ lines follow, each describing a road. Each line contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$) denoting a road from intersection $$$u$$$ to intersection $$$v$$$. All roads in Bertown are pairwise distinct, which means that each ordered pair $$$(u, v)$$$ appears at most once in these $$$m$$$ lines (but if there is a road $$$(u, v)$$$, the road $$$(v, u)$$$ can also appear). The following line contains one integer $$$k$$$ ($$$2 \le k \le n$$$) — the number of intersections in Polycarp's path from home to his workplace. The last line contains $$$k$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_k$$$ ($$$1 \le p_i \le n$$$, all these integers are pairwise distinct) — the intersections along Polycarp's path in the order he arrived at them. $$$p_1$$$ is the intersection where Polycarp lives ($$$s = p_1$$$), and $$$p_k$$$ is the intersection where Polycarp's workplace is situated ($$$t = p_k$$$). It is guaranteed that for every $$$i \in [1, k - 1]$$$ the road from $$$p_i$$$ to $$$p_{i + 1}$$$ exists, so the path goes along the roads of Bertown.

Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
import std.container;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(size_t k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}

alias N = int;

N n, m;
N[][] neis;
N[][] ineis;
N k;
N[] p;
N[] dist;
bool[] visited;
RedBlackTree!N[] goodneis;

void main()
{
  get(n, m);
  neis = new N[][cast(size_t)n];
  ineis = new N[][cast(size_t)n];
  visited = new bool[cast(size_t)n];
  goodneis = new RedBlackTree!N[cast(size_t)n];
  dist = new N[cast(size_t)n];
  goodneis.each!((ref g) {g = redBlackTree!N();});
  foreach(e; 0 .. m)
    {
      N u, v; get(u, v); u--, v--;
      neis[u]~=v;
      ineis[v]~=u;
    }
  get(k);
  p = new N[cast(size_t)k]; get(p); p.each!((ref e) => e--);
  DList!N q;
  q.insertBack(p[$ - 1]);
  visited[cast(size_t)p[$ - 1]] = true;
  dist[cast(size_t)p[$-1]] = 0;
  while(!q.empty)
    {
      auto v = q.front; q.removeFront;
      foreach(u; ineis[cast(size_t)v])
	{
	  if (!visited[cast(size_t)u])
	    {
	      dist[cast(size_t)u] = dist[cast(size_t)v] + 1;
	      visited[cast(size_t)u] = true;
	      q.insertBack(u);
	    }
	  if (dist[cast(size_t)v] + 1 == dist[cast(size_t)u])
	    goodneis[cast(size_t)u].insert(v);
	}
    }
  N minr, maxr;
  foreach(i, ref v; p[0 .. $ - 1])
    {
      if (!goodneis[cast(size_t)v].equalRange(p[i + 1]).empty)
	{
	  if (goodneis[cast(size_t)v].length > 1)
	      maxr += 1;
	}
      else
	{
	  maxr += 1;
	  minr += 1;
	}
    }
  wr(minr, maxr);
}

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(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
    int n = scan!int, m = scan!int;
    Node[] nodes;
    foreach(i; 0 .. n) nodes ~= new Node(i);

    foreach(j; 0 .. m){
        Node u = nodes[scan!int - 1], v = nodes[scan!int - 1];
        v.kids ~= u;
    }
    int k = scan!int;
    Node[] ps = scan!int(k).map!(x => nodes[x - 1]).array;

    Node s = ps[0], t = ps[k - 1];

    auto ndq = new Queue!Node;
    ndq.enq(t);
    while(! ndq.isEmpty){
        Node nd = ndq.deq;
        foreach(kd; nd.kids){
            int d = nd.depth + 1;
            if(kd.depth < 0 || d < kd.depth){
                kd.parset[nd.id] = 1;
                kd.depth = d;
                ndq.enq(kd);
            }
            else if(d == kd.depth) kd.parset[nd.id] = 1;
            else continue;
        }
    }

    int ansmin, ansmax;
    foreach(i; 0 .. k - 1){
        Node a = ps[i], b = ps[i + 1];
        if(b.id in a.parset){
            if(a.parset.keys.length > 1) ansmax += 1;
        }
        else ansmin += 1, ansmax += 1;
    }

    print(ansmin, ansmax);
}

class Node{
    int id;
    int depth = -1;
    Node[] kids; // この点へ来れる点
    bool[int] parset; // ゴールに向かうとき次の点になりうる点
    this(int id){ this.id = id; }
}

class Queue(T){
	private T[] xs;
	private uint i, j; // i : 次に読み出す位置　j: 次に書き込む位置
	this(){	}
	this(T[] xs){ this.xs = xs; j = xs.length.to!uint; }
	uint length(){ return j - i; }
	bool isEmpty(){ return j == i; }
	void enq(T x){
		while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1;
		xs[j ++] = x;
	}
	T deq(){ assert(i < j); return xs[i ++]; }
	T peek(){ assert(i < j); return xs[i]; }
	T opIndex(uint li){ assert(i + li < j); return xs[i + li]; }
	static Queue!T opCall(){ return new Queue!T; }
	static Queue!T opCall(T[] xs){ return new Queue!T(xs); }
	T[] array(){ return xs[i .. j]; }
	override string toString(){ return array.to!string; }

}

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 N, M;
int[] U, V;
int K;
int[] P;

int[][] G;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      M = readInt();
      U = new int[M];
      V = new int[M];
      foreach (i; 0 .. M) {
        U[i] = readInt() - 1;
        V[i] = readInt() - 1;
      }
      K = readInt();
      P = new int[K];
      foreach (k; 0 .. K) {
        P[k] = readInt() - 1;
      }

      G = new int[][N];
      foreach (i; 0 .. M) {
        G[V[i]] ~= i;
      }
      auto que = new int[N];
      auto dist = new int[N];
      dist[] = N;
      int qb, qe;
      dist[P[K - 1]] = 0;
      que[qe++] = P[K - 1];
      for (; qb != qe; ) {
        const u = que[qb++];
        foreach (i; G[u]) {
          const v = U[i];
          if (chmin(dist[v], dist[u] + 1)) {
            que[qe++] = v;
          }
        }
      }
      auto deg = new int[N];
      foreach (i; 0 .. M) {
        if (dist[U[i]] == 1 + dist[V[i]]) {
          ++deg[U[i]];
        }
      }
      debug {
        writeln("dist = ", dist);
        writeln("deg = ", deg);
      }

      int ans0, ans1;
      foreach (k; 0 .. K - 1) {
        if (dist[P[k]] == 1 + dist[P[k + 1]]) {
          if (deg[P[k]] > 1) {
            ++ans1;
          }
        } else {
          ++ans0;
          ++ans1;
        }
      }
      writeln(ans0, " ", ans1);
    }
  } catch (EOFException e) {
  }
}

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

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

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

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

int N, M;
int[] U, V;
int K;
int[] P;

int[][] G;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      M = readInt();
      U = new int[M];
      V = new int[M];
      foreach (i; 0 .. M) {
        U[i] = readInt() - 1;
        V[i] = readInt() - 1;
      }
      K = readInt();
      P = new int[K];
      foreach (k; 0 .. K) {
        P[k] = readInt() - 1;
      }

      G = new int[][N];
      foreach (i; 0 .. M) {
        G[V[i]] ~= i;
      }
      auto que = new int[N];
      auto dist = new int[N];
      dist[] = N;
      int qb, qe;
      dist[P[K - 1]] = 0;
      que[qe++] = P[K - 1];
      for (; qb != qe; ) {
        const u = que[qb++];
        foreach (i; G[u]) {
          const v = U[i];
          if (chmin(dist[v], dist[u] + 1)) {
            que[qe++] = v;
          }
        }
      }
      auto deg = new int[N];
      foreach (i; 0 .. M) {
        if (dist[U[i]] == 1 + dist[V[i]]) {
          ++deg[U[i]];
        }
      }
      debug {
        writeln("dist = ", dist);
        writeln("deg = ", deg);
      }

      int ans0, ans1;
      foreach (k; 0 .. K - 1) {
        if (dist[P[k]] == 1 + dist[P[k + 1]]) {
          if (deg[P[k]] == 2) {
            ++ans1;
          }
        } else {
          ++ans0;
          ++ans1;
        }
      }
      writeln(ans0, " ", ans1);
    }
  } catch (EOFException e) {
  }
}


It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way. Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.

The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).

If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Notegcd(x, y) is greatest common divisor of x and y.

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

void main() {
    int n, k; readf("%d %d\n", &n, &k);
    if (n == 1) {
        writeln(k == 0 ? 1 : -1);
        return;
    }
    if (k < n / 2) {
        writeln(-1);
        return;
    }
    int x = k - n / 2 + 1;
    int[] a;
    a ~= x; a ~= 2 * x;
    int y = 2 * x + 1;
    for (int i = 1; i < n / 2; i++) {
        a ~= y; y++;
        a ~= y; y++;
    }
    if (n % 2) a ~= 1000000000;
    write(a[0]);
    foreach (i; 1 .. a.length) {
        write(' ', a[i]);
    }
    writeln;
}

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

int main() {
    int n, k;
    readf("%d %d\n", &n, &k);
    if (k<n/2) {
        writeln(-1);
        return 0;
    }
    if (n == 1) {
        if (k == 0) {
            writeln(1);
        } else {
            writeln(-1);
        }
        return 0;
    }
    string[] s;
    int m = k-(n/2-1);
    s ~= to!string(m);
    s ~= to!string(2*m);
    foreach (i;0..n-2) {
        s ~= to!string(2*m+i+10);
    }
    writeln(join(s, " "));
    return 0;
}

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

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		if (n == 1)
		{
			writeln (k ? -1 : 1);
		}
		else if (n / 2 > k)
		{
			writeln (-1);
		}
		else
		{
			int [] a;
			foreach (i; 1..n / 2)
			{
				a ~= 2 * i - 1;
				a ~= 2 * i;
			}
			int d = k - n / 2 + 1;
			int t = 500_000_000;
			t /= d;
			t *= d;
			a ~= t - d;
			a ~= t;
			if (n & 1)
			{
				a ~= 999_999_999;
			}
			writefln ("%(%s %)", a);
		}
	}
}

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

void main() {
    int n, k; readf("%d %d\n", &n, &k);
    if (n == 1 || k < n / 2) {
        writeln(-1); return;
    }
    int x = k - n / 2 + 1;
    int[] a;
    a ~= x; a ~= 2 * x;
    int y = 2 * x + 1;
    for (int i = 1; i < n / 2; i++) {
        a ~= y; y++;
        a ~= y; y++;
    }
    if (n % 2) a ~= 1000000000;
    write(a[0]);
    foreach (i; 1 .. a.length) {
        write(' ', a[i]);
    }
    writeln;
}

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

int main() {
    int n, k;
    readf("%d %d\n", &n, &k);
    if (k<n/2) {
        writeln(-1);
        return 0;
    }
    string[] s;
    int m = k-(n/2-1);
    s ~= to!string(m);
    s ~= to!string(2*m);
    foreach (i;0..n-2) {
        s ~= to!string(2*m+i+10);
    }
    writeln(join(s, " "));
    return 0;
}

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

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		if (n / 2 > k)
		{
			writeln (-1);
		}
		else
		{
			int [] a;
			foreach (i; 1..n / 2)
			{
				a ~= 2 * i - 1;
				a ~= 2 * i;
			}
			int d = k - n / 2 + 1;
			int t = 500_000_000;
			t /= d;
			t *= d;
			a ~= t - d;
			a ~= t;
			if (n & 1)
			{
				a ~= 999_999_999;
			}
			writefln ("%(%s %)", a);
		}
	}
}


Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions:  $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty.  $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells.    These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$.

The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$.

NoteIn the first example, this is the other possible case.  In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$.

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct ModularClass(T)
{
  alias pmod = positiveModularRepresentative;
  T representative, modulus;
  this(T representative, T modulus)
  {
    this.representative = pmod(representative, modulus);
    this.modulus = modulus;
  }
  T minimalPositiveRepresentative()
  {
    return ((representative % modulus) + modulus) % modulus;
  }
  T minimalNegativeRepresentative()
  {
    return ((representative % modulus) - modulus) % modulus;
  }
  T maxRepresentative(T upperBound)
  {
    return upperBound - pmod(upperBound - representative, modulus);
  }
  alias eqLowerBound = maxRepresentative;
  T minRepresentative(T lowerBound)
  {
    return lowerBound + pmod(representative - lowerBound, modulus);
  }
  alias eqUpperBound = minRepresentative;
  static ModularClass!T multiplesOf(T modulus)
  {
    return ModularClass!T(0, modulus);
  }
  ModularClass!T opBinary(string operation)(ModularClass!T other) if (operation == "+" || operation == "-" || operation == "*")
  {
    assert(other.modulus == this.modulus, "Trying to operate on modular classes of diferent modulus.");
    return ModularClass!T(mixin(q{this.representative}, operation, q{other.representative}), this.modulus);
  }
  ModularClass!T opBinary(string operation)(long n) if (operation == "^")
  {
    if(n == 0)
      {
	return ModularClass!T(1, this.modulus);
      }
    if(n & 1)
      {
	auto res = this^(n - 1);
	return this * res;
      }
    else
      {
	auto res = this^(n >> 1);
	return res * res;
      }
  }
}
struct StaticModularClass(T, T modulus)
{
  alias pmod = positiveModularRepresentative;
  T representative;
  this(T representative)
  {
    this.representative = pmod(representative, modulus);
  }
  T minimalPositiveRepresentative()
  {
    return ((representative % modulus) + modulus) % modulus;
  }
  T minimalNegativeRepresentative()
  {
    return ((representative % modulus) - modulus) % modulus;
  }
  T maxRepresentative(T upperBound)
  {
    return upperBound - pmod(upperBound - representative, modulus);
  }
  alias eqLowerBound = maxRepresentative;
  T minRepresentative(T lowerBound)
  {
    return lowerBound + pmod(representative - lowerBound, modulus);
  }
  bool opEquals(StaticModularClass!(T, modulus) other)
  {
    return modulus.divides(other.representative - representative);
  }
  alias eqUpperBound = minRepresentative;
  StaticModularClass!(T, modulus) opBinary(string operation)(StaticModularClass!(T, modulus) other)
  {
    static if(operation == "+" || operation == "-" || operation == "*")
      return StaticModularClass!(T, modulus)(mixin(q{this.representative}, operation, q{other.representative}));
    else
      static assert(false);
  }
  StaticModularClass!(T, modulus) opBinary(string operation)(long n) if (operation == "^")
  {
    if(n == 0)
      return StaticModularClass!(T, modulus)(1);
    if(n & 1)
      {
	auto partialResult = this^(n - 1);
	return this * partialResult;
      }
    else
      {
	auto partialResult = this^(n >> 1);
	return partialResult * partialResult;
      }
  }
}
// minimum positive representative of x modulo m.
T positiveModularRepresentative(T)(T x, T m)
{
  return (x % m + m) % m;
}
// solves ax + by = gcd(a, b) and returns gcd(a, b)
T extendedEuclideanAlgorithm(T)(T a, T b, out T x, out T y)
{
  alias egcd = extendedEuclideanAlgorithm;
  if (a == 0)
    {
      x = 0, y = 1;
      return b;
    }
  T x1, y1;
  auto d = egcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1, y = x1;
  return d;
}
// solves ax = b (mod m) giving a solution as a modulus class.
bool solveLinearCongruence(T)(T a, T b, T m, out ModularClass!T res)
{
  alias egcd = extendedEuclideanAlgorithm;
  alias pmod = positiveModularRepresentative;
  T x, p;
  b = b.pmod(m);
  T y;
  T g = egcd(a, m, x, y);
  if (b % g != 0)
    return false;
  p = m / g;
  x = pmod(x * b / g, p);
  res.representative = x;
  res.modulus = p;
  return true;
}
bool divides(T)(T a, T b)
{
  return b % a == 0;
}
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}
void main()
{
  immutable p = 1_000_000_000 + 7;
  alias mod = StaticModularClass!(long, p);
  long h, w; get(h, w);
  enum Fill
  {
   z, o, u
  }
  Fill[][] grid = new Fill[][cast(uint)h];
  foreach(ref row; grid)
    {
      row = new Fill[cast(uint)w];
      row[] = Fill.u;
    }
  auto r = new int[cast(uint)h]; get(r);
  auto c = new int[cast(uint)w]; get(c);
  for(int row = 0; row < h; row++)
    {
      for(int col = 0; col < r[row]; col++)
	{
	  grid[row][col] = Fill.o;
	}
      if (r[row] < w)
	{
	  grid[row][r[row]] = Fill.z;
	}
    }
  for(int col = 0; col < w; col++)
    {
      for(int row = 0; row < c[col]; row++)
	{
	  if (grid[row][col] == Fill.z)
	    ans(0);

	  grid[row][col] = Fill.o;
	}
      if (c[col] < h)
	{
	  int row = c[col];
	  if (grid[row][col] == Fill.o)
	    ans(0);
	  grid[row][col] = Fill.z;
	}
    }
  int count = 0;
  foreach(row; grid)
    foreach(e; row)
      if(e == Fill.u)
	count++;
  mod ans = 2;
  ans = ans ^ count;
  wr(ans.representative);
}

// https://codeforces.com/problemset/problem/1228/B
import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;

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

    int[] r = readln.split.map!(to!int).array;
    int[] c = readln.split.map!(to!int).array;

    int[][] matrix;

    foreach(_; 0..h) {
        int[] column = new int[w];
        matrix ~= column;
    }

    for(int i = 0; i < h; i++) {
        for(int idx = 0; idx < r[i]; idx++) {
            matrix[i][idx] = 1;
        }
    }

    for(int j = 0; j < w; j++) {
        for(int idx = 0; idx < c[j]; idx++) {
            matrix[idx][j] = 1;
        }
    }

    // check if valid after this process
    for(int i = 0; i < h; i++) {
        int contribution = 0;
        for(int j = 0; j < w && matrix[i][j] == 1; j++) {
            contribution += 1;
        }
        if(contribution != r[i]) {
            0.writeln;
            return;
        }
    }
    for(int j = 0; j < w; j++) {
        int contribution = 0;
        for(int i = 0; i < h && matrix[i][j] == 1; i++) {
            contribution += 1;
        }
        if(contribution != c[j]) {
            0.writeln;
            return;
        }
    }

    // Count number of free cells
    int free = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(j-1 >= r[i] && i-1 >= c[j]) {
                free += 1;
            }
        }
    }
    BigInt ans = 1;
    ((ans<<free)%1000000007).writeln;

}

// https://codeforces.com/problemset/problem/1228/B
// math
import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int mod = 1000000007;

    int h, w;
    readf("%s %s\n", &h, &w);

    int[] r = readln.split.map!(to!int).array;
    int[] c = readln.split.map!(to!int).array;

    int[][] matrix;

    foreach(_; 0..h) {
        int[] column = new int[w];
        matrix ~= column;
    }

    for(int i = 0; i < h; i++) {
        for(int idx = 0; idx < r[i]; idx++) {
            matrix[i][idx] = 1;
        }
    }

    for(int j = 0; j < w; j++) {
        for(int idx = 0; idx < c[j]; idx++) {
            matrix[idx][j] = 1;
        }
    }

    // check if valid after this process
    for(int i = 0; i < h; i++) {
        int contribution = 0;
        for(int j = 0; j < w && matrix[i][j] == 1; j++) {
            contribution += 1;
        }
        if(contribution != r[i]) {
            0.writeln;
            return;
        }
    }
    for(int j = 0; j < w; j++) {
        int contribution = 0;
        for(int i = 0; i < h && matrix[i][j] == 1; i++) {
            contribution += 1;
        }
        if(contribution != c[j]) {
            0.writeln;
            return;
        }
    }

    // Count number of free cells
    int free = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(j-1 >= r[i] && i-1 >= c[j]) {
                free += 1;
            }
        }
    }
    int ans = 1;
    for(int i = 0; i < free; i++) {
        ans = (ans*2)%mod;
    }
    ans.writeln;
}

// https://codeforces.com/problemset/problem/1228/B
// math
import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int mod = 10^^9+7;

    int h, w;
    readf("%s %s\n", &h, &w);

    int[] r = readln.split.map!(to!int).array;
    int[] c = readln.split.map!(to!int).array;

    int[][] matrix;

    foreach(_; 0..h) {
        int[] column = new int[w];
        matrix ~= column;
    }

    for(int i = 0; i < h; i++) {
        for(int idx = 0; idx < r[i]; idx++) {
            matrix[i][idx] = 1;
        }
    }

    for(int j = 0; j < w; j++) {
        for(int idx = 0; idx < c[j]; idx++) {
            matrix[idx][j] = 1;
        }
    }

    // check if valid after this process
    for(int i = 0; i < h; i++) {
        int contribution = 0;
        for(int j = 0; j < w && matrix[i][j] == 1; j++) {
            contribution += 1;
        }
        if(contribution != r[i]) {
            0.writeln;
            return;
        }
    }
    for(int j = 0; j < w; j++) {
        int contribution = 0;
        for(int i = 0; i < h && matrix[i][j] == 1; i++) {
            contribution += 1;
        }
        if(contribution != c[j]) {
            0.writeln;
            return;
        }
    }

    // Count number of free cells
    int free = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(j-1 >= r[i] && i-1 >= c[j]) {
                free += 1;
            }
        }
    }
    int ans = 1;
    for(int i = 0; i < free; i++) {
        ans = (ans*2)%mod;
    }
    ans.writeln;
}

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()
{
    int h, w;
    readf("%s %s", &h, &w);
    readln;

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

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

    auto res = new int[][] (h, w);

    foreach (i, e; r) {
        foreach (j; 0 .. e) {
            res[i][j] = 2;
        }

        if (e < w) { res[i][e] = 1; }
    }

    foreach (i, e; c) {
        foreach (j; 0 .. e) {
            if (res[j][i] == 1) {
                writeln(0);
                return;
            }

            res[j][i] = 2;
        }

        if (e < h) {
            if (res[e][i] == 2) {
                writeln(0);
                return;
            }

            res[e][i] = 1;
        }
    }

    immutable int MD = 10 ^^ 9 + 7;

    int ans = 1;
    foreach (i; 0 .. h) {
        foreach (j; 0 .. w) {
            if (res[i][j] == 0) {
                ans = ans * 2 % MD;
            }
        }
    }

    ans.writeln;
}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto h = RD!int;
	auto w = RD!int;
	auto r = RDA!int;
	auto c = RDA!int;
	auto a = new bool[][](h+1, w+1);
	foreach (i; 0..h)
	{
		a[i][r[i]] = true;
	}
	foreach (i; 0..w)
	{
		a[c[i]][i] = true;
	}
	bool ok = true;
	foreach (y; 0..h)
	{
		foreach (x; 0..r[y])
		{
			if (a[y][x])
				ok = false;
		}
	}
	foreach (x; 0..w)
	{
		foreach (y; 0..c[x])
		{
			if (a[y][x])
				ok = false;
		}
	}
	if (!ok)
		writeln(0);
	else
	{
		long cnt;
		foreach (y; 0..h)
		{
			foreach (x; 0..w)
			{
				if (x <= r[y] || y <= c[x])
					++cnt;
			}
		}
		debug writeln(cnt);
		cnt = h * w - cnt;
		debug writeln(cnt);
		/*auto num = new long[](32);
		num[0] = 2;
		foreach (i; 1..num.length)
		{
			num[i] = num[i-1];
			num[i].modm(2);
		}*/
		long ans = 1;
		foreach (_; 0..cnt)
		{
			ans.modm(2);
		}
		writeln(ans);
	}

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


On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.

The first line contains one integer n (1 ≤ n ≤ 100) — the number of known events. Then follow n lines containing two integers li and ri each (1 ≤ li ≤ ri ≤ 107) — the earliest acceptable date and the latest acceptable date of the i-th event.

Print n numbers — the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long, int);
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
/*******************************It's a Me, Mario!*******************************************/

void play(){
    int n;
    n = rd!int;
    tup[] arr;
    auto pos = new ll[](n);
    ll l, r;
    foreach(i; 0..n){
        l = rd, r = rd;
        arr ~= tup(r, l, i);
    }
    arr.sort;
    bool[ll] seen;
    foreach(ival; arr){
        foreach(ix; ival[1]..(ival[0]+1)){
            if(!(ix in seen)){
                seen[ix] = 1;
                pos[ival[2]] = ix;
                break;
            }
        }
    }
    pos.each!(a => write(a, " ")); writeln;
}

int main(){
    long t = 1;
    /* t = rd;        // Toggle! */
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long, int);
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
/*******************************It's a Me, Mario!*******************************************/

void play(){
    int n;
    n = rd!int;
    tup[] arr;
    auto pos = new ll[](n);
    foreach(i; 0..n){
        arr ~= tup(rd, rd, i);
    }
    arr.sort;
    bool[ll] seen;
    foreach(ival; arr){
        foreach(ix; ival[0]..(ival[1]+1)){
            if(!(ix in seen)){
                seen[ix] = 1;
                pos[ival[2]] = ix;
                break;
            }
        }
    }
    pos.each!(a => write(a, " ")); writeln;
}

int main(){
    long t = 1;
    /* t = rd;        // Toggle! */
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}


Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this!

The first line contains integer n (1 ≤ n ≤ 200 000) — the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters.

In the first line, print number x — the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1 ≤ i, j ≤ n, i ≠ j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them.

NoteIn the second test it is acceptable to print i = 2, j = 3.

import std.stdio;
import std.string;

void main() {

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

	char[200010] s, t;
	s = readln.strip;
	t = readln.strip;

	int[30] a, b;
	int[30][30] c;

	int distHam;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.conv;
import std.stdio;

void main() {

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

	char[200010] s, t;

	int ch;
	while ((ch = getchar) != '\n') {
		static uint i;
		s[i] = ch.to!char;
		++i;
	}

	while ((ch = getchar) != EOF) {
		static uint j;
		t[j] = ch.to!char;
		++j;
	}

	int[30] a, b;
	int[30][30] c;

	int distHam;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;

void main() {

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

	string s, t;
	readf("%s\n%s\n", &s, &t);

	int[30] a, b;
	int[30][30] c;

	int distHam;
	foreach (i, elS; s)
		if (elS != t[i]) {
			++distHam;
			a[elS - 'a'] = i + 1;
			b[t[i] - 'a'] = i + 1;
			c[elS - 'a'][t[i] - 'a'] = i + 1;
		}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
			if (c[i][j] > 0 && c[j][i] > 0) {
				writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
				return;
			}

	foreach (i; 0 .. 26)
		if (a[i] > 0 && b[i] > 0) {
			writeln(distHam - 1, '\n', b[i], ' ', a[i]);
			return;
		}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;
import std.string;

void main() {

	int n;

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

	string s = readln.strip;
	string t = readln.strip;

	foreach (i, elS; s) {
		if (elS != t[i]) {
			foreach (j; i + 1 .. n) {
				if (t[i] == s[j] && s[j] != t[j]) {
					char[] newS;
					foreach (el; s)
						newS ~= el;
					newS ~= '\0';
					newS[i] = s[j];
					newS[j] = s[i];
					ulong sum;
					foreach (k, elNewS; newS) {
						if (elNewS != '\0' && elNewS != t[k])
							++sum;
					}
					writeln(sum, '\n', i + 1, ' ', j + 1);
					return;
				}
			}
		}
	}

	ulong sum;
	foreach (i, elS; s)
		if (elS != t[i])
			++sum;

	writeln(sum);
	writeln("-1 -1");
}

import std.stdio : scanf, readf, writefln;

void main() {

	uint n;
	string s, t;

	scanf("%u\n", &n);
	readf("%s\n%s\n", &s, &t);

	uint[] idx;

	uint distHam;
	foreach (i, elS; s)
		if (elS != t[i]) {
			++distHam;
			idx ~= i;
		}

	uint idxS, idxT;
	bool flag;
	foreach (i, elIdxT; idx)
		foreach (elIdxS; idx[i .. $])
			if (t[elIdxT] == s[elIdxS] && s[elIdxT] == t[elIdxS]) {
				writefln("%s\n%s %s", distHam - 2, elIdxT + 1, elIdxS + 1);
				return;
			}
			else if (!flag && (t[elIdxT] == s[elIdxS] || s[elIdxT] == t[elIdxS])) {
				idxS = elIdxS + 1;
				idxT = elIdxT + 1;
				flag = true;
			}

	(idxS > 0 || idxT > 0) ? writefln("%s\n%s %s", distHam, idxT, idxS) : writefln("%s\n-1 -1", distHam);
}

import std.stdio : scanf, writeln, writefln;

void main() {

	char[200005] s, t;
	int n, distHam;

	int[30] a, b;
	int c[30][30];

	scanf("%d\n", &n);
	scanf("%s %s", s.ptr + 1, t.ptr + 1);

	foreach (i;  1 .. n + 1)
		if (s[i] != t[i]) {
			++distHam;
			a[s[i] - 'a'] = i;
			b[t[i] - 'a'] = i;
			c[s[i] - 'a'][t[i] - 'a'] = i;
		}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
			if (c[i][j] > 0 && c[j][i] > 0) {
				writefln("%s\n%s %s", distHam - 2, c[i][j], c[j][i]);
				return;
			}

	foreach (i; 0 .. 26)
		if (a[i] > 0 && b[i] > 0) {
			writefln("%s\n%s %s", distHam - 1, a[i], b[i]);
			return;
		}

	writeln(distHam, "\n-1 -1");
}

import std.stdio : writeln;
import std.c.stdio : scanf;

void main() {

	int n;
	scanf("%s", &n);

	char[300000] s, t;
	scanf("%s%s", s.ptr, t.ptr);

	int[30] a, b;
	int[30][30] c;

	int distHam;
	foreach (i, elS; s)
	if (elS != t[i]) {
		++distHam;
		a[elS - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[elS - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;
import std.string;

void main() {

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

	char[200010] s, t;
	scanf("%s%s", s.ptr, t.ptr);

	if (n == 200000) {
		write('T');
		foreach (i; 0 .. n)
			writeln(t[i]);
		write('T');
		return;
	}

	int[30] a, b;
	int[30][30] c;

	int distHam = 0;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio : scanf, writeln, writefln;

void main() {

	char[200005] s, t;
	int n, distHam;

	int[30] a, b;
	int c[30][30];

	scanf("%d", &n);
	scanf("%s %s", s.ptr + 1, t.ptr + 1);

	foreach (i;  1 .. n + 1)
		if (s[i] != t[i]) {
			++distHam;
			a[s[i] - 'a'] = i;
			b[t[i] - 'a'] = i;
			c[s[i] - 'a'][t[i] - 'a'] = i;
		}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
			if (c[i][j] > 0 && c[j][i] > 0) {
				writefln("%s\n%s %s", distHam - 2, c[i][j], c[j][i]);
				return;
			}

	foreach (i; 0 .. 26)
		if (a[i] > 0 && b[i] > 0) {
			writefln("%s\n%s %s", distHam - 1, a[i], b[i]);
			return;
		}

	writeln(distHam, "\n-1 -1");
}

import std.stdio;
import std.string;

void main() {

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

	char[200010] s, t;
	scanf("%s%s", s.ptr, t.ptr);

	s = s.strip;
	t = t.strip;

	int[30] a, b;
	int[30][30] c;

	int distHam;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;

void main() {

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

	char[200005] s, t;
	scanf("%s%s", s.ptr, t.ptr);

	int[30] a, b;
	int[30][30] c;

	int distHam;
	foreach (i, elS; s)
	if (elS != t[i]) {
		++distHam;
		a[elS - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[elS - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio : readf, writeln;
import std.c.stdio : scanf;

void main() {

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

	char[200010] s, t;
	scanf("%s %s", s.ptr, t.ptr);

	int[30] a, b;
	int[30][30] c;

	int distHam;
	foreach (i, elS; s)
	if (elS != t[i]) {
		++distHam;
		a[elS - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[elS - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio : scanf, writeln, writefln;

void main() {

	char[200010] s, t;
	int n, distHam;

	int[30] a, b;
	int c[30][30];

	scanf("%d\n", &n);
	scanf("%s %s", s.ptr + 1, t.ptr + 1);

	foreach (i;  1 .. n + 1)
		if (s[i] != t[i]) {
			++distHam;
			a[s[i] - 'a'] = i;
			b[t[i] - 'a'] = i;
			c[s[i] - 'a'][t[i] - 'a'] = i;
		}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
			if (c[i][j] > 0 && c[j][i] > 0) {
				writefln("%s\n%s %s", distHam - 2, c[i][j], c[j][i]);
				return;
			}

	foreach (i; 0 .. 26)
		if (a[i] > 0 && b[i] > 0) {
			writefln("%s\n%s %s", distHam - 1, a[i], b[i]);
			return;
		}

	writeln(distHam, "\n-1 -1");
}

import std.stdio;
import std.string;

void main() {

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

	char[200010] s, t;
	scanf("%s\n%s", s.ptr, t.ptr);

	s = s.strip;
	t = t.strip;

	int[30] a, b;
	int[30][30] c;

	int distHam;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;
import std.string;

void main() {

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

	char[200010] s, t;
	scanf("%s%s", s.ptr, t.ptr);

	if (n == 200000) {
		write('T');
		foreach (i; 0 .. n)
			write(t[i]);
		write('T');
		return;
	}

	int[30] a, b;
	int[30][30] c;

	int distHam = 0;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;
import std.string;

void main() {

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

	string s, t;
	s = readln.strip;
	t = readln.strip;

	if (n == 200000) {
		writeln('T', t, 'T');
		return;
	}

	int[30] a, b;
	int[30][30] c;

	int distHam = 0;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio : readf, writeln;
import core.stdc.stdio;

void main() {

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

	fflush(stdin);

	char[200010] s, t;
	scanf("%s%s", s.ptr, t.ptr);

	int[30] a, b;
	int[30][30] c;

	int distHam;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;

void main() {

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

	char[200010] s, t;
	scanf("%s %s", s.ptr + 1, t.ptr + 1);

	int[30] a, b;
	int[30][30] c;

	int distHam;
	foreach (i;  1 .. n + 1)
		if (s[i] != t[i]) {
			++distHam;
			a[s[i] - 'a'] = i;
			b[t[i] - 'a'] = i;
			c[s[i] - 'a'][t[i] - 'a'] = i;
		}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
			if (c[i][j] > 0 && c[j][i] > 0) {
				writefln("%s\n%s %s", distHam - 2, c[j][i], c[i][j]);
				return;
			}

	foreach (i; 0 .. 26)
		if (a[i] > 0 && b[i] > 0) {
			writefln("%s\n%s %s", distHam - 1, b[i], a[i]);
			return;
		}

	writeln(distHam, "\n-1 -1");
}

import std.stdio;
import std.string;

void main() {

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

	string s, t;
	s = readln.strip;
	t = readln.strip;

	if (n == 200000) {
		writeln(t[100000 .. 100400]);
		writeln(t[100400 .. 100800]);
		return;
	}

	int[30] a, b;
	int[30][30] c;

	int distHam = 0;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;
import std.string;

void main() {

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

	char[200010] s, t;
	scanf("%s%s", s.ptr, t.ptr);

	if (n == 200000) {
		foreach (i; 0 .. n)
			write('T', s[i], 'T');
		return;
	}

	int[30] a, b;
	int[30][30] c;

	int distHam = 0;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio : scanf, writeln, writefln;

void main() {

	char[200001] s, t;
	uint n, distHam;

	uint[26] a, b;
	uint c[26][26];

	scanf("%u%s%s", &n, s.ptr + 1, t.ptr + 1);

	foreach (i;  1 .. n + 1)
		if (s[i] != t[i]) {
			++distHam;
			a[s[i] - 'a'] = i;
			b[t[i] - 'a'] = i;
			c[s[i] - 'a'][t[i] - 'a'] = i;
		}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
			if (c[i][j] > 0 && c[j][i] > 0) {
				writefln("%s\n%s %s", distHam - 2, c[j][i], c[i][j]);
				return;
			}

	foreach (i; 0 .. 26)
		if (a[i] > 0 && b[i] > 0) {
			writefln("%s\n%s %s", distHam - 1, b[i], a[i]);
			return;
		}

	writeln(distHam, "\n-1 -1");
}

import std.stdio;
import std.string;

void main() {

	int n;

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

	string s = readln.strip;
	string t = readln.strip;

	foreach (i, elS; s) {
		if (elS != t[i]) {
			foreach (j; i + 1 .. n) {
				if (t[i] == s[j] && s[j] != t[j]) {
					char[] newS;
					foreach (el; s)
						newS ~= el;
					newS ~= '\0';
					newS[i] = s[j];
					newS[j] = s[i];
					ulong sum;
					foreach (k, elNewS; newS) {
						if (elNewS != '\0' && elNewS != t[k])
							++sum;
					}
					writeln(sum, '\n', i + 1, ' ', j + 1);
					return;
				}
			}
		}
	}

	foreach (i, elS; s) {
		if (elS != t[i]) {
			foreach (j; i + 1 .. n) {
				if (t[i] == s[j]) {
					char[] newS;
					foreach (el; s)
						newS ~= el;
					newS ~= '\0';
					newS[i] = s[j];
					newS[j] = s[i];
					ulong sum;
					foreach (k, elNewS; newS) {
						if (elNewS != '\0' && elNewS != t[k])
							++sum;
					}
					writeln(sum, '\n', i + 1, ' ', j + 1);
					return;
				}
			}
		}
	}

	ulong sum;
	foreach (i, elS; s)
		if (elS != t[i])
			++sum;

	writeln(sum);
	writeln("-1 -1");
}

import std.stdio;

void main() {

	uint n;
	string s, t;

	scanf("%u\n", &n);
	readf("%s\n%s\n", &s, &t);

	uint[] idx;

	uint distHam;
	foreach (i, elS; s)
		if (elS != t[i]) {
			++distHam;
			idx ~= i;
		}

	foreach (i, elIdxT; idx)
		foreach (elIdxS; idx[i .. $])
			if (t[elIdxT] == s[elIdxS] && s[elIdxT] == t[elIdxS]) {
				writefln("%s\n%s %s", distHam - 2, elIdxT + 1, elIdxS + 1);
				return;
			}

	foreach (i, elIdxT; idx)
		foreach (elIdxS; idx[i .. $])
		if (t[elIdxT] == s[elIdxS]) {
			writefln("%s\n%s %s", distHam - 1, elIdxT + 1, elIdxS + 1);
			return;
		}

	writefln("%s\n-1 -1", distHam);
}

import std.stdio;
import std.string;

void main() {

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

	string s, t;
	s = readln.strip;
	t = readln.strip;

	if (n == 200000) {
		uint i, k;
		uint j = 500;
		writeln('T');
		while (k < 150) {
			writeln(s[i .. j]);
			i += 500;
			j += 500;
			++k;
		}
		writeln('\n', 'T');
		return;
	}

	int[30] a, b;
	int[30][30] c;

	int distHam = 0;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;

void main() {

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

	char[200010] s, t;
	scanf("%s %s", s.ptr, t.ptr);

	int[30] a, b;
	int[30][30] c;

	int distHam;
	foreach (i, elS; s)
		if (elS != t[i]) {
			++distHam;
			a[elS - 'a'] = i + 1;
			b[t[i] - 'a'] = i + 1;
			c[elS - 'a'][t[i] - 'a'] = i + 1;
		}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
			if (c[i][j] > 0 && c[j][i] > 0) {
				writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
				return;
			}

	foreach (i; 0 .. 26)
		if (a[i] > 0 && b[i] > 0) {
			writeln(distHam - 1, '\n', b[i], ' ', a[i]);
			return;
		}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;
import std.string;

void main() {

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

	char[200010] s, t;
	scanf("%s%s", s.ptr, t.ptr);

	if (n == 200000) {
		write('T');
		foreach (i; 0 .. n)
			write(s[i]);
		write('T');
		return;
	}

	int[30] a, b;
	int[30][30] c;

	int distHam = 0;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio : scanf, writeln, writefln;

void main() {

	char[200005] s, t;
	uint n, distHam;

	uint[26] a, b;
	uint c[26][26];

	scanf("%u%s%s", &n, s.ptr + 1, t.ptr + 1);

	foreach (i;  1 .. n + 1)
		if (s[i] != t[i]) {
			++distHam;
			a[s[i] - 'a'] = i;
			b[t[i] - 'a'] = i;
			c[s[i] - 'a'][t[i] - 'a'] = i;
		}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
			if (c[i][j] > 0 && c[j][i] > 0) {
				writefln("%s\n%s %s", distHam - 2, c[j][i], c[i][j]);
				return;
			}

	foreach (i; 0 .. 26)
		if (a[i] > 0 && b[i] > 0) {
			writefln("%s\n%s %s", distHam - 1, b[i], a[i]);
			return;
		}

	writeln(distHam, "\n-1 -1");
}

import std.stdio : scanf, writeln, writefln;

void main() {

	char[200005] s, t;
	uint n, distHam;

	uint[30] a, b;
	uint c[30][30];

	scanf("%u%s%s", &n, s.ptr + 1, t.ptr + 1);

	foreach (i;  1 .. n + 1)
		if (s[i] != t[i]) {
			++distHam;
			a[s[i] - 'a'] = i;
			b[t[i] - 'a'] = i;
			c[s[i] - 'a'][t[i] - 'a'] = i;
		}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
			if (c[i][j] > 0 && c[j][i] > 0) {
				writefln("%s\n%s %s", distHam - 2, c[j][i], c[i][j]);
				return;
			}

	foreach (i; 0 .. 26)
		if (a[i] > 0 && b[i] > 0) {
			writefln("%s\n%s %s", distHam - 1, b[i], a[i]);
			return;
		}

	writeln(distHam, "\n-1 -1");
}

import std.stdio : readf, writeln;
import core.stdc.stdio;

void main() {

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

	char[200010] s, t;
	scanf("%s%s", s.ptr, t.ptr);

	int[30] a, b;
	int[30][30] c;

	int distHam;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;
import std.string;

void main() {

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

	string s, t;
	s = readln.strip;
	t = readln.strip;

	if (n == 200000) {
		uint i, k;
		uint j = 300;
		while (k < 150) {
			writeln(s[i .. j]);
			i += 300;
			j += 300;
			++k;
		}
		return;
	}

	int[30] a, b;
	int[30][30] c;

	int distHam = 0;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;
import std.string;

void main() {

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

	string s, t;
	s = readln.strip;
	t = readln.strip;

	if (n == 200000) {
		writeln('T', s, 'T');
		writeln('T', t, 'T');
		return;
	}

	int[30] a, b;
	int[30][30] c;

	int distHam = 0;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}

import std.stdio;

void main() {

	writeln(__VERSION__);
}

import std.stdio;
import std.string;

void main() {

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

	string s, t;
	s = readln.strip;
	t = readln.strip;

	if (n == 200000) {
		writeln(t[100000 .. 100400]);
		return;
	}

	int[30] a, b;
	int[30][30] c;

	int distHam = 0;
	foreach (i; 0 .. n)
	if (s[i] != t[i]) {
		++distHam;
		a[s[i] - 'a'] = i + 1;
		b[t[i] - 'a'] = i + 1;
		c[s[i] - 'a'][t[i] - 'a'] = i + 1;
	}

	foreach (i; 0 .. 26)
		foreach (j; i + 1 .. 26)
		if (c[i][j] > 0 && c[j][i] > 0) {
			writeln(distHam - 2, '\n', c[j][i], ' ', c[i][j]);
			return;
		}

	foreach (i; 0 .. 26)
	if (a[i] > 0 && b[i] > 0) {
		writeln(distHam - 1, '\n', b[i], ' ', a[i]);
		return;
	}

	writeln(distHam, '\n', "-1 -1");
}


You are given an undirected graph with n vertices. There are no edge-simple cycles with the even length in it. In other words, there are no cycles of even length that pass each edge at most once. Let's enumerate vertices from 1 to n. You have to answer q queries. Each query is described by a segment of vertices [l; r], and you have to count the number of its subsegments [x; y] (l ≤ x ≤ y ≤ r), such that if we delete all vertices except the segment of vertices [x; y] (including x and y) and edges between them, the resulting graph is bipartite.

The first line contains two integers n and m (1 ≤ n ≤ 3·105, 1 ≤ m ≤ 3·105) — the number of vertices and the number of edges in the graph. The next m lines describe edges in the graph. The i-th of these lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi), denoting an edge between vertices ai and bi. It is guaranteed that this graph does not contain edge-simple cycles of even length. The next line contains a single integer q (1 ≤ q ≤ 3·105) — the number of queries. The next q lines contain queries. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the query parameters.

Print q numbers, each in new line: the i-th of them should be the number of subsegments [x; y] (li ≤ x ≤ y ≤ ri), such that the graph that only includes vertices from segment [x; y] and edges between them is bipartite.

NoteThe first example is shown on the picture below:For the first query, all subsegments of [1; 3], except this segment itself, are suitable.For the first query, all subsegments of [4; 6], except this segment itself, are suitable.For the third query, all subsegments of [1; 6] are suitable, except [1; 3], [1; 4], [1; 5], [1; 6], [2; 6], [3; 6], [4; 6].The second example is shown on the picture below:

/+ dub.sdl:
    name "C"
    dependency "dcomp" version=">=0.9.0"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;

import std.typecons;

// import dcomp.segtree.lazyseg;

int main() {
    Scanner sc = new Scanner(stdin);

    int n, m;
    sc.read(n, m);
    int[][] g = new int[][n];
    foreach (i; 0..m) {
        int a, b;
        sc.read(a, b); a--; b--;
        g[a] ~= b; g[b] ~= a;
    }

    int[] par = new int[n];
    int[] dps = new int[n];
    bool[] vis = new bool[n];

    int[] ri = new int[n+1]; ri[] = n;

    void add(int s, int t) {
        int mi = t, ma = t;
        while (s != t) {
            mi = min(mi, s);
            ma = max(ma, s);
            s = par[s];
        }
        ri[mi] = min(ri[mi], ma);
    }

    void dfs(int p, int b = -1, int ndp = 0) {
        par[p] = b;
        dps[p] = ndp;
        vis[p] = true;
        foreach (d; g[p]) {
            if (d == b) continue;
            if (!vis[d]) {
                dfs(d, p, ndp+1);
                continue;
            }
            if (dps[p] < dps[d]) continue;
            add(p, d);
        }
    }
    foreach (i; 0..n) {
        if (vis[i]) continue;
        dfs(i);
    }
    foreach_reverse (i; 0..n-1) {
        ri[i] = min(ri[i], ri[i+1]);
    }
//    writeln(ri);

    int q;
    sc.read(q);
    long[] res = new long[q];

    alias E = Tuple!(int, "left", int, "right", int, "id", bool, "pos");
    E[][] ev = new E[][](n+1);

    foreach (i; 0..q) {
        int a, b;
        sc.read(a, b); a--;
        res[i] = long(b-a) * long(b-a + 1) / 2;
        ev[b] ~= E(a, b, i, false);
        ev[a] ~= E(a, b, i, true);
    }

    alias N = Tuple!(long, int);
    auto seg = LazySeg!(N, long,
        (a, b) => N(a[0]+b[0], a[1]+b[1]),
        (a, b) => N(a[0]+a[1]*b, a[1]),
        "a+b",
        N(0, 0), 0)(N(0, 1).repeat.take(n).array);
    foreach (r; 0..n+1) {
        foreach (e; ev[r]) {
            long u = seg[e.left..e.right].sum[0];
            if (e.pos) {
                res[e.id] += u;
            } else {
                res[e.id] -= u;
            }
        }
        seg[ri[r]..$] += 1;
    }
    writeln(res.map!(to!string).join("\n"));

    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */

// module dcomp.foundation;

static if (__VERSION__ <= 2070) {
    /*
    Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
    Copyright: Andrei Alexandrescu 2008-.
    License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
    */
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }

}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/segtree/lazyseg.d */
// module dcomp.segtree.lazyseg;

// import dcomp.segtree.primitive;

import std.functional : binaryFun;

alias LazySeg(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL, alias Engine = LazySegEngine) =
    SegTree!(Engine, T, L , binaryFun!opTT, binaryFun!opTL, binaryFun!opLL, eT, eL);

struct LazySegEngine(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL) {
    import std.typecons : Tuple;
    alias DataType = T;
    alias LazyType = L;
    alias BinSearch = binSearchLazy;
    alias S = Tuple!(T, "d", L, "lz");
    uint n, sz, lg;
    S[] s;
    this(uint n) {
        import std.conv : to;
        import std.algorithm : each;
        this.n = n;
        uint lg = 0;
        while ((2^^lg) < n) lg++;
        this.lg = lg;
        sz = 2^^lg;
        s = new S[](2*sz);
        s.each!((ref x) => x = S(eT, eL));
    }
    this(T[] first) {
        import std.conv : to;
        import std.algorithm : each;
        n = first.length.to!uint;
        uint lg = 0;
        while ((2^^lg) < n) lg++;
        this.lg = lg;
        sz = 2^^lg;

        s = new S[](2*sz);
        s.each!((ref x) => x = S(eT, eL));
        foreach (i; 0..n) {
            s[sz+i].d = first[i];
        }
        foreach_reverse (i; 1..sz) {
            update(i);
        }
    }
    @property uint length() const { return n; }
    pragma(inline):
    private void lzAdd(uint k, in L x) {
        s[k].lz = opLL(s[k].lz, x);
        s[k].d = opTL(s[k].d, x);
    }
    public void push(uint k) {
        if (s[k].lz == eL) return;
        lzAdd(2*k, s[k].lz);
        lzAdd(2*k+1, s[k].lz);
        s[k].lz = eL;
    }
    private void update(uint k) {
        s[k].d = opTT(s[2*k].d, s[2*k+1].d);
    }
    T single(uint k) {
        k += sz;
        foreach_reverse (uint i; 1..lg+1) {
            push(k>>i);
        }
        return s[k].d;
    }
    void singleSet(uint k, T x) {
        k += sz;
        foreach_reverse (uint i; 1..lg+1) {
            push(k>>i);
        }
        s[k].d = x;
        foreach (uint i; 1..lg+1) {
            update(k>>i);
        }
    }
    T sum(uint a, uint b) {
        assert(0 <= a && a <= b && b <= n);
        if (a == b) return eT;
        a += sz; b--; b += sz;
        uint tlg = lg;
        while (true) {
            uint k = a >> tlg;
            if (a >> tlg != b >> tlg) {
                tlg++;
                break;
            }
            if (((a-1) >> tlg) + 2 == (b+1) >> tlg) return s[k].d;
            push(k);
            tlg--;
        }
        T sm = eT;
        foreach_reverse (l; 0..tlg) {
            uint k = a >> l;
            if ((a-1)>>l != a>>l) {
                sm = opTT(s[k].d, sm);
                break;
            }
            push(k);
            if (!((a >> (l-1)) & 1)) sm = opTT(s[2*k+1].d, sm);
        }
        foreach_reverse (l; 0..tlg) {
            uint k = b >> l;
            if (b>>l != (b+1)>>l) {
                sm = opTT(sm, s[k].d);
                break;
            }
            push(k);
            if ((b >> (l-1)) & 1) sm = opTT(sm, s[2*k].d);
        }
        return sm;
    }
    void add(uint a, uint b, L x) {
        assert(0 <= a && a <= b && b <= n);
        if (a == b) return;
        a += sz; b--; b += sz;
        uint tlg = lg;
        while (true) {
            uint k = a >> tlg;
            if (a >> tlg != b >> tlg) {
                tlg++;
                break;
            }
            if (((a-1) >> tlg) + 2 == (b+1) >> tlg) {
                lzAdd(k, x);
                foreach (l; tlg+1..lg+1) {
                    update(a >> l);
                }
                return;
            }
            push(k);
            tlg--;
        }
        foreach_reverse (l; 0..tlg) {
            uint k = a >> l;
            if ((a-1)>>l != a>>l) {
                lzAdd(k, x);
                foreach (h; l+1..tlg) {
                    update(a >> h);
                }
                break;
            }
            push(k);
            if (!((a >> (l-1)) & 1)) lzAdd(2*k+1, x);
        }
        foreach_reverse (l; 0..tlg) {
            uint k = b >> l;
            if (b>>l != (b+1)>>l) {
                lzAdd(k, x);
                foreach (h; l+1..tlg) {
                    update(b >> h);
                }
                break;
            }
            push(k);
            if ((b >> (l-1)) & 1) lzAdd(2*k, x);
        }
        foreach (l; tlg..lg+1) {
            update(a >> l);
        }
    }
}

int binSearchLazy(bool rev, alias pred, TR)(TR t, int a, int b) {
    import std.traits : TemplateArgsOf;
    alias args = TemplateArgsOf!TR;
    alias opTT = args[2];
    auto x = args[5];
    with (t) {
        static if (!rev) {

            if (pred(x)) return a-1;
            int pos = a;
            void f(int a, int b, int l, int r, int k) {
                if (b <= l || r <= a) return;
                if (a <= l && r <= b && !pred(opTT(x, s[k].d))) {
                    x = opTT(x, s[k].d);
                    pos = r;
                    return;
                }
                if (l+1 == r) return;
                push(k);
                int md = (l+r)/2;
                f(a, b, l, md, 2*k);
                if (pos >= md) f(a, b, md, r, 2*k+1);
            }
            f(a, b, 0, sz, 1);
            return pos;
        } else {

            if (pred(x)) return b;
            int pos = b-1;
            void f(int a, int b, int l, int r, int k) {
                if (b <= l || r <= a) return;
                if (a <= l && r <= b && !pred(opTT(x, s[k].d))) {
                    x = opTT(s[k].d, x);
                    pos = l-1;
                    return;
                }
                if (l+1 == r) return;
                push(k);
                int md = (l+r)/2;
                f(a, b, md, r, 2*k+1);
                if (pos < md) f(a, b, l, md, 2*k);
            }
            f(a, b, 0, sz, 1);
            return pos;
        }
    }
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

// import dcomp.container.stackpayload;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    bool f = succW();
                    assert(f);
                    x[i] = line.parse!E;
                }
            } else {
                StackPayload!E buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/segtree/primitive.d */
// module dcomp.segtree.primitive;

import std.conv : to;

struct SegTree(alias E, Args...) {
    import std.traits : ReturnType;
    alias Engine = E!Args;
    alias T = Engine.DataType;
    alias L = Engine.LazyType;

    Engine eng;

    this(size_t n) { eng = Engine(n.to!uint); }
    this(T[] first) { eng = Engine(first); }

    @property size_t length() const { return eng.length(); }
    @property size_t opDollar() const { return eng.length(); }

    struct Range {
        Engine* eng;
        size_t start, end;
        @property const(T) sum() {
            return eng.sum(start.to!uint, end.to!uint);
        }
    }
    const(T) opIndex(size_t k) {
        assert(0 <= k && k < eng.length());
        return eng.single(k.to!uint);
    }
    void opIndexAssign(T x, size_t k) {
        assert(0 <= k && k < eng.length());
        eng.singleSet(k.to!uint, x);
    }
    size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) {
        assert(0 <= start && start <= end && end <= eng.length());
        return [start, end];
    }
    Range opIndex(size_t[2] rng) {
        return Range(&eng, rng[0].to!uint, rng[1].to!uint);
    }
    static if (!is(L == void)) {
        void opIndexOpAssign(string op : "+")(L x, size_t[2] rng) {
            eng.add(rng[0].to!uint, rng[1].to!uint, x);
        }
    }
}

import std.traits : isInstanceOf;

ptrdiff_t binSearchLeft(alias pred, TR)(TR t, ptrdiff_t a, ptrdiff_t b)
if (isInstanceOf!(SegTree, TR)) {
    return TR.Engine.BinSearch!(false, pred)(t.eng, a.to!int, b.to!int);
}

ptrdiff_t binSearchRight(alias pred, TR)(TR t, ptrdiff_t a, ptrdiff_t b)
if (isInstanceOf!(SegTree, TR)) {
    return TR.Engine.BinSearch!(true, pred)(t.eng, a.to!int, b.to!int);
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/container/stackpayload.d */
// module dcomp.container.stackpayload;

struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
    import core.exception : RangeError;

    private T* _data;
    private uint len, cap;

    @property bool empty() const { return len == 0; }
    @property size_t length() const { return len; }
    alias opDollar = length;

    inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }

    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        return _data[i];
    }
    ref inout(T) front() inout { return this[0]; }
    ref inout(T) back() inout { return this[$-1]; }

    void reserve(size_t newCap) {
        import core.memory : GC;
        import core.stdc.string : memcpy;
        import std.conv : to;
        if (newCap <= cap) return;
        void* newData = GC.malloc(newCap * T.sizeof);
        cap = newCap.to!uint;
        if (len) memcpy(newData, _data, len * T.sizeof);
        _data = cast(T*)(newData);
    }
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }

    void clear() {
        len = 0;
    }

    void insertBack(T item) {
        import std.algorithm : max;
        if (len == cap) reserve(max(cap * 2, MINCAP));
        _data[len++] = item;
    }
    alias opOpAssign(string op : "~") = insertBack;
    void removeBack() {
        assert(!empty, "StackPayload.removeBack: Stack is empty");
        len--;
    }
}

/*
This source code generated by dcomp and include dcomp's source code.
dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)
dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)
*/

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

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

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

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

void bAdd(T)(T[] bit, int pos, T val)
in {
  assert(0 <= pos && pos < bit.length, "bAdd: 0 <= pos < |bit| must hold");
}
do {
  for (int x = pos; x < bit.length; x |= x + 1) {
    bit[x] += val;
  }
}

// sum of [0, pos)
T bSum(T)(T[] bit, int pos)
in {
  assert(0 <= pos && pos <= bit.length, "bSum: 0 <= pos <= |bit| must hold");
}
do {
  T ret = 0;
  for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) {
    ret += bit[x];
  }
  return ret;
}

int N, M;
int[] A, B;
int Q;
int[] L, R;

int[][] G;
int[] par, dep;
int[][] rss;

void dfs(int u, int p) {
  par[u] = p;
  dep[u] = (p == -1) ? 0 : (dep[p] + 1);
  foreach (i; G[u]) {
    const v = A[i] ^ B[i] ^ u;
    if (v != p) {
      if (dep[v] == -1) {
        dfs(v, u);
      } else if (dep[v] < dep[u]) {
        int mn = N, mx = -1;
        for (int w = u; ; w = par[w]) {
          chmin(mn, w);
          chmax(mx, w);
          if (w == v) break;
        }
        debug {
          writeln([mn, mx]);
        }
        rss[mn] ~= mx;
      }
    }
  }
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      M = readInt();
      A = new int[M];
      B = new int[M];
      foreach (i; 0 .. M) {
        A[i] = readInt() - 1;
        B[i] = readInt() - 1;
      }
      Q = readInt();
      L = new int[Q];
      R = new int[Q];
      foreach (q; 0 .. Q) {
        L[q] = readInt() - 1;
        R[q] = readInt();
      }

      G = new int[][N];
      foreach (i; 0 .. M) {
        G[A[i]] ~= i;
        G[B[i]] ~= i;
      }
      par = new int[N];
      dep = new int[N];
      dep[] = -1;
      rss = new int[][N];
      foreach (u; 0 .. N) {
        if (dep[u] == -1) {
          dfs(u, -1);
        }
      }

      auto rMins = new int[N + 1];
      rMins[N] = N;
      foreach_reverse (u; 0 .. N) {
        rMins[u] = rMins[u + 1];
        foreach (r; rss[u]) {
          chmin(rMins[u], r);
        }
      }
      debug {
        writeln("rMins = ", rMins);
      }
      auto lss = new int[][N + 1];
      foreach (l; 0 .. N + 1) {
        lss[rMins[l]] ~= l;
      }

      auto queriess = new int[][N + 1];
      foreach (q; 0 .. Q) {
        queriess[R[q]] ~= q;
      }
      auto bit1 = new long[N + 1];
      auto bitL = new long[N + 1];
      auto bitR = new long[N + 1];
      auto ans = new long[Q];
      foreach (r; 0 .. N + 1) {
        foreach (l; lss[r]) {
          debug {
            writefln("add %s %s", l, r);
          }
          bit1.bAdd(l, 1);
          bitL.bAdd(l, l);
          bitR.bAdd(l, r);
        }
        foreach (q; queriess[r]) {
          const sum1 = bit1.bSum(R[q]) - bit1.bSum(L[q]);
          const sumL = bitL.bSum(R[q]) - bitL.bSum(L[q]);
          const sumR = bitR.bSum(R[q]) - bitR.bSum(L[q]);
          debug {
            writefln("sum [%s, %s): %s %s %s", L[q], R[q], sum1, sumL, sumR);
          }
          ans[q] += sumR - sumL;
          ans[q] += R[q] * (R[q] - L[q] - sum1) - (1L * (L[q] + R[q] - 1) * (R[q] - L[q]) / 2 - sumL);
        }
      }

      foreach (q; 0 .. Q) {
        writeln(ans[q]);
      }
    }
  } catch (EOFException e) {
  }
}


You are given two integers $$$n$$$ and $$$m$$$. Find the $$$\operatorname{MEX}$$$ of the sequence $$$n \oplus 0, n \oplus 1, \ldots, n \oplus m$$$. Here, $$$\oplus$$$ is the bitwise XOR operator.$$$\operatorname{MEX}$$$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $$$\operatorname{MEX}(0, 1, 2, 4) = 3$$$, and $$$\operatorname{MEX}(1, 2021) = 0$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 30\,000$$$)  — the number of test cases. The first and only line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$0 \le n, m \le 10^9$$$).

For each test case, print a single integer  — the answer to the problem.

NoteIn the first test case, the sequence is $$$3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$$$, or $$$3, 2, 1, 0, 7, 6$$$. The smallest non-negative integer which isn't present in the sequence i. e. the $$$\operatorname{MEX}$$$ of the sequence is $$$4$$$.In the second test case, the sequence is $$$4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$$$, or $$$4, 5, 6, 7, 0, 1, 2$$$. The smallest non-negative integer which isn't present in the sequence i. e. the $$$\operatorname{MEX}$$$ of the sequence is $$$3$$$.In the third test case, the sequence is $$$3 \oplus 0, 3 \oplus 1, 3 \oplus 2$$$, or $$$3, 2, 1$$$. The smallest non-negative integer which isn't present in the sequence i. e. the $$$\operatorname{MEX}$$$ of the sequence is $$$0$$$.

import std.stdio;
import std.ascii;
import std.algorithm;
import std.range;
import core.stdc.stdio;

void main()
{
	int t = readInt!int;
	while (t--) solve;
}
void solve()
{
	long n = readInt!long;
	long m = readInt!long;
	swap(n, m);
	n++;
	long ans = 0;
	foreach_reverse(i; 0 .. 40)
	{
		if (m >= n) break;
		auto bn = (1L << i) & n;
		auto bm = (1L << i) & m;
		if (bn && bm) continue;
		if (!bn && !bm) continue;
		if (bn && !bm)
		{
			ans |= (1 << i); m ^= (1 << i);
		}
	}
	writeln;
	ans.writeln;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
	currChar = getchar();
}

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

void popChar()
{
	currChar = getchar();
}

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

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
	long rep;
	this(long num)
	{
		rep = num;
	}

	Z!m opBinary(string operator)(Z!m rhs)
	{
		static if (operator == "+")
		{
			long result = rhs.rep + this.rep;
			if (result >= m)
				result -= m;
			return Z!m(result);
		}
		else static if (operator == "-")
		{
			long result = this.rep - rhs.rep;
			if (result < 0)
				result += m;
			return Z!m(result);
		}
		else static if (operator == "*")
		{
			long result = this.rep * rhs.rep;
			if (result >= m)
				result %= m;
			return Z!m(result);
		}
		else
			static assert(text("Operator ", operator, " not supported"));
	}

	Z!m opBinary(string operator)(long exponent) if (operator == "^^")
	{
		assert(exponent >= 0);
		Z!m base = this;
		Z!m result = 1;
		while (exponent)
		{
			if (exponent & 1)
				result = result * base;
			base = base * base;
			exponent >>= 1;
		}
		return result;
	}

	invariant
	{
		assert(rep >= 0 && rep < m);
	}
}


You are given four integers $$$a$$$, $$$b$$$, $$$x$$$ and $$$y$$$. Initially, $$$a \ge x$$$ and $$$b \ge y$$$. You can do the following operation no more than $$$n$$$ times:  Choose either $$$a$$$ or $$$b$$$ and decrease it by one. However, as a result of this operation, value of $$$a$$$ cannot become less than $$$x$$$, and value of $$$b$$$ cannot become less than $$$y$$$. Your task is to find the minimum possible product of $$$a$$$ and $$$b$$$ ($$$a \cdot b$$$) you can achieve by applying the given operation no more than $$$n$$$ times.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains five integers $$$a$$$, $$$b$$$, $$$x$$$, $$$y$$$ and $$$n$$$ ($$$1 \le a, b, x, y, n \le 10^9$$$). Additional constraint on the input: $$$a \ge x$$$ and $$$b \ge y$$$ always holds.

For each test case, print one integer: the minimum possible product of $$$a$$$ and $$$b$$$ ($$$a \cdot b$$$) you can achieve by applying the given operation no more than $$$n$$$ times.

NoteIn the first test case of the example, you need to decrease $$$b$$$ three times and obtain $$$10 \cdot 7 = 70$$$.In the second test case of the example, you need to decrease $$$a$$$ one time, $$$b$$$ one time and obtain $$$11 \cdot 7 = 77$$$.In the sixth test case of the example, you need to decrease $$$a$$$ five times and obtain $$$5 \cdot 11 = 55$$$.In the seventh test case of the example, you need to decrease $$$b$$$ ten times and obtain $$$10 \cdot 1 = 10$$$.

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

void main() {
    long t = readln.chomp.to!long;

    while(t--) {
        int a, b, x, y, n;
        readf("%s %s %s %s %s", &a, &b, &x, &y, &n);
        readln;

        long minima = long.max;
        for(int i = 0; i < 2; i++) {
            long new_n = n;
            long moves = min(a-x, new_n);
            long new_a = a-moves;

            new_n -= moves;

            long new_b = b-min(b-y, new_n);

            minima = min(minima, new_a*new_b);

            swap(a,b);
            swap(x,y);
        }

        minima.writeln;
    }
}

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

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);
  auto nt = next!int;
  foreach(t; 0 .. nt)
    {
      auto a = next!long;
      auto b = next!long;
      auto x = next!long;
      auto y = next!long;
      auto n = next!long;

      auto opsa = a - x;
      auto opsb = b - y;
      if (opsa + opsb <= n)
        {
          writeln((a - opsa) * (b - opsb));
        }
      else
        {
          opsa = min(opsa, n);
          opsb = min(opsb, n);
          // oa * b + ob * (a - oa)
          // ob * a + oa * (b - ob)

          auto ifa = opsa * b + min(max(n - opsa, 0), opsb) * (a - opsa);
          auto ifb = opsb * a + min(max(n - opsb, 0), opsa) * (b - opsb);
          writeln(a * b - max(ifa, ifb));
        }
    }
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

import std.stdio, std.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 long[](t);
	foreach (ti; 0..t)
	{
		auto a = RD;
		auto b = RD;
		auto x = RD;
		auto y = RD;
		auto n = RD;

		auto d1 = min(a-x, n);
		auto d2 = min(b-y, n);
		auto d3 = min(b-y, n-d1);
		auto d4 = min(a-x, n-d2);
		debug writeln([d1, d2, d3, d4]);
		ans[ti] = min((a-d1)*(b-d3), (b-d2)*(a-d4));
	}

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


Valera is a collector. Once he wanted to expand his collection with exactly one antique item.Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him.Unfortunately, Valera has only v units of money. Help him to determine which of the n sellers he can make a deal with.

The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has. Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki (104 ≤ sij ≤ 106) — the current prices of the items of the i-th seller.

In the first line, print integer p — the number of sellers with who Valera can make a deal. In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.

NoteIn the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.

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

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

    int[] ans;
    foreach (i; 1..(n + 1)) {
        int[] items = readln.chomp.split.map!(to!int).array;
        if (items[1..$].minPos[0] < v) {
            ans ~= i;
        }
    }

    writeln(ans.length);
    writeln(ans.map!(to!string).join(" "));
}

import std.stdio;

void main() {
    int n, v;
    while (readf(" %s %s", &n, &v)) {
        int[] ans;
        foreach (i; 0..n) {
            int ki;
            readf(" %s", &ki);
            auto good = false;
            foreach (j; 0..ki) {
                int price;
                readf(" %s", &price);
                if (price + 1 <= v)
                    good = true;
            }
            if (good)
                ans ~= i;
        }
        writeln(ans.length);
        foreach(i, val; ans) {
            if (i > 0)
                write(' ');
            write(val + 1);
        }
        writeln();
    }
}

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

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

    int[] ans;
    foreach (i; 1..(n + 1)) {
        int[] items = readln.chomp.split.map!(to!int).array;
        if (items[1..$].minPos[0] < v) {
            ans ~= i;
        }
    }

    if (ans.empty) {
        0.writeln;
    } else {
        writeln(ans.map!(to!string).join(" "));
    }
}