Problem:
Problem
りりあちゃんは夢の国にて繁盛している、とある服屋さんのエンジニアです。
ある日、$n$ 人のお得意さまが着る服のサイズを纏めたリストがHDDの故障によって消失してしまいました。りりあちゃんはお偉いさんにデータの保全責任を問われ、早急にリストを復旧しなければなりません。
えらく怒られたりりあちゃんは職を失い路頭に迷う危機の中、残っているファイルを血眼になって調べたところ、なんとお得意さま一人一人の身長と体重が纏められたファイルを発見しました。
$k$ 番目のお得意さまの名前は $s_k$ で表され、$s_k$ さんの身長と体重は $a_k,b_k$ で表されます。
そして、りりあちゃんが勤める服屋さんでは身長の区分を表す長さ $h$ の数列 $p$ と体重の区分を表す長さ $w$ の数列 $q$ を服のサイズに対応させた表が用意されています。具体的には
$p_1, \ldots, p_h$ に加え、$p_0=0,p_{h+1}=200$ としたときに、$p_{x-1} \le a_k$ かつ $a_k \lt p_x$
$q_1, \ldots, q_w$ に加え、$q_0=0,q_{w+1}=100$ としたときに、$q_{y-1} \le b_k$ かつ $b_k \lt q_y$
を満たすような $x,y$ に対し $c_{x,y}$ が $s_k$ さんの服のサイズです。服のサイズは'S','M','L','X'のみで表されます。
つまり、これらの情報を組み合わせることでお得意さまが着る服のサイズを纏めたリストを復旧できるということです。りりあちゃんはエンジニアの能力を活かし、身長と体重が纏められたファイルと身長と体重を服のサイズに対応させた表を用い、お得意さまが着る服のサイズを纏めたリストを出力するプログラムを作成することにしました。
Input
入力は以下の形式で与えられます。
$n\ h\ w$
$p_1 \cdots p_h$
$q_1 \cdots q_w$
$c_{1,1} \cdots c_{1,w+1}$
$\vdots$
$c_{h+1,1} \cdots c_{h+1,w+1}$
$s_1\ a_1\ b_1$
$\vdots$
$s_n\ a_n\ b_n$
Constraints
入力は以下の条件を満たします。
$1 \le n \le 5 \times 10^4$
$1 \le h,w \le 10^6$
$1 \le h \times w \le 10^6$
$n,h,w$ は整数
$100 \le p_i \lt 200$
$10 \le q_j \lt 100$
$p_i \lt p_{i+1}\ (1 \le i \lt h)$
$q_j \lt q_{j+1}\ (1 \le j \lt w)$
$c_{i,j} \in \{$'S','M','L','X'$\}$
$s_k$ は小文字のアルファベットからなる $1$ 文字以上 $20$ 文字以下の文字列
$100 \le a_k \lt 200$
$10 \le b_k \lt 100$
$p_i,q_j,a_k,b_k$ は、ちょうど小数第五位まで与えられた小数
Output
以下の形式で出力してください。
S:[サイズがSの服を着るお得意さまのリスト]
M:[サイズがMの服を着るお得意さまのリスト]
L:[サイズがLの服を着るお得意さまのリスト]
X:[サイズがXの服を着るお得意さまのリスト]
角括弧で囲まれる各お得意さまのリストでは、各サイズの服を着るお得意さま全員の名前を、辞書順にソートされた状態で空白区切りで出力してください。また、各お得意さまのリストの先頭には空白を入れてください。もし、お得意さまのリストで出力する名前がなかった場合、その行ではサイズとコロン以外何も出力せず改行してください。
Sample Input 1
5 3 3
150.00000 160.00000 170.00000
55.00000 65.00000 75.00000
X S M L
S M L L
M L L X
L L X X
u 157.00000 58.50000
ku 172.00000 75.00000
ni 148.00000 85.00000
chi 164.00000 67.40000
a 155.00000 56.80000
Sample Output 1
S:
M: a u
L: chi ni
X: ku
名前は辞書順にソートされて出力される必要があります。サイズが'S'の服を着るお得意さまはいないため、その行ではサイズとコロン以外何も出力せず改行されています。
Sample Input 2
5 2 3
100.00000 199.99999
10.00000 50.00000 99.99999
X M S L
S X L M
X S M L
pancake 199.99999 99.99999
marshmallow 100.00000 10.00000
macaron 199.99999 50.00000
eclair 100.00000 99.99999
pudding 199.99999 10.00000
Sample Output 2
S: pudding
M: eclair macaron
L: pancake
X: marshmallow
Sample Input 3
2 1 1
150.00000
50.00000
X X
X X
beet 100.00000 10.00000
beet 199.99999 99.99999
Sample Output 3
S:
M:
L:
X: beet beet

Submitted solutions:

code_snippet: // AOJ #3078 Classification of Clothing
// 2025.2.22

#include <bits/stdc++.h>
using namespace std;

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char temp[100];
string Cins() { // 文字列の入力　スペース以下の文字で入力終了
    char *s = temp;
	do *s = gc();
	while (*s++ > ' ');
	*(s-1) = 0;
    string input(temp); // 文字配列からstringを作成
    return input;
}

