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

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

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

	int n = read.to!int;
	int m = read.to!int;
	long ta = read.to!long;
	long tb = read.to!long;
	int k = read.to!int;

	long[] as = readln.chomp.split.map!(to!long).array;
	long[] bs = readln.chomp.split.map!(to!long).array;
	print!1("as:", as);
	print!1("bs:", bs);

	int j;
	long ans = 0;
	foreach(i; 0 .. k + 1){ // cancels (i) planes. = plane of index i goes.
		print!1("i:", i);
		if(i >= n){
			ans = -1;
			break;
		}
		while(bs[j] < as[i] + ta){
			j += 1;
			if(j >= m){
				ans = -1;
				break;
			}
		}
		int j2 = j + (k - i); // possible plane
		print!1("j:", j, " j2: ", j2);
		if(j2 >= m){
			ans = -1;
			break;
		}
		ans = max(ans, bs[j2] + tb);
		print!1("ans: max(ans, ", bs[j2]+ tb, ") = ", 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.string;

immutable long MOD = 10^^9 + 7;
immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1] + 1;
    auto K = s[4];
    auto Ta = s[2];
    auto Tb = s[3];
    auto A = readln.split.map!(to!long).array;
    auto B = readln.split.map!(to!long).array ~ INF;

    if (N <= K || M - 1 <= K) {
        writeln(-1);
        return;
    }

    auto opt = new int[](N);
    long ans = 0;

    for (int i = 0, j = 0; j < M; ++j) {
        while (i < N && A[i] + Ta <= B[j]) opt[i++] = j;
    }

    foreach (i; 0..N) {
        if (i > K) break;
        int j = opt[i] + K - i;
        if (j > M) {
            ans = INF;
            break;
        }
        ans = max(ans, B[j] + Tb);
    }

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

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

void main ()
{
	int n, m, k;
	long ta, tb;
	while (readf !(" %s %s %s %s %s") (n, m, ta, tb, k) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(long)).array;
		auto b = readln.splitter.map !(to !(long)).array;
		sort (a);
		sort (b);
		a ~= b.back + 1;
		n += 1;
		long res = long.min;
		int j = 0;
		foreach (i; 0..n)
		{
			if (i > k)
			{
				break;
			}
			while (j < m && a[i] + ta > b[j])
			{
				j += 1;
			}
			int p = j + (k - i);
			if (p >= m)
			{
				res = long.max;
			}
			else
			{
				res = max (res, b[p] + tb);
			}
		}
		if (res == long.max)
		{
			res = -1;
		}
		writeln (res);
	}
}

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

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;
  immutable n = r.next!int;
  immutable m = r.next!int;
  immutable ta = r.next!long;
  immutable tb = r.next!long;
  immutable k = r.next!int;
  auto a = r.nextA!long(n).map!(t => t + ta).array;
  auto b = r.nextA!long(m);
  auto e = b.assumeSorted;
  long test () {
    if (a.length <= k || b.length <= k) {
      return -1L;
    }
    long res = long.min;
    foreach (i; 0 .. k + 1) {
      int d = k - i;
      auto r = e.upperBound (a[i] - 1);
      if (r.length <= d) {
        return -1;
      }
      res = max (res, r.drop(d).front);
    }
    return res + tb;
  }
  writeln (test ());
}

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

immutable long MOD = 10^^9 + 7;
immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1] + 1;
    auto K = s[4];
    auto Ta = s[2];
    auto Tb = s[3];
    auto A = readln.split.map!(to!long).array;
    auto B = readln.split.map!(to!long).array ~ INF;

    auto opt = new int[](N);
    long ans = 0;

    for (int i = 0, j = 0; j < M; ++j) {
        while (i < N && A[i] + Ta <= B[j]) opt[i++] = j;
    }

    foreach (i; 0..N) {
        if (i > K) break;
        int j = opt[i] + K - i;
        if (j >= M - 1) {
            ans = INF;
            break;
        }
        ans = max(ans, B[j] + Tb);
    }

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

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

void main ()
{
	int n, m, k;
	long ta, tb;
	while (readf !(" %s %s %s %s %s") (n, m, ta, tb, k) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(long)).array;
		auto b = readln.splitter.map !(to !(long)).array;
		long res = long.min;
		int j = 0;
		foreach (i; 0..n)
		{
			if (i > k)
			{
				break;
			}
			while (j < m && a[i] + ta > b[j])
			{
				j += 1;
			}
			int p = j + (k - i);
			if (p >= m)
			{
				res = long.max;
			}
			else
			{
				res = max (res, b[p] + tb);
			}
		}
		if (res == long.max)
		{
			res = -1;
		}
		writeln (res);
	}
}

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

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;
  immutable n = r.next!int;
  immutable m = r.next!int;
  immutable ta = r.next!long;
  immutable tb = r.next!long;
  immutable k = r.next!int;
  auto a = r.nextA!long(n).map!(t => t + ta).array;
  auto b = r.nextA!long(m);
  auto e = b.assumeSorted;
  long test () {
    if (a.length < k || b.length < k) {
      return -1L;
    }
    long res = long.min;
    foreach (i; 0 .. k + 1) {
      int d = k - i;
      long t = a[i];
      auto r = e.upperBound (t - 1);
      if (r.length <= d) {
        return -1;
      }
      res = max (res, r.drop(d).front);
    }
    return res + tb;
  }
  writeln (test ());
}

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

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

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

	int n = read.to!int;
	int m = read.to!int;
	long ta = read.to!long;
	long tb = read.to!long;
	int k = read.to!int;

	long[] as = readln.chomp.split.map!(to!long).array;
	long[] bs = readln.chomp.split.map!(to!long).array;
	print!1("as:", as);
	print!1("bs:", bs);

	int j;
	long ans = 0;
	foreach(i; 0 .. k + 1){ // cancels (i) planes. = plane of index i goes.
		print!1("i:", i);
		while(bs[j] < as[i] + ta){
			j += 1;
			if(j >= m){
				ans = -1;
				break;
			}
		}
		int j2 = j + (k - i); // possible plane
		print!1("j:", j, " j2: ", j2);
		if(j2 >= m){
			ans = -1;
			break;
		}
		ans = max(ans, bs[j2] + tb);
		print!1("ans: max(ans, ", bs[j2]+ tb, ") = ", ans);
	}

	ans.writeln;

}


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

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

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

	int n = read.to!int;

	S[] ps;
	foreach(i; 0 .. n) ps ~= S(i, read.to!int, read.to!int);

	S[] xs, ys;
	foreach(p; ps) if(p.a < p.b) xs ~= p; else ys ~= p;

	if(xs.length > ys.length){
		xs.sort!"a.a>b.a"();
		xs.length.writeln;
		xs.map!(x => (x.id + 1).to!string).array.join(" ").writeln;
	}
	else{
		ys.sort!"a.a<b.a"();
		ys.length.writeln;
		ys.map!(y => (y.id + 1).to!string).array.join(" ").writeln;
	}

}

struct S{
	int id;
	int a, b;
}

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

alias Pair = Tuple !(int, q{a}, int, q{b}, int, q{c});

int [] solve (Pair [] p)
{
	auto q = p.filter !(x => x.a < x.b).array;
	sort (q);
	reverse (q);
	return q.map !(x => x.c).array;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto p = new Pair [n];
		foreach (i, ref x; p)
		{
			readf (" %s %s", &x.a, &x.b);
			x.c = i.to !(int) + 1;
		}
		auto ans = solve (p);
		foreach (ref x; p)
		{
			x = Pair (-x.a, -x.b, x.c);
		}
		auto alt = solve (p);
		if (ans.length < alt.length)
		{
			ans = alt;
		}
		writeln (ans.length);
		writefln ("%(%s %)", ans);
	}
}

//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 std.typecons;

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

//alias T = Tuple!(int, int, int);
alias T = Tuple!(int, int);

void main() {
  auto r = new InputReader;
  immutable n = r.next!int;
  T[] t1, t2;
  foreach (i; 1 .. n + 1) {
    int u = r.next!int;
    int v = r.next!int;
    //auto t = tuple (r.next!int, r.next!int);
    if (u < v) {
      //t1 ~= tuple (u, v, i);
      t1 ~= tuple (v, i);
    } else {
      //t2 ~= tuple (u, v, i);
      t2 ~= tuple (u, i);
    }
  }
  if (t1.length >= t2.length) {
    t1.sort ();
    writeln (t1.length);
    bool f = true;
    foreach_reverse (u; t1) {
      if (f) f = false; else write (' ');
      write (u[1]);
    }
    writeln;
  } else {
    writeln (t2.length);
    t2.sort ();
    bool f = true;
    foreach (u; t2) {
      if (f) f = false; else write (' ');
      write (u[1]);
    }
    writeln;
  }
}

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

