Bandits appeared in the city! One of them is trying to catch as many citizens as he can.The city consists of $$$n$$$ squares connected by $$$n-1$$$ roads in such a way that it is possible to reach any square from any other square. The square number $$$1$$$ is the main square.After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square.At the moment when the bandit appeared on the main square there were $$$a_i$$$ citizens on the $$$i$$$-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square.The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught?

The first line contains a single integer $$$n$$$ — the number of squares in the city ($$$2 \le n \le 2\cdot10^5$$$). The second line contains $$$n-1$$$ integers $$$p_2, p_3 \dots p_n$$$ meaning that there is a one-way road from the square $$$p_i$$$ to the square $$$i$$$ ($$$1 \le p_i < i$$$).  The third line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ — the number of citizens on each square initially ($$$0 \le a_i \le 10^9$$$).

Print a single integer — the number of citizens the bandit will catch if both sides act optimally.

NoteIn the first example the citizens on the square $$$1$$$ can split into two groups $$$2 + 1$$$, so that the second and on the third squares will have $$$3$$$ citizens each.In the second example no matter how citizens act the bandit can catch at least $$$4$$$ citizens.

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

int[][] adj;
bool[] vis;
ll[] citizen;

tup dfs(int v){
    vis[v] = 1;
    ll leafs = 0, nodesum = 0;
    foreach(u; adj[v]){
        if(!vis[u]){
            auto res = dfs(u);
            nodesum += res.x;
            leafs += res.y;
        }
    }
    if(adj[v].length == 0){
        return tup(citizen[v-1], 1);
    }else{
        nodesum += citizen[v-1];
        ll dilute = nodesum/leafs + (nodesum % leafs != 0);
        citizen[v-1] = dilute;
        return tup(nodesum, leafs);
    }
}

void play(){
    int n;
    n = rd!int;
    adj = new int[][](n+1, 0);
    vis = new bool[](n+1);
    foreach(i; 2..n+1){
        adj[rd!int] ~= i;
    }
    citizen = rdarr;
    ll totsum = 0, leafs = 0;
    foreach(el; citizen){ totsum += el; }
    foreach(i; 2..n+1){
        if(adj[i].length == 0) ++leafs;
    }
    dfs(1);
    vis[] = 0;
    show(citizen);

    // Check leafs for max
    writeln(citizen.maxElement); }

int main(){
    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; }

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

int[][] adj;
bool[] vis;
ll[] citizen;
ll cap;

tup dfs(int v){
    vis[v] = 1;
    ll takeable = 0, leafs = 0;
    foreach(u; adj[v]){
        if(!vis[u]){
            auto res = dfs(u);
            takeable += res.x;
            leafs += res.y;
        }
    }
    if(adj[v].length == 0){
        return tup(cap - citizen[v-1], 1);
    }else{
        ll taken = min(takeable, citizen[v-1]);
        takeable -= taken;
        citizen[v-1] -= taken;
        if(citizen[v-1]){
            return tup(takeable, leafs);
        }else{
            ll add = (citizen[v-1]/leafs) + (citizen[v-1] % leafs != 0);
            if(add % leafs != 0){
                takeable += leafs - (add % leafs);
            }
            citizen[v-1] = add;
            return tup(takeable, leafs);
        }
    }
}

void dfssum(int v, ll summ){
    vis[v] = 1;
    foreach(u; adj[v]){
        if(!vis[u]){
            dfssum(v, summ + citizen[v-1]);
        }
    }
    if(adj[v].length == 0){
        citizen[v-1] += summ;
    }
}

void play(){
    int n;
    n = rd!int;
    adj = new int[][](n+1, 0);
    vis = new bool[](n+1);
    foreach(i; 2..n+1){
        adj[rd!int] ~= i;
    }
    citizen = rdarr;
    ll totsum = 0, leafs = 0;
    foreach(el; citizen){ totsum += el; }
    foreach(i; 2..n+1){
        if(adj[i].length == 0) ++leafs;
    }
    cap = totsum/leafs + (totsum % leafs != 0);
    dfs(1);
    dfssum(1, 0);

    ll maxsum = cap;
    // Check leafs for max
    foreach(i; 2..n+1){
        if(adj[i].length == 0){
            maxsum = max(cap, maxsum);
        }
    }
    writeln(maxsum);
}

int main(){
    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; }

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

int[][] adj;
bool[] vis;
ll[] citizen;

tup dfs(int v){
    vis[v] = 1;
    ll leafs = 0, nodesum = 0, maxnode = 0;
    foreach(u; adj[v]){
        if(!vis[u]){
            auto res = dfs(u);
            nodesum += res.x;
            maxnode = max(res.x, maxnode);
            leafs += res.y;
        }
    }
    if(adj[v].length == 0){
        return tup(citizen[v-1], 1);
    }else{
        nodesum += citizen[v-1];
        ll dilute = nodesum/leafs + (nodesum % leafs != 0);
        return tup(citizen[v-1] = max(dilute, maxnode), leafs);
    }
}

void play(){
    int n;
    n = rd!int;
    adj = new int[][](n+1, 0);
    vis = new bool[](n+1);
    foreach(i; 2..n+1){
        adj[rd!int] ~= i;
    }
    citizen = rdarr;
    ll totsum = 0, leafs = 0;
    foreach(el; citizen){ totsum += el; }
    foreach(i; 2..n+1){
        if(adj[i].length == 0) ++leafs;
    }
    dfs(1);
    vis[] = 0;
    show(citizen);

    // Check leafs for max
    writeln(citizen.maxElement);
}

int main(){
    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; }

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

int[][] adj;
bool[] vis;
ll[] citizen;
ll cap;

tup dfs(int v){
    vis[v] = 1;
    ll takeable = 0, leafs = 0;
    foreach(u; adj[v]){
        if(!vis[u]){
            auto res = dfs(u);
            takeable += res.x;
            leafs += res.y;
        }
    }
    if(adj[v].length == 0){
        return tup(cap - citizen[v-1], 1);
    }else{
        ll taken = min(takeable, citizen[v-1]);
        takeable -= taken;
        citizen[v-1] -= taken;
        if(citizen[v-1]){
            return tup(takeable, leafs);
        }else{
            ll add = (citizen[v-1]/leafs) + (citizen[v-1] % leafs != 0);
            if(add % leafs != 0){
                takeable += leafs - (add % leafs);
            }
            citizen[v-1] = add;
            return tup(takeable, leafs);
        }
    }
}

void dfssum(int v, ll summ){
    vis[v] = 1;
    foreach(u; adj[v]){
        if(!vis[u]){
            dfssum(u, summ + citizen[v-1]);
        }
    }
    if(adj[v].length == 0){
        citizen[v-1] += summ;
    }
}

void play(){
    int n;
    n = rd!int;
    adj = new int[][](n+1, 0);
    vis = new bool[](n+1);
    foreach(i; 2..n+1){
        adj[rd!int] ~= i;
    }
    citizen = rdarr;
    ll totsum = 0, leafs = 0;
    foreach(el; citizen){ totsum += el; }
    foreach(i; 2..n+1){
        if(adj[i].length == 0) ++leafs;
    }
    cap = totsum/leafs + (totsum % leafs != 0);
    dfs(1);
    vis[] = 0;
    /* dfssum(1, 0); */
    show(citizen);

    ll maxsum = cap;
    // Check leafs for max
    foreach(i; 1..n+1){
        if(adj[i].length == 0){
            maxsum = max(citizen[i-1], maxsum);
        }else if(citizen[i-1]){
            maxsum = max(cap + citizen[i-1], maxsum);
        }
    }
    writeln(maxsum);
}

