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

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

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

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

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

alias Edge = Tuple!(int, "a", int, "b", long, "w");

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const M = readInt();
      auto E = new Edge[M];
      foreach (i; 0 .. M) {
        E[i].a = readInt() - 1;
        E[i].b = readInt() - 1;
        E[i].w = readLong();
      }

      E.sort!"a.w < b.w";

      auto uf = new int[N];
      uf[] = -1;
      auto ms = new int[N];
      long ans;
      foreach_reverse (ref e; E) {
        const ra = uf.root(e.a);
        const rb = uf.root(e.b);
        if (ra == rb) {
          if (ms[ra] < -uf[ra]) {
            debug {
              writeln(e, " make cycle");
            }
            ans += e.w;
            ++ms[ra];
          }
        } else {
          if (ms[ra] < -uf[ra] || ms[rb] < -uf[rb]) {
            debug {
              writeln(e, " connect");
            }
            ans += e.w;
            uf.connect(ra, rb);
            const int r = uf.root(ra);
            ms[r] = ms[ra] + ms[rb] + 1;
          }
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

/+ dub.sdl:
    name "F"
    dependency "dcomp" version=">=0.7.3"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
import std.typecons;

alias E = Tuple!(int, "to", int, "dist");
alias D = int;

int main() {
    Scanner sc = new Scanner(stdin);

    static struct PairingHeapAllAdd {
        alias NP = Node*;
        static struct Node {
            E e;
            D offset;
            NP head, next;
            this(E e) {
                this.e = e;
                offset = D(0);
            }
        }
        NP n;
        size_t length;
        this(E[] e) {
            length = e.length;
            foreach (d; e) {
                n = merge(n, new Node(d));
            }
        }
        static NP merge(NP x, NP y) {
            if (!x) return y;
            if (!y) return x;
            if (x.e.dist+x.offset < y.e.dist+y.offset) swap(x, y);
            y.offset -= x.offset;
            y.next = x.head;
            x.head = y;
            return x;
        }
        void C() { assert(n); }
        E front() {C; return n.e; }
        void removeFront() {
            assert(n);
            assert(length > 0);
            length--;
            NP x;
            NP s = n.head;
            while (s) {
                NP a, b;
                a = s; s = s.next; a.next = null; a.offset += n.offset;
                if (s) {
                    b = s; s = s.next; b.next = null; b.offset += n.offset;
                }
                a = merge(a, b);
                assert(a);
                if (!x) x = a;
                else {
                    a.next = x.next;
                    x.next = a;
                }
            }
            n = null;
            while (x) {
                NP a = x; x = x.next;
                n = merge(a, n);
            }
        }
        void meld(PairingHeapAllAdd r) {
            length += r.length;
            n = merge(n, r.n);
        }
        ref D offset() {C; return n.offset; }
    }

    int n, m;
    sc.read(n, m);
    E[][] g = new E[][n];
    foreach (i; 0..m) {
        int a, b, c;
        sc.read(a, b, c); a--; b--;
        g[a] ~= E(i, c);
        g[b] ~= E(i, c);
    }

    auto heap = new PairingHeapAllAdd[2*n];
    foreach (i; 0..n) {
//        writeln(i, " -> ", g[i]);
        heap[i] = PairingHeapAllAdd(g[i]);
    }

    int[] pre = new int[m]; pre[] = -1;
    bool[] fix = new bool[m];
    long sm = 0;
    int pc = n;
    foreach (i; 0..2*n) {
        if (i == pc) break;
        while (heap[i].length && fix[heap[i].front.to]) heap[i].removeFront;
        if (!heap[i].length) continue;
        auto e = heap[i].front;
        int c = e.dist;
        int x = i;
        if (pre[e.to] == -1) {
            sm += c;
            pre[e.to] = i;
            continue;
        }
        int y = pre[e.to];
        //merge x, y
        fix[e.to] = true;
        int P = pc++;
        heap[P].meld(heap[x]);
        heap[P].meld(heap[y]);
    }

    writeln(sm);
    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;

static if (__VERSION__ <= 2070) {
    /*
    Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
    Copyright: Andrei Alexandrescu 2008-.
    License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
    */
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }

}
version (X86) static if (__VERSION__ < 2071) {
    import core.bitop : bsf, bsr, popcnt;
    int bsf(ulong v) {
        foreach (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int bsr(ulong v) {
        foreach_reverse (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int popcnt(ulong v) {
        int c = 0;
        foreach (i; 0..64) {
            if (v & (1UL << i)) c++;
        }
        return c;
    }
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

// import dcomp.array;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    bool f = succW();
                    assert(f);
                    x[i] = line.parse!E;
                }
            } else {
                FastAppender!(E[]) buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/array.d */
// module dcomp.array;

T[N] fixed(T, size_t N)(T[N] a) {return a;}

struct FastAppender(A, size_t MIN = 4) {
    import std.algorithm : max;
    import std.conv;
    import std.range.primitives : ElementEncodingType;
    import core.stdc.string : memcpy;

    private alias T = ElementEncodingType!A;
    private T* _data;
    private uint len, cap;

    @property size_t length() const {return len;}
    bool empty() const { return len == 0; }

    void reserve(size_t nlen) {
        import core.memory : GC;
        if (nlen <= cap) return;

        void* nx = GC.malloc(nlen * T.sizeof);

        cap = nlen.to!uint;
        if (len) memcpy(nx, _data, len * T.sizeof);
        _data = cast(T*)(nx);
    }
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }

    void opOpAssign(string op : "~")(T item) {
        if (len == cap) {
            reserve(max(MIN, cap*2));
        }
        _data[len++] = item;
    }

    void insertBack(T item) {
        this ~= item;
    }

    void removeBack() {
        len--;
    }

    void clear() {
        len = 0;
    }
    ref inout(T) back() inout { assert(len); return _data[len-1]; }
    ref inout(T) opIndex(size_t i) inout { return _data[i]; }

    T[] data() {
        return (_data) ? _data[0..len] : null;
    }
}

/*
This source code generated by dcomp and include dcomp's source code.
dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)
dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)
*/


import std;

void main()
{

    bool fight(long hc, long dc, long hm, long dm) {
        long reqMoves = hm / dc + (hm % dc != 0);
        long recoil = (reqMoves-1) * dm;

        if(hc > recoil){
            return true;
        }else{
            return false;
        }
    }
    bool fight2(long hc, long dc, long hm, long dm) {
        if ((hm / dc == 0) || ((hm / dc == 1) && (hm % dc == 0)))
            return true;
        if ((hm / dc) < (hc / dm))
            return true;
        else if ((hm / dc) == (hc / dm))
        {
            if ((hm % dc) == 0)
                return true;
            else if ((hc % dm) == 0)
                return false;
            else
                return true;
        }
        else {
            if ((hm / dc - hc / dm == 1) && (hm % dc == 0) && (hc % dm != 0))
                return true;
            else
                return false;
        }
    }

    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long hc, dc, hm, dm;
        auto s = readln.split.to!(long[]);
        hc = s[0];
        dc = s[1];
        s = readln.split.to!(long[]);
        hm = s[0];
        dm = s[1];
        long k, a, w;
        scanf("%ld %ld %ld", &k, &w, &a);
        getchar();
        bool flag = false;

        for (int i = 0; i <= k; ++i) {
            long new_hc = i*a + hc;
            long new_dc = (k-i)*w + dc;
            flag = fight2(new_hc, new_dc, hm, dm);
            if (flag) {
                break;
            }
        }
        if (flag)
            writeln("YES");
        else
            writeln("NO");
    }
}

import std;

void main()
{

    bool fight(long hc, long dc, long hm, long dm) {
        if ((hm / dc == 0) || ((hm / dc == 1) && (hm % dc == 0)))
            return true;
        if ((hm / dc) < (hc / dm))
            return true;
        else if ((hm / dc) == (hc / dm))
        {
            if ((hm % dc) == 0)
                return true;
            else if ((hc % dm) == 0)
                return false;
            else
                return true;
        }
        else {
            if ((hm / dc - hc / dm == 1) && (hm % dc == 0) && (hc % dm != 0))
                return true;
            else
                return false;
        }
    }

    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long hc, dc, hm, dm;
        auto s = readln.split.to!(long[]);
        hc = s[0];
        dc = s[1];
        s = readln.split.to!(long[]);
        hm = s[0];
        dm = s[1];
        long k, a, w;
        scanf("%ld %ld %ld", &k, &w, &a);
        getchar();
        bool flag = fight(hc, dc, hm, dm);
        if (flag) {
                writeln("YES");
                continue;
            }
        for (int i = 0; i <= k; i++) {
            long new_hc = i*a + hc;
            long new_dc = (k-i)*w + dc;
            flag = fight(new_hc, new_dc, hm, dm);
            if (flag) {
                writeln("YES");
                break;
            }
        }
        if (!flag)
            writeln("NO");
    }
}

bool canDestroy(long hc, long dc, long hm, long dm){
    long reqMoves = hm / dc + (hm % dc != 0);
    long recoil = (reqMoves-1) * dm;
    if(hc > recoil){
        return 1;
    }else{
        return 0;
    }
}

void solve(){
    long hc = scan;
    long dc = scan;

    long hm = scan;
    long dm = scan;

    int k = scan!int;
    long w = scan;
    long a = scan;

    for(int x = 0; x <= k; ++x){
        long nhc = hc + x * a;
        long ndc = dc + (k - x) * w;
        if(canDestroy(nhc, ndc, hm, dm)){
            writeln("YES");
            return;
        }
    }
    writeln("NO");
}

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

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

import std;

void main()
{

    bool fight(long hc, long dc, long hm, long dm) {
        long reqMoves = hm / dc + (hm % dc != 0);
    long recoil = (reqMoves-1) * dm;
    if(hc > recoil){
        return true;
    }else{
        return false;
    }
    }

    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long hc, dc, hm, dm;
        scanf("%ld %ld", &hc, &dc);
        getchar();
        scanf("%ld %ld", &hm, &dm);
        getchar();
        long k, a, w;
        scanf("%ld %ld %ld", &k, &w, &a);
        getchar();
        bool flag = false;

        for (int i = 0; i <= k; ++i) {
            long new_hc = i*a + hc;
            long new_dc = (k-i)*w + dc;
            flag = fight(new_hc, new_dc, hm, dm);
            if (flag) {
                break;
            }
        }
        if (flag)
            writeln("YES");
        else
            writeln("NO");
    }
}

import std;

void main()
{

    bool fight(long hc, long dc, long hm, long dm) {
        long reqMoves = hm / dc + (hm % dc != 0);
    long recoil = (reqMoves-1) * dm;
    if(hc > recoil){
        return true;
    }else{
        return false;
    }
    }

    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long hc, dc, hm, dm;
        scanf("%ld %ld", &hc, &dc);
        getchar();
        scanf("%ld %ld", &hm, &dm);
        getchar();
        long k, a, w;
        scanf("%ld %ld %ld", &k, &w, &a);
        getchar();
        bool flag = false;

        for (int i = 0; i <= k; i++) {
            long new_hc = i*a + hc;
            long new_dc = (k-i)*w + dc;
            flag = fight(new_hc, new_dc, hm, dm);
            if (flag) {
                break;
            }
        }
        if (flag)
            writeln("YES");
        else
            writeln("NO");
    }
}

import std;

void main()
{

    bool fight(long hc, long dc, long hm, long dm) {
        long reqMoves = hm / dc + (hm % dc != 0);
    long recoil = (reqMoves-1) * dm;
    if(hc > recoil){
        return true;
    }else{
        return false;
    }
    }

    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long hc, dc, hm, dm;
        scanf("%ld %ld", &hc, &dc);
        getchar();
        scanf("%ld %ld", &hm, &dm);
        getchar();
        long k, a, w;
        scanf("%ld %ld %ld", &k, &w, &a);
        getchar();
        bool flag = fight(hc, dc, hm, dm);
        if (flag) {
                writeln("YES");
                continue;
            }
        for (int i = 0; i <= k; i++) {
            long new_hc = i*a + hc;
            long new_dc = (k-i)*w + dc;
            flag = fight(new_hc, new_dc, hm, dm);
            if (flag) {
                writeln("YES");
                break;
            }
        }
        if (!flag)
            writeln("NO");
    }
}

