The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:  The query to swap two table rows;  The query to swap two table columns;  The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.

The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly. Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106. Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers.   If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y);  If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y);  If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m).  The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.

For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.

NoteLet's see how the table changes in the second test case.After the first operation is fulfilled, the table looks like that:2 1 41 3 5After the second operation is fulfilled, the table looks like that:1 3 52 1 4So the answer to the third query (the number located in the first row and in the third column) will be 5.

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, 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.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()));
    }

}


You have a description of a lever as string s. We'll represent the string length as record |s|, then the lever looks as a horizontal bar with weights of length |s| - 1 with exactly one pivot. We will assume that the bar is a segment on the Ox axis between points 0 and |s| - 1.The decoding of the lever description is given below.  If the i-th character of the string equals "^", that means that at coordinate i there is the pivot under the bar.  If the i-th character of the string equals "=", that means that at coordinate i there is nothing lying on the bar.  If the i-th character of the string equals digit c (1-9), that means that at coordinate i there is a weight of mass c on the bar. Your task is, given the lever description, print if it will be in balance or not. Assume that the bar doesn't weight anything. Assume that the bar initially is in balance then all weights are simultaneously put on it. After that the bar either tilts to the left, or tilts to the right, or is in balance.

The first line contains the lever description as a non-empty string s (3 ≤ |s| ≤ 106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar. To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs.

Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance.

NoteAs you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever.The pictures to the examples:

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


Acingel is a small town. There was only one doctor here — Miss Ada. She was very friendly and nobody has ever said something bad about her, so who could've expected that Ada will be found dead in her house? Mr Gawry, world-famous detective, is appointed to find the criminal. He asked $$$m$$$ neighbours of Ada about clients who have visited her in that unlucky day. Let's number the clients from $$$1$$$ to $$$n$$$. Each neighbour's testimony is a permutation of these numbers, which describes the order in which clients have been seen by the asked neighbour.However, some facts are very suspicious – how it is that, according to some of given permutations, some client has been seen in the morning, while in others he has been seen in the evening? "In the morning some of neighbours must have been sleeping!" — thinks Gawry — "and in the evening there's been too dark to see somebody's face...". Now he wants to delete some prefix and some suffix (both prefix and suffix can be empty) in each permutation, so that they'll be non-empty and equal to each other after that — some of the potential criminals may disappear, but the testimony won't stand in contradiction to each other.In how many ways he can do it? Two ways are called different if the remaining common part is different.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100\,000$$$, $$$1 \le m \le 10$$$) — the number of suspects and the number of asked neighbors. Each of the next $$$m$$$ lines contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$). It is guaranteed that these integers form a correct permutation (that is, each number from $$$1$$$ to $$$n$$$ appears exactly once).

Output a single integer denoting the number of ways to delete some prefix and some suffix of each permutation (possibly empty), such that the remaining parts will be equal and non-empty.

NoteIn the first example, all possible common parts are $$$[1]$$$, $$$[2]$$$, $$$[3]$$$ and $$$[2, 3]$$$.In the second and third examples, you can only leave common parts of length $$$1$$$.

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

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		readln;
		int [] [] p;
		int [] [] q;
		foreach (j; 0..m)
		{
			p ~= readln.splitter.map !(to !(int)).array;
			p[$ - 1][] -= 1;

			q ~= new int [n];
			foreach (i; 0..n)
			{
				q[$ - 1][p[$ - 1][i]] = i;
			}
		}

		long res = 0;
		auto ans = new int [n];
		foreach_reverse (i; 0..n)
		{
			int value = p[0][i];
			int [] pos;
			foreach (j; 0..m)
			{
				pos ~= q[j][value];
			}

			int cur = 1;
			pos[] += 1;
			if (pos.maxElement < n)
			{
				auto next = p[0][pos[0]];
				if (m.iota.all !(j => p[j][pos[j]] == next))
				{
					cur = ans[next] + 1;
				}
			}
			ans[value] = cur;
			res += cur;
		}

		writeln (res);
	}
}


You have $$$n$$$ rectangular wooden blocks, which are numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th block is $$$1$$$ unit high and $$$\lceil \frac{i}{2} \rceil$$$ units long.Here, $$$\lceil \frac{x}{2} \rceil$$$ denotes the result of division of $$$x$$$ by $$$2$$$, rounded up. For example, $$$\lceil \frac{4}{2} \rceil = 2$$$ and $$$\lceil \frac{5}{2} \rceil = \lceil 2.5 \rceil = 3$$$.For example, if $$$n=5$$$, then the blocks have the following sizes: $$$1 \times 1$$$, $$$1 \times 1$$$, $$$1 \times 2$$$, $$$1 \times 2$$$, $$$1 \times 3$$$.  The available blocks for $$$n=5$$$ Find the maximum possible side length of a square you can create using these blocks, without rotating any of them. Note that you don't have to use all of the blocks.  One of the ways to create $$$3 \times 3$$$ square using blocks $$$1$$$ through $$$5$$$

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the number of blocks.

For each test case, print one integer — the maximum possible side length of a square you can create.

NoteIn the first test case, you can create a $$$1 \times 1$$$ square using only one of the blocks.In the second test case, one of the possible ways to create a $$$3 \times 3$$$ square is shown in the statement. It is impossible to create a $$$4 \times 4$$$ or larger square, so the answer is $$$3$$$.

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


You are given a special jigsaw puzzle consisting of $$$n\cdot m$$$ identical pieces. Every piece has three tabs and one blank, as pictured below.  The jigsaw puzzle is considered solved if the following conditions hold:  The pieces are arranged into a grid with $$$n$$$ rows and $$$m$$$ columns.  For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece. Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.

The test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$) — the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. Each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 10^5$$$).

For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).

