import std.algorithm, std.conv, std.range, std.stdio;
void main () {
	int n;
	readf (" %s ", &n);
	auto a = readln.split.map !(to!int).array, t = sum (a, 0L);
	long [] p;
	for (long d = 2; d * d <= t; d++) {
		if (t % d < 1) {
			p ~= d;
			while (t % d < 1) t /= d;
		}
	}
	if (t > 1) p ~= t;
	long s (long d) {
		long c, r;
		foreach (i; 0..n - 1) {
			c += a[i];
			c %= d;
			r += min (c, d - c);
		}
		return r;
	}
	long z = long.max;
	foreach (ref c; p) z = min (z, s (c));
	writeln (z < long.max ? z : -1);
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto total = sum (a, 0L);
		if (total == 1)
		{
			writeln (-1);
			continue;
		}

		long [] p;
		for (long d = 2; d * d <= total; d++)
		{
			if (total % d == 0)
			{
				p ~= d;
				while (total % d == 0)
				{
					total /= d;
				}
			}
		}
		if (total > 1)
		{
			p ~= total;
		}

		long solve (long d)
		{
			long cur = 0;
			long res = 0;
			foreach (i; 0..n - 1)
			{
				cur += a[i];
				cur %= d;
				res += min (cur, d - cur);
			}
			return res;
		}

		long res = total * n;
		foreach (ref c; p)
		{
			res = min (res, solve (c));
		}
		writeln (res);
	}
}

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

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

void solve(){
	int n = rint;
	long[] as = rlong(n);

	long sum = as.sum;
	long[] ds;
	for(long d = 1; d * d <= sum; d ++) if(sum % d == 0) ds ~= d, ds ~= sum / d;
	log("as:", as, "sum:", sum, "ds:", ds);
	ds.sort();
	long[] d2s;
	A:
	foreach(d; ds){
		if(d == 1) continue;
		foreach(d2; d2s) if(d % d2 == 0) continue A;
		d2s ~= d;
	}
	ds = d2s;
	log("ds:", ds);

	long ans = as.sum * n;
	foreach(d; ds){
		long leftover;
		long tempans;
		long q;
		foreach(i, a; as){
			q += a, q %= d;
			if(q < d - q) tempans += q;
			else tempans += d - q;
			log("i:", i, "q:", q, "tempans:", tempans);
		}
		ans = min(ans, tempans);
		log("tempans:", tempans, "ans:", ans);
	}
	if(ans >= as.sum * n) ans = -1;
	ans.writeln;
}

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

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

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

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

enum INF = 10L^^18;

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

      const S = A.sum;
      long[] ps;
      long s = S;
      for (long p = 2; p * p <= s; ++p) {
        if (s % p == 0) {
          do {
            s /= p;
          } while (s % p == 0);
          ps ~= p;
        }
      }
      if (s > 1) {
        ps ~= s;
      }
      debug {
        writeln("ps = ", ps);
      }

      long ans = INF;
      foreach (p; ps) {
        long cost;
        long now;
        foreach (i; 0 .. N) {
          now += A[i];
          now %= p;
          cost += min(now, p - now);
        }
        debug {
          writeln(p, ": ", cost);
        }
        chmin(ans, cost);
      }
      writeln((ans >= INF) ? -1 : ans);
    }
  } 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]] > 1) {
            ++ans1;
          }
        } else {
          ++ans0;
          ++ans1;
        }
      }
      writeln(ans0, " ", ans1);
    }
  } catch (EOFException e) {
  }
}

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]] == 2) {
            ++ans1;
          }
        } else {
          ++ans0;
          ++ans1;
        }
      }
      writeln(ans0, " ", ans1);
    }
  } catch (EOFException e) {
  }
}


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


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

}

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


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


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

/+ 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)
*/


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


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


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

int toplamGuzellikSayisi = 0;

void main() {

    auto satirSayisi = stdin.readln.strip.to!int();
	char[] hulkunHisleri;
	for ( int i = 0; i < satirSayisi; i++ )
	{
		if ( i == satirSayisi - 1  )
		{
		    if ( i % 2 )
				hulkunHisleri ~= "I love it ";
			else
				hulkunHisleri ~= "I hate it ";
		}
		else if ( i % 2 )
			hulkunHisleri ~= "I love that ";
		else
			hulkunHisleri ~= "I hate that ";
	}
	writeln(hulkunHisleri.chomp());
}

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

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

        int read_int() {
                return read_string.to!int;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // int t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                char[] love = "I love".dup;
                char[] hate = "I hate".dup;
                for (int i = 0; i < n; i++) {
                        if (i % 2 == 0) write(hate);
                        else write(love);
                        if (i != n - 1) write(" that ");
                }
                write(" it");
                writeln();
        }
}

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

