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") string[] mat;

  void solve(long tc = -1)
  {
    foreach(i; 0 .. n)
      {
        foreach(j; 0 .. n)
          {
            if (mat.at(i).at(j) == '1')
              {
                if (i + 1 >= n || mat.at(i + 1).at(j) == '1' ||
                    j + 1 >= n || mat.at(i).at(j + 1) == '1')
                  {

                  }
                else
                  {
                    writeln("NO");
                    return;
                  }
              }
          }
      }
    writeln("YES");
  }
}

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.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 s = new string[](n);
		foreach (i; 0..n)
		{
			s[i] = RD!string;
		}

		ans[ti] = true;
		foreach (i; 0..n-1)
		{
			foreach (j; 0..n-1)
			{
				if (s[i][j] == '0') continue;
				if (s[i][j+1] == '0' && s[i+1][j] == '0')
					ans[ti] = false;
			}
		}
	}

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


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

class Stack(T) {
	private Appender!(T[], T) app;
	private size_t size = 0;

	this() {
		app = appender(new T[0]);
	}

	void push(T value) {
		if (app.data().length > size) {
			app.data[size] = value;
		} else {
			app.put(value);
		}
		++size;
	}

	T get(size_t i) {
		return app.data[i];
	}

	T pop() {
		if (size == 0) {
			throw new RangeError();
		}
		return app.data[--size];
	}

	bool empty() {
		return size == 0;
	}

	size_t length() {
		return size;
	}
}

enum WinCond {
	unknown,
	W1, // first player can enforce a win
	W2  // second player can enforce a win
}
enum LoseCond {
	unknown,
	L1, // first player can enforce a lose
	L2 // second player can enforce a lose
}

class StringNode {
	public StringNode[char.max] edges = null;
	WinCond win_cond;
	LoseCond lose_cond;
}

void addString(StringNode root, string str) {
	foreach (ch; str) {
		if (root.edges[ch] is null) {
			root.edges[ch] = new StringNode;
		}
		root = root.edges[ch];
	}
}

void calculateWinLoseState(StringNode root) {
	// alias ReturnType = Tuple!(WinCond, LoseCond);
	auto stack = new Stack!StringNode;
	stack.push(root);

	for (size_t i = 0; i != stack.length(); ++i) {
		foreach (edge; stack.get(i).edges) {
			if (edge !is null) {
				stack.push(edge);
			}
		}
	}

	while (!stack.empty()) {
		auto node = stack.pop();
		assert(node.win_cond == WinCond.unknown);
		assert(node.lose_cond == LoseCond.unknown);
		bool no_edges = true;
		foreach (i, edge; node.edges) {
			if (edge !is null) {
				//write(cast(char)i, ", ");
				no_edges = false;
				assert(edge.win_cond != WinCond.unknown);
				assert(edge.lose_cond != LoseCond.unknown);
				if (edge.win_cond == WinCond.W2) {
					node.win_cond = WinCond.W1;
				}
				if (edge.lose_cond == LoseCond.L2) {
					node.lose_cond = LoseCond.L1;
				}
			}
		}
		if (node.win_cond == WinCond.unknown) {
			node.win_cond = WinCond.W2;
		}
		if (no_edges) {
			node.lose_cond = LoseCond.L1;
		} else if (node.lose_cond == LoseCond.unknown) {
			node.lose_cond = LoseCond.L2;
		}
		//writeln(": ", node.win_cond, " ", node.lose_cond);
	}
}

void main() {
	int n, k;
	readf("%s %s\n", &n, &k);
	auto root = new StringNode;
	foreach (_; 0..n) {
		string line;
		while (line.empty)
			line = readln().strip;
		addString(root, line);
	}
	calculateWinLoseState(root);
	enum first = "First";
	enum second = "Second";
	switch (root.win_cond) {
	default:
		assert(false);
	case WinCond.W1:
		switch(root.lose_cond) {
		default:
			assert(false);
		case LoseCond.L1:
			writeln(first);
			break;
		case LoseCond.L2:
			writeln(k % 2 == 0 ? second : first);
		}
		break;
	case WinCond.W2:
		writeln(second);
	}
}

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

immutable int LET = 26;
immutable char START = 'a';
immutable int MAX_N = 100_005;
immutable int NA = -1;

struct Node
{
	int [LET] next = NA;
}

Node [MAX_N] t;
int m;
bool cur_outcome;

bool play (int v)
{
	assert (v != NA);

	bool ok = false;
	foreach (d; 0..LET)
	{
		if (t[v].next[d] != NA)
		{
			ok = true;
			if (!play (t[v].next[d]))
			{
				return true;
			}
		}
	}
	if (!ok)
	{
		return cur_outcome;
	}
	return false;
}

void build (const string [] s)
{
	debug {writeln (s);}
	t[] = Node.init;
	m = 1;
	foreach (cur; s)
	{
		int v = 0;
		foreach (let; cur)
		{
			debug {writeln (v, ' ', let - START);}
			if (t[v].next[let - START] == NA)
			{
				t[v].next[let - START] = m;
				m++;
			}
			v = t[v].next[let - START];
		}
	}
}

bool win (bool outcome)
{
	cur_outcome = outcome;
	return play (0);
}

bool solve (const string [] s, int k)
{
	build (s);

	bool can_win = win (false);
	bool can_lose = win (true);
	debug {writeln (can_win, ' ', can_lose);}

	if (can_win && !can_lose)
	{
		return k & 1;
	}

	if (!can_win && can_lose)
	{
		return false;
	}

	if (can_win && can_lose)
	{
		return true;
	}

	if (!can_win && !can_lose)
	{
		return false;
	}

	assert (false);
}

void main ()
{
	int n;
	int k;
	while (readf (" %s %s ", &n, &k) > 0)
	{
		auto s = new string [n];
		foreach (ref x; s)
		{
			x = readln ().strip ();
		}

		writeln (solve (s, k) ? "First" : "Second");
	}
}

import core.thread;
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;

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

//	chmin/chmax
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

immutable LIM = 100_005;
immutable E = 26;

int N, K;
string[] A;

