// cheese-cracker [2022-01-25]

const long INF = 1000_000_000_000;

void main(){
    auto n = scanArray!int;

    auto arr = new tup[][4];
    arr[0] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[1] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[2] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[3] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;

    alias pr = Tuple!(int, int);
    for(int i = 0; i < 3; ++i){
        bool[pr] hmap;

        // Scan into hmap
        int m = scan!int;
        for(int j = 0; j < m; ++j){
            hmap[pr(scan!int, scan!int)] = 1;
        }

        // Sort and Update Prev Round
        int fst = i;
        int snd = fst+1;
        arr[fst].sort;
        foreach(ref el; arr[snd]){
            int x = el[1];
            bool f = 0;
            for(int k = 0; k < n[fst] && arr[fst][k][0] < INF; ++k){
                int y = arr[fst][k][1];
                if(! (pr(y, x) in hmap) ){
                    el[0] += arr[fst][k][0];
                    f = 1;
                    break;
                }
            }
            if(!f){ el[0] = INF; }
        }
        hmap.clear;
    }
    arr[3].sort;
    writeln((arr[3][0][0] < INF) ? arr[3][0][0] : -1);
}

/*_________________________*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, int);
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.algorithm;
import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.string;

immutable int infinity = int.max / 2;

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		auto n = s.splitter.map !(to !(int)).array;
		int [] [] a;
		foreach (i; 0..4)
		{
			a ~= readln.splitter.map !(to !(int)).array;
		}
		foreach (i; 0..3)
		{
			auto t = redBlackTree !(true) (a[i]);
			t.insert (infinity);
			auto g = new int [] [n[i + 1]];
			auto m = readln.strip.to !(int);
			foreach (j; 0..m)
			{
				auto v = readln.split;
				g[v[1].to !(int) - 1] ~= v[0].to !(int) - 1;
			}
			foreach (k; 0..n[i + 1])
			{
				foreach (c; g[k])
				{
					t.removeKey (a[i][c]);
				}
				auto value = t.front;
				foreach (c; g[k])
				{
					t.insert (a[i][c]);
				}
				a[i + 1][k] = (value < infinity) ?
				    a[i + 1][k] + value : infinity;
			}
		}
		auto res = a.back.minElement;
		writeln (res < infinity ? res : -1);
	}
}

// cheese-cracker [2022-01-25]

const long INF = 1000_000_000_000_000;

void main(){
    auto n = scanArray!int;

    auto arr = new tup[][4];
    arr[0] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[1] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[2] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[3] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;

    alias pr = Tuple!(int, int);
    for(int i = 0; i < 3; ++i){
        bool[pr] hmap;

        // Scan into hmap
        int m = scan!int;
        for(int j = 0; j < m; ++j){
            hmap[pr(scan!int, scan!int)] = 1;
        }

        // Sort and Update Prev Round
        int fst = i;
        int snd = fst+1;
        arr[fst].sort;
        foreach(ref el; arr[snd]){
            int x = el[1];
            bool f = 0;
            for(int k = 0; k < n[fst] && arr[fst][k][0] < INF; ++k){
                int y = arr[fst][k][1];
                if(! (pr(x, y) in hmap) ){
                    el[0] += arr[fst][k][0];
                    f = 1;
                    break;
                }
            }
            if(!f){ el[0] = INF; }
        }
    }
    arr[3].sort;
    writeln((arr[3][0][0] < INF) ? arr[3][0][0] : -1);
}

/*_________________________*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, int);
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; } }

// cheese-cracker [2022-01-25]

const long INF = 1_000_000_000;

void main(){
    auto n = scanArray!int;

    auto arr = new tup[][4];
    arr[0] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[1] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[2] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[3] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;

    alias pr = Tuple!(int, int);
    for(int i = 0; i < 3; ++i){
        auto hmap = redBlackTree!(pr);

        // Scan into hmap
        int m = scan!int;
        for(int j = 0; j < m; ++j){
            hmap.insert(pr(scan!int, scan!int));
        }

        // Sort and Update Prev Round
        int fst = i;
        int snd = fst+1;
        arr[fst].sort;
        foreach(ref el; arr[snd]){
            int x = el[1];
            bool f = 0;
            for(int k = 0; k < n[fst] && arr[fst][k][0] < INF; ++k){
                int y = arr[fst][k][1];
                if(! (pr(x, y) in hmap) ){
                    el[0] += arr[fst][k][0];
                    f = 1;
                    break;
                }
            }
            if(!f){ el[0] = INF; }
        }
    }
    arr[3].sort;
    writeln((arr[3][0][0] < INF) ? arr[3][0][0] : -1);
}

/*_________________________*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, int);
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; } }

// cheese-cracker [2022-01-25]

const long INF = 1_000_000_000;

void main(){
    auto n = scanArray!int;

    auto arr = new tup[][4];
    arr[0] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[1] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[2] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[3] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;

    alias pr = Tuple!(int, int);
    for(int i = 0; i < 3; ++i){
        bool[pr] hmap;

        // Scan into hmap
        int m = scan!int;
        for(int j = 0; j < m; ++j){
            hmap[pr(scan!int, scan!int)] = 1;
        }

        // Sort and Update Prev Round
        int fst = i;
        int snd = fst+1;
        arr[fst].sort;
        foreach(ref el; arr[snd]){
            int x = el[1];
            bool f = 0;
            for(int k = 0; k < n[fst] && arr[fst][k][0] < INF; ++k){
                int y = arr[fst][k][1];
                if(! (pr(x, y) in hmap) ){
                    el[0] += arr[fst][k][0];
                    f = 1;
                    break;
                }
            }
            if(!f){ el[0] = INF; }
        }
    }
    arr[3].sort;
    writeln((arr[3][0][0] < INF) ? arr[3][0][0] : -1);
}

/*_________________________*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, int);
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; } }

// cheese-cracker [2022-01-25]

const long INF = 1_000_000_000;

void main(){
    auto n = scanArray!int;

    auto arr = new tup[][4];
    arr[0] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[1] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[2] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;
    arr[3] = scanArray.enumerate.map!(a => tup(a[1], a[0].to!int + 1)).array;

    alias pr = Tuple!(int, int);
    for(int i = 0; i < 3; ++i){
        bool[pr] hmap;

        // Scan into hmap
        int m = scan!int;
        for(int j = 0; j < m; ++j){
            hmap[pr(scan!int, scan!int)] = 1;
        }

        // Sort and Update Prev Round
        int fst = i;
        int snd = fst+1;
        arr[fst].sort;
        foreach(ref el; arr[snd]){
            int x = el[1];
            bool f = 0;
            for(int k = 0; k < n[0] && arr[fst][k][0] < INF; ++k){
                int y = arr[fst][k][1];
                if(! (pr(x, y) in hmap) ){
                    el[0] += arr[fst][k][0];
                    f = 1;
                    break;
                }
            }
            if(!f){ el[0] = INF; }
        }
    }
    arr[3].sort;
    writeln((arr[3][0][0] < INF) ? arr[3][0][0] : -1);
}

/*_________________________*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, int);
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.algorithm;
import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.string;

immutable int infinity = int.max / 2;

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		auto n = s.splitter.map !(to !(int)).array;
		int [] [] a;
		foreach (i; 0..4)
		{
			a ~= readln.splitter.map !(to !(int)).array;
		}
		foreach (i; 0..3)
		{
			auto t = redBlackTree !(true) (a[i]);
			t.insert (infinity);
			auto g = new int [] [n[i + 1]];
			auto m = readln.strip.to !(int);
			foreach (j; 0..m)
			{
				auto v = readln.splitter.map !(to !(int)).array;
				v[] -= 1;
				g[v[1]] ~= v[0];
			}
			foreach (k; 0..n[i + 1])
			{
				foreach (c; g[k])
				{
					t.removeKey (a[i][c]);
				}
				auto value = t.front;
				foreach (c; g[k])
				{
					t.insert (a[i][c]);
				}
				a[i + 1][k] = (value < infinity) ?
				    a[i + 1][k] + value : infinity;
			}
		}
		auto res = a.back.maxElement;
		writeln (res < infinity ? res : -1);
	}
}


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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long k;
    readf!" %d "(k);
    long x, y;
    while ((x + 1) * (x + 1) < k)
      x++;
    y = k - x * x - 1;
    if (y <= x) {
      writefln("%d %d", y + 1, x + 1);
    } else {
      long delta = y - x;
      y = x;
      x -= delta;
      writefln("%d %d", y + 1, x + 1);
    }
  }
}

// Cheese-Cracker: cheese-cracker.github.io

void theCode(){
    ll k = scan;
    k -= 1;
    ll rt = to!ll(floor(sqrt(to!double(k))));
    if((rt + 1) *(rt + 1) <= k){
        rt += 1;
    }
    ll lef = k - rt*rt;
    ll d = min(rt, lef);
    ll b = max(0, lef - rt);
    ll x = (rt+1) - b;
    ll y = d + 1;
    writeln(y, " ", x);
}

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

/*********  That's All Folks!  *********/
import std.stdio, std.random, std.functional, std.container, std.algorithm;
import std.numeric, std.range, std.typecons, std.string, std.math, std.conv;
string[] tk; 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; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		readln;
		auto s = readln.strip;
		auto t = readln.strip;
		auto b = n - m + 1;
		auto r = s[0..b];
		auto can = (t[0] == '0') ?
		    r.minElement == '0' :
		    r.maxElement == '1';
		writeln ((can && s[b..$] == t[1..$]) ? "YES" : "NO");
	}
}

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

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

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

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