void main()
{
  auto n = stdin.readln.strip.to!int;
  write("I hate");
  for(int i = 2; i <= n; i++)
    write(" that I " ~ (i%2==0?"love":"hate"));
  writeln(" it");
}

import std.stdio;
import core.stdc.stdio;
import std.algorithm;
import std.math;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	write("I hate");
	foreach (int i; 1..n)
	{
		write((i % 2 == 0) ? " that I hate" : " that I love");
	}
	write(" it");
	return 0;
}

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

void main() {
    int n;
    scan(n);

    foreach (i ; 0 .. n) {
        write("I ", ["hate ", "love "][i&1], ["that ", "it"][i == n-1]);
    }
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

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

import std.stdio;

int main()
{
	int a=0;
	readf(" %d", &a);
	if (a%2==0)
	{
		for (int i=0; i<(a-2)/2; i++)
		{
			write("I hate that I love that ");
		}
		write("I hate that I love it");
	}
	else
	{
		for (int i=0; i<(a-1)/2; i++)
		{
			write("I hate that I love that ");
		}
		write("I hate it");
	}
	return 0;
}

import std.stdio;

int main()
{
	int a=0;
	readf(" %d", &a);
	if (a%3==1)
	{
		writeln("I hate it");
	}
	else if (a%3==2)
	{
		writeln("I hate that I love it");
	}
	else
	{
		writeln("I hate that I love that I hate it");
	}
	return 0;
}

import std.stdio;

int main()
{
	int a=0;
	readf(" %x", &a);
	if (a%3==1)
	{
		writeln("I hate it");
	}
	else if (a%3==2)
	{
		writeln("I hate that I love it");
	}
	else
	{
		writeln("I hate that I love that I hate it");
	}
	return 0;
}

import std.stdio;

int main()
{
	int a=0;
	readf(" %x", &a);
	if (a%2==0)
	{
		for (int i=0; i<(a-2)/2; i++)
		{
			write("I hate that I love that ");
		}
		write("I hate that I love it");
	}
	else
	{
		for (int i=0; i<(a-1)/2; i++)
		{
			write("I hate that I love that ");
		}
		write("I hate it");
	}
	return 0;
}


module main;

import std.c.stdio;

int main(string[] argv)
{
	int n;
	scanf("%d ", &n);
	char [] arr = new char[n];
	for(int i = 0; i < n; i++)
		scanf("%c", &arr[i]);
	for(int i = 0; i < n; i++){
	if(arr[i] == 'a' || arr[i] == 'i' || arr[i] == 'u' || arr[i] == 'y' || arr[i] == 'o' || arr[i] == 'e'){
    	if(i != n - 1 && arr[i] == arr[i + 1])
	        continue;
	   if(arr[i] == 'o' || arr[i] == 'e'){
	    if(i > 1 && arr[i - 2] == arr[i] && arr[i - 1] == arr[i]){
	    printf("%c", arr[i]);
	     continue;
	     }
	     if(i > 0 && arr[i - 1] == arr[i]){
	        printf("%c", arr[i]);
	     }
	   }
	   else
	   {
	    if(i && arr[i] == arr[i - 1]){
	    printf("%c", arr[i]);
	    continue;
	    }
	   }
    }
	    printf("%c", arr[i]);
	}
	return 0;
}

import std.stdio;
import std.string;

int n, cnt=0;

void main(string[] argv) {

	readf("%s\n", &n);
	string buff, ans="";
	//ans = "";
	buff = readln('\n');
	foreach(int i; 0..n) {
		    if((i>0)&&(buff[i]==buff[i-1]) &&
		    (buff[i]=='a'||buff[i]=='e'||buff[i]=='i'||buff[i]=='o'||buff[i]=='u'||buff[i]=='y')){
		        //cnt++;
		    }
		    else{
		       ans = ans~buff[i];
		    }

		    if((buff[i]=='e'||buff[i]=='o')
		    && (i==0 || (buff[i]!=buff[i-1])) && (i+1<n) && (buff[i]==buff[i+1]) && (i+2>=n || (buff[i]!=buff[i+2]))){
		        ans = ans~buff[i];
		    }

		/*if(buff.length <= 11)
			write(buff);
		else {
			writeln(buff[0], buff.length-3, buff[$-2]);
		}*/
	}
	write(ans);
	return;
}

module main;

import core.stdc.stdio;

int main(string[] arv) {
	int n;
	scanf("%d", &n);
	char [] s = new char[n];
	for(int i = 0; i < n; i++) scanf(" %c", &s[i]);
	for(int i = 0; i < n; i++) {
		if(s[i] != 'a' && s[i] != 'e' && s[i] != 'i' && s[i] != 'o' && s[i] != 'u' && s[i] != 'y')
			printf("%c", s[i]);
		else {
			int count = 1;
			for(int j = i + 1; j < n && s[i] == s[j]; j++) count++;
			if((s[i] == 'e' || s[i] == 'o') && count == 2)
				printf("%c%c", s[i], s[i]);
			else
				printf("%c", s[i]);
			while(s[i] == s[i+1]) i++;
		}
	}
	printf("\n");
	return 0;
}

import std.stdio : writeln, stdin;
import std.conv : to;
import std.range : dropOne;

import core.stdc.stdio;

int main(string[] argv)
{
     int cnt = 1;
     char last = 'Z';
     int n;
     scanf("%d",&n);
     foreach(words; stdin.byLine)
     {
        foreach(word;words){
        if(word != last){
            if (last != 'Z') {
                if (last == 'a' || last == 'e' || last == 'i' || last == 'o' || last == 'u' || last == 'y'){
                    if ((last != 'e' && last != 'o') || cnt != 2) cnt = 1;
                }
                for(int i = 0; i < cnt; ++i) printf("%c",last);
            }
            cnt = 0;
        }
        last = word;
        cnt++;
     }
     if (last != 'Z') {
          if (last == 'a' || last == 'e' || last == 'i' || last == 'o' || last == 'u' || last == 'y'){
             if ((last != 'e' && last != 'o') || cnt != 2) cnt = 1;
          }
           for(int i = 0; i < cnt; ++i) printf("%c",last);
      }
     }
	return 0;
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n;
	char chaine[3*1000*100+1];
	scanf("%d\n", &n);
	for(int i=0;i<n;i++)
	    scanf("%c", &chaine[i]);
	//putchar(chaine[0]);
	for(int i=0;i<n;i++){
	    if((chaine[i]!='a'&&chaine[i]!='e'&&chaine[i]!='i'&&chaine[i]!='o'&&chaine[i]!='u'&&chaine[i]!='y')|| chaine[i]!=chaine[i+1]||(chaine[i]!=chaine[i+2]&&(chaine[i]=='e'||chaine[i]=='o')))
	        putchar(chaine[i]);
        else{
            putchar(chaine[i]);
            i++;
            while(i<n&&chaine[i]==chaine[i-1])i++;
            i--;
        }
	}

	return 0;
}

import std.stdio : writeln, stdin;
import std.conv : to;
import std.range : dropOne;
import core.stdc.stdio;

void main()
{
    int n;
    scanf("%d", &n);
    string ss;
    int[100005] arr;
    for(int i = 0 ;i < 100005; ++i){
        arr[i] = 1;
    }
    foreach(word; stdin.byLine)
    {
        ss = to!string(word);
    }
    for (int i = 0; i < n; ++i) {
        int curr = i;
        if(!(ss[i] == 'a' || ss[i] =='e' || ss[i] =='i' || ss[i] =='o' || ss[i] =='u' || ss[i] =='y'))
        {
           continue;
        }
        while((i+1) < n && ss[i + 1] == ss[curr]){
            ++arr[curr];
            arr[i+1] = 0;
            ++i;
        }
    }

    for(int i = 0; i < n; ++i){
        if(arr[i] == 0){
            continue;
        }
         if(arr[i] ==2 && (ss[i] == 'e' || ss[i] == 'o'))
        {
            printf("%c%c", ss[i], ss[i]);
            while((i + 1) < n && arr[i+1] == 0)
            {
                ++i;
            }
        }
        else if(arr[i] > 0)
        {
            printf("%c", ss[i]);
            while((i + 1) < n && arr[i+1] == 0)
            {
                ++i;
            }
        }

    }
}

module main;
import std.c.stdio;
import std.stdio : writeln, stdin;
import std.conv : to;
import std.range : dropOne;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	char [] arr = new char[n + 1];
	scanf("%c", &arr[0]);
	for(int i = 0; i<n; i++)
		scanf("%c", &arr[i]);

	for(int i = 0; i < n; i++) {
        if ((i == 0 || arr[i - 1] != arr[i]) && i != n - 1 && arr[i] == 'o' && arr[i + 1] == 'o' && (i + 2 == n || arr[i + 2] != 'o')) {
            printf("%c", arr[i]);
            printf("%c", arr[i + 1]);
            i += 1;
        }
        else if ((i == 0 || arr[i - 1] != arr[i]) && i != n - 1 && arr[i] == 'e' && arr[i + 1] == 'e' && (i + 2 == n || arr[i + 2] != 'e')) {
            printf("%c", arr[i]);
            printf("%c", arr[i + 1]);
            i += 1;
        }
	    else if ((arr[i] == 'a' || arr[i] == 'i' || arr[i] == 'e' || arr[i] == 'o' || arr[i] == 'y' || arr[i] == 'u') && (i == 0 || arr[i] != arr[i - 1])) {
	        printf("%c", arr[i]);
	    }
	    else if (!(arr[i] == 'a' || arr[i] == 'i' || arr[i] == 'e' || arr[i] == 'o' || arr[i] == 'y' || arr[i] == 'u'))
	        printf("%c", arr[i]);
	}

	return 0;
}