int V;
int[][] g;
int newNode() {
	g[V][] = -1;
	return V++;
}

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;
		K = readInt;
		A = new string[N];
		foreach (i; 0 .. N) {
			A[i] = readToken;
		}

		V = 0;
		g = new int[][](LIM, E);
		newNode;
		foreach (i; 0 .. N) {
			int u = 0;
			foreach (c; A[i]) {
				const e = c - 'a';
				if (g[u][e] == -1) {
					g[u][e] = newNode;
				}
				u = g[u][e];
			}
		}

		int[] rts = new int[2];
		foreach (lf; 0 .. 2) {
			int[] dp = new int[V];
			foreach_reverse (u; 0 .. V) {
				bool isLeaf = true;
				dp[u] = 0;
				foreach (e; 0 .. E) {
					const v = g[u][e];
					if (v != -1) {
						isLeaf = false;
						if (!dp[v]) {
							dp[u] = 1;
						}
					}
				}
				if (isLeaf && lf) {
					dp[u] = 1;
				}
			}
debug{
writeln("dp = ",dp);
}
			rts[lf] = dp[0];
		}

		int k = K;
		if (k >= 100) {
			k -= (k - 100) / 2 * 2;
		}

		int r = 0;
		foreach (_; 0 .. k) {
			r = rts[r];
		}
		writeln(r ? "First" : "Second");

	}
	} catch (EOFException) {}
}

import std.stdio;
import std.algorithm;
import std.string;

const int MAX = 100005;
string[MAX] s;
int n, k;

struct Node {
    char c;
    Node*[char] children;
}

void main() {
    readf(" %s %s", n, k);
    readln();
    foreach(i; 0..n) s[i] = readln().chomp();

    auto root = new Node();
    foreach(i; 0..n) {
        auto cur = root;
        foreach(c; s[i]) {
            if (c !in cur.children) {
                auto node = new Node();
                node.c = c;
                cur.children[c] = node;
            }
            cur = cur.children[c];
        }
    }

    auto canWinMatch = root.children.values.any!(node => can(node, true));
    auto canLossMatch = root.children.values.any!(node => can(node, false));
    bool firstWin;
    if (!canWinMatch) {
        firstWin = false;
    } else if (canLossMatch) {
        firstWin = true;
    } else {
        firstWin = (k % 2 == 1);
    }
    writeln(firstWin ? "First" : "Second");
}

bool can(Node* node, bool win) {
    if (node.children.empty) {
        return win;
    }
    auto result = true;
    foreach(c; node.children.keys) {
        result &= (can(node.children[c], win) == false);
    }
    return result;
}

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

immutable int LET = 26;
immutable char START = 'a';
immutable int MAX_N = 100_005;
immutable int NA = -1;

struct Node
{
	int [LET] next = NA;
}

Node [MAX_N] t;
int m;
bool cur_outcome;

bool play (int v)
{
	assert (v != NA);

	bool ok = false;
	foreach (d; 0..LET)
	{
		if (t[v].next[d] != NA)
		{
			ok = true;
			if (!play (t[v].next[d]))
			{
				return true;
			}
		}
	}
	if (!ok)
	{
		return cur_outcome;
	}
	return false;
}

void build (const string [] s)
{
	debug {writeln (s);}
	t[] = Node.init;
	m = 1;
	foreach (cur; s)
	{
		int v = 0;
		foreach (let; cur)
		{
			debug {writeln (v, ' ', let - START);}
			if (t[v].next[let - START] == NA)
			{
				t[v].next[let - START] = m;
				m++;
			}
			v = t[v].next[let - START];
		}
	}
}

bool win (bool outcome)
{
	cur_outcome = outcome;
	return play (0);
}

bool solve (const string [] s, int k)
{
	build (s);

	bool can_win = win (false);
	bool can_lose = win (true);

	if (can_win && !can_lose)
	{
		return k & 1;
	}

	if (!can_win && can_lose)
	{
		return false;
	}

	return true;
}

void main ()
{
	int n;
	int k;
	while (readf (" %s %s ", &n, &k) > 0)
	{
		auto s = new string [n];
		foreach (ref x; s)
		{
			x = readln ().strip ();
		}

		writeln (solve (s, k) ? "First" : "Second");
	}
}

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

class Stack(T) {
	private Appender!(T[], T) app;
	private size_t size = 0;

	this() {
		app = appender(new T[0]);
	}

	void push(T value) {
		if (app.data().length > size) {
			app.data[size] = value;
		} else {
			app.put(value);
		}
		++size;
	}

	T get(size_t i) {
		return app.data[i];
	}

	T pop() {
		if (size == 0) {
			throw new RangeError();
		}
		return app.data[--size];
	}

	bool empty() {
		return size == 0;
	}

	size_t length() {
		return size;
	}
}

enum WinCond {
	unknown,
	W1, // first player can enforce a win
	W2  // second player can enforce a win
}
enum LoseCond {
	unknown,
	L1, // first player can enforce a lose
	L2 // second player can enforce a lose
}

class StringNode {
	public StringNode[char.max] edges = null;
	WinCond win_cond;
	LoseCond lose_cond;
}

void addString(StringNode root, string str) {
	foreach (ch; str) {
		if (root.edges[ch] is null) {
			root.edges[ch] = new StringNode;
		}
		root = root.edges[ch];
	}
}

void calculateWinLoseState(StringNode root) {
	// alias ReturnType = Tuple!(WinCond, LoseCond);
	auto stack = new Stack!StringNode;
	stack.push(root);

	for (size_t i = 0; i != stack.length(); ++i) {
		foreach (edge; stack.get(i).edges) {
			if (edge !is null) {
				stack.push(edge);
			}
		}
	}

	while (!stack.empty()) {
		auto node = stack.pop();
		assert(node.win_cond == WinCond.unknown);
		assert(node.lose_cond == LoseCond.unknown);
		bool no_edges = true;
		foreach (edge; node.edges) {
			if (edge !is null) {
				no_edges = false;
				assert(edge.win_cond != WinCond.unknown);
				assert(edge.lose_cond != LoseCond.unknown);
				if (edge.win_cond == WinCond.W2) {
					node.win_cond = WinCond.W1;
				}
				if (edge.lose_cond == LoseCond.L2) {
					node.lose_cond = LoseCond.L1;
				}
			}
		}
		if (node.win_cond == WinCond.unknown) {
			node.win_cond = WinCond.W2;
		}
		if (no_edges) {
			node.lose_cond = LoseCond.L1;
		} else {
			node.lose_cond = LoseCond.L2;
		}
	}
}