alias Pair = Tuple !(int, q{a}, int, q{b}, int, q{c});

int [] solve (Pair [] p)
{
	auto q = p.filter !(x => x.a < x.b).array;
	sort (q);
	reverse (q);
	return q.map !(x => x.c).array;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto p = new Pair [n];
		foreach (i, ref x; p)
		{
			readf (" %s %s", &x.a, &x.b);
			x.c = i.to !(int) + 1;
		}
		auto ans = solve (p);
		foreach (ref x; p)
		{
			x = Pair (-x.a, -x.b, x.c);
		}
		auto alt = solve (p);
		if (ans.length < alt.length)
		{
			ans = alt;
		}
		writeln (alt.length);
		writefln ("%(%s %)", ans);
	}
}


import std.algorithm;
import std.c.stdio;

const int MAX_N = 1003, MAX_L = 1048576;

int [MAX_N] [MAX_N] a;
int [MAX_N] p, q;
char [MAX_L] bufin, bufout;

int main ()
{
	int k, m, n;
	setvbuf (stdin, &bufin[0], _IOFBF, MAX_L);
	setvbuf (stdout, &bufout[0], _IOFBF, MAX_L);
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %c %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					printf ("%d\n", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

void main() {
    int H, W, Q; scanf("%d %d %d\n", &H, &W, &Q);
    auto F = new int[][H];
    foreach (h; 0 .. H) {
        F[h] = readln.chomp.split(" ").map!(to!int).array;
    }

    auto R = iota(0, H, 1).array;
    auto C = iota(0, W, 1).array;
    foreach (q; 0 .. Q) {
        auto ss = readln.chomp.split(" ");
        auto type = ss[0];
        int x = ss[1].to!int, y = ss[2].to!int;
        x--; y--;

        if (type == "r") {
            swap(R[x], R[y]);
        } else if (type == "c") {
            swap(C[x], C[y]);
        } else {
            assert(type == "g");
            writeln(F[ R[x] ][ C[y] ]);
        }
        //writeln(type, [x, y]);
    }
}

import std.algorithm;
import std.c.stdio;

const int MAX_L = 16384;
char [MAX_L] bufin, bufout;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] [] a;
		a = new int [] [n];
		for (int i = 0; i < n; i++)
		{
			a[i] = new int [m];
		}
		int [] p, q;
		p = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		q = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %c %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					printf ("%d\n", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.stdio;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] a;
		a = new int [n * m];
		int [] p, q;
		p = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		q = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i * m + j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %s %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					writefln ("%d", a[p[x] * m + q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.c.stdio;

const int MAX_N = 1003, MAX_L = 65536;

int [MAX_N] [MAX_N] a;
int [MAX_N] p, q;
char [MAX_L] bufin, bufout;

int main ()
{
	int k, m, n;
	setvbuf (stdin, &bufin[0], _IOFBF, MAX_L);
	setvbuf (stdout, &bufout[0], _IOFBF, MAX_L);
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %c %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					printf ("%d\n", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.stdio;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] [] a;
		a = new int [] [n];
		for (int i = 0; i < n; i++)
		{
			a[i] = new int [m];
		}
		int [] p, p2, q, q2;
		p = new int [n];
		p2 = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
			p2[i] = i;
		}
		q = new int [m];
		q2 = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
			q2[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %s %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p2[p[x]], p2[p[y]]);
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q2[q[x]], q2[q[y]]);
					swap (q[x], q[y]);
					break;
				case 'g':
					writefln ("%d", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.stdio;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] a;
		a = new int [n * m];
		int [] p, q;
		p = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		q = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i * m + j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %s %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					writef ("%d\n", a[p[x] * m + q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.c.stdio;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] [] a;
		a = new int [] [n];
		for (int i = 0; i < n; i++)
		{
			a[i] = new int [m];
		}
		int [] p, q;
		p = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		q = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %c %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					printf ("%d\n", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.c.stdio;

const int MAX_N = 1003;

int [MAX_N] [MAX_N] a;
int [MAX_N] p, q;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %c %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					printf ("%d\n", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.c.stdio;

const int MAX_N = 1003;

int [MAX_N] [MAX_N] a;
int [MAX_N] p, q;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %s %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					printf ("%d\n", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.c.stdio;

const int MAX_N = 1003, MAX_L = 16384;

int [MAX_N] [MAX_N] a;
int [MAX_N] p, q;
char [MAX_L] bufin, bufout;

int main ()
{
	int k, m, n;
	setvbuf (stdin, &bufin[0], _IOFBF, MAX_L);
	setvbuf (stdout, &bufout[0], _IOFBF, MAX_L);
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] [] a;
		a = new int [] [n];
		for (int i = 0; i < n; i++)
		{
			a[i] = new int [m];
		}
		int [] p, q;
		p = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		q = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %c %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					printf ("%d\n", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.c.stdio;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] a;
		a = new int [n * m];
		int [] p, q;
		p = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		q = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i * m + j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %s %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					printf ("%d\n", a[p[x] * m + q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.c.stdio;

const int MAX_N = 1003;

int [MAX_N] [MAX_N] a;
int [MAX_N] p, q;

int cur_char;
bool eof = false;

void skip_blanks ()
{
	do
	{
		cur_char = getchar ();
	}
	while (0 <= cur_char && cur_char <= 32);
	if (cur_char == EOF)
	{
		eof = true;
	}
}

char read_char ()
{
	skip_blanks ();
	return cast (char) cur_char;
}

int read_int ()
{
	skip_blanks ();
	int res = 0;
	do
	{
		res = res * 10 + cast (int) (cur_char - '0');
		cur_char = getchar ();
	}
	while (32 < cur_char);
	return res;
}

int main ()
{
	int k, m, n;
	while (true)
	{
	        n = read_int ();
	        m = read_int ();
	        k = read_int ();
	        if (eof)
	        {
	        	break;
	        }
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				a[i][j] = read_int ();
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			ch = read_char ();
			x = read_int ();
			y = read_int ();
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					printf ("%d\n", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.stdio;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] [] a;
		a = new int [] [n];
		for (int i = 0; i < n; i++)
		{
			a[i] = new int [m];
		}
		int [] p, q;
		p = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		q = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %s %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					writefln ("%d", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.c.stdio;

const int MAX_N = 1003;

int [MAX_N] [MAX_N] a;
int [MAX_N] p, q;

int cur_char;
bool eof = false;

void skip_blanks ()
{
	do
	{
		cur_char = getchar ();
	}
	while (0 <= cur_char && cur_char <= 32);
	if (cur_char == EOF)
	{
		eof = true;
	}
}

char read_char ()
{
	skip_blanks ();
	return cast (char) cur_char;
}

int read_int ()
{
	skip_blanks ();
	int res = 0;
	do
	{
		res = res * 10 + cur_char - '0';
		cur_char = getchar ();
	}
	while (32 < cur_char);
	return res;
}

void write_int (int v)
{
        char buf [32];
        int k;
	while (v > 0)
	{
		int w = v / 10;
		int r = v - w * 10;
		buf[k] = cast (char) (r + '0');
		k++;
		v /= 10;
	}
	for (k--; k >= 0; k--)
	{
		putchar (buf[k]);
	}
}

int main ()
{
	int k, m, n;
	while (true)
	{
	        n = read_int ();
	        m = read_int ();
	        k = read_int ();
	        if (eof)
	        {
	        	break;
	        }
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				a[i][j] = read_int ();
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			ch = read_char ();
			x = read_int ();
			y = read_int ();
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					write_int (a[p[x]][q[y]]);
					putchar ('\n');
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.stdio;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] [] a;
		a = new int [] [n];
		for (int i = 0; i < n; i++)
		{
			a[i] = new int [m];
		}
		int [] p, q;
		p = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		q = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %s %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					writefln ("%d", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.stdio;

const int MAX_L = 16384;

int main ()
{
	int k, m, n;
	stdin.setvbuf (MAX_L, _IOFBF);
	stdout.setvbuf (MAX_L, _IOFBF);
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] [] a;
		a = new int [] [n];
		for (int i = 0; i < n; i++)
		{
			a[i] = new int [m];
		}
		int [] p, q;
		p = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		q = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %s %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					printf ("%d\n", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.stdio;

const int MAX_N = 1003;

int [MAX_N] [MAX_N] a;
int [MAX_N] p, q;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %s %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					writef ("%d\n", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.c.stdio;

const int MAX_L = 16384;
char [MAX_L] bufin, bufout;

int main ()
{
	int k, m, n;
	setvbuf (stdin, &bufin[0], _IOFBF, MAX_L);
	setvbuf (stdout, &bufout[0], _IOFBF, MAX_L);
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] [] a;
		a = new int [] [n];
		for (int i = 0; i < n; i++)
		{
			a[i] = new int [m];
		}
		int [] p, q;
		p = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		q = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %c %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					printf ("%d\n", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.c.stdio;

const int MAX_N = 1003, MAX_L = 65536;

int [MAX_N] [MAX_N] a;
int [MAX_N] p, q;
char [MAX_L] buf;

int main ()
{
	int k, m, n;
	setvbuf (stdin, &buf[0], _IOFBF, MAX_L);
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %c %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					printf ("%d\n", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.stdio;

const int MAX_N = 1003;

int [MAX_N * MAX_N] a;
int [MAX_N] p, q;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i * m + j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %s %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					writef ("%d\n", a[p[x] * m + q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.c.stdio;

const int MAX_N = 1003;

int [MAX_N] [MAX_N] a;
int [MAX_N] p, q;

int cur_char;
bool eof = false;

void skip_blanks ()
{
	do
	{
		cur_char = getchar ();
	}
	while (0 <= cur_char && cur_char <= 32);
	if (cur_char == EOF)
	{
		eof = true;
	}
}

char read_char ()
{
	skip_blanks ();
	return cast (char) cur_char;
}

int read_int ()
{
	skip_blanks ();
	int res = 0;
	do
	{
		res = res * 10 + cur_char - '0';
		cur_char = getchar ();
	}
	while (32 < cur_char);
	return res;
}

void write_int (int v)
{
        char buf [32];
        int k;
	while (v > 0)
	{
		buf[k] = cast (char) (v % 10 + '0');
		k++;
		v /= 10;
	}
	for (k--; k >= 0; k--)
	{
		putchar (buf[k]);
	}
}

int main ()
{
	int k, m, n;
	while (true)
	{
	        n = read_int ();
	        m = read_int ();
	        k = read_int ();
	        if (eof)
	        {
	        	break;
	        }
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				a[i][j] = read_int ();
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			ch = read_char ();
			x = read_int ();
			y = read_int ();
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					write_int (a[p[x]][q[y]]);
					putchar ('\n');
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

import std.algorithm;
import std.stdio;

const int MAX_L = 16384;

int main ()
{
	int k, m, n;
	stdin.setvbuf (MAX_L, _IOFBF);
	stdout.setvbuf (MAX_L, _IOFBF);
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] [] a;
		a = new int [] [n];
		for (int i = 0; i < n; i++)
		{
			a[i] = new int [m];
		}
		int [] p, q;
		p = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		q = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
		}
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %s %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q[x], q[y]);
					break;
				case 'g':
					writefln ("%d", a[p[x]][q[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

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

void main() {

    InputReader ir = new InputReader();
    int n = ir.nextInt();
    int m = ir.nextInt();
    int k = ir.nextInt();
    int[][] table = new int[][](n, m);
    foreach (int i; 0 .. n)
        foreach (int j; 0 .. m)
            table[i][j] = ir.nextInt();
    char[] s = new char[k];
    int[] x = new int[k];
    int[] y = new int[k];
    foreach (int i; 0 .. k) {
        s[i] = ir.next()[0];
        //if (i>3)write(s[i], " ");
        x[i] = ir.nextInt() - 1;
        //if (i>3)write(x[i] + 1, " ");
        y[i] = ir.nextInt() - 1;
        //if (i>3)write(y[i] + 1, " ");
        //if (i>3)writeln();
    }
    int[int] ii;
    int[int] jj;
    foreach (int i; 0 .. n)
        ii[i] = i;
    foreach (int j; 0 .. m)
        jj[j] = j;
    foreach (int i; 0 .. k) {
        if (s[i] == 'g') {
            std.c.stdio.printf("%d\n", table[ii[x[i]]][jj[y[i]]]);
        }
        else if (s[i] == 'c')
            swap(jj[y[i]], jj[x[i]]);
        else
            swap(ii[y[i]], ii[x[i]]);
    }
}

class InputReader {

    char INP;
    int AM;

    this() {
    }

    void GETCHAR() {
        INP = to!char(std.c.stdio.getchar());
    }

    bool DIG(char a) {
        return (a >= '0') && (a <= '9');
    }

    bool LETTER(char a) {
        return DIG(a) || ((a >= 'a') && (a <= 'z')) || ((a >= 'A') && (a <= 'Z'));
    }

    int nextInt() {
        int x = 0, c;
        for (; cast(uint)((c = getchar()) - '0') >= 10; ) {
            if (c == '-') return -nextInt();
            if (!~c) {}
        }
        do {
            x = (x << 3) + (x << 1) + (c - '0');
        } while (cast(uint)((c = getchar()) - '0') < 10);
        return x;
    }

    char[] next() {
        GETCHAR();
        while (INP - 0 == 255)
            GETCHAR();
        char[] ans = [INP];
        GETCHAR();
        while (LETTER(INP)) {
            ans ~= INP;
            GETCHAR();
        }
        return ans;
    }
}

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

int main() {
    InputReader ir = new InputReader();
    OutBuffer ob = new OutBuffer();
    int n = ir.nextInt();
    int m = ir.nextInt();
    int k = ir.nextInt();
    int[][] table = new int[][](n, m);

    foreach (int i; 0 .. n)
        foreach (int j; 0 .. m)
            table[i][j] = ir.nextInt();
    char[] s = new char[k];
    int[] x = new int[k];
    int[] y = new int[k];
    foreach (int i; 0 .. k) {
        s[i] = ir.next()[0];
        x[i] = ir.nextInt() - 1;
        y[i] = ir.nextInt() - 1;
    }
    int[int] ii;
    int[int] jj;
    foreach (int i; 0 .. n)
        ii[i] = i;
    foreach (int j; 0 .. m)
        jj[j] = j;
    foreach (int i; 0 .. k) {
        if (s[i] == 'g') {
            ob.write(to!string(table[ii[x[i]]][jj[y[i]]])~"\n");
        }
        else if (s[i] == 'c')
            swap(jj[y[i]], jj[x[i]]);
        else
            swap(ii[y[i]], ii[x[i]]);
    }
    write(ob);
    return 0;
}

class InputReader {

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

    private std.stdio.File input;
    private bool lastOne;
    private uint bufSize;
    private char[] buf;
    private uint remainStart;
    private uint idx = 0;
    private char d;

    public this(std.stdio.File input = stdin, uint bufSize = 100000000, char separator = ' ') {
        this.input = input;
        this.bufSize = bufSize;
        this.d = separator;
        this.lastOne = false;
        this.buf = new char[bufSize];
        this.input.rawRead(this.buf);
        this.idx = 0;
        this.buf = reduce(this.buf);
        this.remainStart = lastIndexOf(this.buf, '\n');
    }

    private int first255(char[] ar) {
        int ans = -1;
        char term = to!char(255);
        for (int j = 0; j < ar.length; ++j)
            if (ar[j] == term)
                return j;
        return ans;
    }

    private char[] reduce(char[] ar) {
        auto termIndex = first255(ar);
        if (termIndex == 0) {
            this.lastOne = true;
            return null;
        }
        else if (termIndex == -1)
            return ar;
        else {
            this.lastOne = true;
            return ar[0 .. termIndex];
        }
    }

    private void refillBuf() {
        char[] newBuf = new char[bufSize];
        input.rawRead(newBuf);
        if (remainStart == -1 || remainStart == bufSize - 1)
            buf ~= reduce(newBuf);
        else
            buf = buf[(remainStart + 1) .. buf.length] ~ reduce(newBuf);
        remainStart = lastIndexOf(buf, "\n");
        idx = 0;
    }

    public char[] next() {
        if ((idx >= remainStart) & !lastOne)
            refillBuf();
        while (idx < buf.length && (buf[idx] == d || buf[idx] == '\n'))
            ++idx;
        if ((idx >= remainStart) & !lastOne)
            refillBuf();
        uint cnt = idx;
        while (cnt < buf.length && buf[cnt] != d && buf[cnt] != '\n')
            ++cnt;
        char[] ans = buf[idx .. cnt];
        idx = cnt;
        return ans;
    }

    public int nextInt() {
        return std.conv.to!int(strip(next()));
    }

    public long nextLong() {
        return std.conv.to!long(strip(next()));
    }

    public double nextDouble() {
        return std.conv.to!double(strip(next()));
    }

}

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

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char rc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    return to!int(ns());
}

long nl ()
{
    return to!long(ns());
}

double nd()
{
    return to!double(ns());
}

char[] nlongs ()
{
    sb ();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar ();
    }
    while (32 < curc);
    return res.data;
}

char[] ns ()
{
    sb ();
    char[] res = [];
    do
    {
        res ~= to!char(curc);
        curc = getchar ();
    }
    while (32 < curc);
    return res;
}

char nc()
{
    curc = getchar();
    return to!char(curc);
}

void main() {
    int n = ni(), m = ni(), k = ni();
    int[][] table = new int[][](n, m);
    foreach (int i; 0 .. n)
        foreach (int j; 0 .. m)
            table[i][j] = ni();
    char[] s = new char[k];
    int[] x = new int[k];
    int[] y = new int[k];
    foreach (int i; 0 .. k) {
        s[i] = nc();
        x[i] = ni() - 1;
        y[i] = ni() - 1;
    }
    int[int] ii;
    int[int] jj;
    foreach (int i; 0 .. n)
        ii[i] = i;
    foreach (int j; 0 .. m)
        jj[j] = j;
    foreach (int i; 0 .. k) {
        if (s[i] == 'g') {
            printf("%d\n", table[ii[x[i]]][jj[y[i]]]);
        }
        else if (s[i] == 'c')
            swap(jj[y[i]], jj[x[i]]);
        else
            swap(ii[y[i]], ii[x[i]]);
    }
}

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

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char nc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    sb ();
    int res = 0;
    int base = 10;
    bool pos = true;
    if (cast (char) curc == '-')
    {
        pos = false;
        curc = getchar();
    }
    if (pos)
    {
        do
        {
            res = res * base + cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }
    else
    {
        do
        {
            res = res * base - cast (int) (curc - '0');
            curc = getchar ();
        }
        while (32 < curc);
    }

    return res;
}

void main() {
    int n = ni(), m = ni(), k = ni();
    int[][] table = new int[][](n, m);
    foreach (int i; 0 .. n)
        foreach (int j; 0 .. m)
            table[i][j] = ni();
    char[] s = new char[k];
    int[] x = new int[k];
    int[] y = new int[k];
    foreach (int i; 0 .. k) {
        s[i] = nc();
        x[i] = ni() - 1;
        y[i] = ni() - 1;
    }
    int[int] ii;
    int[int] jj;
    foreach (int i; 0 .. n)
        ii[i] = i;
    foreach (int j; 0 .. m)
        jj[j] = j;
    foreach (int i; 0 .. k) {
        if (s[i] == 'g') {
            printf("%d\n", table[ii[x[i]]][jj[y[i]]]);
        }
        else if (s[i] == 'c')
            swap(jj[y[i]], jj[x[i]]);
        else
            swap(ii[y[i]], ii[x[i]]);
    }
}

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

int curc;
bool eof = false;

void sb()
{
    do
    {
        curc = getchar ();
    }
    while (0 <= curc && curc <= 32);
    if (curc == EOF)
    {
        eof = true;
    }
}

char rc ()
{
    sb ();
    return cast (char) curc;
}

int ni ()
{
    return to!int(ns());
}

long nl ()
{
    return to!long(ns());
}

double nd()
{
    return to!double(ns());
}

char[] ns ()
{
    sb ();
    auto res = appender!(char[])();
    do
    {
        res.put(to!char(curc));
        curc = getchar ();
    }
    while (32 < curc);
    return res.data;
}

char nc()
{
    curc = getchar();
    return to!char(curc);
}

void main() {
    int n = ni(), m = ni(), k = ni();
    int[][] table = new int[][](n, m);
    foreach (int i; 0 .. n)
        foreach (int j; 0 .. m)
            table[i][j] = ni();
    char[] s = new char[k];
    int[] x = new int[k];
    int[] y = new int[k];
    foreach (int i; 0 .. k) {
        s[i] = nc();
        x[i] = ni() - 1;
        y[i] = ni() - 1;
    }
    int[int] ii;
    int[int] jj;
    foreach (int i; 0 .. n)
        ii[i] = i;
    foreach (int j; 0 .. m)
        jj[j] = j;
    foreach (int i; 0 .. k) {
        if (s[i] == 'g') {
            printf("%d\n", table[ii[x[i]]][jj[y[i]]]);
        }
        else if (s[i] == 'c')
            swap(jj[y[i]], jj[x[i]]);
        else
            swap(ii[y[i]], ii[x[i]]);
    }
}

import std.algorithm;
import std.stdio;

int main ()
{
	int k, m, n;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		int [] [] a;
		a = new int [] [n];
		for (int i = 0; i < n; i++)
		{
			a[i] = new int [m];
		}
		int [] p, p2, q, q2;
		p = new int [n];
		p2 = new int [n];
		for (int i = 0; i < n; i++)
		{
			p[i] = i;
			p2[i] = i;
		}
		q = new int [m];
		q2 = new int [m];
		for (int j = 0; j < m; j++)
		{
			q[j] = j;
			q2[j] = j;
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < m; j++)
			{
				scanf (" %d", &a[i][j]);
			}
		}
		for (int l = 0; l < k; l++)
		{
			int x, y;
			char ch;
			scanf (" %s %d %d", &ch, &x, &y);
			x--;
			y--;
			switch (ch)
			{
				case 'r':
					swap (p2[p[x]], p2[p[y]]);
					swap (p[x], p[y]);
					break;
				case 'c':
					swap (q2[q[x]], q2[q[y]]);
					swap (q[x], q[y]);
					break;
				case 'g':
					writefln ("%d", a[p2[x]][q2[y]]);
					break;
				default:
					assert (false);
			}
		}
	}
	return 0;
}

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

int main() {
    InputReader ir = new InputReader();
    OutBuffer ob = new OutBuffer();
    int n = ir.nextInt();
    int m = ir.nextInt();
    int k = ir.nextInt();
    int[][] table = new int[][](n, m);

    foreach (int i; 0 .. n)
        foreach (int j; 0 .. m)
            table[i][j] = ir.nextInt();
    char[] s = new char[k];
    int[] x = new int[k];
    int[] y = new int[k];
    foreach (int i; 0 .. k) {
        s[i] = ir.next()[0];
        x[i] = ir.nextInt() - 1;
        y[i] = ir.nextInt() - 1;
    }
    int[int] ii;
    int[int] jj;
    foreach (int i; 0 .. n)
        ii[i] = i;
    foreach (int j; 0 .. m)
        jj[j] = j;
    foreach (int i; 0 .. k) {
        if (s[i] == 'g') {
            ob.write(to!string(table[ii[x[i]]][jj[y[i]]])~"\n");
        }
        else if (s[i] == 'c')
            swap(jj[y[i]], jj[x[i]]);
        else
            swap(ii[y[i]], ii[x[i]]);
    }
    write(ob);
    return 0;
}

class InputReader {

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

    private std.stdio.File input;
    private bool lastOne;
    private uint bufSize;
    private char[] buf;
    private uint remainStart;
    private uint idx = 0;
    private char d;

    public this(std.stdio.File input = stdin, uint bufSize = 1000000, char separator = ' ') {
        this.input = input;
        this.bufSize = bufSize;
        this.d = separator;
        this.lastOne = false;
        this.buf = new char[bufSize];
        this.input.rawRead(this.buf);
        this.idx = 0;
        this.buf = reduce(this.buf);
        this.remainStart = lastIndexOf(this.buf, '\n');
    }

    private int first255(char[] ar) {
        int ans = -1;
        char term = to!char(255);
        for (int j = 0; j < ar.length; ++j)
            if (ar[j] == term)
                return j;
        return ans;
    }

    private char[] reduce(char[] ar) {
        auto termIndex = first255(ar);
        if (termIndex == 0) {
            this.lastOne = true;
            return null;
        }
        else if (termIndex == -1)
            return ar;
        else {
            this.lastOne = true;
            return ar[0 .. termIndex];
        }
    }

    private void refillBuf() {
        char[] newBuf = new char[bufSize];
        input.rawRead(newBuf);
        if (remainStart == -1 || remainStart == bufSize - 1)
            buf ~= reduce(newBuf);
        else
            buf = buf[(remainStart + 1) .. buf.length] ~ reduce(newBuf);
        remainStart = lastIndexOf(buf, "\n");
        idx = 0;
    }

    public char[] next() {
        if ((idx >= remainStart) & !lastOne)
            refillBuf();
        while (idx < buf.length && (buf[idx] == d || buf[idx] == '\n'))
            ++idx;
        if ((idx >= remainStart) & !lastOne)
            refillBuf();
        uint cnt = idx;
        while (cnt < buf.length && buf[cnt] != d && buf[cnt] != '\n')
            ++cnt;
        char[] ans = buf[idx .. cnt];
        idx = cnt;
        return ans;
    }

    public int nextInt() {
        return std.conv.to!int(strip(next()));
    }

    public long nextLong() {
        return std.conv.to!long(strip(next()));
    }

    public double nextDouble() {
        return std.conv.to!double(strip(next()));
    }

}

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

int main() {
    InputReader ir = new InputReader();
    OutputWriter ow = new OutputWriter();
    int n = ir.nextInt();
    int m = ir.nextInt();
    int k = ir.nextInt();
    int[][] table = new int[][](n, m);

    foreach (int i; 0 .. n)
        foreach (int j; 0 .. m)
            table[i][j] = ir.nextInt();
    ow.println(table);
    char[] s = new char[k];
    int[] x = new int[k];
    int[] y = new int[k];
    foreach (int i; 0 .. k) {
        s[i] = ir.next()[0];
        x[i] = ir.nextInt() - 1;
        y[i] = ir.nextInt() - 1;
    }
    int[int] ii;
    int[int] jj;
    foreach (int i; 0 .. n)
        ii[i] = i;
    foreach (int j; 0 .. m)
        jj[j] = j;
    foreach (int i; 0 .. k) {
        if (s[i] == 'g') ow.println(table[ii[x[i]]][jj[y[i]]]);
        else if (s[i] == 'c')
            swap(jj[y[i]], jj[x[i]]);
        else
            swap(ii[y[i]], ii[x[i]]);
    }
    return 0;
}

class StringTokenizer {

    private string rawData;
    private string[] tokens;
    private int counter;

    this(string rawData, string delimeter = " ") {
        this.rawData = rawData;
        this.tokens = split(rawData, delimeter);
    }

    bool hasMoreTokens() {
        return this.counter < tokens.length;
    }

    string getRawData() {
        return this.rawData;
    }

    string next() {
        ++counter;
        return tokens[counter - 1];
    }
}

class InputReader {
    private File input;
    private StringTokenizer st;

    this(string filename = null) {
        if (filename !is null)
            this.input = File(filename, "r");
        else
            this.input = stdin;
    }

    string next() {
        while ((st is null) || (!st.hasMoreTokens())) {
            string newLine;
            input.readln(newLine);
            if (newLine)
                st = new StringTokenizer(strip(newLine));
            else
                return null;
        }
        return st.next();
    }

    int nextInt() {
        return std.conv.to!int(next());
    }

    long nextLong() {
        return std.conv.to!long(next());
    }

    double nextDouble() {
        return std.conv.to!double(next());
    }
}

class OutputWriter {
    private File output;

    this(string filename = null) {
        if (filename !is null)
            this.output = File(filename, "w");
        else
            this.output = stdout;
    }

    void print(T...)(T args) { //bydlocode, Ky! razrabam -_-
        bool notfirst = false;
        foreach (el; args) {
            if (notfirst) output.write(" ");
            output.write(el);
            notfirst = true;
        }
    }

    void println(T...)(T args) { //bydlocode, Ky! razrabam -_-
        foreach (el; args)
            output.writeln(el);
    }
}

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

int main() {
    InputReader ir = new InputReader();
    OutBuffer ob = new OutBuffer();
    int n = ir.nextInt();
    int m = ir.nextInt();
    int k = ir.nextInt();
    int[][] table = new int[][](n, m);

    foreach (int i; 0 .. n)
        foreach (int j; 0 .. m)
            table[i][j] = ir.nextInt();
    char[] s = new char[k];
    int[] x = new int[k];
    int[] y = new int[k];
    foreach (int i; 0 .. k) {
        s[i] = ir.next()[0];
        x[i] = ir.nextInt() - 1;
        y[i] = ir.nextInt() - 1;
    }
    int[int] ii;
    int[int] jj;
    foreach (int i; 0 .. n)
        ii[i] = i;
    foreach (int j; 0 .. m)
        jj[j] = j;
    foreach (int i; 0 .. k) {
        if (s[i] == 'g') {
            ob.write(to!string(table[ii[x[i]]][jj[y[i]]])~"\n");
        }
        else if (s[i] == 'c')
            swap(jj[y[i]], jj[x[i]]);
        else
            swap(ii[y[i]], ii[x[i]]);
    }
    write(ob);
    return 0;
}

class InputReader {

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

    private std.stdio.File input;
    private bool lastOne;
    private uint bufSize;
    private char[] buf;
    private uint remainStart;
    private uint idx = 0;
    private char d;

    public this(std.stdio.File input = stdin, uint bufSize = 110000, char separator = ' ') {
        this.input = input;
        this.bufSize = bufSize;
        this.d = separator;
        this.lastOne = false;
        this.buf = new char[bufSize];
        this.input.rawRead(this.buf);
        this.idx = 0;
        this.buf = reduce(this.buf);
        this.remainStart = lastIndexOf(this.buf, '\n');
    }

    private int first255(char[] ar) {
        int ans = -1;
        char term = to!char(255);
        for (int j = 0; j < ar.length; ++j)
            if (ar[j] == term)
                return j;
        return ans;
    }

    private char[] reduce(char[] ar) {
        auto termIndex = first255(ar);
        if (termIndex == 0) {
            this.lastOne = true;
            return null;
        }
        else if (termIndex == -1)
            return ar;
        else {
            this.lastOne = true;
            return ar[0 .. termIndex];
        }
    }

    private void refillBuf() {
        char[] newBuf = new char[bufSize];
        input.rawRead(newBuf);
        if (remainStart == -1 || remainStart == bufSize - 1)
            buf ~= reduce(newBuf);
        else
            buf = buf[(remainStart + 1) .. buf.length] ~ reduce(newBuf);
        remainStart = lastIndexOf(buf, "\n");
        idx = 0;
    }

    public char[] next() {
        if ((idx >= remainStart) & !lastOne)
            refillBuf();
        while (idx < buf.length && (buf[idx] == d || buf[idx] == '\n'))
            ++idx;
        if ((idx >= remainStart) & !lastOne)
            refillBuf();
        uint cnt = idx;
        while (cnt < buf.length && buf[cnt] != d && buf[cnt] != '\n')
            ++cnt;
        char[] ans = buf[idx .. cnt];
        idx = cnt;
        return ans;
    }

    public int nextInt() {
        return std.conv.to!int(strip(next()));
    }

    public long nextLong() {
        return std.conv.to!long(strip(next()));
    }

    public double nextDouble() {
        return std.conv.to!double(strip(next()));
    }

}


//64-bit Integers required
module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

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

void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                string s = cin.readString;
                auto loc = s.indexOf('^');
                long l = 0, r = 0;
                for (int i = 0; i < s.length; i++) {
                        if (s[i] >= '1' && s[i] <= '9') {
                                if (i < loc) l += (s[i] - '0') * (loc - i);
                                else r += (s[i] - '0') * (i - loc);
                        }
                }
                if (l == r) writeln("balance");
                else if (l > r) writeln("left");
                else writeln("right");
        }
}

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

void main() {
  auto lever = readln().chomp();
  auto pivot_pos = lever.indexOf("^");

  ulong left_torque;
  for (auto pos_i = pivot_pos-1; pos_i >= 0; pos_i--) {
    if (lever[pos_i] != '=') {
      auto weight = to!int(lever[pos_i]) - to!int('0');
      left_torque += (pivot_pos - pos_i) * weight;
    }
  }
  ulong right_torque;
  for (auto pos_i = pivot_pos+1; pos_i < lever.length; pos_i++) {
    if (lever[pos_i] != '=') {
      const weight = to!int(lever[pos_i]) - to!int('0');
      right_torque += (pos_i - pivot_pos) * weight;
    }
  }
  if (left_torque > right_torque) {
    writeln("left");
  } else if (left_torque < right_torque) {
    writeln("right");
  } else {
    writeln("balance");
  }
}

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

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

void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                string s = cin.readString;
                auto loc = s.indexOf('^');
                int l = 0, r = 0;
                for (int i = 0; i < s.length; i++) {
                        if (s[i] >= '1' && s[i] <= '9') {
                                if (i < loc) l += (s[i] - '0') * (loc - i);
                                else r += (s[i] - '0') * (i - loc);
                        }
                }
                if (l == r) writeln("balance");
                else if (l > r) writeln("left");
                else writeln("right");
        }
}

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

void main() {
  auto lever = readln().chomp();
  auto pivot_pos = lever.indexOf("^");

  int left_torque;
  for (auto pos_i = pivot_pos-1; pos_i >= 0; pos_i--) {
    if (lever[pos_i] != '=') {
      auto weight = to!int(lever[pos_i]) - to!int('0');
      left_torque += (pivot_pos - pos_i) * weight;
    }
  }
  int right_torque;
  for (auto pos_i = pivot_pos+1; pos_i < lever.length; pos_i++) {
    if (lever[pos_i] != '=') {
      const weight = to!int(lever[pos_i]) - to!int('0');
      right_torque += (pos_i - pivot_pos) * weight;
    }
  }
  if (left_torque > right_torque) {
    writeln("left");
  } else if (left_torque < right_torque) {
    writeln("right");
  } else {
    writeln("balance");
  }
}


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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!long;
    if (n % 2 == 1) {
      writeln((n + 1) / 2);
    } else {
      writeln(n / 2);
    }
  }
}

import std.stdio;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;
import std.functional;

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }

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 solve() {
    long n = read!long;
    writeln(cast(int)ceil(n / 2.));
}

void main() {
    int T = read!int;
    foreach (t; 0 .. T) solve();
}


import std.algorithm;
import std.stdio;

void main ()
{
	readln;
	int n, m;
	while (readf !(" %s %s") (n, m) > 0)
	{
		writeln ((min (n, m) == 1 || max (n, m) <= 2) ? "YES" : "NO");
	}
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto nm = readln.split.to!(int[]);
        auto N = nm[0];
        auto M = nm[1];
        if (N > M) swap(N, M);
        writeln(N == 1 || (N == 2 && M == 2) ? "YES" : "NO");
    }
}

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 m = RD!int;
		if (n == 1 || m == 1)
			ans[ti] = true;
		else if (n == 2 && m == 2)
			ans[ti] = true;
	}

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


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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto t = new int [n];
		t[] = -1;

		int q;
		readf (" %s", &q);
		auto m = new int [q + 1];

		foreach (curTime; 0..q)
		{
			int type;
			readf !(" %s") (type);
			if (type == 1)
			{
				int p, x;
				readf !(" %s %s") (p, x);
				p -= 1;
				a[p] = x;
				t[p] = curTime;
			}
			else
			{
				int x;
				readf !(" %s") (x);
				m[curTime] = x;
			}
		}

		foreach_reverse (curTime; 0..q)
		{
			m[curTime] = max (m[curTime], m[curTime + 1]);
		}

		foreach (i; 0..n)
		{
			a[i] = max (a[i], m[t[i] + 1]);
		}

		writefln !("%(%s %)") (a);
	}
}

/+ dub.sdl:
    name "B"
    dependency "dunkelheit" version="1.0.1"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner, dkh.datastructure.segtree;

int main() {
    Scanner sc = new Scanner(stdin);
    scope(exit) assert(!sc.hasNext);

    int n;
    sc.read(n);
    int[] a;
    sc.read(a);

    auto seg = LazySeg!(int, int,
        "a+b",
        (a, b) => max(a, b),
        (a, b) => max(a, b),
        -1,
        -1)(a);

    int q;
    sc.read(q);

    foreach (i; 0..q) {
        int ty;
        sc.read(ty);
        if (ty == 1) {
            int p, x;
            sc.read(p, x); p--;
            seg[p] = x;
        } else {
            int x;
            sc.read(x);
            seg[0..n] += x;
        }
    }

    iota(n).map!(i => seg[i]).map!(to!string).join(" ").writeln;
    return 0;
}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/datastructure/segtree.d */
// module dkh.datastructure.segtree;

import std.conv : to;
import std.functional : binaryFun;
import std.traits : isInstanceOf;

struct SegTree(alias E, Args...) {
    import std.traits : ReturnType;
    alias Engine = E!Args;
    alias T = Engine.DataType;
    alias L = Engine.LazyType;

    Engine eng;

    this(size_t n) { eng = Engine(n.to!uint); }
    this(T[] first) { eng = Engine(first); }

    @property size_t length() const { return eng.length(); }
    @property size_t opDollar() const { return eng.length(); }

    struct Range {
        Engine* eng;
        size_t start, end;
        @property const(T) sum() {
            return eng.sum(start.to!uint, end.to!uint);
        }
    }
    const(T) opIndex(size_t k) {
        assert(0 <= k && k < eng.length());
        return eng.single(k.to!uint);
    }
    void opIndexAssign(T x, size_t k) {
        assert(0 <= k && k < eng.length());
        eng.singleSet(k.to!uint, x);
    }
    size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) {
        assert(0 <= start && start <= end && end <= eng.length());
        return [start, end];
    }
    Range opIndex(size_t[2] rng) {
        return Range(&eng, rng[0].to!uint, rng[1].to!uint);
    }
    static if (!is(L == void)) {
        void opIndexOpAssign(string op : "+")(L x, size_t[2] rng) {
            eng.add(rng[0].to!uint, rng[1].to!uint, x);
        }
    }
}

ptrdiff_t binSearchLeft(alias pred, TR)(TR t, ptrdiff_t a, ptrdiff_t b)
if (isInstanceOf!(SegTree, TR)) {
    return TR.Engine.BinSearch!(false, pred)(t.eng, a.to!int, b.to!int);
}

ptrdiff_t binSearchRight(alias pred, TR)(TR t, ptrdiff_t a, ptrdiff_t b)
if (isInstanceOf!(SegTree, TR)) {
    return TR.Engine.BinSearch!(true, pred)(t.eng, a.to!int, b.to!int);
}

alias SimpleSeg(T, alias opTT, T eT, alias Engine = SimpleSegEngine) =
    SegTree!(Engine, T, binaryFun!opTT, eT);

struct SimpleSegEngine(T, alias opTT, T eT) {
    alias DataType = T;
    alias LazyType = void;
    alias BinSearch = binSearchSimple;
    uint n, sz, lg;
    T[] d;
    @property uint length() const {return n;}
    this(uint n) {
        import std.algorithm : each;
        this.n = n;
        if (n == 0) return;
        while ((2^^lg) < n) lg++;
        sz = 2^^lg;
        d = new T[](2*sz);
        d.each!((ref x) => x = eT);
    }
    this(T[] first) {
        import std.conv : to;
        import std.algorithm : each;
        n = first.length.to!uint;
        if (n == 0) return;
        while ((2^^lg) < n) lg++;
        sz = 2^^lg;
        d = new T[](2*sz);
        d.each!((ref x) => x = eT);
        foreach (i; 0..n) {
            d[sz+i] = first[i];
        }
        foreach_reverse (i; 1..sz) {
            update(i);
        }
    }
    pragma(inline):
    void update(uint k) {
        d[k] = opTT(d[2*k], d[2*k+1]);
    }
    T single(uint k) {
        return d[k+sz];
    }
    void singleSet(uint k, T x) {
        k += sz;
        d[k] = x;
        foreach (uint i; 1..lg+1) {
            update(k>>i);
        }
    }
    T sum(uint a, uint b) {
        assert(0 <= a && a <= b && b <= n);
        T sml = eT, smr = eT;
        a += sz; b += sz;
        while (a < b) {
            if (a & 1) sml = opTT(sml, d[a++]);
            if (b & 1) smr = opTT(d[--b], smr);
            a >>= 1; b >>= 1;
        }
        return opTT(sml, smr);
    }
}

int binSearchSimple(bool rev, alias pred, TR)(TR t, int a, int b) {
    import std.traits : TemplateArgsOf;
    alias args = TemplateArgsOf!TR;
    alias opTT = args[1];
    auto x = args[2];
    with (t) {
        static if (!rev) {

            if (pred(x)) return a-1;
            int pos = a;
            void f(int a, int b, int l, int r, int k) {
                if (b <= l || r <= a) return;
                if (a <= l && r <= b && !pred(opTT(x, d[k]))) {
                    x = opTT(x, d[k]);
                    pos = r;
                    return;
                }
                if (l+1 == r) return;
                int md = (l+r)/2;
                f(a, b, l, md, 2*k);
                if (pos >= md) f(a, b, md, r, 2*k+1);
            }
            f(a, b, 0, sz, 1);
            return pos;
        } else {

            if (pred(x)) return b;
            int pos = b-1;
            void f(int a, int b, int l, int r, int k) {
                if (b <= l || r <= a) return;
                if (a <= l && r <= b && !pred(opTT(x, d[k]))) {
                    x = opTT(d[k], x);
                    pos = l-1;
                    return;
                }
                if (l+1 == r) return;
                int md = (l+r)/2;
                f(a, b, md, r, 2*k+1);
                if (pos < md) f(a, b, l, md, 2*k);
            }
            f(a, b, 0, sz, 1);
            return pos;
        }
    }
}

alias LazySeg(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL, alias Engine = LazySegEngine) =
    SegTree!(Engine, T, L , binaryFun!opTT, binaryFun!opTL, binaryFun!opLL, eT, eL);

struct LazySegEngine(T, L, alias opTT, alias opTL, alias opLL, T eT, L eL) {
    import std.typecons : Tuple;
    alias DataType = T;
    alias LazyType = L;
    alias BinSearch = binSearchLazy;
    alias S = Tuple!(T, "d", L, "lz");
    uint n, sz, lg;
    S[] s;
    this(uint n) {
        import std.conv : to;
        import std.algorithm : each;
        this.n = n;
        uint lg = 0;
        while ((2^^lg) < n) lg++;
        this.lg = lg;
        sz = 2^^lg;
        s = new S[](2*sz);
        s.each!((ref x) => x = S(eT, eL));
    }
    this(T[] first) {
        import std.conv : to;
        import std.algorithm : each;
        n = first.length.to!uint;
        uint lg = 0;
        while ((2^^lg) < n) lg++;
        this.lg = lg;
        sz = 2^^lg;

        s = new S[](2*sz);
        s.each!((ref x) => x = S(eT, eL));
        foreach (i; 0..n) {
            s[sz+i].d = first[i];
        }
        foreach_reverse (i; 1..sz) {
            update(i);
        }
    }
    @property uint length() const { return n; }
    pragma(inline):
    private void lzAdd(uint k, in L x) {
        s[k].lz = opLL(s[k].lz, x);
        s[k].d = opTL(s[k].d, x);
    }
    public void push(uint k) {
        if (s[k].lz == eL) return;
        lzAdd(2*k, s[k].lz);
        lzAdd(2*k+1, s[k].lz);
        s[k].lz = eL;
    }
    private void update(uint k) {
        s[k].d = opTT(s[2*k].d, s[2*k+1].d);
    }
    T single(uint k) {
        k += sz;
        foreach_reverse (uint i; 1..lg+1) {
            push(k>>i);
        }
        return s[k].d;
    }
    void singleSet(uint k, T x) {
        k += sz;
        foreach_reverse (uint i; 1..lg+1) {
            push(k>>i);
        }
        s[k].d = x;
        foreach (uint i; 1..lg+1) {
            update(k>>i);
        }
    }
    T sum(uint a, uint b) {
        assert(0 <= a && a <= b && b <= n);
        if (a == b) return eT;
        a += sz; b--; b += sz;
        uint tlg = lg;
        while (true) {
            uint k = a >> tlg;
            if (a >> tlg != b >> tlg) {
                tlg++;
                break;
            }
            if (((a-1) >> tlg) + 2 == (b+1) >> tlg) return s[k].d;
            push(k);
            tlg--;
        }
        T sm = eT;
        foreach_reverse (l; 0..tlg) {
            uint k = a >> l;
            if ((a-1)>>l != a>>l) {
                sm = opTT(s[k].d, sm);
                break;
            }
            push(k);
            if (!((a >> (l-1)) & 1)) sm = opTT(s[2*k+1].d, sm);
        }
        foreach_reverse (l; 0..tlg) {
            uint k = b >> l;
            if (b>>l != (b+1)>>l) {
                sm = opTT(sm, s[k].d);
                break;
            }
            push(k);
            if ((b >> (l-1)) & 1) sm = opTT(sm, s[2*k].d);
        }
        return sm;
    }
    void add(uint a, uint b, L x) {
        assert(0 <= a && a <= b && b <= n);
        if (a == b) return;
        a += sz; b--; b += sz;
        uint tlg = lg;
        while (true) {
            uint k = a >> tlg;
            if (a >> tlg != b >> tlg) {
                tlg++;
                break;
            }
            if (((a-1) >> tlg) + 2 == (b+1) >> tlg) {
                lzAdd(k, x);
                foreach (l; tlg+1..lg+1) {
                    update(a >> l);
                }
                return;
            }
            push(k);
            tlg--;
        }
        foreach_reverse (l; 0..tlg) {
            uint k = a >> l;
            if ((a-1)>>l != a>>l) {
                lzAdd(k, x);
                foreach (h; l+1..tlg) {
                    update(a >> h);
                }
                break;
            }
            push(k);
            if (!((a >> (l-1)) & 1)) lzAdd(2*k+1, x);
        }
        foreach_reverse (l; 0..tlg) {
            uint k = b >> l;
            if (b>>l != (b+1)>>l) {
                lzAdd(k, x);
                foreach (h; l+1..tlg) {
                    update(b >> h);
                }
                break;
            }
            push(k);
            if ((b >> (l-1)) & 1) lzAdd(2*k, x);
        }
        foreach (l; tlg..lg+1) {
            update(a >> l);
        }
    }
}

int binSearchLazy(bool rev, alias pred, TR)(TR t, int a, int b) {
    import std.traits : TemplateArgsOf;
    alias args = TemplateArgsOf!TR;
    alias opTT = args[2];
    auto x = args[5];
    with (t) {
        static if (!rev) {

            if (pred(x)) return a-1;
            int pos = a;
            void f(int a, int b, int l, int r, int k) {
                if (b <= l || r <= a) return;
                if (a <= l && r <= b && !pred(opTT(x, s[k].d))) {
                    x = opTT(x, s[k].d);
                    pos = r;
                    return;
                }
                if (l+1 == r) return;
                push(k);
                int md = (l+r)/2;
                f(a, b, l, md, 2*k);
                if (pos >= md) f(a, b, md, r, 2*k+1);
            }
            f(a, b, 0, sz, 1);
            return pos;
        } else {

            if (pred(x)) return b;
            int pos = b-1;
            void f(int a, int b, int l, int r, int k) {
                if (b <= l || r <= a) return;
                if (a <= l && r <= b && !pred(opTT(x, s[k].d))) {
                    x = opTT(s[k].d, x);
                    pos = l-1;
                    return;
                }
                if (l+1 == r) return;
                push(k);
                int md = (l+r)/2;
                f(a, b, md, r, 2*k+1);
                if (pos < md) f(a, b, l, md, 2*k);
            }
            f(a, b, 0, sz, 1);
            return pos;
        }
    }
}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/foundation.d */

// module dkh.foundation;

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

}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;

struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
    import core.exception : RangeError;

    private T* _data;
    private uint len, cap;

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

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

    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        return _data[i];
    }
    ref inout(T) front() inout { return this[0]; }
    ref inout(T) back() inout { return this[$-1]; }

    void reserve(size_t newCap) {
        import core.memory : GC;
        import core.stdc.string : memcpy;
        import std.conv : to;
        if (newCap <= cap) return;
        void* newData = GC.malloc(newCap * T.sizeof);
        cap = newCap.to!uint;
        if (len) memcpy(newData, _data, len * T.sizeof);
        _data = cast(T*)(newData);
    }
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }

    void clear() {
        len = 0;
    }

    void insertBack(T item) {
        import std.algorithm : max;
        if (len == cap) reserve(max(cap * 2, MINCAP));
        _data[len++] = item;
    }
    alias opOpAssign(string op : "~") = insertBack;
    void removeBack() {
        assert(!empty, "StackPayload.removeBack: Stack is empty");
        len--;
    }
}

/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;

// import dkh.container.stackpayload;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    private File f;

    this(File f) {
        this.f = f;
    }
    private char[512] lineBuf;
    private char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

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

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    assert(succW());
                    x[i] = line.parse!E;
                }
            } else {
                StackPayload!E buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }

    int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }

    void read(Args...)(auto ref Args args) {
        import std.exception : enforce;
        static if (args.length != 0) {
            enforce(readSingle(args[0]));
            read(args[1..$]);
        }
    }

    bool hasNext() {
        return succ();
    }
}

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

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

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

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

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

