You are given two integers $$$A$$$ and $$$B$$$, calculate the number of pairs $$$(a, b)$$$ such that $$$1 \le a \le A$$$, $$$1 \le b \le B$$$, and the equation $$$a \cdot b + a + b = conc(a, b)$$$ is true; $$$conc(a, b)$$$ is the concatenation of $$$a$$$ and $$$b$$$ (for example, $$$conc(12, 23) = 1223$$$, $$$conc(100, 11) = 10011$$$). $$$a$$$ and $$$b$$$ should not contain leading zeroes.

The first line contains $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Each test case contains two integers $$$A$$$ and $$$B$$$ $$$(1 \le A, B \le 10^9)$$$.

Print one integer — the number of pairs $$$(a, b)$$$ such that $$$1 \le a \le A$$$, $$$1 \le b \le B$$$, and the equation $$$a \cdot b + a + b = conc(a, b)$$$ is true.

NoteThere is only one suitable pair in the first test case: $$$a = 1$$$, $$$b = 9$$$ ($$$1 + 9 + 1 \cdot 9 = 19$$$).

import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.datetime;
import std.bitmanip;
import std.regex;

void main()
{
    auto N = scanElem;
    foreach(e;scanElem!(long,long)(N))
    {
        auto a = e[0];
        auto b = e[1];
        auto n = b.to!string.length;
        if(b.to!string.any!"a!='9'")n--;
        writeln(a*n);
    }
}

//辞書順順列はiota(1,N),nextPermituionを使う

enum INF = long.max/3;
enum MOD = 10^^9+7;

T binarySearch(alias F, T)(T ok, T ng, long iter=100)
{
    alias FF = unaryFun!F;
    foreach(_;0..iter)
    {
        auto n = (ok+ng)/2;
        if(FF(n)){
            ok = n;
        }else{
            ng = n;
        }
        static if(isIntegral!T){
            if(abs(ok-ng)==1)return ok;
        }
    }
    return ok;
}

//最小を返す
real ternarySearch(alias F)(real l, real r, long iter=200)
{
    alias FF = unaryFun!F;
    foreach(_;0..iter)
    {
        auto nl = lerp(l, r, 1/real(3));
        auto nr = lerp(l, r, 2/real(3));
        if(FF(nl)<FF(nr)){
            r = nr;
        }else{
            l = nl;
        }
    }
    return FF(l);
}
long ternarySearch(alias F)(long l, long r, long iter=200)
{
    alias FF = unaryFun!F;
    foreach(_;0..iter)
    {
        auto nl = lerp(l, r, 1/real(3)).to!long;
        auto nr = lerp(l, r, 2/real(3)).to!long;
        if(nl>11)debugPrint!(l,r,nl,nr,()=>FF(nl),()=>FF(nr));
        if(FF(nl)<FF(nr)){
            r = nr;
        }else{
            l = nl;
        }
        if(r-l<4)break;
    }
    long res=INF;
    foreach(i;l..r+1)
    {
        debugPrint!(l, r, i, ()=>FF(i));
        res = min(FF(i), res);
    }
    return res;
}

CommonType!(A,B,T) lerp(A,B,T)(A a, B b, T t) pure
{
    alias C = CommonType!(A,B,T);
    return (C(b)-a)*t+a;
}

struct Vector{
    real x, y;

    real magnitude()pure
    {
        return sqrt(sqrMagnitude);
    }
    real sqrMagnitude()pure
    {
        return x*x+y*y;
    }

    Vector opBinary(string op, T)(inout T v)
    if(isNumeric!T)
    {
        return Vector(mixin("x"~op~"v"), mixin("y"~op~"v"));
    }
    Vector opBinary(string op)(inout Vector v)
    {
        return Vector(mixin("x"~op~"v.x"), mixin("y"~op~"v.y"));
    }
    void opOpAssign(string op, T)(inout T v)
    {
        this = mixin("this"~op~"v");
    }

    static Vector lerp(Vector a, Vector b, real t)pure
    {
        return (b-a)*t+a;
    }
    static Vector normalized(Vector a)pure
    {
        auto r = a.magnitude();
        return Vector(a.x / r, a.y / r);
    }
    static real distance(Vector a, Vector b)pure
    {
        return (a-b).magnitude;
    }
    static real dot(Vector a, Vector b)pure
    {
        return a.x*b.x+a.y*b.y;
    }
    static real cross(Vector a, Vector b)pure
    {
        return a.x*b.y-b.x*a.y;
    }
}

//ascii文字のみ
long[] suffixArray(Char)(const(Char)[] s) pure
if(isSomeChar!Char)
// in{assert(s.all!"0<=a&&a<127");}
// do
{
    s ~= '\0';
    long[] p = new long[s.length];
    long[] c = new long[s.length];
    {
        long[127] cnt;
        foreach(i;0..s.length)cnt[s[i]]++;
        foreach(i;1..cnt.length)cnt[i] += cnt[i-1];
        foreach(i;0..s.length)p[--cnt[s[i]]] = i;
        long classes=1;
        foreach(i;1..p.length){
            classes += s[p[i]]!=s[p[i-1]]?1:0;
            c[p[i]] = classes-1;
        }
    }
    long[] pn = new long[s.length];
    long[] cn = new long[s.length];
    for(long n=0;(1L<<n) < s.length;n++)
    {
        p.map!(a=>mod(a-(1L<<n), s.length)).copy(pn);
        long[127] cnt;
        foreach(i;0..pn.length)cnt[c[pn[i]]]++;
        foreach(i;1..cnt.length)cnt[i] += cnt[i-1];
        foreach_reverse(i;0..pn.length)p[--cnt[c[pn[i]]]] = pn[i];
        long classes=1;
        for(long i=1;i<c.length;i++)
        {
            if(
                tuple(c[p[i]], c[(p[i]+(1L<<n))%s.length]) !=
                tuple(c[p[i-1]], c[(p[i-1]+(1L<<n))%s.length])
            ) {
                classes++;
            }
            cn[p[i]] = classes - 1;
        }
        cn.copy(c);
    }
    return p[1..$];
}

struct BiparticeMatching{
    int N;
    int[][] path;
    int[] match;
    this(long n)
    {
        N = n.to!int;
        path.length = N;
        match.length = N;
    }
    void addEdge(long u, long v){
        addEdge(u.to!int, v.to!int);
    }
    void addEdge(int u, int v){
        path[u] ~= v;
        path[v] ~= u;
    }
    long calc(){
        auto used = new bool[N];
        bool dfs(int v){
            used[v] = true;
            foreach(u; path[v]){
                int w = match[u];
                if(w==-1||(!used[w]&&dfs(w))){
                    match[v]=u;
                    match[u]=v;
                    return true;
                }
            }
            return false;
        }
        match[] = -1;
        long res = 0;
        foreach(int v; 0..N){
            if(match[v] == -1){
                used[] = false;
                if(dfs(v)){
                    res++;
                }
            }
        }
        return res;
    }
}

// int max_flow(int s, int t){
//     struct edge{
//         int to, cap,  rev;
//     }
//     edge[][MAX_V] G;
//     bool[MAX_V] used;
//     void add_edge(int from, int to, int cap){
//         G[from] ~= edge(to, cap, G[to].length);
//         G[to] ~= edge(from, 0, G[from].length-1);
//     }
//     int dfs(int v, int t, int f)
//     {
//         if(v==t)return f;
//         used[v] = true;
//         foreach(i;0..G[v].length)
//         {
//             edge e = G[v][i];
//             if(!used[e.to] && e.cap > 0){
//                 int d = dfs(e.to, t, min(f, e.cap));
//                 if(d>0){
//                     e.cap -= d;
//                     G[e.to][e.rev].cap +=d ;
//                     return d;
//                 }
//             }
//         }
//         return 0;
//     }
//     int flow = 0;
//     for(;;){
//         int f = dfs(s,t,INF);
//         if(f==0)return flow;
//         flow += f;
//     }
// }