import std;

void main()
{

    bool fight(long hc, long dc, long hm, long dm) {
        if ((hm / dc == 0) || ((hm / dc == 1) && (hm % dc == 0)))
            return true;
        if ((hm / dc) < (hc / dm))
            return true;
        else if ((hm / dc) == (hc / dm))
        {
            if ((hm % dc) == 0)
                return true;
            else if ((hc % dm) == 0)
                return false;
            else
                return true;
        }
        else {
            if ((hm / dc - hc / dm == 1) && (hm % dc == 0) && (hc % dm != 0))
                return true;
            else
                return false;
        }
    }

    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long hc, dc, hm, dm;
        scanf("%ld %ld", &hc, &dc);
        getchar();
        scanf("%ld %ld", &hm, &dm);
        getchar();
        long k, a, w;
        scanf("%ld %ld %ld", &k, &w, &a);
        getchar();
        bool flag = fight(hc, dc, hm, dm);
        if (flag) {
                writeln("YES");
                continue;
            }
        for (int i = 0; i <= k; i++) {
            long new_hc = i*a + hc;
            long new_dc = (k-i)*w + dc;
            flag = fight(new_hc, new_dc, hm, dm);
            if (flag) {
                writeln("YES");
                break;
            }
        }
        if (!flag)
            writeln("NO");
    }
}

import std;

void main()
{

    bool fight(long hc, long dc, long hm, long dm) {
        if ((hm / dc) < (hc / dm))
            return true;
        else if ((hm / dc == 0) || ((hm / dc == 1) && (hm % dc == 0)))
            return true;
        else if ((hm / dc) == (hc / dm))
        {
            if ((hm % dc) == 0)
                return true;
            else if ((hc % dm) == 0)
                return false;
            else
                return true;
        }
        else {
            if ((hm / dc - hc / dm == 1) && (hm % dc == 0))
                return true;
            else
                return false;
        }
    }

    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long hc, dc, hm, dm;
        scanf("%ld %ld", &hc, &dc);
        getchar();
        scanf("%ld %ld", &hm, &dm);
        getchar();
        long k, a, w;
        scanf("%ld %ld %ld", &k, &w, &a);
        getchar();
        bool flag = fight(hc, dc, hm, dm);
        if (flag) {
                writeln("YES");
                continue;
            }
        for (int i = 0; i <= k; i++) {
            auto new_hc = i*a + hc;
            auto new_dc = (k-i)*w + dc;
            flag = fight(new_hc, new_dc, hm, dm);
            if (flag) {
                writeln("YES");
                break;
            }
        }
        if (!flag)
            writeln("NO");
    }
}

import std;

