I, Fischl, Prinzessin der Verurteilung, descend upon this land by the call of fate an — Oh, you are also a traveler from another world? Very well, I grant you permission to travel with me.It is no surprise Fischl speaks with a strange choice of words. However, this time, not even Oz, her raven friend, can interpret her expressions! Maybe you can help us understand what this young princess is saying?You are given a string of $$$n$$$ lowercase Latin letters, the word that Fischl just spoke. You think that the MEX of this string may help you find the meaning behind this message. The MEX of the string is defined as the shortest string that doesn't appear as a contiguous substring in the input. If multiple strings exist, the lexicographically smallest one is considered the MEX. Note that the empty substring does NOT count as a valid MEX.A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds:   $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$;  in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$. A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.Find out what the MEX of the string is!

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the length of the word. The second line for each test case contains a single string of $$$n$$$ lowercase Latin letters. The sum of $$$n$$$ over all test cases will not exceed $$$1000$$$.

For each test case, output the MEX of the string on a new line.

3
28
qaabzwsxedcrfvtgbyhnujmiklop
13
cleanairactbd
10
aannttoonn

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length == b.length)
        return a < b;
    return a.length < b.length;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'e'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(!canFind(s, item)) {
            item.writeln;
            break;
        }
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length == b.length)
        return a < b;
    return a.length < b.length;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'e'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(canFind(s, item))
            continue;
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length == b.length)
        return a < b;
    return a.length < b.length;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'e'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

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

    int n;
    string s;
while(t--) {
    readf("%s\n", &n);
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length == b.length)
        return a < b;
    return a.length < b.length;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'e'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length == b.length)
        return a < b;
    return a.length < b.length;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'z'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length < b.length)
        return true;
    else if(a.length == b.length)
        return a < b;
    else
        return false;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'z'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length < b.length)
        return true;
    return a < b;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi,false);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'z'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

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

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26 + 1);
    bool[] two = new bool[](26 * 26 + 1);
    bool[] three = new bool[](26 * 26 * 26 + 1);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
      if (i + 2 < s.length)
        three[(s[i] - 'a') * 26 * 26 + (s[i + 1] - 'a') * 26 + (s[i + 2] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    long x3 = three.countUntil(false);
    auto result1 = ['a'];
    auto result2 = ['a', 'a'];
    auto result3 = ['a', 'a', 'a'];
    if (x1 < 26) {
      result1[0] += x1;
      writefln("%s", result1.idup);
    } else if (x2 < 26 * 26) {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2.idup);
    } else {
      result3[0] += x3 / (26 * 26);
      result3[1] += (x3 / 26) % 26;
      result3[2] += x3 % 26;
      writefln("%s", result3.idup);
    }
  }
}

import std.container;
import std.stdio;
import std.conv;

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

  while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);
    auto rbt = new RedBlackTree!string;

    for(int k = 1; k <= 3; ++k)
      for(int i = 0; i <= n-k; ++i)
        rbt.insert(s[i..i+k]);

    string abc = "abcdefghijklmnopqrstuvwxyz";
    auto q = DList!string();
    for(char c = 'a'; c <= 'z'; ++c) {
      q.insert(c.to!string);
    }

    while(!q.empty) {
      auto p = q.front();
      q.removeFront();
      if(!(p in rbt)) {
        p.writeln;
        break;
      }
      foreach(char l; abc)
        q.insertBack(p ~ l);
    }
  }
}

import std.container;
import std.stdio;
import std.conv;

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

  while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);
    auto rbt = new RedBlackTree!(string);

    for(int k = 1; k <= 3; ++k)
      for(int i = 0; i <= n-k; ++i)
        rbt.insert(s[i..i+k]);

    string abc = "abcdefghijklmnopqrstuvwxyz";
    auto q = DList!string();
    for(char c = 'a'; c <= 'z'; ++c) {
      q.insert(c.to!string);
    }

    while(!q.empty) {
      auto p = q.front();
      q.removeFront();
      if(!(p in rbt)) {
        p.writeln;
        break;
      }
      foreach(char l; abc)
        q.insertBack(p ~ l);
    }
  }
}

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

dchar[] getStr(ll num){
    dchar[] res;
    while(num > 0){
        num -= 1;
        ll cr = (num % 26);
        if(cr >= 0){
            res ~= to!dchar(cr + 'a');
        }
        num /= 26;
    }
    res.reverse;
    return res;
}

int makeNum(dchar[] w, int st, int end){
    int res = 0;
    for(int i = st; i <= end; ++i){
        dchar cr = w[i];
        res *= 26;
        res += (cr - 'a' +  1);
    }
    return res;
}

void theCode(){
    ll n = scan;
    auto word = scan!(dchar[]);
    auto freq = new ll[](2000);
    for(int j = 0; j < 3; ++j){
        for(int i = 0; i < n - j; ++i){
            int num = makeNum(word, i, i+j);
            if(num < 2000){
                ++freq[num];
            }
        }
    }
    for(int i = 1; i < 2000; ++i){
        if(!freq[i]){
            writeln(getStr(i));
            return;
        }
    }
}

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

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

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length < b.length)
        return true;
    else if(a.length == b.length)
        return a < b;
    else
        return false;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            /*
            for(char e = 'a'; e <= 'z'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
            */
        }
    }

    rbtree.insert("aaa");

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length < b.length)
        return true;
    else if(a.length == b.length)
        return a < b;
    else
        return false;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            /*
            for(char e = 'a'; e <= 'z'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
            */
        }
    }

    rbtree.insert("aaa");
    rbtree.writeln;

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length < b.length)
        return true;
    return a < b;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
        }
    }
    rbtree.insert("aaa");

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length < b.length)
        return true;
    return a < b;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
        }
    }

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

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

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26 + 1);
    bool[] two = new bool[](26 * 26 + 1);
    bool[] three = new bool[](26 * 26 * 26 + 1);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
      if (i + 2 < s.length)
        three[(s[i] - 'a') * 26 * 26 + (s[i + 1] - 'a') * 26 + (s[i + 2] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    long x3 = three.countUntil(false);
    auto result1 = ['a'];
    auto result2 = ['a', 'a'];
    auto result3 = ['a', 'a', 'a'];
    if (x1 < 26) {
      result1[0] += x1;
      writefln("%s", result1.idup);
    } else if (x2 < 26 * 26) {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2.idup);
    } else {
      result3[0] += x2 / (26 * 26);
      result3[1] += (x2 / 26) % 26;
      result3[2] += x2 % 26;
      writefln("%s", result3.idup);
    }
  }
}

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

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26 + 1);
    bool[] two = new bool[](26 * 26 + 1);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    auto result1 = ['a'];
    auto result2 = ['a', 'a'];
    if (x1 < 26) {
      result1[0] += x1;
      writefln("%s", result1.idup);
    } else {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2.idup);
    }
  }
}

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

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26);
    bool[] two = new bool[](26 * 26);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    auto result1 = ['a'];
    auto result2 = ['a', 'a'];
    if (x1 < one.length) {
      result1[0] += x1;
      writefln("%s", result1.idup);
    } else {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2.idup);
    }
  }
}

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

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26);
    bool[] two = new bool[](26 * 26);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    auto result1 = ['a'];
    auto result2 = ['a', 'a'];
    if (x1 < one.length) {
      result1[0] += x1;
      writefln("%s", result1.to!string);
    } else {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2.to!string);
    }
  }
}

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

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26);
    bool[] two = new bool[](26 * 26);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    auto result1 = ['a'];
    auto result2 = ['a', 'a'];
    if (x1 < one.length) {
      result1[0] += x1;
      writefln("%s", result1);
    } else {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2);
    }
  }
}

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

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26);
    bool[] two = new bool[](26 * 26);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    char[1] result1 = "a";
    char[2] result2 = "aa";
    if (x1 < one.length) {
      result1[0] += x1;
      writefln("%s", result1);
    } else {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2);
    }
  }
}

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