enum INF = 10L^^18;

int N, M;
string A, B;

bool solve() {
  if (A[N - M + 1 .. N] != B[1 .. M]) {
    return false;
  }
  bool[2] has;
  foreach (i; 0 .. N - M + 1) {
    has[A[i] - '0'] = true;
  }
  if (has[0] && B[0] == '0') return true;
  if (has[1] && B[0] == '1') return true;
  return false;
}

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

        const ans = solve;
        writeln(ans ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}


import std.stdio;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;
import std.functional;

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }

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 solve() {
    int n,m,k;
    readf!" %d %d %d "(n,m,k);
    auto a = readarray!int;
    bool flag = true;
    int capacity;
    int maxR = k;
    bool[int] memory;
    foreach(e; a) {
        if (e == maxR)
            maxR--;
        else {
            memory[e] = true;
            capacity++;
        }
        while (maxR in memory) {
            memory.remove(maxR);
            capacity--;
            maxR--;
        }
        if (capacity > n*m - 4) {
            flag = false;
            break;
        }
    }
    if (flag)
        writeln("YA");
    else
        writeln("TIDAK");
}

void main() {
    int T = read!int;
    foreach (t; 0 .. T) solve();
}

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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    long n, m, k;
    readf!" %d %d %d "(n, m, k);
    auto a = readln.splitter.map!(to!long).map!(x => k + 1 - x).array;
//    writeln(a);
    long maxsize = n * m - 3;
    auto h = redBlackTree!("a<b", true, long)();
    long stored = 0;
    bool good = true;
    foreach (x ; a) {
      while (!h.empty && h.front == stored + 1) {
        stored = h.front;
        h.removeFront;
      }
      if (h.length >= maxsize) {
        good = false;
        break;
      }
      h.insert(x);
    }
//    writeln(h);
    while (!h.empty && h.front == stored + 1) {
      stored = h.front;
      h.removeFront;
    }
    if (!h.empty)
      good = false;
    writeln(good ? "YA" : "TIDAK");
  }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m, k;
		readf !(" %s %s %s") (n, m, k);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		a[] -= 1;
		int limit = n * m - 4;
		bool ok = true;
		int num = 0;
		int last = k - 1;
		auto vis = new bool [k];
		foreach (i, ref cur; a)
		{
			vis[cur] = true;
			num += 1;
			while (last >= 0 && vis[last])
			{
				last -= 1;
				num -= 1;
			}
			ok &= (num <= limit);
		}
		writeln (ok ? "YA" : "TIDAK");
	}
}

import std.stdio;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;
import std.functional;

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }

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 solve() {
    int n,m,k;
    readf!" %d %d %d "(n,m,k);
    auto a = readarray!int;
    bool flag = true;
    int capacity;
    int maxR = k;
    bool[int] memory;
    foreach(e; a) {
        if (e == maxR)
            maxR--;
        else {
            memory[e] = true;
            capacity++;
        }
        while (maxR in memory) {
            memory.remove(maxR);
            capacity--;
            maxR--;
        }
        if (capacity > (n-1)*(m-1)) {
            flag = false;
            break;
        }
    }
    if (flag)
        writeln("YA");
    else
        writeln("TIDAK");
}

void main() {
    int T = read!int;
    foreach (t; 0 .. T) solve();
}

import std.stdio;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;
import std.functional;

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }

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 solve() {
    int n,m,k;
    readf!" %d %d %d "(n,m,k);
    auto a = readarray!int;
    bool flag = true;
    int capacity;
    int maxR = k;
    bool[int] memory;
    foreach(e; a) {
        if (e == maxR)
            maxR--;
        else {
            memory[e] = true;
            capacity++;
        }
        while (maxR in memory) {
            memory.remove(e);
            capacity--;
            maxR--;
        }
        if (capacity > (n-1)*(m-1)) {
            flag = false;
            break;
        }
    }
    if (flag)
        writeln("YA");
    else
        writeln("TIDAK");
}

void main() {
    int T = read!int;
    foreach (t; 0 .. T) solve();
}


module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,
	std.functional,std.math,std.string,std.range,std.complex,std.bitmanip,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,
	std.meta,core.stdc.stdio : freopen;
import std.numeric: fft,Fft,gcd,inverseFft;
alias big=BigInt;alias pair(X,Y)=Tuple!(X,"fi",Y,"se");
alias lint=long;private const int mod=1_000_000_007;
alias pii=pair!(int,int);alias pll=pair!(long,long);alias mp=make_pair;alias gcd=std.numeric.gcd;
private
{
	pure nothrow
	{
		T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
		pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
		big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
		@property X sqr(X)(in X a_) {return a_*a_;}
		@property X cub(X)(in X a_) {return a_*a_*a_;}
		int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
		size_t lowb(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(!(a[m]<g))r=m;
				else l=m;
			}
			return (!(a[l]<g))?l:r;
		}
		size_t upb(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(g<a[m])r=m;
				else l=m;
			}
			return (g<a[l])?l:r;
		}
		size_t binf(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			auto pos=lowb(a,g);
			return (g==a[pos])?pos:a.length;
		}
		bool binary_search(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			return binf(a,g)!=a.length;
		}
	}
	void putarr(X)(in X a,in char ch=' ') if(isInputRange!X && !isInputRange!(ElementEncodingType!X))
	{foreach(const ref i;a)write(i,ch);}
	void putarr(X)(in X a) if(isInputRange!X && isInputRange!(ElementEncodingType!X))
	{
		foreach(ref const i;a)
		{
			foreach(ref const j;i)write(j,' ');
			writeln;
		}
	}
	bool getarr(X)(X a,in size_t n)
	{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
	bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		size_t s=0;
		foreach(ref e;ptrs)
		{
			if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
			else s+=readf(" %s",&e);
		}
		return s==ptrs.length;
	}
	bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		size_t s=0;
		foreach(ref e;ptrs)
		{
			if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
			else s+=readf(" %s",&e);
		}
		readln;
		return s==ptrs.length;
	}
	nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
	nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
	@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