void main()
{

    bool fight(long hc, long dc, long hm, long dm) {
        if ((hm / dc) < (hc / dm))
            return true;
        else if ((hm / dc) == (hc / dm))
        {
            if ((hm % dc) == 0)
                return true;
            else if ((hc % dm) == 0)
                return false;
            else
                return true;
        }
        else
            return false;
    }

    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long hc, dc, hm, dm;
        scanf("%ld %ld", &hc, &dc);
        getchar();
        scanf("%ld %ld", &hm, &dm);
        getchar();
        long k, a, w;
        scanf("%ld %ld %ld", &k, &w, &a);
        getchar();
        bool flag = fight(hc, dc, hm, dm);
        if (flag) {
                writeln("YES");
                continue;
            }
        for (int i = 0; i <= k; i++) {
            auto new_hc = i*a + hc;
            auto new_dc = (k-i)*w + dc;
            flag = fight(new_hc, new_dc, hm, dm);
            if (flag) {
                writeln("YES");
                break;
            }
        }
        if (!flag)
            writeln("NO");
    }
}

import std;

void main()
{

    bool fight(long hc, long dc, long hm, long dm) {
        if ((hm / dc) <= (hc / dm))
            return true;
        else
            return false;
    }

    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long hc, dc, hm, dm;
        scanf("%ld %ld", &hc, &dc);
        getchar();
        scanf("%ld %ld", &hm, &dm);
        getchar();
        long k, a, w;
        scanf("%ld %ld %ld", &k, &w, &a);
        getchar();
        bool flag = fight(hc, dc, hm, dm);
        if (flag) {
                writeln("YES");
                continue;
            }
        for (int i = 0; i <= k; i++) {
            auto new_hc = i*a + hc;
            auto new_dc = (k-i)*w + dc;
            flag = fight(new_hc, new_dc, hm, dm);
            if (flag) {
                writeln("YES");
                break;
            }
        }
        if (!flag)
            writeln("NO");
    }
}

import std;

void main()
{

    bool fight(long hc, long dc, long hm, long dm) {
        if ((hm / dc) <= (hc / dm))
            return true;
        else
            return false;
    }

    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long hc, dc, hm, dm;
        scanf("%ld %ld", &hc, &dc);
        getchar();
        scanf("%ld %ld", &hm, &dm);
        getchar();
        long k, a, w;
        scanf("%ld %ld %ld", &k, &w, &a);
        getchar();
        bool flag = fight(hc, dc, hm, dm);
        if (flag) {
                writeln("YES");
                continue;
            }
        for (int i = 0; i < k; i++) {
            auto new_hc = i*a + hc;
            auto new_dc = (k-i)*w + dc;
            flag = fight(new_hc, new_dc, hm, dm);
            if (flag) {
                writeln("YES");
                break;
            }
        }
        if (!flag)
            writeln("NO");
    }
}

import std;

void main()
{

    bool fight(long hc, long dc, long hm, long dm) {
        if ((hm / dc) >= (hc / dm))
            return true;
        else
            return false;
    }

    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long hc, dc, hm, dm;
        scanf("%ld %ld", &hc, &dc);
        getchar();
        scanf("%ld %ld", &hm, &dm);
        getchar();
        long k, a, w;
        scanf("%ld %ld %ld", &k, &w, &a);
        getchar();
        bool flag = false;
        for (int i = 0; i < k; i++) {
            auto new_hc = i*a + hc;
            auto new_dc = (k-i)*w + dc;
            flag = fight(new_hc, new_dc, hm, dm);
            if (flag) {
                writeln("YES");
                break;
            }
        }
        if (!flag)
            writeln("NO");
    }
}


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:

auto getAddrTuple() {
    return tuple();
}

auto getAddrTuple(T, U...)(ref T head, ref U tail) {
    return tuple(&head, getAddrTuple(tail).expand);
}

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

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

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

struct Dsu(int maxn) {
    int[maxn] p, sz;

    int get(int x) {
        return x == p[x] ? x : (p[x] = get(p[x]));
    }

    void merge(int x, int y) {
        x = get(x);
        y = get(y);
        if (x != y) {
            p[x] = y;
            sz[y] += sz[x];
        }
    }
}

int n, m;
Dsu!150_000 dsu;

void main() {
    while (read(n, m)) {
        iota(n).copy(dsu.p[ ]);
        dsu.sz[0 .. n] = 1;
        foreach (i; 0 .. m) {
            int x, y;
            read(x, y);
            x--;
            y--;
            dsu.merge(x, y);
        }
        long total = m << 1;
        foreach (i; 0 .. n)
            if (dsu.p[i] == i)
                total -= dsu.sz[i] * cast(long)(dsu.sz[i] - 1);
        writeln(total ? "NO" : "YES");
    }
}

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;

alias Tuple!(int, "a", int, "b") Edge;

int N, M;
int[][] adj;
bool[] used;
bool[Edge] cnt;

long dfs(int n) {
    used[n] = true;
    int ret = 1;

    foreach (m; adj[n]) {
        cnt[Edge(min(n, m), max(n, m))] = true;
        if (!used[m]) ret += dfs(m);
    }

    return ret;
}

void main() {
    auto s = readln.split.map!(to!int);
    N = s[0];
    M = s[1];
    adj = new int[][](N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        adj[s[0]-1] ~= s[1]-1;
        adj[s[1]-1] ~= s[0]-1;
    }

    used = new bool[](N);
    foreach (i; 0..N) {
        if (!used[i]) {
            cnt.clear;
            long r = dfs(i);
            if (cnt.keys.length != r * (r-1) / 2) {
                writeln("NO");
                return;
            }
        }
    }

    writeln("YES") ;
}

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

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

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

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

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

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

      auto uf = new int[N];
      uf[] = -1;
      foreach (i; 0 .. M) {
        uf.connect(A[i], B[i]);
      }

      long m;
      foreach (r; 0 .. N) {
        if (uf[r] < 0) {
          const sz = -uf[r];
          m += 1L * sz * (sz - 1) / 2;
        }
      }

      writeln((m == M) ? "YES" : "NO");
    }
  } catch (EOFException e) {
  }
}

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;

alias Tuple!(int, "a", int, "b") Edge;

int N, M;
int[][] adj;
bool[] used;
bool[Edge] cnt;

int dfs(int n) {
    used[n] = true;
    int ret = 1;

    foreach (m; adj[n]) {
        cnt[Edge(min(n, m), max(n, m))] = true;
        if (!used[m]) ret += dfs(m);
    }

    return ret;
}

void main() {
    auto s = readln.split.map!(to!int);
    N = s[0];
    M = s[1];
    adj = new int[][](N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        adj[s[0]-1] ~= s[1]-1;
        adj[s[1]-1] ~= s[0]-1;
    }

    used = new bool[](N);
    foreach (i; 0..N) {
        if (!used[i]) {
            cnt.clear;
            int r = dfs(i);
            if (cnt.keys.length != r * (r-1) / 2) {
                writeln("NO");
                return;
            }
        }
    }

    writeln("YES") ;
}


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

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

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

	int n = read.to!int;
	string s = readln.chomp;

	char[] ans;
	int i = 0, j = 1;
	while(j < n) if(s[i] != s[j]) ans ~= s[i], ans ~= s[j], i = j + 1, j = i + 1; else j += 1;

	(n - ans.length).writeln;
	ans.writeln;
}

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

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

    dchar[] T;

    foreach (i; 0..N) {
        if (T.empty) {
            T ~= S[i];
        } else if (T.back == S[i] && T.length % 2 == 1) {

        } else {
            T ~= S[i];
        }
    }

    int rest = T.length.to!int;
    int ans = N - rest;
    if (rest % 2 == 1) {
        ans += 1;
        T = T[0..$-1];
    }

    ans.writeln;
    T.writeln;
}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm;
import std.conv : to;
import std.range : iota, tee;
import std.algorithm.comparison;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