int main(){
    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; }

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

int[][] adj;
bool[] vis;
ll[] citizen;

tup dfs(int v){
    vis[v] = 1;
    ll leafs = 0, nodesum = 0, maxnode = 0;
    foreach(u; adj[v]){
        if(!vis[u]){
            auto res = dfs(u);
            nodesum += res.x;
            maxnode = max(res.x, maxnode);
            leafs += res.y;
        }
    }
    if(adj[v].length == 0){
        return tup(citizen[v-1], 1);
    }else{
        nodesum += citizen[v-1];
        ll dilute = nodesum/leafs + (nodesum % leafs != 0);
        citizen[v-1] = max(dilute, maxnode);
        return tup(nodesum, leafs);
    }
}

void play(){
    int n;
    n = rd!int;
    adj = new int[][](n+1, 0);
    vis = new bool[](n+1);
    foreach(i; 2..n+1){
        adj[rd!int] ~= i;
    }
    citizen = rdarr;
    ll totsum = 0, leafs = 0;
    foreach(el; citizen){ totsum += el; }
    foreach(i; 2..n+1){
        if(adj[i].length == 0) ++leafs;
    }
    dfs(1);
    vis[] = 0;
    show(citizen);

    // Check leafs for max
    writeln(citizen.maxElement); }

int main(){
    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; }


You are given a tree (a connected undirected graph without cycles) of $$$n$$$ vertices. Each of the $$$n - 1$$$ edges of the tree is colored in either black or red.You are also given an integer $$$k$$$. Consider sequences of $$$k$$$ vertices. Let's call a sequence $$$[a_1, a_2, \ldots, a_k]$$$ good if it satisfies the following criterion:  We will walk a path (possibly visiting same edge/vertex multiple times) on the tree, starting from $$$a_1$$$ and ending at $$$a_k$$$.  Start at $$$a_1$$$, then go to $$$a_2$$$ using the shortest path between $$$a_1$$$ and $$$a_2$$$, then go to $$$a_3$$$ in a similar way, and so on, until you travel the shortest path between $$$a_{k-1}$$$ and $$$a_k$$$. If you walked over at least one black edge during this process, then the sequence is good.   Consider the tree on the picture. If $$$k=3$$$ then the following sequences are good: $$$[1, 4, 7]$$$, $$$[5, 5, 3]$$$ and $$$[2, 3, 7]$$$. The following sequences are not good: $$$[1, 4, 6]$$$, $$$[5, 5, 5]$$$, $$$[3, 7, 3]$$$.There are $$$n^k$$$ sequences of vertices, count how many of them are good. Since this number can be quite large, print it modulo $$$10^9+7$$$.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^5$$$, $$$2 \le k \le 100$$$), the size of the tree and the length of the vertex sequence. Each of the next $$$n - 1$$$ lines contains three integers $$$u_i$$$, $$$v_i$$$ and $$$x_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$x_i \in \{0, 1\}$$$), where $$$u_i$$$ and $$$v_i$$$ denote the endpoints of the corresponding edge and $$$x_i$$$ is the color of this edge ($$$0$$$ denotes red edge and $$$1$$$ denotes black edge).

Print the number of good sequences modulo $$$10^9 + 7$$$.

NoteIn the first example, all sequences ($$$4^4$$$) of length $$$4$$$ except the following are good:   $$$[1, 1, 1, 1]$$$ $$$[2, 2, 2, 2]$$$ $$$[3, 3, 3, 3]$$$ $$$[4, 4, 4, 4]$$$ In the second example, all edges are red, hence there aren't any good sequences.

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;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto uf = new UnionFind(N);
    foreach (_; 0..N-1) {
        s = readln.split.map!(to!int);
        if (s[2] == 0) {
            uf.unite(s[0]-1, s[1]-1);
        }
    }

    long ans = powmod(N, K, MOD);

    foreach (i; 0..N) {
        if (uf.find(i) != i) continue;
        long x = -uf.table[i];
        ans -= powmod(x, K, MOD);
        ans %= MOD;
    }

    ans = (ans + MOD) % MOD;
    ans.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;
    }
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

class DisjointSet {
  private:
    int [] p, h, s;
    int n;
  public:
  this (int _n) {
    n = _n;
    p = iota (0, n).array;
    h = new int[n];
    s = uninitializedArray!(int[])(n);
    s[] = 1;
  }
  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;
        s[j] = s[i] + s[j];
      } else if (h[i] > h[j]) {
        p[j] = i;
        s[i] = s[i] + s[j];
      } else {
        p[i] = j;
        ++h[j];
        s[j] = s[i] + s[j];
      }
    }
  }
}

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

struct IntM {
  enum q = 1_000_000_007;
  int v;
  this (int m) pure nothrow @nogc {
    v = m % q;
    if (v < 0) {
      v += q;
    }
  }
  IntM opAssign (int m) pure nothrow @nogc {
    v = m % q;
    if (v < 0) {
      v += q;
    }
    return this;
  }
  IntM opUnary (string op : "-")() const pure nothrow @nogc {
    return IntM ((q - v) % q);
  }
  ref IntM opOpAssign (string op : "+")(in IntM rhs) pure nothrow @nogc {
    v += rhs.v;
    v %= q;
    return this;
  }
  ref IntM opOpAssign (string op : "-")(in IntM rhs) pure nothrow @nogc {
    v -= rhs.v;
    v %= q;
    return this;
  }
  ref IntM opOpAssign (string op : "*")(in IntM rhs) pure nothrow @nogc {
    v = ((v.to!(long)) * rhs.v.to!(long)) % q;
    return this;
  }
  IntM opBinary (string op : "+")(in IntM rhs) const pure nothrow @nogc {
    return IntM ( (v + rhs.v) % q);
  }
  IntM opBinary (string op : "-")(in IntM rhs) const pure nothrow @nogc {
    return IntM ( (v - rhs.v) % q);
  }
  IntM opBinary (string op : "*")(in IntM rhs) const pure nothrow @nogc {
    return IntM (((v.to!(long)) * rhs.v.to!(long)) % q);
  }
  IntM opBinary (string op : "^^")(in int rhs) const pure nothrow @nogc {
    IntM a = 1, b = this;
    int p = rhs;
    while (p > 0) {
      //a * (b ^ p) == x ^ rhs
      if (p & 1) {
        a *= b;
      }
      b *= b;
      p >>>= 1;
    }
    return a;
  }
  IntM opBinary (string op)(in int v) const pure nothrow @nogc if (op == "+" || op == "-" || op == "*") {
    mixin ("return this " ~ op ~ " IntM(v);");
  }
  string toString() const pure nothrow { return ((v < 0) ? v + q : v).text; }
}

void main() {
  auto r = new InputReader;
  immutable n = r.next!uint;
  immutable k = r.next!uint;
  auto ds = new DisjointSet (n);
  foreach (edge; 1 .. n) {
    immutable i = r.next!uint - 1;
    immutable j = r.next!uint - 1;
    immutable c = r.next!uint;
    if (c == 0) {
      ds.merge (i, j);
    }
  }
  int[] x;
  foreach (i; 0 .. n) {
    if (ds.findSet (i) == i) {
      x ~= ds.s[i];
    }
  }
  immutable m = x.length.to!int;
  IntM s;
  foreach (i; x) {
    auto c = IntM (i);
    s += c ^^ k;
  }
  IntM res = IntM (n) ^^ k;
  res -= s;
  write (res);
}