private
{

}
void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int a,b,c;
loop:while(read(a,b,c))
	{
		int n;
		read(n);
		auto ar=arread!int;
		sort(ar);
		debug writeln(ar);
		debug writeln(lowb(ar,c),' ',upb(ar,b));
		writeln(max(lowb(ar,c)*1L-upb(ar,b)*1L,0));
	}
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,
	std.functional,std.math,std.string,std.range,std.complex,std.bitmanip,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,
	std.meta,core.stdc.stdio : freopen;
import std.numeric: fft,Fft,gcd,inverseFft;
alias big=BigInt;alias pair(X,Y)=Tuple!(X,"fi",Y,"se");
alias lint=long;private const int mod=1_000_000_007;
alias pii=pair!(int,int);alias pll=pair!(long,long);alias mp=make_pair;alias gcd=std.numeric.gcd;
private
{
	pure nothrow
	{
		T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
		pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
		big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
		@property X sqr(X)(in X a_) {return a_*a_;}
		@property X cub(X)(in X a_) {return a_*a_*a_;}
		int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
		size_t lowb(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(!(a[m]<g))r=m;
				else l=m;
			}
			return (!(a[l]<g))?l:r;
		}
		size_t upb(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(g<a[m])r=m;
				else l=m;
			}
			return (g<a[l])?l:r;
		}
		size_t binf(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			auto pos=lowb(a,g);
			return (g==a[pos])?pos:a.length;
		}
		bool binary_search(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			return binf(a,g)!=a.length;
		}
	}
	void putarr(X)(in X a,in char ch=' ') if(isInputRange!X && !isInputRange!(ElementEncodingType!X))
	{foreach(const ref i;a)write(i,ch);}
	void putarr(X)(in X a) if(isInputRange!X && isInputRange!(ElementEncodingType!X))
	{
		foreach(ref const i;a)
		{
			foreach(ref const j;i)write(j,' ');
			writeln;
		}
	}
	bool getarr(X)(X a,in size_t n)
	{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
	bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		size_t s=0;
		foreach(ref e;ptrs)
		{
			if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
			else s+=readf(" %s",&e);
		}
		return s==ptrs.length;
	}
	bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		size_t s=0;
		foreach(ref e;ptrs)
		{
			if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
			else s+=readf(" %s",&e);
		}
		readln;
		return s==ptrs.length;
	}
	nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
	nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
	@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
private
{

}
void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int a,b,c;
loop:while(read(a,b,c))
	{
		int n;
		read(n);
		int ans;
		foreach(i;0..n)
		{
			int x;
			input(x);
			if(x>b && x<c)ans++;
		}
		writeln(ans);
	}
}

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

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

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

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

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

      int ans;
      foreach (i; 0 .. N) {
        if (B < X[i] && X[i] < C) {
          ++ans;
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,
	std.functional,std.math,std.string,std.range,std.complex,std.bitmanip,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,
	std.meta,core.stdc.stdio : freopen;
import std.numeric: fft,Fft,gcd,inverseFft;
alias big=BigInt;alias pair(X,Y)=Tuple!(X,"fi",Y,"se");
alias lint=long;private const int mod=1_000_000_007;
alias pii=pair!(int,int);alias pll=pair!(long,long);alias mp=make_pair;alias gcd=std.numeric.gcd;
private
{
	pure nothrow
	{
		T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
		pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
		big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
		@property X sqr(X)(in X a_) {return a_*a_;}
		@property X cub(X)(in X a_) {return a_*a_*a_;}
		int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
		size_t lowb(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(!(a[m]<g))r=m;
				else l=m;
			}
			return (!(a[l]<g))?l:r;
		}
		size_t upb(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			auto pos=lowb(a,g);
			if(pos==a.length)return pos;
			else return a[pos]==g?pos+1:pos;
		}
		size_t binf(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			auto pos=lowb(a,g);
			return (g==a[pos])?pos:a.length;
		}
		bool binary_search(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			return binf(a,g)!=a.length;
		}
	}
	void putarr(X)(in X a,in char ch=' ') if(isInputRange!X && !isInputRange!(ElementEncodingType!X))
	{foreach(const ref i;a)write(i,ch);}
	void putarr(X)(in X a) if(isInputRange!X && isInputRange!(ElementEncodingType!X))
	{
		foreach(ref const i;a)
		{
			foreach(ref const j;i)write(j,' ');
			writeln;
		}
	}
	bool getarr(X)(X a,in size_t n)
	{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
	bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		size_t s=0;
		foreach(ref e;ptrs)
		{
			if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
			else s+=readf(" %s",&e);
		}
		return s==ptrs.length;
	}
	bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		size_t s=0;
		foreach(ref e;ptrs)
		{
			if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
			else s+=readf(" %s",&e);
		}
		readln;
		return s==ptrs.length;
	}
	nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
	nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
	@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
private
{

}
void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int a,b,c;
loop:while(read(a,b,c))
	{
		int n;
		read(n);
		auto ar=arread!int;
		sort(ar);
		debug writeln(lowb(ar,c),' ',upb(ar,b));
		writeln(max(lowb(ar,c)*1L-upb(ar,b)*1L,0));
	}
}


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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long a, b;
    readf!" %d %d "(a, b);
    long g = gcd(a, b);
//    writeln(g);
    if (b < a) {
      long tmp = b;
      b = a;
      a = tmp;
    }
//    writefln("a=%d b=%d", a, b);
    long d = b - a;
//    writefln("d=%d", d);
    if (a == b) {
      writeln("0 0");
      continue;
    }
    long ans1 = abs(a - a / d * d);
    long ans2 = abs(a - (a + d - 1) / d * d);
    long ans3 = a;
    writefln("%d %d", d, min(ans1, ans2, ans3));
  }
}

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[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

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 a = RD;
		auto b = RD;

		if (a == b)
		{
			ans[ti] = [0, 0];
			continue;
		}
		if (a > b)
			swap(a, b);
		auto d = b - a;
		auto rem = b % d;
		ans[ti] = [d, min((d-rem) % d, rem)];
	}

	foreach (e; ans)
		writeln(e[0], " ", e[1]);
	stdout.flush;
	debug readln;
}

// code by cutx64

module main;

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

void main() {

  int tests; readf!"%s\n"(tests);
  while(tests--) {
    long a, b;
    readf!"%s %s\n"(a, b);
    if (a == b) {
      "0 0".writeln;
    }
    else {
      long d = abs(a - b);
      long g = min(a % d, d - (a % d));
      writefln!"%s %s"(d, g);
    }
  }

} // main

// Cheese-Cracker: cheese-cracker.github.io

void theCode(){
    ll a = scan;
    ll b = scan;
    ll diff = abs(a - b);
    ll rem = 0;
    if(diff > 0){
        rem = min(b % diff, diff - (b % diff));
    }
    writeln(diff, " ", rem);
}

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

