You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.

The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries. The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a. Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.

Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value  - 1 if there is no such number.

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

const int N = 1000000;

void main()
{
	int n;
	int nQueries;
	string s;

	scanf("%d %d\n", &n, &nQueries);
	Tuple!(int, int)[] numbers = new Tuple!(int, int)[n];
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		numbers[i] = tuple(x, i + 1);
	}
	sort!((a, b) => a[0] == b[0] ? a[1] < b[1] : a[0] < b[0], SwapStrategy.stable)(numbers);

	int[][] possible = new int[][N + 1];
	int[][] forbidden = new int[][N + 1];
	int p = 0;
	while (p < n) {
		int x = numbers[p][0];

		int q = p - 1;
		while (q + 1 < n && x == numbers[q + 1][0])
			q++;

		int nPossible = 0;
		for (int j = p; j <= q; j++) {
			if (j == p || (j > p && numbers[j][1] > numbers[j - 1][1] + 1)) {
				nPossible++;
			}
			if (j == q || (j < q && numbers[j][1] < numbers[j + 1][1] - 2)) {
				nPossible++;
			}
		}

		forbidden[x] = new int[q - p + 1];
		possible[x] = new int[nPossible];
		nPossible = 0;
		for (int j = p; j <= q; j++) {
			forbidden[x][j - p] = numbers[j][1];

			if (j == p || (j > p && numbers[j][1] > numbers[j - 1][1] + 1)) {
				possible[x][nPossible++] = numbers[j][1] - 1;
			}
			if (j == q || (j < q && numbers[j][1] < numbers[j + 1][1] - 2)) {
				possible[x][nPossible++] = numbers[j][1] + 1;
			}
		}

		p = q + 1;
	}

	for (int i = 0; i < nQueries; i++) {
		int l, r, x;
		scanf("%d%d%d", &l, &r, &x);

		if (forbidden[x] == null) {
			writefln("%d", l);
		}
		else {
			auto rangeForbidden = assumeSorted(forbidden[x]).lowerBound(r + 1).upperBound(l - 1);
			auto rangePossible = assumeSorted(possible[x]).lowerBound(r + 1).upperBound(l - 1);
			if (rangeForbidden.length == r - l + 1) {
				writefln("-1");
			}
			else if (rangeForbidden.empty) {
				writefln("%d", l);
			}
			else {
				writefln("%d", rangePossible[0]);
			}
		}
	}
}

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

const int N = 1000000;

void main()
{
	int n;
	int nQueries;
	string s;
	Array!(int)[] numbers = new Array!(int)[N + 1];

	scanf("%d %d\n", &n, &nQueries);
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		numbers[x].insert(i + 1);
	}
	int[][] sorted = new int[][N + 1];
	for (int i = 1; i <= N; i++) {
		if (!numbers[i].empty) {
			Array!(int) res;

			for (int j = 0; j < numbers[i].length; j++) {
				if ((j == 0 && numbers[i][j] > 1) || (j > 0 && numbers[i][j] > numbers[i][j - 1] + 1)) {
					res.insert(numbers[i][j] - 1);
				}
				if ((j == numbers[i].length - 1 && numbers[i][j] < n) || (j != numbers[i].length - 1 && numbers[i][j] < numbers[i][j + 1] - 1)) {
					res.insert(numbers[i][j] + 1);
				}
			}
			sorted[i] = array(res);
		}
	}

	for (int i = 0; i < nQueries; i++) {
		int l, r, x;
		scanf("%d%d%d", &l, &r, &x);

		if (sorted[x] == null) {
			writefln("%d", l);
		}
		else {
			auto range = assumeSorted(sorted[x]).lowerBound(r + 1).upperBound(l - 1);
			if (range.empty) {
				writefln("-1");
			}
			else {
				writefln("%d", range[0]);
			}
		}
	}
}


You are given three integers $$$n$$$, $$$l$$$, and $$$r$$$. You need to construct an array $$$a_1,a_2,\dots,a_n$$$ ($$$l\le a_i\le r$$$) such that $$$\gcd(i,a_i)$$$ are all distinct or report there's no solution.Here $$$\gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows. The first line contains three integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le n \le 10^5$$$, $$$1\le l\le r\le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower). Otherwise, print "YES" (without quotes). In the next line, print $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ — the array you construct. If there are multiple solutions, you may output any.

// cheese-cracker [2022-07-16]

void solve(){
    int n = scan!int;
    long l = scan;
    long r = scan;
    long[] res;
    for(int i = 1; i <= n; ++i){
        long rem = (l % i);
        if(rem) rem = i - rem;
        long num = l + rem;
        if(num > r){
            writeln("NO");
            return;
        }
        res ~= num;
    }
    writeln("YES");
    res.each!(a => write(a, " "));
    writeln;
}

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

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


Misha has a tree with characters written on the vertices. He can choose two vertices s and t of this tree and write down characters of vertices lying on a path from s to t. We'll say that such string corresponds to pair (s, t).Misha has m queries of type: you are given 4 vertices a, b, c, d; you need to find the largest common prefix of the strings that correspond to pairs (a, b) and (c, d). Your task is to help him.

The first line contains integer n (1 ≤ n ≤ 300 000) — the number of vertices in the tree. Next follows a line consisting of n small English letters. The i-th character of the string corresponds to the character written on the i-th vertex.  Next n - 1 lines contain information about edges. An edge is defined by a pair of integers u, v (1 ≤ u, v ≤ n, u ≠ v), separated by spaces. The next line contains integer m (1 ≤ m ≤ 1 000 000) — the number of queries. Next m lines contain information about queries. A query is defined by four integers a, b, c, d (1 ≤ a, b, c, d ≤ n), separated by spaces.

For each query print the length of the largest common prefix on a separate line.

import core.bitop;
import core.checkedint;
import core.simd;
import core.stdc.stdio;
import core.stdc.stdlib;
import core.stdc.string;
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.bitmanip;
import std.complex;
import std.container;
import std.conv;
import std.datetime;
import std.format;
import std.functional;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.regex;
import std.string;
import std.typecons;
import std.variant;

__gshared:

bool read(T...)(T ptrs) if (ptrs.length > 0) {
    return readf(' ' ~ replicate("%s ", ptrs.length), ptrs) == ptrs.length;
}

T[ ] allocate(T)(size_t n) {
    return (cast(T*)calloc(n, T.sizeof))[0 .. n];
}

auto pairwise(R)(R range) if (isForwardRange!R) {
    return lockstep(range, dropOne(range));
}

struct Lca(Node, int n, Flag!`checkBackReferences` checkBackReferences = No.checkBackReferences,
        Flag!`assignLineIndices` assignLineIndices = No.assignLineIndices) {
    Node*[n + 1] lp;
    int[n + 1] height;

    void init(Node* root) {
        int gid = 1;

        static if (checkBackReferences)
            alias PrevType = AliasSeq!(Node*);
        else
            alias PrevType = AliasSeq!();

        int dfs0(Node* self, in PrevType prev) {
            with (self) {
                id = deepestId = gid++;
                int h = bsf(id);
                foreach (node; adj) {
                    static if (checkBackReferences) {
                        if (node is prev[0])
                            continue;
                        const t = dfs0(node, self);
                    } else
                        const t = dfs0(node);
                    if (t > h) {
                        h = t;
                        deepestId = node.deepestId;
                    }
                    lp[node.deepestId] = self;
                }
                height[id] = h;
                return h;
            }
        }

        void dfs1(Node* self, in PrevType prev, int index) {
            with (self) {
                static if (assignLineIndices)
                    indexInLine = index;
                mask |= deepestId & -deepestId;
                foreach (node; adj)
                    static if (checkBackReferences) {
                        if (node !is prev[0]) {
                            node.mask = mask;
                            dfs1(node, self, deepestId == node.deepestId? index + 1 : 0);
                        }
                    } else {
                        node.mask = mask;
                        dfs1(node, deepestId == node.deepestId? index + 1 : 0);
                    }
            }
        }

        root.mask = 0x0;
        static if (checkBackReferences) {
            dfs0(root, null);
            dfs1(root, null, 0);
        } else {
            dfs0(root);
            dfs1(root, 0);
        }
    }

    Node* get(Node* x, Node* y) {
        const dpx = x.deepestId, dpy = y.deepestId;
        if (dpx != dpy) {
            const k = bsr(dpx ^ dpy);
            const zh = bsf(x.mask & y.mask & ~0 << height[(dpx >> k | 0x1) << k]);

            Node* raise(int deepestId, int mask) {
                const k = bsr(mask & ((1 << zh) - 1));
                return lp[(deepestId >> k | 0x1) << k];
            }

            if (bsf(x.mask) != zh)
                x = raise(dpx, x.mask);
            if (bsf(y.mask) != zh)
                y = raise(dpy, y.mask);
        }
        return x.id < y.id? x : y;
    }
}