struct CombTable2(long MOD)
{
    static long[] fac;
    static long[] finv;
    static long[] inv;
    this(long n)
    {
        fac = new long[n];
        finv = new long[n];
        inv = new long[n];

        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        foreach(i;2..n){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    long comb(long n, long k)
    {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
}
struct CombTable(long MOD, long n)
{
    static long[n] fac;
    static long[n] finv;
    static long[n] inv;
    static this()
    {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        foreach(i;2..n){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    static long comb(long n, long k)
    {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
}

void outLine(List...)(List list)
{
    foreach(i, v;list)
    {
        static if(isFloatingPoint!(typeof(v)))
        {
            writef("%.12f", v);
        }else{
            write(v);
        }
        if(i+1!=list.length)write(' ');
    }
    writeln;
}

void end(List...)(List list)
{
    outLine(list);
    end;
}
void end()
{
    import core.stdc.stdlib;
    exit(0);
}

long sequenceSum(long n) pure
{
    return n*(n+1)/2;
}

//HL分解
struct HeavyLightDecomposition
{
    immutable int root = 1;

    int[][] edge;
    int[] vid;
    int[] invid;
    int[] parent;
    int[] depth;
    int[] subCount;
    int[] head;

    this(long n, long root = 1)
    {
        this(n.to!int, root.to!int);
    }
    this(int n, int root = 1)
    {
        this.root = root;
        n++;
        edge.length = n;
        vid.length = n;
        invid.length = n;
        parent.length = n; parent[] = -1;
        depth.length = n;
        head.length = n; head[root] = root;
        subCount.length = n; subCount[] = 1;
    }

    void addEdge(long u, long v)
    {
        addEdge(u.to!int, v.to!int);
    }
    void addEdge(int u, int v)
    {
        edge[u] ~= v;
        edge[v] ~= u;
    }

    void build()
    {
        void dfs(int v){
            foreach(ref u; edge[v])
            {
                if(u==parent[v]) continue;
                parent[u] = v;
                depth[u] = depth[v] + 1;
                dfs(u);
                subCount[v] += subCount[u];
                if(edge[v][0]==parent[v]||subCount[u]>subCount[edge[v][0]])
                    swap(u, edge[v][0]);
            }
        }
        void dfsHead(int v, ref int pos){
            invid[pos] = v;
            vid[v] = pos;
            pos++;
            foreach(ref u; edge[v])
            {
                if(u==parent[v]) continue;

                head[u] = u == edge[v][0] ? head[v] : u;
                dfsHead(u, pos);
            }
        }
        dfs(root);
        int pos;
        dfsHead(root, pos);
    }

    long lca(long u, long v)
    {
        return lca(u.to!int, v.to!int);
    }
    int lca(int u, int v)
    {
        while(true){
            if(vid[u]>vid[v]) swap(u,v);
            if(head[u]==head[v]) return u;
            v = parent[head[v]];
        }
    }

    long distance(long u, long v) { return distance(u.to!int, v.to!int); }
    long distance(int u, int v) { return depth[u] + depth[v] - 2 * depth[lca(u,v)]; }

    //idxのn個上の親を返す
    //バグあるかも
    long nParent(long n, long idx){
        return nParent(n.to!int, idx.to!int);
    }
    int nParent(int n, int idx){
        auto u = 0;
        auto v = idx;
        while(true)
        {
            if(vid[u]>vid[v]) swap(u,v);

            immutable _u = max(vid[head[v]], vid[u]);
            immutable _v = vid[v] + 1;
            if(_v<=_u+n){
                n -= _v-_u;
            }else{
                return invid[_v-n-1];
            }

            if(head[u]==head[v]) return -1;
            v = parent[head[v]];
        }
    }

    void each(long u, long v, void delegate(long u, long v) pred)
    {
        each(u.to!int, v.to!int, pred);
    }
    void each(int u, int v, void delegate(int u, int v) pred)
    {
        while(true)
        {
            if(vid[u]>vid[v]) swap(u,v);
            pred(max(vid[head[v]], vid[u]), vid[v] + 1);
            if(head[u]==head[v]) return;
            v = parent[head[v]];
        }
    }

    void each(alias pred)(long u, long v)
    if(is(typeof(binaryFun!pred(0L,0L))))
    {
        while(true)
        {
            if(vid[u]>vid[v]) swap(u,v);
            binaryFun!pred(max(vid[head[v]], vid[u]), vid[v] + 1);
            if(head[u]==head[v]) return;
            v = parent[head[v]];
        }
    }
}

// struct HLD{

//     long[][] G;
//     long[] vid, head, sub, par, dep, inv, type;

//     void dfs_sz(long v) {
//         foreach(ref u; G[v])
//             if(u==par[v]) swap(u,G[v].back());
//         if(~par[v]) G[v].popBack;

//         foreach(ref u; G[v]){
//             par[u]=v;
//             dep[u]=dep[v]+1;
//             dfs_sz(u);
//             sub[v]+=sub[u];
//             if(sub[u]>sub[G[v][0]]) swap(u,G[v][0]);
//         }
//     }

//     void dfs_hld(long v,long c,ref long pos) {
//         vid[v]=pos++;
//         inv[vid[v]]=v;
//         type[v]=c;
//         foreach(u; G[v]){
//             if(u==par[v]) continue;
//             head[u]=(u==G[v][0]?head[v]:u);
//             dfs_hld(u,c,pos);
//         }
//     }

//     this(long n){
//         G = new long[][n];
//         vid = new long[n]; vid[] = -1;
//         head = new long[n];
//         sub = new long[n]; sub[] = 1;
//         par = new long[n]; par[] = -1;
//         dep = new long[n];
//         inv = new long[n];
//         type = new long[n];
//     }

//     void add_edge(long u,long v) {
//         G[u] ~= v;
//         G[v] ~= u;
//     }

//     void build(long[] rs = [0]) {
//         long c=0,pos=0;
//         foreach(r; rs){
//             dfs_sz(r);
//             head[r]=r;
//             dfs_hld(r,c++,pos);
//         }
//     }

//     long lca(long u,long v){
//         while(1){
//             if(vid[u]>vid[v]) swap(u,v);
//             if(head[u]==head[v]) return u;
//             v=par[head[v]];
//         }
//     }

//     long distance(long u,long v){
//         return dep[u]+dep[v]-2*dep[lca(u,v)];
//     }

//     // for_each(vertex)
//     // [l, r) <- attention!!
//     void for_each(F)(long u, long v, F f) {
//         while(1){
//             if(vid[u]>vid[v]) swap(u,v);
//             f(max(vid[head[v]],vid[u]),vid[v]+1);
//             if(head[u]!=head[v]) v=par[head[v]];
//             else break;
//         }
//     }

//     T for_each(T, Q, F)(long u,long v,T ti,Q q,F f)
//     {
//         T l=ti,r=ti;
//         while(1){
//             if(vid[u]>vid[v]){
//                 swap(u,v);
//                 swap(l,r);
//             }
//             l=f(l,q(max(vid[head[v]],vid[u]),vid[v]+1));
//             if(head[u]!=head[v]) v=par[head[v]];
//                 else break;
//         }
//         return f(l,r);
//     }

//     // for_each(edge)
//     // [l, r) <- attention!!
//     void for_each_edge(F)(long u, long v,F f) {
//         while(1){
//             if(vid[u]>vid[v]) swap(u,v);
//             if(head[u]!=head[v]){
//                 f(vid[head[v]],vid[v]+1);
//                 v=par[head[v]];
//             }else{
//                 if(u!=v) f(vid[u]+1,vid[v]+1);
//                 break;
//             }
//         }
//     }
// }

struct SegTree(T, T UNIT, alias pred){
    int n;
    long size;
    T* arr;
    alias F = binaryFun!pred;

    this(long size)
    {
        this.size = size;
        n=1;
        while(n<size) n<<=1;
        arr = new T[n<<1].ptr;
        arr[0..n<<1] = UNIT;
    }

    void set(long k,T x)
    {
        assert(k>=0&&k<size);

        arr[k+=n]=x;
        while(k>>=1)
            arr[k]=F(arr[(k<<1)|0],arr[(k<<1)|1]);
    }

    T query(long a, long b)
    {
        assert(a>=0&&a<size);
        assert(b>=1&&b<=size);

        T vl=UNIT,vr=UNIT;
        for(long l=a+n,r=b+n;l<r;l>>=1,r>>=1)
        {
            if(l&1) vl=F(vl,arr[l++]);
            if(r&1) vr=F(arr[--r],vr);
        }
        return F(vl,vr);
    }
}

bool isInf(Num)(Num v) pure @nogc
if(isIntegral!Num)
{
    return v>=INF/2;
}

Unqual!M mod(N,M)(N n, M mod) pure @nogc
if(isIntegral!N&&isIntegral!M)
{
    return (n%mod+mod)%mod;
}

long pow(long a, long n) {
    long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

Unqual!M powmod(A,N,M)(A _a, N _n, M mod)
{
    Unqual!A a = _a;
    Unqual!N n = _n;
    M res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

alias MInt = ModInt!MOD;

struct ModInt(alias Mod)
if(isIntegral!(typeof(Mod)) && isPrime(Mod))
{
    int value;

    this(ModInt!Mod v)
    {
        value = v.value;
    }
    this(T)(T v)
    if(isIntegral!T)
    {
        value = mod(v, Mod);
    }

    ModInt!Mod opBinaryRight(string op, T)(inout T v) const
    if((op=="+"||op=="-"||op=="*")&&isIntegral!T)
    {
        return typeof(this)(mixin("v"~op~"value"));
    }
    ModInt!Mod opBinary(string op, T)(inout T v) const
    if((op=="+"||op=="-"||op=="*")&&(is(T==ModInt!Mod)||isIntegral!T))
    {
        return typeof(this)(mixin("value"~op~"v"));
    }

    ModInt!Mod opBinaryRight(string op, T)(inout T v) const
    if((op=="/")&&isIntegral!T)
    {
        return v * (this^^(Mod-2));
    }
    ModInt!Mod opBinary(string op, T)(inout T v) const
    if((op=="/")&&(is(T==ModInt!Mod)||isIntegral!T))
    {
        return this * (typeof(this)(v)^^(Mod-2));
    }

    ModInt!Mod opBinary(string op, T)(inout T v) const
    if((op=="^^")&&isIntegral!T)
    {
        return typeof(this)(powmod(value, v, Mod));
    }

    void opAssign(T)(inout T v)
    if(isIntegral!T)
    {
        this = typeof(this)(v);
    }

    void opOpAssign(string op, T)(inout T v)
    {
        this = mixin("this"~op~"v");
    }

    bool opEquals(T)(const T v) const
    if(is(T==ModInt!Mod)||isIntegral!T)
    {
        return value == typeof(this)(v).value;
    }

    long opCast() const {
        return value;
    }

    string toString() const {
        return value.to!string;
    }
}
unittest
{
    assert(is(ModInt!MOD));
    assert(is(ModInt!17));
    assert(!is(ModInt!0));
    assert(!is(ModInt!10));
}

unittest
{
    alias MInt = ModInt!13;
    MInt value;
    value = MInt(14) + MInt(18);
    assert(value==6);
    value = 14 - MInt(28);
    assert(value==12);
    value = MInt(17) * -19;
    assert(value==2);

    value = MInt(7) / 4;
    assert(value==5);
    value = 8 / MInt(4);
    assert(value==2);
    value = 9;
    value /= 4;
    assert(value==12);

    assert(MInt(3) ^^ 9 == 1);

    value = 29-MInt(16);
    assert(value==0);
    value = MInt(13)*5;
    assert(value==0);
    value = 0;
    assert(value==0);

    value = 3;
    value += MInt(11);
    assert(value==1);
    value -= 7;
    assert(value==7);
    value *= MInt(4);
    assert(value==2);
    value = 23;
    assert(value == cast(long)value);
}
unittest
{
    ModInt!MOD value;
    value = MOD-1;
    assert(value==MOD-1);
    value = MOD;
    assert(value==0);
}

struct Grid(T){
    private T[] grid;
    size_t width, height;
    private size_t stride;

    private this(T[] g, size_t w, size_t h, size_t s)
    {
        grid = g;
        width = w;
        height = h;
        stride = s;
    }

    this(long w, long h, T init = T.init)
    {
        auto arr = new T[(w*h).to!int];
        arr[] = init;
        this(arr, w.to!size_t, h.to!size_t, w.to!size_t);
    }

    // void fill(T elem){
    //     grid[] = elem;
    // }

    bool isInRange(long x, long y) const nothrow
    {
        return
            x>=0 &&
            x<width &&
            y>=0 &&
            y<height;
    }

    int opApply(scope int delegate(ref T) dg)
    {
        int result = 0;

        foreach(y;0..height)
        foreach(x;0..width)
        {
            result = dg(this[x,y]);
            if (result)
                break;
        }
        return result;
    }
    int opApply(scope int delegate(long i, ref T) dg)
    {
        int result = 0;

        long idx;
        foreach(y;0..height)
        foreach(x;0..width)
        {
            result = dg(idx++, this[x,y]);
            if (result)
                break;
        }
        return result;
    }
    int opApply(scope int delegate(long x, long y, ref T) dg)
    {
        int result = 0;

        foreach(y;0..height)
        foreach(x;0..width)
        {
            result = dg(x, y, this[x,y]);
            if (result)
                break;
        }
        return result;
    }

    ref T opIndex(long x, long y)
    {
        assert(isInRange(x,y));
        return (grid.ptr)[(x+stride*y).to!size_t];
    }

    Grid!T opIndex(long[2] r1, long[2] r2)
    {
        auto startOffset = (r1[0] + r2[0]*stride).to!size_t;
        auto endOffset = (r1[1] + (r2[1] - 1)*stride).to!size_t;

        auto resGrid = grid[startOffset .. endOffset];
        auto resStride = stride;
        auto resWidth = (r1[1] - r1[0]).to!size_t;
        auto resHeight = (r2[1] - r2[0]).to!size_t;
        return Grid!T(resGrid, resWidth, resHeight, resStride);
    }

    Grid!T opIndex(long[2] r1, long j) { return opIndex(r1, [j, j+1]); }
    Grid!T opIndex(long i, long[2] r2) { return opIndex([i, i+1], r2); }

    long[2] opSlice(long dim)(long start, long end)
    if (dim == 0 || dim == 1)
    // in { assert(start >= 0 && end <= this.opDollar!dim); }
    body{
        return [start, end];
    }

    Grid!T transpose(){
        auto grid = Grid!T(height, width);

        foreach(w; 0..width)
        foreach(h; 0..height)
        {
            grid[h, w] = this[w, h];
        }
        return grid;
    }

    long opDollar(long dim : 0)() const { return width; }
    long opDollar(long dim : 1)() const { return height; }

    string toString() pure {
        long count;
        foreach(y; 0..height)
        {
            foreach(x; 0..width)
            {
                long eCount = this[x, y].to!string.length;
                static if(is(typeof(this[x,y].isInf)))
                {
                    if(this[x,y].isInf)
                    {
                        eCount = 1;
                    }
                }
                static if(is(typeof(this[x,y])==bool))
                {
                    eCount = 1;
                }
                count = max(count, eCount);
            }
        }
        count++;

        string res = "\n";
        foreach(y; 0..height)
        {
            foreach(x; 0..width)
            {
                string joinStr = this[x, y].to!string;
                static if(is(typeof(this[x,y].isInf)))
                {
                    if(this[x,y].isInf)
                    {
                        joinStr = "*";
                    }
                }
                static if(is(typeof(this[x,y])==bool))
                {
                    joinStr = this[x,y]?"+":"-";
                }
                foreach(i;0..count-joinStr.length)
                {
                    res ~= ' ';
                }
                res ~= joinStr;
            }
            res ~= '\n';
        }
        return res;
    }
}

struct UnionFind{
    private int[] arr;
    int rootCount;

    @disable this();
    this(long n){
        arr.length = n.to!int;
        arr[] = -1;
        rootCount = n.to!int;
    }

    void merge(long a, long b)
    {
        merge(a.to!int, b.to!int);
    }
    void merge(int a, int b)
    {
        if(same(a,b)) return;
        arr[root(a)] = root(b);
        rootCount--;
    }

    bool same(long a, long b)
    {
        return same(a.to!int, b.to!int);
    }
    bool same(int a, int b)
    {
        return root(a)==root(b);
    }

    private int root(int i)
    {
        if(arr[i] == -1) return i;
        return arr[i] = root(arr[i]);
    }
}

unittest{
    assert(is(typeof(UnionFind(10))));
    assert(!is(typeof(UnionFind())));

    auto uf = UnionFind(10);
    uf.merge(2,3);
    assert(uf.same(2,3));
    uf.merge(3,4);
    uf.merge(1,5);
    uf.merge(5,6);
    uf.merge(6,7);
    assert(!uf.same(4,7));
    uf.merge(1,2);
    assert(uf.same(4,7));
}

void debugPrint(List...)()
{
    void _debugPrintElem(alias elem, float rad)()
    {
        import std.experimental.color;
        import std.experimental.color.lab;
        import std.experimental.color.rgb;
        import std.experimental.color.xyz;

        enum color = LCh!float(80f, 100f, rad);
        enum rgb = color.convertColor!(Lab!float).convertColor!(XYZ!float).convertColor!(RGB8).tristimulus;
        enum r = rgb[0].value;
        enum g = rgb[1].value;
        enum b = rgb[2].value;

        stderr.writef!"\033[38;2;%s;%s;%sm"(r, g, b);
        static if(isSomeFunction!elem)
        {
            stderr.write("elem: ", elem(), " ");
        }else{
            enum name =  __traits(identifier, elem);
            stderr.write(name, ": ");
            stderr.write(elem, " ");
        }
    }
    void _debugPrint(int i, float rad, List...)()
    {
        _debugPrintElem!(List[0], i * rad)();
        static if(List.length>1)
        {
            _debugPrint!(i+1, rad, List[1..$])();
        }
    }

    debug(Local)
    {
        _debugPrint!(0, 360f/List.length, List)();
        stderr.writeln("\033[0m");
    }
}

struct Stack(Elem){
    private Elem[] array;
    private size_t endIdx;

    void insertBack(Elem e)
    {
        if(endIdx==array.length){
            array.length = array.length*2+10;
        }
        (array.ptr)[endIdx++] = e;
    }

    void insertBack(Range)(Range range)
    if(is(typeof(array[0] = range.popFront)))
    {
        if(endIdx+range.length>array.length){
            array.length = (endIdx+range.length)*2+10;
        }
        foreach(ref e;range)
        {
            (array.ptr)[endIdx++] = e;
        }
    }

    Elem[] opSlice(){
        return array[0..endIdx];
    }

    void popBack()
    {
        assert(endIdx!=0);
        endIdx--;
    }

    ref Elem back()
    {
        assert(endIdx!=0);
        return (array.ptr)[endIdx-1];
    }

    size_t count() const
    {
        return endIdx;
    }

    bool empty() const
    {
        return endIdx==0;
    }

    void clear()
    {
        endIdx = 0;
    }
}

Grid!T scanGrid(T=long)(long w, long h, dchar t='.')
{
    auto grid = Grid!T(w,h);
    foreach(y;0..h)
    {
        foreach(x;0..w)
        {
            grid[x, y] = scanElem!T;
        }
    }

    return grid;
}

Grid!bool scanGridBool(long w, long h, dchar t='.')
{
    auto grid = Grid!bool(w,h);
    foreach(y;0..h.to!size_t)
    {
        auto line = scanString;
        foreach(x;0..w.to!size_t)
        {
            grid[x, y] = line[x.to!size_t]==t;
        }
    }

    return grid;
}

T[] scanLineArray(T = long)()
{
    static char[] scanBuf;
    readln(scanBuf);
    return scanBuf.split.to!(T[]);
}

char scanChar()
{
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(char)c;
}

T[] scanElem(T=long)(long size)
{
    T[] list = new T[size.to!size_t];
    foreach(i;0..size.to!size_t)
    {
        list[i] = scanElem!T;
    }
    return list;
}

T scanElem(T)()
if(is(T==struct))
{
    T res;
    foreach(ref field; res.tupleof){
        field = scanElem!(typeof(field));
    }
    return res;
}

Tuple!List[] scanElem(List...)(long size)
{
    auto list = new Tuple!List[size.to!size_t];
    foreach(i;0..size.to!size_t)
    {
        list[i] = scanElem!List;
    }
    return list;
}
Tuple!List scanElem(List...)()
{
    List res;
    foreach(i, e; List){
        res[i] = scanElem!e;
    }
    return tuple(res);
}

T scanElem(T = long)()
if(isBasicType!T||isSomeString!T)
{
    import core.stdc.stdlib;
    static auto scanBuf = appender!(char[])([]);

    scanBuf.clear;

    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        scanBuf ~= cast(char) c;
        c = getchar;
    }
    return scanBuf.data.to!T;
}

string scanString(){
    return scanElem!string;
}

CommonType!(A,B) gcd(A,B)(A a, B b) pure
if(isIntegral!A&&isIntegral!B)
{
    if(b==0)return a;
    return gcd(b, a % b);
}

CommonType!(A,B) lcm(A,B)(A a, B b) pure
if(isIntegral!A&&isIntegral!B)
{
    return a / gcd(a, b) * b;
}

struct Factor
{
    long n;
    long c;
}

//素因数分解
Factor[] factors(long n) pure
{
    Factor[] res;
    for (long i = 2; i ^^ 2 <= n; i++)
    {
        if (n % i != 0)
            continue;

        long c;
        while (n % i == 0)
        {
            n = n / i;
            c++;
        }
        res ~= Factor(i, c);
    }
    if (n != 1)
        res ~= Factor(n, 1);

    return res;
}
//約数をすべて列挙
long[] divisors(long n) pure
{
    long[] list;
    void func(Factor[] fs, long n)
    {
        if(fs.empty){
            list ~= n;
            return;
        }

        foreach(c; 0..fs[0].c+1)
        {
            func(fs[1..$], n * (fs[0].n ^^ c));
        }
    }

    func(factors(n), 1);
    sort(list);
    return list;
}
//nまでの素数のリスト
long[] primes(long n) pure
{
    if(n<2)return [];

    auto table = new long[cast(size_t)n+1];

    long[] res;
    for(size_t i = 2;i<=n;i++)
    {
        if(table[i]==-1) continue;
        for(size_t a = i;a<table.length;a+=i)
        {
            table[a] = -1;
        }
        res ~= i;
    }
    return res;
}
//素数判定
bool isPrime(long n) pure
{
    if (n <= 1)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;
    for (long i = 3; i ^^ 2 <= n; i += 2)
        if (n % i == 0)
            return false;
    return true;
}

//桁を数える
long digitCount(long n, long base=10) pure
{
    long res;
    do{
        n/=base;
        res++;
    }while(n!=0);

    return res;
}

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

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

long test (in int a, in int b) {
  long res;
  long d = 10;
  while (d - 1 <= b) {
    res += a;
    d *= 10;
  }
  return res;
}

//a * b + a + b = conc (a, b)
//a * (b + 1) + b = conc (a, b)

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  auto ans = new long[nt];
  foreach (tid; 0 .. nt) {
    int a = r.next!int;
    int b = r.next!int;
    ans[tid] = test (a, b);
  }
  writefln! ("%(%s\n%)")(ans);
}

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 modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto A = RD;
		auto B = RD;
		auto x = B;
		long digit;
		while (x != 0)
		{
			x /= 10;
			++digit;
		}
		debug writeln(B, ":", 10^^(digit)-1);
		if (B == 10^^(digit)-1)
		{
			ans[ti] = A * digit;
		}
		else
		{
			ans[ti] = A * (digit-1);
		}
	}

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


PolandBall has an undirected simple graph consisting of n vertices. Unfortunately, it has no edges. The graph is very sad because of that. PolandBall wanted to make it happier, adding some red edges. Then, he will add white edges in every remaining place. Therefore, the final graph will be a clique in two colors: white and red. Colorfulness of the graph is a value min(dr, dw), where dr is the diameter of the red subgraph and dw is the diameter of white subgraph. The diameter of a graph is a largest value d such that shortest path between some pair of vertices in it is equal to d. If the graph is not connected, we consider its diameter to be -1.PolandBall wants the final graph to be as neat as possible. He wants the final colorfulness to be equal to k. Can you help him and find any graph which satisfies PolandBall's requests?

The only one input line contains two integers n and k (2 ≤ n ≤ 1000, 1 ≤ k ≤ 1000), representing graph's size and sought colorfulness.

If it's impossible to find a suitable graph, print -1. Otherwise, you can output any graph which fulfills PolandBall's requirements. First, output m — the number of red edges in your graph. Then, you should output m lines, each containing two integers ai and bi, (1 ≤ ai, bi ≤ n, ai ≠ bi) which means that there is an undirected red edge between vertices ai and bi. Every red edge should be printed exactly once, you can print the edges and the vertices of every edge in arbitrary order. Remember that PolandBall's graph should remain simple, so no loops or multiple edges are allowed.

NoteIn the first sample case, no graph can fulfill PolandBall's requirements.In the second sample case, red graph is a path from 1 to 5. Its diameter is 4. However, white graph has diameter 2, because it consists of edges 1-3, 1-4, 1-5, 2-4, 2-5, 3-5.

import core.bitop;
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	int n;
	int k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		debug {writeln (n, " ", k, ":");}
		if (k < 2)
		{
			writeln (-1);
			continue;
		}
		if (k > 3)
		{
			writeln (-1);
			continue;
		}
		if (n == 2)
		{
			writeln (-1);
			continue;
		}
		if (n == 3)
		{
			writeln (-1);
			continue;
		}
		if (n == 4)
		{
			if (k == 3)
			{
				writeln (3);
				writeln (1, " ", 2);
				writeln (2, " ", 3);
				writeln (3, " ", 4);
				continue;
			}
			else
			{
				writeln (-1);
				continue;
			}
		}
		if (k == 3)
		{
			if (n == 5)
			{
				writeln (5);
				writeln (1, " ", 2);
				writeln (2, " ", 3);
				writeln (3, " ", 4);
				writeln (2, " ", 5);
				writeln (3, " ", 5);
				continue;
			}
			else
			{
				int [2] [] ans;
				int lo = n / 2;
				for (int i = 0; i < lo; i++)
				{
					for (int j = i + 1; j < lo; j++)
					{
						ans ~= [i, j];
					}
				}
				ans ~= [lo - 1, lo];
				for (int i = lo; i < n; i++)
				{
					for (int j = i + 1; j < n; j++)
					{
						ans ~= [i, j];
					}
				}
				writeln (ans.length);
				foreach (c; ans)
				{
					writeln (c[0] + 1, " ", c[1] + 1);
				}
				continue;
			}
		}
		writeln (n - 1);
		for (int i = 1; i < n; i++)
		{
			writeln (i, " ", i + 1);
		}
		continue;
	}
}

import core.bitop;
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	int n;
	int k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		debug {writeln (n, " ", k, ":");}
		if (k < 2)
		{
			writeln (-1);
			continue;
		}
		if (k > 3)
		{
			writeln (-1);
			continue;
		}
		if (n == 2)
		{
			writeln (-1);
			continue;
		}
		if (n == 3)
		{
			writeln (-1);
			continue;
		}
		if (n == 4)
		{
			if (k == 3)
			{
				writeln (3);
				writeln (1, " ", 2);
				writeln (2, " ", 3);
				writeln (3, " ", 4);
				continue;
			}
			else
			{
				writeln (-1);
				continue;
			}
		}
		if (k == 3)
		{
			if (n == 5)
			{
				writeln (5);
				writeln (1, " ", 2);
				writeln (2, " ", 3);
				writeln (3, " ", 4);
				writeln (2, " ", 5);
				writeln (3, " ", 5);
				continue;
			}
			else
			{
				writeln (-1);
				continue;
			}
		}
		writeln (n - 1);
		for (int i = 1; i < n; i++)
		{
			writeln (i, " ", i + 1);
		}
		continue;
	}
}

import core.bitop;
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	int n;
	int k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		debug {writeln (n, " ", k, ":");}
		if (k < 2)
		{
			writeln (-1);
			continue;
		}
		if (k > 3)
		{
			writeln (-1);
			continue;
		}
		if (n == 2)
		{
			writeln (-1);
			continue;
		}
		if (n == 3)
		{
			writeln (-1);
			continue;
		}
		if (n == 4)
		{
			if (k == 3)
			{
				writeln (3);
				writeln (1, " ", 2);
				writeln (2, " ", 3);
				writeln (3, " ", 4);
				continue;
			}
			else
			{
				writeln (-1);
				continue;
			}
		}
		if (k == 3)
		{
			if (n == 5)
			{
				writeln (5);
				writeln (1, " ", 2);
				writeln (2, " ", 3);
				writeln (3, " ", 4);
				writeln (2, " ", 5);
				writeln (3, " ", 5);
				continue;
			}
			else
			{
				int [2] [] ans;
				int lo = n / 2;
				for (int i = 0; i < lo; i++)
				{
					for (int j = i + 1; j < lo; j++)
					{
						ans ~= [i, j];
					}
				}
				for (int i = lo; i < n; i++)
				{
					for (int j = i + 1; j < n; j++)
					{
						ans ~= [i, j];
					}
				}
				writeln (ans.length);
				foreach (c; ans)
				{
					writeln (c[0] + 1, " ", c[1] + 1);
				}
				continue;
			}
		}
		writeln (n - 1);
		for (int i = 1; i < n; i++)
		{
			writeln (i, " ", i + 1);
		}
		continue;
	}
}