Suppose you have a special $$$x$$$-$$$y$$$-counter. This counter can store some value as a decimal number; at first, the counter has value $$$0$$$. The counter performs the following algorithm: it prints its lowest digit and, after that, adds either $$$x$$$ or $$$y$$$ to its value. So all sequences this counter generates are starting from $$$0$$$. For example, a $$$4$$$-$$$2$$$-counter can act as follows:  it prints $$$0$$$, and adds $$$4$$$ to its value, so the current value is $$$4$$$, and the output is $$$0$$$;  it prints $$$4$$$, and adds $$$4$$$ to its value, so the current value is $$$8$$$, and the output is $$$04$$$;  it prints $$$8$$$, and adds $$$4$$$ to its value, so the current value is $$$12$$$, and the output is $$$048$$$;  it prints $$$2$$$, and adds $$$2$$$ to its value, so the current value is $$$14$$$, and the output is $$$0482$$$;  it prints $$$4$$$, and adds $$$4$$$ to its value, so the current value is $$$18$$$, and the output is $$$04824$$$. This is only one of the possible outputs; for example, the same counter could generate $$$0246802468024$$$ as the output, if we chose to add $$$2$$$ during each step.You wrote down a printed sequence from one of such $$$x$$$-$$$y$$$-counters. But the sequence was corrupted and several elements from the sequence could be erased.Now you'd like to recover data you've lost, but you don't even know the type of the counter you used. You have a decimal string $$$s$$$ — the remaining data of the sequence. For all $$$0 \le x, y < 10$$$, calculate the minimum number of digits you have to insert in the string $$$s$$$ to make it a possible output of the $$$x$$$-$$$y$$$-counter. Note that you can't change the order of digits in string $$$s$$$ or erase any of them; only insertions are allowed.

The first line contains a single string $$$s$$$ ($$$1 \le |s| \le 2 \cdot 10^6$$$, $$$s_i \in \{\text{0} - \text{9}\}$$$) — the remaining data you have. It's guaranteed that $$$s_1 = 0$$$.

Print a $$$10 \times 10$$$ matrix, where the $$$j$$$-th integer ($$$0$$$-indexed) on the $$$i$$$-th line ($$$0$$$-indexed too) is equal to the minimum number of digits you have to insert in the string $$$s$$$ to make it a possible output of the $$$i$$$-$$$j$$$-counter, or $$$-1$$$ if there is no way to do so.

NoteLet's take, for example, $$$4$$$-$$$3$$$-counter. One of the possible outcomes the counter could print is $$$0(4)8(1)4(7)0$$$ (lost elements are in the brackets).One of the possible outcomes a $$$2$$$-$$$3$$$-counter could print is $$$0(35)8(1)4(7)0$$$.The $$$6$$$-$$$8$$$-counter could print exactly the string $$$0840$$$.

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto s = RD!string;
	auto memo = new long[][][](10, 10, 10);
	foreach (i; 0..10)
	{
		foreach (j; 0..10)
		{
			foreach (k; 0..10)
			{
				long cnt = 100;
				/*if (j != 0)
					if (i % j == 0)
						cnt = min(i / j, cnt);
				if (k != 0)
					if (i % k == 0)
						cnt = min(i / k, cnt);*/

				foreach (l; 0..11)
				{
					foreach (n; 0..11)
					{
						if (l + n == 0) continue;
						if ((j*l + k*n) % 10 == i)
							cnt = min(l+n, cnt);
					}
				}
				memo[i][j][k] = cnt;
			}
		}
	}

	long[int] set;
	long last;
	foreach (i; 1..s.length)
	{
		auto x = [s[i]].to!long;
		auto y = (10 + x - last) % 10;
		debug writeln(x, "-", last, "=", y);
		++set[cast(int)y];
		last = x;
	}

	debug writeln(memo);
	debug writeln(set);

	auto keys = set.keys;
	auto ans = new long[][](10, 10);
	foreach (i; 0..10)
	{
		foreach (j; i..10)
		{
			long cnt;
			foreach (key; keys)
			{
				if (memo[key][i][j] == 100)
				{
					cnt = -1;
					break;
				}
				cnt += (memo[key][i][j] - 1) * set[key];
			}
			ans[i][j] = cnt;
			ans[j][i] = cnt;
		}
	}

	foreach (i; 0..10)
	{
		ans[i].map!(to!string).join(" ").writeln;
	}
	stdout.flush();
	debug readln();
}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto s = RD!string;
	auto memo = new long[][][](10, 10, 10);
	foreach (i; 0..10)
	{
		foreach (j; 0..10)
		{
			foreach (k; 0..10)
			{
				long cnt = 11;
				/*if (j != 0)
					if (i % j == 0)
						cnt = min(i / j, cnt);
				if (k != 0)
					if (i % k == 0)
						cnt = min(i / k, cnt);*/

				foreach (l; 0..10)
				{
					foreach (n; 0..10)
					{
						if ((j*l + k*n) % 10 == i)
							cnt = min(l+n, cnt);
					}
				}
				memo[i][j][k] = cnt;
			}
		}
	}

	long[int] set;
	long last;
	foreach (i; 1..s.length)
	{
		auto x = [s[i]].to!long;
		auto y = (10 + x - last) % 10;
		debug writeln(x, "-", last, "=", y);
		++set[cast(int)y];
		last = x;
	}

	debug writeln(memo);
	debug writeln(set);

	auto keys = set.keys;
	auto ans = new long[][](10, 10);
	foreach (i; 0..10)
	{
		foreach (j; i..10)
		{
			long cnt;
			foreach (key; keys)
			{
				if (memo[key][i][j] == 11)
				{
					cnt = -1;
					break;
				}
				cnt += (memo[key][i][j] - 1) * set[key];
			}
			ans[i][j] = cnt;
			ans[j][i] = cnt;
		}
	}

	foreach (i; 0..10)
	{
		ans[i].map!(to!string).join(" ").writeln;
	}
	stdout.flush();
	debug readln();
}


You are given an array $$$s$$$ consisting of $$$n$$$ integers.You have to find any array $$$t$$$ of length $$$k$$$ such that you can cut out maximum number of copies of array $$$t$$$ from array $$$s$$$.Cutting out the copy of $$$t$$$ means that for each element $$$t_i$$$ of array $$$t$$$ you have to find $$$t_i$$$ in $$$s$$$ and remove it from $$$s$$$. If for some $$$t_i$$$ you cannot find such element in $$$s$$$, then you cannot cut out one more copy of $$$t$$$. The both arrays can contain duplicate elements.For example, if $$$s = [1, 2, 3, 2, 4, 3, 1]$$$ and $$$k = 3$$$ then one of the possible answers is $$$t = [1, 2, 3]$$$. This array $$$t$$$ can be cut out $$$2$$$ times.   To cut out the first copy of $$$t$$$ you can use the elements $$$[1, \underline{\textbf{2}}, 3, 2, 4, \underline{\textbf{3}}, \underline{\textbf{1}}]$$$ (use the highlighted elements). After cutting out the first copy of $$$t$$$ the array $$$s$$$ can look like $$$[1, 3, 2, 4]$$$.  To cut out the second copy of $$$t$$$ you can use the elements $$$[\underline{\textbf{1}}, \underline{\textbf{3}}, \underline{\textbf{2}}, 4]$$$. After cutting out the second copy of $$$t$$$ the array $$$s$$$ will be $$$[4]$$$. Your task is to find such array $$$t$$$ that you can cut out the copy of $$$t$$$ from $$$s$$$ maximum number of times. If there are multiple answers, you may choose any of them.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$s$$$ and the desired number of elements in $$$t$$$, respectively. The second line of the input contains exactly $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$1 \le s_i \le 2 \cdot 10^5$$$).