void main() {
    GC.disable();

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

    auto  s = readln().strip().dup;
    if (s.length == 0) { writefln("%s\n%s", 0, s); return ; }

    char [] ans;
    foreach(i; 0 .. s.length) {

      if (ans.length == 0) {
        ans ~= s[i];
      } else {
        if ( ans.length % 2 ==0 || ans[$-1] != s[i]) ans ~= s[i];
      }
    }

    if (ans.length % 2 == 1) {
      ans = ans [0 .. $ - 1];
    }

    writefln("%s\n%s", s.length - ans.length, ans);

}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto N = RD!int;
	auto a = RD!string;

	string ans;
	ans ~= a[0];
	long cnt;
	char last = a[0];
	foreach (i; 1..N)
	{
		if ((i-cnt) % 2 == 1)
		{
			if (a[i] == last)
			{
				++cnt;
				continue;
			}
		}
		last = a[i];
		ans ~= a[i];
	}
	if (ans.length % 2 == 1)
	{
		ans.popBack;
		++cnt;
	}

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


import std.algorithm;
import std.stdio;
import std.typecons;

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		alias Event = Tuple !(int, q{x}, int, q{d});
		Event [] a;
		foreach (i; 0..n)
		{
			int p, q;
			readf (" %s %s", &p, &q);
			a ~= Event (p, -1);
			a ~= Event (q, +1);
		}
		sort (a);

		int b = 0;
		int start;
		int [2] [] ans;
		foreach (e; a)
		{
			b -= e.d;
			if (b == k && e.d == -1)
			{
				start = e.x;
			}
			if (b == k - 1 && e.d == +1)
			{
				ans ~= [start, e.x];
			}
		}

		writefln ("%s\n%(%(%s %)\n%)", ans.length, ans);
	}
}

import std.algorithm;
import std.stdio;
import std.typecons;

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		int [] a;
		foreach (i; 0..n)
		{
			int p, q;
			readf (" %s %s", &p, &q);
			a ~= p * 2 + 0;
			a ~= q * 2 + 1;
		}
		sort (a);

		int b = 0;
		int start;
		int [2] [] ans;
		foreach (e; a)
		{
			int d = (e & 1) ? -1 : +1;
			int x = e >> 1;
			b += d;
			if (b == k && d == +1)
			{
				start = x;
			}
			if (b == k - 1 && d == -1)
			{
				ans ~= [start, x];
			}
		}

		writefln ("%s\n%(%(%s %)\n%)", ans.length, ans);
	}
}

import std.algorithm;
import std.stdio;
import std.typecons;

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		alias Event = Tuple !(int, q{x}, int, q{d});
		Event [] a;
		foreach (i; 0..n)
		{
			int p, q;
			readf (" %s %s", &p, &q);
			a ~= Event (p, -1);
			a ~= Event (q, +1);
		}
		sort !(q{a < b}, SwapStrategy.stable) (a);

		int b = 0;
		int start;
		int [2] [] ans;
		foreach (e; a)
		{
			b -= e.d;
			if (b == k && e.d == -1)
			{
				start = e.x;
			}
			if (b == k - 1 && e.d == +1)
			{
				ans ~= [start, e.x];
			}
		}

		writefln ("%s\n%(%(%s %)\n%)", ans.length, ans);
	}
}

module main;

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

alias Action = Tuple! (int, "coord", bool, "isClose");
alias Segment = Tuple! (int, "left", int, "right");

int main() {

    int n, k;

    readf(" %d %d", &n, &k);
    readln();

    Action[] actions;

    foreach (int i; 0..n) {
        auto temp = readln().strip().split().map! (to! (int)).array();

        actions ~= Action (temp[0], false);
        actions ~= Action (temp[1], true);
    }

    sort(actions);

    debug {writeln(actions);};

    int currentCountOfIntersections;
    int[] opens;
    Segment[] result;
    foreach (int i; 0..actions.length)
        if (!(actions[i].isClose)) {
            opens.assumeSafeAppend();
            opens ~= actions[i].coord;
            currentCountOfIntersections++;
        } else {
            if (currentCountOfIntersections == k)
                result ~= Segment (opens.back, actions[i].coord);

            opens.popBack();
            currentCountOfIntersections--;
        }

    writeln(result.length);
    foreach (int i; 0..result.length)
        writeln(result[i][0], ' ', result[i][1]);

	return 0;
}

module main;

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

int main() {

    auto s = readln().strip();

    char[] stack;
    string open = "({[<";
    string close = ")}]>";

    int result;

    bool flag = true;
    foreach (int i; 0..s.length)
        if (canFind(open, s[i])) {
            stack.assumeSafeAppend();
            stack ~= s[i];
        } else {
            if (stack.length == 0 || canFind(stack.back.to! (string), close)) {
                flag = false;
                break;
            }

            if (s[i] == ')' && stack.back != '(' || s[i] == '}' && stack.back != '{' || s[i] == ']' &&
                stack.back != '[' || s[i] == '>' && stack.back != '<')
                    result++;

            stack.popBack();
        }

    writeln((flag && stack.length == 0) ? result.to! (string) : "Impossible");

	return 0;
}


module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

int a, b, n, m;
int[][] mat;

void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                n = cin.readInt;
                m = cin.readInt;
                mat = new int[][](n, m);
                for (int i = 0; i < n; i++) {
                        for (int j = 0; j < m; j++) {
                                mat[i][j] = cin.readInt;
                        }
                }
                a = cin.readInt;
                b = cin.readInt;
                if (a == b) writeln(colWise());
                else writeln(min(colWise(), rowWise()));
        }
}

int colWise() {
        int minn = 99999999;
        for (int i = 0; i < n - b + 1; i++) {
                for (int j = 0; j < m - a + 1; j++) {
                        int trees = 0;
                        for (int dx = 0; dx < b; dx++) {
                                for (int dy = 0; dy < a; dy++) {
                                        if (mat[i + dx][j + dy]) trees++;
                                }
                        }
                        minn = min(minn, trees);
                }
        }
        return minn;
}

int rowWise() {
        int minn = 99999999;
        for (int i = 0; i < n - a + 1; i++) {
                for (int j = 0; j < m - b + 1; j++) {
                        int trees = 0;
                        for (int dx = 0; dx < a; dx++) {
                                for (int dy = 0; dy < b; dy++) {
                                        if (mat[i + dx][j + dy]) trees++;
                                }
                        }
                        minn = min(minn, trees);
                }
        }
        return minn;
}

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

int n, m;
int[][] mat;

void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                n = cin.readInt;
                m = cin.readInt;
                mat = new int[][](n, m);
                for (int i = 0; i < n; i++) {
                        for (int j = 0; j < m; j++) {
                                mat[i][j] = cin.readInt;
                        }
                }
                int a, b;
                a = cin.readInt;
                b = cin.readInt;
                writeln(min(solve(a, b), solve(b, a)));
        }
}

int solve(int a, int b) {
        int minn = 99999999;
        for (int i = 0; i < n - b + 1; i++) {
                for (int j = 0; j < m - a + 1; j++) {
                        int trees = 0;
                        for (int dx = 0; dx < b; dx++) {
                                for (int dy = 0; dy < a; dy++) {
                                        if (mat[i + dx][j + dy]) trees++;
                                }
                        }
                        minn = min(minn, trees);
                }
        }
        return minn;
}


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