// cheese-cracker [2022-02-06]

void solve(){
    long n = scan;
    long k = scan;

    if(k == 1 || (n % 2 == 0)){
        writeln("YES");
    }else{
        writeln("NO");
        return;
    }
    long m = n * k;
    long x = 1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < k; ++j){
            write(x, " ");
            x += 2;
            if(x > m){
                x = 2;
            }
        }
        writeln;
    }
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; alias tup = Tuple!(long, long);
T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }

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)); }
double euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

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

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

		auto m = n * k;
		auto m2 = m / 2;
		if (m2 % k) continue;

		ans[ti].length = n;
		foreach (i; 0..m2/k)
		{
			foreach (j; 0..k)
			{
				ans[ti][i] ~= (i*k + j + 1) * 2;
			}
		}
		foreach (i; m2/k..n)
		{
			foreach (j; 0..k)
			{
				ans[ti][i] ~= ((i-m2/k)*k + j) * 2 + 1;
			}
		}
	}

	foreach (e; ans)
	{
		if (e.empty)
			writeln("NO");
		else
		{
			writeln("YES");
			foreach (ee; e)
				ee.map!(to!string).join(" ").writeln;
		}
	}
	stdout.flush;
	debug readln;
}


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

string FMT_F = "%.10f";

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

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

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

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

