#include <iomanip>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>

#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;

const int N = 3000010;
const ll INF = 1e18+1;

int n;
int a[N];

int gcd(int a, int b) {
    if (!b) return a;
    return gcd(b, a % b);
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int x = 0;
    for (int i = 1; i <= n; i++) x = max(x, a[i]);
    int z = 0;
    for (int i = 1; i <= n; i++) z = gcd(z, x - a[i]);
    ll y = 0;
    for (int i = 1; i <= n; i++) y += (x - a[i]) / z;
    cout << y << " " << z;
    return 0;
}


#include <cstdio>

long long sward[200000] = { 0 };
long long number[200000] = { 0 };

long long find(long long a, long long b) {
	return (a % b ? find(b, a % b) : b);
}

int main() {
	long long x = 0, y = 0, z = 0, n = 0;

	scanf("%lld", &n);

	long long maxiunm = 0;
	for (long long i = 0; i < n; i++) {
		scanf("%lld", &sward[i]);
		maxiunm = maxiunm > sward[i] ? maxiunm : sward[i];
	}

	for (long long i = 0; i < n; i++) {
		sward[i] = maxiunm - sward[i];
	}

	long long num = 0;
	for (long long i = 0; i < n; i++) {
		if (sward[i]) {
			num = find(num, sward[i]);
		}
	}

	long long time = 0;
	for (long long i = 0; i < n; i++) {
		time += (sward[i] / num);
	}

	printf("%lld %lld", time, num);

	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>

using namespace std;
#define ll long long

int main()
{
	ll n;
	cin >> n;

	vector<ll> as(n);
	ll maxi = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> as[i];
		maxi = max(maxi, as[i]);
	}
	vector<ll> difs;
	ll difference, mindif, maxdif = 0;
	mindif = pow(10, 9) + 1;

	for (int i = 0; i < n; i++)
	{
		difference = maxi - as[i];
		if (difference > 0) {
			difs.push_back(difference);
			mindif = min(mindif, difference);
			maxdif = max(maxdif, difference);
		}
	}

	vector<ll> divisors;
	divisors.push_back(mindif);
	for (int i = 1; i <= sqrt(mindif); i++)
	{
		if (mindif % i == 0) {
			divisors.push_back(i);
			divisors.push_back(mindif / i);
		}
	}
	//sort(divisors.begin(), divisors.end());

	for (int i = 0; i < difs.size(); i++)
	{
		for (int j = 0; j < divisors.size(); j++)
		{
			if (difs[i] % divisors[j] != 0) {
				divisors[j] = -1;
			}
		}
	}

	ll maxdiv = 0;
	for (int i = 0; i < divisors.size(); i++)
	{
		maxdiv = max(maxdiv, divisors[i]);
	}
	ll people = 0;
	for (int i = 0; i < difs.size(); i++)
	{
		people += difs[i] / maxdiv;
	}
	cout << people << " " << maxdiv << endl;

	return 0;
}


#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int a[200010], b[200010];

long long int gcd(long long int a, long long int b)
{
	long long int da = max(a, b);
	long long int xiao = min(a, b);
	if (da % xiao == 0)
		return xiao;
	else
		return gcd(xiao, da % xiao);

}

int main()
{
	int n;
	cin >> n;
	int max_num = 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		max_num = max(max_num, a[i]);
	}
	long long sum = 0;
	long long int t = 1;
	for (int i = 0; i < n; i++)
	{
		if (a[i] != max_num)
		{
			long long int tt;
			tt = max_num - a[i];
			sum += tt;
			if (t == 1)
				t = tt;
			else
				t = gcd(tt, t);
		}
	}
	printf("%lld ", (sum / t));
	printf("%lld", t);
	return 0;
}


#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int a[200010], b[200010];

long long int gcd(long long int a, long long int b)
{
	long long int da = max(a, b);
	long long int xiao = min(a, b);
	if (da % xiao == 0)
		return xiao;
	else
		return gcd(xiao, da % xiao);

}

int main()
{
	int n;
	cin >> n;
	int max_num = 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		max_num = max(max_num, a[i]);
	}
	long long sum = 0;
	long long int t = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] != max_num)
		{
			long long int tt;
			tt = max_num - a[i];
			sum += tt;
			if (t == 0)
				t = tt;
			else
				t = gcd(tt, t);
		}
	}
	if (t == 0)
		printf("0 ");
	else
		printf("%lld ", (sum / t));
	printf("%lld", t);
	return 0;
}


//1216D --1300
#include <iostream>
#include <algorithm>
int n, a[200000], ans;
long long sum;
int gcd (int a, int b)
{
  while (b)
  {
    a %= b;
    std::swap (a, b);
  }
  return a;
}
int main ()
{
  std::cin >> n;
  for (int i = 0; i < n; ++i)
    std::cin >> a[i];
  int mn = *std::max_element (a, a + n);
  for (int i = 0; i < n; ++i)
    a[i] = mn - a[i],
    sum += a[i];
  ans = a[0];
  for (int i = 1; i < n; ++i)
    ans = gcd (ans, a[i]);
  std::cout << sum / ans << " " << ans;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

long long nod(long long a, long long b)
{
	return b ? nod(b, a%b) : a;
}
int main()
{
	long long n, x = 0, y = 0, z = 0, NOD=0, k=0, m=0;
	cin >> n;
	vector<long long> a(n);
	vector<long long> d(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] > x) x = a[i];
	}
	for (int i = 0; i < n; i++)
	{
		d[i] = x - a[i];
	}
	NOD = nod(d[0], d[1]);
	for (int i = 2; i < n; i++)
	{
		NOD = nod(NOD, d[i]);
	}
	for (int i = 0; i < n; i++)
	{
		k += d[i];
	}
	cout << k/NOD << " " << NOD;
	return 0;
}


#include<stdio.h>
int gcd(int m, int n);
int a[200000];
int b[200000];
int main()
{
	int n;
	scanf("%d", &n);
	int i, max = 0;
	int min;
	double sum=0;
	int num;
	int count = 0;
	int j;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		if (a[i] > max) max = a[i];
	}
	min = max;
	j = 0;
	for (i = 0; i < n; i++)
	{
		b[j] = max - a[i];
		if (b[j] == 0)
		{
			count++;
			continue;
		}
		if (b[j] < min) min = b[j];
		sum = sum + b[j];
		j++;
	}
	if (n-count > 2)
	{
		i = gcd(b[0], b[1]);
		for (j = 2; j < n - count; j++)
		{
			i = gcd(i, b[j]);
		}
	}
	else i = b[0];
	printf("%.0lf %d", sum / i, i);
	return 0;
}
int gcd(int m, int n)
{
	int t = 1;
	do
	{
		t = m % n;
		m = n;
		n = t;
	} while (t != 0);
	return m;
}


#include<stdio.h>
int gcd(int m, int n);
int a[200000];
int b[200000];
int main()
{
	int n;
	scanf("%d", &n);
	int i, max = 0;
	int min;
	double sum=0;
	int num;
	int j;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		if (a[i] > max) max = a[i];
	}
	min = max;
	j = 0;
	for (i = 0; i < n; i++)
	{
		b[j] = max - a[i];
		if (b[j] == 0) continue;
		if (b[j] < min) min = b[j];
		sum = sum + b[j];
		j++;
	}
	if (n > 2)
	{
		i = gcd(b[0], b[1]);
		for (j = 2; j < n - 1; j++)
		{
			i = gcd(i, b[j]);
		}
	}
	else i = b[0];
	printf("%.0lf %d", sum / i, i);
	return 0;
}
int gcd(int m, int n)
{
	int t = 1;
	do
	{
		t = m % n;
		m = n;
		n = t;
	} while (t != 0);
	return m;
}


#include<stdio.h>
int gcd(int m, int n);
int a[200000];
int b[200000];
int main()
{
	int n;
	scanf("%d", &n);
	int i, max = 0;
	int min;
	double sum=0;
	int num;
	int count = 0;
	int j;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		if (a[i] > max) max = a[i];
	}
	min = max;
	j = 0;
	for (i = 0; i < n; i++)
	{
		b[j] = max - a[i];
		if (b[j] == 0)
		{
			count++;
			continue;
		}
		if (b[j] < min) min = b[j];
		sum = sum + b[j];
		j++;
	}
	if (n-count >= 2)
	{
		i = gcd(b[0], b[1]);
		for (j = 2; j < n - count; j++)
		{
			i = gcd(i, b[j]);
		}
	}
	else i = b[0];
	printf("%.0lf %d", sum / i, i);
	return 0;
}
int gcd(int m, int n)
{
	int t = 1;
	do
	{
		t = m % n;
		m = n;
		n = t;
	} while (t != 0);
	return m;
}


#include<stdio.h>
int gcd(int m, int n);
int a[200000];
int b[200000];
int main()
{
	int n;
	scanf("%d", &n);
	int i, max = 0;
	int min;
	double sum=0;
	int num;
	int count = 0;
	int j;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		if (a[i] > max) max = a[i];
	}
	min = max;
	j = 0;
	for (i = 0; i < n; i++)
	{
		b[j] = max - a[i];
		if (b[j] == 0)
		{
			count++;
			continue;
		}
		if (b[j] < min) min = b[j];
		sum = sum + b[j];
		j++;
	}
	if (n > 2)
	{
		i = gcd(b[0], b[1]);
		for (j = 2; j < n - count; j++)
		{
			i = gcd(i, b[j]);
		}
	}
	else i = b[0];
	printf("%.0lf %d", sum / i, i);
	return 0;
}
int gcd(int m, int n)
{
	int t = 1;
	do
	{
		t = m % n;
		m = n;
		n = t;
	} while (t != 0);
	return m;
}


#include<iostream>
#include<stack>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<ctime>
#include<math.h>
#include<functional>
#include<cstring>
#include<iomanip>
#include<set>
#include<utility>
#include<limits.h>
#include<stdio.h>

using namespace std;
const int maxn = 200010;
int a[maxn];
int n, maxnum;
int gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a%b);
}
int main()
{
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		cin >> a[i];
		maxnum = max(maxnum, a[i]);
	}
	int t;
	for (int i = 0;i < n;i++)
	{
		a[i] = maxnum - a[i];
		if (i == 0) t = a[i];
		else t = gcd(t, a[i]);
	}
	long long sum = 0;
	for (int i = 0;i < n;i++)
		sum += a[i] / t;
	cout << sum << " "<< t;
	return ~~(0 - 0);
}


#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;

ll gcd(ll a, ll b)
{
	ll temp;
	if (a<b)         //用a来存大数
	{
		temp = a;
		a = b;
		b = temp;
	}
	while (b != 0)
	{
		temp = a % b;
		a = b;
		b = temp;
	}
	return a;
}

ll a[200005];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[n - 1] - a[i];
		a[i] = a[n - 1] - a[i];
	}
	int t = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] == 0)
			t++;
		else {
			break;
		}
	}
	ll maxfac, minmul;
	maxfac = gcd(a[0], a[1]);
	minmul = (a[0] * a[1]) / gcd(a[0], a[1]);
	for (int i = 0; i < n - t; i++)
	{
		maxfac = gcd(maxfac, a[i]);
		minmul = ((minmul*a[i]) / gcd(minmul, a[i]));
	}
	cout << sum / maxfac << " " << maxfac << endl;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <numeric>

using namespace std;

typedef long long li;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forb(i, n) for(int i = int(n) - 1; i >= 0; --i)

const int INF = 1e9;
const li INF64 = 1e18 + 1000;
const int N = 6 * 100 * 1000 + 100;
const int MOD = 1e9 + 9;

li gcd(li a, li b) {
	return a == 0 ? b : gcd(b % a, a);
}

void spr(int x) { cout << setprecision(x) << fixed; }

int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;
	vi a(n);
	int mx = -1;
	forn(i, n) {
		cin >> a[i];
		mx = max(mx, a[i]);
	}
	int g = 0;
	forn(i, n) {
		g = gcd(g, mx - a[i]);
	}
	li ans = 0;
	forn(i, n) {
		ans += (mx - a[i]) * 1ll / g;
	}
	cout << ans << " " << g;

}