void Cout(int n) { // 整数の表示（出力）
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

double Cinf() {    // 実数の入力
	int minus = 0;
	double x, y;
	int n = 0, c = gc();
	if (c == '-') minus = 1, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');

	if (c == '.') {
		x = 0;
		y = 1, c = gc();
		do y *= 0.1, x += y * (c & 0xf), c = gc(); while (c >= '0');
		x += n;
	} else x = n;
	if (minus) x = -x;
	return x;
}

void Couts(const string &s) {
    for (char c : s) pc(c);
}

int main() {
    int n = Cin(), h = Cin(), w = Cin();

    vector<double> p(h+2);
    p[0] = 0.0;
    for (int i = 1; i <= h; i++) p[i] = Cinf();
    p[h+1] = 200.0;

    vector<double> q(w+2);
    q[0] = 0.0;
    for (int j = 1; j <= w; j++) q[j] = Cinf();
    q[w+1] = 100.0;

    vector<vector<char>> siz(h+2, vector<char>(w+2));
    for (int i = 1; i <= h+1; i++){
        for (int j = 1; j <= w+1; j++) siz[i][j] = gc(), gc();
    }

    vector<string> S, M, L, X;
    for (int i = 0; i < n; i++){
        string name = Cins();
        double a = Cinf(), b = Cinf();

        int x = upper_bound(p.begin(), p.end(), a) - p.begin();
        int y = upper_bound(q.begin(), q.end(), b) - q.begin();

        char s = siz[x][y];
        if     (s == 'S') S.push_back(name);
        else if(s == 'M') M.push_back(name);
        else if(s == 'L') L.push_back(name);
        else if(s == 'X') X.push_back(name);
    }

    sort(S.begin(), S.end());
    sort(M.begin(), M.end());
    sort(L.begin(), L.end());
    sort(X.begin(), X.end());

    auto pr = [&](char size, const vector<string>& names){
        pc(size), pc(':');
        if(!names.empty()){
            pc(' ');
            for (int i = 0; i < (int)names.size(); i++){
                Couts(names[i]);
                if (i+1 < names.size()) pc(' ');
            }
        }
        pc('\n');
    };

    pr('S', S);
    pr('M', M);
    pr('L', L);
    pr('X', X);
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 67536
final_rank: 3

code_snippet: // AOJ #3078 Classification of Clothing
// 2025.2.22

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, h, w;
    cin >> n >> h >> w;

    vector<double> p(h+2);
    p[0] = 0.0;
    for (int i = 1; i <= h; i++) cin >> p[i];
    p[h+1] = 200.0;

    vector<double> q(w+2);
    q[0] = 0.0;
    for (int j = 1; j <= w; j++) cin >> q[j];
    q[w+1] = 100.0;

    vector<vector<char>> siz(h+2, vector<char>(w+2));
    for (int i = 1; i <= h+1; i++){
        for (int j = 1; j <= w+1; j++) cin >> siz[i][j];
    }

    vector<string> S, M, L, X;
    for (int i = 0; i < n; i++){
        string name;
        double a, b;
        cin >> name >> a >> b;

        int x = upper_bound(p.begin(), p.end(), a) - p.begin();
        int y = upper_bound(q.begin(), q.end(), b) - q.begin();

        char sizeLetter = siz[x][y];
        if     (sizeLetter == 'S') S.push_back(name);
        else if(sizeLetter == 'M') M.push_back(name);
        else if(sizeLetter == 'L') L.push_back(name);
        else if(sizeLetter == 'X') X.push_back(name);
    }

    sort(S.begin(), S.end());
    sort(M.begin(), M.end());
    sort(L.begin(), L.end());
    sort(X.begin(), X.end());

    auto printList = [&](char size, const vector<string>& names){
        cout << size << ":";
        if(!names.empty()){
            cout << " ";
            for (size_t i = 0; i < names.size(); i++){
                cout << names[i] << (i+1 < names.size() ? " " : "");
            }
        }
        cout << endl;
    };

    printList('S', S);
    printList('M', M);
    printList('L', L);
    printList('X', X);
    return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 67644
final_rank: 12

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 3078.cc: Classification of Clothing
 */

#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_H = 1000000;
const int MAX_W = 1000000;
const int MAX_HW = 1000000;

const char szs[] = "SMLX";

/* typedef */

typedef vector<string> vstr;
typedef vector<int> vi;
typedef vector<vi> vvi;

/* global variables */

double ps[MAX_H], qs[MAX_W];
vstr svs[4];

/* subroutines */

int sz2i(char c) {
  return (c == 'S') ? 0 : (c == 'M') ? 1 : (c == 'L') ? 2 : 3;
}

/* main */

int main() {
  int n, h, w;
  scanf("%d%d%d", &n, &h, &w);
  int hw = h * w;

  for (int i = 0; i < h; i++) scanf("%lf", ps + i);
  for (int i = 0; i < w; i++) scanf("%lf", qs + i);

  vvi cs(h + 1, vi(w + 1));
  for (int i = 0; i <= h; i++)
    for (int j = 0; j <= w; j++) {
      char s[4];
      scanf("%s", s);
      cs[i][j] = sz2i(s[0]);
    }

  for (int i = 0; i < n; i++) {
    char si[32];
    double ai, bi;
    scanf("%s%lf%lf", si, &ai, &bi);

    int y = upper_bound(ps, ps + h, ai) - ps;
    int x = upper_bound(qs, qs + w, bi) - qs;
    svs[cs[y][x]].push_back(string(si));
  }

  for (int i = 0; i < 4; i++) {
    sort(svs[i].begin(), svs[i].end());

    printf("%c:", szs[i]);
    for (auto &s: svs[i]) printf(" %s", s.c_str());
    putchar('\n');
  }

  return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 68824
final_rank: 10

code_snippet: #include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

map<double,int> mhs;
map<double,int> mws;
map<string,int> ks;
map<int,string> ksr;
vector<vector<int> > vs;
map<string,vector<string> > hs;


int main() {
	int n,h,w;
	cin>>n>>h>>w;
	for(int i=1;i<=h;i++){
		double d;
		cin>>d;
		mhs[d]=i;
	}
	mhs[0]=0;
	
	for(int i=1;i<=w;i++){
		double d;
		cin>>d;
		mws[d]=i;
	}
	mws[0]=0;
	
	string strs[4]={"S","M","L","X"};
	for(int i=0;i<4;i++){
		ks[ strs[i]]=i;
		ksr[i]=strs[i];
	}
	
	for(int i=0;i<=h;i++){
		vector<int> vs2;
		vs.push_back(vs2);
		for(int j=0;j<=w;j++){
			string str;
			cin>>str;
			vs[i].push_back(ks[str]);
		}
	}
	map<double,int>::iterator it1,it2;
	//for(it1=mhs.begin();it1!=mhs.end();it1++){
	//	cout<<"("<<(*it1).first<<","<<(*it1).second<<")";
	//}
	//cout<<endl;
	for(int i=0;i<n;i++){
		string str;
		double h1,w1;
		cin>>str>>h1>>w1;
		//cout<<str<<" "<<h1<<" "<<w1<<endl;
		it1=mhs.upper_bound(h1);
		if(it1!=mhs.begin())it1--;
		int p1=(*it1).second;
		it2=mws.upper_bound(w1);
		if(it2!=mws.begin())it2--;
		int p2=(*it2).second;
		int p3=vs[p1][p2];
		hs[ksr[p3]].push_back(str);
	}
	for(int i=0;i<4;i++){
		vector<string> vs3=hs[strs[i]];
		cout<<strs[i]<<":";
		if (vs3.size()>0){
			sort(vs3.begin(),vs3.end());
			for(int j=0;j<vs3.size();j++){
				cout<<" "<<vs3[j];
			}
		}
		cout<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 1240
memory_kb: 123632
final_rank: 20

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <map>

namespace {
    using namespace std;

    template<typename T>
    istream& operator>>(istream& is, vector<T>& vs) {
        for (auto&& v : vs) {
            is >> v;
        }
        return is;
    }

    template<typename T>
    ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os;
        os << vs[0];
        auto it = ++vs.begin();
        for (; it != vs.end(); ++it) {
            os << ' ' << *it;
        }
        return os;
    }
    
    template<typename T>
    ostream& operator<<(ostream& os, const vector<vector<T>>& vs) {
        if (vs.empty()) return os;
        os << vs[0];
        auto it = ++vs.begin();
        for (; it != vs.end(); ++it) {
            os << '\n' << *it;
        }
        return os;
    }

    int N, H, W;
    vector<double> P, Q;
    vector<vector<string>> C;
    vector<string> S;
    vector<double> A, B;
    void input() {
        cin >> N >> H >> W;
        P = vector<double>(H, -1);
        Q = vector<double>(W, -1);
        C = vector<vector<string>>(H+1, vector<string>(W+1));
        cin >> P; P.insert(P.begin(), 0.0); P.insert(P.end(), 200.0);
        cin >> Q; Q.insert(Q.begin(), 0.0); Q.insert(Q.end(), 200.0);
        cin >> C;
        S = vector<string>(N);
        A = vector<double>(N, -1);
        B = vector<double>(N, -1);
        for (int i = 0; i < N; i++) {
            cin >> S[i] >> A[i] >> B[i];
        }
    }


    int lookup_index(const vector<double>& P, double a) {
        int lb = 0, ub = P.size();
        while (lb + 1 < ub) {
            auto mid = lb + (ub - lb) / 2;
            if (P[mid] <= a) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return lb;
    }

    void solve() {
        map<string, vector<string>> M;
        for (int i = 0; i < N; i++) {
            int h = lookup_index(P, A[i]);
            int w = lookup_index(Q, B[i]);
            string size_key = C[h][w];
            M[size_key].push_back(S[i]);
        }
        auto ks = vector<string>({"S", "M", "L", "X"});
        for (auto&& k : ks) {
            cout << k << ":";
            auto output = M[k];
            sort(output.begin(), output.end());
            if (output.empty()) {
                cout << endl;
            } else {
                cout << ' ';
                cout << output << endl;
            }
        }
    }
}

int main() {
    input(); 
    solve();
    return 0;
}
accuracy: 1
time_ms: 640
memory_kb: 121764
final_rank: 19

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

vector<string> split_naive(const string &s,char delim) {
	vector<string> elems;
	string item;
	for(char ch:s){
		if(ch==delim){
			if(!item.empty()) elems.push_back(item);
			item.clear();
		}
		else{
			item += ch;
		}
	}
	if(!item.empty()) elems.push_back(item);
	return elems;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in(),H=in(),W=in();
	vector<double> P(1,0),Q(1,0);
	REP(i,H) P.push_back(in<double>());
	REP(i,W) Q.push_back(in<double>());
	P.push_back(200);
	Q.push_back(100);
	vector<vector<char>> C(H+1,vector<char>(W+1));
	REP(i,H+1){
		REP(j,W+1) C[i][j]=in<char>();
	}
	vector<vector<string>> M(4);
	map<char,int> T;
	T['S']=0;
	T['M']=1;
	T['L']=2;
	T['X']=3;

	REP(i,N){
		string S=in<string>();
		double p=in<double>(),q=in<double>();

		auto pp = upper_bound(ALL(P),p)-P.begin();
		auto qp = upper_bound(ALL(Q),q)-Q.begin();
		M[T[C[pp-1][qp-1]]].emplace_back(S);
	}
	for(auto& x:M){
		sort(ALL(x));
	}
	cout << "S:";
	for(auto& x:M[0]) cout << ' ' << x;
	cout << endl;
	cout << "M:";
	for(auto& x:M[1]) cout << ' ' << x;
	cout << endl;
	cout << "L:";
	for(auto& x:M[2]) cout << ' ' << x;
	cout << endl;
	cout << "X:";
	for(auto& x:M[3]) cout << ' ' << x;
	cout << endl;
	return 0;
}
accuracy: 1
time_ms: 300
memory_kb: 68588
final_rank: 13

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 9223372036854775807
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 1000005

enum Type{
	S,
	M,
	L,
	X,
};

int N,h,w;
ll P[SIZE],Q[SIZE];
vector<string> V[4];
vector<Type> C[SIZE];

int main(){

	scanf("%d %d %d",&N,&h,&w);

	char buf[25];

	P[0] = 0;
	for(int loop = 1; loop <= h; loop++){

		scanf("%s",buf);
		ll tmp = 0;
		for(int i = 0; buf[i] != '\0'; i++){
			if(buf[i] == '.')continue;

			tmp = 10*tmp+(buf[i]-'0');
		}
		P[loop] = tmp;
	}
	P[h+1] = 200*100000;

	Q[0] = 0;
	for(int loop = 1; loop <= w; loop++){

		scanf("%s",buf);
		ll tmp = 0;
		for(int i = 0; buf[i] != '\0'; i++){
			if(buf[i] == '.')continue;

			tmp = 10*tmp+(buf[i]-'0');
		}
		Q[loop] = tmp;
	}
	Q[w+1] = 100*100000;

	for(int i = 1; i <= h+1; i++){
		for(int k = 0; k <= w; k++){

			scanf("%s",buf);

			switch(buf[0]){
			case 'S':

				C[i].push_back(S);
				break;

			case 'M':

				C[i].push_back(M);
				break;

			case 'L':

				C[i].push_back(L);
				break;

			case 'X':

				C[i].push_back(X);
				break;
			}
		}
	}

	string tmp_str;

	int left,right,mid;

	for(int loop = 0; loop < N; loop++){

		cin >> tmp_str;
		scanf("%s",buf);

		ll height = 0;
		for(int i = 0; buf[i] != '\0'; i++){
			if(buf[i] == '.')continue;

			height = 10*height+(buf[i]-'0');
		}

		scanf("%s",buf);

		ll weight = 0;
		for(int i = 0; buf[i] != '\0'; i++){
			if(buf[i] == '.')continue;

			weight = 10*weight+(buf[i]-'0');
		}

		left = 0,right = h+1,mid = (left+right)/2;
		int x;

		while(left <= right){

			if(P[mid] <= height){

				x = mid+1;
				left = mid+1;
			}else{

				right = mid-1;
			}
			mid = (left+right)/2;
		}

		left = 0,right = w+1,mid = (left+right)/2;
		int y;

		while(left <= right){

			if(Q[mid] <= weight){

				y = mid+1;
				left = mid+1;
			}else{

				right = mid-1;
			}
			mid = (left+right)/2;
		}

		Type type = C[x][y-1];
		V[type].push_back(tmp_str);
	}

	for(int i = 0; i < 4; i++){
		if(V[i].size() == 0)continue;

		sort(V[i].begin(),V[i].end());
	}

	char table[4] = {'S','M','L','X'};

	for(int i = 0; i < 4; i++){

		printf("%c:",table[i]);
		for(int a = 0; a < V[i].size(); a++){

			printf(" %s",V[i][a].c_str());
		}
		printf("\n");
	}

	return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 68940
final_rank: 11

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

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

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const double EPS = 1e-7, PI = acos(-1);
//ここから編集

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(6);

  int n, h, w; cin >> n >> h >> w;
  vector<double> p(h+2);
  vector<double> q(w+2);

  for(int i=1; i<=h; i++) cin >> p[i];
  p[h+1] = 200;
  for(int i=1; i<=w; i++) cin >> q[i];
  q[w+1] = 100;

  vector<vector<char>> c(h+1, vector<char>(w+1));
  REP(i,h+1){
    REP(j,w+1) cin >> c[i][j];
  }

  map<char, vector<string>> mp;
  REP(i,n){
    string s;
    double a, b; cin >> s >> a >> b;
    auto x = upper_bound(all(p), a) - p.begin();
    auto y = upper_bound(all(q), b) - q.begin();
    mp[c[x-1][y-1]].push_back(s);
  }
  
  sort(all(mp['S']));
  cout << "S:";
  for(auto e: mp['S']){
    cout << " " << e;
  }
  cout << endl;
  sort(all(mp['M']));
  cout << "M:";
  for(auto e: mp['M']){
    cout << " " << e;
  }
  cout << endl;
  sort(all(mp['L']));
  cout << "L:";
  for(auto e: mp['L']){
    cout << " " << e;
  }
  cout << endl;
  sort(all(mp['X']));
  cout << "X:";
  for(auto e: mp['X']){
    cout << " " << e;
  }
  cout << endl;
  return 0;
}
accuracy: 1
time_ms: 330
memory_kb: 68448
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ld=long double;

signed main(){
  int n,h,w;cin>>n>>h>>w;
  vector<ld> p,q;
  p.push_back(0);
  q.push_back(0);
  for(int i=0;i<h;i++){
    ld a;cin>>a;p.push_back(a);
  }
  p.push_back(200);
  for(int i=0;i<w;i++){
    ld a;cin>>a;q.push_back(a);
  }
  q.push_back(100);
  vector<vector<char>> c(h+1);
  for(int i=0;i<=h;i++){
    for(int j=0;j<=w;j++){
      char a;cin>>a;c[i].push_back(a);
    }
  }
  map<char,multiset<string>> mp;
  for(int i=0;i<n;i++){
    string name;cin>>name;
    ld he,we;cin>>he>>we;
    int l=-1,r=h+1;
    while(r-l>1){
      int mid=(l+r)>>1;
      (p[mid]<=he?l:r)=mid;
    }
    int L=-1,R=w+1;
    while(R-L>1){
      int mid=(L+R)>>1;
      (q[mid]<=we?L:R)=mid;
    }
    mp[c[l][L]].insert(name);
  }
  cout<<"S:";
  for(string name:mp['S'])cout<<" "<<name;cout<<endl;
  cout<<"M:";
  for(string name:mp['M'])cout<<" "<<name;cout<<endl;
  cout<<"L:";
  for(string name:mp['L'])cout<<" "<<name;cout<<endl;
  cout<<"X:";
  for(string name:mp['X'])cout<<" "<<name;cout<<endl;
}
accuracy: 1
time_ms: 760
memory_kb: 78736
final_rank: 18

code_snippet: #include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"


int change(char C){
	if(C == 'S') return 0;
	if(C == 'M') return 1;
	if(C == 'L') return 2;
	if(C == 'X') return 3;
}

int sdtoi(string s){
	int res = 0;
	
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '.') continue;
		res = res * 10 + s[i] - '0';
	}
	
	return res;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	constexpr int p = 100000;
	constexpr int maximumh = 200 * p;
	constexpr int maximumw = 100 * p;
	constexpr int num = 4;
	
	int n, h, w;
	vector<char> s = {'S', 'M', 'L', 'X'};
	vector<int> hg, wg;
	vector<vector<char>> c;
	vector<vector<string>> ans(num);
	
	cin>>n>>h>>w;
	
	hg.resize(h+2);
	wg.resize(w+2);
	c.resize(h+1, vector<char>(w+1));
	
	hg[h+1] = maximumh;
	wg[w+1] = maximumw;
	
	for(int i = 1; i <= h; i++){
		string shg;
		
		cin>>shg;
		
		hg[i] = sdtoi(shg);
	}
	
	for(int i = 1; i <= w; i++){
		string swg;
		
		cin>>swg;
		
		wg[i] = sdtoi(swg);
	}
	
	for(int i = 0; i <= h; i++){
		for(int j = 0; j <= w; j++){
			cin>>c[i][j];
		}
	}
	
	for(int i = 0; i < n; i++){
		string s, shp, swp;
		int hp, wp, x, y;
		
		cin>>s>>shp>>swp;
		
		hp = sdtoi(shp);
		wp = sdtoi(swp);
		
		x = upper_bound(hg.begin(), hg.end(), hp) - hg.begin();
		y = upper_bound(wg.begin(), wg.end(), wp) - wg.begin();
		
		ans[change(c[x-1][y-1])].push_back(s);
	}
	
	for(int i = 0; i < num; i++){
		sort(ans[i].begin(), ans[i].end());
		
		cout<<s[i]<<":";
		
		for(int j = 0; j < ans[i].size(); j++){
			cout<<" "<<ans[i][j];
		}
		
		cout<<endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 68412
final_rank: 8

code_snippet: #include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

void double_to_ll(ll &a){
    long double d;
    cin>>d;
    d *= 1e+5;
    a = (ll)(d + 0.5);
}

int main() {
    cin>>N>>H>>W;
    vec p(H), q(W);
    rep(i, H) double_to_ll(p[i]);
    rep(i, W) double_to_ll(q[i]);
    map<char, int> ctoi = {{'S', 0}, {'M', 1}, {'L', 2}, {'X', 3}};
    vector<char> size = {'S', 'M', 'L', 'X'};
    mat c(H + 1, vec(W + 1));
    rep(i, H + 1){
        rep(j, W + 1) {
            char ct; cin>>ct;
            c[i][j] = ctoi[ct];
        }
    }
    vector<vector<string> > ans(4);
    rep(_, N){
        string s; cin>>s;
        ll a, b;
        double_to_ll(a);
        double_to_ll(b);
        int i = upper_bound(ALL(p), a) - p.begin();
        int j = upper_bound(ALL(q), b) - q.begin();
        ans[c[i][j]].push_back(s);
    }

    rep(i, 4){
        cout<<size[i]<<':';
        sort(ALL(ans[i]));
        for(string &s : ans[i]) cout<<' '<<s;
        cout<<endl;
    }
}
accuracy: 1
time_ms: 750
memory_kb: 68964
final_rank: 17

code_snippet: #pragma region Macros
#pragma GCC optimize("O3")
#pragma GCC target("avx2,avx")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size)                                                                                                                                  \
    vector<type> name(size);                                                                                                                                   \
    IN(name)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w)                                                                                                                                   \
    vector<vector<type>> name(h, vector<type>(w));                                                                                                             \
    IN(name)
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)                                                                                                                         \
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
using namespace std;
string YES[2] = {"NO", "YES"};
string Yes[2] = {"No", "Yes"};
string yes[2] = {"no", "yes"};
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define si(c) (int)(c).size()
#define INT(...)                                                                                                                                               \
    int __VA_ARGS__;                                                                                                                                           \
    IN(__VA_ARGS__)
#define LL(...)                                                                                                                                                \
    ll __VA_ARGS__;                                                                                                                                            \
    IN(__VA_ARGS__)
#define STR(...)                                                                                                                                               \
    string __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS)
#define CHR(...)                                                                                                                                               \
    char __VA_ARGS__;                                                                                                                                          \
    IN(__VA_ARGS)
#define DBL(...)                                                                                                                                               \
    double __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) {
    scan(head);
    IN(tail...);
}
template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
vi iota(int n) {
    vi a(n);
    iota(all(a), 0);
    return a;
}
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
vector<pll> factor(ll x) {
    vector<pll> ans;
    for(ll i = 2; i * i <= x; i++)
        if(x % i == 0) {
            ans.push_back({i, 1});
            while((x /= i) % i == 0) ans.back().second++;
        }
    if(x != 1) ans.push_back({x, 1});
    return ans;
}
template <class T> vector<T> divisor(T x) {
    vector<T> ans;
    for(T i = 1; i * i <= x; i++)
        if(x % i == 0) {
            ans.pb(i);
            if(i * i != x) ans.pb(x / i);
        }
    return ans;
}
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    sort(all(y));
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
int popcount(ll x) { return __builtin_popcountll(x); }
struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(15);
    }
} setup_io;
int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}

