Problem:
Blur
図 1 のような 10×10 のマス目の「布」があり、（1，2）のようにX座標・Y座標の値の対でマス目を示すことにします。座標値は 0 から始まる整数とします。例えば、図 1 の◎の座標は (1, 2) です。
この「布」に染料を少しずつたらして染物を作ります。たらす染料の滴には「大」「中」「小」の 3 サイズがあり、染料の滴の落ちたマス目を中心に図 1 のように周囲も色がつきます。図 1 で☆が中心、○が色のにじむ範囲です。
「布」は、最初は「まっしろ」つまり、どのマス目も色の濃さを示す値が 0 とします。染料の滴が落ちるごとに値が 1 ずつ増えていきます。「小」が（1, 2）、「中」が（3, 2）に落ちた場合、各マス目の値は図 2 の左のようになります。染料がもったいないので、図 2 の右に示すようなにじむ範囲が布の外にはみ出すような染料の落とし方はしないことになっています。また、同じ場所に複数の染料をたらすこともあります。
このような作業を何回か繰り返した結果、布にすばらしい模様が浮かび上がりましたが、残念なことに、うっかり作業経過を記録し忘れてしまいました。どうにもさっぱり思い出せませんが、かろうじて、落とした染料の滴数は覚えていました。あなたは、すばらしい染物を再現しなければなりません。すばらしい染物のデータを読みこんで、どこに、どのような染料をたらしたかを出力するプログラムを作成してください。なお、落とした染料の滴数は 12 以下とします。
入力
入力の形式は以下のとおりです：
最初の 1 行に落とした染料の滴数
n
が与えられます。次の行から 10 行に各座標の色の濃さが空白区切りで与えられます。
出力
出力は
n
行からなります。染料の滴の「大」を 3、「中」を 2、「小」を 1 で表し、落とした染料ごとに、そのX座標、Y座標、滴の大きさを空白で区切って1行に出力してください。
染料のたらし方はどのような順番で出力しても良いものとします。
入力例1
2
0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 1 1 1 0 0 0 0 0
0 0 0 1 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
出力例1
3 2 1
8 4 2
入力例2
6
0 0 1 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0
0 1 1 1 1 1 1 1 0 0
0 0 1 1 1 3 1 1 0 0
0 0 1 1 3 1 1 1 0 0
0 0 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 0 0
出力例2
2 2 3
7 7 3
6 3 2
3 6 2
4 4 1
5 5 1

Submitted solutions:

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

#define N 10

using namespace std;

struct Tri {
    int a, b, c;
    bool operator< (const Tri& o) {
        // greater c -> b -> a
        if(c != o.c) return c > o.c;
        if(b != o.b) return b > o.b;
        return a > o.a;
    }
};

int stamp_size[] = {5, 9, 13};
int dir_x[13] = {0, 0, 0, 1, -1, 1, -1, 1, -1, 0, 0, 2, -2};
int dir_y[13] = {0, 1, -1, 0, 0, 1, -1, -1, 1, 2, -2, 0, 0};

int sizeToDirLength(int size){
    return stamp_size[size];
}

int n;
int nuno[N][N];

bool range(int x, int y, int size) {
    int offset = size != 2 ? 1 : 2;

    if(x < offset || N - offset <= x || y < offset || N - offset <= y){
        return false;
    }
    return true;
}

bool check(int x, int y, int size) {
    if(!range(x, y, size)){
        return false;
    }

    int dirNum = sizeToDirLength(size);
    for(int i = 0; i < dirNum; i++) {
        int nx = x + dir_x[i];
        int ny = y + dir_y[i];

        if(nuno[ny][nx] <= 0) {
            return false;
        }
    }

    return true;
}

void simu(int x, int y, int size, int add) {
    int dirNum = sizeToDirLength(size);
    for(int i = 0; i < dirNum; i++) {
        int nx = x + dir_x[i];
        int ny = y + dir_y[i];
        nuno[ny][nx] += add;
    }
}

int patternToSize(int d, const Tri& pattern){
    if(d < pattern.c) {
        return 2;
    } else if(d < pattern.b + pattern.c) {
        return 1;
    }
    return 0;
}

vector<Tri> answer;
vector<pair<int, int> > cand[3];

bool dfs(int d, int remain, const Tri& pattern) {
    if(d >= n) {
        return remain == 0;
    }

    // int size = patternToSize(d, pattern);

    // for(int i = 0; i < cand[size].size(); i++) {
    //     pair<int, int> p = cand[size][i];
    //     int x = p.first, y = p.second;
    for(int size = 2; size >= 0; size--)
    for(int x = 0; x < N; x++)
    for(int y = 0; y < N; y++){
        if(!check(x, y, size)){
            continue;
        }
        simu(x, y, size, -1);
        if(dfs(d + 1, remain - stamp_size[size], pattern)){
            answer.push_back((Tri){x, y, size + 1});
            printf("%d %d %d\n", x, y, size + 1);

            return true;
        }
        simu(x, y, size, 1);
    }

    return false;
}

vector<Tri> calcStampNum(int n, int sum) {
    vector<Tri> res;
    int r1 = n - (sum - 5*n)/4;
    int r2 = (sum - 5*n)/4;

    for(int a = 0; a < n; a++) {
        for(int b = 0; b < n; b++){
            for(int c = 0; c < n; c++) {
                if(a - c != r1 || b + 2*c != r2){
                    continue;
                }
                res.push_back((Tri){a, b, c});
            }
        }
    }

    return res;
}

int main() {
    cin >> n;

    int sum = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            cin >> nuno[i][j];
            sum += nuno[i][j];
        }
    }

    for(int size = 0; size < 3; size++) {
        for(int x = 0; x < N; x++) {
            for(int y = 0; y < N; y++) {
                if(check(x, y, size)) {
                    cand[size].push_back(make_pair(x, y));
                }
            }
        }
    }

    vector<Tri> stampNum = calcStampNum(n, sum);
    sort(stampNum.begin(), stampNum.end());

    for(int i = 0; i < stampNum.size(); i++) {
        if(dfs(0, sum, stampNum[i])) {
            break;
        }
    }

    sort(answer.begin(), answer.end());

    for(int i = 0; i < answer.size(); i++){
        Tri t = answer[i];
        // printf("%d %d %d\n", t.a, t.b, t.c);
    }

    return 0;
}


/*
a + b + c = n
a*5 + b*9 + c*13 = sum

1 1  1 | n
5 9 13 | sum

1 1 1 | n
0 4 8 | sum-5n

1 1 1 | n
0 1 2 | (sum-5n)/4

1 0 -1 | n-(sum-5n)/4
0 1  2 | (sum-5n)/4

a -   c = n-(sum-5n)/4
b + 2*c = (sum-5n)/4

*/
accuracy: 0.1388888888888889
time_ms: 30
memory_kb: 3232
final_rank: 17

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

#define N 10

using namespace std;

struct Tri {
    int a, b, c;
    bool operator< (const Tri& o) {
        // greater c -> b -> a
        if(c != o.c) return c > o.c;
        if(b != o.b) return b > o.b;
        return a > o.a;
    }
};

int stamp_size[] = {5, 9, 13};
int dir_x[13] = {0, 0, 0, 1, -1, 1, -1, 1, -1, 0, 0, 2, -2};
int dir_y[13] = {0, 1, -1, 0, 0, 1, -1, -1, 1, 2, -2, 0, 0};

int sizeToDirLength(int size){
    return stamp_size[size];
}

int n;
int nuno[N][N];

bool range(int x, int y, int size) {
    int offset = size != 2 ? 1 : 2;

    if(x < offset || N - offset <= x || y < offset || N - offset <= y){
        return false;
    }
    return true;
}

bool check(int x, int y, int size) {
    if(!range(x, y, size)){
        return false;
    }

    int dirNum = sizeToDirLength(size);
    for(int i = 0; i < dirNum; i++) {
        int nx = x + dir_x[i];
        int ny = y + dir_y[i];

        if(nuno[ny][nx] <= 0) {
            return false;
        }
    }

    return true;
}

void simu(int x, int y, int size, int add) {
    int dirNum = sizeToDirLength(size);
    for(int i = 0; i < dirNum; i++) {
        int nx = x + dir_x[i];
        int ny = y + dir_y[i];
        nuno[ny][nx] += add;
    }
}

int patternToSize(int d, const Tri& pattern){
    if(d < pattern.c) {
        return 2;
    } else if(d < pattern.b + pattern.c) {
        return 1;
    }
    return 0;
}

vector<Tri> answer;
vector<pair<int, int> > cand[3];

bool dfs(int d, int remain, const Tri& pattern) {
    if(d >= n) {
        return remain == 0;
    }

    // int size = patternToSize(d, pattern);

    // for(int i = 0; i < cand[size].size(); i++) {
    //     pair<int, int> p = cand[size][i];
    //     int x = p.first, y = p.second;
    for(int size = 2; size >= 0; size--)
    for(int x = 0; x < N; x++)
    for(int y = 0; y < N; y++){
        if(!check(x, y, size)){
            continue;
        }
        simu(x, y, size, -1);
        if(dfs(d + 1, remain - stamp_size[size], pattern)){
            answer.push_back((Tri){x, y, size + 1});
            return true;
        }
        simu(x, y, size, 1);
    }

    return false;
}

vector<Tri> calcStampNum(int n, int sum) {
    vector<Tri> res;
    int r1 = n - (sum - 5*n)/4;
    int r2 = (sum - 5*n)/4;

    for(int a = 0; a < n; a++) {
        for(int b = 0; b < n; b++){
            for(int c = 0; c < n; c++) {
                if(a - c != r1 || b + 2*c != r2){
                    continue;
                }
                res.push_back((Tri){a, b, c});
            }
        }
    }

    return res;
}

int main() {
    cin >> n;

    int sum = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            cin >> nuno[i][j];
            sum += nuno[i][j];
        }
    }

    for(int size = 0; size < 3; size++) {
        for(int x = 0; x < N; x++) {
            for(int y = 0; y < N; y++) {
                if(check(x, y, size)) {
                    cand[size].push_back(make_pair(x, y));
                }
            }
        }
    }

    vector<Tri> stampNum = calcStampNum(n, sum);
    sort(stampNum.begin(), stampNum.end());

    for(int i = 0; i < stampNum.size(); i++) {
        if(dfs(0, sum, stampNum[i])) {
            break;
        }
    }

    sort(answer.begin(), answer.end());

    for(int i = 0; i < answer.size(); i++){
        Tri t = answer[i];
        printf("%d %d %d\n", t.a, t.b, t.c);
    }

    return 0;
}


/*
a + b + c = n
a*5 + b*9 + c*13 = sum

1 1  1 | n
5 9 13 | sum

1 1 1 | n
0 4 8 | sum-5n

1 1 1 | n
0 1 2 | (sum-5n)/4

1 0 -1 | n-(sum-5n)/4
0 1  2 | (sum-5n)/4

a -   c = n-(sum-5n)/4
b + 2*c = (sum-5n)/4

*/
accuracy: 0.1388888888888889
time_ms: 30
memory_kb: 3260
final_rank: 18

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

#define N 10

using namespace std;

struct Tri {
    int a, b, c;
    bool operator< (const Tri& o) {
        // greater c -> b -> a
        if(c != o.c) return c > o.c;
        if(b != o.b) return b > o.b;
        return a > o.a;
    }
};

