Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest).For any integer $$$k$$$ and positive integer $$$n$$$, let $$$k\bmod n$$$ denote the remainder when $$$k$$$ is divided by $$$n$$$. More formally, $$$r=k\bmod n$$$ is the smallest non-negative integer such that $$$k-r$$$ is divisible by $$$n$$$. It always holds that $$$0\le k\bmod n\le n-1$$$. For example, $$$100\bmod 12=4$$$ and $$$(-1337)\bmod 3=1$$$.Then the shuffling works as follows. There is an array of $$$n$$$ integers $$$a_0,a_1,\ldots,a_{n-1}$$$. Then for each integer $$$k$$$, the guest in room $$$k$$$ is moved to room number $$$k+a_{k\bmod n}$$$.After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests.

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

For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower).

NoteIn the first test case, every guest is shifted by $$$14$$$ rooms, so the assignment is still unique.In the second test case, even guests move to the right by $$$1$$$ room, and odd guests move to the left by $$$1$$$ room. We can show that the assignment is still unique.In the third test case, every fourth guest moves to the right by $$$1$$$ room, and the other guests move to the right by $$$5$$$ rooms. We can show that the assignment is still unique.In the fourth test case, guests $$$0$$$ and $$$1$$$ are both assigned to room $$$3$$$.In the fifth test case, guests $$$1$$$ and $$$2$$$ are both assigned to room $$$2$$$.

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto used = new bool[](n);
		bool ok = true;
		foreach (i; 0..n)
		{
			auto p = (i+a[i]+n);
			p += (abs(p/n)+1)*n;
			p %= n;
			if (used[cast(int)p])
			{
				ok = false;
				break;
			}
			used[cast(int)p] = true;
		}
		ans[ti] = ok;
	}

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

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

void main ()
{
	readln;
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		a[] += n.iota.array[];
		a[] = ((a[] % n) + n) % n;
		sort (a);
		writeln (equal (a, n.iota) ? "YES" : "NO");
	}
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const N = readInt();
        auto A = new long[N];
        foreach (i; 0 .. N) {
          A[i] = readLong();
        }

        auto rs = new long[N];
        foreach (i; 0 .. N) {
          rs[i] = ((i + A[i]) % N + N) % N;
        }
        rs.sort;

        bool ans = true;
        foreach (i; 0 .. N) {
          ans = ans && (rs[i] == i);
        }
        writeln(ans ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}

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

alias type = multi;
struct TestCase
{
  mixin prettyPrinting;

  long n;
  @Dim("n") long[] a;

  void solve(long tc = -1)
  {
    auto moved = iota(0, n).map!(i => pmod(a.at(i) + i, n)).array;
    auto movedSet = redBlackTree!long();
    foreach(m; moved)
      movedSet.insert(m);
    if (movedSet.length == n)
      writeln("YES");
    else
      writeln("NO");
  }
}

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

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

alias type = multi;
struct TestCase
{
  mixin prettyPrinting;

  long n;
  @Dim("n") long[] a;

  void solve(long tc = -1)
  {
    if (iota(0, n).map!(i => pmod(a.at(i) + i, n)).array.sort.uniq.array.length == n)
      writeln("YES");
    else
      writeln("NO");
  }
}

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

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

alias type = multi;
struct TestCase
{
  mixin prettyPrinting;

  long n;
  @Dim("n") long[] a;

  void solve(long tc = -1)
  {
    if (iota(0, n).map!(i => pmod(a.at(i) + i, n)).uniq.array.length == n)
      writeln("YES");
    else
      writeln("NO");
  }
}

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


Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.The current state of the wall can be respresented by a sequence $$$a$$$ of $$$n$$$ integers, with $$$a_i$$$ being the height of the $$$i$$$-th part of the wall.Vova can only use $$$2 \times 1$$$ bricks to put in the wall (he has infinite supply of them, however).Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some $$$i$$$ the current height of part $$$i$$$ is the same as for part $$$i + 1$$$, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part $$$1$$$ of the wall or to the right of part $$$n$$$ of it).Note that Vova can't put bricks vertically.Vova is a perfectionist, so he considers the wall completed when:  all parts of the wall has the same height;  the wall has no empty spaces inside it. Can Vova complete the wall using any amount of bricks (possibly zero)?

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of parts in the wall. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the initial heights of the parts of the wall.

Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero). Print "NO" otherwise.

NoteIn the first example Vova can put a brick on parts 2 and 3 to make the wall $$$[2, 2, 2, 2, 5]$$$ and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it $$$[5, 5, 5, 5, 5]$$$.In the second example Vova can put no bricks in the wall.In the third example the wall is already complete.

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 A = readln.split.map!(to!long).array;

    auto pq = new BinaryHeap!(Array!(Tuple!(int, int, long)), "a[2] > b[2]");
    auto uf = new UnionFind(N);
    foreach (i; 0..N) uf.seg[i] = tuple(i, i, A[i]);

    int prev = -1;
    foreach (i; 0..N) {
        if (prev == -1) {
            prev = i;
        } else if (A[i] == A[prev]) {
            uf.unite(i, prev);
        } else {
            pq.insert(tuple(prev, i-1, A[prev]));
            prev = i;
        }
    }
    pq.insert(tuple(prev, N-1, A[prev]));

    while (!pq.empty) {
        auto s = pq.front;
        pq.popFront;
        auto l = s[0];
        auto r = s[1];
        auto t = s[2];
        if (uf.seg[uf.find(l)] != s) {
            continue;
        }
        if (l == 0 && r == N - 1) {
            writeln("YES");
            return;
        }
        if ((r - l) % 2 == 0) {
            writeln("NO");
            return;
        }

        int lseg = l == 0 ? -1 : uf.find(l-1);
        int rseg = r+1 == N ? -1 : uf.find(r+1);

        if (lseg == -1) {
            uf.unite(l, rseg);
        } else if (rseg == -1) {
            uf.unite(l, lseg);
        } else if (uf.seg[lseg][2] < uf.seg[rseg][2]) {
            uf.unite(l, lseg);
        } else if (uf.seg[lseg][2] > uf.seg[rseg][2]) {
            uf.unite(l, rseg);
        } else {
            uf.unite(l, lseg);
            uf.unite(l, rseg);
        }
        pq.insert(uf.seg[uf.find(l)]);
    }

    writeln("NO");
}