#include <iostream>
#include <algorithm>

using namespace std;

long nod(long a, long b)
{
	if (b > a)
		swap(a, b);
	while (b)
	{
		a %= b;
		swap(a, b);
	}
	return a;
}

int main()
{
	int n;
	cin >> n;
	long* a = new long[n + 1];
	long max = 0;
	for (int i = 0; i < n;++i)
	{
		cin >> a[i];
		if (a[i] > max)
			max = a[i];
	}

	long sub = max - a[0];
	long long sum = 0;
	for (int i = 0; i < n; ++i)
	{
		sub = nod(sub, max - a[i]);
		sum += max - a[i];
	}
	sum /= sub;
	cout << sum << " " << sub;

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
long long a[200005];
int main()
{
   long long n;

   cin>>n;
   for (int i=0; i<n; i++){
       cin>>a[i];
   }

   sort (a, a+n);
   long long burg=0;
   long long bounty=0;
   for (int i=0; i<n-1; i++){
       if (a[i] != a[i+1]) {
           if (bounty==0){
               bounty=a[i+1]-a[i];
           }
           else if (bounty>a[i+1]-a[i]){
               bounty=a[i+1]-a[i];
           }
       }
   }
   for (int i=0; i<n-1; i++){
       burg=burg+(a[n-1]-a[i])/bounty;
   }
   cout<<burg<<" "<<bounty;
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
long long a[200005];

long long gcd(long long x,long long y){
    while (x != 0  && y !=0){
        if (x > y)
            x %= y;
        else
        y %= x;

    }
    return x+y;
}
int main()
{
   long long n;

   cin>>n;
   for (int i=0; i<n; i++){
       cin>>a[i];
   }

   sort (a, a+n);
   long long burg=0;
   long long bounty=0;
   for (int i=0; i<n-1; i++){
       if (a[i] != a[i+1]) {
           if (bounty==0){
               bounty=a[i+1]-a[i];
           }
           else
               bounty = gcd(bounty,a[i+1]-a[i]);

       }
   }
   for (int i=0; i<n-1; i++){
       burg=burg+(a[n-1]-a[i])/bounty;
   }
   cout<<burg<<" "<<bounty;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define Maxi 500000

ll a[Maxi];

ll GCD(ll a, ll b)
{
	if (a % b == 0) return b;
	return GCD(b, a % b);
}
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &a[i]);
	}
	sort(a + 1, a + n + 1);
	ll sum = 0, mini = INF;
	for (int i = 1; i < n; i++)
	{
		sum += (a[n] - a[i]);
		if (mini == INF && a[i + 1] - a[i]) mini = a[i + 1] - a[i];
		else if (mini != INF && a[i + 1] - a[i]) mini = GCD(mini, a[i + 1] - a[i]);
	}
	printf("%lld %lld\n", sum / mini, mini);
	return 0;
}


import java.io.*
import java.math.BigInteger
import java.util.*

val inputFile : String? = null
val outputFile : String? = null
val inputType : Int = 0
val tests = arrayOf(
        "4\nIvan 150\nIgor 215\nDasha 158\nKatya 150", "Ivan\nKatya\nDasha\nIgor",
        "2\nSASHA 180\nSASHA 170", "SASHA\nSASHA"
)

fun solve(inp: InputReader, out: OutputWriter, testNumber: Int) {
    var n = inp.readInt()
    var students = Array<Student>(n,
        { var name = inp.readString()
            var height = inp.readInt()
            return@Array Student(name, height)
        })
    Arrays.sort(students, Comparator { a, b -> a.height - b.height })
    for (student in students) {
        out.printLine(student.name)
    }
}

data class Student(val name: String, val height: Int)

fun check(input: String, answer: String, output: String): String {
    var expected = InputReader(StringBufferInputStream(answer))
    var actual = InputReader(StringBufferInputStream(output))

    while (true) {
        if (expected.isExhausted()) {
            if (actual.isExhausted())
                return "OK"
            return "PE, excessive tokens"
        }
        if (actual.isExhausted())
            return "PE, not enough tokens"
        val expectedToken = expected.readString()
        val actualToken = actual.readString()
        if (!expectedToken.equals(actualToken))
            return "WA, " + expectedToken + " != " + actualToken
    }
}

fun main(args: Array<String>) {
    Locale.setDefault(Locale.US)
    if (args.size != 0 && "Test".equals(args[0])) {
        test()
    } else {
        var inp: InputReader
        if (inputFile == null)
            inp = InputReader(System.`in`)
        else
            inp = InputReader(FileInputStream(inputFile))
        var out: OutputWriter
        if (outputFile == null)
            out = OutputWriter(PrintWriter(System.out))
        else
            out = OutputWriter.init(FileOutputStream(outputFile))
        run(inp, out)
    }
}

fun test() {
    Thread.sleep(100)
    var i = 0
    var maxTime: Long = 0
    var ok = -1
    while (i < tests.size) {
        var input = tests[i]
        var answer = tests[i + 1]
        i += 2
        var testNumber = i / 2
        var inp = InputReader(StringBufferInputStream(input))
        var sw = StringWriter()
        var out = OutputWriter(PrintWriter(sw))
        println("Test #" + testNumber)
        println("Input:")
        println(input)
        println()
        println("Answer:")
        println(answer)
        println()
        println("Output:")
        var time = System.currentTimeMillis()
        var verdict: String
        try {
            run(inp, out)
            time = System.currentTimeMillis() - time
            var output = sw.toString()
            println(output)
            verdict = check(input, answer, output)
        } catch (e: Throwable) {
            verdict = "Runtime Error (" + e.javaClass.getSimpleName() + ")"
            println(e.message)
            e.printStackTrace()
        }
        println("Verdict = " + verdict)
        if (!verdict.equals("OK"))
            ok = testNumber
        println(java.lang.String.format("Time = %.3f\n", time / 1000.0))
        maxTime = Math.max(maxTime, time)
        println("----------------------------------------------------------")
    }
    if (ok == -1)
        println("All test passed")
    else
        println("First failed test = " + ok)
    println(java.lang.String.format("Maximal time = %.3f\n", maxTime / 1000.0))
}

fun run(inp: InputReader, out: OutputWriter) {
    if (inputType == 0)
        solve(inp, out, 1)
    else if (inputType == 1) {
        var testCount = inp.readInt()
        for (i in 1..testCount) {
            solve(inp, out, i)
        }
    } else if (inputType == 2) {
        try {
            var test = 1
            while (true) {
                solve(inp, out, test++)
            }
        } catch (e: UnknownError) {
        }
    }
    out.close()
}

open class InputReader(val stream: InputStream) {
    private var finished: Boolean = false
    private var buf: ByteArray = ByteArray(1024)
    private var curChar: Int = 0
    private var numChars: Int = 0
    private var filter: SpaceCharFilter? = null

    public open fun read(): Int {
        if (numChars == -1)
            throw InputMismatchException()

        if (curChar >= numChars)
        {
            curChar = 0
            try
            {
                numChars = stream.read(buf)
            }
            catch (e: IOException) {
                throw InputMismatchException()
            }

            if (numChars <= 0)
                return -1

        }

        return buf[curChar++].toInt()
    }
    public open fun peek(): Int {
        if (numChars == -1)
            return -1

        if (curChar >= numChars)
        {
            curChar = 0
            try
            {
                numChars = stream.read(buf)
            }
            catch (e: IOException) {
                return -1
            }

            if (numChars <= 0)
                return -1

        }

        return buf[curChar].toInt()
    }
    public open fun readInt(): Int {
        var c: Int = read()
        while (isSpaceChar(c))
            c = read()
        var sgn: Int = 1
        if (c == '-'.toInt())
        {
            sgn = -1
            c = read()
        }

        var res: Int = 0
        do
        {
            if (c.toInt() < '0'.toInt() || c.toInt() > '9'.toInt())
                throw InputMismatchException()

            res *= 10
            res += c.toInt() - '0'.toInt()
            c = read()
        }
        while (!isSpaceChar(c))
        return res * sgn
    }
    public open fun readLong(): Long {
        var c: Int = read()
        while (isSpaceChar(c))
            c = read()
        var sgn: Int = 1
        if (c == '-'.toInt())
        {
            sgn = -1
            c = read()
        }

        var res: Long = 0
        do
        {
            if (c.toInt() < '0'.toInt() || c.toInt() > '9'.toInt())
                throw InputMismatchException()

            res *= 10
            res += c.toInt() - '0'.toInt()
            c = read()
        }
        while (!isSpaceChar(c))
        return res * sgn
    }
    public open fun readString(): String {
        var c: Int = read()
        while (isSpaceChar(c))
            c = read()
        var res: StringBuilder = StringBuilder()
        do
        {
            res.appendCodePoint(c)
            c = read()
        }
        while (!isSpaceChar(c))
        return res.toString()
    }
    public open fun isSpaceChar(c: Int): Boolean {
        if (filter != null)
            return filter?.isSpaceChar(c)!!

        return isWhitespace(c)
    }
    private fun readLine0(): String {
        var buf: StringBuilder = StringBuilder()
        var c: Int = read()
        while (c != '\n'.toInt() && c != -1)
        {
            if (c != '\r'.toInt())
                buf.appendCodePoint(c)

            c = read()
        }
        return buf.toString()
    }
    public open fun readLine(): String {
        var s: String = readLine0()
        while ((s.trim().length) == 0)
            s = readLine0()
        return s
    }
    public open fun readLine(ignoreEmptyLines: Boolean): String {
        if (ignoreEmptyLines)
            return readLine()
        else
            return readLine0()
    }
    public open fun readBigInteger(): BigInteger {
        try
        {
            return BigInteger(readString())
        }
        catch (e: NumberFormatException) {
            throw InputMismatchException()
        }

    }
    public open fun readCharacter(): Char {
        var c: Int = read()
        while (isSpaceChar(c))
            c = read()
        return c.toChar()
    }
    public open fun readDouble(): Double {
        var c: Int = read()
        while (isSpaceChar(c))
            c = read()
        var sgn: Int = 1
        if (c == '-'.toInt())
        {
            sgn = -1
            c = read()
        }

        var res: Double = 0.0
        while (!isSpaceChar(c) && c != '.'.toInt())
        {
            if (c == 'e'.toInt() || c == 'E'.toInt())
                return res * Math.pow((10).toDouble(), (readInt()).toDouble())

            if (c.toInt() < '0'.toInt() || c.toInt() > '9'.toInt())
                throw InputMismatchException()

            res *= 10
            res += c.toInt() - '0'.toInt()
            c = read()
        }
        if (c == '.'.toInt())
        {
            c = read()
            var m: Double = 1.0
            while (!isSpaceChar(c))
            {
                if (c == 'e'.toInt() || c == 'E'.toInt())
                    return res * Math.pow((10).toDouble(), (readInt()).toDouble())

                if (c.toInt() < '0'.toInt() || c.toInt() > '9'.toInt())
                    throw InputMismatchException()

                m /= 10
                res += (c.toInt() - '0'.toInt()) * m
                c = read()
            }
        }

        return res * sgn
    }
    public open fun isExhausted(): Boolean {
        var value: Int
        while (true) {
            value = peek()
            if (!isSpaceChar(value) || value == -1)
                break
            read()
        }
        return value == -1
    }
    public open fun next(): String {
        return readString()
    }
    companion object {
        public open fun isWhitespace(c: Int): Boolean {
            return c == ' '.toInt() || c == '\n'.toInt() || c == '\r'.toInt() || c == '\t'.toInt() || c == -1
        }
        public interface SpaceCharFilter {
            public open fun isSpaceChar(ch: Int): Boolean
        }
    }
}