void main() {
	int n, k;
	readf(" %s %s ", &n, &k);
	auto root = new StringNode;
	foreach (_; 0..n) {
		string line;
		readf(" %s ", &line);
		addString(root, line.strip);
	}
	calculateWinLoseState(root);
	enum first = "First";
	enum second = "Second";
	switch (root.win_cond) {
	default:
		assert(false);
	case WinCond.W1:
		switch(root.lose_cond) {
		default:
			assert(false);
		case LoseCond.L1:
			writeln(first);
			break;
		case LoseCond.L2:
			writeln(k % 2 == 0 ? second : first);
		}
		break;
	case WinCond.W2:
		switch(root.lose_cond) {
		default:
			assert(false);
		case LoseCond.L1:
			writeln(k % 2 == 0 ? first : second);
			break;
		case LoseCond.L2:
			writeln(second);
		}
	}
}

import std.stdio;
import std.algorithm;
import std.string;

const int MAX = 100005;
string[MAX] s;
int n, k;

struct Node {
    char c;
    Node*[char] children;
}

void main() {
    readf(" %s %s", n, k);
    readln();
    foreach(i; 0..n) s[i] = readln().chomp();

    auto root = new Node();
    foreach(i; 0..n) {
        auto cur = root;
        foreach(c; s[i]) {
            if (c !in cur.children) {
                auto node = new Node();
                node.c = c;
                cur.children[c] = node;
            }
            cur = cur.children[c];
        }
    }

    auto canWinMatch = root.children.values.any!(node => can(node, true));
    auto canLossMatch = root.children.values.any!(node => can(node, false));
    auto canWin = canWinMatch;
    foreach(i; 0..k-1) {
        canWin = (canLossMatch && canWin) || (canWinMatch && !canWin);
    }
    writeln(canWin ? "First" : "Second");
}

bool can(Node* node, bool win) {
    if (node.children.empty) {
        return win;
    }
    auto result = false;
    foreach(c; node.children.keys) {
        result &= (can(node.children[c], win) == false);
    }
    return result;
}

import std.stdio;
import std.algorithm;
import std.string;

const int MAX = 100005;
string[MAX] s;
int n, k;

struct Node {
    char c;
    Node*[char] children;
}

void main() {
    readf(" %s %s", n, k);
    readln();
    foreach(i; 0..n) s[i] = readln().chomp();

    auto root = new Node();
    foreach(i; 0..n) {
        auto cur = root;
        foreach(c; s[i]) {
            if (c !in cur.children) {
                auto node = new Node();
                node.c = c;
                cur.children[c] = node;
            }
            cur = cur.children[c];
        }
    }

    auto canWinMatch = root.children.values.any!(node => can(node, true));
    auto canLossMatch = root.children.values.any!(node => can(node, false));
    auto canWin = canWinMatch;
    foreach(i; 0..k-1) {
        canWin = (canLossMatch && canWin) || (canWinMatch && !canWin);
    }
    writeln(canWin ? "First" : "Second");
}

bool can(Node* node, bool win) {
    if (node.children.empty) {
        return win;
    }
    auto result = false;
    foreach(c; node.children.keys) {
        result |= (can(node.children[c], win) == false);
    }
    return result;
}

import std.stdio;
import std.algorithm;
import std.string;

const int MAX = 100005;
string[MAX] s;
int n, k;

struct Node {
    char c;
    Node*[char] children;
}

void main() {
    readf(" %s %s", n, k);
    readln();
    foreach(i; 0..n) s[i] = readln().chomp();

    auto root = new Node();
    foreach(i; 0..n) {
        auto cur = root;
        foreach(c; s[i]) {
            if (c !in cur.children) {
                auto node = new Node();
                node.c = c;
                cur.children[c] = node;
            }
            cur = cur.children[c];
        }
    }

    bool firstCanWin = root.children.values.any!(node => canWin(node));
    if (firstCanWin) {
        writeln(k % 2 == 0 ? "SECOND" : "FIRST");
    } else {
        writeln("SECOND");
    }
}

bool canWin(Node* node) {
    if (node.children.empty) {
        return true;
    }
    auto result = false;
    foreach(c; node.children.keys) {
        result |= (canWin(node.children[c]) == false);
    }
    return result;
}

import std.stdio;
import std.algorithm;
import std.string;

const int MAX = 100005;
string[MAX] s;
int n, k;

struct Node {
    char c;
    Node*[char] children;
}

void main() {
    readf(" %s %s", n, k);
    readln();
    foreach(i; 0..n) s[i] = readln().chomp();

    auto root = new Node();
    foreach(i; 0..n) {
        auto cur = root;
        foreach(c; s[i]) {
            if (c !in cur.children) {
                auto node = new Node();
                node.c = c;
                cur.children[c] = node;
            }
            cur = cur.children[c];
        }
    }

    bool firstCanWin = root.children.values.any!(node => canWin(node));
    if (firstCanWin) {
        writeln(k % 2 == 0 ? "Second" : "First");
    } else {
        writeln("Second");
    }
}

bool canWin(Node* node) {
    if (node.children.empty) {
        return true;
    }
    auto result = false;
    foreach(c; node.children.keys) {
        result |= (canWin(node.children[c]) == false);
    }
    return result;
}


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

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);
  auto n = next!int;
  auto a = next!int(n);
  auto df = new byte[](n);
  df[n - 1] = 0;
  int sum = a[n - 1];
  foreach_reverse(i; 0 .. n - 1)
    {
      auto ai = a[i];
      assert(sum >= 0 && sum <= a[i + 1]);
      if (sum >= ai) {df[i] = 1; df[i + 1] ^= 1; sum = sum - ai;}
      else {df[i] = 0; df[i + 1] ^= 1; sum = ai - sum;}
    }
  auto f = new byte[](n);
  f[0] = df[0];
  foreach(i; 1 .. n)
    f[i] = f[i - 1] ^ df[i];
  f.map!(fi => fi == 0? '+' : '-').each!write, writeln;
}

// INPUT

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

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

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

import std.math;
import std.stdio;

int n;

int main ()
{
	while ((readf (" %d", &n) >= 0) && !stdin.eof ())
	{
		auto a = new int [n];
		foreach (i; 0..n)
		{
			readf (" %d", &a[i]);
		}

		auto r = new bool [n];
		r[] = true;
		auto s = a[n - 1];
		for (auto i = n - 2; i >= 0; i--)
		{
			if (s > 0)
			{
				r[i] = false;
				s -= a[i];
			}
			else
			{
				r[i] = true;
				s += a[i];
			}
			assert (abs (s) <= a[i]);
		}

		if (s < 0)
		{
			r[] = r[] ^ 1;
		}

		foreach (i; 0..n)
		{
			writef ("%s", r[i] ? '+' : '-');
		}
		writef ("\n");
	}
	return 0;
}