class UnionFind {
    int N;
    int[] table;
    Tuple!(int, int, long)[] seg;

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

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

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        auto l = min(seg[x][0], seg[y][0]);
        auto r = max(seg[x][1], seg[y][1]);
        auto h = max(seg[x][2], seg[y][2]);
        seg[x] = seg[y] = tuple(l, r, h);
        table[x] += table[y];
        table[y] = x;
    }
}


Kuroni is the coordinator of the next Mathforces round written by the "Proof by AC" team. All the preparation has been done, and he is discussing with the team about the score distribution for the round.The round consists of $$$n$$$ problems, numbered from $$$1$$$ to $$$n$$$. The problems are ordered in increasing order of difficulty, no two problems have the same difficulty. A score distribution for the round can be denoted by an array $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ is the score of $$$i$$$-th problem. Kuroni thinks that the score distribution should satisfy the following requirements:  The score of each problem should be a positive integer not exceeding $$$10^9$$$.  A harder problem should grant a strictly higher score than an easier problem. In other words, $$$1 \leq a_1 < a_2 < \dots < a_n \leq 10^9$$$.  The balance of the score distribution, defined as the number of triples $$$(i, j, k)$$$ such that $$$1 \leq i < j < k \leq n$$$ and $$$a_i + a_j = a_k$$$, should be exactly $$$m$$$. Help the team find a score distribution that satisfies Kuroni's requirement. In case such a score distribution does not exist, output $$$-1$$$.

The first and single line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 5000$$$, $$$0 \leq m \leq 10^9$$$) — the number of problems and the required balance.

If there is no solution, print a single integer $$$-1$$$. Otherwise, print a line containing $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, representing a score distribution that satisfies all the requirements. If there are multiple answers, print any of them.

NoteIn the first example, there are $$$3$$$ triples $$$(i, j, k)$$$ that contribute to the balance of the score distribution.   $$$(1, 2, 3)$$$  $$$(1, 3, 4)$$$  $$$(2, 4, 5)$$$

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}

void main()
{
  int n, m; get(n, m);
  auto trips = new int[n + 1];
  int k = 0;
  foreach(i; 2 .. n + 1)
    trips[i] = trips[i - 1] + cast(int)(i - 1) / 2,
      k = cast(int)(k == 0? (trips[i] > m? i - 1 : 0) : k);
  int remainingLength = n - k - 1;
  int border = 2*k + 1 - 2*(m - trips[k]);
  int startValue = max(2*border, remainingLength - 1);
  int jump = border + 1;
  ans(m > trips[n]? [-1]:
      m == trips[n]? iota(1, 1 + n).array:
      m == 0? iota(n - 1, 2*n - 1).array:
      chain(iota(1, 1 + k),
	    [border],
	    iota(0, remainingLength).map!(i => startValue + jump * i))
      .array);
}

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}

int main()
{
  int n, m;
  get(n, m);
  int[] trips = new int[n + 1];
  trips[1] = 0;
  foreach(i; iota(2, 1 + n))
      trips[i] = trips[i - 1] + (i - 1) / 2;
  if (m > trips[n])
    ans(-1);
  if (m == trips[n])
    ans(iota(1, 1 + n).array);
  if (m == 0)
    ans(iota(n - 1, 2*n - 1).array);
  size_t k = 0;
  foreach(i, t; trips)
      if (t > m)
	{
	  k = i - 1;
	  break;
	}
  auto remainingLength = n - k - 1;
  auto border = 2*k + 1 - 2*(m - trips[k]);
  auto startValue = max(2*border, remainingLength - 1);
  auto jump = border + 1;
  ans(chain(iota(1, 1 + k).array,
	    [border],
	    iota(0, remainingLength).map!(i => startValue + jump * i))
      .array);
  assert(0);
}

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

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

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

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

void main() {
  /*
  debug {
    enum lim = 16;
    auto anss = new int[][][][](lim + 1, lim^^2 + 1);
    foreach (p; 0 .. 1 << lim) {
      const n = popcnt(p);
      int m;
      foreach (a; 1 .. lim + 1) foreach (b; a + 1 .. lim - a + 1) {
        if ((p & 1 << (a - 1)) && (p & 1 << (b - 1)) && (p & 1 << (a + b - 1))) {
          ++m;
        }
      }
      anss[n][m] ~= iota(1, lim + 1).filter!(a => (p & 1 << (a - 1))).array;
    }
    foreach (n; 0 .. lim + 1) {
      foreach (m; 0 .. n^^2 + 1) {
        writeln(n, " ", m, ": ", anss[n][m]);
      }
    }
  }
  */

  try {
    for (; ; ) {
      const N = readInt();
      const M = readInt();

      int[] ans;
      foreach (x; 1 .. N + 1) {
        // x, ..., x + N
        int all;
        foreach (i; 0 .. N + 1) {
          // 0 <= i < j <= N, (x + i) + (x + j) <= x + N
          const lb = i + 1;
          const ub = N - x - i;
          if (lb <= ub) {
            all += (ub - lb + 1);
          }
        }
        foreach (y; 0 .. N + 1) {
          // x, ..., x + y - 1, x + y + 1, ..., x + N
          int num = all;
          /*
            0 <= i < j <= y - 1, (x + i) + (x + j) = x + y
            0 <= i < -i - x + y <= y - 1
          */
          {
            const lb = max(0, -x - 1);
            const ub = ((-x + y - 1) - (((-x + y - 1)) & 1)) / 2;
            if (lb <= ub) {
              num -= (ub - lb + 1);
            }
          }
          // 0 <= i <= N, (x + y) + (x + i) <= x + N
          {
            const lb = 0;
            const ub = min(N, N - x - y);
            if (lb <= ub) {
              num -= (ub - lb + 1);
            }
          }
          // (x + y) + (x + y) <= x + N
          if ((x + y) + (x + y) <= x + N) {
            num += 1;
          }
          debug {
            // writeln(x, " ", y, ": ", num);
          }
          if (num == M) {
            ans = iota(x, x + y).array ~ iota(x + y + 1, x + N + 1).array;
            goto found;
          }
        }
      }
      writeln("-1");
      continue;
     found:
      assert(ans.length == N);
      foreach (i; 0 .. N) {
        if (i > 0) write(" ");
        write(ans[i]);
      }
      writeln();

      debug {
        bool[int] app;
        foreach (i; 0 .. N) {
          app[ans[i]] = true;
        }
        int cnt;
        foreach (i; 0 .. N) foreach (j; i + 1 .. N) {
          if ((ans[i] + ans[j]) in app) {
            ++cnt;
          }
        }
        assert(cnt == M);
      }
    }
  } catch (EOFException e) {
  }
}

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}