/*********  That's All Folks!  *********/
import std.stdio, std.random, std.functional, std.container, std.algorithm;
import std.numeric, std.range, std.typecons, std.string, std.math, std.conv;
string[] tk; 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; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");

// Vicfred
// https://codeforces.com/contest/1543/problem/A
// math
import std.algorithm;
import std.stdio;

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

while(t--) {
    long a, b;
    readf("%s %s\n", &a, &b);
    if(a == b) {
        "0 0".writeln;
        continue;
    }
    if(a > b) {
        swap(a, b);
    }
    writefln("%s %s", b - a, min(a % (b - a), b - a - a % (b - a)));
}
}

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[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

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 a = RD;
		auto b = RD;

		if (a == b)
		{
			ans[ti] = [0, 0];
			continue;
		}
		else if (a == 0)
		{
			ans[ti] = [b, 0];
			continue;
		}
		if (a > b)
			swap(a, b);
		auto d = b - a;
		auto rem = b % d;
		ans[ti] = [d, (d-rem) % d];
	}

	foreach (e; ans)
		writeln(e[0], " ", e[1]);
	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)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

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 a = RD;
		auto b = RD;

		if (a == b)
		{
			ans[ti] = [0, 0];
			continue;
		}
		if (a > b)
			swap(a, b);
		auto d = b - a;
		auto rem = b % d;
		ans[ti] = [d, (d-rem) % d];
	}

	foreach (e; ans)
		writeln(e[0], " ", e[1]);
	stdout.flush;
	debug readln;
}


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

immutable int MED_N = 1 << 17;
immutable int MAX_N = MED_N << 1;

struct Node
{
	int max_value;
	int max_position;
	long sum_values;
}

__gshared Node [MAX_N] t;

long get_sum (int l, int r)
{
	long res = 0;
	for (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1)
	{
		if (l & 1)
		{
			res += t[l].sum_values;
			l++;
		}
		if (!(r & 1))
		{
			res += t[r].sum_values;
			r--;
		}
	}
	return res;
}

void assign (int k, int x)
{
	assert (MED_N <= k && k < MAX_N);
	t[k].max_value = x;
	t[k].max_position = k;
	t[k].sum_values = x;
	for (int i = k >> 1; i > 0; i >>= 1, k >>= 1)
	{
		if (t[k].max_value < t[k ^ 1].max_value)
		{
			k ^= 1;
		}
		t[i].max_value = t[k].max_value;
		t[i].max_position = t[k].max_position;
		t[i].sum_values = t[k].sum_values + t[k ^ 1].sum_values;
	}
}

void modulo (int k, int x)
{
	while (t[k].max_value >= x)
	{
		assign (t[k].max_position, t[k].max_value % x);
	}
}

void modulo (int l, int r, int x)
{
	for (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1)
	{
		if (l & 1)
		{
			modulo (l, x);
			l++;
		}
		if (!(r & 1))
		{
			modulo (r, x);
			r--;
		}
	}
}

void main ()
{
	int n;
	int m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		auto a = new int [n];
		foreach (i, ref x; a)
		{
			readf (" %s", &x);
			assign (i + MED_N, x);
		}
		foreach (q; 0..m)
		{
			int t;
			int l;
			int r;
			int x;
			int k;
			readf (" %s", &t);
			switch (t)
			{
				case 1:
					readf (" %s %s", &l, &r);
					writeln (get_sum (l - 1, r - 1));
					break;
				case 2:
					readf (" %s %s %s", &l, &r, &x);
					modulo (l - 1, r - 1, x);
					break;
				case 3:
					readf (" %s %s", &k, &x);
					assign (k - 1 + MED_N, x);
					break;
				default:
					assert (false);
			}
		}
	}
}

import std.stdio;

immutable int MED_N = 1 << 17, MAX_N = MED_N << 1;

struct Node {int v, p; long s;}

Node [MAX_N] t;

long get_sum (int l, int r) {
	long res = 0;
	for (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {
		if (l & 1)    res += t[l].s, l++;
		if (!(r & 1)) res += t[r].s, r--;
	}
	return res;
}

void assign (int k, int x) {
	t[k].v = x;
	t[k].p = k;
	t[k].s = x;
	for (int i = k >> 1; i > 0; k = i, i >>= 1) {
		if (t[k].v < t[k ^ 1].v) k ^= 1;
		t[i].v = t[k].v;
		t[i].p = t[k].p;
		t[i].s = t[k].s + t[k ^ 1].s;
	}
}

void modulo (int k, int x) {
	while (t[k].v >= x) assign (t[k].p, t[k].v % x);
}

void modulo (int l, int r, int x) {
	for (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {
		if (l & 1)    modulo (l, x), l++;
		if (!(r & 1)) modulo (r, x), r--;
	}
}

void main () {
	int n, m, t, l, r, x, k;
	while (readf (" %s %s", &n, &m) > 0) {
		foreach (i; 1..n + 1) {
			readf (" %s", &x);
			assign (i + MED_N, x);
		}
		foreach (q; 0..m) {
			readf (" %s", &t);
			if (t == 1) {
				readf (" %s %s", &l, &r);
				writeln (get_sum (l, r));
			} else if (t == 2) {
				readf (" %s %s %s", &l, &r, &x);
				modulo (l, r, x);
			} else if (t == 3) {
				readf (" %s %s", &k, &x);
				assign (k + MED_N, x);
			}
		}
	}
}

import std.stdio;

immutable int MED_N = 1 << 17;
immutable int MAX_N = MED_N << 1;

struct Node
{
	int v, p;
	long s;
}

Node [MAX_N] t;

long get_sum (int l, int r)
{
	long res = 0;
	for (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1)
	{
		if (l & 1)
		{
			res += t[l].s;
			l++;
		}
		if (!(r & 1))
		{
			res += t[r].s;
			r--;
		}
	}
	return res;
}

void assign (int k, int x)
{
	t[k].v = x;
	t[k].p = k;
	t[k].s = x;
	for (int i = k >> 1; i > 0; k = i, i >>= 1)
	{
		if (t[k].v < t[k ^ 1].v)
		{
			k ^= 1;
		}
		t[i].v = t[k].v;
		t[i].p = t[k].p;
		t[i].s = t[k].s + t[k ^ 1].s;
	}
}

void modulo (int k, int x)
{
	while (t[k].v >= x)
	{
		assign (t[k].p, t[k].v % x);
	}
}

void modulo (int l, int r, int x)
{
	for (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1)
	{
		if (l & 1)
		{
			modulo (l, x);
			l++;
		}
		if (!(r & 1))
		{
			modulo (r, x);
			r--;
		}
	}
}

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		auto a = new int [n];
		foreach (i, ref x; a)
		{
			readf (" %s", &x);
			assign (i + MED_N, x);
		}
		foreach (q; 0..m)
		{
			int t, l, r, x, k;
			readf (" %s", &t);
			switch (t)
			{
				case 1:
					readf (" %s %s", &l, &r);
					writeln (get_sum (l - 1, r - 1));
					break;
				case 2:
					readf (" %s %s %s", &l, &r, &x);
					modulo (l - 1, r - 1, x);
					break;
				case 3:
					readf (" %s %s", &k, &x);
					assign (k - 1 + MED_N, x);
					break;
				default:
					assert (false);
			}
		}
	}
}

import std.stdio;

immutable int MED_N = 1 << 17, MAX_N = MED_N << 1;

struct Node {int v, p; long s;}