struct AutoNode {
    int len;
    //AutoNode*[char] next;
    AutoNode*[26] next;
    AutoNode* link;
    AutoNode*[ ] invLinks;
    int id, deepestId, mask;

    alias adj = invLinks;

    /+
    this(this) {
        next = next.dup;
    }
    +/

    AutoNode* append(int c, AutoNode* last) {
        /+
        while (auNodesSize >= 1_200_000) { }
        auNodes[auNodesSize] = AutoNode(last.len + 1);
        auto cur = &auNodes[auNodesSize++];
        +/
        auto cur = new AutoNode(last.len + 1);
        /+
        AutoNode** p;
        while ((p = c in last.next) is null) {
            last.next[c] = cur;
            last = last.link;
            if (last is null) {
                cur.link = &this;
                return cur;
            }
        }
        while (p is null) { }
        +/
        for (; last !is null && last.next[c] is null; last = last.link)
            last.next[c] = cur;
        if (last is null) {
            cur.link = &this;
            return cur;
        }
        while (last is null) { }
        auto q = /+*p+/ last.next[c];
        while (q is null) { }
        if (q.len == last.len + 1) {
            cur.link = q;
            return cur;
        }
        /+
        while (auNodesSize >= 1_200_000) { }
        auNodes[auNodesSize] = *q;
        auto clone = &auNodes[auNodesSize++];
        +/
        auto clone = new AutoNode;
        *clone = *q;
        clone.len = last.len + 1;
        //clone.next = clone.next.dup;
        cur.link = q.link = clone;
        for (; last !is null && last.next[c] == q; last = last.link)
            last.next[c] = clone;
        /+
        do {
            while (p is null) { }
            *p = clone;
            last = last.link;
            if (last is null)
                break;
            p = c in last.next;
        } while (p !is null && *p == q);
        +/
        return cur;
    }
}

struct TreeNode {
    char c;
    TreeNode*[ ] adj;
    int id, deepestId, mask, indexInLine, indexInString;

    void genString(in TreeNode* prev) {
        indexInString = strSize;
        str[strSize++] = c;
        foreach (node; adj)
            if (node !is prev && node.deepestId == deepestId) {
                node.genString(&this);
                break;
            }
        foreach (node; adj)
            if (node !is prev && node.deepestId != deepestId)
                node.genString(&this);
    }
}

struct Waypoint {
    int pos, lpos, trgLpos;
    bool up;
}

int n;
TreeNode[300_000] _nodes;
int strSize;
char[300_000] str;
int auNodesSize;
AutoNode[ ] auNodes;
AutoNode*[300_000] _tdNodes, _buNodes;
AutoNode*[ ] tdNodes, buNodes;
Lca!(TreeNode, 300_000, Yes.checkBackReferences, Yes.assignLineIndices) treeLca;
Lca!(AutoNode, 1_200_000) auLca;
Waypoint[38][2] wp;

int solve(TreeNode* a, TreeNode* b, TreeNode* c, TreeNode* d) {
    auto calcWaypoints(TreeNode* a, TreeNode* b, Waypoint[ ] wp) {
        const lca = treeLca.get(a, b);
        int i = 0;

        void walkUp(const(TreeNode)* node, bool up) {
            while (node.deepestId != lca.deepestId) {
                wp[i++] = Waypoint(node.indexInString, node.indexInLine, 0, up);
                node = treeLca.lp[node.deepestId];
            }
            if (up)
                wp[i++] = Waypoint(node.indexInString, node.indexInLine, lca.indexInLine, up);
            else if (node !is lca)
                wp[i++] = Waypoint(node.indexInString, node.indexInLine, lca.indexInLine + 1, up);
        }

        walkUp(a, true);
        const mid = i;
        walkUp(b, false);
        wp[mid .. i].reverse();
        return wp[0 .. i];
    }

    auto wp0 = calcWaypoints(a, b, wp[0][ ]);
    auto wp1 = calcWaypoints(c, d, wp[1][ ]);
    int result = 0;
    while (!wp0.empty && !wp1.empty) {
        const aw = wp0.front;
        const cw = wp1.front;
        auto node0 = aw.up? buNodes[aw.pos] : tdNodes[aw.pos - aw.lpos + aw.trgLpos];
        auto node1 = cw.up? buNodes[cw.pos] : tdNodes[cw.pos - cw.lpos + cw.trgLpos];
        const aLim = aw.lpos - aw.trgLpos + 1;
        const cLim = cw.lpos - cw.trgLpos + 1;
        const lce = min(auLca.get(node0, node1).len, aLim, cLim);
        result += lce;
        if (lce < aLim && lce < cLim)
            return result;

        void update(ref Waypoint[ ] wp, int lim) {
            if (lce == lim)
                wp.popFront();
            else if (wp.front.up) {
                wp.front.pos -= lce;
                wp.front.lpos -= lce;
            } else
                wp.front.trgLpos += lce;
        }

        update(wp0, aLim);
        update(wp1, cLim);
    }

    return result;
}

void main() {
    //auNodes = allocate!AutoNode(1_200_000);
    while (scanf("%d ", &n) == 1) {
        auto nodes = _nodes[0 .. n];
        foreach (ref node; nodes) {
            version (LocalProject)
                node = TreeNode.init;
            node.c = cast(char)getchar();
        }
        foreach (i; 1 .. n) {
            int a, b;
            scanf("%d%d", &a, &b);
            a--;
            b--;
            nodes[a].adj ~= &nodes[b];
            nodes[b].adj ~= &nodes[a];
        }

        treeLca.init(&nodes[0]);
        strSize = 0;
        nodes[0].genString(null);
        while (strSize != n) { }

        AutoNode root;
        while (root.len) { }
        while (root.link !is null) { }
        tdNodes = _tdNodes[0 .. n];
        buNodes = _buNodes[0 .. n];
        auNodesSize = 0;
        //Build automata on reversed strings.
        auto last = &root;
        foreach_reverse (i, c; str[0 .. n]) {
            while (i < 0 || i >= tdNodes.length) { }
            last = tdNodes[i] = root.append(c - 'a', last);
        }
        foreach (i, c; str[0 .. n]) {
            while (i < 0 || i >= buNodes.length) { }
            last = buNodes[i] = root.append(c - 'a', last);
        }
        /+
        foreach (ref node; auNodes[0 .. auNodesSize]) {
            while (node.link is null) { }
            node.link.invLinks ~= &node;
        }
        +/

        void traverse(AutoNode* node) {
            if (node.link !is null) {
                node.link.invLinks ~= node;
                node.link = null;
                foreach (next; node.next)
                    if (next !is null)
                        traverse(next);
            }
        }

        foreach (node; root.next)
            if (node !is null)
                traverse(node);
        auLca.init(&root);

        int q;
        scanf("%d", &q);
        while (q--) {
            int a, b, c, d;
            scanf("%d%d%d%d", &a, &b, &c, &d);
            printf("%d\n", solve(&nodes[a - 1], &nodes[b - 1], &nodes[c - 1], &nodes[d - 1]));
        }
    }
}

import core.bitop;
import core.checkedint;
import core.simd;
import core.stdc.stdio;
import core.stdc.stdlib;
import core.stdc.string;
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.bitmanip;
import std.complex;
import std.container;
import std.conv;
import std.datetime;
import std.format;
import std.functional;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.regex;
import std.string;
import std.typecons;
import std.variant;

__gshared:

bool read(T...)(T ptrs) if (ptrs.length > 0) {
    return readf(' ' ~ replicate("%s ", ptrs.length), ptrs) == ptrs.length;
}