int stamp_size[] = {5, 9, 13};
int dir_x[13] = {0, 0, 0, 1, -1, 1, -1, 1, -1, 0, 0, 2, -2};
int dir_y[13] = {0, 1, -1, 0, 0, 1, -1, -1, 1, 2, -2, 0, 0};

int sizeToDirLength(int size){
    return stamp_size[size];
}

int n;
int nuno[N][N];

bool range(int x, int y, int size) {
    int offset = size != 2 ? 1 : 2;

    if(x < offset || N - offset <= x || y < offset || N - offset <= y){
        return false;
    }
    return true;
}

bool check(int x, int y, int size) {
    if(!range(x, y, size)){
        return false;
    }
    int dirNum = sizeToDirLength(size);

    for(int i = 0; i < dirNum; i++) {
        int nx = x + dir_x[i];
        int ny = y + dir_y[i];

        if(nuno[ny][nx] <= 0) {
            return false;
        }
    }

    return true;
}

void simu(int x, int y, int size, int add) {
    int dirNum = sizeToDirLength(size);
    for(int i = 0; i < dirNum; i++) {
        int nx = x + dir_x[i];
        int ny = y + dir_y[i];
        nuno[ny][nx] += add;
    }
}

int patternToSize(int d, const Tri& pattern){
    if(d < pattern.c) {
        return 2;
    } else if(d < pattern.b + pattern.c) {
        return 1;
    }
    return 0;
}

vector<Tri> answer;
vector<pair<int, int> > cand[3];

bool dfs(int d, int remain, const Tri& pattern) {
    if(d >= n) {
        return remain == 0;
    }

    // int size = patternToSize(d, pattern);
    for(int size = 2; size >= 0; size--)
    for(int i = 0; i < cand[size].size(); i++){
        pair<int, int> p = cand[size][i];
        int x = p.first, y = p.second;
        if(!check(x, y, size)){
            continue;
        }
        simu(x, y, size, -1);
        if(dfs(d + 1, remain - stamp_size[size], pattern)){
            answer.push_back((Tri){x, y, size + 1});
            return true;
        }
        simu(x, y, size, 1);
    }

    return false;
}

vector<Tri> calcStampNum(int n, int sum) {
    vector<Tri> res;
    int r1 = n - (sum - 5*n)/4;
    int r2 = (sum - 5*n)/4;

    for(int a = 0; a < n; a++) {
        for(int b = 0; b < n; b++){
            for(int c = 0; c < n; c++) {
                if(a - c != r1 || b + 2*c != r2){
                    continue;
                }
                res.push_back((Tri){a, b, c});
            }
        }
    }

    return res;
}

int main() {
    cin >> n;

    int sum = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            cin >> nuno[i][j];
            sum += nuno[i][j];
        }
    }

    for(int size = 0; size < 3; size++) {
        for(int x = 0; x < N; x++) {
            for(int y = 0; y < N; y++) {
                if(check(x, y, size)) {
                    cand[size].push_back(make_pair(x, y));
                }
            }
        }
    }

    vector<Tri> stampNum = calcStampNum(n, sum);
    sort(stampNum.begin(), stampNum.end());

    for(int i = 0; i < stampNum.size(); i++) {
        if(dfs(0, sum, stampNum[i])) {
            break;
        }
    }

    sort(answer.begin(), answer.end());

    for(int i = 0; i < answer.size(); i++){
        Tri t = answer[i];
        printf("%d %d %d\n", t.a, t.b, t.c);
    }

    return 0;
}


/*
a + b + c = n
a*5 + b*9 + c*13 = sum

1 1  1 | n
5 9 13 | sum

1 1 1 | n
0 4 8 | sum-5n

1 1 1 | n
0 1 2 | (sum-5n)/4

1 0 -1 | n-(sum-5n)/4
0 1  2 | (sum-5n)/4

a -   c = n-(sum-5n)/4
b + 2*c = (sum-5n)/4

*/
accuracy: 0.1388888888888889
time_ms: 10
memory_kb: 3188
final_rank: 16

code_snippet: #include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1e18
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)

vector dx(3,vector<int>()),dy(3,vector<int>());


vector<int> x,y,type;
vector<int> ans;
bool dfs(vector<vector<int>> g,vector<int> t,int last = 0){
	if(t[0]==0&&t[1]==0&&t[2]==0){
		return true;
	}
	for(int i=last;i<x.size();i++){
		for(int j=2;j>type[i];j--){
			if(t[j]>0)return false;
		}
		bool f = true;
		vector<vector<int>> ng = g;

		rep(j,type[i]+1){
			rep(xx,dx[j].size()){
				
				int X = x[i]+dx[j][xx], Y = y[i]+dy[j][xx];
				if(ng[Y][X]==0){
					f=false;
					goto Label;
				}
				ng[Y][X]--;
				
			}
		}
		Label:
		if(!f)continue;
		t[type[i]]--;
		f = dfs(ng,t,i);
		t[type[i]]++;
		if(f){
			ans.push_back(i);
			return true;
		}
	}
	return false;
}

int main(){
	
	dx[0] = {0,0,0,1,-1};
	dy[0] = {0,1,-1,0,0};

	dx[1] = {1,1,-1,-1};
	dy[1] = {1,-1,1,-1};

	dx[2] = {0,0,2,-2};
	dy[2] = {2,-2,0,0};
	
	int n;
	cin>>n;

	int s = 0;
	vector g(10,vector<int>(10));
	rep(i,10){
		rep(j,10){
			cin>>g[i][j];
			s += g[i][j];
		}
	}
	
	vector<vector<int>> t;
	
	rep(i,n+1){
		rep(j,n+1){
			rep(k,1+n){
				if(i+j+k==n&&i*5+j*9+k*13==s){
					t.push_back({i,j,k});
				}
			}
		}
	}
	
	
	
	rep(_,3){
		for(int i=1;i<9;i++){
			for(int j=1;j<9;j++){
				if(_==2){
					if(i==1||i==8||j==1||j==8)continue;
				}
				x.push_back(i);
				y.push_back(j);
				type.push_back(_);
			}
		}
	}
	reverse(x.begin(),x.end());
	reverse(y.begin(),y.end());
	reverse(type.begin(),type.end());
	rep(i,t.size()){
		if(dfs(g,t[i]))break;
	}
	
	rep(i,ans.size()){
		cout<<x[ans[i]]<<' '<<y[ans[i]]<<' '<<type[ans[i]]+1<<endl;
	}
	
    return 0;
}
accuracy: 1
time_ms: 1810
memory_kb: 3472
final_rank: 7

code_snippet: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int x;
    cin >> x;
    array<int, 100> v{};
    for (auto &&i : v) scanf("%d", &i);
    int A[] = {0, 9, 10, 11, 20};
    int B[] = {0, 1, 2, 10, 11, 12, 20, 21, 22};
    int C[] = {0, 9, 10, 11, 18, 19, 20, 21, 22, 29, 30, 31, 40};
    auto dfs = [&](int cur, int cnt, auto &&f) -> bool {
        if(cnt == 0){
            int ok = !*max_element(v.begin(),v.end());
            if(ok) return 1;
        }
        for (int i = cur; i < 100; ++i) {
            int y = i/10, x = i%10;
            if(y <= 5 && 2 <= x && x <= 7) {
                int ok = 1;
                for (auto &&p : C) if(!v[i+p]) ok = 0;
                if(ok){
                    for (auto &&p : C) v[i+p]--;
                    if(f(i,cnt-1, f)){
                        printf("%d %d 3\n", x, y+2);
                        return 1;
                    }
                    for (auto &&p : C) v[i+p]++;
                }
            }
            if(y <= 7 && x <= 7) {
                int ok = 1;
                for (auto &&p : B) if(!v[i+p]) ok = 0;
                if(ok){
                    for (auto &&p : B) v[i+p]--;
                    if(f(i,cnt-1, f)){
                        printf("%d %d 2\n", x+1, y+1);
                        return 1;
                    }
                    for (auto &&p : B) v[i+p]++;
                }
            }
            if(y <= 7 && 1 <= x && x <= 8) {
                int ok = 1;
                for (auto &&p : A) if(!v[i+p]) ok = 0;
                if(ok){
                    for (auto &&p : A) v[i+p]--;
                    if(f(i,cnt-1, f)){
                        printf("%d %d 1\n", x, y+1);
                        return 1;
                    }
                    for (auto &&p : A) v[i+p]++;
                }
            }


        }
        return 0;
    };
    dfs(0, x, dfs);

    return 0;
}
accuracy: 1
time_ms: 5590
memory_kb: 3228
final_rank: 9

code_snippet: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
//#include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define all(x) x.begin(),x.end()
using namespace std;
int mp[15][15], sum, n;
bool b1(int x, int y) {
	if (mp[x][y] < 1)return 0;
	if (mp[x - 1][y] < 1)return 0;
	if (mp[x + 1][y] < 1)return 0;
	if (mp[x][y - 1] < 1)return 0;
	if (mp[x][y + 1] < 1)return 0;
	return 1;
}
bool b2(int x, int y) {
	if (!b1(x, y))return 0;
	if (mp[x - 1][y - 1] < 1)return 0;
	if (mp[x - 1][y + 1] < 1)return 0;
	if (mp[x + 1][y - 1] < 1)return 0;
	if (mp[x + 1][y + 1] < 1)return 0;
	return 1;
}
bool b3(int x, int y) {
	if (!b2(x, y))return 0;
	if (x < 2 || x > 7 || y < 2 || y > 7)return 0;
	if (mp[x - 2][y] < 1)return 0;
	if (mp[x + 2][y] < 1)return 0;
	if (mp[x][y - 2] < 1)return 0;
	if (mp[x][y + 2] < 1)return 0;
}
void f1(int x, int y) {
	mp[x][y]--;
	mp[x - 1][y]--;
	mp[x + 1][y]--;
	mp[x][y - 1]--;
	mp[x][y + 1]--;
	sum -= 5;
}
void f1_(int x, int y) {
	mp[x][y]++;
	mp[x - 1][y]++;
	mp[x + 1][y]++;
	mp[x][y - 1]++;
	mp[x][y + 1]++;
	sum += 5;
}
void f2(int x, int y) {
	f1(x, y);
	mp[x - 1][y - 1]--;
	mp[x - 1][y + 1]--;
	mp[x + 1][y - 1]--;
	mp[x + 1][y + 1]--;
	sum -= 4;
}
void f2_(int x, int y) {
	f1_(x, y);
	mp[x - 1][y - 1]++;
	mp[x - 1][y + 1]++;
	mp[x + 1][y - 1]++;
	mp[x + 1][y + 1]++;
	sum += 4;
}
void f3(int x, int y) {
	f2(x, y);
	mp[x - 2][y]--;
	mp[x + 2][y]--;
	mp[x][y - 2]--;
	mp[x][y + 2]--;
	sum -= 4;
}
void f3_(int x, int y) {
	f2_(x, y);
	mp[x - 2][y]++;
	mp[x + 2][y]++;
	mp[x][y - 2]++;
	mp[x][y + 2]++;
	sum += 4;
}
bool f(int i, int j) {
	if (n == 0 && sum > 0)return 0;
	if (n > 0 && sum == 0)return 0;
	if (n == 0 && sum == 0)return 1;
	//cout << i << ' ' << j << ' ' << sum << endl;
	if (i >= 9)return 0;
	int in = i, jn = j + 1;
	if (jn == 9) { in++; jn = 1; }
	if (b3(i, j)) {
		f3(i, j); n--;
		if ((sum == 0 && n == 0) || f(i, j)) {
			cout << j << ' ' << i << ' ' << 3 << endl;
			return 1;
		}
		f3_(i, j); n++;
	}
	if (b2(i, j)) {
		f2(i, j); n--;
		if ((sum == 0 && n == 0) || f(i, j)) {
			cout << j << ' ' << i << ' ' << 2 << endl;
			return 1;
		}
		f2_(i, j); n++;
	}
	if (b1(i, j)) {
		if (b3(i, j + 1)) {
			f3(i, j + 1); n--;
			if ((sum == 0 && n == 0) || f(i, j)) {
				cout << j + 1 << ' ' << i << ' ' << 3 << endl;
				return 1;
			}
			f3_(i, j + 1); n++;
		}
		if (b3(i + 1, j)) {
			f3(i + 1, j); n--;
			if ((sum == 0 && n == 0) || f(i, j)) {
				cout << j << ' ' << i + 1 << ' ' << 3 << endl;
				return 1;
			}
			f3_(i + 1, j); n++;
		}
		f1(i, j); n--;
		if ((sum == 0 && n == 0) || f(i, j)) {
			cout << j << ' ' << i << ' ' << 1 << endl;
			return 1;
		}
		f1_(i, j); n++;
	}
	if (f(in, jn))return 1;
	return 0;
}
signed main() {
	cin >> n;
	for0(i, 10)for0(j, 10) { cin >> mp[i][j]; sum += mp[i][j]; }
	f(1, 1);
}
accuracy: 1
time_ms: 6860
memory_kb: 3112
final_rank: 10