int main()
{
  int n, m;
  get(n, m);
  int[] trips = new int[n + 1];
  trips[1] = 0;
  foreach(i; iota(2, 1 + n))
      trips[i] = trips[i - 1] + (i - 1) / 2;
  if (m > trips[n])
    ans(-1);
  if (m == trips[n])
    ans(iota(1, 1 + n).array);
  if (m == 0)
    ans(iota(n - 1, 2*n - 1).array);
  uint k = 0;
  foreach(i, t; trips)
      if (t > m)
	  k = i - 1;
  auto remainingLength = n - k - 1;
  auto startValue = max(2*k + 3 - (m - trips[k]), remainingLength - 1);
  ans(chain(iota(1, 1 + k).array,
	    [2 * k + 1 - 2*(m - trips[k])],
	    iota(startValue, startValue + remainingLength))
      .array);
  assert(0);
}

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}

int main()
{
  int n, m;
  get(n, m);
  int[] trips = new int[n + 1];
  trips[1] = 0;
  foreach(i; iota(2, 1 + n))
      trips[i] = trips[i - 1] + (i - 1) / 2;
  if (m > trips[n])
    ans(-1);
  if (m == trips[n])
    ans(iota(1, 1 + n).array);
  if (m == 0)
    ans(iota(n - 1, 2*n - 1).array);
  size_t k = 0;
  foreach(i, t; trips)
      if (t > m)
	{
	  k = i - 1;
	  break;
	}
  auto remainingLength = n - k - 1;
  auto border = 2*k + 1 - 2*(m - trips[k]);
  auto startValue = max(2*border, remainingLength - 1);
  ans(chain(iota(1, 1 + k).array,
	    [border],
	    iota(startValue, startValue + remainingLength))
      .array);
  assert(0);
}

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}

int main()
{
  int n, m;
  get(n, m);
  int[] trips = new int[n + 1];
  trips[1] = 0;
  foreach(i; iota(2, 1 + n))
      trips[i] = trips[i - 1] + (i - 1) / 2;
  if (m > trips[n])
    ans(-1);
  if (m == trips[n])
    ans(iota(1, 1 + n).array);
  if (m == 0)
    ans(iota(n - 1, 2*n - 1));
  uint k = 0;
  foreach(i, t; trips)
      if (t > m)
	  k = i - 1;
  auto remainingLength = n - k - 1;
  auto startValue = max(2*k + 3 - (m - trips[k]), remainingLength - 1);
  ans(chain(iota(1, 1 + k).array,
	    [2 * k + 1 - 2*(m - trips[k])],
	    iota(startValue, startValue + remainingLength))
      .array);
  assert(0);
}

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}

int main()
{
  int n, m;
  get(n, m);
  int[] trips = new int[n + 1];
  trips[1] = 0;
  foreach(i; iota(2, 1 + n))
      trips[i] = trips[i - 1] + (i - 1) / 2;
  if (m > trips[n])
    ans(-1);
  if (m == trips[n])
    ans(iota(1, 1 + n).array);
  if (m == 0)
    ans(iota(n - 1, 2*n - 1));
  uint k = 0;
  foreach(i, t; trips)
      if (t > m)
	  k = i - 1;
  wr("k", k);
  auto remainingLength = n - k - 1;
  auto startValue = max(2*k + 3 - (m - trips[k]), remainingLength - 1);
  ans(chain(iota(1, 1 + k).array,
	    [2 * k + 1 - 2*(m - trips[k])],
	    iota(startValue, startValue + remainingLength))
      .array);
  assert(0);
}


Given an array $$$a=[a_1,a_2,\dots,a_n]$$$ of $$$n$$$ positive integers, you can do operations of two types on it:  Add $$$1$$$ to every element with an odd index. In other words change the array as follows: $$$a_1 := a_1 +1, a_3 := a_3 + 1, a_5 := a_5+1, \dots$$$.  Add $$$1$$$ to every element with an even index. In other words change the array as follows: $$$a_2 := a_2 +1, a_4 := a_4 + 1, a_6 := a_6+1, \dots$$$.Determine if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers. In other words, determine if you can make all elements of the array have the same parity after any number of operations.Note that you can do operations of both types any number of times (even none). Operations of different types can be performed a different number of times.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 50$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^3$$$) — the elements of the array. Note that after the performed operations the elements in the array can become greater than $$$10^3$$$.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteFor the first test case, we can increment the elements with an even index, obtaining the array $$$[1, 3, 1]$$$, which contains only odd numbers, so the answer is "YES".For the second test case, we can show that after performing any number of operations we won't be able to make all elements have the same parity, so the answer is "NO".For the third test case, all elements already have the same parity so the answer is "YES".For the fourth test case, we can perform one operation and increase all elements at odd positions by $$$1$$$, thus obtaining the array $$$[1001, 1, 1001, 1, 1001]$$$, and all elements become odd so the answer is "YES".

import std;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		writeln (iota (n - 2).all !(i =>
		    a[i] % 2 == a[i + 2] % 2) ? "YES" : "NO");
	}
}


You are given an array $$$a$$$ of $$$n$$$ positive integers.You can use the following operation as many times as you like: select any integer $$$1 \le k \le n$$$ and do one of two things:   decrement by one $$$k$$$ of the first elements of the array.  decrement by one $$$k$$$ of the last elements of the array. For example, if $$$n=5$$$ and $$$a=[3,2,2,1,4]$$$, then you can apply one of the following operations to it (not all possible options are listed below):   decrement from the first two elements of the array. After this operation $$$a=[2, 1, 2, 1, 4]$$$;  decrement from the last three elements of the array. After this operation $$$a=[3, 2, 1, 0, 3]$$$;  decrement from the first five elements of the array. After this operation $$$a=[2, 1, 1, 0, 3]$$$; Determine if it is possible to make all the elements of the array equal to zero by applying a certain number of operations.

The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 30000$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case begins with a line containing one integer $$$n$$$ ($$$1 \le n \le 30000$$$) — the number of elements in the array. The second line of each test case contains $$$n$$$ integers $$$a_1 \ldots a_n$$$ ($$$1 \le a_i \le 10^6$$$). The sum of $$$n$$$ over all test cases does not exceed $$$30000$$$.