Kamil likes streaming the competitive programming videos. His MeTube channel has recently reached $$$100$$$ million subscribers. In order to celebrate this, he posted a video with an interesting problem he couldn't solve yet. Can you help him?You're given a tree — a connected undirected graph consisting of $$$n$$$ vertices connected by $$$n - 1$$$ edges. The tree is rooted at vertex $$$1$$$. A vertex $$$u$$$ is called an ancestor of $$$v$$$ if it lies on the shortest path between the root and $$$v$$$. In particular, a vertex is an ancestor of itself.Each vertex $$$v$$$ is assigned its beauty $$$x_v$$$ — a non-negative integer not larger than $$$10^{12}$$$. This allows us to define the beauty of a path. Let $$$u$$$ be an ancestor of $$$v$$$. Then we define the beauty $$$f(u, v)$$$ as the greatest common divisor of the beauties of all vertices on the shortest path between $$$u$$$ and $$$v$$$. Formally, if $$$u=t_1, t_2, t_3, \dots, t_k=v$$$ are the vertices on the shortest path between $$$u$$$ and $$$v$$$, then $$$f(u, v) = \gcd(x_{t_1}, x_{t_2}, \dots, x_{t_k})$$$. Here, $$$\gcd$$$ denotes the greatest common divisor of a set of numbers. In particular, $$$f(u, u) = \gcd(x_u) = x_u$$$.Your task is to find the sum$$$$$$ \sum_{u\text{ is an ancestor of }v} f(u, v). $$$$$$As the result might be too large, please output it modulo $$$10^9 + 7$$$.Note that for each $$$y$$$, $$$\gcd(0, y) = \gcd(y, 0) = y$$$. In particular, $$$\gcd(0, 0) = 0$$$.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 100\,000$$$) — the number of vertices in the tree. The following line contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$0 \le x_i \le 10^{12}$$$). The value $$$x_v$$$ denotes the beauty of vertex $$$v$$$. The following $$$n - 1$$$ lines describe the edges of the tree. Each of them contains two integers $$$a, b$$$ ($$$1 \le a, b \le n$$$, $$$a \neq b$$$) — the vertices connected by a single edge.