dchar[] getStr(ll num){
    dchar[] res;
    while(num > 0){
        ll cr = (num % 26) - 1;
        if(cr >= 0){
            res ~= to!dchar(cr + 'a');
        }
        num /= 26;
    }
    res.reverse;
    return res;
}

int makeNum(dchar[] w, int st, int end){
    int res = 0;
    for(int i = st; i <= end; ++i){
        dchar cr = w[i];
        res *= 26;
        res += (cr - 'a' + 1);
    }
    return res;
}

void theCode(){
    ll n = scan;
    auto word = scan!(dchar[]);
    auto freq = new ll[](2000);
    for(int j = 0; j < 3; ++j){
        for(int i = 0; i < n - j; ++i){
            int num = makeNum(word, i, i+j);
            if(num < 2000){
                ++freq[num];
            }
        }
    }
    for(int i = 1; i < 2000; ++i){
        if(!freq[i]){
            writeln(getStr(i));
            return;
        }
    }
}

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

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


There are $$$n$$$ participants in a competition, participant $$$i$$$ having a strength of $$$s_i$$$. Every participant wonders how much of an advantage they have over the other best participant. In other words, each participant $$$i$$$ wants to know the difference between $$$s_i$$$ and $$$s_j$$$, where $$$j$$$ is the strongest participant in the competition, not counting $$$i$$$ (a difference can be negative).So, they ask you for your help! For each $$$i$$$ ($$$1 \leq i \leq n$$$) output the difference between $$$s_i$$$ and the maximum strength of any participant other than participant $$$i$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The descriptions of the test cases follow. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2\cdot10^5$$$) — the length of the array. The following line contains $$$n$$$ space-separated positive integers $$$s_1$$$, $$$s_2$$$, ..., $$$s_n$$$ ($$$1 \leq s_i \leq 10^9$$$) — the strengths of the participants. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, output $$$n$$$ space-separated integers. For each $$$i$$$ ($$$1 \leq i \leq n$$$) output the difference between $$$s_i$$$ and the maximum strength of any other participant.

NoteFor the first test case: The first participant has a strength of $$$4$$$ and the largest strength of a participant different from the first one is $$$7$$$, so the answer for the first participant is $$$4 - 7 = -3$$$.  The second participant has a strength of $$$7$$$ and the largest strength of a participant different from the second one is $$$5$$$, so the answer for the second participant is $$$7 - 5 = 2$$$. The third participant has a strength of $$$3$$$ and the largest strength of a participant different from the third one is $$$7$$$, so the answer for the third participant is $$$3 - 7 = -4$$$. The fourth participant has a strength of $$$5$$$ and the largest strength of a participant different from the fourth one is $$$7$$$, so the answer for the fourth participant is $$$5 - 7 = -2$$$.

// Taken from https://codeforces.com/contest/1760/submission/182072909
// and rewritten a bit to get rid of C/C++ style scanf/printf and
// imperative loops. Allocate the array on stack. Bring back printf.

import std;

void main()
{
  int[200000] arr = void;
  foreach (t ; readln.strip.to!int.iota) {
    int m = 0, M = 0, n = readln.strip.to!int;
    auto a = arr[0 .. n];

    // calculate 'm' and 'M' in a single pass while reading the array
    readln.splitter.map!((x) { auto k = x.to!int;
                               if (k > M) {
                                 m = M;
                                 M = k;
                               } else if (k > m) {
                                 m = k;
                               }
                               return k; }).copy(a);

    foreach (k ; a)
      printf("%d ", (k == M) ? (k - m) : (k - M));
    printf("\n");
  }
}

// Taken from https://codeforces.com/contest/1760/submission/182072909
// and rewritten a bit to get rid of C/C++ style scanf/printf and
// imperative loops. Allocate the array on stack.

import std;

void main()
{
  int[200000] arr = void;
  foreach (t ; readln.strip.to!int.iota) {
    int m = 0, M = 0, n = readln.strip.to!int;
    auto a = arr[0 .. n];

    // calculate 'm' and 'M' in a single pass while reading the array
    readln.splitter.map!((x) { auto k = x.to!int;
                               if (k > M) {
                                 m = M;
                                 M = k;
                               } else if (k > m) {
                                 m = k;
                               }
                               return k; }).copy(a);
    a.map!(k => (k == M) ? (k - m) : (k - M)).writefln!"%(%s %)";
  }
}

import std;

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!int;
    auto a = readln.splitter.map!(to!int).array;
    auto seg = a.Segtree!(int, (x, y) => max(x, y), () => 0);
    n.iota.map!(i => a[i] - max(seg.prod(0, i), seg.prod(i + 1, n)))
          .writefln!"%(%s %)";
  }
}

// Code from: https://github.com/kotet/atcoder-library-d

int celiPow2(int n) @safe pure nothrow @nogc
{
    int x = 0;
    while ((1u << x) < cast(uint)(n))
        x++;
    return x;
}

// --- segtree ---

struct Segtree(S, alias op, alias e)
{
    import std.functional : binaryFun, unaryFun;
    import std.traits : isCallable, Parameters;

    static if (is(typeof(e) : string))
    {
        auto unit()
        {
            return mixin(e);
        }
    }
    else
    {
        alias unit = e;
    }

    this(int n)
    {
        auto buf = new S[](n);
        buf[] = unit();
        this(buf);
    }

    this(S[] v)
    {
        _n = cast(int) v.length;
        log = celiPow2(_n);
        size = 1 << log;
        d = new S[](2 * size);
        d[] = unit();
        foreach (i; 0 .. _n)
            d[size + i] = v[i];
        foreach_reverse (i; 1 .. size)
            update(i);
    }