For each test case, output on a separate line:    YES, if it is possible to make all elements of the array equal to zero by applying a certain number of operations.  NO, otherwise.  The letters in the words YES and NO can be outputed in any case.

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		int lo = int.max;
		int hi = 0;
		bool ok = true;
		foreach (i; 0..n)
		{
			lo = min (lo, a[i] - hi);
			hi = max (hi, a[i] - lo);
			ok &= (lo >= 0 && lo + hi == a[i]);
			debug {writeln (lo, " ", hi, " ", ok);}
		}
		writeln (ok ? "YES" : "NO");
	}
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const N = readInt();
        auto A = new long[N];
        foreach (i; 0 .. N) {
          A[i] = readLong();
        }

        auto ds = new long[N + 1];
        ds[0] = A[0] - 0;
        foreach (i; 1 .. N) {
          ds[i] = A[i] - A[i - 1];
        }
        ds[N] = 0 - A[N - 1];
        debug {
          writeln("ds = ", ds);
        }

        long posi, nega;
        foreach (i; 1 .. N) {
          if (ds[i] > 0) posi += ds[i];
          if (ds[i] < 0) nega += ds[i];
        }

        const ans = (ds[0] >= -nega && -ds[N] >= posi);
        writeln(ans ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
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 bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;

		long x = a[0];
		long y;
		foreach (i; 0..n)
		{
			x.chmin(a[i]);
			auto rem = a[i] - x;
			auto d = rem - y;
			if (d < 0)
			{
				x += d;
			}
			if (x < 0) break;
			a[i] -= x;
			y = a[i];
		}
		x = a[$-1];
		y = 0;
		foreach_reverse (i; 0..n)
		{
			x.chmin(a[i]);
			auto rem = a[i] - x;
			auto d = rem - y;
			if (d < 0)
			{
				x += d;
			}
			if (x < 0) break;
			a[i] -= x;
			y = a[i];
		}
		auto s = a.sum;
		ans[ti] = s == 0;
	}

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

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		auto b = new int [n];
		foreach (k; 0..2)
		{
			int lo = int.max;
			foreach (i; 0..n)
			{
				lo = min (lo, a[i]);
				b[i] += lo;
			}
			reverse (a);
			reverse (b);
		}
		writeln (n.iota.all !(i => a[i] <= b[i]) ? "YES" : "NO");
	}
}


A PIN code is a string that consists of exactly $$$4$$$ digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0.Polycarp has $$$n$$$ ($$$2 \le n \le 10$$$) bank cards, the PIN code of the $$$i$$$-th card is $$$p_i$$$.Polycarp has recently read a recommendation that it is better to set different PIN codes on different cards. Thus he wants to change the minimal number of digits in the PIN codes of his cards so that all $$$n$$$ codes would become different.Formally, in one step, Polycarp picks $$$i$$$-th card ($$$1 \le i \le n$$$), then in its PIN code $$$p_i$$$ selects one position (from $$$1$$$ to $$$4$$$), and changes the digit in this position to any other. He needs to change the minimum number of digits so that all PIN codes become different.Polycarp quickly solved this problem. Can you solve it?

The first line contains integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then test cases follow. The first line of each of $$$t$$$ test sets contains a single integer $$$n$$$ ($$$2 \le n \le 10$$$) — the number of Polycarp's bank cards. The next $$$n$$$ lines contain the PIN codes $$$p_1, p_2, \dots, p_n$$$ — one per line. The length of each of them is $$$4$$$. All PIN codes consist of digits only.

Print the answers to $$$t$$$ test sets. The answer to each set should consist of a $$$n + 1$$$ lines In the first line print $$$k$$$ — the least number of changes to make all PIN codes different. In the next $$$n$$$ lines output the changed PIN codes in the order corresponding to their appearance in the input. If there are several optimal answers, print any of them.

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

void main ()
{
	int tests;
	readf !(" %s") (tests);
	foreach (test; 0..tests)
	{
		int n;
		readf !(" %s") (n);
		readln;

		char [] [] s;
		foreach (i; 0..n)
		{
			s ~= readln.strip.dup;
		}

		int res = 0;
		bool [string] vis;
		foreach (ref line; s)
		{
			if (line.idup in vis)
			{
				res += 1;
				line[0] = "0123456789".byChar.find !(c =>
				    s.all !(other => other[0] != c)).front;
			}
			vis[line.idup] = true;
		}
		writeln (res);
		foreach (ref line; s)
		{
			writeln (line);
		}
	}
}

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

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

void solve(){
	int t = rint;
	foreach(_; 0 .. t){
		int n = rint;
		string[] ps = rtypes!string(n);
		string[] qs = new string[](n);
		A: foreach(i; 0 .. n){
			foreach(j; 0 .. n) if(ps[i] == qs[j]) continue A;
			qs[i] = ps[i];
		}
		string m = "1234567890";
		foreach(i; 0 .. n){
			if(qs[i] != "") continue;
			string p = ps[i];
			while(1){
				bool f = 0;
				foreach(j; 0 .. n) if(p == qs[j]) f = 1;
				if(f) p = p[0 .. 3] ~ m[p[3] - '0'];
				else break;
			}
			qs[i] = p;
		}
		int cnt;
		foreach(i; 0 .. n) if(ps[i] != qs[i]) cnt += 1;
		cnt.writeln;
		foreach(q; qs) q.writeln;
	}
}

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new string[][](t);
	auto cnt = new int[](t);
	foreach (i; 0..t)
	{
		auto n = RD!int;
		int[string] set;
		auto str = new string[](n);
		foreach (j; 0..n)
		{
			auto p = RD!string;
			str[j] = p;
			++set[p];
		}
		foreach (j; 0..n)
		{
			if (set[str[j]] == 1)
			{
				continue;
			}

			--set[str[j]];
			++cnt[i];
			(){
			foreach (k; 0..4)
			{
				foreach (num; 0..10)
				{
					auto tmp = str[j].dup;
					tmp[k] = num.to!string[0];
					if (set.get(tmp.idup, 0) == 0)
					{
						str[j] = tmp.idup;
						++set[str[j]];
						return;
					}
				}
			}}();
		}
		ans[i].length = n;
		foreach (j; 0..n)
		{
			ans[i][j] = str[j];
		}
	}

	foreach (i; 0..t)
	{
		writeln(cnt[i]);
		foreach (e; ans[i])
			writeln(e);
	}
	stdout.flush;
	debug readln;
}

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