T[ ] allocate(T)(size_t n) {
    return (cast(T*)calloc(n, T.sizeof))[0 .. n];
}

auto pairwise(R)(R range) if (isForwardRange!R) {
    return lockstep(range, dropOne(range));
}

struct Lca(Node, int n, Flag!`checkBackReferences` checkBackReferences = No.checkBackReferences,
        Flag!`assignLineIndices` assignLineIndices = No.assignLineIndices) {
    Node*[n + 1] lp;
    int[n + 1] height;

    void init(Node* root) {
        int gid = 1;

        static if (checkBackReferences)
            alias PrevType = AliasSeq!(Node*);
        else
            alias PrevType = AliasSeq!();

        int dfs0(Node* self, in PrevType prev) {
            with (self) {
                id = deepestId = gid++;
                int h = bsf(id);
                foreach (node; adj) {
                    static if (checkBackReferences) {
                        if (node is prev[0])
                            continue;
                        const t = dfs0(node, self);
                    } else
                        const t = dfs0(node);
                    if (t > h) {
                        h = t;
                        deepestId = node.deepestId;
                    }
                    lp[node.deepestId] = self;
                }
                height[id] = h;
                return h;
            }
        }

        void dfs1(Node* self, in PrevType prev, int index) {
            with (self) {
                static if (assignLineIndices)
                    indexInLine = index;
                mask |= deepestId & -deepestId;
                foreach (node; adj)
                    static if (checkBackReferences) {
                        if (node !is prev[0]) {
                            node.mask = mask;
                            dfs1(node, self, deepestId == node.deepestId? index + 1 : 0);
                        }
                    } else {
                        node.mask = mask;
                        dfs1(node, deepestId == node.deepestId? index + 1 : 0);
                    }
            }
        }

        root.mask = 0x0;
        static if (checkBackReferences) {
            dfs0(root, null);
            dfs1(root, null, 0);
        } else {
            dfs0(root);
            dfs1(root, 0);
        }
    }

    Node* get(Node* x, Node* y) {
        const dpx = x.deepestId, dpy = y.deepestId;
        if (dpx != dpy) {
            const k = bsr(dpx ^ dpy);
            const zh = bsf(x.mask & y.mask & ~0 << height[(dpx >> k | 0x1) << k]);

            Node* raise(int deepestId, int mask) {
                const k = bsr(mask & ((1 << zh) - 1));
                return lp[(deepestId >> k | 0x1) << k];
            }

            if (bsf(x.mask) != zh)
                x = raise(dpx, x.mask);
            if (bsf(y.mask) != zh)
                y = raise(dpy, y.mask);
        }
        return x.id < y.id? x : y;
    }
}

struct AutoNode {
    int len;
    //AutoNode*[char] next;
    AutoNode*[26] next;
    AutoNode* link;
    AutoNode*[ ] invLinks;
    int id, deepestId, mask;

    alias adj = invLinks;

    /+
    this(this) {
        next = next.dup;
    }
    +/

    AutoNode* append(int c, AutoNode* last) {
        while (auNodesSize >= 1_200_000) { }
        auNodes[auNodesSize] = AutoNode(last.len + 1);
        auto cur = &auNodes[auNodesSize++];
        /+
        AutoNode** p;
        while ((p = c in last.next) is null) {
            last.next[c] = cur;
            last = last.link;
            if (last is null) {
                cur.link = &this;
                return cur;
            }
        }
        while (p is null) { }
        +/
        for (; last !is null && last.next[c] is null; last = last.link)
            last.next[c] = cur;
        if (last is null) {
            cur.link = &this;
            return cur;
        }
        while (last is null) { }
        auto q = /+*p+/ last.next[c];
        while (q is null) { }
        if (q.len == last.len + 1) {
            cur.link = q;
            return cur;
        }
        while (auNodesSize >= 1_200_000) { }
        auNodes[auNodesSize] = *q;
        auto clone = &auNodes[auNodesSize++];
        clone.len = last.len + 1;
        //clone.next = clone.next.dup;
        cur.link = q.link = clone;
        for (; last !is null && last.next[c] == q; last = last.link)
            last.next[c] = clone;
        /+
        do {
            while (p is null) { }
            *p = clone;
            last = last.link;
            if (last is null)
                break;
            p = c in last.next;
        } while (p !is null && *p == q);
        +/
        return cur;
    }
}

struct TreeNode {
    char c;
    TreeNode*[ ] adj;
    int id, deepestId, mask, indexInLine, indexInString;

    void genString(in TreeNode* prev) {
        indexInString = strSize;
        str[strSize++] = c;
        foreach (node; adj)
            if (node !is prev && node.deepestId == deepestId) {
                node.genString(&this);
                break;
            }
        foreach (node; adj)
            if (node !is prev && node.deepestId != deepestId)
                node.genString(&this);
    }
}

struct Waypoint {
    int pos, lpos, trgLpos;
    bool up;
}

int n;
TreeNode[300_000] _nodes;
int strSize;
char[300_000] str;
int auNodesSize;
AutoNode[ ] auNodes;
AutoNode*[300_000] _tdNodes, _buNodes;
AutoNode*[ ] tdNodes, buNodes;
Lca!(TreeNode, 300_000, Yes.checkBackReferences, Yes.assignLineIndices) treeLca;
Lca!(AutoNode, 1_200_000) auLca;
Waypoint[38][2] wp;

int solve(TreeNode* a, TreeNode* b, TreeNode* c, TreeNode* d) {
    auto calcWaypoints(TreeNode* a, TreeNode* b, Waypoint[ ] wp) {
        const lca = treeLca.get(a, b);
        int i = 0;

        void walkUp(const(TreeNode)* node, bool up) {
            while (node.deepestId != lca.deepestId) {
                wp[i++] = Waypoint(node.indexInString, node.indexInLine, 0, up);
                node = treeLca.lp[node.deepestId];
            }
            if (up)
                wp[i++] = Waypoint(node.indexInString, node.indexInLine, lca.indexInLine, up);
            else if (node !is lca)
                wp[i++] = Waypoint(node.indexInString, node.indexInLine, lca.indexInLine + 1, up);
        }

        walkUp(a, true);
        const mid = i;
        walkUp(b, false);
        wp[mid .. i].reverse();
        return wp[0 .. i];
    }

    auto wp0 = calcWaypoints(a, b, wp[0][ ]);
    auto wp1 = calcWaypoints(c, d, wp[1][ ]);
    int result = 0;
    while (!wp0.empty && !wp1.empty) {
        const aw = wp0.front;
        const cw = wp1.front;
        auto node0 = aw.up? buNodes[aw.pos] : tdNodes[aw.pos - aw.lpos + aw.trgLpos];
        auto node1 = cw.up? buNodes[cw.pos] : tdNodes[cw.pos - cw.lpos + cw.trgLpos];
        const aLim = aw.lpos - aw.trgLpos + 1;
        const cLim = cw.lpos - cw.trgLpos + 1;
        const lce = min(auLca.get(node0, node1).len, aLim, cLim);
        result += lce;
        if (lce < aLim && lce < cLim)
            return result;

        void update(ref Waypoint[ ] wp, int lim) {
            if (lce == lim)
                wp.popFront();
            else if (wp.front.up) {
                wp.front.pos -= lce;
                wp.front.lpos -= lce;
            } else
                wp.front.trgLpos += lce;
        }

        update(wp0, aLim);
        update(wp1, cLim);
    }

    return result;
}