template <typename T> struct edge {
    int from, to;
    T cost;
    int id;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
    edge(int from, int to, T cost, int id) : from(from), to(to), cost(cost), id(id) {}
    edge &operator=(const int &x) {
        to = x;
        return *this;
    }
    operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;

using Tree = vector<vector<int>>;
using Graph = vector<vector<int>>;
template <class T> using Wgraph = vector<vector<edge<T>>>;
Graph getG(int n, int m = -1, bool directed = false, int margin = 1) {
    Tree res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        cin >> a >> b;
        a -= margin, b -= margin;
        res[a].emplace_back(b);
        if(!directed) res[b].emplace_back(a);
    }
    return move(res);
}
template <class T> Wgraph<T> getWg(int n, int m = -1, bool directed = false, int margin = 1) {
    Wgraph<T> res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        T c;
        cin >> a >> b >> c;
        a -= margin, b -= margin;
        res[a].emplace_back(b, c);
        if(!directed) res[b].emplace_back(a, c);
    }
    return move(res);
}

#define i128 __int128_t
#define ull unsigned long long int
#define TEST                                                                                                                                                   \
    INT(testcases);                                                                                                                                            \
    while(testcases--)
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    for(auto &e : v) cout << e << " ";
    cout << endl;
    return os;
}
template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &p) {
    cout << "(" << p.fi << ", " << p.se << ")";
    return os;
}
template <class S, class T> string to_string(pair<S, T> p) { return "(" + to_string(p.first) + "," + to_string(p.second) + ")"; }
template <class A> string to_string(A v) {
    if(v.empty()) return "{}";
    string ret = "{";
    for(auto &x : v) ret += to_string(x) + ",";
    ret.back() = '}';
    return ret;
}