Output the sum of the beauties on all paths $$$(u, v)$$$ such that $$$u$$$ is ancestor of $$$v$$$. This sum should be printed modulo $$$10^9 + 7$$$.

NoteThe following figure shows all $$$10$$$ possible paths for which one endpoint is an ancestor of another endpoint. The sum of beauties of all these paths is equal to $$$42$$$:

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

immutable int mod = 10 ^^ 9 + 7;
immutable int NA = -1;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto x = readln.splitter.map !(to !(long)).array;
		auto g = new int [] [n];
		foreach (i; 0..n - 1)
		{
			int u, v;
			readf (" %s %s", &u, &v);
			u -= 1;
			v -= 1;
			g[u] ~= v;
			g[v] ~= u;
		}

		int res = 0;

		void recur (int v, int p, int [long] s)
		{
			int [long] t;
			t[x[v]] = 1;
			foreach (k, w; s)
			{
				auto r = gcd (k, x[v]);
				t[r] += w;
			}
			foreach (k, w; t)
			{
				res = (res + k * w) % mod;
			}
			foreach (u; g[v])
			{
				if (u != p)
				{
					recur (u, v, t);
				}
			}
		}

		recur (0, NA, null);
		writeln (res);
	}
}

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

void main () {
	auto n = readln.strip.to !(int);
	auto x = readln.splitter.map !(to !(long)).array;
	auto g = new int [] [n];
	foreach (i; 0..n - 1) {
		int u, v;
		readf (" %s %s", &u, &v);
		u -= 1;
		v -= 1;
		g[u] ~= v;
		g[v] ~= u;
	}

	int res = 0;

	void recur (int v, int p, int [long] s) {
		int [long] t;
		t[x[v]] = 1;
		foreach (k, w; s) t[gcd (k, x[v])] += w;
		foreach (k, w; t) res = (res + k * w) % (10 ^^ 9 + 7);
		foreach (u; g[v]) if (u != p) recur (u, v, t);
	}

	recur (0, -1, null);
	writeln (res);
}

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

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

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

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

	foreach(i; 0 .. n - 1){
		int a = rint - 1, b = rint - 1;
		nodes[a].nodes ~= nodes[b];
		nodes[b].nodes ~= nodes[a];
	}

	nodes[0].treefy(null);

	Finite ans = nodes[0].calc;

	ans.writeln;
}
/*
Tree DP.

*/
class Node{
	int id;
	static long k;
	Node[] nodes;
	Node[] kids;
	Node parent;
	bool isVisited;
	long value;
	this(int id, long value){
		this.id = id;
		this.value = value;
	}
	void treefy(Node parent){
		this.parent = parent;
		foreach(nd; nodes) if(!parent || nd.id != parent.id) this.kids ~= nd, nd.treefy(this);
	}
	P[] points;
	Finite calc(){
		Finite res = Finite(0);
		this.points = [];
		P[] parpoints = [];
		if(parent) parpoints = parent.points;
		foreach(p; parpoints){
			long d = gcd(p.value, this.value);
			if(points.length && points[$ - 1].value == d){
				points[$ - 1] = P(d, points[$ - 1].count + p.count);
			}
			else{
				points ~= P(d, p.count);
			}
		}
		points ~= P(this.value, 1);

		foreach(p; this.points){
			res += p.value * p.count;
		}
		log("id:", (id + 1), "value:", value, "points:", points, "res:", res);

		foreach(kid; kids){
			res += kid.calc();
		}

		return res;
	}
	override string toString(){
		return "id:" ~ id.to!string ~ " value:" ~ value.to!string ~ " kids:" ~ kids.map!(x => x.id).to!string;
	}
}
struct P{
	long value, count;
}