string solve (int n, int k)
{
	int c = 0;
	auto board = new char [] [] (n, n);
	foreach (ref line; board)
	{
		line[] = '.';
	}
	while (k > 0 && c < n)
	{
		board[c][c] = 'R';
		k -= 1;
		c += 2;
	}
	if (k == 0)
	{
		return format !("%-(%s\n%)") (board);
	}
	else
	{
		return "-1";
	}
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		writeln (solve (n, k));
	}
}

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

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

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

void main() {
  int T;
  read(T);
  while (T--) {
    int n, k;
    read(n, k);
    if (k * 2 - 1 > n) {
      writeln(-1);
      continue;
    }

    auto board = new char[][](n, n);
    foreach (ref c; board) c[] = '.';

    foreach (i; 0 .. k) {
      board[i * 2][i * 2] = 'R';
    }

    foreach (c; board) writeln(c);
  }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		if (k > (n+1)/2) continue;
		ans[ti].length = n;
		foreach (i; 0..n)
		{
			foreach (j; 0..n)
			{
				if (i/2 < k && i % 2 != 1)
				{
					if (i == j)
						ans[ti][i] ~= "R";
					else
						ans[ti][i] ~= ".";
				}
				else
					ans[ti][i] ~= ".";
			}
		}
	}

	foreach (e; ans)
	{
		if (e.empty)
			writeln(-1);
		else
		{
			foreach (ee; e)
				writeln(ee);
		}
	}
	stdout.flush;
	debug readln;
}

import std;

void main () {
    immutable tests = (){ uint t; readf!"%s\n"(t); return t; }();

    foreach (test_index; 0 .. tests) {
        immutable n = (){ uint n; readf!"%s "(n); return n; }();
        immutable k = (){ uint k; readf!"%s\n"(k); return k; }();

        auto r = iota(0, n, 2).take(k);

        if (r.length < k) {
            writeln("-1");
            continue;
        }

        foreach (i; 0 .. n) {
            foreach (j; 0 .. n)
                if (!r.empty && r.front == i && r.front == j) {
                    write('R');
                    r.popFront();
                } else
                    write('.');
            writeln();
        }
    }
}
// ""


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

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

    int n;
    while(t--) {
        readf("%s\n", &n);
        bool found = false;
        for(int x = 0; 3*x <= n; x += 1) {
            if(found)
                break;
            for(int y = 0; 5*y <= n; y += 1) {
                int z = (n - 3*x - 5*y)/7;
                if(z >= 0 && (3*x + 5*y + 7*z == n)) {
                    writefln("%s %s %s", x, y, z);
                    found = true;
                    break;
                }
            }
        }
        if(!found)
            "-1".writeln;
    }
}

import std.stdio;
import std.conv;
import std.string;

void main()
{
    auto t = stdin.readln.strip.to!int;
testcase:
    while (t-- > 0) {
        // a * 3 + b * 5 + c * 7 = n
        auto n = stdin.readln.strip.to!int;
        int result = 0;
        for (int a = 0; a * 3 <= n; ++a) {
            for (int b = 0; a * 3 + b * 5 <= n; ++b) {
                for (int c = 0; a * 3 + b * 5 + c * 7 <= n; ++c) {
                    if (a * 3 + b * 5 + c * 7 == n) {
                        writeln(a, ' ', b, ' ', c);
                        continue testcase;
                    }
                }
            }
        }
        writeln("-1");
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		(){
		foreach (i; 0..n)
		{
			auto n1 = n - i * 3;
			if (n1 < 0) break;
			foreach (j; 0..n)
			{
				auto n2 = n1 - j * 5;
				if (n2 < 0) break;
				foreach (k; 0..n)
				{
					auto n3 = n2 - k * 7;
					if (n3 < 0) break;
					else if (n3 == 0)
					{
						ans[ti] = [i, j, k];
						return;
					}
				}
			}
		}}();
	}

	foreach (e; ans)
	{
		if (e.empty)
			writeln(-1);
		else
			e.map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}

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

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

    int n;
    while(t--) {
        readf("%s\n", &n);
        bool found = false;
        for(int x = 0; 3*x <= n; x += 1) {
            if(found)
                break;
            for(int y = 0; 5*y <= n; y += 1) {
                int z = (n - 3*x - 5*y)/7;
                if(z >= 0 && (3*x + 5*y + 7*z == n)) {
                    writefln("%s %s %s", x, y, z);
                    found = true;
                }
            }
        }
        if(!found)
            "-1".writeln;
    }
}


import std;

void main(){
	auto t=readln.strip.to!int;
	foreach(_;0..t){
		readln;
		auto c=readln.strip.split.to!(int[]);
		auto a=c.map!(x=>x?1:0).array~1;
		foreach(i,x;c) a[x+i*!a[i]]=0;
		a[0..$-1].map!text.join(" ").writeln;
	}
}

import std;

void main(){
	auto t=readln.strip.to!int;
	foreach(_;0..t){
		auto n=readln.strip.to!int;
		auto c=readln.strip.split.to!(int[]);
		auto a=(-1).repeat(n).array;
		auto j=0, iz=n.repeat(n).array, z=0;
		iz[0]=c[0];
		while(j<n&&c[j]==0) a[j++]=0;
		if(j<n) a[j++]=1;
		foreach(i;j-1..n){
			if(a[i]==0) iz[++z]=i;
			int p=c[i]-i*a[i]+min(i,iz[i]);
			while(j<p) a[j++]=1;
			if(j<n) a[j++]=0;
		}
		a.map!text.join(" ").writeln;
	}
}

import std;

void main(){
	auto t=readln.strip.to!int;
	foreach(_;0..t){
		auto n=readln.strip.to!int;
		auto c=readln.strip.split.to!(int[]);
		auto a=c.map!(x=>x?1:0).array~1;
		foreach(i,x;c) a[x+i*!a[i]]=0;
		a[0..n].map!text.join(" ").writeln;
	}
}

import std;

void main(){
	int t=readln.strip.to!int;
	foreach(_;0..t){
		auto n=readln.strip.to!int;
		auto c=readln.strip.split.to!(int[]);
		auto a=(-1).repeat(n).array;
		int z=0,j=0;
		auto iz=0.repeat(n).array;
		iz[0]=c[0];
		while(j<n&&c[j]==0) a[j++]=0;
		if(j<n) a[j++]=1;
		foreach(i;j-1..n){
			if(a[i]==0) iz[++z]=i;
			int p=c[i]-i*a[i]+min(i,iz[i]);
			while(j<p) a[j++]=1;
			if(j<n) a[j++]=0;
		}
		a.map!text.join(" ").writeln;
	}
}


import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm;
import std.conv : to;
import std.range : iota, tee;
import std.algorithm.comparison;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

long MOD = 998244353;

void main() {
    GC.disable();

    //

    uint n;
    readf(" %s", n);
    auto a = new long [n];
    foreach(i; 0 .. n) readf(" %s", a[i]);
    auto b = new long [n];
    foreach(i; 0 .. n) readf(" %s", b[i]);

    sort!"a>b"(b);

    long[] vv;
    foreach(i; 0..n) {
      // a
      long t = i+1;
      long mul =  ( t*(n - t + 1) ); // % MOD;
      mul = (mul *a[i]);// % MOD;
      vv ~= mul;
    }

    sort!"a<b"(vv);

    long tt = 0;

    foreach(i; 0 .. n) {
      tt += ( (vv[i]%MOD) * b[i] ) % MOD;
      tt = (tt % MOD);
    }

    writeln(tt);

    //

}

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

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

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

	int n = read.to!int;
	long[] as;
	foreach(i; 0 .. n) as ~= read.to!long;
	print!1("as:", as);

	long[] bs;
	foreach(i; 0 .. n) bs ~= read.to!long;
	print!1("bs:", bs);

	long[] cs;
	foreach(i; 0 .. n){
		long k = i + 1; k *= n - i;
		cs ~= k * as[i];
	}
	print!1("cs:", cs);

	cs.sort();
	bs.sort();

	print!1("cs:", cs);
	print!1("bs:", bs);

	long ans;
	foreach(i; 0 .. n) ans += (bs[i] * (cs[n - 1 - i] % mod)) % mod, ans %= mod;

	ans.writeln;
}