public open class OutputWriter(val writer: PrintWriter) {
    public open fun print(array: CharArray): Unit {
        writer.print(array)
    }
    public open fun print(vararg objects: Any): Unit {
        for (i in 0..objects.size - 1) {
            if (i != 0)
                writer.print(' ')

            writer.print(objects[i])
        }
    }
    public open fun print(array: IntArray): Unit {
        for (i in 0..array.size - 1) {
            if (i != 0)
                writer.print(' ')

            writer.print(array[i])
        }
    }
    public open fun print(array: LongArray): Unit {
        for (i in 0..array.size - 1) {
            if (i != 0)
                writer.print(' ')

            writer.print(array[i])
        }
    }
    public open fun printLine(array: IntArray): Unit {
        print(array)
        writer.println()
    }
    public open fun printLine(array: LongArray): Unit {
        print(array)
        writer.println()
    }
    public open fun printLine(): Unit {
        writer.println()
    }
    public open fun printLine(vararg objects: Any): Unit {
        print(*objects)
        writer.println()
    }
    public open fun print(i: Char): Unit {
        writer.print(i)
    }
    public open fun printLine(i: Char): Unit {
        writer.println(i)
    }
    public open fun printLine(array: CharArray): Unit {
        writer.println(array)
    }
    public open fun printFormat(format: String, vararg objects: Any): Unit {
        writer.printf(format, objects)
    }
    public open fun close(): Unit {
        writer.close()
    }
    public open fun flush(): Unit {
        writer.flush()
    }
    public open fun print(i: Long): Unit {
        writer.print(i)
    }
    public open fun printLine(i: Long): Unit {
        writer.println(i)
    }
    public open fun print(i: Int): Unit {
        writer.print(i)
    }
    public open fun printLine(i: Int): Unit {
        writer.println(i)
    }
    companion object {
        public open fun init(outputStream: OutputStream): OutputWriter {
            val __1 = OutputWriter(PrintWriter(BufferedWriter(OutputStreamWriter(outputStream))))
            return __1
        }
        public open fun init(writer: Writer): OutputWriter {
            val __1 = OutputWriter(PrintWriter(writer))
            return __1
        }
    }
}

public open class IntegerUtils() {
    companion object {
        public open fun gcd(_a: Long, _b: Long): Long {
            var a = _a
            var b = _b
            a = Math.abs(a)
            b = Math.abs(b)
            while (b != 0.toLong())
            {
                var temp: Long = a % b
                a = b
                b = temp
            }
            return a
        }
        public open fun gcd(_a: Int, _b: Int): Int {
            var a = _a
            var b = _b
            a = Math.abs(a)
            b = Math.abs(b)
            while (b != 0)
            {
                var temp: Int = a % b
                a = b
                b = temp
            }
            return a
        }
        public open fun generatePrimes(upTo: Int): IntArray {
            var isPrime: BooleanArray = generatePrimalityTable(upTo)
            var primes: MutableList<Int>? = ArrayList()
            for (i in 0..upTo - 1) {
                if (isPrime[i])
                    primes?.add(i)

            }
            return primes?.toIntArray()!!
        }
        public open fun generatePrimalityTable(upTo: Int): BooleanArray {
            var isPrime: BooleanArray = BooleanArray(upTo)
            if (upTo < 2)
                return isPrime

            Arrays.fill(isPrime, true)
            isPrime[0] = false
            isPrime[1] = false
            for (i in 2..upTo - 1) {
                if (isPrime[i])
                {
                    var j: Int = i * i
                    while (j < upTo)
                    {
                        isPrime[j] = false
                        j += i
                    }
                }
                if (i * i >= upTo)
                    break
            }
            return isPrime
        }
        public open fun generateDivisorTable(upTo: Int): IntArray {
            var divisor: IntArray = IntArray(upTo)
            for (i in 1..upTo - 1) divisor[i] = i
            for (i in 2..upTo - 1) {
                if (divisor[i] == i)
                {
                    var j: Int = i * i
                    while (j < upTo)
                    {
                        divisor[j] = i
                        j += i
                    }
                }

            }
            return divisor
        }
        public open fun powerInFactorial(_n: Long, p: Long): Long {
            var n = _n
            var result: Long = 0
            while (n != 0.toLong())
            {
                n /= p
                result += n
            }
            return result
        }
        public open fun sumDigits(number: CharSequence): Int {
            var result: Int = 0
            var i: Int = (number.length) - 1
            while (i >= 0)
            {
                result += digitValue((number[i]))
                i--
            }
            return result
        }
        public open fun digitValue(digit: Char): Int {
            if (Character.isDigit(digit))
                return digit - '0'

            if (Character.isUpperCase(digit))
                return digit + 10 - 'A'

            return digit + 10 - 'a'
        }
        public open fun longCompare(a: Long, b: Long): Int {
            if (a < b)
                return -1

            if (a > b)
                return 1

            return 0
        }
        public open fun generateBinomialCoefficients(n: Int): Array<LongArray> {
            var result: Array<LongArray> = Array<LongArray>(n + 1, { LongArray(n + 1) })
            for (i in 0..n) {
                result[i][0] = 1
                for (j in 1..i) result[i][j] = result[i - 1][j - 1] + result[i - 1][j]
            }
            return result
        }
        public open fun generateBinomialCoefficients(n: Int, module: Long): Array<LongArray> {
            var result: Array<LongArray> = Array<LongArray>(n + 1, { LongArray(n + 1) })
            if (module == 1.toLong())
                return result

            for (i in 0..n) {
                result[i][0] = 1
                for (j in 1..i) {
                    result[i][j] = result[i - 1][j - 1] + result[i - 1][j]
                    if (result[i][j] >= module)
                        result[i][j] -= module

                }
            }
            return result
        }
        public open fun generateBinomialRow(n: Int, module: Long): LongArray {
            var result: LongArray = generateReverse(n + 1, module)
            result[0] = 1
            for (i in 1..n) result[i] = result[i - 1] * (n - i + 1) % module * result[i] % module
            return result
        }
        public open fun representationInBase(_number: Long, base: Int): IntArray {
            var number = _number
            var basePower: Long = base.toLong()
            var exponent: Int = 1
            while (number >= basePower)
            {
                basePower *= base
                exponent++
            }
            var representation: IntArray = IntArray(exponent)
            for (i in 0..exponent - 1) {
                basePower /= base
                representation[i] = ((number / basePower).toInt())
                number %= basePower
            }
            return representation
        }
        public open fun trueDivide(a: Int, b: Int): Int {
            return (a - trueMod(a, b)) / b
        }
        public open fun trueMod(_a: Int, b: Int): Int {
            var a = _a
            a %= b
            a += b
            a %= b
            return a
        }
        public open fun trueMod(_a: Long, b: Long): Long {
            var a = _a
            a %= b
            a += b
            a %= b
            return a
        }
        public open fun factorial(n: Int): Long {
            var result: Long = 1
            for (i in 2..n) result *= i
            return result
        }
        public open fun factorial(n: Int, mod: Long): Long {
            var result: Long = 1
            for (i in 2..n) result = result * i % mod
            return result % mod
        }
        public open fun factorize(_number: Long): List<Pair<Long, Int>> {
            var number = _number
            var result: MutableList<Pair<Long, Int>> = ArrayList<Pair<Long, Int>>()
            for (i in 2..number) {
                if (number % i == 0.toLong())
                {
                    var power: Int = 0
                    do
                    {
                        power++
                        number /= i
                    }
                    while (number % i == 0.toLong())
                    result.add(Pair(i, power))
                }

            }
            if (number != 1.toLong())
                result.plus(Pair(number, 1))

            return result
        }
        public open fun getDivisors(number: Long): List<Long?>? {
            var primeDivisors: List<Pair<Long?, Int?>?>? = factorize(number)
            return getDivisorsImpl(primeDivisors, 0, (1).toLong(), ArrayList<Long?>())
        }
        private fun getDivisorsImpl(primeDivisors: List<Pair<Long?, Int?>?>?, index: Int, current_: Long,
                                         result: MutableList<Long?>?): List<Long?>? {
            var current = current_
            if (index == (primeDivisors?.size)!!)
            {
                result?.add(current)
                return result
            }

            var p: Long = primeDivisors?.get(index)?.first!!
            var power: Int = primeDivisors?.get(index)?.second!!
            for (i in 0..power) {
                getDivisorsImpl(primeDivisors, index + 1, current, result)
                current *= p
            }
            return result
        }
        public open fun power(base: Long, exponent: Long): Long {
            if (exponent == 0.toLong())
                return 1

            var result: Long = power(base, exponent shr 1)
            result = result * result
            if ((exponent and 1) != 0.toLong())
                result = result * base

            return result
        }
        public open fun power(base_: Long, exponent: Long, mod: Long): Long {
            var base = base_
            if (base >= mod)
                base %= mod

            if (exponent == 0.toLong())
                return 1 % mod

            var result: Long = power(base, exponent shr 1, mod)
            result = result * result % mod
            if ((exponent and 1) != 0.toLong())
                result = result * base % mod

            return result
        }
        public open fun lcm(a: Long, b: Long): Long {
            return a / gcd(a, b) * b
        }
        public open fun generateFibonacci(upTo: Long): LongArray? {
            var count: Int = 0
            var last: Long = 0
            var current: Long = 1
            while (current <= upTo)
            {
                var next: Long = last + current
                last = current
                current = next
                count++
            }
            return generateFibonacci(count, (-1).toLong())
        }
        public open fun generateFibonacci(count: Int, module: Long): LongArray {
            var result: LongArray = LongArray(count)
            if (module == -1.toLong())
            {
                if (count != 0)
                    result[0] = 1

                if (count > 1)
                    result[1] = 1

                for (i in 2..count - 1) result[i] = result[i - 1] + result[i - 2]
            }
            else
            {
                if (count != 0)
                    result[0] = 1 % module

                if (count > 1)
                    result[1] = 1 % module

                for (i in 2..count - 1) result[i] = (result[i - 1] + result[i - 2]) % module
            }
            return result
        }
        public open fun generateHappy(digits: Int): LongArray {
            var happy: LongArray = LongArray((1 shl (digits + 1)) - 2)
            happy[0] = 4
            happy[1] = 7
            var first: Int = 0
            var last: Int = 2
            for (i in 2..digits) {
                for (j in 0..last - first - 1) {
                    happy[last + 2 * j] = 10 * happy[first + j] + 4
                    happy[last + 2 * j + 1] = 10 * happy[first + j] + 7
                }
                var next: Int = last + 2 * (last - first)
                first = last
                last = next
            }
            return happy
        }
        public open fun generateFactorial(count: Int, module: Long): LongArray {
            var result: LongArray = LongArray(count)
            if (module == -1.toLong())
            {
                if (count != 0)
                    result[0] = 1

                for (i in 1..count - 1) result[i] = result[i - 1] * i
            }
            else
            {
                if (count != 0)
                    result[0] = 1 % module

                for (i in 1..count - 1) result[i] = (result[i - 1] * i) % module
            }
            return result
        }
        public open fun reverse(number: Long, module: Long): Long {
            return power(number, module - 2, module)
        }
        public open fun isPrime(number: Long): Boolean {
            if (number < 2)
                return false

            for (i in 2..number) {
                if (number % i.toLong() == 0.toLong())
                    return false

            }
            return true
        }
        public open fun generateReverse(upTo: Int, module: Long): LongArray {
            var result: LongArray = LongArray(upTo)
            if (upTo > 1)
                result[1] = 1

            for (i in 2..upTo - 1) result[i] = (module - module / i * result[(((module % i) as Int))] % module) % module
            return result
        }
        public open fun generateReverseFactorials(upTo: Int, module: Long): LongArray {
            var result: LongArray = generateReverse(upTo, module)
            if (upTo > 0)
                result[0] = 1

            for (i in 1..upTo - 1) result[i] = result[i] * result[i - 1] % module
            return result
        }
        public open fun generatePowers(base: Long, count: Int, mod: Long): LongArray {
            var result: LongArray = LongArray(count)
            if (count != 0)
                result[0] = 1 % mod

            for (i in 1..count - 1) result[i] = result[i - 1] * base % mod
            return result
        }
        public open fun nextPrime(from_: Long): Long {
            var from = from_
            if (from <= 2)
                return 2

            from += 1 - (from and 1)
            while (!isPrime(from))
                from += 2
            return from
        }
        public open fun binomialCoefficient(n: Int, m_: Int, mod: Long): Long {
            var m = m_
            if (m < 0 || m > n)
                return 0

            if (2 * m > n)
                m = n - m

            var result: Long = 1
            for (i in n - m + 1..n) result = result * i % mod
            return result * (BigInteger.valueOf(factorial(m, mod))?.modInverse(BigInteger.valueOf(mod)))!!.toLong() %
                    mod
        }
        public open fun isSquare(number: Long): Boolean {
            var sqrt: Long = Math.round(Math.sqrt((number).toDouble()))
            return sqrt * sqrt == number
        }
        public open fun findCommon(aRemainder_: Long, aMod_: Long, bRemainder_: Long, bMod_: Long): Long {
            var aRemainder = aRemainder_
            var aMod = aMod_
            var bRemainder = bRemainder_
            var bMod = bMod_
            var modGCD: Long = gcd(aMod, bMod)
            var gcdRemainder: Long = aRemainder % modGCD
            if (gcdRemainder != bRemainder % modGCD)
                return -1

            aMod /= modGCD
            aRemainder /= modGCD
            bMod /= modGCD
            bRemainder /= modGCD
            var aReverse: Long = BigInteger.valueOf(aMod)?.modInverse(BigInteger.valueOf(bMod))?.toLong()!!
            var bReverse: Long = BigInteger.valueOf(bMod)?.modInverse(BigInteger.valueOf(aMod))?.toLong()!!
            var mod: Long = aMod * bMod
            return (bReverse * aRemainder % mod * bMod + aReverse * bRemainder % mod * aMod) % mod * modGCD + gcdRemainder
        }
        public open fun generatePowers(base: Long, maxValue: Long): LongArray? {
            if (maxValue <= 0)
                return LongArray(0)

            var size: Int = 1
            var current: Long = 1
            while (maxValue / base >= current)
            {
                current *= base
                size++
            }
            return generatePowers(base, size, Long.MAX_VALUE)
        }
    }
}