code_snippet: #include<iostream>
using namespace std;
int N;
int S[10][10];
int A[5][2]={{1,0},{0,1},{-1,0},{0,-1},{0,0}};
int B[9][2]={{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1},{0,0}};
int C[13][2]={{2,0},{0,-2},{-2,0},{0,2},{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1},{0,0}};
int cnt;
bool dfs(int x,int y,int id,int t)
{
	if(id==N)
	{
		return cnt==0;
	}
	if(t==0)
	{
		int k;
		for(k=0;k<5;k++)
		{
			int tx=x+A[k][0],ty=y+A[k][1];
			if(0<=tx&&tx<10&&0<=ty&&ty<10)
			{
				if(S[tx][ty]==0)break;
				S[tx][ty]--;
				cnt--;
			}
		}
		if(k==5)
		{
			if(dfs(x,y,id+1,t))
			{
				cout<<y<<" "<<x<<" "<<1<<endl;
				return true;
			}
		}
		for(;k--;)
		{
			int tx=x+A[k][0],ty=y+A[k][1];
			if(0<=tx&&tx<10&&0<=ty&&ty<10)S[tx][ty]++,cnt++;
		}
		return dfs(x,y,id,t+1);
	}
	else if(t==1)
	{
		int k;
		for(k=0;k<9;k++)
		{
			int tx=x+B[k][0],ty=y+B[k][1];
			if(0<=tx&&tx<10&&0<=ty&&ty<10)
			{
				if(S[tx][ty]==0)break;
				S[tx][ty]--;
				cnt--;
			}
		}
		if(k==9)
		{
			if(dfs(x,y,id+1,t))
			{
				cout<<y<<" "<<x<<" "<<2<<endl;
				return true;
			}
		}
		for(;k--;)
		{
			int tx=x+B[k][0],ty=y+B[k][1];
			if(0<=tx&&tx<10&&0<=ty&&ty<10)S[tx][ty]++,cnt++;
		}
		return dfs(x,y,id,t+1);
	}
	else if(t==2)
	{
		int k;
		for(k=0;k<13;k++)
		{
			int tx=x+C[k][0],ty=y+C[k][1];
			if(0<=tx&&tx<10&&0<=ty&&ty<10)
			{
				if(S[tx][ty]==0)break;
				S[tx][ty]--;
				cnt--;
			}
		}
		if(k==13)
		{
			if(dfs(x,y,id+1,t))
			{
				cout<<y<<" "<<x<<" "<<3<<endl;
				return true;
			}
		}
		for(;k--;)
		{
			int tx=x+C[k][0],ty=y+C[k][1];
			if(0<=tx&&tx<10&&0<=ty&&ty<10)S[tx][ty]++,cnt++;
		}
		if(x>=2)
		{
			if(S[x-2][y]>0)return false;
		}
		return dfs(y==9?x+1:x,y==9?0:y+1,id,0);
	}
}
main()
{
	cin>>N;
	for(int i=0;i<10;i++)for(int j=0;j<10;j++)
	{
		cin>>S[i][j];
		cnt+=S[i][j];
	}
	dfs(0,0,0,0);
}
accuracy: 1
time_ms: 50
memory_kb: 3116
final_rank: 1

code_snippet: #define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int n, F[100], A[100];
int px[15], py[15];

bool func(int pos, int cnt, int num){
	if(cnt > n){
		return false;
	}
	if(pos == 100){
		return cnt == n;
	}
	if(A[pos] < 0){
		return false;
	}
	if(A[pos] == 0){
		return func(pos + 1, cnt, num);
	}
	int x = pos % 10, y = pos / 10;
	if(num % 3 == 0){
		if(x == 0 || x == 9 || y >= 8){
			return false;
		}
		A[y * 10 + x] -= 1;
		A[(y + 1) * 10 + x - 1] -= 1;
		A[(y + 1) * 10 + x] -= 1;
		A[(y + 1) * 10 + x + 1] -= 1;
		A[(y + 2) * 10 + x] -= 1;
		px[cnt] = x;
		py[cnt] = y + 1;
	}else if(num % 3 == 1){
		if(x >= 8 || y >= 8){
			return false;
		}
		A[y * 10 + x] -= 1;
		A[y * 10 + x + 1] -= 1;
		A[y * 10 + x + 2] -= 1;
		A[(y + 1) * 10 + x] -= 1;
		A[(y + 1) * 10 + x + 1] -= 1;
		A[(y + 1) * 10 + x + 2] -= 1;
		A[(y + 2) * 10 + x] -= 1;
		A[(y + 2) * 10 + x + 1] -= 1;
		A[(y + 2) * 10 + x + 2] -= 1;
		px[cnt] = x + 1;
		py[cnt] = y + 1;
	}else{
		if(x <= 1 || x >= 8 || y >= 6){
			return false;
		}
		A[y * 10 + x] -= 1;
		A[(y + 1) * 10 + x - 1] -= 1;
		A[(y + 1) * 10 + x] -= 1;
		A[(y + 1) * 10 + x + 1] -= 1;
		A[(y + 2) * 10 + x - 2] -= 1;
		A[(y + 2) * 10 + x - 1] -= 1;
		A[(y + 2) * 10 + x] -= 1;
		A[(y + 2) * 10 + x + 1] -= 1;
		A[(y + 2) * 10 + x + 2] -= 1;
		A[(y + 3) * 10 + x - 1] -= 1;
		A[(y + 3) * 10 + x] -= 1;
		A[(y + 3) * 10 + x + 1] -= 1;
		A[(y + 4) * 10 + x] -= 1;
		px[cnt] = x;
		py[cnt] = y + 2;
	}
	return func(pos, cnt + 1, num / 3);
}