const long mod = 998244353;

/*
s = sum(r; 0 .. n) sum(l; 0 .. r) sum(i; l .. r + 1) a[i] b[i]

how many times the term a[i] b[i] appears?
= how many pair (l, r) exist such that l <= i and i <= r ?
= (i + 1)(n - i).

s = sum(i; 0 .. n) (i + 1)(n - i) a[i] b[i].

let k[i] = (i + 1)(n - i) a[i].
arrange smaller b[i] for smaller k[i].

*/

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

immutable long MOD = 998244353 ;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    auto B = readln.split.map!(to!long).array;
    B.sort!"a > b";

    foreach (i; 0..N) {
        long tmp = 1L * (i + 1) * (N - i);
        A[i] = A[i] * tmp;
    }
    A.sort();

    long ans = 0;

    foreach (i; 0..N) {
        (ans += A[i] % MOD * B[i] % MOD) %= MOD;
    }

    ans.writeln;
}

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

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

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

	int n = read.to!int;
	long[] as;
	foreach(i; 0 .. n) as ~= read.to!long;
	print!1("as:", as);

	long[] bs;
	foreach(i; 0 .. n) bs ~= read.to!long;
	print!1("bs:", bs);

	long[] cs;
	foreach(i; 0 .. n) cs ~= (i + 1) * (n - i) * as[i];
	print!1("cs:", cs);

	cs.sort();
	bs.sort();

	print!1("cs:", cs);
	print!1("bs:", bs);

	long ans;
	foreach(i; 0 .. n) ans += (bs[i] * (cs[n - 1 - i] % mod)) % mod, ans %= mod;

	ans.writeln;
}

const long mod = 998244353;

/*
s = sum(r; 0 .. n) sum(l; 0 .. r) sum(i; l .. r + 1) a[i] b[i]

how many times the term a[i] b[i] appears?
= how many pair (l, r) exist such that l <= i and i <= r ?
= (i + 1)(n - i).

s = sum(i; 0 .. n) (i + 1)(n - i) a[i] b[i].

let k[i] = (i + 1)(n - i) a[i].
arrange smaller b[i] for smaller k[i].

*/

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

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

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

	int n = read.to!int;
	long[] as;
	foreach(i; 0 .. n) as ~= read.to!long;
	print!1("as:", as);

	long[] bs;
	foreach(i; 0 .. n) bs ~= read.to!long;
	print!1("bs:", bs);

	long[] cs;
	foreach(i; 0 .. n) cs ~= (i + 1) * (n - i) * as[i];
	print!1("cs:", cs);

	cs.sort();
	bs.sort();

	print!1("cs:", cs);
	print!1("bs:", bs);

	long ans;
	foreach(i; 0 .. n) ans += (bs[i] * cs[n - 1 - i]) % mod, ans %= mod;

	ans.writeln;
}

const long mod = 998244353;

/*
s = sum(r; 0 .. n) sum(l; 0 .. r) sum(i; l .. r + 1) a[i] b[i]

how many times the term a[i] b[i] appears?
= how many pair (l, r) exist such that l <= i and i <= r ?
= (i + 1)(n - i).

s = sum(i; 0 .. n) (i + 1)(n - i) a[i] b[i].

let k[i] = (i + 1)(n - i) a[i].
arrange smaller b[i] for smaller k[i].

*/

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm;
import std.conv : to;
import std.range : iota, tee;
import std.algorithm.comparison;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

long MOD = 998244353;

void main() {
    GC.disable();

    //

    uint n;
    readf(" %s", n);
    auto a = new long [n];
    foreach(i; 0 .. n) readf(" %s", a[i]);
    auto b = new long [n];
    foreach(i; 0 .. n) readf(" %s", b[i]);

    sort!"a>b"(b);

    long[] vv;
    foreach(i; 0..n) {
      // a
      long t = i+1;
      long mul =  ( t*(n - t + 1) ); // % MOD;
      mul = (mul *a[i]);// % MOD;
      vv ~= mul;
    }

    sort!"a>b"(vv);

    long tt = 0;

    foreach(i; 0 .. n) {
      tt += (vv[i] * b[i] ) % MOD;
      tt = (tt % MOD);
    }

    writeln(tt);

    //

}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm;
import std.conv : to;
import std.range : iota, tee;
import std.algorithm.comparison;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

long MOD = 998244353;

void main() {
    GC.disable();

    //

    uint n;
    readf(" %s", n);
    auto a = new long [n];
    foreach(i; 0 .. n) readf(" %s", a[i]);
    auto b = new long [n];
    foreach(i; 0 .. n) readf(" %s", b[i]);

    sort!"a>b"(b);

    long[] vv;
    foreach(i; 0..n) {
      // a
      long t = i+1;
      long mul =  ( t*(n - t + 1) ); // % MOD;
      mul = (mul *a[i]);// % MOD;
      vv ~= mul;
    }

    sort!"a<b"(vv);

    long tt = 0;

    foreach(i; 0 .. n) {
      tt += (vv[i] * b[i] ) % MOD;
      tt = (tt % MOD);
    }

    writeln(tt);

    //

}


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

int calc_weight(int node, int[] b, int[] ans, int[] cumulative)
{
  int w = 0;
  while (b[node] != node) {
    if (cumulative[node] != 0)
      return w + cumulative[node];
    w += ans[node];
    node = b[node];
  }
  return w;
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    int n;
    readf!" %d "(n);
    auto b = readln.splitter.map!(x => x.to!int - 1).array;
    auto p = readln.splitter.map!(x => x.to!int - 1).array;
    bool[int][] adj = new bool[int][](n);
    int root = -1;
    foreach (i ; 0 .. cast(int)b.length) {
      if (b[i] == i) {
        root = i;
        continue;
      }
      adj[i][b[i]] = true;
      adj[b[i]][i] = true;
    }
    if (p[0] != root) {
      writeln(-1);
      continue;
    }
//    writefln("root=%d, adj=%s", root, adj);
    bool good = true;
    int[] ans = new int[](n);
    int[] cumulative = new int[](n);
    int w = n + 1;
    foreach_reverse (node ; p) {
      if (node == root)
        break;
      if (adj[node].length != 1) {
//        writefln("bad node %d", node);
        good = false;
        break;
      }
      int ancestor = adj[node].keys[0];
      adj[ancestor].remove(node);
//      writefln("remove %d from %d, adj=%s", node, ancestor, adj);
      ans[node] = w--;
    }

    int prev_w = 0;
    foreach (i ; 1 .. cast(int)p.length) {
      w = calc_weight(p[i], b, ans, cumulative);
      if (w <= prev_w) {
        ans[p[i]] += prev_w - w + 1;
        w += prev_w - w + 1;
        cumulative[p[i]] = w;
      }
      prev_w = w;
    }

    if (good)
      writefln("%(%s %)", ans);
    else
      writeln(-1);
  }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto b = readln.splitter.map !(to !(int)).array;
		b[] -= 1;
		auto p = readln.splitter.map !(to !(int)).array;
		p[] -= 1;

		auto dist = new int [n];
		foreach (int i, ref v; p)
		{
			dist[v] = i;
		}

		auto vis = new bool [n];
		auto a = new int [n];
		bool ok = (b[p[0]] == p[0]);
		foreach (int i, ref v; p)
		{
			if (i == 0)
			{
				ok &= (b[v] == v);
			}
			else
			{
				ok &= vis[b[v]];
			}
			vis[v] = true;
			a[v] = dist[v] - dist[b[v]];
		}

		if (ok)
		{
			writefln !("%(%s %)") (a);
		}
		else
		{
			writeln (-1);
		}
	}
}