    void set(int p, S x)
    {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        foreach (i; 1 .. log + 1)
            update(p >> i);
    }

    S get(int p)
    {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r)
    {
        assert(0 <= l && l <= r && r <= _n);
        S sml = unit(), smr = unit();
        l += size;
        r += size;
        while (l < r)
        {
            if (l & 1)
                sml = binaryFun!(op)(sml, d[l++]);
            if (r & 1)
                smr = binaryFun!(op)(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return binaryFun!(op)(sml, smr);
    }

    S allProd()
    {
        return d[1];
    }

    int maxRight(alias f)(int l)
    {
        return maxRight(l, &unaryFun!(f));
    }

    int maxRight(F)(int l, F f) if (isCallable!F && Parameters!(F).length == 1)
    {
        assert(0 <= l && l <= _n);
        assert(f(unit()));
        if (l == _n)
            return _n;
        l += size;
        S sm = unit();
        do
        {
            while (l % 2 == 0)
                l >>= 1;
            if (!f(binaryFun!(op)(sm, d[l])))
            {
                while (l < size)
                {
                    l = 2 * l;
                    if (f(binaryFun!(op)(sm, d[l])))
                    {
                        sm = binaryFun!(op)(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = binaryFun!(op)(sm, d[l]);
            l++;
        }
        while ((l & -l) != l);
        return _n;
    }

    int minLeft(alias f)(int r)
    {
        return minLeft(r, &unaryFun!(f));
    }

    int minLeft(F)(int r, F f) if (isCallable!F && Parameters!(F).length == 1)
    {
        assert(0 <= r && r <= _n);
        assert(f(unit()));
        if (r == 0)
            return 0;
        r += size;
        S sm = unit();
        do
        {
            r--;
            while (r > 1 && (r % 2))
                r >>= 1;
            if (!f(binaryFun!(op)(d[r], sm)))
            {
                while (r < size)
                {
                    r = 2 * r + 1;
                    if (f(binaryFun!(op)(d[r], sm)))
                    {
                        sm = binaryFun!(op)(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = binaryFun!(op)(d[r], sm);
        }
        while ((r & -r) != r);
        return 0;
    }

private:
    int _n = 0, size = 1, log = 0;
    S[] d = [unit(), unit()];
    void update(int k)
    {
        d[k] = binaryFun!(op)(d[2 * k], d[2 * k + 1]);
    }
}

// Taken from https://codeforces.com/contest/1760/submission/182072909
// and rewritten a bit to get rid of C/C++ style scanf/printf and
// imperative loops. Also added ".take(n)"

import std;

void main()
{
  foreach (t ; readln.strip.to!int.iota) {
    int m = 0, M = 0, n = readln.strip.to!int;

    // calculate 'm' and 'M' in a single pass while reading the array
    auto a = readln.splitter.map!((x) { auto k = x.to!int;
                                        if (k > M) {
                                          m = M;
                                          M = k;
                                        } else if (k > m) {
                                          m = k;
                                        }
                                        return k; }).take(n).array;

    a.map!(k => (k == M) ? (k - m) : (k - M)).writefln!"%(%s %)";
  }
}

// Taken from https://codeforces.com/contest/1760/submission/182072909
// and rewritten a bit to get rid of C/C++ style scanf/printf and
// imperative loops

import std;

void main()
{
  foreach (t ; readln.strip.to!int.iota) {
    int m = 0, M = 0, n = readln.strip.to!int;

    // calculate 'm' and 'M' in a single pass while reading the array
    auto a = readln.splitter.map!((x) { auto k = x.to!int;
                                        if (k > M) {
                                          m = M;
                                          M = k;
                                        } else if (k > m) {
                                          m = k;
                                        }
                                        return k; }).array;

    a.map!(k => (k == M) ? (k - m) : (k - M)).writefln!"%(%s %)";
  }
}

import std;

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!int;
    auto a = readln.splitter.map!(to!int).array;
    auto seg = a.Segtree!(int, (x, y) => max(x, y), () => 0);
    int[] ans;
    foreach (i ; 0 .. a.length.to!int) {
      int best = max(seg.prod(0, i), seg.prod(i + 1, n));
      ans ~= a[i] - best;
    }
    writefln("%(%s %)", ans);
  }
}

// Code from: https://github.com/kotet/atcoder-library-d

int celiPow2(int n) @safe pure nothrow @nogc
{
    int x = 0;
    while ((1u << x) < cast(uint)(n))
        x++;
    return x;
}

// --- segtree ---

struct Segtree(S, alias op, alias e)
{
    import std.functional : binaryFun, unaryFun;
    import std.traits : isCallable, Parameters;

    static if (is(typeof(e) : string))
    {
        auto unit()
        {
            return mixin(e);
        }
    }
    else
    {
        alias unit = e;
    }

    this(int n)
    {
        auto buf = new S[](n);
        buf[] = unit();
        this(buf);
    }

    this(S[] v)
    {
        _n = cast(int) v.length;
        log = celiPow2(_n);
        size = 1 << log;
        d = new S[](2 * size);
        d[] = unit();
        foreach (i; 0 .. _n)
            d[size + i] = v[i];
        foreach_reverse (i; 1 .. size)
            update(i);
    }

    void set(int p, S x)
    {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        foreach (i; 1 .. log + 1)
            update(p >> i);
    }

    S get(int p)
    {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r)
    {
        assert(0 <= l && l <= r && r <= _n);
        S sml = unit(), smr = unit();
        l += size;
        r += size;
        while (l < r)
        {
            if (l & 1)
                sml = binaryFun!(op)(sml, d[l++]);
            if (r & 1)
                smr = binaryFun!(op)(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return binaryFun!(op)(sml, smr);
    }

    S allProd()
    {
        return d[1];
    }

    int maxRight(alias f)(int l)
    {
        return maxRight(l, &unaryFun!(f));
    }

    int maxRight(F)(int l, F f) if (isCallable!F && Parameters!(F).length == 1)
    {
        assert(0 <= l && l <= _n);
        assert(f(unit()));
        if (l == _n)
            return _n;
        l += size;
        S sm = unit();
        do
        {
            while (l % 2 == 0)
                l >>= 1;
            if (!f(binaryFun!(op)(sm, d[l])))
            {
                while (l < size)
                {
                    l = 2 * l;
                    if (f(binaryFun!(op)(sm, d[l])))
                    {
                        sm = binaryFun!(op)(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = binaryFun!(op)(sm, d[l]);
            l++;
        }
        while ((l & -l) != l);
        return _n;
    }

    int minLeft(alias f)(int r)
    {
        return minLeft(r, &unaryFun!(f));
    }

    int minLeft(F)(int r, F f) if (isCallable!F && Parameters!(F).length == 1)
    {
        assert(0 <= r && r <= _n);
        assert(f(unit()));
        if (r == 0)
            return 0;
        r += size;
        S sm = unit();
        do
        {
            r--;
            while (r > 1 && (r % 2))
                r >>= 1;
            if (!f(binaryFun!(op)(d[r], sm)))
            {
                while (r < size)
                {
                    r = 2 * r + 1;
                    if (f(binaryFun!(op)(d[r], sm)))
                    {
                        sm = binaryFun!(op)(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = binaryFun!(op)(d[r], sm);
        }
        while ((r & -r) != r);
        return 0;
    }

private:
    int _n = 0, size = 1, log = 0;
    S[] d = [unit(), unit()];
    void update(int k)
    {
        d[k] = binaryFun!(op)(d[2 * k], d[2 * k + 1]);
    }
}

import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
//import std.numeric;
//import std.range;
import std.array;
//import std.bigint;
import std.string;

void sol(){

    int n, k, m=0, M=0;
    int[200000] arr;

    scanf("%d",&n);

    foreach(i; 0..n){
        scanf("%d ",&k);
        arr[i] = k;

        if(k>M){
            m=M;
            M=k;
        }
        else if(k>m){
            m=k;
        }
    }

    foreach(i; 0..n){
        k = arr[i];
        if (k==M){
            printf("%d ", k-m);
        }
        else{
            printf("%d ", k-M);
        }
    }
    printf("\n");
}

void main(){

    int t;
    readf!"%d"(t);
    while (t--){
        sol();
    }
}

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

void main()
{
    auto t = readln().strip().to!int;
    foreach (_; 0..t)
    {
        auto n = readln().strip().to!int;
        auto s = readln().strip().split().map!(e=>e.to!int).array;
        auto sorted = s.dup;
        sorted.sort;

        foreach (e; s)
        {
            if (e == sorted[$-1])
            {
                writef("%d ", e - sorted[$-2]);
            }
            else
            {
                writef("%d ", e - sorted[$-1]);
            }
        }
    }
}

import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
//import std.numeric;
//import std.range;
import std.array;
//import std.bigint;
import std.string;

void sol(){

    int n, k, m=0, M=0;
    int[200000] arr;

    scanf("%d",&n);

    foreach(i; 0..n){
        scanf("%d ",&k);
        arr[i] = k;

        if(k>M){
            M=k;
        }
        else if(k>m){
            m=k;
        }
    }

    foreach(i; 0..n){
        k = arr[i];
        if (k==M){
            printf("%d ", k-m);
        }
        else{
            printf("%d ", k-M);
        }
    }
    printf("\n");
}

void main(){

    int t;
    readf!"%d"(t);
    while (t--){
        sol();
    }
}


In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced.

The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different.

Print the k-th pronounced identifier (assume that the numeration starts from 1).

NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.

import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    long n, k;
    readlnTo(n, k);
    auto id = readLongs();
    long m;
    while((m+1)*(m+2)/2 < k) {
        ++m;
    }
    auto l = k - m*(m+1)/2;
    writeln(id[(l-1).to!uint]);
}


In some social network, there are $$$n$$$ users communicating with each other in $$$m$$$ groups of friends. Let's analyze the process of distributing some news between users.Initially, some user $$$x$$$ receives the news from some source. Then he or she sends the news to his or her friends (two users are friends if there is at least one group such that both of them belong to this group). Friends continue sending the news to their friends, and so on. The process ends when there is no pair of friends such that one of them knows the news, and another one doesn't know.For each user $$$x$$$ you have to determine what is the number of users that will know the news if initially only user $$$x$$$ starts distributing it.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 5 \cdot 10^5$$$) — the number of users and the number of groups of friends, respectively. Then $$$m$$$ lines follow, each describing a group of friends. The $$$i$$$-th line begins with integer $$$k_i$$$ ($$$0 \le k_i \le n$$$) — the number of users in the $$$i$$$-th group. Then $$$k_i$$$ distinct integers follow, denoting the users belonging to the $$$i$$$-th group. It is guaranteed that $$$\sum \limits_{i = 1}^{m} k_i \le 5 \cdot 10^5$$$.

Print $$$n$$$ integers. The $$$i$$$-th integer should be equal to the number of users that will know the news if user $$$i$$$ starts distributing it.

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.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto uf = new UnionFind(N);
    foreach (_; 0..M) {
        auto A = readln.split.map!(to!int).array;
        foreach (i; 2..A.length.to!int) {
            uf.unite(A[1]-1, A[i]-1);
        }
    }
    N.iota.map!(i => -uf.table[uf.find(i)]).map!(to!string).join(" ").writeln;
}

class UnionFind {
    int N;
    int[] table;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        table[y] = x;
    }
}

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

class DisjointSet {
  private:
    int [] p, h;
    int n;
  public:
  this (int _n) {
    n = _n;
    p = iota (0, n).array;
    h = new int[n];
  }
  int findSet (int x) pure nothrow @nogc {
    if (p[x] == x) {
      return x;
    }
    return p[x] = findSet (p[x]);
  }
  void merge (int i, int j) pure nothrow @nogc {
    i = findSet (i);
    j = findSet (j);
    if (i != j) {
      if (h[i] < h[j]) {
        p[i] = j;
      } else if (h[i] > h[j]) {
        p[j] = i;
      } else {
        p[i] = j;
        ++h[j];
      }
    }
  }
  int biggest_set_size () pure {
    auto c = new int[n];
    foreach (i; 0 .. n) {
      ++c[findSet (i)];
    }
    return c.reduce! (max);
  }
}

class InputReader {
  private:
  ubyte[] p;
  ubyte[] buffer;
  size_t cur;
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
    p = stdin.rawRead (buffer);
  }
  final ubyte skipByte (ubyte lo) {
    while (true) {
      auto a = p[cur .. $];
      auto r = a.find! (c => c >= lo);
      if (!r.empty) {
        cur += a.length - r.length;
        return p[cur++];
      }
      p = stdin.rawRead (buffer);
      cur = 0;
      if (p.empty) return 0;
    }
  }
  final ubyte nextByte () {
    if (cur < p.length) {
       return p[cur++];
    }
    p = stdin.rawRead (buffer);
    if (p.empty) return 0;
    cur = 1;
    return p[0];
  }

  template next(T) if (isSigned!T) {
    final T next ()  {
      T res;
      ubyte b = skipByte (45);
      if (b == 45) {
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    final T next () {
      T res = skipByte (48) - 48;
      while (true) {
        ubyte b = nextByte ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  final T[] nextA(T) (int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader;
  immutable n = r.next!uint, m = r.next!uint;
  auto ds = new DisjointSet (n);
  foreach (group; 0 .. m) {
    immutable k = r.next!uint;
    auto x = r.nextA!uint (k);
    foreach (i; 1 .. k) {
      ds.merge (x[i] - 1, x[i-1] - 1);
    }
  }
  auto c = new int[n];
  foreach (i; 0 .. n) {
    ++c[ds.findSet (i)];
  }
  int[] res;
  res.reserve (n);
  foreach (i; 0 .. n) {
    res ~= c[ds.findSet (i)];
  }
  writefln ("%(%s %)", res);
}

import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	long n = read.to!long;
	long m = read.to!long;

	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i, 0);

	foreach(nd; nodes){
		nd.group = new Group(nd);
	}

	Edge[] edges;
	foreach(i; 0 .. m){
		long k = read.to!long;
		if(k > 0){
			int a = read.to!int - 1;
			foreach(j; 1 .. k){
				int b = read.to!int - 1;
				edges ~= new Edge(nodes[a], nodes[b], 1);
			}
		}
	}

	foreach(ed; edges){
		if(ed.node1.group.id != ed.node2.group.id){
			ed.node1.group.eat(ed.node2.group);
		}
	}

	long[] ans;
	foreach(nd; nodes) ans ~= nd.group.nodes.length;

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

}

class Edge{
	Node node1;
	Node node2;
	long value;
	this(Node node1, Node node2, long value){
		this.node1 = node1, this.node2 = node2;
		this.value = value;
	}
}

class Node{
	long id;
	long value;
	Group group;
	this(long id, long value){
		this.id = id;
		this.value = value;
	}
}

class Group{
	long value;
	long pendingEdgeCount;
	long id;
	Node[] nodes;
	this(Node node){
		this.id = node.id;
		this.nodes = [node];
		this.value = node.value;
	}
	void eat(Group gp){
		if(gp.nodes.length > this.nodes.length) gp.eat(this);
		else{
			foreach(nd; gp.nodes){
				this.nodes ~= nd;
				nd.group = this;
				this.value += nd.value;
			}
			this.pendingEdgeCount += gp.pendingEdgeCount;
		}
	}
}

module _;
void main() {
	import std.stdio;
	import std.algorithm;
	import std.array, std.range;
	int n,m;
	int[] pa, h, sz;
	readf("%s %s ", &n, &m);
	pa = iota(n).array;
	h = new int[n];
	sz = new int[n];
	h[] = 1;
	sz[] = 1;

	int getpa(int a) {
		if (pa[a] == a) {
			return a;
		}
		pa[a] = getpa(pa[a]);
		return pa[a];
	}
	void merge(int a, int b) {
		int paa = getpa(a), pab = getpa(b);
		if (paa == pab) {
			return;
		}
		if (h[paa] > h[pab]) {
			pa[pab] = paa;
			sz[paa] += sz[pab];
		} else {
			pa[paa] = pab;
			sz[pab] += sz[paa];
			if (h[paa] == h[pab]) {
				h[pab]++;
			}
		}
	}

	foreach(i; 0..m) {
		int k;
		readf("%s ", &k);
		if (k) {
			int mem0;
			readf("%s ", &mem0);
			foreach(j; 1..k) {
				int mem;
				readf("%s ", &mem);
				merge(mem-1, mem0-1);
			}
		}
	}
	foreach(i; 0..n) {
		writef("%s ", sz[getpa(i)]);
	}
	writeln;
}

module _;
void main() {
	import std.stdio;
	import std.algorithm;
	import std.array, std.range;
	int n,m;
	int[] pa, h, sz;
	readf("%s %s ", &n, &m);
	pa = iota(n).array;
	h = new int[n];
	sz = new int[n];
	h[] = 1;
	sz[] = 1;

	int getpa(int a) {
		if (pa[a] == a) {
			return a;
		}
		pa[a] = getpa(pa[a]);
		return pa[a];
	}
	void merge(int a, int b) {
		int paa = getpa(a), pab = getpa(b);
		if (h[paa] > h[pab]) {
			pa[pab] = paa;
			sz[paa] += sz[pab];
		} else {
			pa[paa] = pab;
			sz[pab] += sz[paa];
			if (h[paa] == h[pab]) {
				h[pab]++;
			}
		}
	}

	foreach(i; 0..m) {
		int k;
		readf("%s ", &k);
		int mem0;
		if (k) {
			readf("%s ", &mem0);
			foreach(j; 1..k) {
				int mem;
				readf("%s ", &mem);
				merge(mem-1, mem0-1);
			}
		}
	}
	foreach(i; 0..n) {
		writef("%s ", sz[getpa(i)]);
	}
	writeln;
}


In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.Tzuyu gave Sana two integers $$$a$$$ and $$$b$$$ and a really important quest.In order to complete the quest, Sana has to output the smallest possible value of ($$$a \oplus x$$$) + ($$$b \oplus x$$$) for any given $$$x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^{4}$$$). Description of the test cases follows. The only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^{9}$$$).

For each testcase, output the smallest possible value of the given expression.

NoteFor the first test case Sana can choose $$$x=4$$$ and the value will be ($$$6 \oplus 4$$$) + ($$$12 \oplus 4$$$) = $$$2 + 8$$$ = $$$10$$$. It can be shown that this is the smallest possible value.

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

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

    long a, b;
    while(t--) {
        readf("%s %s\n", &a, &b);

        long bits = 0L;

        for(int i = 0; i < 32; i++)
            if(a&(1<<i) && b&(1<<i))
                bits += (1<<i);

        long ans = (a^bits) + (b^bits);
        ans.writeln;
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto x = a & b;
		ans[ti] = (a ^ x) + (b ^ x);
	}

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


You have a garland consisting of $$$n$$$ lamps. Each lamp is colored red, green or blue. The color of the $$$i$$$-th lamp is $$$s_i$$$ ('R', 'G' and 'B' — colors of lamps in the garland).You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $$$1$$$) have distinct colors.In other words, if the obtained garland is $$$t$$$ then for each $$$i$$$ from $$$1$$$ to $$$n-1$$$ the condition $$$t_i \ne t_{i + 1}$$$ should be satisfied.Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of lamps. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ characters 'R', 'G' and 'B' — colors of lamps in the garland.

In the first line of the output print one integer $$$r$$$ — the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $$$t$$$ of length $$$n$$$ — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.

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.string;

void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    auto T = "RGB";

    auto dp = new int[][](N, 3);
    auto prev = new dchar[][](N+1, 3);
    foreach (i; 0..N) dp[i][] = 1 << 29;
    foreach (j; 0..3) dp[0][j] = S[0] != T[j];

    foreach (i; 1..N) {
        foreach (j; 0..3) {
            foreach (k; 0..3) {
                if (j == k) continue;
                int cost = S[i] != T[k];
                if (dp[i-1][j] + cost < dp[i][k]) {
                    dp[i][k] = dp[i-1][j] + cost;
                    prev[i][k] = j;
                }
            }
        }
    }

    int minv = 1 << 29;
    int mink = 0;
    foreach (k; 0..3) {
        if (dp[N-1][k] < minv) {
            minv = dp[N-1][k];
            mink = k;
        }
    }

    dchar[] ans = [T[mink]];

    foreach_reverse (i; 1..N) {
        ans ~= T[prev[i][mink]];
        mink = prev[i][mink];
    }

    minv.writeln;
    ans.reverse;
    ans.writeln;
}


Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h2 health points and an attack power of a2. Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle.Vova's character has h1 health points and an attack power of a1. Also he has a large supply of healing potions, each of which increases his current amount of health points by c1 when Vova drinks a potion. All potions are identical to each other. It is guaranteed that c1 > a2.The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by a1) or drink a healing potion (it increases Vova's health by c1; Vova's health can exceed h1). Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by a2. The battle ends when Vova's (or Modcrab's) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova's attack.Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases.Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win.

The first line contains three integers h1, a1, c1 (1 ≤ h1, a1 ≤ 100, 2 ≤ c1 ≤ 100) — Vova's health, Vova's attack power and the healing power of a potion. The second line contains two integers h2, a2 (1 ≤ h2 ≤ 100, 1 ≤ a2 < c1) — the Modcrab's health and his attack power.

In the first line print one integer n denoting the minimum number of phases required to win the battle. Then print n lines. i-th line must be equal to HEAL if Vova drinks a potion in i-th phase, or STRIKE if he attacks the Modcrab. The strategy must be valid: Vova's character must not be defeated before slaying the Modcrab, and the monster's health must be 0 or lower after Vova's last action. If there are multiple optimal solutions, print any of them.

NoteIn the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win.In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left.

import core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,
	std.container, std.conv, std.datetime, std.functional, std.math, std.meta;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.parallelism, std.random, std.range, std.regex, std.stdio, std.string,
	std.traits, std.typecons, std.uni, std.variant;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
/// struct vector as c++ vector
struct Vec(T)
{
	private Array!T buf;
	alias buf this;
	this(this)
	{
		buf = buf.dup;
	}
	/// construct from length
	this(U)(U length)
			if (is(U == int) || is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint))
	{
		buf.length = length;
	}
	/// construct from length and default value
	this(U, X)(U length, X val)
			if (isImplicitlyConvertible!(X, T) || (is(U == int)
				|| is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint)))
	{
		buf.length = length;
		foreach (ref x; buf[])
		{
			x = val;
		}
	}
	/// construct from other array
	this(U)(U[] values...) if (isImplicitlyConvertible!(U, T))
	{
		buf = Array!(T)(values);
	}
	/// construct from other range
	this(Range)(Range r)
			if (isInputRange!Range && isImplicitlyConvertible!(ElementType!Range,
				T) && !is(Range == T[]))
	{
		buf = Array!(T)(r);
	}
	/// integer length
	int size() @property const
	{
		return cast(int) buf.length;
	}
}
///mmulo
enum mm = 10 ^^ 9 + 7, mm2 = mm + 2;
public
{
	pure nothrow
	{
		///lcm
		T lcm(T)(auto ref T a, auto ref T b)
		{
			return a / gcd(a, b) * b;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///BigInt greatest common divizor
		BigInt biggcd(BigInt a, BigInt b)
		{
			BigInt res = 1;
			while (b)
			{
				if ((a & 1) && (b & 1))
				{
					a -= b;
					a >>= 1;
				}
				else if (a & 1)
				{
					b >>= 1;
				}
				else if (b & 1)
				{
					a >>= 1;
				}
				else
				{
					res <<= 1;
					a >>= 1;
					b >>= 1;
				}
				if (a < b)
					swap(a, b);
			}
			return res * a;
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	///write an array
	void putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)
	{
		writefln("%(%s" ~ ch ~ "%)", a);
	}
	///write a matrix
	void putarr(X)(in X a)
			if (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))
	{
		writefln("%(%(%s %)\n%)", a);
	}
	///get an array
	bool getarr(X)(X a, in size_t n)
	{
		bool b = 1;
		foreach (ref i; a[0 .. n])
			b = input(&i);
		return b;
	}
	///read without format
	bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
	}
	///readln without format
	bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		return readf!(replicate(" %s", ptrs.length) ~ '\n')(ptrs) == ptrs.length;
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------

void main()
{
	int h1, a1, c1;
	read(h1, a1, c1);
	int h2, a2;
	read(h2, a2);
	string[] ans;
	while (h2 > 0)
	{
		if (a1 >= h2)
		{
			ans ~= "STRIKE";
			break;
		}
		else if (a2 >= h1)
		{
			ans ~= "HEAL";
			h1 += c1;
		}
		else
		{
			ans ~= "STRIKE";
			h2 -= a1;
		}
		h1 -= a2;
	}
	writeln(ans.length);
	foreach (s; ans)
	{
		writeln(s);
	}
}

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

void main() {
    int h1, a1, c1;
    int h2, a2;

    scan(h1, a1, c1);
    scan(h2, a2);

    auto cmd = ["STRIKE", "HEAL"];

    auto ans = new string[](0);

    while (h2 > 0) {
        if (h2 > a1 && h1 <= a2) {
            ans ~= cmd[1];
            h1 += c1;
        }
        else {
            ans ~= cmd[0];
            h2 -= a1;
        }

        h1 -= a2;
    }

    writeln(ans.length);
    foreach (ai ; ans) {
        writeln(ai);
    }
}

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

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


You are given an array $$$a_1, a_2, \dots, a_n$$$. You can perform operations on the array. In each operation you can choose an integer $$$i$$$ ($$$1 \le i < n$$$), and swap elements $$$a_i$$$ and $$$a_{i+1}$$$ of the array, if $$$a_i + a_{i+1}$$$ is odd.Determine whether it can be sorted in non-decreasing order using this operation any number of times.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. 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 the array. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print "Yes" or "No" depending on whether you can or can not sort the given array. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).

NoteIn the first test case, we can simply swap $$$31$$$ and $$$14$$$ ($$$31 + 14 = 45$$$ which is odd) and obtain the non-decreasing array $$$[1,6,14,31]$$$.In the second test case, the only way we could sort the array is by swapping $$$4$$$ and $$$2$$$, but this is impossible, since their sum $$$4 + 2 = 6$$$ is even.In the third test case, there is no way to make the array non-decreasing.In the fourth test case, the array is already non-decreasing.

import std.stdio, std.string, std.conv;
import std.algorithm.iteration;
import std.algorithm.searching;
import std.algorithm.mutation;
import std.range;
import std.typecons;
void solution(ref File input, ref File output) {
    auto t = input.readln.chomp.to!int;
    while (t-- > 0) {
        auto _ = input.readln;
        auto source = input.readln.chomp
            .split(' ')
            .map!(to!int);
        int max_e = -1, max_o = -1;
        foreach(item; source)
        {
            if (item % 2) {
                if (max_o > item)
                {
                    output.writeln("No");
                    goto end;
                } else
                {
                    max_o = item;
                }

            } else
            {
                if (max_e > item)
                {
                    output.writeln("No");
                    goto end;
                } else
                {
                    max_e = item;
                }

            }
        }
        output.writeln("Yes");
        end:
    }
}
void main()
{
    File input, output;
    debug(1) {
        input = File("input.txt", "r");
        output = File("output.txt", "w");
    } else {
        input = stdin;
        output = stdout;
    }
    solution(input, output);
}

void main() { runSolver(); }

void problem() {
  auto QN = scan!int;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto A = scan!int(N);

      int lastOdd = 1;
      int lastEven = 0;
      foreach(a; A) {
        if (a % 2 == 0) {
          if (lastOdd > a) return YESNO[false];
          lastOdd = a;
        } else {
          if (lastEven > a) return YESNO[false];
          lastEven = a;
        }
      }

      return YESNO[true];
    }

    foreach(i; 0..QN) {
      subSolve().writeln;
    }
  }

  outputForAtCoder(&solve);
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
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)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

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

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}

import std.stdio, std.string, std.conv;
import std.algorithm.iteration;
import std.algorithm.searching;
import std.algorithm.mutation;
import std.range;
import std.typecons;
void solution(ref File input, ref File output) {
    auto t = input.readln.chomp.to!int;
    while (t-- > 0) {
        auto _ = input.readln;
        auto source = input.readln.chomp
            .split(' ')
            .map!(to!int);
        int max_e = -1, max_o = -1;
        foreach(item; source)
        {
            if (item % 2) {
                if (max_o > item)
                {
                    output.writeln("No");
                    goto end;
                }
                if (max_o == -1)
                {
                    max_o = item;
                }

            } else
            {
                if (max_e > item)
                {
                    output.writeln("No");
                    goto end;
                }
                if (max_e == -1)
                {
                    max_e = item;
                }

            }
        }
        output.writeln("Yes");
        end:
    }
}
void main()
{
    File input, output;
    debug(1) {
        input = File("input.txt", "r");
        output = File("output.txt", "w");
    } else {
        input = stdin;
        output = stdout;
    }
    solution(input, output);
}


Tired of boring office work, Denis decided to open a fast food restaurant.On the first day he made $$$a$$$ portions of dumplings, $$$b$$$ portions of cranberry juice and $$$c$$$ pancakes with condensed milk.The peculiarity of Denis's restaurant is the procedure of ordering food. For each visitor Denis himself chooses a set of dishes that this visitor will receive. When doing so, Denis is guided by the following rules:  every visitor should receive at least one dish (dumplings, cranberry juice, pancakes with condensed milk are all considered to be dishes);  each visitor should receive no more than one portion of dumplings, no more than one portion of cranberry juice and no more than one pancake with condensed milk;  all visitors should receive different sets of dishes. What is the maximum number of visitors Denis can feed?

The first line contains an integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases to solve. Each of the remaining $$$t$$$ lines contains integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$0 \leq a, b, c \leq 10$$$) — the number of portions of dumplings, the number of portions of cranberry juice and the number of condensed milk pancakes Denis made.

For each test case print a single integer — the maximum number of visitors Denis can feed.

NoteIn the first test case of the example, Denis can feed the first visitor with dumplings, give the second a portion of cranberry juice, and give the third visitor a portion of cranberry juice and a pancake with a condensed milk.In the second test case of the example, the restaurant Denis is not very promising: he can serve no customers.In the third test case of the example, Denise can serve four visitors. The first guest will receive a full lunch of dumplings, a portion of cranberry juice and a pancake with condensed milk. The second visitor will get only dumplings. The third guest will receive a pancake with condensed milk, and the fourth guest will receive a pancake and a portion of dumplings. Please note that Denis hasn't used all of the prepared products, but is unable to serve more visitors.

module main;

import std.stdio : writeln;

struct IO {
    string readToken() {
        import std.range : empty, front, popFront, split;
        import std.stdio : readln;

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

    int readInt() {
        import std.conv : to;

        return readToken.to!int;
    }

    string[] tokens;
}

void main() {
    import core.bitop : popcnt;
    import std.algorithm : max;

    IO io;
    int T = io.readInt;
    while (T--) {
        int[3] count;
        for (int i = 0; i < 3; ++i) {
            count[i] = io.readInt;
        }
        int result = 0;
        for (int mask = 0; mask < 1 << 8; mask += 2) {
            bool ok = true;
            for (int i = 0; i < 3; ++i) {
                int c = count[i];
                for (int s = 0; s < 8; ++s) {
                    if ((s >> i & 1) && (mask >> s & 1)) {
                        c--;
                    }
                }
                ok &= c >= 0;
            }
            if (ok) {
                result = max(result, popcnt(mask));
            }
        }
        writeln(result);
    }
}

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

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

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

    while (t--) {
        int a, b, c;
        scan(a, b, c);
        auto ans = solve(a, b, c);
        writeln(ans);
    }
}

int solve(int a, int b, int c) {
    int res;

    foreach (comb ; 0 .. 1 << (1 << 3)) {
        auto x = new int[](3);

        foreach (i ; 0 .. 1 << 3) if (comb & 1 << i) {
            foreach (j ; 0 .. 3) if (i & 1 << j) {
                x[j]++;
            }
        }

        if (x[0] <= a && x[1] <= b && x[2] <= c) {
            chmax(res, comb.popcnt);
        }
    }

    res--;

    return res;
}

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

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

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

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto abc = RDA;
		abc.sort!"a > b"();
		foreach (ref e; abc)
		{
			if (e != 0)
			{
				++ans[ti];
				--e;
			}
		}
		foreach (i; 0..2)
		{
			foreach (j; i+1..3)
			{
				if (abc[i] != 0 && abc[j] != 0)
				{
					++ans[ti];
					--abc[i];
					--abc[j];
				}
			}
		}
		if (abc[0] != 0 && abc[1] != 0 && abc[2] != 0)
			++ans[ti];
	}

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


Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible. You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.The mex of a set S is a minimum possible non-negative integer that is not in S.

The first line contains two integers n and m (1 ≤ n, m ≤ 105). The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n), that describe the subarray a[li], a[li + 1], ..., a[ri].

In the first line print single integer — the maximum possible minimum mex. In the second line print n integers — the array a. All the elements in a should be between 0 and 109. It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109. If there are multiple solutions, print any of them.

NoteThe first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.

import core.bitop;
import core.checkedint;
import core.simd;
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.stdio;
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;
}

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

void main() {
    int n, m;
    while (read(&n, &m)) {
        int len = int.max;
        foreach (i; 0 .. m) {
            int left, right;
            read(&left, &right);
            left--;
            len = min(len, right - left);
        }
        writeln(len);
        foreach (i; 0 .. n)
            write(i % len, ' ');
        writeln();
    }
}


Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division.To improve his division skills, Oleg came up with $$$t$$$ pairs of integers $$$p_i$$$ and $$$q_i$$$ and for each pair decided to find the greatest integer $$$x_i$$$, such that:   $$$p_i$$$ is divisible by $$$x_i$$$;  $$$x_i$$$ is not divisible by $$$q_i$$$.  Oleg is really good at division and managed to find all the answers quickly, how about you?

The first line contains an integer $$$t$$$ ($$$1 \le t \le 50$$$) — the number of pairs. Each of the following $$$t$$$ lines contains two integers $$$p_i$$$ and $$$q_i$$$ ($$$1 \le p_i \le 10^{18}$$$; $$$2 \le q_i \le 10^{9}$$$) — the $$$i$$$-th pair of integers.

Print $$$t$$$ integers: the $$$i$$$-th integer is the largest $$$x_i$$$ such that $$$p_i$$$ is divisible by $$$x_i$$$, but $$$x_i$$$ is not divisible by $$$q_i$$$. One can show that there is always at least one value of $$$x_i$$$ satisfying the divisibility conditions for the given constraints.

NoteFor the first pair, where $$$p_1 = 10$$$ and $$$q_1 = 4$$$, the answer is $$$x_1 = 10$$$, since it is the greatest divisor of $$$10$$$ and $$$10$$$ is not divisible by $$$4$$$.For the second pair, where $$$p_2 = 12$$$ and $$$q_2 = 6$$$, note that   $$$12$$$ is not a valid $$$x_2$$$, since $$$12$$$ is divisible by $$$q_2 = 6$$$;  $$$6$$$ is not valid $$$x_2$$$ as well: $$$6$$$ is also divisible by $$$q_2 = 6$$$.  The next available divisor of $$$p_2 = 12$$$ is $$$4$$$, which is the answer, since $$$4$$$ is not divisible by $$$6$$$.

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

ll[] primes;

void play(){
    ll p, q;
    p = rd; q = rd;
    ll P = p, Q = q;

    // Base
    if(p % q != 0){
        writeln(p);
        return;
    }

    // Prime Factorize
    ll[] pfact;
    int[] cntp;
    foreach(prime; primes){
        int isin = 0;
        while(q % prime == 0 && q > 1){
            q /= prime;
            ++isin;
        }
        if(isin){
            pfact ~= prime;
            cntp ~= isin;
        }
    }
    if(q != 1){ pfact ~= q; cntp ~= 1; }
    show(pfact);

    ll mindiv = -1;
    foreach(i; 0.. pfact.length){
        ll prime = pfact[i];
        ll k = 1;
        while(p % prime == 0 && p > 1){
            p /= prime;
            k *= prime;
        }
        foreach(j; 1..cntp[i]){
            k /= prime;
        }
        show(k);
        if(mindiv == -1){
            mindiv = k;
        }else{
            mindiv = min(mindiv, k);
        }
        show(mindiv);
    }
    writeln(P/mindiv);
}

int main(){
    // Sieve
    const int SZ = 100000;
    ll[SZ+1] notprime;
    foreach(p; 2..1000){
        if(!notprime[p]){
            for(int div = p*p; div <= SZ; div += p){
                notprime[div] = 1;
            }
        }
    }
    foreach(i; 2..SZ){
        if(!notprime[i]){
            primes ~= i.to!long;
        }
    }
    long t = 1;
    t = rd;        // Toggle!
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }
alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, "x",  long, "y");
T max(T = long)(T a, T b){ return (a > b) ? a : b; }
T min(T = long)(T a, T b){ return (a < b) ? a : b; }

// a
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 A = readLong();
        const B = readLong();

        long ans = 1;
        if (A % B != 0) {
          chmax(ans, A);
        }

        long[] ps;
        long b = B;
        for (long p = 2; p^^2 <= b; ++p) {
          if (b % p == 0) {
            do {
              b /= p;
            } while (b % p == 0);
            ps ~= p;
          }
        }
        if (b > 1) {
          ps ~= b;
        }

        foreach (p; ps) {
          long a = A;
          for (; a % B == 0; a /= p) {}
          chmax(ans, a);
        }

        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

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

int [] divisors (int n)
{
	int [] res;
	for (int d = 2; d * d <= n; d++)
	{
		if (n % d == 0)
		{
			res ~= d;
			while (n % d == 0)
			{
				n /= d;
			}
		}
	}
	if (n > 1)
	{
		res ~= n;
	}
	return res;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		long p;
		int q;
		readf !(" %s %s") (p, q);
		auto d = divisors (q);

		long res = 1;

		void recur (long cur, int i)
		{
			if (cur % q != 0)
			{
				res = max (res, cur);
			}
			if (i >= d.length)
			{
				return;
			}
			recur (cur, i + 1);
			while (cur % d[i] == 0)
			{
				cur /= d[i];
				recur (cur, i + 1);
			}
		}

		recur (p, 0);
		writeln (res);
	}
}

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

ll[] primes;

void play(){
    ll p, q;
    p = rd; q = rd;
    ll P = p, Q = q;

    // Base
    if(p % q != 0){
        writeln(p);
        return;
    }

    // Prime Factorize
    ll[] pfact;
    foreach(prime; primes){
        bool isin = 0;
        while(q % prime == 0 && q > 1){
            q /= prime;
            isin = 1;
        }
        if(isin){
            pfact ~= prime;
        }
    }
    if(q != 1){ pfact ~= q; }
    show(pfact);

    ll mindiv = -1;
    foreach(ll prime; pfact){
        ll k = 1;
        while(p % prime == 0 && p > 1){
            p /= prime;
            k *= prime;
        }
        show(k);
        if(mindiv == -1){
            mindiv = k;
        }else{
            mindiv = min(mindiv, k);
        }
        show(mindiv);
    }
    writeln(P/mindiv);
}

int main(){
    // Sieve
    const int SZ = 100000;
    ll[SZ+1] notprime;
    foreach(p; 2..1000){
        if(!notprime[p]){
            for(int div = p*p; div <= SZ; div += p){
                notprime[div] = 1;
            }
        }
    }
    foreach(i; 2..SZ){
        if(!notprime[i]){
            primes ~= i.to!long;
        }
    }
    long t = 1;
    t = rd;        // Toggle!
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }
alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, "x",  long, "y");
T max(T = long)(T a, T b){ return (a > b) ? a : b; }
T min(T = long)(T a, T b){ return (a < b) ? a : b; }