void dump() { cerr << endl; }
template <class Head, class... Tail> void dump(Head head, Tail... tail) {
    cerr << to_string(head) << " ";
    dump(tail...);
}
#define endl '\n'
#ifdef _LOCAL
#undef endl
#define debug(x)                                                                                                                                               \
    cout << #x << ": ";                                                                                                                                        \
    dump(x)
#else
#define debug(x)
#endif
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// int rnd(int n) { return uniform_int_distribution<int>(0, n - 1)(rng); }
// ll rndll(ll n) { return uniform_int_distribution<ll>(0, n - 1)(rng); }

template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
#pragma endregion

int main() {
    INT(n, h, w);
    vi p(h), q(w);
    rep(i, h) {
        double x;
        cin >> x;
        p[i] = round(x * 100000);
    }
    rep(i, w) {
        double x;
        cin >> x;
        q[i] = round(x * 100000);
    }
    VV(char, c, h + 1, w + 1);
    map<char, vector<string>> ans;
    rep(i, n) {
        string s;
        cin >> s;
        double a, b;
        cin >> a >> b;
        int A = round(a * 100000), B = round(b * 100000);
        int ii = ub(p, A), j = ub(q, B);
        ans[c[ii][j]].eb(s);
    }
    for(auto e : {'S', 'M', 'L', 'X'}) {
        cout << e << ":";
        if(ans[e].empty())
            cout << endl;
        else
            cout << " ";
        sort(all(ans[e]));
        rep(i, si(ans[e])) cout << ans[e][i] << " \n"[i == si(ans[e]) - 1];
    }
}
accuracy: 1
time_ms: 300
memory_kb: 63748
final_rank: 9