void main ()
{
	int tests;
	readf !(" %s") (tests);
	foreach (test; 0..tests)
	{
		int n;
		readf !(" %s") (n);
		readln;

		char [] [] s;
		foreach (i; 0..n)
		{
			s ~= readln.strip.dup;
		}

		int res = 0;
		bool [string] vis;
		foreach (ref line; s)
		{
			if (line.idup in vis)
			{
				res += 1;
				do
				{
					int d = line[0] - '0';
					d = (d + 1) % 10;
					line[0] = cast (char) (d + '0');
				}
				while (line in vis);
			}
			vis[line.idup] = true;
		}
		writeln (res);
		foreach (ref line; s)
		{
			writeln (line);
		}
	}
}

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

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

void solve(){
	int t = rint;
	foreach(_; 0 .. t){
		int n = rint;
		string[] ps = rtypes!string(n);
		string[] qs;
		int[string] px;
		bool[string] qset;
		int cnt = 0;
		foreach(int i, p; ps) if(p !in px) px[p] = i;
		foreach(int i, p; ps){
			if(px[p] != i){
				cnt += 1;
				char[] q = p.to!(char[]);
				while(q.to!string in qset) q[3] = '0' + (q[3] - '0' + 1) % 10;
				qset[q.to!string] = 1;
				qs ~= q.to!string;
			}
			else{
				qset[p] = 1;
				qs ~= p;
			}
		}
		cnt.writeln;
		foreach(q; qs) q.writeln;
	}
}

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

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

void solve(){
	int t = rint;
	foreach(_; 0 .. t){
		int n = rint;
		string[] ps = rtypes!string(n);
		string[] qs;
		bool[string] qset;
		int cnt = 0;
		foreach(p; ps){
			char[] q = p.to!(char[]);
			if(q.to!string in qset) cnt += 1;
			while(q.to!string in qset) q[3] = '0' + (q[3] - '0' + 1) % 10;
			qset[q.to!string] = 1;
			qs ~= q.to!string;
		}
		cnt.writeln;
		foreach(q; qs) q.writeln;
	}
}

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new string[][](t);
	auto cnt = new int[](t);
	foreach (i; 0..t)
	{
		auto n = RD!int;
		int[string] set;
		foreach (j; 0..n)
		{
			auto p = RD!string;
			bool ok = true;
			while (set.get(p, -1) >= 0)
			{
				ok = false;
				p = ((p.to!int+1) % 10000).to!string;
			}
			set[p] = j;
			if (!ok)
				++cnt[i];
		}
		ans[i].length = n;
		foreach (key; set.keys)
		{
			ans[i][set[key]] = key;
		}
	}

	foreach (i; 0..t)
	{
		writeln(cnt[i]);
		foreach (e; ans[i])
			writeln(e);
	}
	stdout.flush;
	debug readln;
}


Lena is a programmer. She got a task to solve at work.There is an empty set of pairs of integers and n queries to process. Each query is one of three types:  Add a pair (a, b) to the set.  Remove a pair added in the query number i. All queries are numbered with integers from 1 to n.  For a given integer q find the maximal value x·q + y over all pairs (x, y) from the set. Help Lena to process the queries.

The first line of input contains integer n (1 ≤ n ≤ 3·105) — the number of queries. Each of the next n lines starts with integer t (1 ≤ t ≤ 3) — the type of the query. A pair of integers a and b ( - 109 ≤ a, b ≤ 109) follows in the query of the first type. An integer i (1 ≤ i ≤ n) follows in the query of the second type. It is guaranteed that i is less than the number of the query, the query number i has the first type and the pair from the i-th query is not already removed. An integer q ( - 109 ≤ q ≤ 109) follows in the query of the third type.

For the queries of the third type print on a separate line the desired maximal value of x·q + y. If there are no pairs in the set print "EMPTY SET".

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

immutable long inf = 2 * cast(long) 1e18 + 5;

struct line
{
    long a, b;
    long val(long x)
    {
        return a * x + b;
    }
}

class convex_hull
{
    line[] d;
    size_t ptr = 0;
    bool check(in line i, in line j, in line k)
    {
        return (k.b - i.b) * 1.0L / (i.a - k.a) < (j.b - i.b) * 1.0L / (i.a - j.a);
    }

    ref line opIndex(size_t x)
    {
        return d[x];
    }

    void opOpAssign(string op)(line x)
    {
        if (op == "~")
        {
            if (d.length && d[$ - 1].a == x.a)
            {
                x.b = max(x.b, d[$ - 1].b);
                --d.length;
            }
            d ~= x;
            while (d.length > 2 && check(d[$ - 3], d[$ - 2], d[$ - 1]))
            {
                d[$ - 2] = d[$ - 1];
                --d.length;
            }
        }
    }

    long query(long x)
    {
        if (ptr == d.length)
            return -inf;
        while (ptr + 1 < d.length && d[ptr].val(x) < d[ptr + 1].val(x))
            ++ptr;
        return d[ptr].val(x);
    }
}

class IT
{
    convex_hull[] T;
    this(int size = 0)
    {
        T = new convex_hull[4 * size];
        foreach (ref t; T)
            t = new convex_hull;
    }

    void up(int v, int l, int r, int i, int j, in line val)
    {
        if (l > j || r < i)
            return;
        if (i <= l && r <= j)
        {
            T[v] ~= val;
            return;
        }
        immutable int mid = (l + r) / 2;
        up(2 * v, l, mid, i, j, val);
        up(2 * v + 1, mid + 1, r, i, j, val);
    }

    long get(int v, int l, int r, int pos, in long x)
    {
        if (l > pos || r < pos)
            return -inf;
        if (l == r)
            return T[v].query(x);
        immutable int mid = (l + r) / 2;
        return max(T[v].query(x), get(2 * v, l, mid, pos, x), get(2 * v + 1, mid + 1,
            r, pos, x));
    }
}

IT T;

struct Query
{
    int typ, x, st, ed;
    line a;
}

Query[] Q, Add, Ask;
long[] ans;

int N;