void main () {
Node [MAX_N] a;

long get_sum (int l, int r) {
	long res = 0;
	for (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {
		if (l & 1)    res += a[l].s, l++;
		if (!(r & 1)) res += a[r].s, r--;
	}
	return res;
}

void assign (int k, int x) {
	a[k].v = x;
	a[k].p = k;
	a[k].s = x;
	for (int i = k >> 1; i > 0; k = i, i >>= 1) {
		if (a[k].v < a[k ^ 1].v) k ^= 1;
		a[i].v = a[k].v;
		a[i].p = a[k].p;
		a[i].s = a[k].s + a[k ^ 1].s;
	}
}

void modulo (int k, int x) {
	while (a[k].v >= x) assign (a[k].p, a[k].v % x);
}

void modulo2 (int l, int r, int x) {
	for (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {
		if (l & 1)    modulo (l, x), l++;
		if (!(r & 1)) modulo (r, x), r--;
	}
}

	int n, m, t, l, r, x, k;
	while (readf (" %s %s", &n, &m) > 0) {
		foreach (i; 1..n + 1) {
			readf (" %s", &x);
			assign (i + MED_N, x);
		}
		foreach (q; 0..m) {
			readf (" %s", &t);
			if (t == 1) {
				readf (" %s %s", &l, &r);
				writeln (get_sum (l, r));
			} else if (t == 2) {
				readf (" %s %s %s", &l, &r, &x);
				modulo2 (l, r, x);
			} else if (t == 3) {
				readf (" %s %s", &k, &x);
				assign (k + MED_N, x);
			}
		}
	}
}

import std.stdio;

immutable int MED_N = 1 << 17, MAX_N = MED_N << 1;

struct Node {int v, p; long s;}

class D {
static:
Node [MAX_N] t;

long get_sum (int l, int r) {
	long res = 0;
	for (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {
		if (l & 1)    res += t[l].s, l++;
		if (!(r & 1)) res += t[r].s, r--;
	}
	return res;
}

void assign (int k, int x) {
	t[k].v = x;
	t[k].p = k;
	t[k].s = x;
	for (int i = k >> 1; i > 0; k = i, i >>= 1) {
		if (t[k].v < t[k ^ 1].v) k ^= 1;
		t[i].v = t[k].v;
		t[i].p = t[k].p;
		t[i].s = t[k].s + t[k ^ 1].s;
	}
}

void modulo (int k, int x) {
	while (t[k].v >= x) assign (t[k].p, t[k].v % x);
}

void modulo (int l, int r, int x) {
	for (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {
		if (l & 1)    modulo (l, x), l++;
		if (!(r & 1)) modulo (r, x), r--;
	}
}

void solve () {
	int n, m, t, l, r, x, k;
	while (readf (" %s %s", &n, &m) > 0) {
		foreach (i; 1..n + 1) {
			readf (" %s", &x);
			assign (i + MED_N, x);
		}
		foreach (q; 0..m) {
			readf (" %s", &t);
			if (t == 1) {
				readf (" %s %s", &l, &r);
				writeln (get_sum (l, r));
			} else if (t == 2) {
				readf (" %s %s %s", &l, &r, &x);
				modulo (l, r, x);
			} else if (t == 3) {
				readf (" %s %s", &k, &x);
				assign (k + MED_N, x);
			}
		}
	}
}
}

void main () {
	D.solve ();
}

import std.stdio;

immutable int MED_N = 1 << 17, MAX_N = MED_N << 1;

struct Node {int v, p; long s;}

__gshared Node [MAX_N] t;

long get_sum (int l, int r) {
	long res = 0;
	for (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {
		if (l & 1)    res += t[l].s, l++;
		if (!(r & 1)) res += t[r].s, r--;
	}
	return res;
}

void assign (int k, int x) {
	t[k].v = x;
	t[k].p = k;
	t[k].s = x;
	for (int i = k >> 1; i > 0; k = i, i >>= 1) {
		if (t[k].v < t[k ^ 1].v) k ^= 1;
		t[i].v = t[k].v;
		t[i].p = t[k].p;
		t[i].s = t[k].s + t[k ^ 1].s;
	}
}

void modulo (int k, int x) {
	while (t[k].v >= x) assign (t[k].p, t[k].v % x);
}

void modulo (int l, int r, int x) {
	for (l += MED_N, r += MED_N; l <= r; l >>= 1, r >>= 1) {
		if (l & 1)    modulo (l, x), l++;
		if (!(r & 1)) modulo (r, x), r--;
	}
}

void main () {
	int n, m, t, l, r, x, k;
	while (readf (" %s %s", &n, &m) > 0) {
		foreach (i; 1..n + 1) {
			readf (" %s", &x);
			assign (i + MED_N, x);
		}
		foreach (q; 0..m) {
			readf (" %s", &t);
			if (t == 1) {
				readf (" %s %s", &l, &r);
				writeln (get_sum (l, r));
			} else if (t == 2) {
				readf (" %s %s %s", &l, &r, &x);
				modulo (l, r, x);
			} else if (t == 3) {
				readf (" %s %s", &k, &x);
				assign (k + MED_N, x);
			}
		}
	}
}


import std.algorithm.sorting : sort;
import std.stdio;

void main()
{
  char c;
  int n, k;
  readf!"%d %d\n"(n, k);
  auto a = new int[n];
  auto b = new int[n-1];
  foreach (i; 0..n) readf!"%d%c"(a[i], c);
  foreach (i; 0..n-1) b[i] = a[i] - a[i+1];

  b.sort;

  int s = a[$-1] - a[0];
  foreach (i; 0..k-1) s += b[i];

  writeln(s);
}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto n = RD!int;
	auto k = RD!int;
	auto a = RDA;
	auto d = new long[](n-1);
	foreach (i; 0..n-1)
	{
		d[i] = a[i+1] - a[i];
	}
	d.sort();
	auto ans = d[0..$-(k-1)].sum;

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

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

void solve(){
	int n = read.to!int;
	int k = read.to!int;
	long[] as;
	foreach(i; 0 .. n) as ~= read.to!int;

	long sum = as[n - 1] - as[0];
	log("sum:", sum);

	long[] ds;
	foreach(i; 0 .. n - 1) ds ~= as[i + 1] - as[i];
	log("ds:", ds);

	ds.sort!"a>b"();
	log("ds:", ds);

	foreach(i; 0 .. k - 1){
		sum -= ds[i];
	}

	sum.writeln;

}


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

immutable int MD = 998244353;

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

    if (n.to!long * m * 2 % k != 0) {
        writeln("NO");
        return;
    }

    auto r = 2*n;
    auto c = m;

    auto q = gcd(r, k);
    r /= q;
    k /= q;

    c /= k;

    if (r > n) r /= 2, c *= 2;
    if (c > m) {
        writeln("NOdf");
        return;
    }

    auto p1 = tuple(0, 0);
    auto p2 = tuple(r, 0);
    auto p3 = tuple(0, c);

    writeln("YES");
    [p1, p2, p3].each!(t => writeln(t[0], ' ', t[1]));
}

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  long n, m, k;
  rd(n, m, k);
  if (n * m * 2 % k != 0) {
    writeln("NO");
    return;
  }

  writeln("YES");
  bool odd = true;
  if (k % 2 == 0) {
    k /= 2;
    odd = false;
  }
  import std.numeric : gcd;

  auto g = gcd(n, k), a = n / g;
  k /= g;
  auto b = m / k;
  if (odd) {
    if (a == n) {
      b *= 2;
    } else {
      a *= 2;
    }
  }
  writeln(0, " ", 0);
  writeln(a, " ", 0);
  writeln(0, " ", b);

}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}

import core.stdc.stdio;
import std.algorithm;
int n,m,k;
int gcd(int p,int q)
{
	if (q==0)
	{
		return p;
	}
	return gcd(q,p%q);
}
void main()
{
    int i,x,y;
	scanf("%d%d%d",&n,&m,&k);
	if (cast(long)2*n*m%k!=0)
	{
		printf("NO\n");
		return;
	}
	printf("YES\n");
	if (k%2==0)
	{
		k/=2;
		x=gcd(n,k);
		y=k/x;
		printf("0 0\n");
		printf("%d 0\n",n/x);
		printf("0 %d\n",m/y);
		return;
	}
	x=gcd(n,k);
	y=k/x;
	printf("0 0\n");
	printf("%d 0\n",n/x*(x>1?2:1));
	printf("0 %d\n",m/y*(x>1?1:2));
}

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

immutable int MD = 998244353;

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

    if (n.to!long * m * 2 % k != 0) {
        writeln("NO");
        return;
    }

    auto r = 2*n;
    auto c = m;

    auto q = gcd(r, k);
    r /= q;
    k /= q;

    c /= k;

    if (r > n) r /= 2, c *= 2;

    auto p1 = tuple(0, 0);
    auto p2 = tuple(r, 0);
    auto p3 = tuple(0, c);

    writeln("YES");
    [p1, p2, p3].each!(t => writeln(t[0], ' ', t[1]));
}

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

immutable int MD = 998244353;

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

    if (n.to!long * m % (2*k) != 0) {
        writeln("NO");
        return;
    }

    auto q = gcd(n, k);
    auto r = n / q;
    k /= q;

    auto c = m / k;
    // k /= k;

    if (r * 2 <= n) r *= 2;
    else if (c * 2 <= m) c *= 2;
    else {
        writeln("NO");
        return;
    }

    auto p1 = tuple(0, 0);
    auto p2 = tuple(r, 0);
    auto p3 = tuple(0, c);

    writeln("YES");
    [p1, p2, p3].each!(t => writeln(t[0], ' ', t[1]));
}

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