import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;

long egcd(long a, long b, ref long x, ref long y)
{
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }

  long x1, y1;
  long d = egcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

void main(string[] args)
{
  inputFile = stdin;
  auto n = next!long;
  auto a = next!long(n);

  if (n == 1)
    {
      writeln(1, " ", 1);
      writeln(0);
      writeln(1, " ", 1);
      writeln(0);
      writeln(1, " ", 1);
      writeln(-a[0]);
      return;
    }
  long x, y;
  egcd(n, n - 1, x, y);
  assert(n * x + (n - 1) * y == 1);
  writeln(1, " ", n);
  foreach(i, ai; a)
    {
      write(- ai * x * n, " ");
    }
  writeln;
  writeln(1, " ", n - 1);
  foreach(i, ai; a[0 .. $ - 1])
    {
      write(- ai * y * (n - 1), " ");
    }
  writeln;
  writeln(2, " ", n);
  foreach(ai; a[1 .. $ - 1])
    {
      write(0, " ");
    }
  writeln(- a[$ - 1] * y * (n - 1));
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byChunk;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(long)).array;
		if (n == 1)
		{
			writeln ("1 1");
			writeln (-a.front);
			writeln ("1 1");
			writeln ("0");
			writeln ("1 1");
			writeln ("0");
			continue;
		}

		writeln (1, " ", n - 1);
		long [] ans;
		foreach (i; 0..n - 1)
		{
			auto rem = ((-a[i] % n) + n) % n;
			auto delta = (-(n - 1) * rem);
			a[i] += delta;
			ans ~= delta;
		}
		writefln !("%(%s %)") (ans);

		writeln (n, " ", n);
		auto deltaLast = -a.back;
		writeln (deltaLast);
		a.back += deltaLast;

		writeln (1, " ", n);
		writefln !("%(%s %)") (a.map !(q{-a}));
	}
}

import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;

long egcd(long a, long b, ref long x, ref long y)
{
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }

  long x1, y1;
  long d = egcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

void main(string[] args)
{
  inputFile = stdin;
  auto n = next!long;
  auto a = next!long(n);

  if (n == 1)
    {
      writeln(1, " ", 1);
      writeln(0);
      writeln(1, " ", 1);
      writeln(0);
      writeln(1, " ", 1);
      writeln(-a[0]);
      return;
    }
  long x, y;
  egcd(n, n - 1, x, y);
  assert(n * x + (n - 1) * y == 1);
  writeln(1, " ", n);
  foreach(i, ai; a)
    {
      write(- ai * x * n, " ");
    }
  writeln;
  writeln(1, " ", n - 1);
  foreach(i, ai; a[0 .. $ - 1])
    {
      write(- ai * y * (n - 1), " ");
    }
  writeln;
  writeln(2, " ", n);
  foreach(ai; a[1 .. $ - 1])
    {
      write(0, " ");
    }
  writeln(- a[$ - 1] * y * (n - 1));
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;

long egcd(long a, long b, ref long x, ref long y)
{
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }

  long x1, y1;
  long d = egcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

void main(string[] args)
{
  inputFile = stdin;
  auto n = next!long;
  auto a = next!long(n);

  if (n == 1)
    {
      writeln(1, " ", 1);
      writeln(0);
      writeln(1, " ", 1);
      writeln(0);
      writeln(1, " ", 1);
      writeln(-a[0]);
      return;
    }
  long x, y;
  egcd(n, n - 1, x, y);
  assert(n * x + (n - 1) * y == 1);
  writeln(1, " ", n);
  foreach(i, ai; a)
    {
      write(- ai * x * n, " ");
    }
  writeln;
  writeln(1, " ", n - 1);
  foreach(i, ai; a[0 .. $ - 1])
    {
      write(- ai * y * (n - 1), " ");
    }
  writeln;
  writeln(2, " ", n);
  foreach(ai; a[1 .. $ - 1])
    {
      write(0, " ");
    }
  writeln(- a[$ - 1] * y * (n - 1));
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byChunk;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;

long egcd(long a, long b, ref long x, ref long y)
{
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }

  long x1, y1;
  long d = egcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

void main(string[] args)
{
  inputFile = stdin;
  auto n = next!long;
  auto a = next!long(n);

  if (n == 1)
    {
      writeln(1, " ", 1);
      writeln(0);
      writeln(1, " ", 1);
      writeln(0);
      writeln(1, " ", 1);
      writeln(-a[0]);
      return;
    }
  long x, y;
  egcd(n, n - 1, x, y);
  assert(n * x + (n - 1) * y == 1);
  writeln(1, " ", n);
  foreach(i, ai; a)
    {
      write(- ai * x * n, " ");
    }
  writeln;
  writeln(1, " ", n - 1);
  foreach(i, ai; a[0 .. $ - 1])
    {
      write(- ai * y * (n - 1), " ");
    }
  writeln;
  writeln(2, " ", n);
  foreach(ai; a[1 .. $ - 1])
    {
      write(0, " ");
    }
  writeln(- a[$ - 1] * y * (n - 1));
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byChunk;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 8 * 1024 * 1024;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

long egcd(long a, long b, ref long x, ref long y)
{
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }

  long x1, y1;
  long d = egcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

alias type = single;
struct TestCase
{
  mixin prettyPrinting;

  int n;
  @Dim(q{n}) long[] a;

  void solve(long tc = -1)
  {
    if (n == 1)
      {
        writeln(1, " ", 1);
        writeln(0);
        writeln(1, " ", 1);
        writeln(0);
        writeln(1, " ", 1);
        writeln(-a[0]);
        return;
      }
    long x, y;
    egcd(n, n - 1, x, y);
    assert(n * x + (n - 1) * y == 1);
    writeln(1, " ", n);
    foreach(i, ai; a)
      {
        write(- ai * x * n, " ");
      }
    writeln;
    writeln(1, " ", n - 1);
    foreach(i, ai; a[0 .. $ - 1])
      {
        write(- ai * y * (n - 1), " ");
      }
    writeln;
    writeln(2, " ", n);
    foreach(ai; a[1 .. $ - 1])
      {
        write(0, " ");
      }
    writeln(- a[$ - 1] * y * (n - 1));
  }
}

struct Interval
{
  long l, h;

  bool empty()
  {
    return l > h;
  }
}

Interval intersect(Interval a, Interval b)
{
  return Interval(max(a.l, b.l), min(a.h, b.h));
}

struct If
{
  string condition;
}
enum ignore = If("false");
struct Dim
{
  string dimensions;
  int levels;
  this(string dimensions)
  {
    this.dimensions = dimensions;
    levels = cast(int)dimensions.count(",") + 1;
  }
}

template getArrayLevel(W)
{
  static if (isDynamicArray!W && !is(W == string))
    enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));
  else
    enum getArrayLevel = 0;
}

static foreach(fieldName; 'a' .. cast(char)('z' + 1))
  {
    static if (fieldName != 'o')
      mixin("enum d", fieldName, " = Dim(\"", fieldName, "\");");
  }

mixin template prettyPrinting()
{
  string toString()
  {
    alias structType = typeof(this);
    auto res = appender!(string)();
    res.put(structType.stringof);
    res.put("(");
    static foreach(fieldName; FieldNameTuple!structType)
      {
        res.put(text(" ", fieldName, ": ", mixin(fieldName)));
      }
    res.put(" )");
    res.put("\n");
    return res[];
  }
}

struct Graph(N)
{
  size_t size;
  this(S)(S size)
  {
    adjacencyList.length = cast(size_t) size;
    this.size = cast(size_t) size;
    this.visited = makeSlice!bool(size);
  }
  N[][] adjacencyList;
  alias ne = neighbours;
  N[] neighbours(N n)
  {
    return adjacencyList.at(n);
  }
  alias bcon = biconnect;
  void biconnect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
    adjacencyList.at(b) ~= a;
  }
  alias con = connect;
  void connect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
  }
  void connect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        connect(edge[0], edge[1]);
      }
  }
  void biconnect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        biconnect(edge[0], edge[1]);
      }
  }
  alias deg = degree!long;
  auto degree(T)(N a)
  {
    return cast(T) adjacencyList.at(a).length;
  }

  auto visited = new bool[0];
  void dfs(Visitor)(long startNode)
  {
    auto visitor = Visitor.init;
    void internalDfs(long node)
    {
      visited.set(node, true);
      static if (is(typeof({visitor.n = node;})))
        visitor.n = node;
      static if (is(typeof({visitor.pre;})))
        visitor.pre;
      foreach(w; ne(node))
        if (!visited.at(w))
          {
            static if (is(typeof({visitor.w = w;})))
              visitor.w = w;
            static if (is(typeof(visitor.pren)))
              visitor.pren;
            internalDfs(w);
            static if (is(typeof(visitor.postn)))
              visitor.postn;
          }
      static if (is(typeof(visitor.post)))
        visitor.post;
    }
    internalDfs(startNode);
  }
  void dfs(long startNode)
  {
    struct DefVisitor {}
    dfs!DefVisitor(startNode);
  }
}