void main() {
    auNodes = new AutoNode[1_200_000];
    while (auNodes.ptr is null) { }
    while (scanf("%d ", &n) == 1) {
        auto nodes = _nodes[0 .. n];
        foreach (ref node; nodes) {
            version (LocalProject)
                node = TreeNode.init;
            node.c = cast(char)getchar();
        }
        foreach (i; 1 .. n) {
            int a, b;
            scanf("%d%d", &a, &b);
            a--;
            b--;
            nodes[a].adj ~= &nodes[b];
            nodes[b].adj ~= &nodes[a];
        }

        treeLca.init(&nodes[0]);
        strSize = 0;
        nodes[0].genString(null);
        while (strSize != n) { }

        AutoNode root;
        while (root.len) { }
        while (root.link !is null) { }
        tdNodes = _tdNodes[0 .. n];
        buNodes = _buNodes[0 .. n];
        auNodesSize = 0;
        //Build automata on reversed strings.
        auto last = &root;
        foreach_reverse (i, c; str[0 .. n]) {
            while (i < 0 || i >= tdNodes.length) { }
            last = tdNodes[i] = root.append(c - 'a', last);
        }
        foreach (i, c; str[0 .. n]) {
            while (i < 0 || i >= buNodes.length) { }
            last = buNodes[i] = root.append(c - 'a', last);
        }
        /+
        foreach (ref node; auNodes[0 .. auNodesSize]) {
            while (node.link is null) { }
            node.link.invLinks ~= &node;
        }
        +/

        void traverse(AutoNode* node) {
            if (node.link !is null) {
                node.link.invLinks ~= node;
                node.link = null;
                foreach (next; node.next)
                    if (next !is null)
                        traverse(next);
            }
        }

        foreach (node; root.next)
            if (node !is null)
                traverse(node);
        auLca.init(&root);

        int q;
        scanf("%d", &q);
        while (q--) {
            int a, b, c, d;
            scanf("%d%d%d%d", &a, &b, &c, &d);
            printf("%d\n", solve(&nodes[a - 1], &nodes[b - 1], &nodes[c - 1], &nodes[d - 1]));
        }
    }
}

import core.bitop;
import core.checkedint;
import core.simd;
import core.stdc.stdio;
import core.stdc.stdlib;
import core.stdc.string;
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.bitmanip;
import std.complex;
import std.container;
import std.conv;
import std.datetime;
import std.format;
import std.functional;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.regex;
import std.string;
import std.typecons;
import std.variant;

__gshared:

bool read(T...)(T ptrs) if (ptrs.length > 0) {
    return readf(' ' ~ replicate("%s ", ptrs.length), ptrs) == ptrs.length;
}

T[ ] allocate(T)(size_t n) {
    return (cast(T*)malloc(n * T.sizeof))[0 .. n];
}

auto pairwise(R)(R range) if (isForwardRange!R) {
    return lockstep(range, dropOne(range));
}

struct Lca(Node, int n, Flag!`checkBackReferences` checkBackReferences = No.checkBackReferences,
        Flag!`assignLineIndices` assignLineIndices = No.assignLineIndices) {
    Node*[n + 1] lp;
    int[n + 1] height;

    void init(Node* root) {
        int gid = 1;

        static if (checkBackReferences)
            alias PrevType = AliasSeq!(Node*);
        else
            alias PrevType = AliasSeq!();

        int dfs0(Node* self, in PrevType prev) {
            with (self) {
                id = deepestId = gid++;
                int h = bsf(id);
                foreach (node; adj) {
                    static if (checkBackReferences) {
                        if (node is prev[0])
                            continue;
                        const t = dfs0(node, self);
                    } else
                        const t = dfs0(node);
                    if (t > h) {
                        h = t;
                        deepestId = node.deepestId;
                    }
                    lp[node.deepestId] = self;
                }
                height[id] = h;
                return h;
            }
        }

        void dfs1(Node* self, in PrevType prev, int index) {
            with (self) {
                static if (assignLineIndices)
                    indexInLine = index;
                mask |= deepestId & -deepestId;
                foreach (node; adj)
                    static if (checkBackReferences) {
                        if (node !is prev[0]) {
                            node.mask = mask;
                            dfs1(node, self, deepestId == node.deepestId? index + 1 : 0);
                        }
                    } else {
                        node.mask = mask;
                        dfs1(node, deepestId == node.deepestId? index + 1 : 0);
                    }
            }
        }

        root.mask = 0x0;
        static if (checkBackReferences) {
            dfs0(root, null);
            dfs1(root, null, 0);
        } else {
            dfs0(root);
            dfs1(root, 0);
        }
    }

    Node* get(Node* x, Node* y) {
        const dpx = x.deepestId, dpy = y.deepestId;
        if (dpx != dpy) {
            const k = bsr(dpx ^ dpy);
            const zh = bsf(x.mask & y.mask & ~0 << height[(dpx >> k | 0x1) << k]);

            Node* raise(int deepestId, int mask) {
                const k = bsr(mask & ((1 << zh) - 1));
                return lp[(deepestId >> k | 0x1) << k];
            }

            if (bsf(x.mask) != zh)
                x = raise(dpx, x.mask);
            if (bsf(y.mask) != zh)
                y = raise(dpy, y.mask);
        }
        return x.id < y.id? x : y;
    }
}

struct AutoNode {
    int len;
    AutoNode*[char] next;
    AutoNode* link;
    AutoNode*[ ] invLinks;
    int id, deepestId, mask;

    alias adj = invLinks;

    this(this) {
        next = next.dup;
    }

    AutoNode* append(char c, AutoNode* last) {
        auto cur = createNode(last.len + 1);
        AutoNode** p;
        while ((p = c in last.next) is null) {
            last.next[c] = cur;
            last = last.link;
            if (last is null) {
                cur.link = &this;
                return cur;
            }
        }
        auto q = *p;
        if (q.len == last.len + 1) {
            cur.link = q;
            return cur;
        }
        auto clone = createNode(*q);
        clone.len = last.len + 1;
        cur.link = q.link = clone;
        do {
            *p = clone;
            last = last.link;
            if (last is null)
                break;
            p = c in last.next;
        } while (p !is null && *p == q);
        return cur;
    }
}

struct TreeNode {
    char c;
    TreeNode*[ ] adj;
    int id, deepestId, mask, indexInLine, indexInString;

    void genString(in TreeNode* prev) {
        indexInString = strSize;
        str[strSize++] = c;
        foreach (node; adj)
            if (node !is prev && node.deepestId == deepestId) {
                node.genString(&this);
                break;
            }
        foreach (node; adj)
            if (node !is prev && node.deepestId != deepestId)
                node.genString(&this);
    }
}

struct Waypoint {
    int pos, lpos, trgLpos;
    bool up;
}

int n;
TreeNode[300_000] _nodes;
int strSize;
char[300_000] str;
int auNodesSize;
AutoNode[ ] auNodes;
AutoNode*[300_000] _tdNodes, _buNodes;
AutoNode*[ ] tdNodes, buNodes;
Lca!(TreeNode, 300_000, Yes.checkBackReferences, Yes.assignLineIndices) treeLca;
Lca!(AutoNode, 1_200_000) auLca;
Waypoint[38][2] wp;

int solve(TreeNode* a, TreeNode* b, TreeNode* c, TreeNode* d) {
    auto calcWaypoints(TreeNode* a, TreeNode* b, Waypoint[ ] wp) {
        const lca = treeLca.get(a, b);
        int i = 0;

        void walkUp(const(TreeNode)* node, bool up) {
            while (node.deepestId != lca.deepestId) {
                wp[i++] = Waypoint(node.indexInString, node.indexInLine, 0, up);
                node = treeLca.lp[node.deepestId];
            }
            if (up)
                wp[i++] = Waypoint(node.indexInString, node.indexInLine, lca.indexInLine, up);
            else if (node !is lca)
                wp[i++] = Waypoint(node.indexInString, node.indexInLine, lca.indexInLine + 1, up);
        }

        walkUp(a, true);
        const mid = i;
        walkUp(b, false);
        wp[mid .. i].reverse();
        return wp[0 .. i];
    }

    auto wp0 = calcWaypoints(a, b, wp[0][ ]);
    auto wp1 = calcWaypoints(c, d, wp[1][ ]);
    int result = 0;
    while (!wp0.empty && !wp1.empty) {
        const aw = wp0.front;
        const cw = wp1.front;
        auto node0 = aw.up? buNodes[aw.pos] : tdNodes[aw.pos - aw.lpos + aw.trgLpos];
        auto node1 = cw.up? buNodes[cw.pos] : tdNodes[cw.pos - cw.lpos + cw.trgLpos];
        const aLim = aw.lpos - aw.trgLpos + 1;
        const cLim = cw.lpos - cw.trgLpos + 1;
        const lce = min(auLca.get(node0, node1).len, aLim, cLim);
        result += lce;
        if (lce < aLim && lce < cLim)
            return result;

        void update(ref Waypoint[ ] wp, int lim) {
            if (lce == lim)
                wp.popFront();
            else if (wp.front.up) {
                wp.front.pos -= lce;
                wp.front.lpos -= lce;
            } else
                wp.front.trgLpos += lce;
        }

        update(wp0, aLim);
        update(wp1, cLim);
    }

    return result;
}