import std.stdio;
import std.string;

int main()
{
	int a=0;
	readf(" %d", &a);
	if (a%2==0)
	{
		writeln(a/2);
		for (int i=0; i<a/2; i++)
		{
			writeln(2);
		}
	}
	else
	{
		writeln(a/2);
		for (int i=0; i<a/2-1; i++)
		{
			writeln(2);
		}
		writeln(3);
	}
	return 0;
}

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

void main()
{
	int n;
	while(input(&n))
	{
		if(n&1)
		{
			writeln((n-3)/2+1);
			write(3,' ');
			foreach(i;0..(n-3)/2)write(2,' ');
		}
		else
		{
			writeln(n/2);
			foreach(i;0..n/2)write(2,' ');
		}
	}
	debug system("pause");
}


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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		auto a = RDA!int;
		auto b = RDA!int;
		bool[int] set;
		long cnt;
		foreach (i; 0..m)
		{
			if (set.get(b[i], false))
			{
				++cnt;
				set.remove(b[i]);
				continue;
			}
			cnt += set.length*2;
			while (a.front != b[i])
			{
				set[a.front] = true;
				a.popFront;
				cnt += 2;
			}
			a.popFront;
			++cnt;
			debug writeln("cnt:", cnt);
		}
		ans[ti] = cnt;
	}

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

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

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

void solve(){
	foreach(_; 0 .. rint){
		int n = rint, m = rint;
		long[] as = rlong(n).map!(x => x - 1).array;
		long[] bs = rlong(m).map!(x => x - 1).array;
		log("as:", as);
		log("bs:", bs);

		long[long] az;
		foreach(i, a; as) az[a] = i.to!long;
		log("az:", az);

		long[] us = bs.map!(x => az[x]).array;
		log("us:", us);

		long ans;
		long umax = 0;
		foreach(i, u; us){
			if(u < umax) ans += 1;
			else{
				ans += (u - i) *2 + 1;
				umax = u;
			}
			log("i:", i, "u:", u, "umax:", umax, "ans:", ans);
		}
		ans.writeln;
	}
}

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

void solve() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = readln.split.map!(x => x.to!int-1).array;
    auto B = readln.split.map!(x => x.to!int-1).array;
    auto C = new int[](N);
    foreach (i; 0..N) C[A[i]] = i;
    long ans = 0;
    int mx = -1;
    long cnt = 0;

    foreach (b; B) {
        if (C[b] < mx) {
            ans += 1;
        } else {
            mx = C[b];
            ans += (C[b] - cnt) * 2 + 1;
        }
        cnt += 1;
    }

    ans.writeln;
}

void main() {
    auto T = readln.chomp.to!int;
    while (T--) solve;
}

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

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

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

void main() {
  auto r = new InputReader;
  auto nt = r.next!uint;
  foreach (tid; 0 .. nt) {
    immutable n = r.next!uint;
    immutable m = r.next!uint;
    auto a = r.nextA!uint (n);
    auto b = r.nextA!uint (m);
    a[] -= 1;
    b[] -= 1;
    auto rank = new uint[n];
    foreach (i; 0 .. n) {
      rank[a[i]] = i;
    }
    long res = m;
    int e;
    int cur;
    foreach (i; 0 .. m) {
      if (rank[b[i]] > cur) {
        cur = rank[b[i]];
        res += 2 * (rank[b[i]] + e);
      }
      --e;
    }
    writeln (res);
  }
}

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

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

void solve(){
	foreach(_; 0 .. rint){
		int n = rint, m = rint;
		int[] as = rint(n).map!(x => x - 1).array;
		int[] bs = rint(m).map!(x => x - 1).array;
		log("as:", as);
		log("bs:", bs);

		int[] az = new int[](n);
		foreach(int i, a; as) az[a] = i;
		log("az:", az);

		int[] us = bs.map!(x => az[x]).array;
		log("us:", us);

		int ans;
		int umax = 0;
		foreach(int i, u; us){
			if(u < umax) ans += 1;
			else{
				ans += (u - i) *2 + 1;
				umax = u;
			}
			log("i:", i, "u:", u, "umax:", umax, "ans:", ans);
		}
		ans.writeln;
	}
}

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
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 int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		auto a = RDA!int;
		auto b = RDA!int;
		bool[int] set;
		int cnt;
		foreach (i; 0..m)
		{
			if (set.get(b[i], false))
			{
				++cnt;
				set.remove(b[i]);
				continue;
			}
			cnt += set.length*2;
			while (a.front != b[i])
			{
				set[a.front] = true;
				a.popFront;
				cnt += 2;
			}
			a.popFront;
			++cnt;
			debug writeln("cnt:", cnt);
		}
		ans[ti] = cnt;
	}

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


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

enum V = 26;