int main(){
	cin >> n;
	for(int i = 0; i < 100; i++){
		cin >> F[i];
	}
	int lim = 1;
	for(int i = 0; i < n; i++){
		lim *= 3;
	}
	int ans = 0;
	for(int i = 0; i < lim; i++){
		copy(F, F + 100, A);
		if(func(0, 0, i)){
			ans = i;
			break;
		}
	}
	for(int i = 0; i < n; i++){
		cout << px[i] << " " << py[i] << " " << ans % 3 + 1 << endl;
		ans /= 3;
	}
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3108
final_rank: 2

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

struct aa{
	int x;
	int y;
	int t;
	aa(int a,int b,int c){
		x=a;
		y=b;
		t=c;
	}
};

int inks[3][5][5]={
	{
		{0,0,0,0,0},
		{0,0,1,0,0},
		{0,1,1,1,0},
		{0,0,1,0,0},
		{0,0,0,0,0},
	},
	{
		{0,0,0,0,0},
		{0,1,1,1,0},
		{0,1,1,1,0},
		{0,1,1,1,0},
		{0,0,0,0,0},
	},
	{
		{0,0,1,0,0},
		{0,1,1,1,0},
		{1,1,1,1,1},
		{0,1,1,1,0},
		{0,0,1,0,0},
	},
};

bool ok(const vector<vector<int>>&v,int ink_x,int ink_y,int ink_id){
	for(int dy=0;dy<5;++dy){
		for(int dx=0;dx<5;++dx){
			if(inks[ink_id][dy][dx]){
				int ax=ink_x-2+dx;
				int ay=ink_y-2+dy;

				if(ax<0||ax>=10||ay<0||ay>=10)return false;
				if(v[ay][ax]<=0)return false;
			}
		}
	}
	return true;
}

vector<aa>solve(int now_x,int now_y,int rest,vector<vector<int>>&v){
	if(rest==0){
		bool ok=true;
		for(int i=0;i<10;++i){
			for(int j=0;j<10;++j){
				if(v[i][j])ok=false;
			}
		}
		aa k=aa(-1,-1,-1);
		if(ok)return vector<aa>();
		else return vector<aa>(1,aa(-1,-1,-1));
	}
	if(now_y==10){
		return vector<aa>(1,aa(-1,-1,-1));
	}
	if(now_y>=3&&now_x==0){
		for(int y=0;y<now_y-2;++y){
			for(int x=0;x<10;++x){
				if(v[y][x])return vector<aa>(1,aa(-1,-1,-1));
			}
		}
	}
	
	for(int ink_id=0;ink_id<=2;++ink_id){
		if(ok(v,now_x,now_y,ink_id)){
			for(int dy=0;dy<5;++dy){
				for(int dx=0;dx<5;++dx){
					if(inks[ink_id][dy][dx]){
						int ax=now_x-2+dx;
						int ay=now_y-2+dy;

						if(ax<0||ax>=10||ay<0||ay>=10)assert(false);
						if(v[ay][ax]<=0)assert(false);

						v[ay][ax]--;
					}
				}
			}
			vector<aa>aas=solve(now_x,now_y,rest-1,v);
			for(int dy=0;dy<5;++dy){
				for(int dx=0;dx<5;++dx){
					if(inks[ink_id][dy][dx]){
						int ax=now_x-2+dx;
						int ay=now_y-2+dy;
						v[ay][ax]++;
					}
				}
			}
			if(aas.size()==1&&aas[0].x==-1)continue;
			else{
				aas.push_back(aa(now_x,now_y,ink_id));
				return aas;
			}
		}
	}
	int next_x=now_x+1;
	int next_y=now_y;
	if(next_x==10){
		next_x=0;
		next_y=next_y+1;
	}
	return solve(next_x,next_y,rest,v);
}

int main() { 
	int N;cin>>N;
	vector<vector<int>>v(10,vector<int>(10));
	for(int i=0;i<10;++i){
		for(int j=0;j<10;++j){
			cin>>v[i][j];
		}
	}
	auto p=solve(0,0,N,v);
	for(int i=0;i<p.size();++i){
		cout<<p[i].x<<" "<<p[i].y<<" "<<p[i].t+1<<endl;
	}
	//cout<<"0"<<endl;
	return 0;
}
accuracy: 1
time_ms: 1770
memory_kb: 3148
final_rank: 6

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N,ans[10][10];
int diff_row_1[5] = {-1,0,0,0,1},diff_col_1[5] = {0,-1,0,1,0};
int diff_row_2[9] = {-1,-1,-1,0,0,0,1,1,1},diff_col_2[9] = {-1,0,1,-1,0,1,-1,0,1};
int diff_row_3[13] = {-2,-1,-1,-1,0,0,0,0,0,1,1,1,2},diff_col_3[13] = {0,-1,0,1,-2,-1,0,1,2,-1,0,1,0};
bool Found = false;

struct Info{
	void set(int arg_x,int arg_y,int arg_size){
		x = arg_x;
		y = arg_y;
		size = arg_size;
	}
	int x,y,size;
};

struct Data{
	int table[10][10];
	Info info[13];
	int count;
};

Info result[13];

void recursive(int base_row,int base_col,Data data){

	if(Found == true)return;

	bool FLG;

	if(data.count == N){

		FLG = true;

		for(int row = 0; row < 10; row++){
			for(int col = 0; col < 10; col++){
				if(data.table[row][col] != ans[row][col]){
					FLG = false;
					break;
				}
			}
			if(!FLG)break;
		}

		if(FLG){

			for(int i = 0; i < N; i++){
				result[i].set(data.info[i].x,data.info[i].y,data.info[i].size);
			}
			Found = true;
		}
		return;
	}

	for(int row = 0; row <= base_row-3; row++){
		for(int col = 0; col < 10; col++){
			if(data.table[row][col] != ans[row][col])return;
		}
	}

	if(base_row >= 2){
		for(int col = 0; col < base_col; col++){
			if(data.table[base_row-2][col] != ans[base_row-2][col])return;
		}
	}


	bool size_1 = true,size_2 = true,size_3 = true;

	//size_1
	for(int i = 0; i < 5; i++){
		if(data.table[base_row+diff_row_1[i]][base_col+diff_col_1[i]] >= ans[base_row+diff_row_1[i]][base_col+diff_col_1[i]]){
			size_1 = false;
			break;
		}
	}

	//size_2
	for(int i = 0; i < 9; i++){
		if(data.table[base_row+diff_row_2[i]][base_col+diff_col_2[i]] >= ans[base_row+diff_row_2[i]][base_col+diff_col_2[i]]){
			size_2 = false;
			break;
		}
	}

	//size_3
	for(int i = 0; i < 13; i++){
		if(data.table[base_row+diff_row_3[i]][base_col+diff_col_3[i]] >= ans[base_row+diff_row_3[i]][base_col+diff_col_3[i]]){
			size_3 = false;
			break;
		}
	}

	if(base_col == 9){

		if(base_row == 9)return;
		recursive(base_row+1,0,data);
	}else{
		recursive(base_row,base_col+1,data);
	}

	if(size_1){

		Data next;
		for(int i = 0; i < 10; i++){
			for(int k = 0; k < 10; k++)next.table[i][k] = data.table[i][k];
		}
		//垂らす
		for(int i = 0; i < 5; i++){
			next.table[base_row+diff_row_1[i]][base_col+diff_col_1[i]]++;
		}

		for(int i = 0; i < data.count;i++){
			next.info[i].set(data.info[i].x,data.info[i].y,data.info[i].size);
		}
		next.info[data.count].set(base_col,base_row,1);
		next.count = data.count+1;

		recursive(base_row,base_col,next);
	}

	if(size_2){

		Data next;
		for(int i = 0; i < 10; i++){
			for(int k = 0; k < 10; k++)next.table[i][k] = data.table[i][k];
		}
		//垂らす
		for(int i = 0; i < 9; i++){
			next.table[base_row+diff_row_2[i]][base_col+diff_col_2[i]]++;
		}

		for(int i = 0; i < data.count;i++){
			next.info[i].set(data.info[i].x,data.info[i].y,data.info[i].size);
		}
		next.info[data.count].set(base_col,base_row,2);
		next.count = data.count+1;

		recursive(base_row,base_col,next);
	}

	if(size_3){
		Data next;
		for(int i = 0; i < 10; i++){
			for(int k = 0; k < 10; k++)next.table[i][k] = data.table[i][k];
		}
		//垂らす
		for(int i = 0; i < 13; i++){
			next.table[base_row+diff_row_3[i]][base_col+diff_col_3[i]]++;
		}

		for(int i = 0; i < data.count;i++){
			next.info[i].set(data.info[i].x,data.info[i].y,data.info[i].size);
		}
		next.info[data.count].set(base_col,base_row,3);
		next.count = data.count+1;

		recursive(base_row,base_col,next);
	}
}


int main(){

	scanf("%d",&N);

	Data first;
	first.count = 0;

	for(int i = 0; i < 10; i++){
		for(int k = 0; k < 10; k++){
			scanf("%d",&ans[i][k]);
			first.table[i][k] = 0;
		}
	}

	recursive(1,1,first);

	for(int i = 0; i < N; i++){
		printf("%d %d %d\n",result[i].x,result[i].y,result[i].size);
	}

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3320
final_rank: 4

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

vector<pii> ansa, ansb, ansc;

int cc = 0;

void dfs(int y, int x, vector<vector<int>> &v, vector<pii> &a, vector<pii> &b, vector<pii> &c, int less ){
    cc++;
//    if( ansa.size() || ansb.size() || ansc.size() )return ;
    if(less <= 0){
        for(int i=y;i<10;i++){
            rep(j,10){
                if(v[i][j]==1)return ;
            }
        }
        ansa = a;
        ansb = b;
        ansc = c;
        
        return ;
    }
    rep(i,10){
        rep(j,10){
            if( v[i][j]==1 ){
                if( i+2 >= 10 )continue;
                if( j==0 || v[i+1][j-1]==0 ){
                    if(j+2 >= 10 )continue;
                    bool ng = false;
                    rep(k,3){
                        rep(l,3){
                            v[i+k][j+l] --;
                            if( v[i+k][j+l]<0 )ng = true;
                        }
                    }
                    a.push_back(pii(i+1,j+1));
                    if( !ng ) dfs(i, j, v, a, b, c, less-1);
                    a.pop_back();
                    rep(k,3){
                        rep(l,3){
                            v[i+k][j+l] ++;
                        }
                    }
                }
                else{
                    if( i+2 >= 10 || j+1 >= 10 )continue;
                    
                    int dx1[] = {0, 0, 0, -1, 1};
                    int dy1[] = {0, 1, 2, 1, 1};
                    
                    bool ng = false;
                    rep(k,5){
                        int ddy = i+dy1[k];
                        int ddx = j+dx1[k];
                        v[ddy][ddx]--;
                        if( v[ddy][ddx] < 0 )ng = true;
                    }
                    b.push_back(pii(i+1,j));
                    if( !ng ) dfs(i, j, v, a, b, c, less-1);
                    b.pop_back();
                    rep(k,5){
                        int ddy = i+dy1[k];
                        int ddx = j+dx1[k];
                        v[ddy][ddx]++;
                    }
                    
                    if(j+2>=10 || i+4 >= 10)continue;
                    
                    int dx2[] = {0, 0, -2, 2};
                    int dy2[] = {0, 4, 2, 2};
                    ng = false;
                    rep(k,4){
                        int ddy = i+dy2[k];
                        int ddx = j+dx2[k];
                        v[ddy][ddx]--;
                        if( v[ddy][ddx] < 0 )ng = true;
                    }
                    rep(k,3){
                        rep(l,3){
                            v[i+k+1][j+l-1]--;
                            if( v[i+k+1][j+l-1]<0 )ng = true;
                        }
                    }
                    c.push_back(pii(i+2,j));
                    if( !ng ) dfs(i, j, v, a, b, c, less-1);
                    c.pop_back();
                    rep(k,4){
                        int ddy = i+dy2[k];
                        int ddx = j+dx2[k];
                        v[ddy][ddx]++;
                    }
                    rep(k,3){
                        rep(l,3){
                            v[i+k+1][j+l-1]++;
                        }
                    }
                }
                goto end;
            }
        }
    end:;
    }
}

int main(){
    int n;
    cin>>n;
    vector<vector<int>> v(10,vector<int>(10));
    
    rep(i,10)rep(j,10)cin>>v[i][j];
    
    vector<pii> a, b, c;    //3*3, +, ++
    
    dfs(0, 0, v, a, b, c, n);
    
    rep(i,ansa.size()){
        cout<<ansa[i].second<<" "<<ansa[i].first<<" "<<2<<endl;
    }
    rep(i,ansb.size()){
        cout<<ansb[i].second<<" "<<ansb[i].first<<" "<<1<<endl;
    }
    rep(i,ansc.size()){
        cout<<ansc[i].second<<" "<<ansc[i].first<<" "<<3<<endl;
    }
}
accuracy: 0.1111111111111111
time_ms: 300
memory_kb: 3104
final_rank: 19

code_snippet: #include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <random>
#include <cstdlib>
#include <cmath>
#include <sstream>
using namespace std;

int small[][5]{
	0,0,1,0,0,
	0,1,1,1,0,
	0,0,1,0,0,
	0,0,0,0,0,
	0,0,0,0,0
};
pair<int, int> smallCenter = { 0,1 };

int middle[][5]{
	0,0,1,1,1,
	0,0,1,1,1,
	0,0,1,1,1,
	0,0,0,0,0,
	0,0,0,0,0
};
pair<int, int> middleCenter = { 1,1 };

int big[][5]{
	0,0,1,0,0,
	0,1,1,1,0,
	1,1,1,1,1,
	0,1,1,1,0,
	0,0,1,0,0
};
pair<int, int> bigCenter = { 0,2 };

pair<pair<int, int>, int> point[12];
int table[10][10];

bool clearCheck() {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (table[i][j] != 0) return false;
		}
	}
	return true;
}
bool removeCheck(int y, int x, int drop[][5]) {
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			if (!drop[i][j]) continue;
			if (x + j - 2 < 0 || x + j - 2 >= 10) return false;
			if (y + i < 0 || y + i >= 10) return false;
			if (!table[y + i][x + j - 2]) return false;
		}
	}
	return true;
}

void remove(int y, int x, int drop[][5]) {
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			table[y + i][x + j - 2] -= drop[i][j];
		}
	}
}

void add(int y, int x, int drop[][5]) {
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			table[y + i][x + j - 2] += drop[i][j];
		}
	}
}

bool rec(int i, int j, int c) {
	if (c < 0) return clearCheck();
	while (1) {
		j++;
		i += j / 10;
		j = j % 10;
		if (i == 10) break;

		if (table[i][j]) {
			if (removeCheck(i, j, small)) {
				point[c] = make_pair(make_pair(i + smallCenter.second, j + smallCenter.first), 1);
				remove(i, j, small);
				if (rec(i, j, c - 1)) return true;
				add(i, j, small);
			}

			if (removeCheck(i, j, middle)) {
				point[c] = make_pair(make_pair(i + middleCenter.second, j + middleCenter.first), 2);
				remove(i, j, middle);
				if (rec(i, j, c - 1)) return true;
				add(i, j, middle);
			}

			if (removeCheck(i, j, big)) {
				point[c] = make_pair(make_pair(i + bigCenter.second, j + bigCenter.first), 3);
				remove(i, j, big);
				if (rec(i, j, c - 1)) return true;
				add(i, j, big);
			}
		}
	}
	return false;
}
void q91() {
	int n;
	for (; cin >> n;) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				cin >> table[i][j];
			}
		}
		rec(0, 0, n - 1);
		for (int i = 0; i < n; i++) {
			cout << point[i].first.second << " " << point[i].first.first << " " << point[i].second << endl;
		}
	}
}