auto createNode(int len) {
    auNodes[auNodesSize] = AutoNode(len);
    return &auNodes[auNodesSize++];
}

auto createNode(ref AutoNode node) {
    auNodes[auNodesSize] = node;
    return &auNodes[auNodesSize++];
}

void main() {
    auNodes = uninitializedArray!(AutoNode[ ])(1_200_000);
    while (scanf("%d ", &n) == 1) {
        auto nodes = _nodes[0 .. n];
        foreach (ref node; nodes) {
            version (LocalProject)
                node = TreeNode.init;
            node.c = cast(char)getchar();
        }
        foreach (i; 1 .. n) {
            int a, b;
            scanf("%d%d", &a, &b);
            a--;
            b--;
            nodes[a].adj ~= &nodes[b];
            nodes[b].adj ~= &nodes[a];
        }

        treeLca.init(&nodes[0]);
        strSize = 0;
        nodes[0].genString(null);
        assert(strSize == n);

        AutoNode root;
        tdNodes = _tdNodes[0 .. n];
        buNodes = _buNodes[0 .. n];
        auNodesSize = 0;
        //Build automata on reversed strings.
        auto last = &root;
        foreach_reverse (i, c; str[0 .. n])
            last = tdNodes[i] = root.append(c, last);
        foreach (i, c; str[0 .. n])
            last = buNodes[i] = root.append(c, last);
        foreach (ref node; auNodes[0 .. auNodesSize])
            node.link.invLinks ~= &node;
        auLca.init(&root);

        int q;
        scanf("%d", &q);
        while (q--) {
            int a, b, c, d;
            scanf("%d%d%d%d", &a, &b, &c, &d);
            printf("%d\n", solve(&nodes[a - 1], &nodes[b - 1], &nodes[c - 1], &nodes[d - 1]));
        }
    }
}


Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other.

The first line of the input contains n (1 ≤ n ≤ 200 000) — the number of bishops. Each of next n lines contains two space separated integers xi and yi (1 ≤ xi, yi ≤ 1000) — the number of row and the number of column where i-th bishop is positioned. It's guaranteed that no two bishops share the same position.

Output one integer — the number of pairs of bishops which attack each other.

NoteIn the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.


Once again, Boris needs the help of Anton in creating a task. This time Anton needs to solve the following problem:There are two arrays of integers $$$a$$$ and $$$b$$$ of length $$$n$$$. It turned out that array $$$a$$$ contains only elements from the set $$$\{-1, 0, 1\}$$$.Anton can perform the following sequence of operations any number of times:   Choose any pair of indexes $$$(i, j)$$$ such that $$$1 \le i < j \le n$$$. It is possible to choose the same pair $$$(i, j)$$$ more than once.   Add $$$a_i$$$ to $$$a_j$$$. In other words, $$$j$$$-th element of the array becomes equal to $$$a_i + a_j$$$. For example, if you are given array $$$[1, -1, 0]$$$, you can transform it only to $$$[1, -1, -1]$$$, $$$[1, 0, 0]$$$ and $$$[1, -1, 1]$$$ by one operation.Anton wants to predict if it is possible to apply some number (zero or more) of these operations to the array $$$a$$$ so that it becomes equal to array $$$b$$$. Can you help him?

Each test contains multiple test cases.  The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10000$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$)  — the length of arrays. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-1 \le a_i \le 1$$$)  — elements of array $$$a$$$. There can be duplicates among elements. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$)  — elements of array $$$b$$$. There can be duplicates among elements. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.

For each test case, output one line containing "YES" if it's possible to make arrays $$$a$$$ and $$$b$$$ equal by performing the described operations, or "NO" if it's impossible. You can print each letter in any case (upper or lower).

NoteIn the first test-case we can choose $$$(i, j)=(2, 3)$$$ twice and after that choose $$$(i, j)=(1, 2)$$$ twice too. These operations will transform $$$[1, -1, 0] \to [1, -1, -2] \to [1, 1, -2]$$$In the second test case we can't make equal numbers on the second position.In the third test case we can choose $$$(i, j)=(1, 2)$$$ $$$41$$$ times. The same about the fourth test case.In the last lest case, it is impossible to make array $$$a$$$ equal to the array $$$b$$$.

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		auto b = readln.splitter.map !(to !(int)).array;
		bool havePos = false;
		bool haveNeg = false;
		bool canDo = true;
		foreach (i; 0..n)
		{
			if (a[i] < b[i])
			{
				canDo &= havePos;
			}
			if (a[i] > b[i])
			{
				canDo &= haveNeg;
			}
			havePos |= (a[i] > 0);
			haveNeg |= (a[i] < 0);
		}
		writeln (canDo ? "YES" : "NO");
	}
}

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

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

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  foreach (tid; 0 .. nt) {
    const n = r.next!uint;
    auto a = r.nextA!int (n);
    auto b = r.nextA!int (n);
    auto mask = uninitializedArray!(uint[])(n);
    int flags = 0;
    foreach (i; 0 .. n) {
      if (a[i] < 0) flags |= 1;
      if (a[i] > 0) flags |= 2;
      mask[i] = flags;
    }
    bool test () {
      foreach_reverse (j; 0 .. n) {
        if (b[j] == a[j]) continue;
        const f = j > 0 ? mask[j-1] : 0;
        if (b[j] > a[j] && (f & 2)) continue;
        if (b[j] < a[j] && (f & 1)) continue;
        return false;
      }
      return true;
    }
    writeln (test() ? "YES" : "NO");
  }
}

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(){
    foreach(_; 0 .. scan!int){
        int n = scan!int;
        long[] as = scan!long(n), bs = scan!long(n);
        bool f, g;
        bool isOK = 1;
        foreach(i; 0 .. n){
            long a = as[i], b = bs[i];
            if(a < b && ! f) isOK = 0;
            if(a > b && ! g) isOK = 0;

            if(a > 0) f = 1;
            if(a < 0) g = 1;
        }
        (isOK? "YES": "NO").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)); }

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		auto b = RDA;
		bool add, sub;
		ans[ti] = true;
		foreach (i; 0..n)
		{
			if (a[i] > b[i])
			{
				if (!sub)
				{
					ans[ti] = false;
					break;
				}
			}
			else if (a[i] < b[i])
			{
				if (!add)
				{
					ans[ti] = false;
					break;
				}
			}
			if (a[i] > 0)
				add = true;
			else if (a[i] < 0)
				sub = true;
		}
	}

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


The score of an array $$$v_1,v_2,\ldots,v_n$$$ is defined as the number of indices $$$i$$$ ($$$1 \le i \le n$$$) such that $$$v_1+v_2+\ldots+v_i = 0$$$.You are given an array $$$a_1,a_2,\ldots,a_n$$$ of length $$$n$$$. You can perform the following operation multiple times:  select an index $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i=0$$$;  then replace $$$a_i$$$ by an arbitrary integer.  What is the maximum possible score of $$$a$$$ that can be obtained by performing a sequence of such operations?

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$) — array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print the maximum possible score of the array $$$a$$$ after performing a sequence of operations.

NoteIn the first test case, it is optimal to change the value of $$$a_2$$$ to $$$-2$$$ in one operation.The resulting array $$$a$$$ will be $$$[2,-2,1,-1,0]$$$, with a score of $$$3$$$:  $$$a_1+a_2=2-2=0$$$;  $$$a_1+a_2+a_3+a_4=2-2+1-1=0$$$;  $$$a_1+a_2+a_3+a_4+a_5=2-2+1-1+0=0$$$. In the second test case, it is optimal to change the value of $$$a_3$$$ to $$$-2\,000\,000\,000$$$, giving us an array with a score of $$$1$$$.In the third test case, it is not necessary to perform any operations.

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;