char chr(int u) {
  return cast(char)('a' + u);
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const S = readToken();
        const N = cast(int)(S.length);
        debug {
          writeln("S = ", S);
          stdout.flush;
        }

        auto freq = new int[V];
        foreach (i; 0 .. N) {
          ++freq[S[i] - 'a'];
        }

        int ansLen;
        auto ans = new char[N];
        ans[] = '?';
        foreach (u; 0 .. V) {
          if (freq[u] == N) {
            ans[] = chr(u);
            goto done;
          }
        }
        foreach (u; 0 .. V) {
          if (freq[u] == 1) {
            ans[ansLen++] = chr(u);
            foreach (v; 0 .. V) {
              if (u != v) {
                foreach (_; 0 .. freq[v]) {
                  ans[ansLen++] = chr(v);
                }
              }
            }
            goto done;
          }
        }
        {
          int u0 = -1;
          foreach (u; 0 .. V) {
            if (freq[u] > 0) {
              u0 = u;
              break;
            }
          }
          assert(~u0);
          if (freq[u0] <= N / 2 + 1) {
            ans[0] = chr(u0);
            int pos = 1;
            foreach (_; 1 .. freq[u0]) {
              ans[pos] = chr(u0);
              pos += 2;
            }
            pos = 0;
            foreach (v; u0 + 1 .. V) {
              foreach (_; 0 .. freq[v]) {
                for (; ans[pos] != '?'; ++pos) {}
                ans[pos] = chr(v);
              }
            }
          } else {
            int u1 = -1;
            foreach (u; u0 + 1 .. V) {
              if (freq[u] > 0) {
                u1 = u;
                break;
              }
            }
            assert(~u1);
            int u2 = -1;
            foreach (u; u1 + 1 .. V) {
              if (freq[u] > 0) {
                u2 = u;
                break;
              }
            }
            if (~u2) {
              ans[ansLen++] = chr(u0);
              ans[ansLen++] = chr(u1);
              foreach (_; 1 .. freq[u0]) ans[ansLen++] = chr(u0);
              ans[ansLen++] = chr(u2);
              foreach (_; 1 .. freq[u1]) ans[ansLen++] = chr(u1);
              foreach (_; 1 .. freq[u2]) ans[ansLen++] = chr(u2);
              foreach (u; u2 + 1 .. V) {
                foreach (_; 0 .. freq[u]) ans[ansLen++] = chr(u);
              }
            } else {
              ans[ansLen++] = chr(u0);
              foreach (_; 0 .. freq[u1]) ans[ansLen++] = chr(u1);
              foreach (_; 1 .. freq[u0]) ans[ansLen++] = chr(u0);
            }
          }
        }
       done:{}
        writeln(ans);

        debug {
          auto A = new int[N];
          foreach (i; 0 .. N) {
            A[i] = S[i] - 'a';
          }
          A.sort;
          int mn = N + 1;
          int[] ams;
          do {
            auto fail = new int[N + 1];
            int j = fail[0] = -1;
            foreach (i; 0 .. N) {
              for (; ~j && A[j] != A[i]; j = fail[j]) {}
              fail[i + 1] = ++j;
            }
            const cost = fail.maxElement;
            // writeln(A, ": ", fail, " ", cost);
            if (chmin(mn, cost)) {
              ams = A.dup;
            }
          } while (A.nextPermutation);
          writeln("mn = ", mn);
          string brt;
          foreach (i; 0 .. N) {
            brt ~= chr(ams[i]);
          }
          writeln("brt = ", brt);
          assert(brt == ans);
        }
      }
    }
  } catch (EOFException e) {
  }
}

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

immutable int letters = 26;

string solve (string s)
{
	int [letters] d;
	foreach (ref c; s)
	{
		d[c - 'a'] += 1;
	}

	foreach (let; 0..letters)
	{
		if (d[let] == 1)
		{
			string res;
			res ~= cast (char) (let + 'a');
			d[let] -= 1;
			foreach (x; 0..letters)
			{
				foreach (y; 0..d[x])
				{
					res ~= cast (char) (x + 'a');
				}
			}
			return res;
		}
	}

	foreach (let; 0..letters)
	{
		if (d[let] > 0)
		{
			string res;
			res ~= cast (char) (let + 'a');
			d[let] -= 1;
			string [2] add;
			foreach (x; 0..letters)
			{
				foreach (y; 0..d[x])
				{
					add[x > let] ~= cast (char) (x + 'a');
				}
			}

			if (add[0].length <= add[1].length + 1)
			{
				while (!add[0].empty || !add[1].empty)
				{
					foreach (v; 0..2)
					{
						if (!add[v].empty)
						{
							res ~= add[v][0];
							add[v].popFront ();
						}
					}
				}
				return res;
			}

			if (add[1].empty || add[1].front == add[1].back)
			{
				res ~= add[1];
				res ~= add[0];
				return res;
			}

			auto second = add[1][0];
			res ~= second;
			add[1].popFront ();
			res ~= add[0];
			foreach (i, ref c; add[1])
			{
				if (c != second)
				{
					res ~= c;
					res ~= add[1][0..i];
					res ~= add[1][i + 1..$];
					return res;
				}
			}

			assert (false);
		}
	}

	assert (false);
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		writeln (solve (s));
	}
}


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

string FMT_F = "%.10f";

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

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

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

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

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

	if (n == 1)
		writeln("9 8");
	else
	{
		writeln(n*3, " ", n*2);
	}

	stdout.flush;
	debug readln;
}

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

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

        int read_int() {
                return read_string.to!int;
        }

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                int a = cin.read_int;
                writeln(a * 9, " ", a * 8);
        }
}

import std.stdio;
bool isSimple(int a)
{
	if (a!=0)
	{
		int c=0;
		for (int i=1; i<a+1; i++)
		{
			if (a%i==0)
			{
				c=c+1;
			}
		}
		if (c>2)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return false;
	}
}
int main()
{
	int a=0;
	readf(" %d", &a);
	int c=0;
	int b=a;
	while (true)
	{
		b=b+1;
		c=c+1;
		if (!(isSimple(b)) && !(isSimple(c)))
		{
			break;
		}
	}
	writeln(b);
	writeln(c);
	return 0;
}

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

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

        int read_int() {
                return read_string.to!int;
        }

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                int a = cin.read_int;
                writeln(a * 8, " ", a * 8);
        }
}

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

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

        int read_int() {
                return read_string.to!int;
        }

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                int a = cin.read_int;
                writeln(a * 3, " ", a * 2);
        }
}

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

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

        int read_int() {
                return read_string.to!int;
        }

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                int a = cin.read_int;
                writeln(a * 3 - a * 2);
        }
}

import std.stdio;
bool isSimple(int a)
{
	int c=0;
	for (int i=1; i<a+1; i++)
	{
		if (a%i==0)
		{
			c=c+1;
		}
	}
	if (c>2)
	{
		return false;
	}
	else
	{
		return true;
	}
}
int main()
{
	int a=0;
	readf(" %d", &a);
	int c=4;
	int b=0;
	while (true)
	{
		b=a+c;
		c=c+2;
		if (!(isSimple(b)))
		{
			break;
		}
	}
	writeln(b);
	writeln(c);
	return 0;
}

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

string FMT_F = "%.10f";

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

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

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

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

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

	if (n == 1)
		writeln("9 8");
	else
	{
		writeln(n*2, " ", n*3);
	}

	stdout.flush;
	debug readln;
}


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 S = readToken();
      const L = cast(int)(S.length);

      auto kss = new int[][26];
      foreach (k; 0 .. L) {
        kss[S[k] - 'a'] ~= k;
      }
      int ans;
      foreach (a; 0 .. 26) {
        int mx;
        foreach (x; 0 .. L) {
          auto cnt = new int[26];
          foreach (k; kss[a]) {
            ++cnt[S[(k + x) % L] - 'a'];
          }
          int num1;
          foreach (b; 0 .. 26) {
            if (cnt[b] == 1) {
              ++num1;
            }
          }
          chmax(mx, num1);
        }
        ans += mx;
      }
      writefln("%.10f", ans / cast(real)(L));
    }
  } catch (EOFException e) {
  }
}

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