// --------

import std.conv;
struct Finite{
	ulong value; static ulong mod = 1_000_000_007;
	private static ulong[] _inv = [0, 1], _frac = [1, 1], _invfrac = [1, 1];
	this(ulong v){ value = v % mod; }
	bool opCast(T: bool)(){ return value != 0; }
	Finite opUnary(string s){ ulong v;
		if(s == "+") v = value;
		else if(s == "-") v = mod - value;
		else if(s == "++") v = value + 1;
		else if(s == "--") v = value + mod - 1;
		else assert(0, "Operator unary " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opBinary(string s)(Finite b){
		return opBinary!s(b.value);
	}
	Finite opBinary(string s)(ulong u){ ulong v;
		if(s == "+") v = value + u;
		else if(s == "-") v = value + mod - u;
		else if(s == "*") v = value * u;
		else if(s == "/") v = value * inv(u);
		else assert(0, "Operator " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opBinaryRight(string s)(ulong u){ ulong v;
		if(s == "+") v = u + value;
		else if(s == "-") v = u + mod - value;
		else if(s == "*") v = u * value;
		else if(s == "/") v = u * invvalue;
		else assert(0, "Operator " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opAssign(ulong v){ value = v; return this; }
	Finite opOpAssign(string s)(Finite b){
		return opOpAssign!s(b.value);
	}
	Finite opOpAssign(string s)(ulong v){
		if(s == "+") value = (value + v) % mod;
		else if(s == "-") value = (value + mod - v) % mod;
		else if(s == "*") value = (value * v) % mod;
		else if(s == "/") value = (value * inv(v)) % mod;
		else assert(0, "Operator " ~ s ~ "= not implemented");
		return this;
	}
	bool opEquals(Finite b){
		return(value == b.value);
	}
	string toString(){ return value.to!string; }
	ulong inv(ulong v){
		assert(v > 0);
		assert(v < mod);
		while(v >= _inv.length){
			_inv ~= _inv[mod % $] * (mod - mod / _inv.length) % mod;
		}
		return _inv[v.to!uint];
	}
	ulong invvalue(){
		return inv(value);
	}
	static Finite opCall(ulong v){
		return Finite(v);
	}

}

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

long gcd(long a, long b){ // OK with 0, non-negative
	if(a < 0) return gcd(-a, b);
	if(b < 0) return gcd(a, -b);
	if(a == 0) return b;
	if(b == 0) return a;
	if(a % b == 0) return b;
	if(a < b) return gcd(b, a);
	else return gcd(b, a % b);
}

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

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

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

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

struct ModInt(long M) {
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt opUnary(string op)() const if (op == "-") { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const { return mixin("ModInt(this) " ~ op ~ "= a"); }
  ModInt opBinaryRight(string op)(long a) const { return mixin("ModInt(a) " ~ op ~ "= this"); }
  string toString() const { return x.to!string; }
}

enum MO = 10L^^9 + 7;
alias Mint = ModInt!MO;

enum E = 17;

int N;
long[] X;
int[] A, B;

int[][] G;
int[][] par;

void dfs(int u, int p) {
  par[0][u] = p;
  foreach (v; G[u]) {
    if (v != p) {
      dfs(v, u);
    }
  }
}

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

      G = new int[][N];
      foreach (i; 0 .. N - 1) {
        G[A[i]] ~= B[i];
        G[B[i]] ~= A[i];
      }
      par = new int[][](E, N + 1);
      dfs(0, N);
      par[0][N] = N;
      foreach (e; 0 .. E - 1) {
        foreach (u; 0 .. N + 1) {
          par[e + 1][u] = par[e][par[e][u]];
        }
      }

      auto ds = new long[][](E, N);
      foreach (u; 0 .. N) {
        const v = par[0][u];
        ds[0][u] = (v == N) ? 0 : X[v];
      }
      foreach (e; 0 .. E - 1) {
        foreach (u; 0 .. N) {
          const v = par[e][u];
          ds[e + 1][u] = (v == N) ? ds[e][u] : gcd(ds[e][u], ds[e][v]);
        }
      }
      debug {
        foreach (e; 0 .. 4) {
          writeln(par[e]);
          writeln(ds[e]);
        }
      }

      Mint ans;
      foreach (u; 0 .. N) {
        long g = X[u];
        int v = u;
        for (; ; ) {
          long sum;
          foreach_reverse (e; 0 .. E) {
            const w = par[e][v];
            if (w != N) {
              // gcd(g, ds[e][v]) == g
              if ((g == 0) ? (ds[e][v] == 0) : (ds[e][v] % g == 0)) {
                sum |= 1 << e;
                v = w;
              }
            }
          }
          ans += g * Mint(sum + 1);
          v = par[0][v];
          if (v == N) {
            break;
          }
          g = gcd(g, X[v]);
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Slime has a sequence of positive integers $$$a_1, a_2, \ldots, a_n$$$.In one operation Orac can choose an arbitrary subsegment $$$[l \ldots r]$$$ of this sequence and replace all values $$$a_l, a_{l + 1}, \ldots, a_r$$$ to the value of median of $$$\{a_l, a_{l + 1}, \ldots, a_r\}$$$.In this problem, for the integer multiset $$$s$$$, the median of $$$s$$$ is equal to the $$$\lfloor \frac{|s|+1}{2}\rfloor$$$-th smallest number in it. For example, the median of $$$\{1,4,4,6,5\}$$$ is $$$4$$$, and the median of $$$\{1,7,5,8\}$$$ is $$$5$$$.Slime wants Orac to make $$$a_1 = a_2 = \ldots = a_n = k$$$ using these operations.Orac thinks that it is impossible, and he does not want to waste his time, so he decided to ask you if it is possible to satisfy the Slime's requirement, he may ask you these questions several times.

The first line of the input is a single integer $$$t$$$: the number of queries. The first line of each query contains two integers $$$n\ (1\le n\le 100\,000)$$$ and $$$k\ (1\le k\le 10^9)$$$, the second line contains $$$n$$$ positive integers $$$a_1,a_2,\dots,a_n\ (1\le a_i\le 10^9)$$$ The total sum of $$$n$$$ is at most $$$100\,000$$$.

The output should contain $$$t$$$ lines. The $$$i$$$-th line should be equal to 'yes' if it is possible to make all integers $$$k$$$ in some number of operations or 'no', otherwise. You can print each letter in lowercase or uppercase.

NoteIn the first query, Orac can't turn all elements into $$$3$$$.In the second query, $$$a_1=6$$$ is already satisfied.In the third query, Orac can select the complete array and turn all elements into $$$2$$$.In the fourth query, Orac can't turn all elements into $$$3$$$.In the fifth query, Orac can select $$$[1,6]$$$ at first and then select $$$[2,10]$$$.

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

bool solve (R) (R a, int n, int k)
{
	if (a.length == 1)
	{
		return k == a.front;
	}
	if (!a.canFind (k))
	{
		return false;
	}
	if (a.length == 2)
	{
		return sum (a) >= 2 * k;
	}
	foreach (i; 0..n - 2)
	{
		if ((a[i] >= k) + (a[i + 1] >= k) + (a[i + 2] >= k) >= 2)
		{
			return true;
		}
	}
	return false;
}

void main ()
{
	readln;
	int n, k;
	while (readf !(" %s %s") (n, k) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		writeln (solve (a, n, k) ? "yes" : "no");
	}
}

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

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

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

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

bool solve(int[] as) {
  const n = cast(int)(as.length);
  const cnt1 = as.count(1);
  if (cnt1 == 0) {
    return false;
  }
  if (cnt1 == n) {
    return true;
  }
  foreach (i; 0 .. n - 2 + 1) {
    if (as[i] >= 1 && as[i + 1] >= 1) {
      return true;
    }
  }
  foreach (i; 0 .. n - 3 + 1) {
    if (as[i] >= 1 && as[i + 2] >= 1) {
      return true;
    }
  }
  return false;
}

void main() {
  debug {
    enum lim = 8;
    foreach (n; 1 .. lim + 1) {
      auto graph = new int[][3^^n];
      foreach (u; 0 .. 3^^n) {
        auto as = new int[n];
        foreach (i; 0 .. n) {
          as[i] = u / 3^^i % 3;
        }
        foreach (i; 0 .. n) foreach (j; i + 1 .. n + 1) {
          auto bs = as[i .. j].dup;
          bs.sort;
          auto cs = as.dup;
          cs[i .. j] = bs[($ + 1) / 2 - 1];
          int v;
          foreach_reverse (k; 0 .. n) {
            v = v * 3 + cs[k];
          }
          graph[v] ~= u;
        }
      }
      int start;
      foreach_reverse (i; 0 .. n) {
        start = start * 3 + 1;
      }
      DList!int que;
      auto vis = new bool[3^^n];
      vis[start] = true;
      que ~= start;
      for (; !que.empty; ) {
        const u = que.front;
        que.removeFront;
        foreach (v; graph[u]) {
          if (!vis[v]) {
            vis[v] = true;
            que ~= v;
          }
        }
      }
      foreach (u; 0 .. 3^^n) {
        auto as= new int[n];
        foreach (i; 0 .. n) {
          as[i] = u / 3^^i % 3;
        }
        const res = solve(as);
        if (vis[u] != res) {
          foreach (i; 0 .. n) {
            write(as[i]);
          }
          writeln();
          writeln(vis[u], " ", res);
          assert(false);
        }
      }
    }
  }

  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const N = readInt();
        const K = readInt();
        auto A = new int[N];
        foreach (i; 0 .. N) {
          A[i] = readInt();
        }

        auto ss = new int[N];
        foreach (i; 0 .. N) {
          ss[i] = (A[i] < K) ? 0 : (A[i] == K) ? 1 : 2;
        }
        const ans = solve(ss);
        writeln(ans ? "yes" : "no");
      }
    }
  } catch (EOFException e) {
  }
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_t; 0..T) {
        auto nk = readln.split.to!(int[]);
        auto N = nk[0];
        auto K = nk[1];
        int[] as;
        bool has;
        foreach (a; readln.split.to!(int[])) {
            if (a == K) has = true;
            as ~= a;
        }
        if (!has) {
            writeln("no");
            continue;
        }
        if (N == 1) {
            writeln(has ? "yes" : "no");
            continue;
        }
        foreach (i, a; as[0..$-1]) {
            if (a == K) {
                if (as[i+1] >= K) goto ok;
                if (i+2 < N && as[i+2] >= K) goto ok;
            } else if (a > K) {
                if (as[i+1] >= K) goto ok;
                if (i+2 < N && as[i+2] >= K) goto ok;
            }
        }
        writeln("no");
        continue;
        ok:
        writeln("yes");
    }
}

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

bool solve (R) (R a, int n, int k)
{
	if (a.length == 1)
	{
		return k == a.front;
	}
	if (!a.canFind (k))
	{
		return false;
	}
	foreach (i; 0..n - 2)
	{
		if ((a[i] >= k) + (a[i + 1] >= k) + (a[i + 2] >= k) >= 2)
		{
			return true;
		}
	}
	return false;
}

void main ()
{
	readln;
	int n, k;
	while (readf !(" %s %s") (n, k) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		writeln (solve (a, n, k) ? "yes" : "no");
	}
}

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

bool solve (R) (R a, int k)
{
	if (a.length < 2)
	{
		return k == a.front;
	}
	int lo = 0;
	int me = 0;
	int hi = 0;
	// k = 3
	// 3 x
	// 3 1 x
	// 3 1 3 v
	// 3 5 v
	foreach (ref c; a.find (k))
	{
		lo += (c < k);
		me += (c == k);
		hi += (c > k);
		int n = lo + me + hi;
		writeln (lo, " ", me, " ", hi);
		if (n > 1 && lo <= (n - 1) / 2 && lo + me > (n - 1) / 2)
		{
			return true;
		}
		if (c == k)
		{
			lo = 0;
			me = 1;
			hi = 0;
		}
	}
	return false;
}

void main ()
{
	readln;
	int n, k;
	while (readf !(" %s %s") (n, k) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		writeln (solve (a, k) || solve (a.retro, k) ? "yes" : "no");
	}
}

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

bool solve (R) (R a, int k)
{
	if (a.length < 2)
	{
		return k == a.front;
	}
	int lo = 0;
	int me = 0;
	int hi = 0;
	foreach (ref c; a.find (k))
	{
		lo += (c < k);
		me += (c == k);
		hi += (c > k);
		int n = lo + me + hi;
		if (n > 1 && lo <= (n - 1) / 2 && lo + me > (n - 1) / 2)
		{
			return true;
		}
		if (c == k)
		{
			lo = 0;
			me = 1;
			hi = 0;
		}
	}
	return false;
}

void main ()
{
	readln;
	int n, k;
	while (readf !(" %s %s") (n, k) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		writeln (solve (a, k) || solve (a.retro, k) ? "yes" : "no");
	}
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_t; 0..T) {
        auto nk = readln.split.to!(int[]);
        auto N = nk[0];
        auto K = nk[1];
        int[] as;
        size_t[] kis = [0];
        foreach (i, a; readln.split.to!(int[])) {
            as ~= a;
            if (a == K) kis ~= i;
        }
        if (N == 1) {
            writeln(as[0] == K ? "yes" : "no");
            continue;
        }
        if (kis.length == 1) {
            writeln("no");
            continue;
        }
        foreach (i, s; kis[1..$]) {
            int x;
            foreach_reverse (j; kis[i]+1..s) {
                if (as[j] >= K) {
                    ++x;
                } else {
                    --x;
                }
                if (x >= 0) goto ok;
            }
        }
        kis = kis[1..$] ~ N.to!size_t;
        foreach (i, s; kis[0..$-1]) {
            int x;
            foreach (j; s+1..kis[i+1]) {
                if (as[j] >= K) {
                    ++x;
                } else {
                    --x;
                }
                if (x >= 0) goto ok;
            }
        }
        writeln("no");
        continue;
        ok:
        writeln("yes");
    }
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_t; 0..T) {
        auto nk = readln.split.to!(int[]);
        auto N = nk[0];
        auto K = nk[1];
        int[] as;
        size_t[] kis = [0];
        foreach (i, a; readln.split.to!(int[])) {
            as ~= a;
            if (a == K) kis ~= i;
        }
        if (N == 1) {
            writeln(as[0] == K ? "yes" : "no");
            continue;
        }
        if (kis.length == 1) {
            writeln("no");
            continue;
        }
        foreach (i, s; kis[1..$]) {
            int x;
            foreach_reverse (j; kis[i]..s) {
                if (as[j] >= K) {
                    ++x;
                } else {
                    --x;
                }
                if (x >= 0) goto ok;
            }
        }
        kis ~= (N-1).to!size_t;
        kis = kis[1..$];
        foreach (i, s; kis[0..$-1]) {
            int x;
            foreach (j; s+1..kis[i+1]+1) {
                if (as[j] >= K) {
                    ++x;
                } else {
                    --x;
                }
                if (x >= 0) goto ok;
            }
        }
        writeln("no");
        continue;
        ok:
        writeln("yes");
    }
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_t; 0..T) {
        auto nk = readln.split.to!(int[]);
        auto N = nk[0];
        auto K = nk[1];
        int[] as;
        size_t[] kis;
        foreach (i, a; readln.split.to!(int[])) {
            as ~= a;
            if (a == K) kis ~= i;
        }
        if (N == 1) {
            writeln(as[0] == K ? "yes" : "no");
            continue;
        }
        if (kis.empty) {
            writeln("no");
            continue;
        }
        if (kis[0] != 0) {
            int x;
            foreach_reverse (i; 0..kis[0]) {
                if (as[i] >= K) {
                    ++x;
                } else {
                    --x;
                }
                if (x >= 0) goto ok;
            }
        }
        kis ~= (N-1).to!size_t;
        foreach (i, s; kis[0..$-1]) {
            int x;
            foreach (j; s+1..kis[i+1]+1) {
                if (as[j] >= K) {
                    ++x;
                } else {
                    --x;
                }
                if (x >= 0) goto ok;
            }
        }
        writeln("no");
        continue;
        ok:
        writeln("yes");
    }
}


Asya loves animals very much. Recently, she purchased $$$n$$$ kittens, enumerated them from $$$1$$$ and $$$n$$$ and then put them into the cage. The cage consists of one row of $$$n$$$ cells, enumerated with integers from $$$1$$$ to $$$n$$$ from left to right. Adjacent cells had a partially transparent partition wall between them, hence there were $$$n - 1$$$ partitions originally. Initially, each cell contained exactly one kitten with some number.Observing the kittens, Asya noticed, that they are very friendly and often a pair of kittens in neighboring cells wants to play together. So Asya started to remove partitions between neighboring cells. In particular, on the day $$$i$$$, Asya:  Noticed, that the kittens $$$x_i$$$ and $$$y_i$$$, located in neighboring cells want to play together.  Removed the partition between these two cells, efficiently creating a single cell, having all kittens from two original cells. Since Asya has never putted partitions back, after $$$n - 1$$$ days the cage contained a single cell, having all kittens.For every day, Asya remembers numbers of kittens $$$x_i$$$ and $$$y_i$$$, who wanted to play together, however she doesn't remember how she placed kittens in the cage in the beginning. Please help her and find any possible initial arrangement of the kittens into $$$n$$$ cells.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 150\,000$$$) — the number of kittens. Each of the following $$$n - 1$$$ lines contains integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$, $$$x_i \ne y_i$$$) — indices of kittens, which got together due to the border removal on the corresponding day. It's guaranteed, that the kittens $$$x_i$$$ and $$$y_i$$$ were in the different cells before this day.

For every cell from $$$1$$$ to $$$n$$$ print a single integer — the index of the kitten from $$$1$$$ to $$$n$$$, who was originally in it. All printed integers must be distinct. It's guaranteed, that there is at least one answer possible. In case there are multiple possible answers, print any of them.

NoteThe answer for the example contains one of several possible initial arrangements of the kittens.The picture below shows how the cells were united for this initial arrangement. Note, that the kittens who wanted to play together on each day were indeed in adjacent cells.

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 uf = new UnionFind(N);

    foreach (_; 0..N-1) {
        auto s = readln.split.map!(to!int);
        uf.unite(s[0]-1, s[1]-1);
    }

    uf.group[uf.find(0)].map!(i => (i + 1).to!string).join(" ").writeln;
}

class UnionFind {
    int N;
    int[] table;
    int[][] group;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
        group = N.iota.map!(i => [i]).array;
    }

    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);
        group[x] ~= group[y];
        group[y] = [];
        table[x] += table[y];
        table[y] = x;
    }
}