// zero-prefixed array
long solvez(long[] a, long s)
{
  long[long] freq;
  freq[s]++;
  foreach (i ; 1 .. a.length) {
    if (a[i] == 0) {
      long best = 0;
      long ans = 0;
      foreach (k, v ; freq) {
        if (v > best) {
          best = v;
        }
      }
      return best + solvez(a[i .. $], s);
    }
    s += a[i];
    freq[s]++;
  }
  long best = 0;
  long ans = 0;
  foreach (k, v ; freq) {
    if (v > best) {
      best = v;
    }
  }
  return best;
}

long solve(long[] a)
{
  long ans = 0;
  long s = 0;
  foreach (i ; 0 .. a.length) {
    s += a[i];
    if (a[i] == 0)
      return ans + solvez(a[i .. $], s);
    if (s == 0)
      ans++;
  }
  return ans;
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!long;
    auto a = readln.splitter.map!(to!long).array;
    writeln(solve(a));
  }
}

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 = read!int;
    auto s = readarray!long;
    long[long] d;
    long cur_sum, res;
    int i = 0;
    bool flag = false;
    while (i < s.length) {
        cur_sum += s[i];
        //writeln("sum", cur_sum);
        if (flag) {
            if (s[i] == 0) {
                auto m_key = d.byPair.maxElement!(p => p.value);
                cur_sum += m_key.key;
                res += m_key.value;
                d.clear();
            }
            d[cur_sum] = 1 + d.get(cur_sum, 0);
        }
        else if (s[i] == 0) {
            flag = true;
            d[cur_sum] = 1 + d.get(cur_sum, 0);
        }
        else if (cur_sum == 0)
            res++;
        i++;
    }
    if (!d.empty) {
        auto m_key = d.byPair.maxElement!(p => p.value);
        cur_sum += m_key.key;
        res += m_key.value;
    }
    writeln(res);
}

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


You are given an array $$$a_1, a_2, \ldots, a_n$$$ of positive integers. A good pair is a pair of indices $$$(i, j)$$$ with $$$1 \leq i, j \leq n$$$ such that, for all $$$1 \leq k \leq n$$$, the following equality holds:$$$$$$ |a_i - a_k| + |a_k - a_j| = |a_i - a_j|, $$$$$$ where $$$|x|$$$ denotes the absolute value of $$$x$$$.Find a good pair. Note that $$$i$$$ can be equal to $$$j$$$.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) where $$$a_i$$$ is the $$$i$$$-th element of the array. The sum of $$$n$$$ for all test cases is at most $$$2 \cdot 10^5$$$.

For each test case, print a single line with two space-separated indices $$$i$$$ and $$$j$$$ which form a good pair of the array. The case $$$i=j$$$ is allowed. It can be shown that such a pair always exists. If there are multiple good pairs, print any of them.

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

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

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

		auto l = a.MIN_POS;
		auto r = a.MIN_POS!"a > b";
		ans[ti] = [l+1, r+1];
	}

	foreach (e; ans)
		writeln(e[0], " ", e[1]);
	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)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		auto i = n - a.minPos.length.to !(int);
		auto j = n - a.maxPos.length.to !(int);
		writeln (i + 1, " ", j + 1);
	}
}


Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked $$$n$$$ of them how much effort they needed to reach red."Oh, I just spent $$$x_i$$$ hours solving problems", said the $$$i$$$-th of them. Bob wants to train his math skills, so for each answer he wrote down the number of minutes ($$$60 \cdot x_i$$$), thanked the grandmasters and went home. Bob could write numbers with leading zeroes — for example, if some grandmaster answered that he had spent $$$2$$$ hours, Bob could write $$$000120$$$ instead of $$$120$$$.Alice wanted to tease Bob and so she took the numbers Bob wrote down, and for each of them she did one of the following independently:   rearranged its digits, or  wrote a random number. This way, Alice generated $$$n$$$ numbers, denoted $$$y_1$$$, ..., $$$y_n$$$.For each of the numbers, help Bob determine whether $$$y_i$$$ can be a permutation of a number divisible by $$$60$$$ (possibly with leading zeroes).

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 418$$$) — the number of grandmasters Bob asked. Then $$$n$$$ lines follow, the $$$i$$$-th of which contains a single integer $$$y_i$$$ — the number that Alice wrote down. Each of these numbers has between $$$2$$$ and $$$100$$$ digits '0' through '9'. They can contain leading zeroes.

Output $$$n$$$ lines. For each $$$i$$$, output the following. If it is possible to rearrange the digits of $$$y_i$$$ such that the resulting number is divisible by $$$60$$$, output "red" (quotes for clarity). Otherwise, output "cyan".

NoteIn the first example, there is one rearrangement that yields a number divisible by $$$60$$$, and that is $$$360$$$.In the second example, there are two solutions. One is $$$060$$$ and the second is $$$600$$$.In the third example, there are $$$6$$$ possible rearrangments: $$$025$$$, $$$052$$$, $$$205$$$, $$$250$$$, $$$502$$$, $$$520$$$. None of these numbers is divisible by $$$60$$$.In the fourth example, there are $$$3$$$ rearrangements: $$$228$$$, $$$282$$$, $$$822$$$.In the fifth example, none of the $$$24$$$ rearrangements result in a number divisible by $$$60$$$.In the sixth example, note that $$$000\dots0$$$ is a valid solution.

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

void main() {
    auto T = readln.chomp.to!int;
    auto cnt = new int[](10);
    while (T--) {
        cnt[] = 0;
        auto S = readln.chomp;
        auto N = S.length.to!int;
        int zero = 0;
        int even = 0;
        int div3 = 0;
        foreach (i; 0..N) {
            int d = S[i]-'0';
            if (d == 0) zero += 1;
            if (d % 2 == 0) even += 1;
            div3 = (div3 + d) % 3;
        }
        if (zero >= 1 && even >= 2 && div3 == 0) {
            writeln("red");
        } else {
            writeln("cyan");
        }
    }
}

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

bool solve (string s)
{
	auto t = s.map !(q{a - '0'}).array;
	sort (t);
	if (t[0] != 0)
	{
		return false;
	}
	if (t.sum % 3 != 0)
	{
		return false;
	}
	if (!t.drop (1).canFind !(x => x % 2 == 0))
	{
		return false;
	}
	return true;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		writeln (solve (s) ? "red" : "cyan");
	}
}

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

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

void solve(){
	int n = rint;
	string[] as = rtypes!string(n);

	foreach(a; as){
		string ans;
		int[] ks = a.split("").map!(to!int).array;
		int[] cnt = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
		foreach(k; ks) cnt[k] += 1;
		if(cnt[0] == 0) ans = "cyan";
		else if(cnt[0] + cnt[2] + cnt[4] + cnt[6] + cnt[8] <= 1) ans = "cyan";
		else if(ks.sum % 3 != 0) ans = "cyan";
		else ans = "red";
		ans.writeln;
	}
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.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 numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const S = readToken();
        int sum, zero, even;
        foreach (c; S) {
          const d = c - '0';
          sum += d;
          if (d == 0) {
            ++zero;
          }
          if (d % 2 == 0) {
            ++even;
          }
        }
        const ans = (sum % 3 == 0 && zero >= 1 && even >= 2);
        writeln(ans ? "red" : "cyan");
      }
    }
  } catch (EOFException e) {
  }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!int;
	foreach (i; 0..n)
	{
		auto s = RD!string;
		auto cnt = new int[](10);
		foreach (c; s)
		{
			auto x = c - '0';
			++cnt[x];
		}
		int x;
		foreach (j; 0..10)
			x += cnt[j] * j;

		if (cnt[0] == 0 || x % 3)
			writeln("cyan");
		/*else if (s.length <= 3)
		{
			bool ok;
			if (cnt[6] >= 1)
				ok = true;
			else if (cnt[1] == 1 && cnt[2]+cnt[8] == 1)
				ok = true;
			else if (cnt[4] == 1 && cnt[2]+cnt[5]+cnt[8] == 1)
				ok = true;
			else if (cnt[7] == 1 && cnt[8]+cnt[2] == 1)
				ok = true;
			writeln(ok ? "red" : "cyan");
		}*/
		else if (cnt[0] == 1)
		{
			bool ok;
			foreach (j; 1..5)
			{
				if (cnt[j*2])
					ok = true;
			}
			writeln(ok ? "red" : "cyan");
		}
		else
		{
			writeln("red");
		}
	}

	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; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

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