fun main(args: Array<String>) {
    val (len) = readLine()!!.split(' ').map(String::toInt)
    //print(len)
    val name = Array(5005, { i -> (i * i).toString() })
    var ht = Array(5005, { i -> (i * i) })

    var ya = 0
    for(ya in 0..len-1)
    {
        val (tmp1, tmp2) = readLine()!!.split(' ')
        //print(tmp1)
        //print(tmp2)
        name[ya] = tmp1
        ht[ya] = tmp2.toInt()
    }

    var cur = 120

    while(cur < 218)
    {
        var ya = 0
        while(ya < len)
        {
            if(ht[ya] == cur)
            {
                print(name[ya])
                print("\n")
            }
            ya++
        }
        cur++
    }
}


fun main(args: Array<String>) {
    val (len) = readLine()!!.split(' ').map(String::toInt)
    //print(len)
    val name = Array(5005, { i -> (i * i).toString() })
    var ht = Array(5005, { i -> (i * i) })

    var ya = 0
    for(ya in 0..len-1)
    {
        val (tmp1, tmp2) = readLine()!!.split(' ')
        //print(tmp1)
        //print(tmp2)
        name[ya] = tmp1
        ht[ya] = tmp2.toInt()
    }

    var cur = 216

    while(cur > 120)
    {
        var ya = 0
        while(ya < len)
        {
            if(ht[ya] == cur)
            {
                print(name[ya])
                print("\n")
            }
            ya++
        }
        cur--
    }
}


fun main(args: Array<String>) {
    var n = Integer.parseInt(readLine())
    var names: MutableList<String> = arrayListOf()
    var score: MutableList<Int> = arrayListOf()
    var m: Int = n
    while (n>0) {
        var s = readLine()!!.split(' ')
        var x = s[0]
        var y = Integer.parseInt(s[1])
        names.add(x)
        score.add(y)
        n=n-1
    }
    for (i in 0..m-2) {
        for (j in 0..m-i-2) {
            if (score[j]>score[j+1]) {
                var tmp: String = names[j]
                names[j]=names[j+1]
                names[j+1]=tmp
                var tmp1: Int = score[j]
                score[j+1]=score[j]
                score[j]=tmp1
            }
        }
    }
    for (i in names)
        println(i)
}


fun main(args: Array<String>) {
    var n = Integer.parseInt(readLine())
    var names: MutableList<String> = arrayListOf()
    var score: MutableList<Int> = arrayListOf()
    var m: Int = n
    while (n>0) {
        var s = readLine()!!.split(' ')
        var x = s[0]
        var y = Integer.parseInt(s[1])
        names.add(x)
        score.add(y)
        n=n-1
    }
    for (i in 0..m-2) {
        for (j in 0..m-i-2) {
            if (score[j]>score[j+1]) {
                var tmp: String = names[j]
                names[j]=names[j+1]
                names[j+1]=tmp
                var tmp1: Int = score[j]
                score[j]=score[j+1]
                score[j+1]=tmp1
            }
        }
    }
    for (i in names)
        println(i)
}


fun main(args: Array<String>)
{

    var x = readLine()!!.toInt()

    var nam = arrayOfNulls<String>(5000)
    var num = IntArray(5000)

    for(i in 1..x)
    {
        var (a, b) = readLine()!!.split(' ')
        nam[i-1] = a
        num[i-1] = b.toInt()
    }

    for(i in 1..x)
    {
        var (a, b) = readLine()!!.split(' ')
        nam[i-1] = a
        num[i-1] = b.toInt()
    }

    for(i in 1..x)
    {
        var k = num[0]
        var index = 0

        for(j in 1..(x-1))
        {
            if(num[j] > k)
            {
                k = num[j]
				index = j ;
            }
        }

        print(nam[index])

        num[index] = -10
    }

    }


/**
 * Line 13 demonstrates string templates and array access.
 * See this pages for details:
 * http://kotlinlang.org/docs/reference/basic-types.html#strings
 * http://kotlinlang.org/docs/reference/basic-types.html#arrays
 */

fun main(args: Array<String>): Int {

    var x = readLine()!!.toInt()

	var nam = arrayOfNulls<String>(5000)
    var num = IntArray(5000)

    for(i in 1..x)
    {
        var (a, b) = readLine()!!.split(' ')
        nam[i-1] = a
        num[i-1] = b.toInt()
    }

    for(i in 1..x)
    {
        var k = num[0]
        var index = 0

        for(j in 1..(x-1))
        {
            if(num[j] > k)
            {
                k = num[j]
				index = j ;
            }
        }

        print(nam[index])

        num[index] = -10
    }

    return 0

}


/**
 * Line 13 demonstrates string templates and array access.
 * See this pages for details:
 * http://kotlinlang.org/docs/reference/basic-types.html#strings
 * http://kotlinlang.org/docs/reference/basic-types.html#arrays
 */

fun main(args: Array<String>): Int {

    var x = readLine()!!.toInt()

    return 0

}


/**
 * Line 13 demonstrates string templates and array access.
 * See this pages for details:
 * http://kotlinlang.org/docs/reference/basic-types.html#strings
 * http://kotlinlang.org/docs/reference/basic-types.html#arrays
 */

import java.util.*

fun main(args: Array<String>): Int {

    var (x) = readLine()!!.split(' ').map(String::toInt)

    var nam = Array(5000) { "" }
    var num = IntArray(5000)

    for(i in 1..x)
    {
        var (a, b) = readLine()!!.split(' ')
        nam[i-1] = a
        num[i-1] = b.toInt()
    }

    for(i in 1..x)
    {
        var k = num[0]
        var index = 0

        for(j in 1..(x-1))
        {
            if(num[j] > k)
            {
                k = num[j]
				index = j ;
            }
        }

        print(nam[index])

        num[index] = -10
    }

    return 0

}


fun main(args: Array<String>)
{

    var x = readLine()!!.toInt()

    var nam = arrayOfNulls<String>(5000)
    var num = IntArray(5000)

    for(i in 1..x)
    {
        var (a, b) = readLine()!!.split(' ')
        nam[i-1] = a
        num[i-1] = b.toInt()
    }

    for(i in 1..x)
    {
        var k = num[0]
        var index = 0

        for(j in 1..(x-1))
        {
            if(num[j] > k)
            {
                k = num[j]
				index = j ;
            }
        }

        print(nam[index])

        num[index] = -10
    }

    }


fun main(args: Array<String>)
{

    var x = readLine()!!.toInt()

    var nam = arrayOfNulls<String>(5000)
    var num = IntArray(5000)

    for(i in 1..x)
    {
        var (a, b) = readLine()!!.split(' ')
        nam[i-1] = a
        num[i-1] = b.toInt()
    }

    for(i in 1..x)
    {
        var k = num[0]
        var index = 0

        for(j in 1..(x-1))
        {
            if(num[j] < k)
            {
                k = num[j]
				index = j ;
            }
        }

        println(nam[index])

        num[index] = 9999
    }

    }


import java.util.*

fun main(args: Array<String>) {
    var a = ArrayList<Pair<Int, String>> ();
    val (n) = readLine()!!.split(' ').map(String::toInt)

    for (i in 0..n - 1) {
        val (name, t) = readLine()!!.split(' ')
        val x = t.toInt()
        a.add(Pair(x, name))
    }
    a.sortBy { it: Pair<Int, String> -> it.first }

    for (x in a)
        println(x.second)
}


import java.util.*
import java.util.Collections.sort

fun max(a: Int, b: Int) = if (a > b) a else b
fun min(a: Int, b: Int) = if (a < b) a else b

fun test() {
    val scope = "world"
    println("Hello, $scope!")
    val (x, y) = readLine()!!.split(' ').map(String::toInt)
    println("max = ${max(x, y)}")
    for (i in 1..x+y)
        println("$i")

    val name = when (x) {
        1 -> "one"
        2 -> "two"
        else -> "unknown"
    }
    println("name of $x: $name")
}

fun main(args: Array<String>) {
    var a = ArrayList<Pair<Int, String>> ();
    val (n) = readLine()!!.split(' ').map(String::toInt)
    println(n)

    for (i in 0..n - 1) {
        val (name, t) = readLine()!!.split(' ')
        val x = t.toInt()
        a.add(Pair(x, name))
    }
    a.sortBy { it: Pair<Int, String> -> it.first }

    for (x in a)
        println(x.second)
}


fun main(args: Array<String>) {
    var a = ArrayList<Pair<Int, String>> ();
    val (n) = readLine()!!.split(' ').map(String::toInt)
    println(n)

    for (i in 0..n - 1) {
        val (name, t) = readLine()!!.split(' ')
        val x = t.toInt()
        a.add(Pair(x, name))
    }
    a.sortBy { it: Pair<Int, String> -> it.first }

    for (x in a)
        println(x.second)
}


import java.io.InputStreamReader
import java.io.BufferedReader
import java.util.*
import kotlin.*

fun main(args: Array<String>) {
    var sc = Scanner(System.`in`)
    var n = sc.nextInt()
    var h: Int
    var s: String = ""
    var p: Person
    var list: ArrayList<Person> = ArrayList<Person>()
    loop@ for (i in 1..n) {
    	s = sc.next()
        h = sc.nextInt()
        p = Person(h, s)
        list.add(p)
	}
    list.sortBy{ p -> p.h }
    loop@ for (i in 1..n) {
    	println(list[i-1].name)
}
}

public class Person(val h: Int, val name: String){

}


import com.sun.xml.internal.fastinfoset.util.StringArray
import java.io.*;
import java.util.*;

var LOCAL = File("input.txt").exists();

var _reader = when {
    LOCAL -> BufferedReader(FileReader("input.txt"));
    else -> BufferedReader(InputStreamReader(System.`in`));
}
var out = when {
    LOCAL -> PrintWriter("output.txt");
    else -> PrintWriter(System.`out`);
};
var _tokenizer = StringTokenizer("");