code_snippet: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

int szinp() {
	string s; cin >> s;
	rep(i, s.size())if (s[i] == '.')s.erase(s.begin() + i);
	while (s.size() > 1 && s[0] == '0')s.erase(s.begin());
	return stoi(s);
}
void solve() {
	int n, h, w; cin >> n >> h >> w;
	vector<int> p(h + 2);
	p[0] = 0, p[h + 1] = 20000000;
	rep1(i, h)p[i] = szinp();
	vector<int> q(w + 2);
	q[0] = 0, q[w + 1] = 10000000;
	rep1(i, w)q[i] = szinp();
	vector<vector<char>> c(h+1,vector<char>(w+1));
	rep(i, h+1)rep(j, w+1) {
		cin >> c[i][j];
	}
	vector<string> v[4];
	string sz = "SMLX";
	rep(i, n) {
		string x; cin >> x;
		int a = szinp();
		int b = szinp();
		a = upper_bound(all(p), a) - p.begin();
		b = upper_bound(all(q), b) - q.begin();
		a--; b--;
		//cout << "??? " << a << " " << b << "\n";
		char z = c[a][b];
		v[sz.find(z)].push_back(x);
	}
	rep(i, 4) {
		sort(all(v[i]));
		cout << sz[i] << ":";
		rep(j, v[i].size())cout << " " << v[i][j];
		cout << "\n";
	}
}





signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 64512
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  int64_t N,H,W; cin>>N>>H>>W;
  vector<double> P(H),Q(W);
  rep(i,H) cin>>P[i];
  P.push_back(200);
  rep(i,W) cin>>Q[i];
  Q.push_back(100);
  vector<char> I={'S','M','L','X'};
  vector<vector<char>> C(H+1,vector<char>(W+1));
  rep(i,H+1){
    rep(j,W+1){
      cin>>C[i][j];
    }
  }
  vector<vector<string>> A(4);
  rep(o,N){
    string s; cin>>s;
    double a,b; cin>>a>>b;
    int i= upper_bound(P.begin(), P.end(),a)-P.begin();
    int j= upper_bound(Q.begin(), Q.end(),b)-Q.begin();
    auto k=C.at(i).at(j);
    if(k=='S') A[0].push_back(s);
    if(k=='M') A[1].push_back(s);
    if(k=='L') A[2].push_back(s);
    if(k=='X') A[3].push_back(s);
  }
  rep(i,4){
    int k=A.at(i).size();
    if(k==0){
      cout<<I[i]<<":"<<endl;
    }
    else{
      sort(A[i].begin(),A[i].end());
      cout<<I[i]<<": ";
      rep(j,k-1){
        cout<<A[i][j]<<' ';
      }
      cout<<A[i][k-1]<<endl;
    }
  }
}
accuracy: 1
time_ms: 730
memory_kb: 68924
final_rank: 16

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;