void main()
{
	auto n = RD!int;
	foreach (i; 0..n)
	{
		auto s = RD!string;
		auto cnt = new int[](10);
		foreach (c; s)
		{
			auto x = c - '0';
			++cnt[x];
		}
		int x;
		foreach (j; 0..10)
			x += cnt[j] * j;
		if (x % 3)
			writeln("cyan");
		else
		{
			if ((cnt[0] >= 1 && cnt[6] >= 1) || (cnt[0] >= 2))
				writeln("red");
			else
				writeln("cyan");
		}
	}

	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; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

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

void main()
{
	auto n = RD!int;
	foreach (i; 0..n)
	{
		auto s = RD!string;
		auto cnt = new int[](10);
		foreach (c; s)
		{
			auto x = c - '0';
			++cnt[x];
		}
		int x;
		foreach (j; 0..10)
			x += cnt[j] * j;

		if (s.length <= 3)
		{
			if (cnt[0] == 0)
				writeln("cyan");
			else
			{
				bool ok;
				if (cnt[6] >= 1)
					ok = true;
				else if (cnt[1] == 1 && cnt[2]+cnt[8] == 1)
					ok = true;
				else if (cnt[4] == 1 && cnt[2]+cnt[5]+cnt[8] == 1)
					ok = true;
				else if (cnt[7] == 1 && cnt[8]+cnt[2] == 1)
					ok = true;
				writeln(ok ? "red" : "cyan");
			}
		}
		else
		{
			writeln(x % 3 || (cnt[0] >= 1 && cnt[0]+cnt[6] <= 1) ? "cyan" : "red");
		}
	}

	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; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

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

void main()
{
	auto n = RD!int;
	foreach (i; 0..n)
	{
		auto s = RD!string;
		auto cnt = new int[](10);
		foreach (c; s)
		{
			auto x = c - '0';
			++cnt[x];
		}
		int x;
		foreach (j; 0..10)
			x += cnt[j] * j;

		if (s.length <= 3)
		{
			if (cnt[0] == 0)
				writeln("cyan");
			else
			{
				bool ok;
				if (cnt[6] >= 1)
					ok = true;
				else if (cnt[1] == 1 && cnt[2]+cnt[8] == 1)
					ok = true;
				else if (cnt[4] == 1 && cnt[2]+cnt[5]+cnt[8] == 1)
					ok = true;
				else if (cnt[7] == 1 && cnt[8]+cnt[2] == 1)
					ok = true;
				writeln(ok ? "red" : "cyan");
			}
		}
		else
		{
			writeln(x % 3 || (cnt[0] == 0 || cnt[0]+cnt[6] <= 1) ? "cyan" : "red");
		}
	}

	stdout.flush;
	debug readln;
}


You are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:  All cells in a set have the same color.  Every two cells in a set share row or column.

The first line of input contains integers n and m (1 ≤ n, m ≤ 50) — the number of rows and the number of columns correspondingly. The next n lines of input contain descriptions of rows. There are m integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black.

Output single integer  — the number of non-empty sets from the problem description.

NoteIn the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.

// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.algorithm  : sort, sum;
import std.array      : split, appender;
import std.conv       : to;
import std.stdio      : readln, writeln;
import std.string     : chomp;

auto gets() { return readln.chomp; }
auto getV(T)() { return gets.to!T; }
auto getVals(T)() { return gets.split.to!(T[]); }

long c(int n, int k) {
    long ret = 1;
    foreach (v; 0..k) {
        ret *= n - v;
        ret /= v + 1;
    }
    return ret;
}

void main() {
    auto s = getVals!int;
    auto n = s[0], m = s[1];
    auto cols = new int[m];
    long ans = n * m;
    foreach (_; 0..n) {
        auto rows = getVals!int;
        auto x = 0;
        foreach (i, v; rows) {
            if (v == 0) { continue; }
            cols[i]++;
            x++;
        }
        foreach (i; 1..x) {
            ans += c(x, i+1);
        }
        x = m - x;
        foreach (i; 1..x) {
            ans += c(x, i+1);
        }
    }
    foreach (v; cols) {
        auto x = v;
        foreach (i; 1..x) {
            ans += c(x, i+1);
        }
        x = n - x;
        foreach (i; 1..x) {
            ans += c(x, i+1);
        }
    }
    writeln(ans);
}


Let's define $$$S(x)$$$ to be the sum of digits of number $$$x$$$ written in decimal system. For example, $$$S(5) = 5$$$, $$$S(10) = 1$$$, $$$S(322) = 7$$$.We will call an integer $$$x$$$ interesting if $$$S(x + 1) < S(x)$$$. In each test you will be given one integer $$$n$$$. Your task is to calculate the number of integers $$$x$$$ such that $$$1 \le x \le n$$$ and $$$x$$$ is interesting.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — number of test cases. Then $$$t$$$ lines follow, the $$$i$$$-th line contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) for the $$$i$$$-th test case.

Print $$$t$$$ integers, the $$$i$$$-th should be the answer for the $$$i$$$-th test case.

NoteThe first interesting number is equal to $$$9$$$.

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 n = RD!int;

		ans[ti] = n / 10;
		if (n % 10 == 9)
			++ans[ti];
	}

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

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

int main()
{
	int t = readInt!int;
	while (t--)
	{
		int n = readInt!int;
		if (n % 10 == 9)
		{
			n++;
			(n/10).writeln;
		}
		else
		{
			n -= n%10;
			(n/10).writeln;
		}
	}
	return 0;
}

/* 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()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long n;
    readf!" %d "(n);
    writeln((n + 1) / 10);
  }
}

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)
	{
		auto n = readln.strip.to !(int);
		writeln ((n + 1) / 10);
	}
}

// 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, std.random;
// import std.bigint, std.complex, std.bitmanip;
// import std.math, std.mathspecial, std.numeric;

void main() {

  int tests; readf!"%s\n"(tests);
  while(tests--) {
    int n; readf!"%s\n"(n);
    ((n + 1) / 10).writeln;
  }

} // main


You are given a positive integer $$$x$$$. Check whether the number $$$x$$$ is representable as the sum of the cubes of two positive integers.Formally, you need to check if there are two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b$$$) such that $$$a^3+b^3=x$$$.For example, if $$$x = 35$$$, then the numbers $$$a=2$$$ and $$$b=3$$$ are suitable ($$$2^3+3^3=8+27=35$$$). If $$$x=4$$$, then no pair of numbers $$$a$$$ and $$$b$$$ is suitable.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case contains one integer $$$x$$$ ($$$1 \le x \le 10^{12}$$$). Please note, that the input for some test cases won't fit into $$$32$$$-bit integer type, so you should use at least $$$64$$$-bit integer type in your programming language.

For each test case, output on a separate line:    "YES" if $$$x$$$ is representable as the sum of the cubes of two positive integers.  "NO" otherwise.  You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

NoteThe number $$$1$$$ is not representable as the sum of two cubes.The number $$$2$$$ is represented as $$$1^3+1^3$$$.The number $$$4$$$ is not representable as the sum of two cubes.The number $$$34$$$ is not representable as the sum of two cubes.The number $$$35$$$ is represented as $$$2^3+3^3$$$.The number $$$16$$$ is represented as $$$2^3+2^3$$$.The number $$$703657519796$$$ is represented as $$$5779^3+7993^3$$$.

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

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 t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto x = RD;

		for (long i = 1; i^^3 < x; ++i)
		{
			auto a = i^^3;
			auto y = x - a;
			bool f(long j)
			{
				if (j > y/j) return false;
				if (j*j > y/j) return false;
				return j^^3 <= y;
			}
			auto r = binarySearch!(f)(1, y+1);
			if (i == 5779)
				debug writeln("i:", i, " r:", r);
			ans[ti] = true;
			foreach (j; 0..3)
			{
				if (y % r)
				{
					if (i == 5779)
						debug writeln("y:", y, " r:", r);
					ans[ti] = false;
					break;
				}
				y /= r;
			}
			if (ans[ti] && y == 1)
				break;
			else
				ans[ti] = false;

		}
	}

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

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

void main()
{
    bool[long] memo;
    for (long b = 1; b^^3 <= 10L^^12; ++b) memo[b^^3] = true;
    int T; get(T); while (T--) {
        long X; get(X);
        for (long a = 1; a^^3 <= X; ++a) if (X - a^^3 in memo) {
            writeln("YES");
            goto ok;
        }
        writeln("NO");
        ok:
    }
}

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

void main ()
{
	bool [long] cubes;
	for (long s = 1; s <= 10 ^^ 4; s++)
	{
		cubes[s ^^ 3] = true;
	}

	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(long);
		bool ok = false;
		for (long s = 1; s ^^ 3 <= n; s++)
		{
			ok |= ((n - s ^^ 3) in cubes) !is null;
		}
		writeln (ok ? "YES" : "NO");
	}
}


Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve.He's got a square 2n × 2n-sized matrix and 4n integers. You need to arrange all these numbers in the matrix (put each number in a single individual cell) so that the beauty of the resulting matrix with numbers is maximum.The beauty of a 2n × 2n-sized matrix is an integer, obtained by the following algorithm:  Find the maximum element in the matrix. Let's denote it as m.  If n = 0, then the beauty of the matrix equals m. Otherwise, a matrix can be split into 4 non-intersecting 2n - 1 × 2n - 1-sized submatrices, then the beauty of the matrix equals the sum of number m and other four beauties of the described submatrices. As you can see, the algorithm is recursive.Help Ilya, solve the problem and print the resulting maximum beauty of the matrix.

The first line contains integer 4n (1 ≤ 4n ≤ 2·106). The next line contains 4n integers ai (1 ≤ ai ≤ 109) — the numbers you need to arrange in the 2n × 2n-sized matrix.

On a single line print the maximum value of the beauty of the described matrix. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteConsider the second sample. You need to arrange the numbers in the matrix as follows:1 23 4Then the beauty of the matrix will equal: 4 + 1 + 2 + 3 + 4 = 14.

import std.algorithm;
import std.stdio;

immutable int MED_N = 10;
immutable int MAX_N = MED_N << 1;
immutable int POW_N = 1 << MAX_N;

int [POW_N] a;
int n;

void main ()
{
    while (scanf (" %d", &n) != EOF)
    {
        foreach (i; 0..n)
        {
            scanf (" %d", &a[i]);
        }
        sort (a[0..n]);
        reverse (a[0..n]);

        long k = 0;
        for (int p = n; p > 0; p >>= 2)
        {
            k++;
        }
        int cur = 1, total = 3;

        long res = 0;
        for (int i = 0; i < n; i++)
        {
            cur--;
            res += k * a[i];
            if (cur == 0)
            {
                k--;
                cur = total;
                total *= 4;
            }
        }

        writeln (res);
    }
}

import std.algorithm;
import std.stdio;

immutable int MED_N = 10;
immutable int MAX_N = MED_N << 1;
immutable int POW_N = 1 << MAX_N;

int [POW_N] a;
int n;

void main ()
{
    while (scanf (" %d", &n) > 0)
    {
        foreach (i; 0..n)
        {
            scanf (" %d", &a[i]);
        }
        sort (a[0..n]);
        reverse (a[0..n]);

        long k = 0;
        for (int p = n; p > 0; p >>= 2)
        {
            k++;
        }
        int cur = 1, total = 3;

        long res = 0;
        for (int i = 0; i < n; i++)
        {
            cur--;
            res += k * a[i];
            if (cur == 0)
            {
                k--;
                cur = total;
                total *= 4;
            }
        }

        writeln (res);
    }
}

import std.stdio: readln, writeln;
import std.conv: to;
import std.string: strip;
import std.array: split;
import std.algorithm: sort, reverse;

/**
 * User: Jior
 * Date: 04.06.13
 * Time: 17:55
 */

void main(string[] args) {
	int countEls = to!int(strip(readln()));
	long[] els = to!(long[])(strip(readln()).split());
	sort(els);
	reverse(els);

	foreach (i, ref long el; els[1..$]) {
		el += els[i];
	}

	long result;
	while (countEls > 0) {
		result += els[countEls-1];
		countEls /= 4;
	}
	writeln(result);
}

import std.stdio: readln, writeln;
import std.conv: to;
import std.string: strip;
import std.array: split;
import std.algorithm: sort, reverse;

/**
 * User: Jior
 * Date: 04.06.13
 * Time: 17:55
 */

void main(string[] args) {
	int countEls = to!int(strip(readln()));
	int[] els = to!(int[])(strip(readln()).split());
	sort(els);
	reverse(els);

	foreach (i, ref int el; els[1..$]) {
		el += els[i];
	}

	long result;
	while (countEls > 0) {
		result += els[countEls-1];
		countEls /= 4;
	}
	writeln(result);
}

import std.stdio: readln, writeln;
import std.conv: to;
import std.string: strip;
import std.array: split;

import std.math: sqrt;
import std.algorithm: max;

/**
 * User: Jior
 * Date: 04.06.13
 * Time: 17:55
 */

int beauty(int[] mx) {
	int n = cast(int)sqrt(cast(float)mx.length);
	if (n == 1)
		return mx[0];

	int m = mx[0];
	foreach(int l; mx[1..$]) {
		m = max(m, l);
	}

	int[] left, right;
	foreach (int i; 0..n) {
		left ~= mx[i*n..((i+1)*n)-n/2];
		right ~= mx[i*n+n/2..(i+1)*n];
	}

	return beauty(left[0..$/2]) + beauty(left[$/2..$]) + beauty(right[0..$/2]) + beauty(right[$/2..$]) + m;
}

void main(string[] args) {
	int countEls = to!int(strip(readln()));
	int[] els = to!(int[])(strip(readln()).split());
	writeln(beauty(els));
}


Petya has a rectangular Board of size $$$n \times m$$$. Initially, $$$k$$$ chips are placed on the board, $$$i$$$-th chip is located in the cell at the intersection of $$$sx_i$$$-th row and $$$sy_i$$$-th column.In one action, Petya can move all the chips to the left, right, down or up by $$$1$$$ cell.If the chip was in the $$$(x, y)$$$ cell, then after the operation:   left, its coordinates will be $$$(x, y - 1)$$$;  right, its coordinates will be $$$(x, y + 1)$$$;  down, its coordinates will be $$$(x + 1, y)$$$;  up, its coordinates will be $$$(x - 1, y)$$$. If the chip is located by the wall of the board, and the action chosen by Petya moves it towards the wall, then the chip remains in its current position.Note that several chips can be located in the same cell.For each chip, Petya chose the position which it should visit. Note that it's not necessary for a chip to end up in this position.Since Petya does not have a lot of free time, he is ready to do no more than $$$2nm$$$ actions.You have to find out what actions Petya should do so that each chip visits the position that Petya selected for it at least once. Or determine that it is not possible to do this in $$$2nm$$$ actions.

The first line contains three integers $$$n, m, k$$$ ($$$1 \le n, m, k \le 200$$$) — the number of rows and columns of the board and the number of chips, respectively. The next $$$k$$$ lines contains two integers each $$$sx_i, sy_i$$$ ($$$ 1 \le sx_i \le n, 1 \le sy_i \le m$$$) — the starting position of the $$$i$$$-th chip. The next $$$k$$$ lines contains two integers each $$$fx_i, fy_i$$$ ($$$ 1 \le fx_i \le n, 1 \le fy_i \le m$$$) — the position that the $$$i$$$-chip should visit at least once.

In the first line print the number of operations so that each chip visits the position that Petya selected for it at least once. In the second line output the sequence of operations. To indicate operations left, right, down, and up, use the characters $$$L, R, D, U$$$ respectively. If the required sequence does not exist, print -1 in the single line.

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
    int n = scan!int, m = scan!int, k = scan!int;
    foreach(i; 0 .. k) int sx = scan!int, sy = scan!int;
    foreach(i; 0 .. k) int fx = scan!int, fy = scan!int;

    int ans = (n - 1) + (m - 1) + (n * m - 1);
    ans.writeln;

    foreach(i; 0 .. n - 1) "U".write;
    foreach(j; 0 .. m - 1) "L".write;
    string x = "R";
    foreach(i; 0 .. n){
        foreach(j; 0 .. m - 1) x.write;
        if(i < n - 1) "D".write;
        if(x == "R") x = "L"; else x = "R";
    }
    "".writeln;
}