int N;
int[] A;
int Q;
int[] T, P, X;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }
      Q = readInt();
      T = new int[Q];
      P = new int[Q];
      X = new int[Q];
      foreach (q; 0 .. Q) {
        T[q] = readInt();
        if (T[q] == 1) {
          P[q] = readInt() - 1;
        }
        X[q] = readInt();
      }

      auto ans = new int[N];
      ans[] = -1;
      int maxPay;
      foreach_reverse (q; 0 .. Q) {
        switch (T[q]) {
          case 1: {
            if (ans[P[q]] == -1) {
              ans[P[q]] = max(X[q], maxPay);
            }
          } break;
          case 2: {
            chmax(maxPay, X[q]);
          } break;
          default: assert(false);
        }
      }
      foreach (i; 0 .. N) {
        if (ans[i] == -1) {
          ans[i] = max(A[i], maxPay);
        }
      }

      foreach (i; 0 .. N) {
        if (i > 0) {
          write(" ");
        }
        write(ans[i]);
      }
      writeln();
    }
  } catch (EOFException e) {
  }
}

import std.stdio;
import std.algorithm;

const int MAX = 200005;
int n, q;
int[MAX] a;
int[MAX] p;
int[MAX] last_spent, maxPayout, payout;
int type, id, x;

void main() {
    readf(" %s", n);
    foreach(i; 0..n) readf(" %s", a[i]);
    readf(" %s", q);
    foreach(i; 0..q) {
        readf(" %s", type);
        if (type == 1) {
            readf(" %s %s", id, x);
            id--;
            a[id] = x;
            last_spent[id] = i;
        } else {
            readf(" %s", payout[i]);
        }
    }
    foreach_reverse(i; 0..q) maxPayout[i] = max(maxPayout[i+1], payout[i]);
    foreach(i; 0..n) {
        int result = max(a[i], maxPayout[last_spent[i]]);
        write(result, " ");
    }
}