DList!string _words;

template removeArray(W, int times)
{
  static if (times == 0)
    alias removeArray = W;
  else static if (times == 1)
    alias removeArray = typeof(function(){W w; return w[0];}());
  else
    {
      static assert(isDynamicArray!W);
      alias removeArray = removeArray!(removeArray!(W, 1), times - 1);
    }
}

template baseType(W)
{
  static if (isDynamicArray!W && !is(W == string))
    alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));
  else
    alias baseType = W;
}

auto makeSlice(E, W, T...)(W size, T otherSizes)
{
  static if (T.length == 0)
    {
      E[] res;
      res.length = cast(size_t) size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = cast(size_t) size;
      foreach(ref row; res)
        row = makeSlice!E(otherSizes);
      return res;
    }
}

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, If))
              enum condition = getUDAs!(fieldSymbol, If)[0].condition;
            else
              enum condition = "true";

            if (mixin(condition))
              {
                static if (hasUDA!(fieldSymbol, Dim))
                  {
                    static assert(isDynamicArray!(typeOfField)
                                  , text(W.stringof, ".", fieldName, " has Dim UDA but isn't a Dynamic Array."));
                    enum uda = getUDAs!(fieldSymbol, Dim)[0];
                    static assert(getArrayLevel!(typeOfField) == uda.levels,
                                  text(W.stringof, ".", fieldName, " has a Dim UDA with different number of dimensions than it's type."));
                    mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});
                  }
                else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
                  {
                    pragma(msg, "Warning: You probably want to add dimension to input ", W.stringof, ".", fieldName);
                  }
                read(mixin(fieldName));
              }
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

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

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

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

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

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

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

    }
}

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

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  static if (is(typeof(f(i))))
    foreach(i; 0 .. times)
      f(i);
  else
    foreach(i; 0 .. times)
      f();
}

void multi()
{
  foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

void single()
{
  auto tc = next!TestCase;
  tc.solve;
}

void main(string[] args)
{
  debug stdin = File(args[1]);
  type;
}

import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;

long egcd(long a, long b, ref long x, ref long y)
{
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }

  long x1, y1;
  long d = egcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

void main(string[] args)
{
  inputFile = stdin;
  auto n = next!long;
  auto a = next!long(n);

  if (n == 1)
    {
      writeln(1, " ", 1);
      writeln(0);
      writeln(1, " ", 1);
      writeln(0);
      writeln(1, " ", 1);
      writeln(-a[0]);
      return;
    }
  long x, y;
  egcd(n, n - 1, x, y);
  assert(n * x + (n - 1) * y == 1);
  writeln(1, " ", n);
  foreach(i, ai; a)
    {
      write(- ai * x * n, " ");
    }
  writeln;
  writeln(1, " ", n - 1);
  foreach(i, ai; a[0 .. $ - 1])
    {
      write(- ai * y * (n - 1), " ");
    }
  writeln;
  writeln(2, " ", n);
  foreach(ai; a[1 .. $ - 1])
    {
      write(0, " ");
    }
  writeln(- a[$ - 1] * y * (n - 1));
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byChunk;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 4 * 1024 * 1024;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;

long egcd(long a, long b, ref long x, ref long y)
{
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }

  long x1, y1;
  long d = egcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

void main(string[] args)
{
  inputFile = stdin;
  auto n = next!long;
  auto a = next!long(n);

  if (n == 1)
    {
      writeln(1, " ", 1);
      writeln(0);
      writeln(1, " ", 1);
      writeln(0);
      writeln(1, " ", 1);
      writeln(-a[0]);
      return;
    }
  long x, y;
  egcd(n, n - 1, x, y);
  assert(n * x + (n - 1) * y == 1);
  writeln(1, " ", n);
  foreach(i, ai; a)
    {
      write(- ai * x * n, " ");
    }
  writeln;
  writeln(1, " ", n - 1);
  foreach(i, ai; a[0 .. $ - 1])
    {
      write(- ai * y * (n - 1), " ");
    }
  writeln;
  writeln(2, " ", n);
  foreach(ai; a[1 .. $ - 1])
    {
      write(0, " ");
    }
  writeln(- a[$ - 1] * y * (n - 1));
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byChunk;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!int;
	auto a = RDA;

	auto ans1 = new long[](n);
	foreach (i; 0..n-1)
	{
		ans1[i] = -n * a[i];
	}
	auto ans2 = new long[](n-1);
	foreach (i; 0..n-1)
	{
		ans2[i] = (n-1) * a[i];
	}

	if (n == 1)
	{
		writeln("1 1");
		writeln(0);
		writeln("1 1");
		writeln(0);
		writeln("1 1");
		writeln(-a[0]);
	}
	else
	{
		writeln("1 ", n);
		ans1.map!(to!string).join(" ").writeln;
		writeln("1 ", n-1);
		ans2.map!(to!string).join(" ").writeln;
		writeln(n, " ", n);
		writeln(-a[$-1]);
	}

	stdout.flush;
	debug readln;
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!int;
	auto a = RDA;

	auto ans1 = new long[](n);
	foreach (i; 0..n-1)
	{
		ans1[i] = -n * a[i];
	}
	auto ans2 = new long[](n-1);
	foreach (i; 0..n-1)
	{
		ans2[i] = (n-1) * a[i];
	}

	writeln("1 ", n);
	ans1.map!(to!string).join(" ").writeln;
	writeln("1 ", n-1);
	ans2.map!(to!string).join(" ").writeln;
	writeln(n, " ", n);
	writeln(-a[$-1]);

	stdout.flush;
	debug readln;
}