immutable int MD = 998244353;

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

    if (n.to!long * m % k != 0) {
        writeln("NO");
        return;
    }

    auto r = 2*n;
    auto c = m;

    auto q = gcd(r, k);
    r /= q;
    k /= q;

    c /= k;

    if (r > n) r /= 2, c *= 2;
    if (c > m) {
        writeln("NO");
        return;
    }

    auto p1 = tuple(0, 0);
    auto p2 = tuple(r, 0);
    auto p3 = tuple(0, c);

    writeln("YES");
    [p1, p2, p3].each!(t => writeln(t[0], ' ', t[1]));
}

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  long n, m, k;
  rd(n, m, k);
  if (n * m * 2 % k != 0) {
    writeln("NO");
    return;
  }

  writeln("YES");
  if (k % 2 == 0)
    k /= 2;
  import std.numeric : gcd;

  auto g = gcd(n, k), a = n / g;
  k /= g;
  auto b = m / k;
  if (a * b / 2 != n * m * k) {
    if (a == n) {
      b *= 2;
    } else {
      a *= 2;
    }
  }
  writeln(0, " ", 0);
  writeln(a, " ", 0);
  writeln(0, " ", b);

}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  long n, m, k;
  rd(n, m, k);
  if (n * m * 2 % k != 0) {
    writeln("NO");
    return;
  }

  writeln("YES");
  if (k % 2 == 0)
    k /= 2;
  import std.numeric : gcd;

  auto g = gcd(n, k), a = n / g;
  k /= g;
  auto b = m / k;
  if (a == n) {
    b *= 2;
  } else {
    a *= 2;
  }
  writeln(0, " ", 0);
  writeln(a, " ", 0);
  writeln(0, " ", b);

}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  import std.bigint;

  BigInt n, m, k;
  rd(n, m, k);

  BigInt ansx, ansy;
  bool enough(BigInt x) { // x>0
    // x*y*0.5 = nm/k -> xy*k = 2nm
    auto y = m * n * 2 / k / x;
    if (y <= 0)
      return true;
    ansx = x;
    ansy = y;
    return x * y * k >= m * n * 2;
  }

  BigInt ng = 0, ok = n + 1;
  while (ok - ng > 1) {
    auto mid = (ng + ok) / 2;
    if (enough(mid))
      ok = mid;
    else
      ng = mid;
  }
  if (0 <= ok && ok <= n) {
    if (ansx * ansy * k == 2 * n * m) {
      writeln("YES");
      writeln(0, " ", 0);
      writeln(ansx, " ", 0);
      writeln(0, " ", ansy);
    } else {
      writeln("NO");
    }
  } else {
    writeln("NO");
  }
}

void rd(T...)(ref T x) {
  import std.stdio, std.string, std.conv;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


// Vicfred
// https://codeforces.com/contest/1494/problem/A
// brute force
import std.array;
import std.stdio;

bool check(string s) {
    int c = 0;
    foreach(p; s) {
        if(p == '(')
            c += 1;
        else
            c -= 1;
        if(c < 0)
            return false;
    }
    return c == 0;
}

string generate(string t) {
    string p = "()";
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
            for(int k = 0; k < 2; k++) {
                string s = t
                    .replace('A', p[i])
                    .replace('B', p[j])
                    .replace('C', p[k]);

                if(check(s)) {
                    return "YES";
                }
            }
        }
    }
    return "NO";
}

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

while(t--) {
    string a;
    readf("%s\n", &a);
    generate(a).writeln;
}
}

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

bool isGood (R) (R s)
{
	int balance = 0;
	foreach (c; s)
	{
		balance += c ? +1 : -1;
		if (balance < 0)
		{
			return false;
		}
	}
	return balance == 0;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		bool ok = false;
		foreach (i; 0..8)
		{
			int [char] t;
			t['A'] = (i >> 0) & 1;
			t['B'] = (i >> 1) & 1;
			t['C'] = (i >> 2) & 1;
			ok |= isGood (s.byChar.map !(c => t[c]));
		}
		writeln (ok ? "YES" : "NO");
	}
}

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

string FMT_F = "%.10f";

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

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

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

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(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 bool[](t);
	foreach (ti; 0..t)
	{
		auto a = RD!string;

		foreach (i; 0..2^^3)
		{
			auto arr = new int[](3);
			arr[0] = i & 0b100;
			arr[1] = i & 0b010;
			arr[2] = i & 0b001;
			long cnt;
			bool ok = true;
			foreach (c; a)
			{
				auto num = c - 'A';
				if (arr[num])
					++cnt;
				else
					--cnt;
				if (cnt < 0)
				{
					ok = false;
					break;
				}
			}
			if (!ok) continue;
			if (cnt == 0)
			{
				ans[ti] = true;
				break;
			}
		}
	}

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


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		readln;
		auto k = readln.splitter.map !(to !(int)).array;
		auto c = readln.splitter.map !(to !(int)).array;
		sort (k);
		int lo = 1;
		for (int j = 1; j <= m; j++)
		{
			if (j <= n && j < k[$ - j])
			{
				k[$ - j] = j;
			}
			else
			{
				break;
			}
		}
		writeln (k.map !(i => c[i - 1]).sum (0L));
	}
}

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

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

alias C = Tuple!(int, "i", long, "k", long, "c");