Print $$$k$$$ integers — the elements of array $$$t$$$ such that you can cut out maximum possible number of copies of this array from $$$s$$$. If there are multiple answers, print any of them. The required array $$$t$$$ can contain duplicate elements. All the elements of $$$t$$$ ($$$t_1, t_2, \dots, t_k$$$) should satisfy the following condition: $$$1 \le t_i \le 2 \cdot 10^5$$$.

NoteThe first example is described in the problem statement.In the second example the only answer is $$$[7, 3, 1, 3]$$$ and any its permutations. It can be shown that you cannot choose any other array such that the maximum number of copies you can cut out would be equal to $$$2$$$.In the third example the array $$$t$$$ can be cut out $$$5$$$ times.

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

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

    auto arr = readln.chomp.split.map!(to!int).array.sort().group().array.sort!((t1, t2) => t1[1] > t2[1]).array;

    debug { arr.writeln; }

    bool f(int m, ref int[] ans) {
        ans = [];
        foreach (t; arr) {
            auto r = t[1] / m;
            foreach (_; 0 .. r) if (ans.length < k) ans ~= t[0];
        }

        return ans.length == k;
    }

    int[] ans;
    int le = 1, r = n / k;
    while (le < r) {
        auto m = (le + r) / 2 + 1;
        if (f(m, ans)) le = m;
        else r = m-1;
    }

    f(le, ans);
    ans.writefln!("%(%s %)");
}

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

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

    auto arr = readln.chomp.split.map!(to!int).array.sort().group().array.sort!((t1, t2) => t1[1] > t2[1]).array;

    debug { arr.writeln; }

    bool f(int m, ref int[] ans) {
        ans = [];
        foreach (t; arr) {
            auto r = t[1] / m;
            foreach (_; 0 .. r) if (ans.length < k) ans ~= t[0];
        }

        return ans.length == k;
    }

    int[] ans;
    int le = 1, r = n / k;
    while (le < r) {
        auto m = (le + r) / 2 + 1;
        if (f(m, ans)) le = m;
        else r = m-1;
    }

    f(le, ans);
    ans.writeln; //writefln!("%(%s %)");
}

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

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

    auto arr = readln.chomp.split.map!(to!int).array.sort().group().array.sort!((t1, t2) => t1[1] > t2[1]).array;

    debug { arr.writeln; }

    bool f(int m, ref int[] ans) {
        foreach (t; arr) {
            auto r = t[1] / m;
            foreach (_; 0 .. r) if (ans.length < k) ans ~= t[0];
        }

        return ans.length == k;
    }

    int[] ans;
    int le = 1, r = n / k;
    while (le < r) {
        auto m = (le + r) / 2 + 1;
        if (f(m, ans)) le = m;
        else r = m-1;
    }

    f(le, ans);
    ans.writefln!("%(%s %)");
}

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

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

    auto arr = readln.chomp.split.map!(to!int).array.sort().group().array.sort!((t1, t2) => t1[1] > t2[1]).array;

    debug { arr.writeln; }

    bool f(int m, ref int[] ans) {
        foreach (t; arr) {
            auto r = t[1] / m;
            foreach (_; 0 .. r) if (ans.length < k) ans ~= t[0];
        }

        return ans.length == k;
    }

    int[] ans;
    int le = 0, r = n / k;
    while (le < r) {
        auto m = (le + r) / 2 + 1;
        if (f(m, ans)) le = m;
        else r = m-1;
    }

    f(le, ans);
    ans.writefln!("%(%s %)");
}


You are given a connected weighted graph with n vertices and m edges. The graph doesn't contain loops nor multiple edges. Consider some edge with id i. Let's determine for this edge the maximum integer weight we can give to it so that it is contained in all minimum spanning trees of the graph if we don't change the other weights.You are to determine this maximum weight described above for each edge. You should calculate the answer for each edge independently, it means there can't be two edges with changed weights at the same time.

The first line contains two integers n and m (2 ≤ n ≤ 2·105, n - 1 ≤ m ≤ 2·105), where n and m are the number of vertices and the number of edges in the graph, respectively. Each of the next m lines contains three integers u, v and c (1 ≤ v, u ≤ n, v ≠ u, 1 ≤ c ≤ 109) meaning that there is an edge between vertices u and v with weight c.

Print the answer for each edge in the order the edges are given in the input. If an edge is contained in every minimum spanning tree with any weight, print -1 as the answer.

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

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

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

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

int root(int[] uf, int u) {
  return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool connect(int[] uf, int u, int v) {
  u = uf.root(u);
  v = uf.root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}

enum E = 18;
enum INF = 10^^9 + 10;

int N, M;
int[] A, B, C;

bool[] on;
int[][] G;
int[][] par;
int[] pari;
int[] dep;

void dfs(int u, int p, int pi) {
  par[0][u] = p;
  pari[u] = pi;
  dep[u] = (p == -1) ? 0 : (dep[p] + 1);
  foreach (i; G[u]) {
    const v = A[i] ^ B[i] ^ u;
    if (v != p) {
      dfs(v, u, i);
    }
  }
}

int[] ans;
int[][] adds, rems;

alias Multiset = RedBlackTree!(int, "a < b", true);
Multiset solve(int u, int p, int pi) {
  auto ret = new Multiset;
  foreach (i; G[u]) {
    const v = A[i] ^ B[i] ^ u;
    if (v != p) {
      auto res = solve(v, u, i);
      if (ret.length < res.length) {
        swap(ret, res);
      }
      foreach (c; res) {
        ret.insert(c);
      }
    }
  }
  foreach (i; adds[u]) {
    ret.insert(C[i]);
  }
  foreach (i; rems[u]) {
    ret.removeKey(C[i]);
    ret.removeKey(C[i]);
  }
  if (pi != -1) {
    if (!ret.empty) {
      chmin(ans[pi], ret.front - 1);
    }
  }
  return ret;
}

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

      alias Entry = Tuple!(int, "c", int, "i");
      auto es = new Entry[M];
      foreach (i; 0 .. M) {
        es[i] = Entry(C[i], i);
      }
      es.sort;
      auto uf = new int[N];
      uf[] = -1;
      on = new bool[M];
      foreach (ref e; es) {
        const i = e.i;
        on[i] = uf.connect(A[i], B[i]);
      }
      debug {
        writeln("on = ", on);
      }
      assert(on.count(true) == N - 1);

      G = new int[][N];
      foreach (i; 0 .. M) {
        if (on[i]) {
          G[A[i]] ~= i;
          G[B[i]] ~= i;
        }
      }
      par = new int[][](E, N);
      pari = new int[N];
      dep = new int[N];
      const rt = 0;
      dfs(rt, -1, -1);
      par[0][rt] = rt;
      auto mxs = new int[][](E, N);
      foreach (u; 0 .. N) {
        mxs[0][u] = (pari[u] == -1) ? -INF : C[pari[u]];
      }
      foreach (e; 1 .. E) {
        foreach (u; 0 .. N) {
          par[e][u] = par[e - 1][par[e - 1][u]];
          mxs[e][u] = max(mxs[e - 1][u], mxs[e - 1][par[e - 1][u]]);
        }
      }

      ans = new int[M];
      ans[] = INF;
      adds = new int[][N];
      rems = new int[][N];
      foreach (i; 0 .. M) {
        if (!on[i]) {
          int u = A[i], v = B[i];
          int mx = -INF;
          foreach_reverse (e; 0 .. E) {
            if (dep[u] - (1 << e) >= dep[v]) {
              chmax(mx, mxs[e][u]);
              u = par[e][u];
            }
            if (dep[v] - (1 << e) >= dep[u]) {
              chmax(mx, mxs[e][v]);
              v = par[e][v];
            }
          }
          foreach_reverse (e; 0 .. E) {
            if (par[e][u] != par[e][v]) {
              chmax(mx, mxs[e][u]);
              chmax(mx, mxs[e][v]);
              u = par[e][u];
              v = par[e][v];
            }
          }
          if (u != v) {
            chmax(mx, mxs[0][u]);
            chmax(mx, mxs[0][v]);
            u = par[0][u];
            v = par[0][v];
          }
          debug {
            writeln(i, ": ", A[i], " ", B[i], " ", u, "; ", mx);
          }
          chmin(ans[i], mx - 1);
          adds[A[i]] ~= i;
          adds[B[i]] ~= i;
          rems[u] ~= i;
        }
      }
      solve(rt, -1, -1);

      foreach (i; 0 .. M) {
        if (i > 0) write(" ");
        write((ans[i] >= INF) ? -1 : ans[i]);
      }
      writeln;
    }
  } catch (EOFException e) {
  }
}

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

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

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

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