fun readString(): String {
    while (!_tokenizer.hasMoreTokens()) {
        _tokenizer = StringTokenizer(_reader.readLine()!!);
    }
    return _tokenizer.nextToken();
}

fun readInt(): Int {
    return java.lang.Integer.parseInt(readString());
}

fun readLong(): Long {
    return java.lang.Long.parseLong(readString());
}

fun readDouble(): Double {
    return java.lang.Double.parseDouble(readString());
}

fun debug(o: Any) {
    if (LOCAL) {
        System.`err`.println(o);
    }
}

fun main(args: Array<String>) {
    var t1: Long = 0;
    var t2: Long;
    if (LOCAL) {
        t1 = System.currentTimeMillis();
    };
    Locale.setDefault(Locale.US);
    solve();
    _reader.close();
    out.close();
    if (LOCAL) {
        t2 = System.currentTimeMillis();
        debug("Time = " + (t2 - t1));
    };
}

class Edge(
        val name: String,
        val y: Int
)

fun solve() {
    var n = readInt();

    var a = Array<Edge>(n) { Edge(readString(), readInt()) };

    for (i in 0..n - 1) {
        for (j in i + 1..n - 1) {
            if (a[i].y > a[j].y) {
                var t = a[i];
                a[i] = a[j];
                a[j] = t;
            }
        }
    }
    for (i in 0..n - 1) {
        out.println(a[i].name);
    }
}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt() - 1
    data class Man(val name: String, val height: Int)

    val school: MutableList<Man> = mutableListOf()

    for (i in 0..n) {
        val (name, h) = readLine()!!.split(' ')
        val height = h.toInt()
        val m = Man(name = name, height = height)
        school.add(m)
    }
    school.sortBy { it.height }

    for (i in 0..n) {
        println(school[i].name)
    }
}


fun main(args: Array<String>)
{
	val hs = Array(readLine()!!.toInt())
	{
		val p = readLine()!!.split(' ')
		Pair(p[0], p[1].toInt())
	}
	hs.sortBy{it.second}
	hs.forEach{println(it.first)}
}


fun main(args: Array<String>) {
	val a = readLine()!!.split(' ').map(String::toInt)
	val n = a[0].toInt()
	val names:MutableList<String> = mutableListOf()
	val hts:MutableList<Int> = mutableListOf()
	for(i in 1..n){
    var inp = readLine()!!.split(' ')
    var b = inp[1].toInt()
    names.add(inp[0].toString())
    hts.add(b)
    }
    for( i in 1..n-1)
    {
        var key=hts[i]
        var nm = names[i]
        var j = i-1
        while(j>=0 && hts[j]>key)
        {
            names[j+1]=names[j]
            j = j-1
        }
        names[j+1]=nm
    }
    for(i in 0..n-1)println(names[i])
    return
}


fun main(args: Array<String>) {
	val a = readLine()!!.split(' ').map(String::toInt)
	val n = a[0].toInt()
	val names:MutableList<String> = mutableListOf()
	val hts:MutableList<Int> = mutableListOf()
	for(i in 1..n){
    var inp = readLine()!!.split(' ')
    var b = inp[1].toInt()
    names.add(inp[0].toString())
    hts.add(b)
    }
    for( i in 1..n-1)
    {
        var key=hts[i]
        var nm = names[i]
        var j = i-1
        while(j>=0 && hts[j]>key)
        {
            names[j+1]=names[j]
            hts[j+1]=hts[j]
            j = j-1
        }
        names[j+1]=nm
        hts[j+1]=key
    }
    for(i in 0..n-1)println(names[i])
    return
}


fun main(args: Array<String>) {
    val ar = Array(6000, {0})
    val str = Array(6000, {""})
    var a = readLine()!!.toInt()
    var i = 1
    while (i < a + 1){
        val (s, s1) = readLine()!!.split(' ')
        ar[i] = s1.toInt()
        str[i] = s;
        i = i + 1
    }
    i = 1;
    var j = 1
    while (i <= a){
        j = 1;
        while (j < a){
            if (ar[j] < ar[j + 1]) {
                val c = ar[j]
                ar[j] = ar[j + 1]
                ar[j + 1] = c
                val s2 = str[j]
                str[j] = str[j + 1]
                str[j + 1] = s2
            }
            j++
        }
        i++
    }
    i = 1
    while (i <= a){
        println(str[i])
        i++
    }
}


fun main(args: Array<String>) {
    val ar = Array(5000, {0})
    val str = Array(5000, {""})
    var a = readLine()!!.toInt()
    var i = 1
    while (i < a + 1){
        val (s, s1) = readLine()!!.split(' ')
        ar[i] = s1.toInt()
        str[i] = s;
        i = i + 1
    }
    i = 1;
    var j = 1
    while (i <= a){
        j = 1;
        while (j < a){
            if (ar[j] > ar[j + 1]) {
                val c = ar[j]
                ar[j] = ar[j + 1]
                ar[j + 1] = c
                val s2 = str[j]
                str[j] = str[j + 1]
                str[j + 1] = s2
            }
            j++
        }
        i++
    }
    i = 1
    while (i <= a){
        println(str[i])
        i++
    }
}