void main()
{
    readf("%d\n", &N);
    Q = new Query[N];
    T = new IT(N);
    ans = new long[N];
    foreach (i; 0 .. N)
    {
        auto q = &Q[i];
        readf("%d ", &q.typ);
        if (q.typ == 1)
        {
            readf("%d %d\n", &q.a.a, &q.a.b);
            q.st = i + 1;
            q.ed = N;
        }
        else if (q.typ == 2)
        {
            readf("%d\n", &q.x);
            Q[q.x - 1].ed = i + 1;
        }
        else
        {
            readf("%d\n", &q.x);
            q.st = i + 1;
            Ask ~= *q;
        }
    }
    foreach (ref q; Q)
        if (q.typ == 1)
            Add ~= q;
    sort!`a.a.a < b.a.a`(Add);
    foreach (ref q; Add)
        T.up(1, 1, N, q.st, q.ed, q.a);
    sort!`a.x < b.x`(Ask);
    foreach (ref q; Ask)
        ans[q.st - 1] = T.get(1, 1, N, q.st, q.x);
    foreach (i; 0 .. N)
        if (Q[i].typ == 3)
        {
            if (ans[i] == -inf)
                writeln("EMPTY SET");
            else
                writeln(ans[i]);
        }
}

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

immutable long inf = 2 * cast(long) 1e18 + 5;

struct line
{
    long a, b;
    long val(long x)
    {
        return a * x + b;
    }
}

class convex_hull
{
    line[] d;
    size_t ptr = 0;
    bool check(in line i, in line j, in line k)
    {
        return (k.b - i.b) * 1.0L / (i.a - k.a) < (j.b - i.b) * 1.0L / (i.a - j.a);
    }

    ref line opIndex(size_t x)
    {
        return d[x];
    }

    void opOpAssign(string op)(line x)
    {
        if (op == "~")
        {
            if (d.length && d[$ - 1].a == x.a)
            {
                x.b = max(x.b, d[$ - 1].b);
                --d.length;
            }
            d ~= x;
            while (d.length > 2 && check(d[$ - 3], d[$ - 2], d[$ - 1]))
            {
                d[$ - 2] = d[$ - 1];
                --d.length;
            }
        }
    }

    long query(long x)
    {
        if (ptr == d.length)
            return -inf;
        while (ptr + 1 < d.length && d[ptr].val(x) < d[ptr + 1].val(x))
            ++ptr;
        return d[ptr].val(x);
    }
}

class IT
{
    convex_hull[] T;
    this(int size = 0)
    {
        T = new convex_hull[4 * size];
        foreach (ref t; T)
            t = new convex_hull;
    }

    void up(int v, int l, int r, int i, int j, in line val)
    {
        if (l > j || r < i)
            return;
        if (i <= l && r <= j)
        {
            T[v] ~= val;
            return;
        }
        immutable int mid = (l + r) / 2;
        up(2 * v, l, mid, i, j, val);
        up(2 * v + 1, mid + 1, r, i, j, val);
    }

    long get(int v, int l, int r, int pos, in long x)
    {
        if (l > pos || r < pos)
            return -inf;
        if (l == r)
            return T[v].query(x);
        immutable int mid = (l + r) / 2;
        return max(T[v].query(x), get(2 * v, l, mid, pos, x), get(2 * v + 1, mid + 1,
            r, pos, x));
    }
}

IT T;

struct Query
{
    int typ, x, st, ed;
    line a;
}

Query[] Q, Add, Ask;
long[] ans;

int N;

void main()
{
    readf("%d\n", &N);
    Q = new Query[N];
    T = new IT(N);
    ans = new long[N];
    foreach (i; 0 .. N)
    {
        auto q = &Q[i];
        readf("%d ", &q.typ);
        if (q.typ == 1)
        {
            readf("%d %d\n", &q.a.a, &q.a.b);
            q.st = i + 1;
            q.ed = N;
        }
        else if (q.typ == 2)
        {
            readf("%d\n", &q.x);
            Q[q.x - 1].ed = i + 1;
        }
        else
        {
            readf("%d\n", &q.x);
            q.st = i + 1;
            Ask ~= *q;
        }
    }
    foreach (ref q; Q)
        if (q.typ == 1)
            Add ~= q;
    sort!`a.a.a < b.a.a`(Add);
    foreach (ref q; Add)
        T.up(1, 1, N, q.st, q.ed, q.a);
    sort!`a.x < b.x`(Ask);
    foreach (ref q; Ask)
        ans[q.st - 1] = T.get(1, 1, N, q.st, q.x);
    foreach (i; 0 .. N)
        if (Q[i].typ == 3)
        {
            if (ans[i] == -inf)
                writef("EMPTY SET\n");
            else
                writef("%d\n", ans[i]);
        }
}

import std.stdio;
import std.algorithm;
import std.typecons;
import core.memory;
import std.container.array : Array;

immutable long inf = 2 * cast(long) 1e18 + 5;

struct line
{
    long a, b;
    long val(long x)
    {
        return a * x + b;
    }
}

class convex_hull
{
    line[] d;
    size_t ptr = 0;
    bool check(in line i, in line j, in line k)
    {
        return (k.b - i.b) * 1.0L / (i.a - k.a) < (j.b - i.b) * 1.0L / (i.a - j.a);
    }

    ref line opIndex(size_t x)
    {
        return d[x];
    }

    void opOpAssign(string op)(line x)
    {
        if (op == "~")
        {
            if (d.length && d[$ - 1].a == x.a)
            {
                x.b = max(x.b, d[$ - 1].b);
                --d.length;
            }
            d ~= x;
            while (d.length > 2 && check(d[$ - 3], d[$ - 2], d[$ - 1]))
            {
                d[$ - 2] = d[$ - 1];
                --d.length;
            }
        }
    }

    long query(long x)
    {
        if (ptr == d.length)
            return -inf;
        while (ptr + 1 < d.length && d[ptr].val(x) < d[ptr + 1].val(x))
            ++ptr;
        return d[ptr].val(x);
    }
}

class IT
{
    convex_hull[] T;
    this(int size = 0)
    {
        T = new convex_hull[4 * size];
        foreach (ref t; T)
            t = new convex_hull;
    }

    void up(int v, int l, int r, int i, int j, in line val)
    {
        if (l > j || r < i)
            return;
        if (i <= l && r <= j)
        {
            T[v] ~= val;
            return;
        }
        immutable int mid = (l + r) / 2;
        up(2 * v, l, mid, i, j, val);
        up(2 * v + 1, mid + 1, r, i, j, val);
    }