int main() {
	q91();
	return 0;
}
accuracy: 0.1111111111111111
time_ms: 3590
memory_kb: 3088
final_rank: 20

code_snippet: #include <bits/stdc++.h>


#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
using namespace std;


int main()
{
	int t;
	cin >>t;
	array<array<int,10>, 10> ba;
	rep(i,10) rep(j,10) cin >>ba[i][j];
	
	vector<vector<array<int, 2>>> mdl={
		{{0,0},{1,0}, {1,-1}, {1,1},{2,0}},
		{{0,0},{1,1},{0,1},{0,2},{1,0},{1,2},{2,0},{2,1},{2,2}},
		{{0,0},{2,0},{1,-1},{1,0},{1,1},{2,-2},{2,-1},{2,1},{2,2},
		 {3,-1},{3,0},{3,1},{4,0}}
	};
	
	int gk=0;
	rep(i,10) rep(j,10) gk+=ba[i][j];
	
	vector<int> cnd;
	rep(a,t+1) rep(b,t+1) rep(c,t+1){
		if(a+b+c==t && 5*a + 9*b + 13*c == gk){
		
			string s = string(a, '0') + string(b, '1') + string(c, '2');
			do {
				auto wa = ba;
				vector<int> ans;
				bool ok=1; 
				rep(i,t){
					if(!ok) break;
					int my,mx;
					rep(y,10) rep(x,10) if(wa[y][x]>0){my=y; mx=x; y=100; break;}
					ans.push_back(my*100+mx);
					int cr=s[i]-'0';
					
					for(auto r: mdl[cr]) if(ok){
						int ny=r[0]+my, nx=r[1]+mx;
						if(ny<0 || ny>=10 || nx<0 || nx>=10){ ok=0; break;}
						if(wa[ny][nx] >0 ) wa[ny][nx]--;
						else if(wa[ny][nx] <1 ){ ok=0; break;}
					}
				}
				bool ng=0;
				rep(y,10) rep(x,10) if(wa[y][x] !=0) ng=1;
				//rep(y,10) rep(x,10) printf("%d%s",wa[y][x],(x==9? "\n":" "));
				if(!ng){
					rep(i,t){
						printf("%d %d %d\n", 
							ans[i]%100 + mdl[s[i]-'0'][1][1],
							ans[i]/100 + mdl[s[i]-'0'][1][0],
							s[i]-'0'+1);
					}
					return 0;
				}
			} while ( next_permutation(s.begin(), s.end()) );
		}
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3304
final_rank: 3

code_snippet: #include <bits/stdc++.h>


#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
using namespace std;


int main()
{
	int t;
	cin >>t;
	array<array<int,10>, 10> ba;
	rep(i,10) rep(j,10) cin >>ba[i][j];
	
	vector<vector<array<int, 2>>> mdl={
		{{0,0},{1,0}, {1,-1}, {1,1},{2,0}},
		{{0,0},{1,1},{0,1},{0,2},{1,0},{1,2},{2,0},{2,1},{2,2}},
		{{0,0},{2,0},{1,-1},{1,0},{1,1},{2,-2},{2,-1},{2,1},{2,2},
		 {3,-1},{3,0},{3,1},{4,0}}
	};
	
	int gk=0;
	rep(i,10) rep(j,10) gk+=ba[i][j];
	
	vector<int> cnd;
	rep(a,t+1) rep(b,t+1) rep(c,t+1){
		if(a+b+c==t && 5*a + 9*b + 13*c == gk){
		
			string s = string(a, '0') + string(b, '1') + string(c, '2');
			do {
				auto wa = ba;
				vector<int> ans;
				rep(i,t){
					int my,mx;
					rep(y,10) rep(x,10) if(wa[y][x]>0){my=y; mx=x; y=100; break;}
					ans.push_back(my*100+mx);
					bool ok=1; 
					int cr=s[i]-'0';
					
					for(auto r: mdl[cr]) if(ok){
						int ny=r[0]+my, nx=r[1]+mx;
						if(ny<0 || ny>=10 || nx<0 || nx>=10){ ok=0; break;}
						if(wa[ny][nx] >0 ) wa[ny][nx]--;
						else if(wa[ny][nx] <1 ){ ok=0; break;}
					}
				}
				bool ng=0;
				rep(y,10) rep(x,10) if(wa[y][x] !=0) ng=1;
				//rep(y,10) rep(x,10) printf("%d%s",wa[y][x],(x==9? "\n":" "));
				if(!ng){
					rep(i,t){
						printf("%d %d %d\n", 
							ans[i]%100 + mdl[s[i]-'0'][1][1],
							ans[i]/100 + mdl[s[i]-'0'][1][0],
							s[i]-'0'+1);
					}
					return 0;
				}
			} while ( next_permutation(s.begin(), s.end()) );
		}
	}
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3368
final_rank: 5

code_snippet: #include <cstdio>
#include <cstdlib>
#include <stack>
#include <utility>
using namespace std;

typedef pair<int, int> Pair;
typedef pair<int, Pair> Data;

int n;
int total;
int field[10][10];
stack<Data> ans;

int ex[] = {9, 0, 0, 9};
int ey[] = {0, 9, 0, 9};
int fx[] = {8, 1, 1, 8};
int fy[] = {1, 8, 1, 8};
int dx1[] = {-1, 0, 0, 0, 1};
int dy1[] = {0, -1, 0, 1, 0};
int dx2[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dy2[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dx3[] = {-2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int dy3[] = {0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0};
int used[10][10];

bool CheckPlace(int y, int x, int type) {
  if (type == 1) {
    for (int i=0; i<5; i++) {
      int newy = y + dy1[i];
      int newx = x + dx1[i];
      if (field[newy][newx] == 0) return false;
    }
  } else if (type == 2) {
    for (int i=0; i<9; i++) {
      int newy = y + dy2[i];
      int newx = x + dx2[i];
      if (field[newy][newx] == 0) return false;
    }
  } else if (type == 3) {
    for (int i=0; i<13; i++) {
      int newy = y + dy3[i];
      int newx = x + dx3[i];
      if (field[newy][newx] == 0) return false;
    }
  }

  return true;
}

void AddPlace(int (&field)[10][10], int y, int x, int type, int t) {
  if (type == 1) {
    for (int i=0; i<5; i++) {
      int newy = y + dy1[i];
      int newx = x + dx1[i];
      field[newy][newx] += t;
    }
  } else if (type == 2) {
    for (int i=0; i<9; i++) {
      int newy = y + dy2[i];
      int newx = x + dx2[i];
      field[newy][newx] += t;
    }
  } else if (type == 3) {
    for (int i=0; i<13; i++) {
      int newy = y + dy3[i];
      int newx = x + dx3[i];
      field[newy][newx] += t;
    }
  }
}

bool CheckImpossible() {
  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      used[i][j] = false;
    }
  }

  for (int i=1; i<9; i++) {
    for (int j=1; j<9; j++) {
      if (i > 1 && i < 8 && j < 8 && j > 1 && CheckPlace(i, j, 3)) {
        AddPlace(used, i, j, 3, 1);
      } else if (CheckPlace(i, j, 2)) {
        AddPlace(used, i, j, 2, 1);
      } else if (CheckPlace(i, j, 1)) {
        AddPlace(used, i, j, 1, 1);
      }
    }
  }

  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      if (field[i][j] && !used[i][j]) return true;
    }
  }

  return false;
}
void check(int x, int y, int z) {
  if (CheckImpossible()) return;

  if (y > 0) {
    for (int i=1; i<9; i++) {
      for (int j=1; j<9; j++) {
        if (CheckPlace(i, j, 2)) {
          AddPlace(field, i, j, 2, -1);
          ans.push(Data(2, Pair(i, j)));
          check(x, y-1, z);
          ans.pop();
          AddPlace(field, i, j, 2, 1);
        }
      }
    }

    return;
  }

  if (z > 0) {
    for (int i=2; i<8; i++) {
      for (int j=2; j<8; j++) {
        if (CheckPlace(i, j, 3)) {
          AddPlace(field, i, j, 3, -1);
          ans.push(Data(3, Pair(i, j)));
          check(x, y, z-1);
          ans.pop();
          AddPlace(field, i, j, 3, 1);
        }
      }
    }

    return;
  }

  if (x > 0) {
    for (int i=1; i<9; i++) {
      for (int j=1; j<9; j++) {
        if (CheckPlace(i, j, 1)) {
          AddPlace(field, i, j, 1, -1);
          ans.push(Data(1, Pair(i, j)));
          check(x-1, y, z);
          ans.pop();
          AddPlace(field, i, j, 1, 1);
        }
      }
    }

    return;
  }

  while (!ans.empty()) {
    Data d = ans.top(); ans.pop();
    int level = d.first;
    Pair p = d.second;
    printf("%d %d %d\n", p.second, p.first, level);
  }

  exit(0);
}

int main() {
  scanf("%d", &n);
  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      scanf("%d", &field[i][j]);
      total += field[i][j];
    }
  }

  for (int i=0; i<4; i++) {
    int y = ey[i];
    int x = ex[i];

    if (field[y][x]) {
      total -= field[y][x]*9;
      n -= field[y][x];
      for (int j=0; j<field[y][x]; j++) {
        ans.push(Data(2, Pair(fy[i], fx[i])));
      }
      AddPlace(field, fy[i], fx[i], 2, -field[y][x]);
    }
  }

  int x = 0;
  int y = (13*n-total)/4;
  while (y >= 0) {
    int z = n-(x+y);
    if (z < 0) {
      y -= 2;
      x += 1;
      continue;
    }

    check(x, y, z);
    y -= 2;
    x += 1;
  }

  while (!ans.empty()) {
    Data d = ans.top(); ans.pop();
    int level = d.first;
    Pair p = d.second;
    printf("%d %d %d\n", p.second, p.first, level);
  }
}
accuracy: 1
time_ms: 4860
memory_kb: 2764
final_rank: 8