immutable int letters = 26;

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		auto n = s.length.to !(int);
		s = s ~ s;
		real invN = 1.0 / n;
		real res = 0.0;
		foreach (c; 'a'..'z' + 1)
		{
			string [] t;
			foreach (i; 0..n)
			{
				if (s[i] == c)
				{
					t ~= s[i..i + n];
				}
			}
			int temp = 0;
			foreach (i; 0..n)
			{
				int [letters] d;
				foreach (r; t)
				{
					d[r[i] - 'a'] += 1;
				}
				int cur = 0;
				foreach (e; 0..letters)
				{
					if (d[e] == 1)
					{
						cur += 1;
					}
				}
				temp = max (temp, cur);
			}
			res += temp * invN;
		}
		writefln ("%.20f", res);
	}
}


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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(long)).array;
		long res = 0;
		long saved = 0;
		foreach_reverse (i; 0..n)
		{
			auto pairs = a[i] / 2;
			saved += pairs;
			if (a[i] % 2 == 1 && saved > 0)
			{
				res += 1;
				saved -= 1;
			}
		}
		res += saved * 2 / 3;
		writeln (res);
	}
}

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

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

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

    int prev = 0;
    long ans = 0;
    foreach (e; arr) {
        auto withprev = min(prev, e / 2);
        e -= withprev * 2;
        prev -= withprev;
        ans += withprev;

        auto triple = e / 3;
        e -= triple * 3;
        ans += triple;

        prev += e;
    }

    ans.writeln;
}

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

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

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

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

int N;
long[] A;

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

      long ans;
      long sum;
      foreach (i; 0 .. N) {
        sum += A[i];
        const tmp = min(sum / 3, A[i] / 2);
        ans += tmp;
        sum -= tmp * 3;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

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

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

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

    int prev = 0;
    long ans = 0;
    foreach (e; arr) {
        auto withprev = min(prev*2, e);
        e -= withprev;
        prev -= withprev / 2;
        ans += withprev / 2;

        auto triple = e / 3;
        e -= triple * 3;
        ans += triple;

        prev += e;
    }

    ans.writeln;
}

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

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

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

    int prev = 0;
    long ans = 0;
    foreach (e; arr) {
        ans += e / 3;
        e = e % 3;
        if (e == 2 && prev > 0) {
            ans += 1;
            e -= 2;
            prev -= 1;
        }

        prev += e;
    }

    ans.writeln;
}


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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Seg = Tuple!(int, "s", int, "t", int, "d", int, "v");
alias Env = Tuple!(int, "v", int, "d", int, "t");

void main() {
    int n, m, k;
    scan(n, m, k);

    auto s = new Seg[](k);

    foreach (i ; 0 .. k) {
        int si, ti, di, vi;

        scan(si, ti, di, vi);
        si--, ti--, di--;
        s[i] = Seg(si, ti, di, vi);
    }

    s.sort();

    auto bh = new BinaryHeap!(Array!Env, "a < b")();
    auto dp = new long[][](n + 1, m + 1);
    fillAll(dp, inf6);
    dp[0][0] = 0;

    foreach (i ; 0 .. n) {
        while (!s.empty && s.front.s <= i) {
            bh.insert(Env(s.front.v, s.front.d, s.front.t));
            s.popFront();
        }
        while (!bh.empty && bh.front.t < i) {
            bh.popFront();
        }

        if (bh.empty) {
            foreach (j ; 0 .. m + 1) {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            }
            continue;
        }

        int v = bh.front.v;
        int d = bh.front.d;

        debug {
            writeln(v, " ", d);
        }

        foreach (j ; 0 .. m + 1) {
            if (dp[i][j] == inf6) continue;
            // いたずらした場合
            if (j < m) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);
            // しなかった場合
            dp[d + 1][j] = min(dp[d + 1][j], dp[i][j] + v);
        }
    }

    debug {
        writefln("%(%s\n%)", dp);
    }

    long ans = inf6;

    foreach (j ; 0 .. m + 1) {
        ans = min(ans, dp[n][j]);
    }

    writeln(ans);
}

struct UnionFind {
    private {
        int _size;
        int[] _parent;
        long[] wa;
        int bcnt;
        bool[] bad;
        int[] hen;
    }

    this(int N, long[] x)
    in {
        assert(N > 0);
    }
    body {
        _size = N;
        _parent = new int[](_size);
        foreach (i ; 0 .. _size) {
            _parent[i] = i;
        }
        wa = new long[](N);
        wa[] = x.dup;
        bad = new bool[](N);
        hen = new int[](N);
    }

    int findRoot(int x)
    in {
        assert(0 <= x && x < _size);
    }
    body {
        if (_parent[x] != x) {
            _parent[x] = findRoot(_parent[x]);
        }

        return _parent[x];
    }

    bool same(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        return findRoot(x) == findRoot(y);
    }

    void merge(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        int u = findRoot(x);
        int v = findRoot(y);

        if (u == v) return;

        _parent[v] = u;
        wa[u] += wa[v];
        wa[v] = 0;

        hen[u] += hen[v] + 1;
        hen[v] = 0;
    }
}

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

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

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

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;

alias Block = Tuple!(int, "s", int, "t", int, "d", long, "w");
immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto K = s[2];
    auto B = new Block[](K);
    foreach (i; 0..K) {
        s = readln.split.map!(to!int);
        B[i] = Block(s[0], s[1], s[2], s[3].to!long);
    }

    B.sort!"a[0] < b[0]";
    auto pq = new BinaryHeap!(Array!Block, "a[3] == b[3] ? a[2] < b[2] : a[3] < b[3]");
    int p = 0;

    auto dp = new long[][](N+2, M+1);
    foreach (i; 0..N+2) dp[i][] = INF;
    dp[1][0] = 0;

    foreach (i; 1..N+1) {
        while (!pq.empty && pq.front.t < i) pq.removeFront;
        while (p < K && B[p].s == i) pq.insert(B[p++]);
        auto next = pq.empty ? Block(-1, -1, -1, -INF) : pq.front;

        foreach (j; 0..M+1) {
            if (next.s == -1) {
                dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            } else {
                dp[next.d+1][j] = min(dp[next.d+1][j], dp[i][j] + next.w);
                if (j < M) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]);
            }
        }
    }

    dp[N+1].reduce!min.writeln;
}

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

alias Envelope = Tuple !(int, q{w}, int, q{d}, int, q{s}, int, q{t}, int, q{i});