    long get(int v, int l, int r, int pos, in long x)
    {
        if (l > pos || r < pos)
            return -inf;
        if (l == r)
            return T[v].query(x);
        immutable int mid = (l + r) / 2;
        return max(T[v].query(x), get(2 * v, l, mid, pos, x), get(2 * v + 1, mid + 1,
            r, pos, x));
    }
}

IT T;

alias Query = Tuple!(int, "x", int, "st", int, "ed", line, "a", int, "typ");

Query[] Q, Add, Ask;
long[] ans;

int N;

void main()
{
    readf("%d\n", &N);
    Q = new Query[N];
    T = new IT(N);
    ans = new long[N];
    foreach (i; 0 .. N)
    {
        auto q = &Q[i];
        readf("%d ", &q.typ);
        if (q.typ == 1)
        {
            readf("%d %d\n", &q.a.a, &q.a.b);
            q.st = i + 1;
            q.ed = N;
        }
        else if (q.typ == 2)
        {
            readf("%d\n", &q.x);
            Q[q.x - 1].ed = i + 1;
        }
        else
        {
            readf("%d\n", &q.x);
            q.st = i + 1;
            Ask ~= *q;
        }
    }
    foreach (ref q; Q)
        if (q.typ == 1)
            Add ~= q;
    sort!`a.a.a < b.a.a`(Add);
    foreach (ref q; Add)
        T.up(1, 1, N, q.st, q.ed, q.a);
    sort!`a.x < b.x`(Ask);
    foreach (ref q; Ask)
        ans[q.st - 1] = T.get(1, 1, N, q.st, q.x);
    foreach (i; 0 .. N)
        if (Q[i].typ == 3)
        {
            if (ans[i] == -inf)
                writef("EMPTY SET\n");
            else
                writef("%d\n", ans[i]);
        }
}

import std.stdio;
import std.algorithm;
import std.typecons;
import core.memory;
import std.array : uninitializedArray;

immutable long inf = 2 * cast(long) 1e18 + 5;

struct line
{
    long a, b;
    long val(long x)
    {
        return a * x + b;
    }
}

class convex_hull
{
    line[] d;
    size_t ptr = 0;
    bool check(in line i, in line j, in line k)
    {
        return (k.b - i.b) * 1.0L / (i.a - k.a) < (j.b - i.b) * 1.0L / (i.a - j.a);
    }

    ref line opIndex(size_t x)
    {
        return d[x];
    }

    void opOpAssign(string op)(line x)
    {
        if (op == "~")
        {
            if (d.length && d[$ - 1].a == x.a)
            {
                x.b = max(x.b, d[$ - 1].b);
                --d.length;
            }
            d ~= x;
            while (d.length > 2 && check(d[$ - 3], d[$ - 2], d[$ - 1]))
            {
                d[$ - 2] = d[$ - 1];
                --d.length;
            }
        }
    }

    long query(long x)
    {
        if (ptr == d.length)
            return -inf;
        while (ptr + 1 < d.length && d[ptr].val(x) < d[ptr + 1].val(x))
            ++ptr;
        return d[ptr].val(x);
    }
}

class IT
{
    convex_hull[] T;
    this(int size = 0)
    {
        T = new convex_hull[4 * size];
        foreach (ref t; T)
            t = new convex_hull;
    }

    void up(int v, int l, int r, int i, int j, in line val)
    {
        if (l > j || r < i)
            return;
        if (i <= l && r <= j)
        {
            T[v] ~= val;
            return;
        }
        immutable int mid = (l + r) / 2;
        up(2 * v, l, mid, i, j, val);
        up(2 * v + 1, mid + 1, r, i, j, val);
    }

    long get(int v, int l, int r, int pos, in long x)
    {
        if (l > pos || r < pos)
            return -inf;
        if (l == r)
            return T[v].query(x);
        immutable int mid = (l + r) / 2;
        return max(T[v].query(x), get(2 * v, l, mid, pos, x), get(2 * v + 1, mid + 1,
            r, pos, x));
    }
}

IT T;

alias Query = Tuple!(int, "x", int, "st", int, "ed", line, "a", int, "typ");

Query[] Q, Add, Ask;
long[] ans;

int N;

void main()
{
    readf("%d\n", &N);
    Q = uninitializedArray!(Query[])(N);
    T = new IT(N);
    ans = uninitializedArray!(long[])(N);
    foreach (i; 0 .. N)
    {
        auto q = &Q[i];
        readf("%d ", &q.typ);
        if (q.typ == 1)
        {
            readf("%d %d\n", &q.a.a, &q.a.b);
            q.st = i + 1;
            q.ed = N;
        }
        else if (q.typ == 2)
        {
            readf("%d\n", &q.x);
            Q[q.x - 1].ed = i + 1;
        }
        else
        {
            readf("%d\n", &q.x);
            q.st = i + 1;
            Ask ~= *q;
        }
    }
    foreach (ref q; Q)
        if (q.typ == 1)
            Add ~= q;
    sort!`a.a.a < b.a.a`(Add);
    foreach (ref q; Add)
        T.up(1, 1, N, q.st, q.ed, q.a);
    sort!`a.x < b.x`(Ask);
    foreach (ref q; Ask)
        ans[q.st - 1] = T.get(1, 1, N, q.st, q.x);
    foreach (i; 0 .. N)
        if (Q[i].typ == 3)
        {
            if (ans[i] == -inf)
                writef("EMPTY SET\n");
            else
                writef("%d\n", ans[i]);
        }
}

import std.stdio;
import std.algorithm;
import std.typecons;
import core.memory;
import std.array : uninitializedArray;

immutable long inf = 2 * cast(long) 1e18 + 5;

struct line
{
    long a, b;
    long val(long x)
    {
        return a * x + b;
    }
}

class convex_hull
{
    line[] d;
    size_t ptr = 0;
    bool check(in line i, in line j, in line k)
    {
        return (k.b - i.b) * 1.0L / (i.a - k.a) < (j.b - i.b) * 1.0L / (i.a - j.a);
    }

    ref line opIndex(size_t x)
    {
        return d[x];
    }

    void opOpAssign(string op)(line x)
    {
        if (op == "~")
        {
            if (d.length && d[$ - 1].a == x.a)
            {
                x.b = max(x.b, d[$ - 1].b);
                --d.length;
            }
            d ~= x;
            while (d.length > 2 && check(d[$ - 3], d[$ - 2], d[$ - 1]))
            {
                d[$ - 2] = d[$ - 1];
                --d.length;
            }
        }
    }