code_snippet: #include<iostream>
#include<queue>
#include<vector>
#include<tuple>
#include<cstdlib>
#include<ctime>
#include<algorithm>
using namespace std;
vector<vector<char>>S; int n;
bool dp[13][160]; int LIM2 = 0; int _size = 0; int CC = 0;
vector<vector<char>> solve(vector<vector<char>>p, int x, int y, int r) {
	if (r == 1) { p[x][y]--; p[x + 1][y]--; p[x - 1][y]--; p[x][y - 1]--; p[x][y + 1]--; }
	if (r == 2) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; }
	if (r == 3) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; p[x + 2][y]--; p[x][y + 2]--; p[x - 2][y]--; p[x][y - 2]--; }
	return p;
}
bool isgood(int p) {
	if (p % 4 == 1 && p >= 5)return true;
	if (p % 4 == 2 && p >= 10)return true;
	if (p % 4 == 3 && p >= 15)return true;
	if (p % 4 == 0 && p >= 20)return true;
	return false;
}
bool hantei(vector<vector<char>>p) {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (p[i][j] < 0)return false;
		}
	}
	bool OKs[10][10]; for (int i = 0; i < 100; i++)OKs[i / 10][i % 10] = false;
	for (int i = 1; i < 9; i++) {
		for (int j = 1; j < 9; j++) {
			if (p[i][j] == 0)continue; bool OK6 = false;
			if (p[i - 1][j] >= 1 && p[i + 1][j] >= 1 && p[i][j - 1] >= 1 && p[i][j + 1] >= 1) {
				OK6 = true; OKs[i][j] = true; OKs[i - 1][j] = true; OKs[i][j - 1] = true; OKs[i][j + 1] = true; OKs[i + 1][j] = true;
			}
			if (OK6 == false)continue;
			bool OK4 = true;
			for (int k = -1; k <= 1; k++)for (int l = -1; l <= 1; l++)if (p[i + k][j + l] == 0)OK4 = false;
			if (OK4 == false)continue;
			for (int k = -1; k <= 1; k++)for (int l = -1; l <= 1; l++)OKs[i + k][j + l] = true;
		}
	}
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			if (OKs[i][j] == false && p[i][j] >= 1)return false;
		}
	}
	queue<pair<int, int>>Q3; bool OK5[10][10]; for (int i = 0; i < 100; i++)OK5[i / 10][i % 10] = false;
	if (rand() % 9 <= 1 && n == 12 && _size >= 1000)return false;
	return true;
}
vector<tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>>>Vec;
void zen_shori() {
	int JJ = 165; if (LIM2 == 2)JJ = 27061;
	for (int i = 0; i < JJ; i++) {
		tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>>ZZ;
		Vec.push_back(ZZ);
	}
	vector<vector<char>>ZERO; int LL = 0, RR = 0;
	vector<tuple<char, char, char>>ZERO3;
	for (int i = 0; i < 10; i++) { vector<char>ZERO5(10, 0); ZERO.push_back(ZERO5); }
	Vec[0] = make_tuple(ZERO, 0, ZERO3); RR++;
	while (LL < RR && RR < JJ) {
		vector<vector<char>>a1 = get<0>(Vec[LL]); int a2 = get<1>(Vec[LL]);
		vector<tuple<char, char, char>>a3 = get<2>(Vec[LL]);
		LL++; if (a2 == LIM2)continue;
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };
		for (int i = 1; i <= 3; i++) {
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					vector<vector<char>>a4 = solve(a1, j, k, i);
					vector<tuple<char, char, char>>a5 = a3; a5.push_back(make_tuple(j, k, i));
					if (RR < JJ) { Vec[RR] = make_tuple(a4, a2 + 1, a5); RR++; }
				}
			}
		}
	}
	for (int i = 0; i < Vec.size(); i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				get<0>(Vec[i])[j][k] *= -1;
			}
		}
	}
	sort(Vec.begin(), Vec.end());
}
int main() {
	srand((unsigned)time(NULL));
	cin >> n; dp[0][0] = true;
	LIM2 = 2;
	for (int i = 0; i < 12; i++) {
		for (int j = 0; j < 160; j++) {
			if (dp[i][j] == false)continue;
			dp[i + 1][j + 5] = true; dp[i + 1][j + 9] = true; dp[i + 1][j + 13] = true;
		}
	}
	for (int i = 0; i < 10; i++) { vector<char>V(10, 0); S.push_back(V); }
	vector<vector<char>>START = S; int SUM = 0;
	for (int i = 0; i < 10; i++)for (int j = 0; j < 10; j++) { int SS; cin >> SS; S[i][j] = SS; SUM += S[i][j]; }
	queue<tuple<int, vector<tuple<char, char, char>>, int>> Q;
	vector<tuple<char, char, char>>ZERO;
	Q.push(make_tuple(0, ZERO, SUM));
	zen_shori(); CC = SUM;

	while (!Q.empty()) {
		vector<vector<char>>a1 = S; int a2 = get<0>(Q.front());
		vector<tuple<char, char, char>>a3 = get<1>(Q.front()); int a4 = get<2>(Q.front()); Q.pop(); _size = Q.size();
		for (int i = 0; i < a3.size(); i++) {
			a1 = solve(a1, get<0>(a3[i]), get<1>(a3[i]), get<2>(a3[i]));
		}
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };
		for (int i = 1; i <= 3; i++) {
			int rem1 = a4 - P[i], rem2 = n - (a2 + 1); bool OK = true;
			if (dp[rem2][rem1] == false)OK = false;
			if (OK == false)continue;
			int LIM = 0; if (a3.size() >= 1) LIM = get<0>(a3[a3.size() - 1]) * 100 + get<1>(a3[a3.size() - 1]) * 10 + get<2>(a3[a3.size() - 1]);
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					int DD = j * 100 + k * 10 + i;
					if (DD < LIM) continue;
					vector<vector<char>>G = solve(a1, j, k, i);
					vector<tuple<char, char, char>>H = a3;
					if (hantei(G) == false)continue;
					H.push_back(make_tuple(j, k, i));
					if (G == START && a2 + 1 == n) {
						for (int j = 0; j < H.size(); j++) {
							cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl;
						}
						goto E;
					}
					if (a2 + 1 >= n - LIM2) {
						int P = lower_bound(Vec.begin(), Vec.end(), make_tuple(G, 0, ZERO)) - Vec.begin();
						if (P < Vec.size() && get<0>(Vec[P]) == G) {
							for (int j = 0; j < H.size(); j++) {
								cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl;
							}
							vector<tuple<char, char, char>>J = get<2>(Vec[P]);
							for (int j = 0; j < J.size(); j++) {
								cout << (int)get<1>(J[j]) << ' ' << (int)get<0>(J[j]) << ' ' << (int)get<2>(J[j]) << endl;
							}
							goto E;
						}
					}
					Q.push(make_tuple(a2 + 1, H, a4 - P[i]));
				}
			}
		}
	}
E:;
	return 0;
}
accuracy: 1
time_ms: 7780
memory_kb: 32276
final_rank: 11

code_snippet: #include<iostream>
#include<queue>
#include<vector>
#include<tuple>
#include<cstdlib>
#include<ctime>
#include<algorithm>
using namespace std;
vector<vector<char>>S; int n;
bool dp[13][160]; int LIM2 = 0; int _size = 0; int CC = 0;
vector<vector<char>> solve(vector<vector<char>>p, int x, int y, int r) {
	if (r == 1) { p[x][y]--; p[x + 1][y]--; p[x - 1][y]--; p[x][y - 1]--; p[x][y + 1]--; }
	if (r == 2) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; }
	if (r == 3) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; p[x + 2][y]--; p[x][y + 2]--; p[x - 2][y]--; p[x][y - 2]--; }
	return p;
}
bool isgood(int p) {
	if (p % 4 == 1 && p >= 5)return true;
	if (p % 4 == 2 && p >= 10)return true;
	if (p % 4 == 3 && p >= 15)return true;
	if (p % 4 == 0 && p >= 20)return true;
	return false;
}
bool hantei(vector<vector<char>>p) {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (p[i][j] < 0)return false;
		}
	}
	bool OKs[10][10]; for (int i = 0; i < 100; i++)OKs[i / 10][i % 10] = false;
	for (int i = 1; i < 9; i++) {
		for (int j = 1; j < 9; j++) {
			if (p[i][j] == 0)continue; bool OK6 = false;
			if (p[i - 1][j] >= 1 && p[i + 1][j] >= 1 && p[i][j - 1] >= 1 && p[i][j + 1] >= 1) {
				OK6 = true; OKs[i][j] = true; OKs[i - 1][j] = true; OKs[i][j - 1] = true; OKs[i][j + 1] = true; OKs[i + 1][j] = true;
			}
			if (OK6 == false)continue;
			bool OK4 = true;
			for (int k = -1; k <= 1; k++)for (int l = -1; l <= 1; l++)if (p[i + k][j + l] == 0)OK4 = false;
			if (OK4 == false)continue;
			for (int k = -1; k <= 1; k++)for (int l = -1; l <= 1; l++)OKs[i + k][j + l] = true;
		}
	}
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			if (OKs[i][j] == false && p[i][j] >= 1)return false;
		}
	}
	queue<pair<int, int>>Q3; bool OK5[10][10]; for (int i = 0; i < 100; i++)OK5[i / 10][i % 10] = false;
	if (rand() % 37 <= 7 && n == 12 && _size >= 1000)return false;
	return true;
}
vector<tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>>>Vec;
void zen_shori() {
	int JJ = 165; if (LIM2 == 2)JJ = 27061;
	for (int i = 0; i < JJ; i++) {
		tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>>ZZ;
		Vec.push_back(ZZ);
	}
	vector<vector<char>>ZERO; int LL = 0, RR = 0;
	vector<tuple<char, char, char>>ZERO3;
	for (int i = 0; i < 10; i++) { vector<char>ZERO5(10, 0); ZERO.push_back(ZERO5); }
	Vec[0] = make_tuple(ZERO, 0, ZERO3); RR++;
	while (LL < RR && RR < JJ) {
		vector<vector<char>>a1 = get<0>(Vec[LL]); int a2 = get<1>(Vec[LL]);
		vector<tuple<char, char, char>>a3 = get<2>(Vec[LL]);
		LL++; if (a2 == LIM2)continue;
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };
		for (int i = 1; i <= 3; i++) {
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					vector<vector<char>>a4 = solve(a1, j, k, i);
					vector<tuple<char, char, char>>a5 = a3; a5.push_back(make_tuple(j, k, i));
					if (RR < JJ) { Vec[RR] = make_tuple(a4, a2 + 1, a5); RR++; }
				}
			}
		}
	}
	for (int i = 0; i < Vec.size(); i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				get<0>(Vec[i])[j][k] *= -1;
			}
		}
	}
	sort(Vec.begin(), Vec.end());
}
int main() {
	srand((unsigned)time(NULL));
	cin >> n; dp[0][0] = true;
	LIM2 = 2;
	for (int i = 0; i < 12; i++) {
		for (int j = 0; j < 160; j++) {
			if (dp[i][j] == false)continue;
			dp[i + 1][j + 5] = true; dp[i + 1][j + 9] = true; dp[i + 1][j + 13] = true;
		}
	}
	for (int i = 0; i < 10; i++) { vector<char>V(10, 0); S.push_back(V); }
	vector<vector<char>>START = S; int SUM = 0;
	for (int i = 0; i < 10; i++)for (int j = 0; j < 10; j++) { int SS; cin >> SS; S[i][j] = SS; SUM += S[i][j]; }
	queue<tuple<int, vector<tuple<char, char, char>>, int>> Q;
	vector<tuple<char, char, char>>ZERO;
	Q.push(make_tuple(0, ZERO, SUM));
	zen_shori(); CC = SUM;

	while (!Q.empty()) {
		vector<vector<char>>a1 = S; int a2 = get<0>(Q.front());
		vector<tuple<char, char, char>>a3 = get<1>(Q.front()); int a4 = get<2>(Q.front()); Q.pop(); _size = Q.size();
		for (int i = 0; i < a3.size(); i++) {
			a1 = solve(a1, get<0>(a3[i]), get<1>(a3[i]), get<2>(a3[i]));
		}
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };
		for (int i = 1; i <= 3; i++) {
			int rem1 = a4 - P[i], rem2 = n - (a2 + 1); bool OK = true;
			if (dp[rem2][rem1] == false)OK = false;
			if (OK == false)continue;
			int LIM = 0; if (a3.size() >= 1) LIM = get<0>(a3[a3.size() - 1]) * 100 + get<1>(a3[a3.size() - 1]) * 10 + get<2>(a3[a3.size() - 1]);
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					int DD = j * 100 + k * 10 + i;
					if (DD < LIM) continue;
					vector<vector<char>>G = solve(a1, j, k, i);
					vector<tuple<char, char, char>>H = a3;
					if (hantei(G) == false)continue;
					H.push_back(make_tuple(j, k, i));
					if (G == START && a2 + 1 == n) {
						for (int j = 0; j < H.size(); j++) {
							cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl;
						}
						goto E;
					}
					if (a2 + 1 >= n - LIM2) {
						int P = lower_bound(Vec.begin(), Vec.end(), make_tuple(G, 0, ZERO)) - Vec.begin();
						if (P < Vec.size() && get<0>(Vec[P]) == G) {
							for (int j = 0; j < H.size(); j++) {
								cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl;
							}
							vector<tuple<char, char, char>>J = get<2>(Vec[P]);
							for (int j = 0; j < J.size(); j++) {
								cout << (int)get<1>(J[j]) << ' ' << (int)get<0>(J[j]) << ' ' << (int)get<2>(J[j]) << endl;
							}
							goto E;
						}
					}
					Q.push(make_tuple(a2 + 1, H, a4 - P[i]));
				}
			}
		}
	}