int root(int[] uf, int u) {
  return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool connect(int[] uf, int u, int v) {
  u = uf.root(u);
  v = uf.root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}

enum E = 18;
enum INF = 10^^9 + 10;

int N, M;
int[] A, B, C;

bool[] on;
int[][] G;
int[][] par;
int[] pari;
int[] dep;

void dfs(int u, int p, int pi) {
  par[0][u] = p;
  pari[u] = pi;
  dep[u] = (p == -1) ? 0 : (dep[p] + 1);
  foreach (i; G[u]) {
    const v = A[i] ^ B[i] ^ u;
    if (v != p) {
      dfs(v, u, i);
    }
  }
}

int[] ans;
int[][] adds, rems;

alias Multiset = RedBlackTree!(int, "a < b", true);
Multiset solve(int u, int p, int pi) {
  auto ret = new Multiset;
  foreach (i; G[u]) {
    const v = A[i] ^ B[i] ^ u;
    if (v != p) {
      auto res = solve(v, u, i);
      if (ret.length < res.length) {
        swap(ret, res);
      }
      foreach (c; res) {
        ret.insert(c);
      }
    }
  }
  foreach (i; adds[u]) {
    ret.insert(C[i]);
  }
  foreach (i; rems[u]) {
    ret.removeKey(C[i]);
    ret.removeKey(C[i]);
  }
  if (pi != -1) {
    if (!ret.empty) {
      chmin(ans[pi], ret.front - 1);
    }
  }
  return ret;
}

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

      alias Entry = Tuple!(int, "c", int, "i");
      auto es = new Entry[M];
      foreach (i; 0 .. M) {
        es[i] = Entry(C[i], i);
      }
      es.sort;
      auto uf = new int[N];
      uf[] = -1;
      on = new bool[M];
      foreach (ref e; es) {
        const i = e.i;
        on[i] = uf.connect(A[i], B[i]);
      }
      debug {
        writeln("on = ", on);
      }
      assert(on.count(true) == N - 1);

      G = new int[][N];
      foreach (i; 0 .. M) {
        if (on[i]) {
          G[A[i]] ~= i;
          G[B[i]] ~= i;
        }
      }
      par = new int[][](E, N);
      pari = new int[N];
      dep = new int[N];
      const rt = 0;
      dfs(rt, -1, -1);
      par[0][rt] = rt;
      auto mn = new int[][](E, N);
      foreach (u; 0 .. N) {
        mn[0][u] = (pari[u] == -1) ? INF : C[pari[u]];
      }
      foreach (e; 1 .. E) {
        foreach (u; 0 .. N) {
          par[e][u] = par[e - 1][par[e - 1][u]];
          mn[e][u] = min(mn[e - 1][u], mn[e - 1][par[e - 1][u]]);
        }
      }

      ans = new int[M];
      ans[] = INF;
      adds = new int[][N];
      rems = new int[][N];
      foreach (i; 0 .. M) {
        if (!on[i]) {
          int u = A[i], v = B[i];
          foreach_reverse (e; 0 .. E) {
            if (dep[u] - (1 << e) >= dep[v]) {
              chmin(ans[i], mn[e][u] - 1);
              u = par[e][u];
            }
            if (dep[v] - (1 << e) >= dep[u]) {
              chmin(ans[i], mn[e][v] - 1);
              v = par[e][v];
            }
          }
          foreach_reverse (e; 0 .. E) {
            if (par[e][u] != par[e][v]) {
              chmin(ans[i], mn[e][u] - 1);
              chmin(ans[i], mn[e][v] - 1);
              u = par[e][u];
              v = par[e][v];
            }
          }
          if (u != v) {
            chmin(ans[i], mn[0][u] - 1);
            chmin(ans[i], mn[0][v] - 1);
            u = par[0][u];
            v = par[0][v];
          }
          debug {
            writeln(i, ": ", A[i], " ", B[i], " ", u);
          }
          adds[A[i]] ~= i;
          adds[B[i]] ~= i;
          rems[u] ~= i;
        }
      }
      solve(rt, -1, -1);

      foreach (i; 0 .. M) {
        if (i > 0) write(" ");
        write((ans[i] >= INF) ? -1 : ans[i]);
      }
      writeln;
    }
  } catch (EOFException e) {
  }
}


Polycarp is sad — New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland!For example, if you provide $$$3$$$ red, $$$3$$$ green and $$$3$$$ blue lamps, the resulting garland can look like this: "RGBRBGBGR" ("RGB" being the red, green and blue color, respectively). Note that it's ok to have lamps of the same color on the ends of the garland.However, if you provide, say, $$$1$$$ red, $$$10$$$ green and $$$2$$$ blue lamps then the store workers won't be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided.So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of sets of lamps Polycarp has bought. Each of the next $$$t$$$ lines contains three integers $$$r$$$, $$$g$$$ and $$$b$$$ ($$$1 \le r, g, b \le 10^9$$$) — the number of red, green and blue lamps in the set, respectively.

Print $$$t$$$ lines — for each set of lamps print "Yes" if the store workers can build a garland from them and "No" otherwise.

NoteThe first two sets are desribed in the statement.The third set produces garland "RBRG", for example.

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;
    while (T--) {
        auto s = readln.split.map!(to!int).array;
        s.sort();
        auto a = s[0];
        auto b = s[1];
        auto c = s[2];
        if (c <= a + b + 1) {
            writeln("Yes");
        } else {
            writeln("No");
        }
    }
}