fun main(args: Array<String>) {
    val ar = Array(6000, {0})
    val str = Array(6000, {""})
    var a = readLine()!!.toInt()
    var i = 1
    while (i < a + 1){
        val (s, s1) = readLine()!!.split(' ')
        ar[i] = s1.toInt()
        str[i] = s;
        i = i + 1
    }
    i = 1;
    var j = 1
    while (i <= a){
        j = 1;
        while (j < a){
            if (ar[j] > ar[j + 1]) {
                val c = ar[j]
                ar[j] = ar[j + 1]
                ar[j + 1] = c
                val s2 = str[j]
                str[j] = str[j + 1]
                str[j + 1] = s2
            }
            j++
        }
        i++
    }
    i = 1
    while (i <= a){
        println(str[i])
        i++
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar.set(i, Pair(z, x))
    }

    return

    ar.sort()
    for (i in ar.indices) {
        println(ar.get(i).second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar.set(i, Pair(z, x))
    }

    ar.sort()
    for (i in ar.indices) {
        println(ar.get(i).second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar.set(i, Pair(z, x))
    }

    for (i in ar.indices) {
        for (j in ar.indices) {
            if ((j > 0) and (ar[j].first < ar[j - 1].first)) {
                val k = ar[j]
                ar[j] = ar[j - 1]
                ar[j - 1] = k
            }
        }
    }

    for (i in ar.indices) {
        println(ar.get(i).second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar[i] = Pair(z, x)
    }

    val ars = ar.sortedWith(compareBy({it.first}, {it.second}))
    for (i in ars) {
        println(i.second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar.set(i, Pair(z, x))
    }

    for (i in ar.indices) {
        for (j in ar.indices) {
            if ((j > 1) and (ar[j].first < ar[j - 1].first)) {
                val k = ar[j]
                ar[j] = ar[j - 1]
                ar[j - 1] = k
            }
        }
    }

    for (i in ar.indices) {
        println(ar.get(i).second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar.set(i, Pair(z, x))
    }

    for (i in ar.indices) {
        for (j in ar.indices) {
            if ((j > 1) and (ar.get(j).first < ar.get(j - 1).first)) {
                val k : Pair<Int, String> = ar.get(j)
                ar.set(j, ar.get(j - 1))
                ar.set(j - 1, k)
            }
        }
    }

    for (i in ar.indices) {
        println(ar.get(i).second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar[i] = Pair(z, x)
    }

    val ars = ar.sort()
    for (Int : i in ars.indices) {
        println(ars[i].second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar[i] = Pair(z, x)
    }

    val ars = ar.sort()
    for (i in ars) {
        println(i.second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar.set(i, Pair(z, x))
    }

    for (i in 1..n) {
        for (j in 2..n) {
            if (ar.get(j).first < ar.get(j - 1).first) {
            /*
                val k : Pair<Int, String> = ar.get(j)
                val k2 : Pair<Int, String> = ar.get(j - 1)
                ar.set(j, k2)
                ar.set(j - 1, k)
            */
            }
        }
    }

    for (i in ar.indices) {
        println(ar.get(i).second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar.set(i, Pair(z, x))
    }

    for (i in 0..(n-1)) {
        for (j in 1..(n-1)) {
            if (ar.get(j).first < ar.get(j - 1).first) {
                val k : Pair<Int, String> = ar.get(j)
                val k2 : Pair<Int, String> = ar.get(j - 1)
                ar.set(j, k2)
                ar.set(j - 1, k)
            }
        }
    }

    for (i in ar.indices) {
        println(ar.get(i).second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.map(String::toInt)
    val ar = arrayOfNulls(n)
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar[i] = (z, x)
    }

    val ars = ar.sorted()
    for (i in ars) {
        println(i.second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar.set(i, Pair(z, x))
    }

    ar.sort()
    return
    for (i in ar.indices) {
        println(ar.get(i).second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar[i] = Pair(z, x)
    }

    val ars = ar.sort()
    for (i in ars.indices) {
        println(ars[i].second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar.set(i, Pair(z, x))
    }

    for (i in 1..n) {
        for (j in 2..n) {
            if (ar.get(j).first < ar.get(j - 1).first) {
                val k : Pair<Int, String> = ar.get(j)
                ar.set(j, ar.get(j - 1))
                ar.set(j - 1, k)
            }
        }
    }

    for (i in ar.indices) {
        println(ar.get(i).second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.toInt()
    val ar : Array< Pair<Int, String> > = arrayOfNulls(n)
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar[i] = Pair(z, x)
    }

    val ars = ar.sorted()
    for (i in ars) {
        println(i.second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar[i] = Pair(z, x)
    }

    ar.sort()
    for (i in ar.indices) {
        println(ar[i].second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar.set(i, Pair(z, x))
    }

    for (i in ar.indices) {
        for (j in ar.indices) {
        /*
            if ((j > 1) and (ar.get(j).first < ar.get(j - 1).first)) {
                val k : Pair<Int, String> = ar.get(j)
                ar.set(j, ar.get(j - 1))
                ar.set(j - 1, k)
            }
        */
        }
    }

    for (i in ar.indices) {
        println(ar.get(i).second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar.set(i, Pair(z, x))
    }

    for (i in 1..n) {
        for (j in 2..n) {
            if (ar.get(j).first < ar.get(j - 1).first) {
                val k : Pair<Int, String> = ar.get(j)
                val k2 : Pair<Int, String> = ar.get(j - 1)
                ar.set(j, k2)
                ar.set(j - 1, k)
            }
        }
    }

    for (i in ar.indices) {
        println(ar.get(i).second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.toInt()
    val ar : Array< Pair<int, String> > = arrayOfNulls(n)
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : int = y.toInt()
        ar[i] = Pair(int : z, String : x)
    }

    val ars = ar.sorted()
    for (i in ars) {
        println(i.second)
    }
}


import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    val(n) = readLine()!!.split(' ').map(String::toInt)
    val ar = Array(n, {i -> Pair(0, "")})
    for (i in ar.indices) {
        val(x, y) = readLine()!!.split(' ')
        val z : Int = y.toInt()
        ar[i] = Pair(z, x)
    }

    val ars : Array< Pair<Int, String> > = ar.sort()
    for (i in ars.indices) {
        println(ars[i].second)
    }
}


import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun toInt(s: String) = Integer.parseInt(s)

class St constructor(name1: String, h1: Int) {
    public val name = name1
    public val h = h1
}

fun parse(s: String): St {
    val t = s.split(" ")
    return St(t[0], toInt(t[1]))
}

fun main(args: Array<String>) {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    val n = toInt(reader.readLine())
    var students = Array<St>(n, {i -> parse(reader.readLine())})
    Arrays.sort(students, {u, v -> Integer.compare(u.h, v.h)})
    for (s in students) {
        println(s.name)
    }
}


package b

import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun toInt(s: String) = Integer.parseInt(s)

class St constructor(name1: String, h1: Int) {
    public val name = name1
    public val h = h1
}

fun parse(s: String): St {
    val t = s.split(" ")
    return St(t[0], toInt(t[1]))
}

fun main(args: Array<String>) {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    val n = toInt(reader.readLine())
    var students = Array<St>(n, {i -> parse(reader.readLine())})
    Arrays.sort(students, {u, v -> Integer.compare(u.h, v.h)})
    for (s in students) {
        println(s.name)
    }
}


fun main(args: Array<String>) {
    val (n) = readLine()!!.split(' ').map(String::toInt)
    var index = 0;
    var strArr= arrayOfNulls<String>(5000);
    val intArr= IntArray(5000) { it + 1 }

    while(index < n)
    {
        val(n,s) = readLine()!!.split(' ');
        val x = s.toInt();
        strArr[index] = n;
        intArr[index] = x;
        index++;
    }

    for(i in 0..n)
        for(j in 0..n-1)
            if(intArr[j] > intArr[j+1]){
                var tmp = intArr[j]
                intArr[j] = intArr[j+1]
                intArr[j+1] = tmp

                var tmpp = strArr[j]
                strArr[j] = strArr[j+1]
                strArr[j+1] = tmpp
            }

    for(i in 1..n) println(strArr[i])
}


fun main(args: Array<String>) {
    val (n) = readLine()!!.split(' ').map(String::toInt)
    var index = 0;
    var strArr= arrayOfNulls<String>(5000);
    val intArr= IntArray(5000) { it + 1 }

    while(index < n)
    {
        val(n,s) = readLine()!!.split(' ');
        val x = s.toInt();
        strArr[index] = n;
        intArr[index] = x;
        index++;
    }

    for(i in 1..n)
        for(j in 0..n-2)
            if(intArr[j] > intArr[j+1]){
                var tmp = intArr[j]
                intArr[j] = intArr[j+1]
                intArr[j+1] = tmp

                var tmpp = strArr[j]
                strArr[j] = strArr[j+1]
                strArr[j+1] = tmpp
            }

    for(i in 0..n-1) println(strArr[i])
}


import java.util.*

fun main(args: Array<String>) {
    val (n) = readLine()!!.split(' ').map(String::toInt)
    val name = ArrayList<String>()
    val num = ArrayList<Int>()
    for (i in 1..n) {
        val (s, ss) = readLine()!!.split(' ').map(String::toString)
        var x = ss.toInt()
        num.add(x)
        name.add(s)

    }
    for (i in 0..n-1)
        for (j in i+1..n-1)
            if (num[i]>num[j]) {
                val t1 = num[i]
                num[i] = num[j]
                num[j] = t1
                val t2 = name[i]
                name[i] = name[j]
                name[j] = t2
            }
    for (i in 0..n-1) println(name[i])
}


import java.util.Scanner
import java.util.Arrays
import java.util.*

fun main(args: Array<String>) {
    val (n) = readLine()!!.split(' ').map(String::toInt)
    val name = ArrayList<String>()
    val num = ArrayList<Int>()
    for (i in 1..n)
    {
        val (s, sa) = readLine()!!.split(' ').map(String::toString)
        var x = sa.toInt()
        name.add(s)
        num.add(x)
    }
    for (i in 0..n-1)
        for (j in i+1..n-1)
            if (num[i]>num[j])
            {
                val t1 = num[i]
                num[i] = num[j]
                num[j] = t1
                val t2 = name[i]
                name[i] = name[j]
                name[j] = t2
            }
    for (i in 0..n-1) println(name[i])
}


fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val a = arrayOfNulls<String>(5)
    val b = IntArray(n);
    for (i in 0..n - 1)
    {
        val(x, y) = readLine()!!.split(' ');
        a[i] = x;
        b[i] = y.toInt();
    }
    for (i in 0..n - 1)
    {
        for (j in 0 .. n - 2)
        {
            if (b[j] > b[j + 1])
            {
                val t = b[j];
                b[j] = b[j + 1];
                b[j + 1] = t;
                val c = a[j];
                a[j] = a[j + 1];
                a[j + 1] = c;
            }
        }
    }
    for (i in 0..n - 1)
    {
        println(a[i]);
    }
}


fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val a = arrayOfNulls<String>(n)
    val b = IntArray(n);
    for (i in 0..n - 1)
    {
        val(x, y) = readLine()!!.split(' ');
        a[i] = x;
        b[i] = y.toInt();
    }
    for (i in 0..n - 1)
    {
        for (j in 0 .. n - 2)
        {
            if (b[j] > b[j + 1])
            {
                val t = b[j];
                b[j] = b[j + 1];
                b[j + 1] = t;
                val c = a[j];
                a[j] = a[j + 1];
                a[j + 1] = c;
            }
        }
    }
    for (i in 0..n - 1)
    {
        println(a[i]);
    }
}


import kotlin.comparisons.*;
fun main(args: Array<String>) {
    val (n) = readLine()!!.split(' ').map(String::toInt)
    val arr = Array(n, {i -> readLine()!!.split(' ')})
    val arr2 =  arr.sortedWith(compareBy({it.component2().toString()}));
    for (i in arr2) {
        println(i.component1())
    }
}


fun main(args: Array<String>) {
    val (n) = readLine()!!.split(' ').map(String::toInt)
    val arr = Array(n, {i -> readLine()!!.split(' ')})
    for (i in 1..n) {
        for (j in 0..n) {
            if (j < n - 1 && arr.get(j).component2().toInt() > arr.get(j + 1).component2().toInt()) {
                val tmp = arr[j]
                arr[j] = arr[j + 1]
                arr[j + 1] = tmp
            }
        }
    }
    for (i in arr) {
        println(i.component1())
    }
}


/*
 * Language = Kotlin 0.7.270
 */

import java.io.*;
import java.util.*;

var LOCAL = File("input.txt").exists();

var _reader = when {
    LOCAL -> BufferedReader(FileReader("input.txt"));
    else -> BufferedReader(InputStreamReader(System.`in`));
}
var out = when {
    LOCAL -> PrintWriter("output.txt");
    else -> PrintWriter(System.`out`);
};
var _tokenizer = StringTokenizer("");

fun readString(): String {
    while (!_tokenizer.hasMoreTokens()) {
        _tokenizer = StringTokenizer(_reader.readLine()!!);
    }
    return _tokenizer.nextToken();
}

fun readInt(): Int {
    return java.lang.Integer.parseInt(readString());
}

fun readLong(): Long {
    return java.lang.Long.parseLong(readString());
}

fun readDouble(): Double {
    return java.lang.Double.parseDouble(readString());
}

fun debug(o: Any) {
    if (LOCAL) {
        System.`err`.println(o);
    }
}

fun main(args: Array<String>) {
    var t1: Long = 0;
    var t2: Long;
    if (LOCAL) {
        t1 = System.currentTimeMillis();
    };
    Locale.setDefault(Locale.US);
    solve();
    _reader.close();
    out.close();
    if (LOCAL) {
        t2 = System.currentTimeMillis();
        debug("Time = " + (t2 - t1));
    };
}

fun dfs(x: Int, p: Int, a: Array<ArrayList<Int>>, dp: IntArray, sumChildren: IntArray) {
    var cnt = 0;
    sumChildren[x] = 1;
    for (y in a[x]) {
        if (y != p) {
            cnt++;
            dfs(y, x, a, dp, sumChildren);
            sumChildren[x] += sumChildren[y];
        }
    }
    if (cnt == 0) {
        dp[x] = 0;
        return;
    }
    if (cnt == 1) {
        dp[x] = sumChildren[x] - 1;
        return;
    }
    var max1 = -100500;
    var max2 = -100500;
    var maxID1 = -1;
    var maxID2 = -1;
    for (y in a[x]) {
        if (y != p) {
            var t = sumChildren[y] - dp[y];
            if (t >= max1) {
                max2 = max1;
                max1 = t;
                maxID2 = maxID1;
                maxID1 = y;
            } else if (t >= max2) {
                max2 = t;
                maxID2 = y;
            }
        }
    }
    dp[x] = 0;
    for (y in a[x]) {
        if (y != p) {
            if (y == maxID1 || y == maxID2) {
                dp[x] += dp[y];
            } else {
                dp[x] += sumChildren[y];
            }
        }
    }
}

class Person(var name: String, var height: Int) : Comparable<Person> {
    override fun compareTo(other: Person): Int {
        return other.height - this.height;
    }
}

fun solve() {
    var n = readInt();
    var a = Array<Person>(n) {i -> Person(readString(), readInt())};
    a.sort();
    for (p in a) {
        out.println(p.name);
    }
//    var tests = readInt()
//    for (test in 1 .. tests) {
//        out.print("Case #${test}: ");
//        var n = readInt();
//        var a = Array<ArrayList<Int>>(n) { ArrayList() };
//        for (i in 1 .. n-1) {
//            var x = readInt() - 1;
//            var y = readInt() - 1;
//            a[x].add(y);
//            a[y].add(x);
//        }
//        var best = 100500;
//        var dp = IntArray(n);
//        var sumChildren = IntArray(n);
//        for (root in 0..n-1) {
//            dp.fill(100500);
//            sumChildren.fill(0);
//            dfs(root, -1, a, dp, sumChildren);
////            for (i in 0 .. n-1) {
////                if (dp[i] >= sumChildren[i]) {
////                    throw RuntimeException();
////                }
////            }
//            //debug(Arrays.toString(dp));
//            best = Math.min(best, dp[root]);
//        }
//        out.println(best);
//        System.`err`.println("Test ${test} completed");
//    }
}


/*
 * Language = Kotlin 0.7.270
 */

import java.io.*;
import java.util.*;

var LOCAL = File("input.txt").exists();

var _reader = when {
    LOCAL -> BufferedReader(FileReader("input.txt"));
    else -> BufferedReader(InputStreamReader(System.`in`));
}
var out = when {
    LOCAL -> PrintWriter("output.txt");
    else -> PrintWriter(System.`out`);
};
var _tokenizer = StringTokenizer("");

fun readString(): String {
    while (!_tokenizer.hasMoreTokens()) {
        _tokenizer = StringTokenizer(_reader.readLine()!!);
    }
    return _tokenizer.nextToken();
}

fun readInt(): Int {
    return java.lang.Integer.parseInt(readString());
}

fun readLong(): Long {
    return java.lang.Long.parseLong(readString());
}

fun readDouble(): Double {
    return java.lang.Double.parseDouble(readString());
}

fun debug(o: Any) {
    if (LOCAL) {
        System.`err`.println(o);
    }
}

fun main(args: Array<String>) {
    var t1: Long = 0;
    var t2: Long;
    if (LOCAL) {
        t1 = System.currentTimeMillis();
    };
    Locale.setDefault(Locale.US);
    solve();
    _reader.close();
    out.close();
    if (LOCAL) {
        t2 = System.currentTimeMillis();
        debug("Time = " + (t2 - t1));
    };
}

fun dfs(x: Int, p: Int, a: Array<ArrayList<Int>>, dp: IntArray, sumChildren: IntArray) {
    var cnt = 0;
    sumChildren[x] = 1;
    for (y in a[x]) {
        if (y != p) {
            cnt++;
            dfs(y, x, a, dp, sumChildren);
            sumChildren[x] += sumChildren[y];
        }
    }
    if (cnt == 0) {
        dp[x] = 0;
        return;
    }
    if (cnt == 1) {
        dp[x] = sumChildren[x] - 1;
        return;
    }
    var max1 = -100500;
    var max2 = -100500;
    var maxID1 = -1;
    var maxID2 = -1;
    for (y in a[x]) {
        if (y != p) {
            var t = sumChildren[y] - dp[y];
            if (t >= max1) {
                max2 = max1;
                max1 = t;
                maxID2 = maxID1;
                maxID1 = y;
            } else if (t >= max2) {
                max2 = t;
                maxID2 = y;
            }
        }
    }
    dp[x] = 0;
    for (y in a[x]) {
        if (y != p) {
            if (y == maxID1 || y == maxID2) {
                dp[x] += dp[y];
            } else {
                dp[x] += sumChildren[y];
            }
        }
    }
}

class Person(var name: String, var height: Int) : Comparable<Person> {
    override fun compareTo(other: Person): Int {
        return this.height - other.height;
    }
}

fun solve() {
    var n = readInt();
    var a = Array<Person>(n) {i -> Person(readString(), readInt())};
    a.sort();
    for (p in a) {
        out.println(p.name);
    }
//    var tests = readInt()
//    for (test in 1 .. tests) {
//        out.print("Case #${test}: ");
//        var n = readInt();
//        var a = Array<ArrayList<Int>>(n) { ArrayList() };
//        for (i in 1 .. n-1) {
//            var x = readInt() - 1;
//            var y = readInt() - 1;
//            a[x].add(y);
//            a[y].add(x);
//        }
//        var best = 100500;
//        var dp = IntArray(n);
//        var sumChildren = IntArray(n);
//        for (root in 0..n-1) {
//            dp.fill(100500);
//            sumChildren.fill(0);
//            dfs(root, -1, a, dp, sumChildren);
////            for (i in 0 .. n-1) {
////                if (dp[i] >= sumChildren[i]) {
////                    throw RuntimeException();
////                }
////            }
//            //debug(Arrays.toString(dp));
//            best = Math.min(best, dp[root]);
//        }
//        out.println(best);
//        System.`err`.println("Test ${test} completed");
//    }
}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val names : MutableList<String> = mutableListOf()
    val scores : MutableList<Int> = mutableListOf()

    for (i in 1..n) {
        val (x, y) = readLine()!!.split(' ')
        val score = y.toInt()
        names.add(x)
        scores.add(score)
    }

    for (i1 : Int in 1..n) {
        for (j1 : Int in (i1 + 1)..n) {
            if (i1 == j1)
                continue

            var i = i1 - 1
            var j = j1 - 1

            if (scores[i] > scores[j]) {
                val k1 = scores[i]
                scores[i] = scores[j]
                scores[j] = k1

                val k2 =  names[i]
                names[i] = names[j]
                names[j] = k2
            }
            i += 1
            j += 1
        }
    }

    for (t in names)
        println("$t")

}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val names : MutableList<String> = mutableListOf()
    val scores : MutableList<Int> = mutableListOf()

    for (i in 1..n) {
        val (x, y) = readLine()!!.split(' ')
        val score = y.toInt()
        names.add(x)
        scores.add(score)
    }

    for (i1 : Int in 1..n) {
        for (j1 : Int in (i1 + 1)..n) {
            if (i1 == j1)
                continue

            var i = i1 - 1
            var j = j1 - 1

            if (scores[i] > scores[j]) {
                val k1 = scores[i]
                scores[i] = scores[j]
                scores[j] = k1

                val k2 =  names[i]
                names[i] = names[j]
                names[j] = k2
            }
            i += 1
            j += 1
        }
    }

    for (t in names)
        print("$t ")

}


import java.util.*

fun main(args: Array<String>) {

    val scan = Scanner(System.`in`)
    val n = scan.nextInt()
    val names = Array(n, {i -> ""})
    val heights = Array(n, {i -> 0})
    for (i in 0..n - 1) {
        names[i] = scan.next()
        heights[i] = scan.nextInt()
    }
    for (i in 0..n - 2) {
        var max = heights[i]
        var pos = i
        for (j in i + 1..n - 1) {
            if (heights[j] > max) {
                max = heights[j]
                pos = j
            }
        }
        val temp = names[pos]
        names[pos] = names[i]
        names[i] = temp
        heights[pos] = heights[i]
        heights[i] = max
    }
    for (i in 0..n-1) {
        println(names[i] + " " + heights[i])
    }
}


import java.util.*

fun main(args: Array<String>) {

    val scan = Scanner(System.`in`)
    val n = scan.nextInt()
    val names = Array(n, {i -> ""})
    val heights = Array(n, {i -> 0})
    for (i in 0..n - 1) {
        names[i] = scan.next()
        heights[i] = scan.nextInt()
    }
    for (i in 0..n - 2) {
        var min = heights[i]
        var pos = i
        for (j in i + 1..n - 1) {
            if (heights[j] < min) {
                min = heights[j]
                pos = j
            }
        }
        val temp = names[pos]
        names[pos] = names[i]
        names[i] = temp
        heights[pos] = heights[i]
        heights[i] = min
    }
    for (i in 0..n-1) {
        println(names[i])
    }
}


import java.util.*

fun main(args: Array<String>) {

    val scan = Scanner(System.`in`)
    val n = scan.nextInt()
    val names = Array(n, {i -> ""})
    val heights = Array(n, {i -> 0})
    for (i in 0..n - 1) {
        names[i] = scan.next()
        heights[i] = scan.nextInt()
    }
    for (i in 0..n - 2) {
        var max = heights[i]
        var pos = i
        for (j in i + 1..n - 1) {
            if (heights[j] > max) {
                max = heights[j]
                pos = j
            }
        }
        val temp = names[pos]
        names[pos] = names[i]
        names[i] = temp
        heights[pos] = heights[i]
        heights[i] = max
    }
    for (i in 0..n-1) {
        println(names[i])
    }
}


fun main(args: Array<String>) {
    val map: MutableList<Pair<Int, String>> = mutableListOf()

    val N = (readLine() as String).toInt()

    for (i in 1..N) {
        val s = (readLine() as String).split(' ')
        val p: Pair<Int, String> = Pair(s[1].toInt(), s[0])
        map.add(p)
    }

    for (o in map.sortedBy { it.first })
        println(o.second)

}


fun main(args: Array<String>) {

val map = hashMapOf<String, String>()
var (n) = readLine()!!.split(' ').map(String::toInt)
var m = n
while(n>0){
val (x, y) = readLine()!!.split(' ').map(String::toString)
map.put(y,x)
n--
}
for((p,q) in map){
println(q)
}

}


fun main(args: Array<String>) {

	var (n) = readLine()!!.split(' ').map(String::toInt)
	var m = n
	var s = arrayListOf<String>()
	var a = arrayListOf<String>()
	var mark = arrayListOf<Int>()
	for(i in 1..n){
		mark.add(0)
		val (x, y) = readLine()!!.split(' ').map(String::toString)
		a.add(y)
		s.add(x)
	}
	while(m>0){
		var mx = "1"
		var po = 1
		for(j in a.indices){
			if(mark[j] == 0){
				mx = a[j]
				po = j
			}
		}
		for(j in a.indices){
			if(mark[j] == 0){
				if(a[j]<mx){
					mx = a[j]
					po = j
				}
			}
		}
		mark[po] = 1
		println(s[po])
		m--
	}

}


fun main(args: Array<String>) {
    val pupils = mutableListOf<Pupil>()

    val n = readLine()!!.toInt()
    for (i in 1..n) {
        val (name, height) = readLine()!!.split(' ')
        pupils.add(Pupil(name, height.toInt()))
    }

    pupils.sortBy{p -> p.height}

    for (p in pupils) {
        println(p.name)
    }
}

data class Pupil(val name: String, val height: Int)


import java.util.*
import kotlin.comparisons.compareBy

fun main(args: Array<String>) {
    val inp = Scanner(System.`in`)
    val n = inp.nextInt()
    val list: MutableList<Human> = LinkedList()

    for(i in 1..n) {
        val name = inp.next()
        val height = inp.nextInt()
        list.add(Human(name, height))
    }
    list.sortedWith(compareBy { it.height }).forEach { println(it.name) }
}

data class Human(val name: String, val height: Int)


public fun main(args: Array<String>){
    val numLines = readLine()!!.toInt()
    var pupils : MutableMap<Int, List<String>> = hashMapOf()
    for(x in 0..numLines){
        var (name, h) = readLine()!!.split(' ')
        var height = h.toInt()
        var hasSameHeight = pupils.get(height)
        hasSameHeight = hasSameHeight?.plus(name) ?: listOf(name)
        pupils.put(height, hasSameHeight)
    }
    pupils.keys.forEach {
        var names = pupils.get(it)
        names?.forEach {
            print(it)
        }
    }
}


public fun main(args: Array<String>){
    val numLines = readLine()!!.toInt()
    var pupils : MutableMap<Int, List<String>> = hashMapOf()
    for(x in 1..numLines){
        var (name, h) = readLine()!!.split(' ')
        var height = h.toInt()
        var hasSameHeight = pupils.get(height)
        hasSameHeight = hasSameHeight?.plus(name) ?: listOf(name)
        pupils.put(height, hasSameHeight)
    }
    pupils.keys.forEach {
        var names = pupils.get(it)
        names?.forEach {
            println(it)
        }
    }
}


public fun main(args: Array<String>){
    val numLines = readLine()!!.toInt()
    var pupils : MutableMap<Int, List<String>> = hashMapOf()
    for(x in 1..numLines){
        var (name, h) = readLine()!!.split(' ')
        var height = h.toInt()
        var hasSameHeight = pupils.get(height)
        hasSameHeight = hasSameHeight?.plus(name) ?: listOf(name)
        pupils.put(height, hasSameHeight)
    }
    pupils.keys.sorted().forEach {
        var names = pupils.get(it)
        names?.forEach {
            println(it)
        }
    }
}


public fun main(args: Array<String>){
    val numLines = readLine()!!.toInt()
    var pupils : MutableMap<Int, List<String>> = hashMapOf()
    for(x in 1..numLines){
        var (name, h) = readLine()!!.split(' ')
        var height = h.toInt()
        var hasSameHeight = pupils.get(height)
        hasSameHeight = hasSameHeight?.plus(name) ?: listOf(name)
        pupils.put(height, hasSameHeight)
    }
    pupils.keys.forEach {
        var names = pupils.get(it)
        names?.forEach {
            print(it)
        }
    }
}


import java.util.*

/**
 * Created by Shakhov on 16.06.2016.
 */

fun main(args: Array<String>) {
    var l1: List<Int> = readLine()!!.split(' ').map(String::toInt)
    var l2: List<Int> = readLine()!!.split(' ').map(String::toInt)

    var l3: List<Int> = l1.filter { it -> !l2.contains(it) }
    var l4: List<Int> = l2.filter { it -> !l1.contains(it) }

    var l5 = l3 + l4

    print(l5.size())
    for (n in l5) {
        print(" " + n)
    }

}


import java.util.*

fun main(args: Array<String>) {
    var l1: List<Int> = readLine()!!.split(' ').map(String::toInt)
    var l2: List<Int> = readLine()!!.split(' ').map(String::toInt)

    l1 = l1.filter { t -> l1.indexOf(t) > 0 }
    l2 = l2.filter { t -> l2.indexOf(t) > 0 }

    var l3: List<Int> = l1.filter { it -> !l2.contains(it)}
    var l4: List<Int> = l2.filter { it -> !l1.contains(it)}

    var l5 = l3 + l4

    l5 = l5.sort();

    print(l5.size)
    for (t in l5) {
        print(" " + t)
    }

}


import java.util.*

fun main(args: Array<String>) {
    var l1: List<Int> = readLine()!!.split(' ').map(String::toInt)
    var l2: List<Int> = readLine()!!.split(' ').map(String::toInt)

    var l3: List<Int> = l1.filter { it -> !l2.contains(it) }
    var l4: List<Int> = l2.filter { it -> !l1.contains(it) }

    var l5 = l3 + l4

    print(l5.size())
    for (t in l5) {
        print(" " + t)
    }

}


import java.util.*

fun main(args: Array<String>) {
    var l1: List<Int> = readLine()!!.split(' ').map(String::toInt)
    var l2: List<Int> = readLine()!!.split(' ').map(String::toInt)

    var l3: List<Int> = l1.filter { it -> !l2.contains(it) }
    var l4: List<Int> = l2.filter { it -> !l1.contains(it) }

    var l5 = l3 + l4

    print(l5.size)
    for (t in l5) {
        print(" " + t)
    }

}


import java.util.*

fun main(args: Array<String>) {
    var l1: List<Int> = readLine()!!.split(' ').map(String::toInt)
    var l2: List<Int> = readLine()!!.split(' ').map(String::toInt)

    l1 = l1.subList(1, l1.size())
    l2 = l2.subList(1, l2.size())

    var l3: List<Int> = l1.filter { it -> !l2.contains(it)}
    var l4: List<Int> = l2.filter { it -> !l1.contains(it)}

    var l5 = l3 + l4

    Collections.sort(l5);

    print(l5.size)
    for (t in l5) {
        print(" " + t)
    }

}


import java.util.*

fun main(args: Array<String>) {
    var l1: List<Int> = readLine()!!.split(' ').map(String::toInt)
    var l2: List<Int> = readLine()!!.split(' ').map(String::toInt)

    l1 = l1.subList(1, l1.size)
    l2 = l2.subList(1, l2.size)

    var l3: List<Int> = l1.filter { it -> !l2.contains(it)}
    var l4: List<Int> = l2.filter { it -> !l1.contains(it)}

    var l5 = l3 + l4

    Collections.sort(l5);

    print(l5.size)
    for (t in l5) {
        print(" " + t)
    }

}


import java.util.*

fun main(args: Array<String>) {
    var l1: List<Int> = readLine()!!.split(' ').map(String::toInt)
    var l2: List<Int> = readLine()!!.split(' ').map(String::toInt)

    l1 = l1.filter { t -> l1.indexOf(t) > 0 }
    l2 = l2.filter { t -> l2.indexOf(t) > 0 }

    var l3: List<Int> = l1.filter { it -> !l2.contains(it)}
    var l4: List<Int> = l2.filter { it -> !l1.contains(it)}

    var l5 = l3 + l4

    Collections.sort(l5);

    print(l5.size)
    for (t in l5) {
        print(" " + t)
    }

}


fun main(args: Array<String>) {

    val A = readLine()!!.split(' ')
    val B = readLine()!!.split(' ')
    val ans = Array(A.size, {i -> i})

    var idx = 0
    for (i in A.indices) {
        if (i == 0) { continue; }
        var found = false
        for (j in B.indices) {
            if (j == 0) { continue; }
            if (A[i].toInt() == B[j].toInt()) {
                found = true
                break
            }
        }
        if (!found) {
            ans[idx++] = A[i].toInt()
        }
    }
    for (i in B.indices) {
        if (i == 0) { continue; }
        var found = false
        for (j in A.indices) {
            if (j == 0) { continue; }
            if (B[i].toInt() == A[j].toInt()) {
                found = true
                break
            }
        }
        if (!found) {
            ans[idx++] = B[i].toInt()
        }
    }

    print(idx)
    for (i in ans.indices) {
        if (i < idx) {
            print(" " + ans[i])
        }
    }

}


fun main(args: Array<String>) {

    val A = readLine()!!.split(' ')
    val B = readLine()!!.split(' ')
    val ans = Array(A.size + B.size + 5, {i -> i})

    var idx = 0
    for (i in A.indices) {
        if (i == 0) { continue; }
        var found = false
        for (j in B.indices) {
            if (j == 0) { continue; }
            if (A[i].toInt() == B[j].toInt()) {
                found = true
                break
            }
        }
        if (!found) {
            ans[idx++] = A[i].toInt()
        }
    }
    for (i in B.indices) {
        if (i == 0) { continue; }
        var found = false
        for (j in A.indices) {
            if (j == 0) { continue; }
            if (B[i].toInt() == A[j].toInt()) {
                found = true
                break
            }
        }
        if (!found) {
            ans[idx++] = B[i].toInt()
        }
    }

    print(idx)
    for (i in ans.indices) {
        if (i < idx) {
            print(" " + ans[i])
        }
    }
}


fun main(args: Array<String>) {
    val p1=readLine()!!.split(' ')
    val q1=readLine()!!.split(' ')
    val n=p1[0]!!.toInt()
    val m=q1[0]!!.toInt()
    var i:Int
    var j:Int
    val p=Array(1007,{i -> 0})
    val q=Array(1007,{i -> 0})
    i=0
    while (i<n) {
        p[i]=p1[i+1]!!.toInt()
        i++
    }
    i=0
    while (i<m) {
        q[i]=q1[i+1]!!.toInt()
        i++
    }
    i=0
    while (i<m) {
        j=i+1
        while (j<m) {
            if (q[j]<q[i]) {
                var tmp=q[i]
                q[i]=q[j]
                q[j]=tmp

            }
            j++
        }
        i++
    }
    i=0
    while (i<n) {
        j=i+1
        while (j<n) {
            if (p[j]<p[i]) {
                var tmp=p[i]
                p[i]=p[j]
                p[j]=tmp

            }
            j++
        }
        i++
    }
    i=0
    j=0
    var k:Int
    k=0
    val b=Array(2007,{i -> 0})
    q[m]=10000
    p[n]=10000
    while (i<n||j<m) {
        if (p[i]<q[j]) {
            b[k]=p[i]
            k++
            i++
        }
        else if (p[i]>q[j]) {
            b[k]=q[j]
            k++
            j++
        }
        else {
            i++
            j++
        }
    }
    i=0
    print(k)
    while (i<k) {
        print(" ")
        print(b[i])
        i++
    }
    println("")
}


fun main(args: Array<String>) {
    val p1=readLine()!!.split(' ')
    val q1=readLine()!!.split(' ')
    val n=p1.count()-1
    val m=q1.count()-1
    var i:Int
    var j:Int
    val p=Array(1007,{i -> 0})
    val q=Array(1007,{i -> 0})
    i=0
    while (i<n) {
        p[i]=p1[i+1]!!.toInt()
        i++
    }
    i=0
    while (i<m) {
        q[i]=q1[i+1]!!.toInt()
        i++
    }
    i=0
    while (i<m) {
        j=i+1
        while (j<m) {
            if (q[j]<q[i]) {
                var tmp=q[i]
                q[i]=q[j]
                q[j]=tmp

            }
            j++
        }
        i++
    }
    i=0
    while (i<m) {
        j=i+1
        while (j<m) {
            if (p[j]<p[i]) {
                var tmp=p[i]
                p[i]=p[j]
                p[j]=tmp

            }
            j++
        }
        i++
    }
    i=0
    j=0
    var k:Int
    k=0
    val b=Array(2007,{i -> 0})
    q[m]=1000000
    p[n]=1000000
    while (i<n||j<m) {
        if (p[i]<q[j]) {
            b[k]=p[i]
            k++
            i++
        }
        else if (p[i]>q[j]) {
            b[k]=q[j]
            k++
            j++
        }
        else {
            i++
            j++
        }
    }
    i=0
    print(k)
    while (i<k) {
        print(" ")
        print(b[i])
        i++
    }
    println("")
}


fun main(args: Array<String>) {
    val p1=readLine()!!.split(' ')
    val q1=readLine()!!.split(' ')
    val n=p1[0]!!.toInt()
    val m=q1[0]!!.toInt()
    var i:Int
    var j:Int
    val p=Array(1007,{i -> 0})
    val q=Array(1007,{i -> 0})
    i=0
    while (i<n) {
        p[i]=p1[i+1]!!.toInt()
        i++
    }
    i=0
    while (i<m) {
        q[i]=q1[i+1]!!.toInt()
        i++
    }
    i=0
    while (i<m) {
        j=i+1
        while (j<m) {
            if (q[j]<q[i]) {
                var tmp=q[i]
                q[i]=q[j]
                q[j]=tmp

            }
            j++
        }
        i++
    }
    i=0
    while (i<m) {
        j=i+1
        while (j<m) {
            if (p[j]<p[i]) {
                var tmp=p[i]
                p[i]=p[j]
                p[j]=tmp

            }
            j++
        }
        i++
    }
    i=0
    j=0
    var k:Int
    k=0
    val b=Array(2007,{i -> 0})
    q[m]=1000000
    p[n]=1000000
    while (i<n||j<m) {
        if (p[i]<q[j]) {
            b[k]=p[i]
            k++
            i++
        }
        else if (p[i]>q[j]) {
            b[k]=q[j]
            k++
            j++
        }
        else {
            i++
            j++
        }
    }
    i=0
    print(k)
    while (i<k) {
        print(" ")
        print(b[i])
        i++
    }
    println("")
}


fun readset():List<Int> = readLine()!!.split(' ').map(String::toInt).drop(1)

fun main(args: Array<String>) {
	val a=readset()
	val b=readset()
	val c=a.union(b).minus(a.intersect(b))
	print(c.size)
	for(x in c.sorted()) print(" $x")
	println()
}


/**
 * Created by vovka on 6/16/16.
 */
import java.util.Scanner
import java.util.Arrays

fun main(args: Array<String>) {
    var row1 = readLine()!!.split(' ').map(String::toInt)
    var row2 = readLine()!!.split(' ').map(String::toInt)

    row1 = row1.drop(1)
    row2 = row2.drop(1)

    val s1 = row1.toSet()
    val s2 = row2.toSet()

    val d1 = s1.minus(s2)
    val d2 = s2.minus(s1)

    val r = d1.union(d2).toList()

    print(r.size)
    for (v in r) {
        print(" ")
        print(v)
    }

}


fun main(args: Array<String>) {
    val _a = readLine()!!.split(' ').map(String::toInt)
    val a = _a.slice(1.._a[0])

    val _b = readLine()!!.split(' ').map(String::toInt)
    val b = _b.slice(1.._b[0])

    var cur = 0;
    val ans = Array(2000, {i -> -1111} )
    for(i in a)
    {
    if(!(i in b) && !(i in ans)){
        ans[cur] = i
        cur = cur + 1
        }
    }
     for(i in b)
    {
    if(!(i in a) && !(i in ans)){
        ans[cur] = i
        cur = cur + 1
        }
    }
    print("${cur} ")
    for(i in 0..cur-1){
    print("${ans[i]} ")
    }
}


fun main(args: Array<String>) {
    val _a = readLine()!!.split(' ').map(String::toInt)
    val a = _a.slice(1.._a[0]-1)
    val _b = readLine()!!.split(' ').map(String::toInt)
    val b = _b.slice(1.._b[0]-1)
    var cur = 0;
    val ans = Array(2000, {i -> -1111} )
    for(i in a)
    {
    if(!(i in b) && !(i in ans)){
        ans[cur] = i
        cur = cur + 1
        }
    }
     for(i in b)
    {
    if(!(i in a) && !(i in ans)){
        ans[cur] = i
        cur = cur + 1
        }
    }
    print("${cur} ")
    for(i in 0..cur-1){
    print("${ans[i]} ")
    }
}


fun main(args: Array<String>) {
    val a = readLine()!!.split(' ').map(String::toInt)
    val b = readLine()!!.split(' ').map(String::toInt)
    val cur = 0;
    val ans = Array(2000, {i -> -1111} )
    for(i in a)
    {
    if(!(i in b) && !(i in ans))
        ans[cur] = i
        cur = cur + 1
    }
     for(i in b)
    {
    if(!(i in a) && !(i in ans))
        ans[cur] = i
        cur = cur + 1
    }
    print("${cur) ")
    for(i in 0..cur-1){
    print("${i} ")
    }
}


fun main(args: Array<String>) {
    val a = readLine()!!.split(' ').map(String::toInt)
    val b = readLine()!!.split(' ').map(String::toInt)
    var cur = 0;
    val ans = Array(2000, {i -> -1111} )
    for(i in a)
    {
    if(!(i in b) && !(i in ans)){
        ans[cur] = i
        cur = cur + 1
        }
    }
     for(i in b)
    {
    if(!(i in a) && !(i in ans)){
        ans[cur] = i
        cur = cur + 1
        }
    }
    print("${cur} ")
    for(i in 0..cur-1){
    print("${ans[i]} ")
    }
}