E:;
	return 0;
}
accuracy: 0.5
time_ms: 4310
memory_kb: 26252
final_rank: 13

code_snippet: #include<iostream>
#include<queue>
#include<vector>
#include<tuple>
#include<cstdlib>
#include<ctime>
#include<algorithm>
using namespace std;
vector<vector<char>>S; int n;
bool dp[13][160]; int LIM2 = 0; int _size = 0; int CC = 0;
vector<vector<char>> solve(vector<vector<char>>p, int x, int y, int r) {
	if (r == 1) { p[x][y]--; p[x + 1][y]--; p[x - 1][y]--; p[x][y - 1]--; p[x][y + 1]--; }
	if (r == 2) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; }
	if (r == 3) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; p[x + 2][y]--; p[x][y + 2]--; p[x - 2][y]--; p[x][y - 2]--; }
	return p;
}
bool isgood(int p) {
	if (p % 4 == 1 && p >= 5)return true;
	if (p % 4 == 2 && p >= 10)return true;
	if (p % 4 == 3 && p >= 15)return true;
	if (p % 4 == 0 && p >= 20)return true;
	return false;
}
bool hantei(vector<vector<char>>p) {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (p[i][j] < 0)return false;
		}
	}
	bool OKs[10][10]; for (int i = 0; i < 100; i++)OKs[i / 10][i % 10] = false;
	for (int i = 1; i < 9; i++) {
		for (int j = 1; j < 9; j++) {
			if (p[i][j] == 0)continue; bool OK6 = false;
			if (p[i - 1][j] >= 1 && p[i + 1][j] >= 1 && p[i][j - 1] >= 1 && p[i][j + 1] >= 1) {
				OK6 = true; OKs[i][j] = true; OKs[i - 1][j] = true; OKs[i][j - 1] = true; OKs[i][j + 1] = true; OKs[i + 1][j] = true;
			}
			if (OK6 == false)continue;
			bool OK4 = true;
			for (int k = -1; k <= 1; k++)for (int l = -1; l <= 1; l++)if (p[i + k][j + l] == 0)OK4 = false;
			if (OK4 == false)continue;
			for (int k = -1; k <= 1; k++)for (int l = -1; l <= 1; l++)OKs[i + k][j + l] = true;
		}
	}
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			if (OKs[i][j] == false && p[i][j] >= 1)return false;
		}
	}
	queue<pair<int, int>>Q3; bool OK5[10][10]; for (int i = 0; i < 100; i++)OK5[i / 10][i % 10] = false;
	if (rand() % 19 <= 3 && n == 12 && _size >= 1000)return false;
	return true;
}
vector<tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>>>Vec;
void zen_shori() {
	int JJ = 165; if (LIM2 == 2)JJ = 27061;
	for (int i = 0; i < JJ; i++) {
		tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>>ZZ;
		Vec.push_back(ZZ);
	}
	vector<vector<char>>ZERO; int LL = 0, RR = 0;
	vector<tuple<char, char, char>>ZERO3;
	for (int i = 0; i < 10; i++) { vector<char>ZERO5(10, 0); ZERO.push_back(ZERO5); }
	Vec[0] = make_tuple(ZERO, 0, ZERO3); RR++;
	while (LL < RR && RR < JJ) {
		vector<vector<char>>a1 = get<0>(Vec[LL]); int a2 = get<1>(Vec[LL]);
		vector<tuple<char, char, char>>a3 = get<2>(Vec[LL]);
		LL++; if (a2 == LIM2)continue;
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };
		for (int i = 1; i <= 3; i++) {
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					vector<vector<char>>a4 = solve(a1, j, k, i);
					vector<tuple<char, char, char>>a5 = a3; a5.push_back(make_tuple(j, k, i));
					if (RR < JJ) { Vec[RR] = make_tuple(a4, a2 + 1, a5); RR++; }
				}
			}
		}
	}
	for (int i = 0; i < Vec.size(); i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				get<0>(Vec[i])[j][k] *= -1;
			}
		}
	}
	sort(Vec.begin(), Vec.end());
}
int main() {
	srand((unsigned)time(NULL));
	cin >> n; dp[0][0] = true;
	LIM2 = 2;
	for (int i = 0; i < 12; i++) {
		for (int j = 0; j < 160; j++) {
			if (dp[i][j] == false)continue;
			dp[i + 1][j + 5] = true; dp[i + 1][j + 9] = true; dp[i + 1][j + 13] = true;
		}
	}
	for (int i = 0; i < 10; i++) { vector<char>V(10, 0); S.push_back(V); }
	vector<vector<char>>START = S; int SUM = 0;
	for (int i = 0; i < 10; i++)for (int j = 0; j < 10; j++) { int SS; cin >> SS; S[i][j] = SS; SUM += S[i][j]; }
	queue<tuple<int, vector<tuple<char, char, char>>, int>> Q;
	vector<tuple<char, char, char>>ZERO;
	Q.push(make_tuple(0, ZERO, SUM));
	zen_shori(); CC = SUM;

	while (!Q.empty()) {
		vector<vector<char>>a1 = S; int a2 = get<0>(Q.front());
		vector<tuple<char, char, char>>a3 = get<1>(Q.front()); int a4 = get<2>(Q.front()); Q.pop(); _size = Q.size();
		for (int i = 0; i < a3.size(); i++) {
			a1 = solve(a1, get<0>(a3[i]), get<1>(a3[i]), get<2>(a3[i]));
		}
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };
		for (int i = 1; i <= 3; i++) {
			int rem1 = a4 - P[i], rem2 = n - (a2 + 1); bool OK = true;
			if (dp[rem2][rem1] == false)OK = false;
			if (OK == false)continue;
			int LIM = 0; if (a3.size() >= 1) LIM = get<0>(a3[a3.size() - 1]) * 100 + get<1>(a3[a3.size() - 1]) * 10 + get<2>(a3[a3.size() - 1]);
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					int DD = j * 100 + k * 10 + i;
					if (DD < LIM) continue;
					vector<vector<char>>G = solve(a1, j, k, i);
					vector<tuple<char, char, char>>H = a3;
					if (hantei(G) == false)continue;
					H.push_back(make_tuple(j, k, i));
					if (G == START && a2 + 1 == n) {
						for (int j = 0; j < H.size(); j++) {
							cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl;
						}
						goto E;
					}
					if (a2 + 1 >= n - LIM2) {
						int P = lower_bound(Vec.begin(), Vec.end(), make_tuple(G, 0, ZERO)) - Vec.begin();
						if (P < Vec.size() && get<0>(Vec[P]) == G) {
							for (int j = 0; j < H.size(); j++) {
								cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl;
							}
							vector<tuple<char, char, char>>J = get<2>(Vec[P]);
							for (int j = 0; j < J.size(); j++) {
								cout << (int)get<1>(J[j]) << ' ' << (int)get<0>(J[j]) << ' ' << (int)get<2>(J[j]) << endl;
							}
							goto E;
						}
					}
					Q.push(make_tuple(a2 + 1, H, a4 - P[i]));
				}
			}
		}
	}
E:;
	return 0;
}
accuracy: 0.5
time_ms: 4630
memory_kb: 26204
final_rank: 14

code_snippet: #include<iostream>
#include<queue>
#include<vector>
#include<tuple>
#include<cstdlib>
#include<ctime>
#include<algorithm>
using namespace std;
vector<vector<char>>S; int n;
bool dp[13][160]; int LIM2 = 0; int _size = 0; int CC = 0;
vector<vector<char>> solve(vector<vector<char>>p, int x, int y, int r) {
	if (r == 1) { p[x][y]--; p[x + 1][y]--; p[x - 1][y]--; p[x][y - 1]--; p[x][y + 1]--; }
	if (r == 2) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; }
	if (r == 3) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; p[x + 2][y]--; p[x][y + 2]--; p[x - 2][y]--; p[x][y - 2]--; }
	return p;
}
bool isgood(int p) {
	if (p % 4 == 1 && p >= 5)return true;
	if (p % 4 == 2 && p >= 10)return true;
	if (p % 4 == 3 && p >= 15)return true;
	if (p % 4 == 0 && p >= 20)return true;
	return false;
}
bool hantei(vector<vector<char>>p) {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (p[i][j] < 0)return false;
		}
	}
	bool OKs[10][10]; for (int i = 0; i < 100; i++)OKs[i / 10][i % 10] = false;
	for (int i = 1; i < 9; i++) {
		for (int j = 1; j < 9; j++) {
			if (p[i][j] == 0)continue; bool OK6 = false;
			if (p[i - 1][j] >= 1 && p[i + 1][j] >= 1 && p[i][j - 1] >= 1 && p[i][j + 1] >= 1) {
				OK6 = true; OKs[i][j] = true; OKs[i - 1][j] = true; OKs[i][j - 1] = true; OKs[i][j + 1] = true; OKs[i + 1][j] = true;
			}
			if (OK6 == false)continue;
			bool OK4 = true;
			for (int k = -1; k <= 1; k++)for (int l = -1; l <= 1; l++)if (p[i + k][j + l] == 0)OK4 = false;
			if (OK4 == false)continue;
			for (int k = -1; k <= 1; k++)for (int l = -1; l <= 1; l++)OKs[i + k][j + l] = true;
		}
	}
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			if (OKs[i][j] == false && p[i][j] >= 1)return false;
		}
	}
	queue<pair<int, int>>Q3; bool OK5[10][10]; for (int i = 0; i < 100; i++)OK5[i / 10][i % 10] = false;
	if (rand() % 6 == 0 && n == 12 && _size >= 1000)return false;
	return true;
}
vector<tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>>>Vec;
void zen_shori() {
	int JJ = 165; if (LIM2 == 2)JJ = 27061;
	for (int i = 0; i < JJ; i++) {
		tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>>ZZ;
		Vec.push_back(ZZ);
	}
	vector<vector<char>>ZERO; int LL = 0, RR = 0;
	vector<tuple<char, char, char>>ZERO3;
	for (int i = 0; i < 10; i++) { vector<char>ZERO5(10, 0); ZERO.push_back(ZERO5); }
	Vec[0] = make_tuple(ZERO, 0, ZERO3); RR++;
	while (LL < RR && RR < JJ) {
		vector<vector<char>>a1 = get<0>(Vec[LL]); int a2 = get<1>(Vec[LL]);
		vector<tuple<char, char, char>>a3 = get<2>(Vec[LL]);
		LL++; if (a2 == LIM2)continue;
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };
		for (int i = 1; i <= 3; i++) {
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					vector<vector<char>>a4 = solve(a1, j, k, i);
					vector<tuple<char, char, char>>a5 = a3; a5.push_back(make_tuple(j, k, i));
					if (RR < JJ) { Vec[RR] = make_tuple(a4, a2 + 1, a5); RR++; }
				}
			}
		}
	}
	for (int i = 0; i < Vec.size(); i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				get<0>(Vec[i])[j][k] *= -1;
			}
		}
	}
	sort(Vec.begin(), Vec.end());
}
int main() {
	srand((unsigned)time(NULL));
	cin >> n; dp[0][0] = true;
	LIM2 = 2;
	for (int i = 0; i < 12; i++) {
		for (int j = 0; j < 160; j++) {
			if (dp[i][j] == false)continue;
			dp[i + 1][j + 5] = true; dp[i + 1][j + 9] = true; dp[i + 1][j + 13] = true;
		}
	}
	for (int i = 0; i < 10; i++) { vector<char>V(10, 0); S.push_back(V); }
	vector<vector<char>>START = S; int SUM = 0;
	for (int i = 0; i < 10; i++)for (int j = 0; j < 10; j++) { int SS; cin >> SS; S[i][j] = SS; SUM += S[i][j]; }
	queue<tuple<int, vector<tuple<char, char, char>>, int>> Q;
	vector<tuple<char, char, char>>ZERO;
	Q.push(make_tuple(0, ZERO, SUM));
	zen_shori(); CC = SUM;

	while (!Q.empty()) {
		vector<vector<char>>a1 = S; int a2 = get<0>(Q.front());
		vector<tuple<char, char, char>>a3 = get<1>(Q.front()); int a4 = get<2>(Q.front()); Q.pop(); _size = Q.size();
		for (int i = 0; i < a3.size(); i++) {
			a1 = solve(a1, get<0>(a3[i]), get<1>(a3[i]), get<2>(a3[i]));
		}
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };
		for (int i = 1; i <= 3; i++) {
			int rem1 = a4 - P[i], rem2 = n - (a2 + 1); bool OK = true;
			if (dp[rem2][rem1] == false)OK = false;
			if (OK == false)continue;
			int LIM = 0; if (a3.size() >= 1) LIM = get<0>(a3[a3.size() - 1]) * 100 + get<1>(a3[a3.size() - 1]) * 10 + get<2>(a3[a3.size() - 1]);
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					int DD = j * 100 + k * 10 + i;
					if (DD < LIM) continue;
					vector<vector<char>>G = solve(a1, j, k, i);
					vector<tuple<char, char, char>>H = a3;
					if (hantei(G) == false)continue;
					H.push_back(make_tuple(j, k, i));
					if (G == START && a2 + 1 == n) {
						for (int j = 0; j < H.size(); j++) {
							cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl;
						}
						goto E;
					}
					if (a2 + 1 >= n - LIM2) {
						int P = lower_bound(Vec.begin(), Vec.end(), make_tuple(G, 0, ZERO)) - Vec.begin();
						if (P < Vec.size() && get<0>(Vec[P]) == G) {
							for (int j = 0; j < H.size(); j++) {
								cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl;
							}
							vector<tuple<char, char, char>>J = get<2>(Vec[P]);
							for (int j = 0; j < J.size(); j++) {
								cout << (int)get<1>(J[j]) << ' ' << (int)get<0>(J[j]) << ' ' << (int)get<2>(J[j]) << endl;
							}
							goto E;
						}
					}
					Q.push(make_tuple(a2 + 1, H, a4 - P[i]));
				}
			}
		}
	}