void main() {
	auto t = ri;
	foreach(i; 0..t) {
		auto ip = readAs!(long[]).sort.array;
		if(ip[2] > ip[0] + ip[1] + 1) writeln("No");
		else writeln("Yes");
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

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;
  auto nt = r.next!uint;
  foreach (tid; 0 .. nt) {
    auto a = r.nextA!ulong(3);
    sort (a);
    auto s = sum (a);
    long m = (s + 1) / 2;
    if (a[2] > m) {
      writeln ("No");
    } else {
      writeln ("Yes");
    }
  }
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
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(){
	foreach(_; 0 .. rint){
		long a = rlong, b = rlong, c = rlong;
		long n = a + b + c;
		long m = (n + 1) / 2;
		if(a > m || b > m || c > m) "No".writeln;
		else "Yes".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; }
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 t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto r = RD!int;
		auto g = RD!int;
		auto b = RD!int;
		long[] arr = [r, g, b];
		arr.sort();
		ans[ti] = arr[2] <= (arr.sum+1)/2;
	}

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

void main() {
	auto t = ri;
	foreach(i; 0..t) {
		auto ip = readAs!(int[]), r = ip[0], g = ip[1], b = ip[2];
		if(r > (g + b) || g > (r + b) || b > (r + g)) writeln("No");
		else writeln("Yes");
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

void main() {
	auto t = ri;
	foreach(i; 0..t) {
		auto ip = readAs!(int[]), r = ip[0], g = ip[1], b = ip[2];
		if(r > (g + b) && g > (r + b) && b > (r + g)) writeln("No");
		else writeln("Yes");
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

void main() {
	auto t = ri;
	foreach(i; 0..t) {
		auto ip = readAs!(int[]).sort.uniq.array;
		if(ip[2] > ip[0] + ip[1] + 1) writeln("No");
		else writeln("Yes");
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
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(){
	foreach(_; 0 .. rint){
		long a = rlong, b = rlong, c = rlong;
		long n = a + b + c;
		long m = n / 2;
		if(a > m || b > m || c > m) "No".writeln;
		else "Yes".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; }
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 t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto r = RD!int;
		auto g = RD!int;
		auto b = RD!int;
		auto arr = [r, g, b];
		arr.sort();
		ans[ti] = arr[2] <= (arr.sum+1)/2;
	}

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


Mr. F has $$$n$$$ positive integers, $$$a_1, a_2, \ldots, a_n$$$.He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers.But this problem is too simple for him, so he does not want to do it by himself. If you help him, he will give you some scores in reward.Your task is to calculate the minimum number of integers you need to remove so that the greatest common divisor of the remaining integers is bigger than that of all integers.

The first line contains an integer $$$n$$$ ($$$2 \leq n \leq 3 \cdot 10^5$$$) — the number of integers Mr. F has. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 1.5 \cdot 10^7$$$).

Print an integer — the minimum number of integers you need to remove so that the greatest common divisor of the remaining integers is bigger than that of all integers. You should not remove all of the integers. If there is no solution, print «-1» (without quotes).

NoteIn the first example, the greatest common divisor is $$$1$$$ in the beginning. You can remove $$$1$$$ so that the greatest common divisor is enlarged to $$$2$$$. The answer is $$$1$$$.In the second example, the greatest common divisor is $$$3$$$ in the beginning. You can remove $$$6$$$ and $$$9$$$ so that the greatest common divisor is enlarged to $$$15$$$. There is no solution which removes only one integer. So the answer is $$$2$$$.In the third example, there is no solution to enlarge the greatest common divisor. So the answer is $$$-1$$$.

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

immutable int N = 15_000_000 + 10;

void main()
{
    auto pr = new bool[N];
    auto cnt = new int[N];

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

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

    auto gcdnow = arr.fold!gcd;
    debug { gcdnow.writeln; }

    arr.each!(e => ++cnt[e / gcdnow]);

    auto ans = 0;
    pr[] = true;
    foreach (i; 2 .. N) {
        if (!pr[i]) continue;

        auto cur = 0;
        for (int j = i; j < N; j += i) {
            cur += cnt[j];
            pr[j] = false;
        }

        ans = max(ans, cur);
    }

    ans = ans > 0 ? n - ans : -1;
    writeln(ans);
}

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

immutable int N = 15_000_000 + 10;

void main()
{
    auto dvs = new int[N];
    auto cnt = new int[N];

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

    foreach (i; 2 .. N) {
        if (dvs[i] != 0) continue;

        dvs[i] = i;
        for (int j = i+i; j < N; j += i) dvs[j] = i;
    }

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

    auto gcdnow = arr.fold!gcd;
    arr[] /= gcdnow;

    debug { gcdnow.writeln; }

    foreach (e; arr) {
        while (e > 1) {
            auto now = dvs[e];
            ++cnt[now];
            while (dvs[e] == now) e /= now;
        }
    }

    auto left = cnt[2 .. $].maxElement;

    if (left == 0) {
        writeln(-1);
        return;
    }

    writeln(n - left);
}

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

immutable int N = 15_000_000 + 10;

void main()
{
    auto dvs = new int[N];
    auto cnt = new int[N];

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

    foreach (i; 2 .. N) {
        if (dvs[i] != 0) continue;

        dvs[i] = i;
        for (int j = i+i; j < N; j += i) dvs[j] = i;
    }

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

    auto gcdnow = arr.fold!gcd;

    debug { gcdnow.writeln; }

    foreach (e; arr) {
        while (e > 1) {
            auto now = dvs[e];
            ++cnt[now];
            while (dvs[e] == now) e /= now;
        }
    }

    auto left = cnt[gcdnow+1 .. $].maxElement;

    if (left == 0) {
        writeln(-1);
        return;
    }

    writeln(n - left);
}


Given an array $$$a$$$, consisting of $$$n$$$ integers, find:$$$$$$\max\limits_{1 \le i < j \le n} LCM(a_i,a_j),$$$$$$where $$$LCM(x, y)$$$ is the smallest positive integer that is divisible by both $$$x$$$ and $$$y$$$. For example, $$$LCM(6, 8) = 24$$$, $$$LCM(4, 12) = 12$$$, $$$LCM(2, 3) = 6$$$.

The first line contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$) — the elements of the array $$$a$$$.

Print one integer, the maximum value of the least common multiple of two elements in the array $$$a$$$.

import std.algorithm;
import std.conv : to;
import std.numeric : gcd;
import std.range;
import std.stdio;
import std.typecons : Tuple, tuple;

string readToken()
{
    static string[] tokens;
    while (tokens.empty)
        tokens = readln.split;
    auto token = tokens.front;
    tokens.popFront;
    return token;
}

int readInt()
{
    return readToken.to!int;
}

void main()
{
    int n = readInt;
    auto a = new int[n];
    for (int i = 0; i < n; ++i)
        a[i] = readInt;
    int m = a.maxElement;
    auto cnt = new int[m + 1];
    auto mu = new int[m + 1];
    mu[1] = 1;
    for (int d = 1; d <= m; ++d)
    {
        if (!mu[d])
            continue;
        cnt[d]++;
        for (int i = d * 2; i <= m; i += d)
            cnt[i]++, mu[i] -= mu[d];
    }
    auto divs = new int[][m + 1];
    for (int i = 1; i <= m; ++i)
        divs[i] = new int[cnt[i]];
    fill(cnt, 0);
    for (int d = 1; d <= m; ++d)
        if (mu[d])
            for (int i = d; i <= m; i += d)
                divs[i][cnt[i]++] = d;
    fill(cnt, 0);
    for (int i = 0; i < n; ++i)
        cnt[a[i]]++;
    long result = m;
    int[] stack = new int[m], subcnt = new int[m + 1];
    for (int g = 1; g <= m; ++g)
    {
        int m1 = m / g;
        int top = 0;
        for (int x = m1; x >= 1; --x)
            if (cnt[g * x])
            {
                int coprimes = 0;
                foreach (d; divs[x])
                    coprimes += mu[d] * subcnt[d];
                while (coprimes)
                {
                    int y = stack[--top];
                    if (gcd(x, y) == 1)
                        coprimes--, result = max(result, cast(long) g * x * y);
                    foreach (d; divs[y])
                        subcnt[d]--;
                }
                foreach (d; divs[x])
                    subcnt[d]++;
                stack[top++] = x;
            }
        while (top--)
            foreach (d; divs[stack[top]])
                subcnt[d]--;
    }
    writeln(result);
}

import std.algorithm : max, maxElement, sort, swap;
import std.conv : to;
import std.numeric : gcd;
import std.range;
import std.stdio;
import std.typecons : Tuple, tuple;
import std.algorithm.mutation;

// import std.container.array;

string readToken()
{
    static string[] tokens;
    while (tokens.empty)
    {
        tokens = readln.split;
    }
    auto token = tokens.front;
    tokens.popFront;
    return token;
}

int readInt()
{
    return readToken.to!int;
}

void main()
{
    int n = readInt;
    auto a = new int[n];
    for (int i = 0; i < n; ++i)
        a[i] = readInt;
    int m = a.maxElement;
    auto cnt = new int[m + 1];
    auto mu = new int[m + 1];
    mu[1] = 1;
    for (int d = 1; d <= m; ++d)
    {
        cnt[d]++;
        for (int i = d * 2; i <= m; i += d)
            cnt[i]++, mu[i] -= mu[d];
    }
    auto divs = new int[][m + 1];
    for (int i = 1; i <= m; ++i)
        divs[i] = new int[cnt[i]];
    fill(cnt, 0);
    for (int d = 1; d <= m; ++d)
        for (int i = d; i <= m; i += d)
            divs[i][cnt[i]++] = d;
    fill(cnt, 0);
    for (int i = 0; i < n; ++i)
        cnt[a[i]]++;
    long result = m;
    int[] stack = new int[m], subcnt = new int[m + 1];
    for (int g = 1; g <= m; ++g)
    {
        int m1 = m / g;
        int top = 0;
        for (int x = m1; x >= 1; --x)
            if (cnt[g * x])
            {
                int coprimes = 0;
                foreach (d; divs[x])
                    coprimes += mu[d] * subcnt[d];
                while (coprimes)
                {
                    int y = stack[--top];
                    if (gcd(x, y) == 1)
                        coprimes--, result = max(result, cast(long) g * x * y);
                    foreach (d; divs[y])
                        subcnt[d]--;
                }
                foreach (d; divs[x])
                    subcnt[d]++;
                stack[top++] = x;
            }
        while (top--)
            foreach (d; divs[stack[top]])
                subcnt[d]--;
    }
    writeln(result);
}


Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...The string $$$s$$$ he found is a binary string of length $$$n$$$ (i. e. string consists only of 0-s and 1-s).In one move he can choose two consecutive characters $$$s_i$$$ and $$$s_{i+1}$$$, and if $$$s_i$$$ is 1 and $$$s_{i + 1}$$$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $$$s$$$ as clean as possible. He thinks for two different strings $$$x$$$ and $$$y$$$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.Now you should answer $$$t$$$ test cases: for the $$$i$$$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.Small reminder: if we have two strings $$$x$$$ and $$$y$$$ of the same length then $$$x$$$ is lexicographically smaller than $$$y$$$ if there is a position $$$i$$$ such that $$$x_1 = y_1$$$, $$$x_2 = y_2$$$,..., $$$x_{i - 1} = y_{i - 1}$$$ and $$$x_i < y_i$$$.

The first line contains the integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.  Next $$$2t$$$ lines contain test cases — one per two lines. The first line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the string $$$s$$$. The second line contains the binary string $$$s$$$. The string $$$s$$$ is a string of length $$$n$$$ which consists only of zeroes and ones. It's guaranteed that sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$.

Print $$$t$$$ answers — one per test case. The answer to the $$$i$$$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).

NoteIn the first test case, Lee can't perform any moves.In the second test case, Lee should erase $$$s_2$$$.In the third test case, Lee can make moves, for example, in the following order: 11001101 $$$\rightarrow$$$ 1100101 $$$\rightarrow$$$ 110101 $$$\rightarrow$$$ 10101 $$$\rightarrow$$$ 1101 $$$\rightarrow$$$ 101 $$$\rightarrow$$$ 01.

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 s = readln.strip;
		string res1, res2, res3;
		while (!s.empty && s.front == '0')
		{
			res1 ~= s.front;
			s.popFront ();
		}
		while (!s.empty && s.back == '1')
		{
			res3 ~= s.back;
			s.popBack ();
		}
		if (!s.empty)
		{
			res2 = "0";
		}
		writeln (res1 ~ res2 ~ res3);
	}
}

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

DList!string _words;

void read(T...)(ref T t)
{
  void singleRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!T(word);
  }
  static foreach(i; 0 .. T.length)
    {
      static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))
        {
          foreach(ref element; t[i])
            read(element);
        }
      else
        {
          singleRead(t[i]);
        }
    }
}