void main ()
{
	int n, m, k;
	while (readf (" %s %s %s", &n, &m, &k) > 0)
	{
		n += 1;
		auto a = new Envelope [k];
		auto add = new int [] [n + 1];
		auto rem = new int [] [n + 1];
		foreach (i, ref e; a)
		{
			readf (" %s %s %s %s", &e.s, &e.t, &e.d, &e.w);
			e.i = i;
			add[e.s] ~= i;
			rem[e.t] ~= i;
		}

		auto t = redBlackTree !(Envelope) ();
		auto f = new long [] [] (n + 1, m + 1);
		foreach (ref line; f)
		{
			line[] = long.max / 2;
		}
		f[0][0] = 0;
		foreach (x; 0..n)
		{
			foreach (z; add[x])
			{
				t.insert (a[z]);
			}
			foreach (y; 0..m + 1)
			{
				auto ny = y + !t.empty;
				if (ny <= m)
				{
					f[x + 1][ny] =
					    min (f[x + 1][ny],
					    f[x][y]);
				}
				if (!t.empty)
				{
					f[t.back.d + 1][y] =
					    min (f[t.back.d + 1][y],
					    f[x][y] + t.back.w);
				}
			}
			foreach (z; rem[x])
			{
				t.removeKey (a[z]);
			}
		}
		writeln (f[n].minElement);
	}
}


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

void main() {
    int n, k;
    scan(n, k);

    auto h = readln.split.to!(int[]);

    auto hmin = h.reduce!min;
    auto hmax = h.reduce!max;

    if (hmin == hmax) {
        writeln(0);
        return;
    }

    auto cnt = new int[](hmax + 1);
    foreach (i ; 0 .. n) {
        cnt[h[i]]++;
    }

    foreach_reverse (i ; 0 .. hmax) {
        cnt[i] += cnt[i+1];
    }

    debug {
        stderr.writeln(cnt);
    }

    int ans;
    int store;

    foreach_reverse (i ; 0 .. hmax + 1) {
        if (i == hmin) {
            ans++;
            break;
        }
        if (store + cnt[i] > k) {
            ans++;
            store = cnt[i];
        }
        else {
            store += cnt[i];
        }
    }

    writeln(ans);
}

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

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

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

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, k;
  rd(n, k);
  auto a = readln.split.to!(int[]);

  auto all = reduce!((res, val) => (res && val == a[0]))(true, a);
  if (all) {
    writeln(0);
    return;
  }
  auto freq = new int[](3 * 10 ^^ 5);
  foreach (val; a)
    freq[val]++;
  auto mn = reduce!(min)(a), mx = reduce!(max)(a);
  int num = 0, s = 0;
  for (int h = mx; h > mn; h--) {
    freq[h] += freq[h + 1];
    if ((s += freq[h]) > k) {
      num++;
      s = freq[h];
    }
  }
  writeln(num + (s > 0));
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, k;
  rd(n, k);
  auto a = readln.split.to!(int[]);

  auto all = reduce!((res, val) => (res && val == a[0]))(true, a);
  if (all) {
    writeln(0);
    return;
  }
  auto freq = new int[](3 * 10 ^^ 5);
  foreach (val; a)
    freq[val]++;
  auto mn = reduce!(min)(a), mx = reduce!(max)(a);
  int num = 0;
  for (int h = mx, s = 0; h >= mn; h--) {
    freq[h] += freq[h + 1];
    if ((s += freq[h]) > k) {
      num++;
      s = freq[h];
    }
  }
  writeln(num);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


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

bool check (int i) {
  return 0 == ((i + 1) & i);
}

void main() {
  int x;
  readf (" %d", &x);
  int[] a;
  if (check (x)) {
    writeln (0);
    return;
  }
  foreach (ops; 0 .. 40) {
    debug stderr.writeln (x);
    if (ops & 1) {
      ++x;
    } else {
      int j = -1;
      foreach (i; 0 .. 30) {
        if (x & (1 << i)) {
          j = i;
        }
      }
      a ~= j + 1;
      x ^= (1 << (j + 1)) - 1;
    }
    if (check (x)) {
      writeln (ops + 1);
      writefln ("%(%s %)", a);
      return;
    }
  }
  enforce (false);
}

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

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

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

	ulong x = read.to!ulong;

	int t = 0;
	int[] ns = [];

	int i = 1;
	ulong m = 1;
	while(m <= x) m *= 2, i += 1;
	if(x == m - 1){
		t = 0, ns = [];
		writeln(t), writeln(ns.map!(to!string).join(" "));
		return;
	}
	else{
		while(m > 0){
			m /= 2, i -= 1;
			if(m & x) continue;
			if(m == 0) break;

			t += 1;
			ns ~= i;
			x ^= m * 2 - 1;
			if((x & (m * 2 - 1)) == m * 2 - 1) break;

			t += 1;
			x += 1;
		}
	}
	writeln(t);
	writeln(ns.map!(to!string).join(" "));
}

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

string FMT_F = "%.10f";

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

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

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

void main()
{
	auto x = RD;

	long cnt;
	long[] ans;
	foreach (i; 0..20)
	{
		auto y = 1UL << (19 - i);
		if (x & y) continue;
		x = x ^ ((y << 1) - 1);
		ans ~= 20 - i;
		++cnt;
		if (x == (2^^20)-1) break;
		++x;
		++cnt;
	}

	debug writeln(x);

	writeln(cnt);
	if (cnt != 0)
	{
		write(ans[0]);
		foreach (e; ans[1..$])
			write(" ", e);
		writeln();
	}
	stdout.flush();
	debug readln();
}

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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
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; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

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

void main()
{
	auto x = RD;

	long cnt;
	long[] ans;
	foreach (i; 0..20)
	{
		auto y = 1UL << (19 - i);
		if (x & y) continue;
		x = x ^ ((y << 1) - 1);
		ans ~= 20 - i;
		++cnt;
		if (x == (2^^21)-1) break;
		++x;
		++cnt;
	}

	debug writeln(x);

	writeln(cnt);
	if (cnt != 0)
	{
		write(ans[0]);
		foreach (e; ans[1..$])
			write(" ", e);
		writeln();
	}
	stdout.flush();
	debug readln();
}

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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
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; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

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