Let's define a balanced multiset the following way. Write down the sum of all elements of the multiset in its decimal representation. For each position of that number check if the multiset includes at least one element such that the digit of the element and the digit of the sum at that position are the same. If that holds for every position, then the multiset is balanced. Otherwise it's unbalanced.For example, multiset $$$\{20, 300, 10001\}$$$ is balanced and multiset $$$\{20, 310, 10001\}$$$ is unbalanced:   The red digits mark the elements and the positions for which these elements have the same digit as the sum. The sum of the first multiset is $$$10321$$$, every position has the digit required. The sum of the second multiset is $$$10331$$$ and the second-to-last digit doesn't appear in any number, thus making the multiset unbalanced.You are given an array $$$a_1, a_2, \dots, a_n$$$, consisting of $$$n$$$ integers.You are asked to perform some queries on it. The queries can be of two types:  $$$1~i~x$$$ — replace $$$a_i$$$ with the value $$$x$$$;  $$$2~l~r$$$ — find the unbalanced subset of the multiset of the numbers $$$a_l, a_{l + 1}, \dots, a_r$$$ with the minimum sum, or report that no unbalanced subset exists. Note that the empty multiset is balanced.For each query of the second type print the lowest sum of the unbalanced subset. Print -1 if no unbalanced subset exists.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the number of elements in the array and the number of queries, respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i < 10^9$$$). Each of the following $$$m$$$ lines contains a query of one of two types:   $$$1~i~x$$$ ($$$1 \le i \le n$$$, $$$1 \le x < 10^9$$$) — replace $$$a_i$$$ with the value $$$x$$$;  $$$2~l~r$$$ ($$$1 \le l \le r \le n$$$) — find the unbalanced subset of the multiset of the numbers $$$a_l, a_{l + 1}, \dots, a_r$$$ with the lowest sum, or report that no unbalanced subset exists.  It is guaranteed that there is at least one query of the second type.