auto next(T)()
{
  T t;
  read(t);
  return t;
}

size_t ind(T)(T t)
{
  return cast(size_t)t;
}

ref auto at(R, I)(ref R r, I i)
{
  return r[cast(size_t)i];
}

void set(R, I, V)(ref R r, I i, V v)
{
  r[cast(size_t)i] = v;
}

import std.conv;
import std.traits;
import std.meta;
int _loglevel = -1;
void _log(string functionName, argSeq...)()
{
  foreach(i; 0 .. _loglevel * 4)
    write(' ');
  write(functionName);
  static foreach(arg; argSeq)
    {
      write(" ", arg.stringof, " = ", arg);
    }
  writeln;
}
enum logCall =
  q{
    debug
    {
     {
     _loglevel++;
     alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, ".").back));
     static if (_parameterTuple.length > 0)
       mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(", ").array, `);`);
     else
       _log!(__FUNCTION__);
      }
     foreach(i; 0 .. _loglevel * 4) write(' ');
     writeln('{');
     scope(exit)
       {
         foreach(i; 0 .. _loglevel * 4) write(' ');
         writeln('}');
         _loglevel--;
       }
    }
};

void logSym(S...)(int line = __LINE__, string file = __FUNCTION__)
{
  debug
    {
      foreach(i; 0 .. _loglevel * 4) write(' ');
      write(file, "(", line, "):");
      static foreach(s; S)
        write(" ", s.stringof, " = ", s);
      writeln;

    }
}

Array!E makeArray(E, S)(S size, lazy E value = E.init)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  foreach(ref ai; a)
    ai = value();
  return a;
}
Array!E makeArray(E, S)(S size)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  return a;
}