T binarySearch(alias pred, T)(T ok, T ng)
{
	while (abs(ok-ng) > 1)
	{
		auto mid = (ok+ng)/2;
		if (unaryFun!pred(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

void main()
{
	auto n = RD!int;
	auto a = RDA;
	auto b = RDA;
	auto c = new long[](n);
	foreach (i; 0..n)
	{
		c[i] = a[i] - b[i];
	}
	c.sort();

	long ans;
	foreach (i; 0..n)
	{
		bool f(int x)
		{
			return c[i]+c[x] > 0;
		}
		auto cnt = n - binarySearch!(f)(n, cast(int)i);
		ans += cnt;
	}

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

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

void main()
{
    auto N = readln.chomp.to!int;
    auto as = readln.split.to!(long[]);
    auto bs = readln.split.to!(long[]);
    long[] cs;
    foreach (i; 0..N) cs ~= as[i] - bs[i];
    sort(cs);
    long res;
    foreach (i; 0..N-1) {
        auto c = cs[i];
        if (cs[$-1] + c <= 0) continue;
        if (cs[i+1] + c > 0) {
            res += N-i-1;
            continue;
        }
        int l = i+1, r = N-1;
        while (l+1 < r) {
            auto m = (l+r)/2;
            if (cs[m] + c > 0) {
                r = m;
            } else {
                l = m;
            }
        }
        res += N - r;
    }
    writeln(res);
}