    long query(long x)
    {
        if (ptr == d.length)
            return -inf;
        while (ptr + 1 < d.length && d[ptr].val(x) < d[ptr + 1].val(x))
            ++ptr;
        return d[ptr].val(x);
    }
}

class IT
{
    convex_hull[] T;
    this(int size = 0)
    {
        T = new convex_hull[4 * size];
        foreach (i; 0..4 * size)
						T[i] = new convex_hull;
    }

    void up(int v, int l, int r, int i, int j, in line val)
    {
        if (l > j || r < i)
            return;
        if (i <= l && r <= j)
        {
            T[v] ~= val;
            return;
        }
        immutable int mid = (l + r) / 2;
        up(2 * v, l, mid, i, j, val);
        up(2 * v + 1, mid + 1, r, i, j, val);
    }

    long get(int v, int l, int r, int pos, in long x)
    {
        if (l > pos || r < pos)
            return -inf;
        if (l == r)
            return T[v].query(x);
        immutable int mid = (l + r) / 2;
        return max(T[v].query(x), get(2 * v, l, mid, pos, x), get(2 * v + 1, mid + 1,
            r, pos, x));
    }
}

IT T;

alias Query = Tuple!(int, "x", int, "st", int, "ed", line, "a", int, "typ");

Query[] Q, Add, Ask;
long[] ans;

int N;

void main()
{
    readf("%d\n", &N);
    Q = uninitializedArray!(Query[])(N);
    T = new IT(N);
    ans = uninitializedArray!(long[])(N);
    foreach (i; 0 .. N)
    {
        auto q = &Q[i];
        readf("%d ", &q.typ);
        if (q.typ == 1)
        {
            readf("%d %d\n", &q.a.a, &q.a.b);
            q.st = i + 1;
            q.ed = N;
        }
        else if (q.typ == 2)
        {
            readf("%d\n", &q.x);
            Q[q.x - 1].ed = i + 1;
        }
        else
        {
            readf("%d\n", &q.x);
            q.st = i + 1;
            Ask ~= *q;
        }
    }
    for (int i = 0; i < N; ++i)
        if (Q[i].typ == 1)
            Add ~= Q[i];
    sort!`a.a.a < b.a.a`(Add);
    for (int i = 0; i < Add.length; ++i)
        T.up(1, 1, N, Add[i].st, Add[i].ed, Add[i].a);
    sort!`a.x < b.x`(Ask);
    for (int i = 0; i < Ask.length; ++i)
				ans[Ask[i].st - 1] = T.get(1, 1, N, Ask[i].st, Ask[i].x);
    foreach (i; 0 .. N)
        if (Q[i].typ == 3)
        {
            if (ans[i] == -inf)
                writef("EMPTY SET\n");
            else
                writef("%d\n", ans[i]);
        }
}

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

immutable long inf = 2 * cast(long) 1e18 + 5;

struct line
{
    long a, b;
    long val(long x)
    {
        return a * x + b;
    }
}

class convex_hull
{
    line[] d;
    size_t ptr = 0;
    bool check(in line i, in line j, in line k)
    {
        return (k.b - i.b) * 1.0L / (i.a - k.a) < (j.b - i.b) * 1.0L / (i.a - j.a);
    }

    ref line opIndex(size_t x)
    {
        return d[x];
    }

    void opOpAssign(string op)(line x)
    {
        if (op == "~")
        {
            if (d.length && d[$ - 1].a == x.a)
            {
                x.b = max(x.b, d[$ - 1].b);
                --d.length;
            }
            d ~= x;
            while (d.length > 2 && check(d[$ - 3], d[$ - 2], d[$ - 1]))
            {
                writeln(d.length);
                d[$ - 2] = d[$ - 1];
                --d.length;
            }
        }
    }

    long query(long x)
    {
        if (ptr == d.length)
            return -inf;
        while (ptr + 1 < d.length && d[ptr].val(x) < d[ptr + 1].val(x))
            ++ptr;
        return d[ptr].val(x);
    }
}

class IT
{
    convex_hull[] T;
    this(int size = 0)
    {
        T = new convex_hull[4 * size];
        foreach (ref t; T)
            t = new convex_hull;
    }

    void up(int v, int l, int r, int i, int j, in line val)
    {
        if (l > j || r < i)
            return;
        if (i <= l && r <= j)
        {
            T[v] ~= val;
            return;
        }
        immutable int mid = (l + r) / 2;
        up(2 * v, l, mid, i, j, val);
        up(2 * v + 1, mid + 1, r, i, j, val);
    }

    long get(int v, int l, int r, int pos, in long x)
    {
        if (l > pos || r < pos)
            return -inf;
        if (l == r)
            return T[v].query(x);
        immutable int mid = (l + r) / 2;
        return max(T[v].query(x), get(2 * v, l, mid, pos, x), get(2 * v + 1, mid + 1,
            r, pos, x));
    }
}

IT T;

struct Query
{
    int typ, x, st, ed;
    line a;
}

Query[] Q, Add, Ask;
long[] ans;

int N;

void main()
{
    readf("%d\n", &N);
    Q = new Query[N];
    T = new IT(N);
    ans = new long[N];
    foreach (i; 0 .. N)
    {
        auto q = &Q[i];
        readf("%d ", &q.typ);
        if (q.typ == 1)
        {
            readf("%d %d\n", &q.a.a, &q.a.b);
            q.st = i + 1;
            q.ed = N;
        }
        else if (q.typ == 2)
        {
            readf("%d\n", &q.x);
            Q[q.x - 1].ed = i + 1;
        }
        else
        {
            readf("%d\n", &q.x);
            q.st = i + 1;
            Ask ~= *q;
        }
    }
    foreach (ref q; Q)
        if (q.typ == 1)
            Add ~= q;
    sort!`a.a.a < b.a.a`(Add);
    foreach (ref q; Add)
        T.up(1, 1, N, q.st, q.ed, q.a);
    sort!`a.x < b.x`(Ask);
    foreach (ref q; Ask)
        ans[q.st - 1] = T.get(1, 1, N, q.st, q.x);
    foreach (i; 0 .. N)
        if (Q[i].typ == 3)
        {
            if (ans[i] == -inf)
                writeln("EMPTY SET");
            else
                writeln(ans[i]);
        }
}