void main()
{
  int t;
  read(t);
  while(t--)
    {
      int n;
      read(n);
      string s;
      read(s);
      string rs = s.dup.reverse;
      auto prefix = cast(long) s.countUntil('1');
      if (prefix == -1)
        prefix = n;
      auto suffix = cast(long) rs.countUntil('0');
      if (suffix == -1)
        suffix = n;
      string middle = "";
      if (suffix + prefix < n)
        middle = "0";
      string res = s[0 .. cast(size_t)prefix] ~ middle ~ s[$ - cast(size_t)suffix .. $];
      writeln(res);
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		int l = n, r = -1;
		foreach (int i; 0..n)
		{
			if (s[i] == '1')
			{
				l = i;
				break;
			}
		}
		foreach_reverse (int i; 0..n)
		{
			if (s[i] == '0')
			{
				r = i;
				break;
			}
		}
		if (l < r)
			ans[ti] = s[0..l] ~ '0' ~ s[r+1..s.length];
		else
			ans[ti] = s[0..l] ~ s[r+1..s.length];
	}

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


Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly k of the nodes should be exit-nodes, that means that each of them should be connected to exactly one other node of the network, while all other nodes should be connected to at least two nodes in order to increase the system stability.Arkady wants to make the system as fast as possible, so he wants to minimize the maximum distance between two exit-nodes. The distance between two nodes is the number of wires a package needs to go through between those two nodes.Help Arkady to find such a way to build the network that the distance between the two most distant exit-nodes is as small as possible.

The first line contains two integers n and k (3 ≤ n ≤ 2·105, 2 ≤ k ≤ n - 1) — the total number of nodes and the number of exit-nodes. Note that it is always possible to build at least one network with n nodes and k exit-nodes within the given constraints.

In the first line print the minimum possible distance between the two most distant exit-nodes. In each of the next n - 1 lines print two integers: the ids of the nodes connected by a wire. The description of each wire should be printed exactly once. You can print wires and wires' ends in arbitrary order. The nodes should be numbered from 1 to n. Exit-nodes can have any ids. If there are multiple answers, print any of them.

NoteIn the first example the only network is shown on the left picture.In the second example one of optimal networks is shown on the right picture.Exit-nodes are highlighted.

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

immutable int INF = 10L ^^ 9 + 23;

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

    Tuple!(int, int)[] ans;
    foreach (i; 2 .. n+1) {
        int prev = i-k < 1 ? 1 : i-k;
        ans ~= tuple(prev, i);
    }

    int longerCnt = (n-1)%k;
    int longerVal = (n-1 + k-1)/k;
    int shorterVal = (n-1)/k;
    int dst = longerCnt == 0 ? shorterVal * 2
        : longerCnt == 1 ? shorterVal + longerVal : 2 * longerVal;
    writeln(dst);
    ans.each!(t => writeln(t[0], ' ', t[1]));
}

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

immutable int INF = 10L ^^ 9 + 23;

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

    Tuple!(int, int)[] ans;
    foreach (i; 2 .. n+1) {
        int prev = i-k < 1 ? 1 : i-k;
        ans ~= tuple(prev, i);
    }

    int longerCnt = (n-1)%k;
    int longerVal = (n-1 + k-1)/k;
    int shorterVal = (n-1)/k;
    int dst = longerCnt == 0 ? shorterVal * 2
        : longerCnt == 1 ? shorterVal + longerVal : longerVal * 2;
    writeln(dst);
    ans.each!(t => writeln(t[0], ' ', t[1]));
}

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

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

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

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

int N;
int[][] graph;

alias Result = Tuple!(int, "d", int, "u");

Result dfs(int u, int p) {
  auto ret = Result(0, u);
  foreach (v; graph[u]) {
    if (v != p) {
      const res = dfs(v, u);
      chmax(ret, Result(1 + res.d, res.u));
    }
  }
  return ret;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      const K = readInt();

      int[][] ans;
      int n = 1 + (N - 1) % K;
      foreach (u; 1 .. n) {
        ans ~= [0, u];
      }
      int a, b;
      if (n == 1) {
        a = 0;
        b = 1;
      } else if (n == 2) {
        a = 0;
        b = 2;
      } else {
        a = 1;
        b = n;
      }
      debug {
        writefln("N = %s, K = %s", N, K);
        writefln("n = %s, a = %s, b = %s", n, a, b);
      }
      for (; n < N; n += K) {
        foreach (k; 0 .. K) {
          ans ~= [a + k % (b - a), n + k];
        }
        a = n;
        b = n + K;
      }

      graph = new int[][N];
      foreach (edge; ans) {
        graph[edge[0]] ~= edge[1];
        graph[edge[1]] ~= edge[0];
      }
      const res0 = dfs(0, -1);
      const res1 = dfs(res0.u, -1);
      writeln(res1.d);
      foreach (edge; ans) {
        writeln(edge[0] + 1, " ", edge[1] + 1);
      }
    }
  } catch (EOFException e) {
  }
}

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

immutable int INF = 10L ^^ 9 + 23;

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

    Tuple!(int, int)[] ans;

    void star(int sz) {
        foreach (i; 2 .. sz+1) {
            ans ~= tuple(1, i);
        }
    }

    if (k == n-1) {
        star(n);
        writeln(2);
        ans.each!(t => writeln(t[0], ' ', t[1]));
    } else {
        star(k+1);
        foreach (i; k+1 .. n) {
            ans ~= tuple(i, i+1);
        }

        writeln(n - (k-1));
        ans.each!(t => writeln(t[0], ' ', t[1]));
    }
}

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

immutable int INF = 10L ^^ 9 + 23;

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

    Tuple!(int, int)[] ans;

    void star(int sz) {
        foreach (i; 2 .. sz+1) {
            ans ~= tuple(1, i);
        }
    }

    if (k == n-1) {
        star(n);
        writeln(2);
        ans.each!(t => writeln(t[0], ' ', t[1]));
    } else {
        star(k+1);
        foreach (i; k+2 .. n) {
            ans ~= tuple(i, i+1);
        }

        writeln(n - (k-1));
        ans.each!(t => writeln(t[0], ' ', t[1]));
    }
}

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

immutable int INF = 10L ^^ 9 + 23;

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

    Tuple!(int, int)[] ans;
    foreach (i; 2 .. n+1) {
        int prev = i-k < 1 ? 1 : i-k;
        ans ~= tuple(prev, i);
    }

    writeln((n-1)/k + (n-1 + k-1)/k);
    ans.each!(t => writeln(t[0], ' ', t[1]));
}

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

immutable int INF = 10L ^^ 9 + 23;

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

    Tuple!(int, int)[] ans;

    void star(int sz) {
        foreach (i; 2 .. sz+1) {
            ans ~= tuple(1, i);
        }
    }

    if (k == n-1) {
        star(n);
    } else if (k == n-2) {
        star(n-2);
        ans ~= tuple(1, n-1);
        ans ~= tuple(n-1, n);
    } else {
        star(k+1);
        foreach (i; k+2 .. n) {
            ans ~= tuple(i, i+1);
        }
        ans ~= tuple(n, 1);
    }

    ans.length.writeln;
    foreach (t; ans) {
        writeln(t[0], ' ', t[1]);
    }
}

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

immutable int INF = 10L ^^ 9 + 23;

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

    Tuple!(int, int)[] ans;

    void star(int sz) {
        foreach (i; 2 .. sz+1) {
            ans ~= tuple(1, i);
        }
    }

    if (k == n-1) {
        star(n);
        writeln(2);
        ans.each!(t => writeln(t[0], ' ', t[1]));
    } else {
        star(k);
        foreach (i; k .. n) {
            ans ~= tuple(i, i+1);
        }

        writeln(n - (k-1));
        ans.each!(t => writeln(t[0], ' ', t[1]));
    }
}