import std.stdio;
import std.algorithm;

const int MAX = 200005;
int n, q;
int[MAX] a, p;
int[MAX] lastSpent, maxPayout, payout;

void main() {
    readf(" %s", n);
    foreach(i; 0..n) readf(" %s", a[i]);
    readf(" %s", q);
    foreach(i; 0..q) {
        int type;
        readf(" %s", type);
        if (type == 1) {
            int j, x;
            readf(" %s %s", j, x);
            j--;
            a[j] = x;
            lastSpent[j] = i;
        } else {
            readf(" %s", payout[i]);
        }
    }

    foreach_reverse(i; 0..q) maxPayout[i] = max(maxPayout[i+1], payout[i]);
    foreach(i; 0..n) {
        int result = max(a[i], maxPayout[lastSpent[i]]);
        write(result, " ");
    }
}

import std.stdio;
import std.algorithm;

const int MAX = 200005;
int n, q;
int[MAX] a;
int[MAX] p;
int[MAX] last_spent, maxPayout, payout;
int type, id, x;

void main() {
    readf(" %s", n);
    foreach(i; 0..n) readf(" %s", a[i]);
    readf(" %s", q);
    foreach(i; 0..q) {
        readf(" %s", type);
        if (type == 1) {
            readf(" %s %s", id, x);
            id--;
            a[id] = x;
            last_spent[id] = i;
        } else {
            readf(" %s", payout[i]);
        }
    }
    foreach_reverse(i; 0..n) maxPayout[i] = max(maxPayout[i+1], payout[i]);
    foreach(i; 0..n) {
        int result = max(a[i], maxPayout[last_spent[i]]);
        write(result, " ");
    }
}


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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		auto b = new bool [n];

		int res = 0;
		int best = 0;
		foreach (block; 1..n)
		{
			int cur = n - n / (block + 1) - !!(n % (block + 1));
			cur -= block;
			if (res < cur)
			{
				res = cur;
				best = block + 1;
			}
		}

		void go (R) (R r)
		{
			auto len = r.walkLength.to !(int);
			writefln ("%s%( %s%)", len, r.map !(q{a + 1}));
			foreach (ref c; r)
			{
				b[c] = true;
			}
			stdout.flush ();
			int k;
			readf !(" %s") (k);
			if (k == -1)
			{
				assert (false);
			}
			k -= 1;
			foreach (i; 0..len)
			{
				b[k] = false;
				k = (k + 1) % n;
			}
		}

		while (b.sum < res)
		{
			auto p = iota (n - 1)
			    .filter !(i => i % best != best - 1)
			    .filter !(i => !b[i]).array;
			go (p);
		}

		writeln (0);
		stdout.flush ();
	}
}

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

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

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

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