E:;
	return 0;
}
accuracy: 0.5833333333333334
time_ms: 4890
memory_kb: 27016
final_rank: 12

code_snippet: #include<iostream>
#include<queue>
#include<vector>
#include<tuple>
#include<cstdlib>
#include<ctime>
#include<algorithm>
using namespace std;
vector<vector<char>>S; int n;
bool dp[13][160]; int LIM2 = 0; int _size = 0; int CC = 0;
vector<vector<char>> solve(vector<vector<char>>p, int x, int y, int r) {
	if (r == 1) { p[x][y]--; p[x + 1][y]--; p[x - 1][y]--; p[x][y - 1]--; p[x][y + 1]--; }
	if (r == 2) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; }
	if (r == 3) { for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++)p[x + i][y + j]--; p[x + 2][y]--; p[x][y + 2]--; p[x - 2][y]--; p[x][y - 2]--; }
	return p;
}
bool isgood(int p) {
	if (p % 4 == 1 && p >= 5)return true;
	if (p % 4 == 2 && p >= 10)return true;
	if (p % 4 == 3 && p >= 15)return true;
	if (p % 4 == 0 && p >= 20)return true;
	return false;
}
bool hantei(vector<vector<char>>p) {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (p[i][j] < 0)return false;
		}
	}
	bool OKs[10][10]; for (int i = 0; i < 100; i++)OKs[i / 10][i % 10] = false;
	for (int i = 1; i < 9; i++) {
		for (int j = 1; j < 9; j++) {
			if (p[i][j] == 0)continue;
			if (p[i - 1][j] >= 1 && p[i + 1][j] >= 1 && p[i][j - 1] >= 1 && p[i][j + 1] >= 1) {
				OKs[i][j] = true; OKs[i - 1][j] = true; OKs[i][j - 1] = true; OKs[i][j + 1] = true; OKs[i + 1][j] = true;
			}
			bool OK4 = true;
			for (int k = -1; k <= 1; k++)for (int l = -1; l <= 1; l++)if (p[i + k][j + l] == 0)OK4 = false;
			if (OK4 == false)continue;
			for (int k = -1; k <= 1; k++)for (int l = -1; l <= 1; l++)OKs[i + k][j + l] = true;
		}
	}
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			if (OKs[i][j] == false && p[i][j] >= 1)return false;
		}
	}
	queue<pair<int, int>>Q3; bool OK5[10][10]; for (int i = 0; i < 100; i++)OK5[i / 10][i % 10] = false;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (p[i][j] == 0 || OK5[i][j] == false)continue;
			vector<int>sc; Q3.push(make_pair(i, j)); OK5[i][j] = true; sc.push_back(p[i][j]);
			int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
			while (!Q3.empty()) {
				int a11 = Q3.front().first, a12 = Q3.front().second; Q3.pop();
				for (int k = 0; k < 4; k++) {
					int cx = a11 + dx[k], cy = a12 + dy[k];
					if (cx < 0 || cx >= 10 || cy < 0 || cy >= 10)continue;
					if (p[cx][cy] == 0 || OK5[cx][cy] == true)continue;
					Q3.push(make_pair(cx, cy)); sc.push_back(p[cx][cy]); OK5[cx][cy] = true;
				}
			}
			int sums = 0; for (int i = 0; i < sc.size(); i++)sums += sc[i];
			if (isgood(sums) == false)return false;
		}
	}
	if (rand() % 3 == 0 && n == 12 && _size >= 1000)return false;
	return true;
}
vector<tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>>>Vec;
void zen_shori() {
	int JJ = 165; if (LIM2 == 2)JJ = 25000;
	for (int i = 0; i < JJ; i++) {
		tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>>ZZ;
		Vec.push_back(ZZ);
	}
	vector<vector<char>>ZERO; int LL = 0, RR = 0;
	vector<tuple<char, char, char>>ZERO3;
	for (int i = 0; i < 10; i++) { vector<char>ZERO5(10, 0); ZERO.push_back(ZERO5); }
	Vec[0] = make_tuple(ZERO, 0, ZERO3); RR++;
	while (LL < RR && RR < JJ) {
		vector<vector<char>>a1 = get<0>(Vec[LL]); int a2 = get<1>(Vec[LL]);
		vector<tuple<char, char, char>>a3 = get<2>(Vec[LL]);
		LL++; if (a2 == LIM2)continue;
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };
		for (int i = 1; i <= 3; i++) {
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					vector<vector<char>>a4 = solve(a1, j, k, i);
					vector<tuple<char, char, char>>a5 = a3; a5.push_back(make_tuple(j, k, i));
					if (RR < JJ) { Vec[RR] = make_tuple(a4, a2 + 1, a5); RR++; }
				}
			}
		}
	}
	for (int i = 0; i < Vec.size(); i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				get<0>(Vec[i])[j][k] *= -1;
			}
		}
	}
	sort(Vec.begin(), Vec.end());
}
int main() {
	srand((unsigned)time(NULL));
	cin >> n; dp[0][0] = true;
	LIM2 = 2;
	for (int i = 0; i < 12; i++) {
		for (int j = 0; j < 160; j++) {
			if (dp[i][j] == false)continue;
			dp[i + 1][j + 5] = true; dp[i + 1][j + 9] = true; dp[i + 1][j + 13] = true;
		}
	}
	for (int i = 0; i < 10; i++) { vector<char>V(10, 0); S.push_back(V); }
	vector<vector<char>>START = S; int SUM = 0;
	for (int i = 0; i < 10; i++)for (int j = 0; j < 10; j++) { int SS; cin >> SS; S[i][j] = SS; SUM += S[i][j]; }
	queue<tuple<int, vector<tuple<char, char, char>>, int>> Q;
	vector<tuple<char, char, char>>ZERO;
	Q.push(make_tuple(0, ZERO, SUM));
	zen_shori(); CC = SUM;

	while (!Q.empty()) {
		vector<vector<char>>a1 = S; int a2 = get<0>(Q.front());
		vector<tuple<char, char, char>>a3 = get<1>(Q.front()); int a4 = get<2>(Q.front()); Q.pop(); _size = Q.size();
		for (int i = 0; i < a3.size(); i++) {
			a1 = solve(a1, get<0>(a3[i]), get<1>(a3[i]), get<2>(a3[i]));
		}
		int L[4] = { 0,1,1,2 }, R[4] = { 9,8,8,7 }, P[4] = { 0,5,9,13 };
		for (int i = 1; i <= 3; i++) {
			int rem1 = a4 - P[i], rem2 = n - (a2 + 1); bool OK = true;
			if (dp[rem2][rem1] == false)OK = false;
			if (OK == false)continue;
			int LIM = 0; if (a3.size() >= 1) LIM = get<0>(a3[a3.size() - 1]) * 100 + get<1>(a3[a3.size() - 1]) * 10 + get<2>(a3[a3.size() - 1]);
			for (int j = L[i]; j <= R[i]; j++) {
				for (int k = L[i]; k <= R[i]; k++) {
					int DD = j * 100 + k * 10 + i;
					if (DD < LIM) continue;
					vector<vector<char>>G = solve(a1, j, k, i);
					vector<tuple<char, char, char>>H = a3;
					if (hantei(G) == false)continue;
					H.push_back(make_tuple(j, k, i));
					if (G == START && a2 + 1 == n) {
						for (int j = 0; j < H.size(); j++) {
							cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl;
						}
						goto E;
					}
					if (a2 + 1 >= n - LIM2) {
						int P = lower_bound(Vec.begin(), Vec.end(), make_tuple(G, 0, ZERO)) - Vec.begin();
						if (P < Vec.size() && get<0>(Vec[P]) == G) {
							for (int j = 0; j < H.size(); j++) {
								cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl;
							}
							vector<tuple<char, char, char>>J = get<2>(Vec[P]);
							for (int j = 0; j < J.size(); j++) {
								cout << (int)get<1>(J[j]) << ' ' << (int)get<0>(J[j]) << ' ' << (int)get<2>(J[j]) << endl;
							}
							goto E;
						}
					}
					Q.push(make_tuple(a2 + 1, H, a4 - P[i]));
				}
			}
		}
	}
E:;
	return 0;
}
accuracy: 0.16666666666666666
time_ms: 840
memory_kb: 20644
final_rank: 15