map<char, vector<string>> mp;
vector<ll> p, q;
vector<string> c;
ll N, H, W;

void f(char a) {
    cout << a << ":";
    sort(mp[a].begin(), mp[a].end());
    for(auto tmp : mp[a]) {
        cout << " " << tmp;
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> H >> W;
    p.resize(H+1);
    p[0] = -1;
    for(int i = 0; i < H; i++) {
        double tmp;
        cin >> tmp;
        ll a = round(100000 * tmp);
        p[i+1] = a;
    }
    q.resize(W+1);
    for(int i = 0; i < W; i++) {
        double tmp;
        cin >> tmp;
        ll a = round(100000 * tmp);
        q[i+1] = a;
    }
    c.resize(H + 1);
    for(int h = 0; h <= H; h++) {
        for(int w = 0; w <= W; w++) {
            char a;
            cin >> a;
            c[h].push_back(a);
        }
    }
    for(int _ = 0; _ < N; _++) {
        string s;
        cin >> s;
        double tmp;
        cin >> tmp;
        ll a = round(100000 * tmp);
        cin >> tmp;
        ll b = round(100000 * tmp);
        auto itr = upper_bound(p.begin(), p.end(), a);
        int idxa = itr - p.begin() - 1;
        itr = upper_bound(q.begin(), q.end(), b);
        int idxb = itr - q.begin() - 1;
        //cerr << a << " " << b << " " << idxa << " "<< idxb << endl;
        mp[c[idxa][idxb]].push_back(s);
    }
    f('S');
    f('M');
    f('L');
    f('X');
    return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 44216
final_rank: 2

code_snippet: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

int n,h,w;
vector<ld> ps,qs;
vector<vector<char>> c;
map<char,multiset<string>> ma;

int comp(ld x,vector<ld> &v){
    return upper_bound(v.begin(),v.end(),x)-v.begin()-1;
}

void solve(){
    cin >> n >> h >> w;
    ps.resize(h+2);qs.resize(w+2);
    rep(i,h) cin >> ps[i+1];
    rep(i,w) cin >> qs[i+1];
    ps[h+1]=200;qs[w+1]=100;
    c.resize(h+1,vector<char>(w+1));
    rep(i,h+1){
        rep(j,w+1){
            cin >> c[i][j];
        }
    }
    rep(i,n){
        string s;ld a,b;cin >> s >> a >> b;
        //cout << comp(a,ps) << " " << comp(b,qs) << endl;
        ma[c[comp(a,ps)][comp(b,qs)]].insert(s);
    }
    vector<char> S={'S','M','L','X'};
    for(char x:S){
        if(ma[x].empty()) cout << x << ":" << endl;
        else{
            cout << x << ": ";
            auto it=ma[x].begin();auto en=ma[x].end();en--;
            while(it!=ma[x].end()){
                if(it!=en)cout << (*it) << " ";
                else cout << (*it) << "";
                it++;
            }
            cout << "" << endl;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}
accuracy: 1
time_ms: 310
memory_kb: 77724
final_rank: 15

code_snippet: #include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n, h, w;
    cin>>n>>h>>w;
    int p[1000010], q[1000010];
    for(int i=0; i<h; i++){
        int p1, p2;
        scanf("%d.%d", &p1, &p2);
        p[i]=p1*100000+p2;
    }
    for(int i=0; i<w; i++){
        int p1, p2;
        scanf("%d.%d", &p1, &p2);
        q[i]=p1*100000+p2;
    }
    vector<vector<char>> c(h+1, vector<char>(w+1));
    for(int i=0; i<h+1; i++) for(int j=0; j<w+1; j++) cin>>c[i][j];
    vector<string> ans[4];
    for(int i=0; i<n; i++){
        string s;
        int a, b, p1, p2;
        cin>>s;
        scanf("%d.%d", &p1, &p2);
        a=p1*100000+p2;
        scanf("%d.%d", &p1, &p2);
        b=p1*100000+p2;
        int x=upper_bound(p, p+h, a)-p;
        int y=upper_bound(q, q+w, b)-q;
        if(c[x][y]=='S') ans[0].push_back(s);
        else if(c[x][y]=='M') ans[1].push_back(s);
        else if(c[x][y]=='L') ans[2].push_back(s);
        else ans[3].push_back(s);
    }
    for(int i=0; i<4; i++) sort(ans[i].begin(), ans[i].end());
    cout<<"S:";
    for(auto s:ans[0]) cout<<" "<<s;
    cout<<endl;
    cout<<"M:";
    for(auto s:ans[1]) cout<<" "<<s;
    cout<<endl;
    cout<<"L:";
    for(auto s:ans[2]) cout<<" "<<s;
    cout<<endl;
    cout<<"X:";
    for(auto s:ans[3]) cout<<" "<<s;
    cout<<endl;
    return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 65116
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,h,w; cin >> n >> h >> w;
	vector<ll> p(h+2),q(w+2);
	for(int i=1;i<=h;i++){
		string A; cin >> A;
		ll a=0;
		for(int j=0;j<A.size();j++){
			if('0'<=A[j]&&A[j]<='9'){
				a=10*a+A[j]-'0';
			}
		}
		p[i]=a;
	}
	p[0]=0; p[h+1]=200*100000;
	q[0]=0; q[w+1]=200*100000;
	for(int i=1;i<=w;i++){
		string A; cin >> A;
		ll a=0;
		for(int j=0;j<A.size();j++){
			if('0'<=A[j]&&A[j]<='9'){
				a=10*a+A[j]-'0';
			}
		}
		q[i]=a;
	}
	vector<char> c((h+1)*(w+1));
	for(int i=0;i<(h+1)*(w+1);i++){
		cin >> c[i];
	}
	vector<string> S,M,L,X;
	for(int i=0;i<n;i++){
		string Name; cin >> Name;
		string A,B; cin >> A >> B;
		ll a=0,b=0;
		for(int j=0;j<A.size();j++){
			if('0'<=A[j]&&A[j]<='9'){
				a=10*a+A[j]-'0';
			}
		}
		for(int j=0;j<B.size();j++){
			if('0'<=B[j]&&B[j]<='9'){
				b=10*b+B[j]-'0';
			}
		}
		int id=lower_bound(p.begin(), p.end(),a+1)-p.begin()-1;
		int jd=lower_bound(q.begin(), q.end(),b+1)-q.begin()-1;
		char C=c[id*(w+1)+jd];
		if(C=='S'){
			S.push_back(Name);
		}
		if(C=='M'){
			M.push_back(Name);
		}
		if(C=='L'){
			L.push_back(Name);
		}
		if(C=='X'){
			X.push_back(Name);
		}
	}
	sort(S.begin(), S.end());
	sort(M.begin(), M.end());
	sort(L.begin(), L.end());
	sort(X.begin(), X.end());
	cout << "S:";
	for(int i=0;i<S.size();i++){
		cout << " " << S[i];
	}
	cout << endl;
	cout << "M:";
	for(int i=0;i<M.size();i++){
		cout << " " << M[i];
	}
	cout << endl;
	cout << "L:";
	for(int i=0;i<L.size();i++){
		cout << " " << L[i];
	}
	cout << endl;
	cout << "X:";
	for(int i=0;i<X.size();i++){
		cout << " " << X[i];
	}
	cout << endl;
}
accuracy: 1
time_ms: 140
memory_kb: 15716
final_rank: 1

code_snippet: #include "bits/stdc++.h"
using namespace std;
// #include "atcoder/all"
// using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)

signed main(){
	IOS();
	int N, H, W;
	cin >> N >> H >> W;

	vector<int>p(H + 2), q(W + 2);
	p.back() = 20000000;
	q.back() = 10000000;
	auto parse = [&]() -> int {
		string s;
		cin >> s;
		string t;
		int ret = 0;
		REP(i, s.size()) if(s[i] != '.') t += s[i];
		return stoll(t);
	};
	FOR(i, 1, H + 1) p[i] = parse();
	FOR(i, 1, W + 1) q[i] = parse();
	//REP(i,p.size())cout << p[i] << " \n"[i+1 == p.size()];
	//REP(i,q.size())cout << q[i] << " \n"[i+1 == q.size()];
	//return 0;
	vector<vector<char>> c(H + 1, vector<char>(W + 1));
	REP(i, H + 1) REP(j, W + 1) cin >> c[i][j];

	map<char, vector<string>>mp;
	REP(i, N) {
		string s;
		cin >> s;
		int a = parse(), b = parse();
		int y = upper_bound(ALL(p), a) - p.begin();
		int x = upper_bound(ALL(q), b) - q.begin();
		//out(a, b, y, x);
		mp[c[y - 1][x - 1]].emplace_back(s);
	}
	string t = "SMLX";
	for(auto e: t) {
		cout << e << ":";
		auto v = mp[e];
		sort(ALL(v));
		REP(i,v.size())cout << " " << v[i];
		cout << "\n";
	}
}
accuracy: 1
time_ms: 150
memory_kb: 68136
final_rank: 5

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

int getint() {
    int x, y;
    char tmp;
    std::cin >> x >> tmp >> y;
    return x * 100000 + y;
}

void solve() {
    int n, h, w;
    std::cin >> n >> h >> w;

    std::vector<int> ps(h), qs(w);
    for (auto& p : ps) p = getint();
    for (auto& q : qs) q = getint();

    const std::string size = "SMLX";
    auto css = vec(h + 1, vec(w + 1, 0));
    for (auto& cs : css) {
        for (auto& c : cs) {
            char d;
            std::cin >> d;
            while (size[c] != d) ++c;
        }
    }

    std::vector<std::vector<std::string>> ans(4);
    while (n--) {
        std::string s;
        std::cin >> s;
        int p = getint(),
            q = getint();

        int i = std::upper_bound(ps.begin(), ps.end(), p) - ps.begin();
        int j = std::upper_bound(qs.begin(), qs.end(), q) - qs.begin();
        ans[css[i][j]].push_back(s);
    }

    for (int i = 0; i < 4; ++i) {
        std::cout << size[i] << ":";

        auto& v = ans[i];
        std::sort(v.begin(), v.end());
        for (const auto& s : v) std::cout << " " << s;
        std::cout << "\n";
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 1
time_ms: 190
memory_kb: 63548
final_rank: 4