NoteAll the subsets of multiset $$$\{20, 300, 10001\}$$$ are balanced, thus the answer is -1.The possible unbalanced subsets in the third query are $$$\{20, 310\}$$$ and $$$\{20, 310, 10001\}$$$. The lowest sum one is $$$\{20, 310\}$$$. Note that you are asked to choose a subset, not a subsegment, thus the chosen elements might not be adjancent in the array.The fourth query includes only the empty subset and subset $$$\{20\}$$$. Both of them are balanced.The last query includes the empty subset and the subsets $$$\{20\}$$$, $$$\{20\}$$$ and $$$\{20, 20\}$$$. Only $$$\{20, 20\}$$$ is unbalanced, its sum is $$$40$$$. Note that you are asked to choose a multiset, thus it might include equal elements.

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 s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = readln.split.map!(to!int).array;

    alias SegTree = SegmentTree!(int[2], (a,b)=>a[0]<=b[0]?a:b, [int.max, 0]);
    auto st = new SegTree[](9);
    foreach (i; 0..9) st[i] = new SegTree(N);

    pragma(inline, true)
    void set(int idx, int orgval) {
        int val = orgval;
        foreach (i; 0..9) {
            st[i].modify(idx, val % 10 == 0 ? [int.max, idx] : [orgval, idx]);
            val /= 10;
        }
    }

    pragma(inline, true)
    int calc(int left, int right) {
        int ans = int.max;
        foreach (i; 0..9) {
            auto t1 = st[i].query(left, right + 1);
            auto m1 = t1[0];
            auto idx = t1[1];
            if (m1 == int.max) continue;
            auto m2 = min(st[i].query(left, idx)[0], st[i].query(idx + 1, right + 1)[0]);
            if (m2 == int.max) continue;
            ans = min(ans, m1 + m2);
        }
        return ans;
    }

    foreach (i; 0..N) set(i, A[i]);

    while (M--) {
        auto q = readln.split.map!(to!int).array;
        if (q[0] == 1) {
            auto idx = q[1] - 1;
            auto val = q[2];
            set(idx, val);
        } else {
            auto left = q[1] - 1;
            auto right = q[2] - 1;
            int ans = calc(left, right);
            (ans == int.max ? -1 : ans).writeln;
        }
    }
}

class SegmentTree(T, alias op, T e) {
    int n;
    T[] table;

    this(int n) {
        this.n = n;
        table = new T[](2 * n);
        table[] = e;
    }

    void modify(int p, T value) {
        for (table[p += n] = value; p > 1; p >>= 1) table[p>>1] = op(table[p], table[p^1]);
    }

    T query(int l, int r) { //[l, r)
        if (r <= l) return e;
        T res = e;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l&1) res = op(res, table[l++]);
            if (r&1) res = op(res, table[--r]);
        }
        return res;
    }
}


One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior.We will call person a a subordinates of another person b, if either b is an immediate supervisor of a, or the immediate supervisor of a is a subordinate to person b. In particular, subordinates of the head are all other employees of the company.To solve achieve an Important Goal we need to form a workgroup. Every person has some efficiency, expressed by a positive integer ai, where i is the person's number. The efficiency of the workgroup is defined as the total efficiency of all the people included in it.The employees of the big software company are obsessed with modern ways of work process organization. Today pair programming is at the peak of popularity, so the workgroup should be formed with the following condition. Each person entering the workgroup should be able to sort all of his subordinates who are also in the workgroup into pairs. In other words, for each of the members of the workgroup the number of his subordinates within the workgroup should be even.Your task is to determine the maximum possible efficiency of the workgroup formed at observing the given condition. Any person including the director of company can enter the workgroup.

The first line contains integer n (1 ≤ n ≤ 2·105) — the number of workers of the Big Software Company.  Then n lines follow, describing the company employees. The i-th line contains two integers pi, ai (1 ≤ ai ≤ 105) — the number of the person who is the i-th employee's immediate superior and i-th employee's efficiency. For the director p1 =  - 1, for all other people the condition 1 ≤ pi < i is fulfilled.

Print a single integer — the maximum possible efficiency of the workgroup.

NoteIn the sample test the most effective way is to make a workgroup from employees number 1, 2, 4, 5, 6.

import std.algorithm;
import std.range;
import std.stdio;

immutable int NA = -1;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [] [n];
		auto p = new int [n];
		auto c = new int [n];
		int r = NA;
		foreach (i; 0..n)
		{
			readf (" %s %s", &p[i], &c[i]);
			if (p[i] == NA)
			{
				r = i;
			}
			else
			{
				p[i]--;
				a[p[i]] ~= i;
			}
		}
		assert (r != NA);

		auto d = new long [2] [n];

		foreach_reverse (v; 0..n)
		{
			d[v][0] = 0;
			d[v][1] = long.min / 2;
			foreach (u; a[v])
			{
				auto d0 = d[v][0];
				auto d1 = d[v][1];
				d[v][0] = max (d0 + d[u][0], d1 + d[u][1]);
				d[v][1] = max (d0 + d[u][1], d1 + d[u][0]);
			}
			d[v][1] = max (d[v][1], d[v][0] + c[v]);
		}

		writeln (max (d[r][0], d[r][1]));
	}
}

import std.algorithm;
import std.range;
import std.stdio;

immutable int NA = -1;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [] [n];
		auto p = new int [n];
		auto c = new int [n];
		int r = NA;
		foreach (i; 0..n)
		{
			readf (" %s %s", &p[i], &c[i]);
			if (p[i] == NA)
			{
				r = i;
			}
			else
			{
				p[i]--;
				a[p[i]] ~= i;
			}
		}
		assert (r != NA);

		auto d = new long [2] [n];

		void recur (int v)
		{
			d[v][0] = 0;
			d[v][1] = long.min / 2;
			foreach (u; a[v])
			{
				recur (u);
				auto d0 = d[v][0];
				auto d1 = d[v][1];
				d[v][0] = max (d0 + d[u][0], d1 + d[u][1]);
				d[v][1] = max (d0 + d[u][1], d1 + d[u][0]);
			}
			auto d0 = d[v][0];
			auto d1 = d[v][1];
			d[v][0] = max (d0, d1);
			d[v][1] = d0 + c[v];
		}

		recur (r);
		writeln (max (d[r][0], d[r][1]));
	}
}

import std.algorithm;
import std.range;
import std.stdio;

immutable int NA = -1;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [] [n];
		auto p = new int [n];
		auto c = new long [n];
		int r = NA;
		foreach (i; 0..n)
		{
			readf (" %s %s", &p[i], &c[i]);
			if (p[i] == NA)
			{
				r = i;
			}
			else
			{
				p[i]--;
				a[p[i]] ~= i;
			}
		}
		assert (r != NA);

		long res = 0;
		auto d = new long [n];

		void recur (int v)
		{
			long [] z;
			foreach (u; a[v])
			{
				recur (u);
				z ~= d[u];
			}
			sort (z);
			d[v] = c[v] + sum (z[$ & 1..$]);
			res = max (res, d[v]);
		}

		recur (r);
		writeln (res);
	}
}


A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment except root comments (comments of the highest level) has exactly one parent comment.When Polycarp wants to save comments to his hard drive he uses the following format. Each comment he writes in the following format:   at first, the text of the comment is written;  after that the number of comments is written, for which this comment is a parent comment (i. e. the number of the replies to this comments);  after that the comments for which this comment is a parent comment are written (the writing of these comments uses the same algorithm).  All elements in this format are separated by single comma. Similarly, the comments of the first level are separated by comma.For example, if the comments look like:  then the first comment is written as "hello,2,ok,0,bye,0", the second is written as "test,0", the third comment is written as "one,1,two,2,a,0,b,0". The whole comments feed is written as: "hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0". For a given comments feed in the format specified above print the comments in a different format:   at first, print a integer d — the maximum depth of nesting comments;  after that print d lines, the i-th of them corresponds to nesting level i;  for the i-th row print comments of nesting level i in the order of their appearance in the Policarp's comments feed, separated by space.

The first line contains non-empty comments feed in the described format. It consists of uppercase and lowercase letters of English alphabet, digits and commas.  It is guaranteed that each comment is a non-empty string consisting of uppercase and lowercase English characters. Each of the number of comments is integer (consisting of at least one digit), and either equals 0 or does not contain leading zeros. The length of the whole string does not exceed 106. It is guaranteed that given structure of comments is valid.