NoteFor the first test case, this is an example solution:   For the second test case, we can show that no solution exists.For the third test case, this is an example solution:

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


Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.

The first input line contains integer n (1 ≤ n ≤ 100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.

If the given sequence has the second order statistics, output this order statistics, otherwise output NO.

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

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

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

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

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

int N;
int[] A;

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

		A.sort();
		auto res = A.unique;
		if (res.length >= 2) {
			writeln(res[1]);
		} else {
			writeln("NO");
		}
	}
	} catch (EOFException) {}
}


The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task?

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days.

Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution.

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

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

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

    auto ans = 0.0;
    foreach (len; k .. arr.length + 1) {
        auto s = arr[0 .. len - 1].sum;
        foreach (toDrop, toAdd; lockstep(arr, arr.drop(len - 1))) {
            debug { writeln(toDrop, ' ', toAdd); }
            s += toAdd;
            ans = max(ans, cast(double) s / len);
            s -= toDrop;
        }
    }
    ans.writefln!("%.10f");
}

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

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

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

    auto s = arr[0..k].sum;
    auto cur = s;
    foreach (le, r; lockstep(arr, arr.drop(k))) {
        debug { writeln(le, ' ', r); }
        cur = cur + r - le;
        s = max(s, cur);
    }

    auto ans = cast(double)s / k;
    ans.writefln!("%.7f");
}

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

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

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

    auto ans = 0.0;
    foreach (len; k .. arr.length) {
        auto s = arr[0 .. len - 1].sum;
        foreach (toDrop, toAdd; lockstep(arr, arr.drop(len - 1))) {
            debug { writeln(toDrop, ' ', toAdd); }
            s += toAdd;
            ans = max(ans, cast(double) s / len);
            s -= toDrop;
        }
    }
    ans.writefln!("%.10f");
}

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

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

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

    auto s = arr[0..k].sum;
    auto cur = s;
    foreach (le, r; lockstep(arr, arr.drop(k))) {
        debug { writeln(le, ' ', r); }
        cur = cur + r - le;
        s = max(s, cur);
    }

    auto ans = cast(real)s / k;
    ans.writefln!("%.11f");
}


There is a country with $$$n$$$ citizens. The $$$i$$$-th of them initially has $$$a_{i}$$$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $$$x$$$ are paid accordingly so that after the payout they have exactly $$$x$$$ money. In this case the citizens don't send a receipt.You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{5}$$$) — the numer of citizens. The next line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$0 \le a_{i} \le 10^{9}$$$) — the initial balances of citizens. The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^{5}$$$) — the number of events. Each of the next $$$q$$$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($$$1 \le p \le n$$$, $$$0 \le x \le 10^{9}$$$), or 2 x ($$$0 \le x \le 10^{9}$$$). In the first case we have a receipt that the balance of the $$$p$$$-th person becomes equal to $$$x$$$. In the second case we have a payoff with parameter $$$x$$$.

Print $$$n$$$ integers — the balances of all citizens after all events.

NoteIn the first example the balances change as follows: 1 2 3 4 $$$\rightarrow$$$ 3 3 3 4 $$$\rightarrow$$$ 3 2 3 4 $$$\rightarrow$$$ 3 2 3 4In the second example the balances change as follows: 3 50 2 1 10 $$$\rightarrow$$$ 3 0 2 1 10 $$$\rightarrow$$$ 8 8 8 8 10 $$$\rightarrow$$$ 8 8 20 8 10

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

/+ 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.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);
	}
}

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..n) maxPayout[i] = max(maxPayout[i+1], payout[i]);
    foreach(i; 0..n) {
        int result = max(a[i], maxPayout[last_spent[i]]);
        write(result, " ");
    }
}


This is an interactive problem.John and his imaginary friend play a game. There are $$$n$$$ lamps arranged in a circle. Lamps are numbered $$$1$$$ through $$$n$$$ in clockwise order, that is, lamps $$$i$$$ and $$$i + 1$$$ are adjacent for any $$$i = 1, \ldots, n - 1$$$, and also lamps $$$n$$$ and $$$1$$$ are adjacent. Initially all lamps are turned off.John and his friend take turns, with John moving first. On his turn John can choose to terminate the game, or to make a move. To make a move, John can choose any positive number $$$k$$$ and turn any $$$k$$$ lamps of his choosing on. In response to this move, John's friend will choose $$$k$$$ consecutive lamps and turn all of them off (the lamps in the range that were off before this move stay off). Note that the value of $$$k$$$ is the same as John's number on his last move. For example, if $$$n = 5$$$ and John have just turned three lamps on, John's friend may choose to turn off lamps $$$1, 2, 3$$$, or $$$2, 3, 4$$$, or $$$3, 4, 5$$$, or $$$4, 5, 1$$$, or $$$5, 1, 2$$$.After this, John may choose to terminate or move again, and so on. However, John can not make more than $$$10^4$$$ moves.John wants to maximize the number of lamps turned on at the end of the game, while his friend wants to minimize this number. Your task is to provide a strategy for John to achieve optimal result. Your program will play interactively for John against the jury's interactor program playing for John's friend.Suppose there are $$$n$$$ lamps in the game. Let $$$R(n)$$$ be the number of turned on lamps at the end of the game if both players act optimally. Your program has to terminate the game with at least $$$R(n)$$$ turned on lamps within $$$10^4$$$ moves. Refer to Interaction section below for interaction details.For technical reasons hacks for this problem are disabled.

NoteWhen $$$n = 3$$$, any John's move can be reversed, thus $$$R(3) = 0$$$, and terminating the game immediately is correct.$$$R(4) = 1$$$, and one strategy to achieve this result is shown in the second sample case.Blank lines in sample interactions are for clarity and should not be printed.

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