void main()
{
	auto x = RD!int;

	long cnt;
	long[] ans;
	foreach (i; 0..20)
	{
		auto y = 1 << (19 - i);
		if (x & y) continue;
		x = x ^ y;
		ans ~= 21 - i;
		++cnt;
		if (x == (2^^20)-1) break;
		++x;
		++cnt;
	}

	debug writeln(x);

	writeln(cnt);
	if (cnt != 0)
	{
		write(ans[0]);
		foreach (e; ans[1..$])
			write(" ", e);
		writeln();
	}
	stdout.flush();
	debug readln();
}

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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
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; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

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

void main()
{
	auto x = RD;

	long cnt;
	long[] ans;
	foreach (i; 0..20)
	{
		auto y = 1UL << (19 - i);
		if (x & y) continue;
		x = x ^ ((y << 1) - 1);
		ans ~= 21 - i;
		++cnt;
		if (x == (2^^20)-1) break;
		++x;
		++cnt;
	}

	debug writeln(x);

	writeln(cnt);
	if (cnt != 0)
	{
		write(ans[0]);
		foreach (e; ans[1..$])
			write(" ", e);
		writeln();
	}
	stdout.flush();
	debug readln();
}

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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
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; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

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

void main()
{
	auto t = RD!int;

	long cnt;
	long[] ans;
	foreach (i; 0..6)
	{
		auto x = 1 << (5 - i);
		if (t & x) continue;
		t = t ^ x;
		ans ~= 7 - i;
		++cnt;
		if (t == 63) break;
		++t;
		++cnt;
	}

	debug writeln(t);

	writeln(cnt);
	if (cnt != 0)
	{
		write(ans[0]);
		foreach (e; ans[1..$])
			write(" ", e);
		writeln();
	}
	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)
	{
		int n, q;
		readf !(" %s %s") (n, q);

		auto divs = [1];
		int m = n;
		for (int d = 2; d * d <= m; d++)
		{
			if (m % d == 0)
			{
				divs ~= n / d;
				do
				{
					m /= d;
				}
				while (m % d == 0);
			}
		}
		if (1 < m && m < n)
		{
			divs ~= n / m;
		}
		auto nDivs = divs.length.to !(int);

/*
		auto a = new int [n];
		foreach (ref x; a)
		{
			readf !(" %s") (x);
		}
*/
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto c = new long [] [nDivs];
		foreach (j, d; divs)
		{
			c[j] = new long [d * 2 + 2];
			foreach (i; 0..n)
			{
				c[j][i % d + d] += a[i] * 1L * d;
			}
			foreach_reverse (k; 1..d)
			{
				c[j][k] = max (c[j][k * 2], c[j][k * 2 + 1]);
			}
		}

		writeln (c.map !(line => line[1]).maxElement);
		foreach (r; 0..q)
		{
			int i, x;
			readf !(" %s %s") (i, x);
			i -= 1;
			auto delta = x - a[i];
			foreach (j, d; divs)
			{
				int k = i % d + d;
				c[j][k] += delta * 1L * d;
				for (k >>= 1; k > 0; k >>= 1)
				{
					c[j][k] = max (c[j][k * 2],
					    c[j][k * 2 + 1]);
				}
			}
			a[i] = x;
			writeln (c.map !(line => line[1]).maxElement);
		}
	}
}

    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)
    	{
    		int n, q;
    		readf !(" %s %s") (n, q);

    		auto divs = [1];
    		int m = n;
    		for (int d = 2; d * d <= m; d++)
    		{
    			if (m % d == 0)
    			{
    				divs ~= n / d;
    				do
    				{
    					m /= d;
    				}
    				while (m % d == 0);
    			}
    		}
    		if (1 < m && m < n)
    		{
    			divs ~= n / m;
    		}
    		auto nDivs = divs.length.to !(int);

    		readln;
    		auto a = readln.splitter.map !(to !(int)).array;
    		auto c = new long [] [nDivs];
    		foreach (j, d; divs)
    		{
    			c[j] = new long [d * 2 + 2];
    			foreach (i; 0..n)
    			{
    				c[j][i % d + d] += a[i] * 1L * d;
    			}
    			foreach_reverse (k; 1..d)
    			{
    				c[j][k] = max (c[j][k * 2], c[j][k * 2 + 1]);
    			}
    		}

    		writeln (c.map !(line => line[1]).maxElement);
    		foreach (r; 0..q)
    		{
    			int i, x;
    			readf !(" %s %s") (i, x);
        		readln;
    			i -= 1;
    			auto delta = x - a[i];
    			foreach (j, d; divs)
    			{
    				int k = i % d + d;
    				c[j][k] += delta * 1L * d;
    				for (k >>= 1; k > 0; k >>= 1)
    				{
    					c[j][k] = max (c[j][k * 2],
    					    c[j][k * 2 + 1]);
    				}
    			}
    			a[i] = x;
    			writeln (c.map !(line => line[1]).maxElement);
    		}
    	}
    }


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

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

void main()
{
	int n;
	read(n);
	long[long] q;
	long sum;
	BigInt ans;
	foreach (i; 0 .. n)
	{
		long x;
		input(x);
		BigInt cur = sum;
		long k;
		foreach (j; -1 .. 2)
		{

			cur -= (x + j) * q.get(x + j, 0);
			k += q.get(x + j, 0);

		}
		ans += x * (i - k) - cur;
		sum += x;
		q[x]++;
	}
	writeln(ans);
}

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

void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);

    int[int] cnt;
    BigInt ans;

    foreach (i ; 0 .. n) {
        int d;
        if (a[i] in cnt) d += cnt[a[i]];
        if (a[i]+1 in cnt) d += cnt[a[i]+1];
        if (a[i]-1 in cnt) d += cnt[a[i]-1];
        ans += 1L * a[i] * (i - d);
        cnt[a[i]]++;
        debug {
            writeln(cnt);
        }
    }

    cnt.clear();

    debug {
        writeln(cnt);
    }

    foreach_reverse (i ; 0 .. n) {
        int d;
        if (a[i] in cnt) d += cnt[a[i]];
        if (a[i]+1 in cnt) d += cnt[a[i]+1];
        if (a[i]-1 in cnt) d += cnt[a[i]-1];
        ans -= 1L * a[i] * (n - 1 - i - d);
        cnt[a[i]]++;
    }

    writeln(ans);
}

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

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


import std;

void main()
{
    int t;
    scanf("%d", &t);
    getchar();
    long n;
    foreach(_; 0..t)
    {
        auto s = readln.strip.toLower();
        if (s == "yes")
            writeln("YES");
        else
            writeln("NO");
    }
}

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 s = readln.strip;
		writeln (s.toLower.equal ("yes") ? "YES" : "NO");
	}
}