Print comments in a format that is given in the statement. For each level of nesting, comments should be printed in the order they are given in the input.

NoteThe first example is explained in the statements.

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

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

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

int pos;
string s;
string[ ][ ] result;
int resDepth;

void parse(int depth) {
    assert(pos < s.length);
    resDepth = max(resDepth, depth);
    if (depth == result.length)
        result ~= cast(string[ ])null;
    int comma = cast(int)(s.length - s[pos .. $].find(',').length);
    result[depth] ~= s[pos .. comma];
    pos = comma + 1;
    comma = cast(int)(s.length - s[pos .. $].find(',').length);
    int count = s[pos .. comma].to!int;
    pos = comma + 1;
    foreach (i; 0 .. count)
        parse(depth + 1);
}

void main() {
    while ((s = readln()).length > 1) {
        s = s[0 .. $ - 1];
        result = null;
        resDepth = 0;
        pos = 0;
        while (pos < s.length)
            parse(0);
        writeln(resDepth + 1);
        writefln("%(%-(%s %)\n%)", result);
    }
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,
std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio:freopen;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
immutable int mod=1000000007;
@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)
{
	return a/gcd(a,b)*b;
}
pure nothrow @property X binpow(X,Y)(X base,Y exp)
if(is(typeof(exp&1)))
{
	if(exp<0)return X(0);
	X res=X(1);
	while(exp>0)
	{
		if(exp&1)res*=base;
		base*=base;
		exp>>=1;
	}
	return res;
}
pure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
if(is(typeof(exp&1)))
{
	if(mm==0) return binpow(base,exp);
	if(exp<0)return X(0);
	auto res=X(1)%mm;
	while(exp>0)
	{
		if(exp&1)res=(res*base)%mm;
		base*=base;
		base%=mm;
		exp>>=1;
	}
	return res;
}
@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
@property void putarr(X)(X a,in int n,in int m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p)
	{
		fi=p.fi;
		se=p.se;
	}
	int opCmp(in pair!(X,Y) s_) const pure nothrow @safe
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
X sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}
X cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}
nothrow @nogc @system void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow @nogc @system void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
auto arread(T)(){return readln.split.map!(to!(T)).array;}
nothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (!(a[l]<g))?l:r;
}
pure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(g<a[m])r=m;
		else l=m;
	}
	return (g<a[l])?l:r;
}
pure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (g==a[l])?l:a.length;
}
pure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	return binf(a,g)!=a.length;
}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	string s;
	while((s=readln.strip)!="")
	{
		auto a=s.split(',').array;
		int pos,n=a.length;
		string[][] ans=new string[][1];
		auto u=new bool[n];
		void dfs(int lev)
		{
			if(pos==n)return;
			u[pos]=1;
			if(lev==ans.length)
			{
				ans.length++;
			}
			ans[lev]~=a[pos];
			int k=a[pos+1].to!int;
			pos+=2;
			foreach(i;0..k)
			{
				dfs(lev+1);
			}
			//pos-=2;
		}
		int pp=pos;
		for(;pp<n;pp+=2)
		{
			if(!u[pp]){pos=pp;dfs(0);}
			//debug writeln(pos);
		}
		writeln(ans.length);
		foreach(i;ans)
		{
			foreach(j;i)write(j,' ');
			writeln;
		}
		debug writeln("takt");
	}
	debug readln;
}


Nikita has a stack. A stack in this problem is a data structure that supports two operations. Operation push(x) puts an integer x on the top of the stack, and operation pop() deletes the top integer from the stack, i. e. the last added. If the stack is empty, then the operation pop() does nothing.Nikita made m operations with the stack but forgot them. Now Nikita wants to remember them. He remembers them one by one, on the i-th step he remembers an operation he made pi-th. In other words, he remembers the operations in order of some permutation p1, p2, ..., pm. After each step Nikita wants to know what is the integer on the top of the stack after performing the operations he have already remembered, in the corresponding order. Help him!

The first line contains the integer m (1 ≤ m ≤ 105) — the number of operations Nikita made. The next m lines contain the operations Nikita remembers. The i-th line starts with two integers pi and ti (1 ≤ pi ≤ m, ti = 0 or ti = 1) — the index of operation he remembers on the step i, and the type of the operation. ti equals 0, if the operation is pop(), and 1, is the operation is push(x). If the operation is push(x), the line also contains the integer xi (1 ≤ xi ≤ 106) — the integer added to the stack. It is guaranteed that each integer from 1 to m is present exactly once among integers pi.

Print m integers. The integer i should equal the number on the top of the stack after performing all the operations Nikita remembered on the steps from 1 to i. If the stack is empty after performing all these operations, print -1.

NoteIn the first example, after Nikita remembers the operation on the first step, the operation push(2) is the only operation, so the answer is 2. After he remembers the operation pop() which was done before push(2), answer stays the same.In the second example, the operations are push(2), push(3) and pop(). Nikita remembers them in the order they were performed.In the third example Nikita remembers the operations in the reversed order.

import core.bitop;
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int logN = 17;
immutable int medN = 1 << logN;
immutable int maxN = medN << 1;

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

		alias Entry = Tuple !(int, q{s}, int, q{m});
		auto t = new Entry [maxN];
		int total = 0;

		void add (int pos, int delta)
		{
			for (pos += medN; pos > 0; pos >>= 1)
			{
				t[pos].s += delta;
				if (pos < medN)
				{
					t[pos].m = min (t[pos * 2 + 0].m,
					    t[pos * 2 + 0].s +
					    t[pos * 2 + 1].m);
				}
				else
				{
					t[pos].m = min (0, t[pos].s);
				}
			}
			total += delta;
		}

		auto x = new int [n];
		foreach (r; 0..n)
		{
			auto v = readln.splitter.map !(to !(int)).array;
			int pos = v[0] - 1;
			int type = v[1];
			if (type == 0)
			{
				add (pos, -1);
			}
			else if (type == 1)
			{
				x[pos] = v[2];
				add (pos, +1);
			}
			else
			{
				assert (false);
			}

			int level = 0;
			int cur = 1;
			while (cur < medN)
			{
				int next0 = cur * 2 + 0;
				int next1 = cur * 2 + 1;
				if (level + t[next0].s + t[next1].m < total)
				{
					level += t[next0].s;
					cur = next1;
				}
				else
				{
					cur = next0;
				}
			}
			if (level == total - 1)
			{
				writeln (x[cur - medN]);
			}
			else
			{
				writeln (-1);
			}
		}
	}
}


Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu". Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something! Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result.

The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters.

Print the given string after it is processed. It is guaranteed that the result will contain at least one character.

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

void main() {
    string s = stdin.readln;
    Array!char a;
    foreach (c; s) {
        if (a.empty) { a.insert(c); }
        else if (a.back == c) { a.removeBack; }
        else { a.insert(c); }
    }
    foreach (c; a) {
        write(c);
    }
}

module cf_81A;

import std.stdio;

void main() {
    string text;

    readf("%s\n", &text);

    string optText = "";

    while (text.length > 0) {
        if (optText.length == 0) {
            optText ~= text[0];
        } else if (optText[$ - 1] == text[0]) {
            optText = optText[0 .. $ - 1];
        } else {
            optText ~= text[0];
        }

        text = text[1 .. $];
    }

    writeln(optText);
}


This is an interactive problem.Anton and Harris are playing a game to decide which of them is the king of problemsetting.There are three piles of stones, initially containing $$$a$$$, $$$b$$$, and $$$c$$$ stones, where $$$a$$$, $$$b$$$, and $$$c$$$ are distinct positive integers. On each turn of the game, the following sequence of events takes place:  The first player chooses a positive integer $$$y$$$ and provides it to the second player.  The second player adds $$$y$$$ stones to one of the piles, with the condition that he cannot choose the same pile in two consecutive turns. The second player loses if, at any point, two of the piles contain the same number of stones. The first player loses if $$$1000$$$ turns have passed without the second player losing.Feeling confident in his skills, Anton decided to let Harris choose whether he wants to go first or second. Help Harris defeat Anton and become the king of problemsetting!

The first line of input contains three distinct positive integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$)  — the initial number of stones in piles $$$1$$$, $$$2$$$, and $$$3$$$ respectively.

NoteIn the sample input, the piles initially have $$$5$$$, $$$2$$$, and $$$6$$$ stones. Harris decides to go first and provides the number $$$2$$$ to Anton. Anton adds $$$2$$$ stones to the third pile, which results in $$$5$$$, $$$2$$$, and $$$8$$$.In the next turn, Harris chooses $$$3$$$. Note that Anton cannot add the stones to the third pile since he chose the third pile in the previous turn. Anton realizes that he has no valid moves left and reluctantly recognizes Harris as the king.

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

void main ()
{
	auto a = readln.splitter.map !(to !(long)).array;
	auto p = 3.iota.array;
	writeln ("First");
	stdout.flush ();
	while (true)
	{
		schwartzSort !(i => a[i]) (p);
		long delta = a[p[2]] - a[p[0]] + a[p[2]] - a[p[1]];
		if (a[p[2]] - a[p[1]] == a[p[1]] - a[p[0]])
		{
			delta = a[p[2]] - a[p[1]];
		}
		writeln (delta);
		stdout.flush ();
		auto k = readln.strip.to !(int);
		if (k == 0)
		{
			break;
		}
		a[k - 1] += delta;
		debug {stderr.writeln (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() {
  auto A = new long[3];
  foreach (i; 0 .. 3) {
    A[i] = readLong();
  }
  writeln("First");
  stdout.flush;

  enum ini = 10L^^10;
  writeln(ini);
  stdout.flush;
  const i0 = readInt() - 1;
  if (i0 == -1) {
    return;
  }
  A[i0] += ini;
  debug {
    writeln("A = ", A);
  }

  auto a = A.dup;
  a.sort;
  const magic = (a[1] - a[0]) + 2 * (a[2] - a[1]);
  writeln(magic);
  stdout.flush;
  const i1 = readInt() - 1;
  if (i1 == -1) {
    return;
  }
  A[i1] += magic;
  debug {
    writeln("A = ", A);
  }

  auto b = A.dup;
  b.sort;
  assert(b[1] - b[0] == b[2] - b[1]);
  const diff = b[1] - b[0];
  writeln(diff);
  stdout.flush;
  const i2 = readInt() - 1;
  if (i2 == -1) {
    return;
  }
  assert(false);
}