void main()
{
    int T; get(T);
    while (T--) {
        int N, M; get(N, M);
        int[] KS; get(KS);
        long[] CS; get(CS);
        C[] cs;
        foreach (i, c; CS) cs ~= C(i.to!int, 0, c);
        foreach (k; KS) ++cs[k - 1].k;
        sort!"a.c > b.c"(cs);
        auto bs = new bool[](M);
        long r;
        int i;
        foreach (c; cs) {
            while (c.k > 0 && i < c.i) {
                if (!bs[i]) {
                    bs[i] = true;
                    r += CS[i];
                    --c.k;
                }
                ++i;
            }
            bs[c.i] = true;
            while (c.k > 0) {
                r += c.c;
                --c.k;
            }
        }
        writeln(r);
    }
}

// Cheese-Cracker: cheese-cracker.github.io

void theCode(){
    int n, m;
    n = scan!int, m = scan!int;
    auto peeps = scanArray;
    auto gifts = scanArray;
    peeps.sort;
    peeps.reverse;
    ll res = 0;
    int gptr = 0;
    for(int i = 0; i < n; ++i){
        if(gptr < m && gifts[gptr] < gifts[to!int(peeps[i]-1)]){
            res += gifts[gptr];
            ++gptr;
        }else{
            res += gifts[to!int(peeps[i] -1)];
        }
    }
    writeln(res);
}

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

/*********  That's All Folks!  *********/
import std.stdio, std.random, std.functional, std.container, std.algorithm;
import std.numeric, std.range, std.typecons, std.string, std.math, std.conv;
string[] tk; 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; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");

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(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 m = RD!int;
		auto k = RDA!int(-1);
		auto c = RDA;

		k.sort();
		BinaryHeap!(Array!long, "a > b") heap1, heap2;
		int ci;
		foreach (i; 0..n)
		{
			while (ci <= k[i])
			{
				heap1.insert(c[ci]);
				++ci;
			}
			heap2.insert(c[k[i]]);
			if (heap2.front <= heap1.front)
			{
				ans[ti] += heap2.front; heap2.removeFront;
			}
			else
			{
				ans[ti] += heap1.front; heap1.removeFront;
			}
		}
	}

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


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

void read(S...)(ref S args) {
  auto input = readln.split;
  assert(input.length == args.length);
  foreach (i, ref arg; args) {
    arg = input[i].to!(S[i]);
  }
}

auto list(T)() { return readln.split.map!(e => e.to!T).array; }

string[] words;

int solve(char c) {
  int[] arr = new int[words.length];

  foreach (i, w; words) {
    auto a = w.count(c).to!int;
    arr[i] = a - (w.length.to!int - a);
  }

  sort(arr);
  reverse(arr);

  if (arr[0] < 1) return 0;

  long total = arr[0];
  int answer = 1;

  foreach (i; 1 .. arr.length) {
    total += arr[i];
    if (total <= 0) break;
    answer++;
  }

  return answer;
}

void main() {
  int t;
  read(t);

  while (t--) {
    string s = readln.strip();

    int once = 0;
    int more = 0;
    foreach (c; 'a' .. 'z' + 1) {
      auto T = s.count(c);
      if (T == 1) once++;
      if (T > 1) more++;
    }

    writeln(more + once / 2);
  }
}

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

void main()
{
	int t = readInt!int;
	while (t--)
	{
		solve();
	}
}

void solve()
{
	string s = readString;
	int[30] cnt = 0;
	foreach(c; s) cnt[c-'a']++;
	int c2 = 0;
	int c1 = 0;
	foreach(c; cnt)
	{
		if (c >= 2)
		{
			c2 += 1;
		}
		if (c == 1)
		{
			c1++;
		}
	}
	(((c1/2)*2+c2*2)/2).writeln;
}

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

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

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

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

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

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

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

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

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

void main()
{
  int t;
  readf!" %d "(t);
  while (t--) {
    auto a = readln.strip.split("").map!(x => x[0] - 'a').array;
    int[int] freq;
    foreach (x ; a)
      freq[x]++;
    long nocolor = 0;
    foreach (k, v ; freq)
      if (v > 2)
        nocolor += v - 2;
    writeln((cast(long)a.length - nocolor) / 2);
  }
}


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

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

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

    int[long] pos;
    pos[0] = 0;

    long ans = 0;
    long sm = 0;
    int lstpos = -1;
    foreach (i, e; arr) {
        sm += e;
        lstpos = max(lstpos, pos.get(sm, -1));
        ans += i+1 - (lstpos+1);
        pos[sm] = i.to!int + 1;
    }

    ans.writeln;
}

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

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

alias T = Tuple!(long, uint);

void main() {
  auto r = new InputReader ();
  const n = r.next!uint;
  auto a = r.nextA!int (n);
  const s = sum (a, 0L);
  //prefix[i] + suffix[j] + a[i .. j] == s
  //prefix[i] + suffix[j] == s
  auto pr = new long[n+1];
  pr[0] = 0;
  foreach (i; 1 .. n + 1) pr[i] = pr[i-1] + a[i-1];
  /*
  auto sf = new long[n+1];
  sf[n] = 0;
  foreach_reverse (i; 0 .. n) sf[i] = sf[i+1] + a[i];
  */
  T[] x;
  x.reserve (n + 1);
  foreach (i; 0 .. n + 1) x ~= tuple (pr[i], i);
  sort (x);
  debug stderr.writeln ("pr = ", pr);
  debug stderr.writeln ("x = ", x);
  int i;
  auto z = new uint[n+1];
  z[] = uint.max;
  while (i < x.length) {
    int j = i + 1;
    while (j < x.length && x[i][0] == x[j][0]) ++j;
    uint last = uint.max;
    foreach_reverse (const ref q; x[i .. j]) {
      debug stderr.writeln (q);
      if (last != uint.max) {
        z[q[1]] = last - 1;
      }
      last = q[1];
    }
    i = j;
  }
  debug stderr.writeln ("z = ", z);
  foreach_reverse (k; 0 .. n) {
    z[k] = min (z[k+1], z[k]);
  }
  debug stderr.writeln ("z = ", z);
  long res;
  foreach (k; 0 .. n) {
    z[k] = min (z[k], n);
    if (z[k] > k) {
      res += z[k] - k;
    }
  }
  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(); } 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;
    long[] as = scan!long(n);

    long[] sums = [0];
    foreach(a; as) sums ~= sums[$ - 1] + a;

    long ans;
    int[long] pos;
    int l = 0;
    foreach(i, s; sums){
        if(s in pos) l.raiseTo(pos[s] + 1);
        ans += i - l;
        pos[s] = i.to!int;
    }

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

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

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

long test(long[] arr)
{
	long res;
	foreach (i; 0..arr.length)
	{
		long x;
		foreach (j; i..arr.length)
		{
			x += arr[j];
			if (arr[j] == 0 || x == 0) break;
			++res;
		}
	}
	return res;
}