void main() {
  /*
  debug {
    foreach (n; 1 .. 16 + 1) {
      auto dp = new int[1 << n];
      auto prev = new int[1 << n];
      foreach (p; 0 .. 1 << n) {
        dp[p] = popcnt(p);
        prev[p] = -1;
      }
      int iter;
      for (; ; ++iter) {
        bool upd;
        foreach_reverse (p; 0 .. 1 << n) {
          const sup = ((1 << n) - 1) ^ p;
          for (int q = sup; q; --q &= sup) {
            const k = popcnt(q);
            int mn = n + 1;
            foreach (i; 0 .. n) {
              int r = p | q;
              foreach (j; 0 .. k) {
                r &= ~(1 << ((i + j) % n));
              }
              chmin(mn, dp[r]);
            }
            if (chmax(dp[p], mn)) {
              upd = true;
              prev[p] = q;
            }
          }
        }
        if (!upd) {
          break;
        }
      }
      write(n, ": ", iter, " ", dp[0], " ");
      foreach (i; 0 .. n) {
        write((prev[0] >> i) & 1);
      }
      writeln;
      for (int p = 0; ; ) {
        foreach (i; 0 .. n) {
          write((p >> i) & 1);
        }
        writeln;
        if (prev[p] == -1) {
          break;
        }
        foreach (i; 0 .. n) {
          write(((p | prev[p]) >> i) & 1);
        }
        writeln;
        const k = popcnt(prev[p]);
        int mn = n + 1;
        int rm = -1;
        foreach (i; 0 .. n) {
          int r = p | prev[p];
          foreach (j; 0 .. k) {
            r &= ~(1 << ((i + j) % n));
          }
          assert(dp[p] <= dp[r]);
          if (dp[p] == dp[r]) {
            if (chmin(mn, popcnt(r))) {
              rm = r;
            }
          }
        }
        assert(rm != -1);
        p = rm;
      }
      stdout.flush;
    }
  }
  //*/

  debug {
    foreach (n; 1 .. 16 + 1) {
      int mx;
      foreach (a; 1 .. n + 1) {
        const q = n / a, r = n % a;
        int score;
        foreach (x; 1 .. a) {
          score += (q + ((x < r) ? 1 : 0)) - 1;
        }
        chmax(mx, score);
      }
      writeln(n, ": ", mx);
    }
  }

  const N = readInt();

  int mx = -1;
  int am;
  foreach (a; 1 .. N + 1) {
    const q = N / a, r = N % a;
    int score;
    foreach (x; 1 .. a) {
      score += (q + ((x < r) ? 1 : 0)) - 1;
    }
    if (chmax(mx, score)) {
      am = a;
    }
  }

  bool[] on;
  const qm = N / am, rm = N % am;
  foreach (x; 0 .. am) {
    const b = qm + ((x < rm) ? 1 : 0);
    foreach (y; 0 .. b) {
      on ~= (y != 0);
    }
  }
  debug {
    writeln(N, ": ", mx, " ", am, " ", qm, " ", rm, " ", on);
  }

  auto now = new bool[N];
  for (; ; ) {
    if (now.count(true) >= mx) {
      writeln(0);
      stdout.flush;
      return;
    }
    int[] js;
    foreach (j; 0 .. N) {
      if (on[j] && !now[j]) {
        js ~= j;
      }
    }
    const jsLen = cast(int)(js.length);
    writeln(jsLen);
    foreach (k; 0 .. jsLen) {
      if (jsLen > 0) write(" ");
      write(js[k] + 1);
    }
    writeln;
    stdout.flush;
    const res = readInt();
    if (res == -1) {
      stderr.writeln("ERROR");
      return;
    }
    now[] = on[];
    foreach (k; 0 .. jsLen) {
      now[(res - 1 + k) % N] = false;
    }
  }
}

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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		auto b = new bool [n];

		void go (R) (R r)
		{
			auto len = r.walkLength.to !(int);
			writefln ("%s%( %s%)", len, r.map !(q{a + 1}));
			foreach (ref c; r)
			{
				b[c] = true;
			}
			stdout.flush ();
			int k;
			readf !(" %s") (k);
			k -= 1;
			foreach (i; 0..len)
			{
				b[k] = false;
				k = (k + 1) % n;
			}
		}

		int res = n / 2 - 1;
		while (b.sum < res)
		{
			auto p = n.iota.drop (1).stride (2)
			    .filter !(i => !b[i]).array;
			go (p);
		}

		writeln (0);
		stdout.flush ();
	}
}