void main()
{
	auto n = RD!int;
	auto a = RDA;
	/*while (true){
	auto n = 3;
	auto a = new long[](3);
	foreach (i; 0..3)
	{
		a[i] = uniform(-3, 4);
	}*/

	int[][long] set;
	auto b = new long[](n+1);
	foreach_reverse (i; 0..n)
	{
		b[i] = b[i+1] + a[i];
	}
	foreach (i; 0..n+1)
	{
		set[b[i]] ~= i;
	}
	auto zero = new RedBlackTree!(int);
	foreach (i; 0..n)
	{
		if (a[i] == 0)
			zero.insert(i);
	}

	long ans;
	foreach (i; 0..n)
	{
		if (a[i] == 0) continue;
		auto arr = set.get(b[i+1], []);
		if (arr.empty)
		{
			ans += i+1;
		}
		else
		{
			auto r = binarySearch!((int p) => arr[p] < i)(-1, cast(int)arr.length);
			int r2 = -1;
			auto arr2 = zero.lowerBound(i);
			if (!arr2.empty)
				r2 = arr2.back;
			if (r == -1 && r2 == -1)
			{
				ans += i+1;
			}
			else
			{
				int x;
				if (r != -1)
					x = arr[r];
				if (r2 != -1)
					x.chmax(r2);
				zero.insert(x);
				ans += i - x;
				//debug writeln("i:", i, " r:", r, " arr[r]:", arr[r]);
			}
		}
		//debug writeln(ans);
	}

	/*auto ans2 = test(a);
	/writeln(a);
	writeln(ans, ":", ans2);*/
	writeln(ans);
	stdout.flush;
	/*if (ans != ans2) break;
	}*/
	debug readln;
}

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;
		long res = 0;
		int [long] used;
		used[0] = 0;
		int lo = 0;
		long cur;
		foreach (i; 0..n)
		{
			cur += a[i];
			if (cur in used)
			{
				lo = max (lo, used[cur] + 1);
			}
			used[cur] = i + 1;
			res += i + 1 - lo;
		}
		writeln (res);
	}
}

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

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

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

    int[int] pos;
    pos[0] = 0;

    long ans = 0;
    int sm = 0, lstpos = -1;
    foreach (i, e; arr) {
        sm += e;
        lstpos = max(lstpos, pos.get(sm, -1));
        ans += i+1 - (lstpos+1);
        pos[sm] = i.to!int + 1;
    }

    ans.writeln;
}

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

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

void main() {
  auto r = new InputReader ();
  const n = r.next!uint;
  auto a = r.nextA!int (n);
  const s = sum (a, 0L);
  //prefix[i] + suffix[j] + a[i .. j] == s
  //prefix[i] + suffix[j] == s
  auto pr = new long[n+1];
  pr[0] = 0;
  foreach (i; 1 .. n + 1) pr[i] = pr[i-1] + a[i-1];
  /*
  auto sf = new long[n+1];
  sf[n] = 0;
  foreach_reverse (i; 0 .. n) sf[i] = sf[i+1] + a[i];
  */
  int[long] h;
  Tuple!(int, int)[] bad;
  h[0] = 0;
  debug stderr.writeln ("pr = ", pr);
  foreach (j; 0 .. n) {
    //auto p = s - sf[j+1];
    auto p = pr[j+1];
    auto ptr = p in h;
    if (ptr !is null) {
      bad ~= tuple (*ptr, (j + 1).to!int);
    } else {
      h[p] = j + 1;
    }
  }
  int cur = int.max;
  foreach_reverse (ref q; bad) {
    cur = min (cur, q[1]);
    q[1] = cur;
  }
  debug stderr.writeln(bad);
  long res;
  auto e = assumeSorted (bad);
  foreach (i; 0 .. n) {
    auto d = e.upperBound (tuple (i, -1));
    if (d.empty) {
      res += n - i;
    } else {
      res += d.front[1] - 1 - i;
    }
  }
  writeln (res);
}

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

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

void main() {
  auto r = new InputReader ();
  const n = r.next!uint;
  auto a = r.nextA!int (n);
  const s = sum (a, 0L);
  //prefix[i] + suffix[j] + a[i .. j] == s
  //prefix[i] + suffix[j] == s
  auto pr = new long[n+1];
  pr[0] = 0;
  foreach (i; 1 .. n + 1) pr[i] = pr[i-1] + a[i-1];
  /*
  auto sf = new long[n+1];
  sf[n] = 0;
  foreach_reverse (i; 0 .. n) sf[i] = sf[i+1] + a[i];
  */
  int[long] h;
  Tuple!(int, int)[] bad;
  h[0] = 0;
  debug stderr.writeln ("pr = ", pr);
  foreach (j; 0 .. n) {
    //auto p = s - sf[j+1];
    auto p = pr[j+1];
    auto ptr = p in h;
    if (ptr !is null) {
      bad ~= tuple (*ptr, (j + 1).to!int);
    }
    h[p] = j + 1;
  }
  int cur = int.max;
  foreach_reverse (ref q; bad) {
    cur = min (cur, q[1]);
    q[1] = cur;
  }
  debug stderr.writeln(bad);
  long res;
  auto e = assumeSorted (bad);
  foreach (i; 0 .. n) {
    auto d = e.upperBound (tuple (i, -1));
    if (d.empty) {
      res += n - i;
    } else {
      res += d.front[1] - 1 - i;
    }
  }
  writeln (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) { 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;

	int[][long] set;
	auto b = new long[](n+1);
	foreach_reverse (i; 0..n)
	{
		b[i] = b[i+1] + a[i];
	}
	foreach (i; 0..n+1)
	{
		set[b[i]] ~= i;
	}

	long ans;
	foreach (i; 0..n)
	{
		if (a[i] == 0) continue;
		auto arr = set.get(b[i+1], []);
		if (arr.empty)
		{
			ans += i+1;
		}
		else
		{
			auto r = binarySearch!((int p) => arr[p] < i)(-1, cast(int)arr.length);
			if (r == -1)
			{
				ans += i+1;
			}
			else
			{
				ans += i - arr[r];
				debug writeln("i:", i, " r:", r, " arr[r]:", arr[r]);
			}
		}
	}

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

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;

	int[][long] set;
	auto b = new long[](n+1);
	foreach_reverse (i; 0..n)
	{
		b[i] = b[i+1] + a[i];
	}
	foreach (i; 0..n+1)
	{
		set[b[i]] ~= i;
	}

	long ans;
	long x;
	foreach (i; 0..n)
	{
		x += a[i];
		auto arr = set.get(b[i+1], []);
		if (arr.empty)
		{
			ans += i+1;
		}
		else
		{
			auto r = binarySearch!((int p) => arr[p] < i)(-1, cast(int)arr.length);
			if (r == -1)
			{
				ans += i+1;
			}
			else
			{
				ans += i - arr[r];
				debug writeln("i:", i, " r:", r, " arr[r]:", arr[r]);
			}
		}
	}

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

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;

	int[][long] set;
	auto b = new long[](n+1);
	foreach_reverse (i; 0..n)
	{
		b[i] = b[i+1] + a[i];
	}
	foreach (i; 0..n+1)
	{
		set[b[i]] ~= i;
	}
	int[] zero;
	foreach (i; 0..n)
	{
		if (a[i] == 0)
			zero ~= i;
	}

	long ans;
	foreach (i; 0..n)
	{
		if (a[i] == 0) continue;
		auto arr = set.get(b[i+1], []);
		if (arr.empty)
		{
			ans += i+1;
		}
		else
		{
			auto r = binarySearch!((int p) => arr[p] < i)(-1, cast(int)arr.length);
			auto r2 = binarySearch!((int p) => zero[p] < i)(-1, cast(int)zero.length);
			if (r == -1 && r2 == -1)
			{
				ans += i+1;
			}
			else
			{
				int x;
				if (r != -1)
					x = arr[r];
				if (r2 != -1)
					x.chmax(zero[r2]);
				ans += i - x;
				//debug writeln("i:", i, " r:", r, " arr[r]:", arr[r]);
			}
		}
	}

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