Problem:
Problem I:
Mysterious Onslaught
In 2012, human beings have been exposed to fierce onslaught of unidentified mysterious extra-terrestrial creatures. We have exhaused because of the long war and can't regist against them any longer. Only you, an excellent wizard, can save us. Yes, it's time to stand up!
The enemies are dispatched to the earth with being aligned like an
n
*
n
square. Appearently some of them have already lost their fighting capabilities for some unexpected reason. You have invented a highest grade magic spell 'MYON' to defeat them all. An attack of this magic covers any rectangles (which is parallel to axis). Once you cast a spell "myon," then all the enemies which the magic covers will lose their fighting capabilities because of tremendous power of the magic. However, the magic seems to activate enemies' self-repairing circuit. Therefore if any enemy which have already lost its fighting capability is exposed to the magic, the enemy repossesses its fighting capability. You will win the war when all the enemies will lose their fighting capabilities.
Let me show an example. An array of enemies below have dispatched:
1 1 1 1 1
1 0 0 0 1
1 0 1 0 1
1 0 0 0 1
1 1 1 1 1
Here, '
0
' means an enemy that doesn't possess fighting capability, and '
1
' means an enemy that possesses.
First, you cast a spell "
myon
" with covering all the enemies, which results in;
0 0 0 0 0
0 1 1 1 0
0 1 0 1 0
0 1 1 1 0
0 0 0 0 0
Next, cast once again with covering central 3 * 3 enemies.
0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
0 0 0 0 0
0 0 0 0 0
Now you can defeat them all by casting a spell covers remaining one. Therefore you can cast "
myonmyonmyon
," which is the shortest spell for this case.
You are given the information of the array. Please write a program that generates the shortest spell that can defeat them all.
Input
The first line of each test case has an integer
n
. Following
n
lines are information of an array of enemies. The format is same as described in the problem statement.
Input terminates when n = 0.
You may assume that one or more enemy have fighting capability.
Output
For each dataset, output the shortest spell.
Constraints
1 ≤
n
≤ 5
Sample Input
5
1 1 1 1 1
1 0 0 0 1
1 0 1 0 1
1 0 0 0 1
1 1 1 1 1
3
1 1 1
1 1 1
1 1 1
5
1 1 1 1 0
1 1 1 1 0
1 0 0 0 1
0 1 1 1 1
0 1 1 1 1
0
Output for the Sample Input
myonmyonmyon
myon
myonmyon

Submitted solutions:

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

using namespace std;

struct Node{
    int val, step;
};

map<int, bool> flag;
queue<Node> q;
int n;

void getxy(int i, int &x, int &y) {
    x = i/n+1;
    y = i%n+1;
}

int getbin(int now, int sx, int sy, int ex, int ey) {
    for (int i=sx; i<=ex; ++i) {
        for (int j=sy; j<=ey; ++j) {
            int nochan = (i-1)*n+j-1;
            now = (now ^ (1<<nochan));
        }
    }
    return now;
}

void bfs(int x) {
    if (x==0) {
        printf("\n");
        return;
    }
    flag.clear();
    while (!q.empty()) q.pop();
    Node fir;
    flag[fir.val] = true;
    fir.val = x;
    fir.step = 0;
    q.push(fir);
    while (!q.empty()) {
        Node now = q.front();
        q.pop();
        for (int i=0; i<n*n; ++i) {
            if ((1<<i)&now.val) {
                int sx, sy;
                getxy(i, sx, sy);
                for (int ex = sx; ex<=n; ++ex) {
                    for (int ey = sy; ey<=n; ++ey) {
                        Node next;
                        next.val = getbin(now.val, sx, sy, ex, ey);
                        if (next.val == 0) {
                            for (int j=1; j<=now.step+1; ++j) {
                                printf("myon");
                            }
                            printf("\n");
                            return;
                        }
                        if (flag.count(next.val)==0) {
                            flag[next.val] = true;
                            next.step = now.step+1;
                            q.push(next);
                        }
                    }
                }
                break;
            }
        }
    }
}

void doit() {
    int fir = 0;
    scanf("%d", &n);
    if (n==0) exit(0);
    for (int i=1; i<=n; ++i) {
        for (int j=1; j<=n; ++j) {
            int temp;
            scanf("%d", &temp);
            fir<<=1;
            fir+=temp;
        }
    }
    bfs(fir);
}

int main() {
    while (1) {
        doit();
    }
    return 0;
}
accuracy: 1
time_ms: 1400
memory_kb: 13268
final_rank: 9

code_snippet: #pragma GCC optimize("O2")
#include <bits/stdc++.h>

using namespace std;

using ld = long double;
using pii = pair<int, int>;

const int N = 5;
const int M = 5;
const int AREA = N * M;
const int SIZE = 1 << AREA;

char dp[SIZE];
vector<int> masks;

void precalc() {
    for (int li = 0; li < N; ++li) {
        for (int ri = li; ri < N; ++ri) {
            for (int lj = 0; lj < M; ++lj) {
                for (int rj = lj; rj < M; ++rj) {
                    int mask = 0;
                    for (int i = li; i <= ri; ++i) {
                        for (int j = lj; j <= rj; ++j) {
                            mask |= 1 << (i * M + j);
                        }
                    }
                    masks.push_back(mask);
                }
            }
        }
    }
    fill(dp, dp + SIZE, char(AREA));
    dp[0] = 0;
    for (int mask : masks) {
        for (int x = 0; x < SIZE; ++x) {
            int y = x ^ mask;
            if (x < y) {
                char ny = min<char>(dp[y], dp[x] + 1);
                char nx = min<char>(dp[x], dp[y] + 1);
                dp[x] = nx;
                dp[y] = ny;
            }
        }
    }
}

signed main() {

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

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

    precalc();

    for (int n; cin >> n;) {
        if (n == 0) break;
        int mask = 0;
        for (int i = 0; i < n; ++i) {
            for (int x, j = 0; j < n; ++j) {
                cin >> x;
                if (x) mask |= 1 << (i * M + j);
            }
        }
        char res = dp[mask];
        string s;
        for (int it = 0; it < res; ++it) s += "myon";
        cout << s << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 7410
memory_kb: 36128
final_rank: 20

code_snippet: #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ld = long double;
using pii = pair<int, int>;

const int N = 5;
const int M = 5;
const int AREA = N * M;
const int SIZE = 1 << AREA;

char dp[SIZE];
vector<int> masks;

void precalc() {
    for (int li = 0; li < N; ++li) {
        for (int ri = li; ri < N; ++ri) {
            for (int lj = 0; lj < M; ++lj) {
                for (int rj = lj; rj < M; ++rj) {
                    int mask = 0;
                    for (int i = li; i <= ri; ++i) {
                        for (int j = lj; j <= rj; ++j) {
                            mask |= 1 << (i * M + j);
                        }
                    }
                    masks.push_back(mask);
                }
            }
        }
    }
    fill(dp, dp + SIZE, char(AREA));
    dp[0] = 0;
    for (int mask : masks) {
        for (int x = 0; x < SIZE; ++x) {
            int y = x ^ mask;
            if (x < y) {
                char ny = min<char>(dp[y], dp[x] + 1);
                char nx = min<char>(dp[x], dp[y] + 1);
                dp[x] = nx;
                dp[y] = ny;
            }
        }
    }
}

signed main() {

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

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

    precalc();

    for (int n; cin >> n;) {
        if (n == 0) break;
        int mask = 0;
        for (int i = 0; i < n; ++i) {
            for (int x, j = 0; j < n; ++j) {
                cin >> x;
                if (x) mask |= 1 << (i * M + j);
            }
        }
        char res = dp[mask];
        string s;
        for (int it = 0; it < res; ++it) s += "myon";
        cout << s << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 7420
memory_kb: 35920
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001


#define NUM 30
#define MAX 20
#define MAX2 26
#define MAX_DEPTH 3

struct Info{
	Info(){

		state = count = 0;
	}
	Info(int arg_state,char arg_count){
		state = arg_state;
		count = arg_count;
	}
	bool operator<(const struct Info& arg) const{

		return count > arg.count; //昇順(PQ)
	}
	int state;
	char count;
};


int POW[MAX2+1];
char D[5][1 << 17];
char min_dist[1 << 21];
char dp[1 << 26];
char ANS;


void dfs(int state,char depth){
	if(ANS <= depth)return;

	int table[5][5];

	for(int loop = 0; loop < 5*5; loop++){
		int row = loop/5;
		int col = loop%5;
		if(state&POW[loop]){

			table[row][col] = 1;

		}else{

			table[row][col] = 0;
		}
	}

	bool FLG = false;
	int pos;

	for(int col = 0; col < 5; col++){
		if(table[0][col] == 1){
			pos = col;
			FLG = true;
			break;
		}
	}
	if(!FLG){ //1行目に1がない

		int tmp_state = 0;
		for(int row = 1; row < 5; row++){
			for(int col = 0; col < 5; col++){
				if(table[row][col] == 1){

					tmp_state += POW[5*(row-1)+col];
				}
			}
		}


		if(ANS > depth+min_dist[tmp_state]){
			ANS = depth+min_dist[tmp_state];
		}
		return;
	}

	if(depth == MAX_DEPTH)return;

	for(int base_row = 0; base_row <= 0; base_row++){ //長方形の上端は1行目で固定
		for(int base_col = 0; base_col <= pos; base_col++){ //一番左上の1を必ず含むとする
			for(int h = 1; h <= 5; h++){
				for(int w = pos-base_col+1; base_col+w-1 < 5;w++){ //★★★-1するのに注意★★★
					int next_state = state;
					for(int row = 0; row < h; row++){
						for(int col = base_col; col < base_col+w; col++){
							if(table[row][col] == 1){

								next_state -= POW[5*row+col];
							}else{

								next_state += POW[5*row+col];
							}
						}
					}
					dfs(next_state,depth+1);
				}
			}
		}
	}

}


int main(){

	POW[0] = 1;
	for(int i = 1; i <= MAX2; i++){

		POW[i] = POW[i-1]*2;
	}

	//■2*2～4*4
	{

		for(int len = 2; len <= 4; len++){

			int H = len;
			int W = len;

			D[len][0] = 0;
			for(int state = 1; state < POW[H*W]; state++){

				D[len][state] = NUM;
			}

			priority_queue<Info> Q;
			Q.push(Info(0,0));

			while(!Q.empty()){

				Info info = Q.top();
				Q.pop();

				if(info.count > D[len][info.state])continue;

				int table[H][W];

				for(int loop = 0; loop < H*W; loop++){
					int row = loop/W;
					int col = loop%W;
					if(info.state&POW[loop]){

						table[row][col] = 1;

					}else{

						table[row][col] = 0;
					}
				}

				for(int base_row = 0; base_row < H; base_row++){
					for(int base_col = 0; base_col < W; base_col++){
						for(int h = 1; base_row+h-1 < H; h++){
							for(int w = 1; base_col+w-1 < W; w++){

								int next_state = info.state;
								for(int row = base_row; row < base_row+h; row++){
									for(int col = base_col; col < base_col+w; col++){
										if(table[row][col] == 1){

											next_state -= POW[W*row+col];
										}else{
											next_state += POW[W*row+col];
										}
									}
								}

								if(D[len][next_state] > info.count+1){
									D[len][next_state] = info.count+1;
									Q.push(Info(next_state,info.count+1));
								}
							}
						}
					}
				}
			}
		}
	}


	//■5*5
	{

		for(int state = 0; state < POW[4*5]; state++){

			min_dist[state] = NUM; //状態0から、その状態になるまでの最短距離
		}
		min_dist[0] = 0;

		priority_queue<Info> Q;
		Q.push(Info(0,0));

		//2行目以上の状態を前計算
		while(!Q.empty()){

			Info info = Q.top();
			Q.pop();

			if(info.count > min_dist[info.state])continue;

			/*■■下4行を前計算■■*/
			int table[4][5];

			for(int loop = 0; loop < 4*5; loop++){
				int row = loop/5;
				int col = loop%5;
				if(info.state&POW[loop]){

					table[row][col] = 1;

				}else{

					table[row][col] = 0;
				}
			}

			for(int base_row = 0; base_row < 4; base_row++){
				for(int base_col = 0; base_col < 5; base_col++){
					for(int h = 1; base_row+h-1 < 4; h++){
						for(int w = 1; base_col+w-1 < 5; w++){

							int next_state = info.state;
							for(int row = base_row; row < base_row+h; row++){
								for(int col = base_col; col < base_col+w; col++){
									if(table[row][col] == 1){

										next_state -= POW[5*row+col];
									}else{

										next_state += POW[5*row+col];
									}
								}
							}

							if(min_dist[next_state] > info.count+1){
								min_dist[next_state] = info.count+1;
								Q.push(Info(next_state,info.count+1));
							}
						}
					}
				}
			}
		}

		for(int state = 0; state < POW[5*5]; state++){

			dp[state] = 30;
		}

		dp[0] = 0;
		for(int state = 1; state < POW[4*5]; state++){

			dp[state*POW[5]] = min_dist[state];
		}
	}

	int N;
	while(true){

		scanf("%d",&N);
		if(N == 0)break;

		if(N == 1){

			int tmp;
			scanf("%d",&tmp);

			printf("myon\n");

		}else{

			int input[N][N];
			int state = 0;

			for(int row = 0; row < N; row++){
				for(int col = 0; col < N; col++){

					scanf("%d",&input[row][col]);
					if(input[row][col] == 1){

						state += POW[N*row+col];
					}
				}
			}

			int count;

			if(N >= 2 && N<=4){

				count = D[N][state];

			}else{

				ANS = NUM;

				dfs(state,0);
				count = ANS;
			}

			for(int a = 0; a < count; a++){

				printf("myon");
			}
			printf("\n");
		}
	}

	return 0;
}
accuracy: 1
time_ms: 3400
memory_kb: 42908
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001


#define NUM 30
#define MAX 20
#define MAX2 26
#define MAX_DEPTH 3

struct Info{
	Info(){

		state = count = 0;
	}
	Info(int arg_state,char arg_count){
		state = arg_state;
		count = arg_count;
	}
	bool operator<(const struct Info& arg) const{

		return count > arg.count; //昇順(PQ)
	}
	int state;
	char count;
};


int POW[MAX2+1];
char D[5][1 << 17];
char min_dist[1 << 21];
char dp[1 << 26];
char ANS;


void dfs(int state,char depth){
	if(ANS <= depth)return;

	int table[5][5];

	for(int loop = 0; loop < 5*5; loop++){
		int row = loop/5;
		int col = loop%5;
		if(state&POW[loop]){

			table[row][col] = 1;

		}else{

			table[row][col] = 0;
		}
	}

	bool FLG = false;
	int pos;

	for(int col = 0; col < 5; col++){
		if(table[0][col] == 1){
			pos = col;
			FLG = true;
			break;
		}
	}
	if(!FLG){ //1行目に1がない

		int tmp_state = 0;
		for(int row = 1; row < 5; row++){
			for(int col = 0; col < 5; col++){
				if(table[row][col] == 1){

					tmp_state += POW[5*(row-1)+col];
				}
			}
		}


		if(ANS > depth+min_dist[tmp_state]){
			ANS = depth+min_dist[tmp_state];
		}
		return;
	}

	if(depth == MAX_DEPTH)return;

	for(int base_row = 0; base_row <= 0; base_row++){
		for(int base_col = 0; base_col <= pos; base_col++){
		//for(int base_col = 0; base_col < 5; base_col++){
			for(int h = 1; h <= 5; h++){
				for(int w = pos-base_col+1; base_col+w-1 < 5;w++){
				//for(int w = 1; base_col+w-1 < 5; w++){
					int next_state = state;
					for(int row = 0; row < h; row++){
						for(int col = base_col; col < base_col+w; col++){
							if(table[row][col] == 1){

								next_state -= POW[5*row+col];
							}else{

								next_state += POW[5*row+col];
							}
						}
					}
					dfs(next_state,depth+1);
				}
			}
		}
	}

}


int main(){

	POW[0] = 1;
	for(int i = 1; i <= MAX2; i++){

		POW[i] = POW[i-1]*2;
	}

	//■2*2～4*4
	{

		for(int len = 2; len <= 4; len++){

			int H = len;
			int W = len;

			D[len][0] = 0;
			for(int state = 1; state < POW[H*W]; state++){

				D[len][state] = NUM;
			}

			priority_queue<Info> Q;
			Q.push(Info(0,0));

			while(!Q.empty()){

				Info info = Q.top();
				Q.pop();

				if(info.count > D[len][info.state])continue;

				int table[H][W];

				for(int loop = 0; loop < H*W; loop++){
					int row = loop/W;
					int col = loop%W;
					if(info.state&POW[loop]){

						table[row][col] = 1;

					}else{

						table[row][col] = 0;
					}
				}

				for(int base_row = 0; base_row < H; base_row++){
					for(int base_col = 0; base_col < W; base_col++){
						for(int h = 1; base_row+h-1 < H; h++){
							for(int w = 1; base_col+w-1 < W; w++){

								int next_state = info.state;
								for(int row = base_row; row < base_row+h; row++){
									for(int col = base_col; col < base_col+w; col++){
										if(table[row][col] == 1){

											next_state -= POW[W*row+col];
										}else{
											next_state += POW[W*row+col];
										}
									}
								}

								if(D[len][next_state] > info.count+1){
									D[len][next_state] = info.count+1;
									Q.push(Info(next_state,info.count+1));
								}
							}
						}
					}
				}
			}
		}
	}


	//■5*5
	{

		for(int state = 0; state < POW[4*5]; state++){

			min_dist[state] = NUM; //状態0から、その状態になるまでの最短きょり
		}
		min_dist[0] = 0;

		priority_queue<Info> Q;
		Q.push(Info(0,0));

		//2行目以上の状態を前計算
		while(!Q.empty()){

			Info info = Q.top();
			Q.pop();

			if(info.count > min_dist[info.state])continue;

			/*■■下4行を前計算■■*/
			int table[4][5];

			for(int loop = 0; loop < 4*5; loop++){
				int row = loop/5;
				int col = loop%5;
				if(info.state&POW[loop]){

					table[row][col] = 1;

				}else{

					table[row][col] = 0;
				}
			}

			for(int base_row = 0; base_row < 4; base_row++){
				for(int base_col = 0; base_col < 5; base_col++){
					for(int h = 1; base_row+h-1 < 4; h++){
						for(int w = 1; base_col+w-1 < 5; w++){

							int next_state = info.state;
							for(int row = base_row; row < base_row+h; row++){
								for(int col = base_col; col < base_col+w; col++){
									if(table[row][col] == 1){

										next_state -= POW[5*row+col];
									}else{

										next_state += POW[5*row+col];
									}
								}
							}

							if(min_dist[next_state] > info.count+1){
								min_dist[next_state] = info.count+1;
								Q.push(Info(next_state,info.count+1));
							}
						}
					}
				}
			}
		}

		for(int state = 0; state < POW[5*5]; state++){

			dp[state] = 30;
		}

		dp[0] = 0;
		for(int state = 1; state < POW[4*5]; state++){

			dp[state*POW[5]] = min_dist[state];
		}
	}

	int N;
	while(true){

		scanf("%d",&N);
		if(N == 0)break;

		if(N == 1){

			int tmp;
			scanf("%d",&tmp);

			printf("myon\n");

		}else{

			int input[N][N];
			int state = 0;

			for(int row = 0; row < N; row++){
				for(int col = 0; col < N; col++){

					scanf("%d",&input[row][col]);
					if(input[row][col] == 1){

						state += POW[N*row+col];
					}
				}
			}

			int count;

			if(N >= 2 && N<=4){

				count = D[N][state];
				//printf("count:%d\n",count);

			}else{

				ANS = NUM;

				dfs(state,0);
				count = ANS;
			}

			for(int a = 0; a < count; a++){

				printf("myon");
			}
			printf("\n");
		}
	}

	return 0;
}
accuracy: 1
time_ms: 3410
memory_kb: 42856
final_rank: 17

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

    int h(const vector<vector<int>> &x) {
        const int C = 997;      // ???f??????
        size_t t = 0;
        for (int i = 0; i != x.size(); ++i) {
            for (int j = 0; j < x[i].size(); ++j) {
                t = t * 2 + x[i][j];
            }
        }
        return t;
    }

vector<map<int,int>>memo(6);
 
int N; 
int solve(const vii &field){
    if(memo[field.size()].find(h(field))==memo[field.size()].end()){
        for(int y=0;y<field.size();++y){
            for(int x=0;x<field[y].size();++x){
                if(field[y][x]){
                int ans=100;
                    for(int xsz=1;xsz<=N-x;++xsz){
                        for(int ysz=1;ysz<=N-y;++ysz){
                            vii nextfield(field);
                            for(int dy=0;dy<ysz;++dy){
                                for(int dx=0;dx<xsz;++dx){
                                    int nexty=y+dy;
                                    int nextx=x+dx;
                                    nextfield[nexty][nextx]=!nextfield[nexty][nextx];
                                }
                            }
                            ans=min(ans,1+solve(nextfield));
                        }
                    }
                 return memo[field.size()][h(field)]=ans;
                }
            }
        }
        return memo[field.size()][h(field)]=0;
    }
    return memo[field.size()][h(field)];
}
int main(){
    while(true){
        cin>>N;
        if(!N)break;
        vii field(N,vector<int>(N));
        for(int i=0;i<N;++i){
            for(int j=0;j<N;++j){
                cin>>field[i][j];
            }
        }
        int ans=solve(field);
        for(int i=0;i<ans;++i){
            cout<<"myon";
        }
        cout<<endl;
 
    }
    return 0;
 
}
accuracy: 1
time_ms: 4230
memory_kb: 39212
final_rank: 18

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int solve(int x,const vi& ms,vector<int8_t>& memo)
{
	if(memo[x]!=-1) return memo[x];
	
	if(x==0) return memo[x]=0;
	int res=INF;
	for(int m:ms) if(__builtin_ctz(x)==__builtin_ctz(m))
		res=min(res,solve(x^m,ms,memo));
	return memo[x]=res+1;
}

int main()
{
	vi ms;
	rep(t,5) repi(b,t,5) rep(l,5) repi(r,l,5){
		int m=0;
		repi(i,t,b+1) repi(j,l,r+1) m|=1<<(i*5+j);
		ms.push_back(m);
	}
	vector<int8_t> memo(1<<25,-1);
	
	for(int n;cin>>n && n;){
		int x=0;
		rep(i,n) rep(j,n){
			int b; cin>>b;
			x|=b<<(i*5+j);
		}
		
		int res=solve(x,ms,memo);
		rep(i,res) cout<<string("myon"); cout<<endl;
	}
}
accuracy: 1
time_ms: 410
memory_kb: 33772
final_rank: 12

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int solve(int x,const vi& ms,unordered_map<int,int>& memo)
{
	auto i=memo.find(x);
	if(i!=end(memo)) return i->second;
	
	if(x==0) return memo[x]=0;
	int res=INF;
	for(int m:ms) if(__builtin_ctz(x)==__builtin_ctz(m))
		res=min(res,solve(x^m,ms,memo));
	return memo[x]=res+1;
}

int main()
{
	vi ms;
	rep(t,5) repi(b,t,5) rep(l,5) repi(r,l,5){
		int m=0;
		repi(i,t,b+1) repi(j,l,r+1) m|=1<<(i*5+j);
		ms.push_back(m);
	}
	unordered_map<int,int> memo;
	
	for(int n;cin>>n && n;){
		int x=0;
		rep(i,n) rep(j,n){
			int b; cin>>b;
			x|=b<<(i*5+j);
		}
		
		int res=solve(x,ms,memo);
		rep(i,res) cout<<string("myon"); cout<<endl;
	}
}
accuracy: 1
time_ms: 860
memory_kb: 42364
final_rank: 14

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

inline int ctz(uint x)
{
	int i=0;
	if(!(x&0x0000ffff)) i+=16,x>>=16;
	if(!(x&0x000000ff)) i+=8,x>>=8;
	if(!(x&0x0000000f)) i+=4,x>>=4;
	if(!(x&0x00000003)) i+=2,x>>=2;
	if(!(x&0x00000001)) i+=1,x>>=1;
	return i+!x;
}

int solve(int x0)
{
	static array<int,225> ms;
	{
		int k=0;
		rep(t,5) repi(b,t,5) rep(l,5) repi(r,l,5){
			int m=0;
			repi(i,t,b+1) repi(j,l,r+1) m|=1<<(i*5+j);
			ms[k++]=m;
		}
	}
	
	queue<tuple<int,int>> q; q.emplace(x0,0);
	unordered_set<int> vis;
	while(q.size()){
		int x,c; tie(x,c)=q.front(); q.pop();
		if(x==0) return c;
		if(!vis.insert(x).second) continue;
		for(int m:ms) if(ctz(x)==ctz(m))
			q.emplace(x^m,c+1);
	}
	return -1;
}

int main()
{
	for(int n;cin>>n && n;){
		int x0=0;
		rep(i,n) rep(j,n){
			int b; cin>>b;
			x0|=b<<(i*5+j);
		}
		string res;
		per(_,solve(x0)) res+="myon";
		cout<<res<<endl;
	}
}
accuracy: 1
time_ms: 3430
memory_kb: 18776
final_rank: 13

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
int b[6][6];
int rec[6][6][6][6];
int n;
int solve(int p,int q,int t,int c){
	if(t==0){
		if(c)return 0;
		return 1;
	}
	if(p==n)return 0;
	if(q==n)return solve(p+1,0,t,c);
	if(!(c&(1<<(p*n+q))))return solve(p,q+1,t,c);
	for(int h=q;h<n;h++){
		for(int i=p;i<n;i++){
			if(solve(p,q+1,t-1,c^rec[p][q][i][h]))return 1;
		}
	}
	return 0;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		n=a;
		for(int i=0;i<6;i++)for(int j=0;j<6;j++)for(int k=0;k<6;k++)for(int l=0;l<6;l++)
			rec[i][j][k][l]=0;
		for(int i=0;i<a;i++)for(int j=0;j<a;j++){
			for(int k=i;k<a;k++)for(int l=j;l<a;l++){
				for(int x=i;x<=k;x++)for(int y=j;y<=l;y++)
					rec[i][j][k][l]+=(1<<(x*a+y));
			}
		}
		for(int i=0;i<a;i++)for(int j=0;j<a;j++)scanf("%d",&b[i][j]);
		int st=0;
		for(int i=0;i<a;i++)for(int j=0;j<a;j++)if(b[i][j])st+=(1<<(i*a+j));
		for(int i=1;;i++){
			if(solve(0,0,i,st)){
				for(int j=0;j<i;j++)printf("myon");
				printf("\n");
				break;
			}
		}
	}
}
accuracy: 1
time_ms: 3940
memory_kb: 1020
final_rank: 10

code_snippet: #include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cassert>
#include<bitset>
#include<queue>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX (1<<20)
using namespace std;

struct P
{
  int state,cost;
  P(int state=inf,int cost=inf):state(state),cost(cost){}
  bool operator < (const P& a)const
  {
    return cost > a.cost;
  }
};

short mincost[MAX];
short mincost5[1<<5];
int rect[5][5][5][5];


void init()
{
  rep(i,MAX)mincost[i] = 25;
  rep(i,5)rep(j,5)rep(k,5)rep(l,5)rect[i][j][k][l] = 0;
}

void makeRect()
{
  rep(y1,5)rep(x1,5)//top-left
    REP(y2,y1,5)REP(x2,x1,5)//bottom-right
      REP(y,y1,y2+1)REP(x,x1,x2+1)
        rect[y1][x1][y2][x2] |= (1<<(y*5+x));
}

void makeMincost()
{
  mincost[0] = 0;
  priority_queue<P> que;
  que.push(P(0,0));

  while(!que.empty())
    {
      P p = que.top(); que.pop();

      rep(y1,4)rep(x1,5)
	REP(y2,y1,4)REP(x2,x1,5)
	{
	  int nstate = p.state ^ rect[y1][x1][y2][x2];
	  if(mincost[nstate] > p.cost + 1)
	    {
	      mincost[nstate] = p.cost + 1;
	      que.push(P(nstate,p.cost+1));
	    }
	}
    }

}

void print(int f)
{
  bitset<25> ff(f);
  rep(i,5)
    {
      cout << i << " : ";
      rep(j,5)
	{
	  cout << ff[i*5+j] << " ";
	}
      cout << endl;
    }
  cout << endl;
}

void dfs(int state,int cur,int cost,int &ans)
{
  if(state < (1<<20))ans = min(ans,cost + mincost[state]);
  if(cost >= ans)return;
  if(cur >= 3)return;

  rep(y1,5)rep(x1,5)REP(x,x1,5)
    {
      int nstate = state ^ rect[y1][x1][4][x];
      int nstate5 = (nstate>>20);      

      //cout << "ns = " << endl;
      //print(nstate);

      dfs(nstate,cur+1,cost+1,ans);
	
    }
  
}

int compute(int field)
{
  int bf = (field>>20);
  int nfield = field & (1<<20)-1;
  int ret = __builtin_popcount(bf) + mincost[nfield];

  //cout << "start dfs" << endl;
  dfs(field,0,0,ret);
  //cout << "end dfs" << endl;
  //cout << "ret = " << ret << endl;
  return ret;
}

int main()
{
  int n,field;
  init();
  makeRect();
  /*
  rep(y,3)
    rep(x,3)
    {
      bitset<20> b(rect[0][0][y][x]);
      cout << "(" << x << "," << y << ") " << b << endl;
    }
  */
  //cout << "finish -- makeRect" << endl;
  makeMincost();
  //cout << "finish -- makeMincost" <<endl;

  while(cin >> n,n)
    {
      field = 0;
      {
	char c;
	rep(y,n)rep(x,n)
	  {
	    cin >> c;
	    if(c == '1')field |= (1<<(y*5+x));
	  }
	int cnt = (n<=4?mincost[field]:compute(field));
	rep(i,cnt)cout << "myon";
	cout << endl;

      }

    }
  return 0;
}


/*
struct P
{
  int state,cost;
  P(int state = inf,int cost = inf):state(state),cost(cost){}
  bool operator < (const P& a)const
  {
    return cost > a.cost;
  }
};

int n;
short mincost[5][MAX];
int rect[5][5][5][5][5];
int lim;

void makeRect()
{
  rep(i,5)rep(j,5)rep(k,5)rep(l,5)rep(m,5)rect[i][j][k][l][m] = 0;

  rep(depth,5)
    {
      rep(y1,depth+1)rep(x1,depth+1)
	REP(y2,y1,depth+1)REP(x2,x1,depth+1)
	  REP(y,y1,y2+1)REP(x,x1,x2+1)
	  {
            rect[depth][y1][x1][y2][x2] |= (1<<(y*(depth+1)+x));
	  }
    }

}



void compute(int N)
{
  rep(i,(1<<(N*N)))mincost[N-1][i] = N*N+1;
  mincost[N-1][0] = 0;
  cout << "N = "<< N << endl;
  rep(state,(1<<(N*N)))
    {
      if(mincost[N-1][state] == N*N+1)continue;
      rep(y1,N)rep(x1,N)
	REP(y2,y1,N)REP(x2,x1,N)
	{  
	  int nstate = state ^ rect[N-1][y1][x1][y2][x2];
	  mincost[N-1][nstate] = min(mincost[N-1][nstate],
				     (short)(mincost[N-1][state]+1));
	}
    }
}

int main()
{

  makeRect();
  cout << "finish --- make rectangle" << endl;
 
  compute(1);
  compute(2);
  compute(3);
  compute(4);
  //compute(5);
  cout << "-------------" << endl;
  while(cin >> n,n)
    {
      lim = (1<<n);

      int field = 0,c;
      rep(y,n)rep(x,n)
	{
	  cin >> c;
	  if(c)field |= (1<<(n*y + x));
	}
      bitset<25> bi(field);
      cout << "field " << bi << endl;

      cout << mincost[n-1][field] << endl;

    }
  return 0;
}
*/

 /*
  REP(y,1,3)
    {
      REP(x,1,3)
	{
	  cout << "y = " << y << " x = " << x << endl;
	  bitset<10> bit(rect[2][1][1][y][x]);
	  cout << "***" << bit << "***" << endl;
	}
    }
  */

/*
void compute(int N)
{
  rep(j,(1<<(N*N)))mincost[N-1][j] = N*N+1;
  mincost[N-1][0] = 0;
  //queue<P> que;
  priority_queue<P> que;
  que.push(P(0,0));

  cout << "N = " << N << endl;
  while(!que.empty())
    {
      //P p = que.front(); que.pop();
      P p = que.top(); que.pop();
      //bitset<5> bb(p.state);
      //cout << "cur = " << bb << " cost = " << p.cost << endl;

      rep(y1,N)
	{
	  rep(x1,N)
	    {
	      REP(y2,y1,N)
		{
		  REP(x2,x1,N)
		    {
		      //bitset<5> re(rect[N-1][y1][x1][y2][x2]);
		      //cout << "rect["<<y1<<"]["<<x1<<"]["<<y2<<"]["<<x2<<"] = " << re << endl;
		      int nstate = p.state ^ rect[N-1][y1][x1][y2][x2];
		      if(mincost[N-1][nstate] > p.cost + 1)
			{
			  bitset<5> nex(nstate);
			  //cout << "go to next = " << nex << " cost = " << p.cost+1 << endl;
			  //cout << endl;
			  mincost[N-1][nstate] = p.cost + 1;
			  que.push(P(nstate,p.cost+1));
			}
		      //else cout << re << " is bad case because " << mincost[N-1][nstate] << " !> " << p.cost+1<< endl << endl;
		    }
		}
	    }
	}

    }

}
*/
accuracy: 1
time_ms: 460
memory_kb: 11472
final_rank: 6

code_snippet: #include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

unsigned char memo[1<<20];
int mask[5][5][6][6];

void printS(int s){
  int tmp[5][5];
  fill(tmp[0], tmp[5], 0);
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      tmp[i][j] = s >> (i*5+j) & 1;
    }
  }
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      cout << tmp[i][j];
    }
    cout << endl;
  }
  cout << endl;
}

void init(){
  fill(memo, memo + (1<<20), -1);
  fill(mask[0][0][0], mask[5][0][0], 0);
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      for(int h=1;i+h<=5;h++){
        for(int w=1;j+w<=5;w++){
          int tmp = (1 << w) - 1 << j;
          for(int k=0;k<h;k++){
            mask[i][j][h][w] |= tmp << (i+k) * 5;
          }
        }
      }
    }
  }
  queue<int> q;
  memo[0] = 0;
  q.push(0);
  while(!q.empty()){
    int u = q.front();
    q.pop();
    for(int i=0;i<4;i++){
      for(int j=0;j<5;j++){
        for(int h=1;i+h<=4;h++){
          for(int w=1;j+w<=5;w++){
            int v = u ^ mask[i][j][h][w];
            if(memo[v] > memo[u] + 1){
              memo[v] = memo[u] + 1;
              /*if((int)memo[v] == 2 && 0){
                cout << "cost = " << (int)memo[v] << endl;
                printS(v);
                }*/
              q.push(v);
            }
          }
        }
      }
    }
  }
}

const int INF = 1 << 28;

void rec(int t, int x, int cnt, int &res){
  if((t >> 20) == 0){
    //printS(t);
    //cout << (int)memo[t&(1<<20)-1] << endl;
    res = min(res, memo[t] + cnt);
  }
  if(x >= 5) return;
  for(int i=0;i<5;i++){
    for(int j=x;j<5;j++){
      int nt = t ^ mask[i][x][5-i][j-x+1];
      if(!(nt&1<<20+x)) rec(nt, x+1, cnt+1, res);
    }
  }
  if(!(t&1<<20+x)) rec(t, x+1, cnt, res);
}

int solve(int s){
  int cnt = 0;
  for(int i=0;i<5;i++){
    if(s >> (20 + i) & 1) cnt++;
  }
  int res = memo[s&(1<<20)-1] + min(cnt, 6-cnt);
  //cout << res << ' ';
  rec(s, 0, 0, res);
  //cout << res << endl;
  return res;
}

main(){
  init();
  int n;
  while(cin >> n && n){
    int m = 0;
    for(int i=0;i<n;i++){
      int t = 0, c;
      for(int j=0;j<n;j++){
        cin >> c;
        t |= c << j;
      }
      m |= t << i * 5;
    }
    int ans = n < 5 ? memo[m] : solve(m);
    for(int i=0;i<ans;i++){
      cout << "myon";
    }
    cout << endl;
  }
}
accuracy: 1
time_ms: 310
memory_kb: 4704
final_rank: 1

code_snippet: //57
#include<iostream>
#include<vector>
#include<bitset>
#include<queue>

using namespace std;

struct S{
  int t,v;
};

int main(){
  for(int n;cin>>n,n;){
    int v=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	int b;
	cin>>b;
	v|=b<<i*n+j;
      }
    }
    queue<S> que;
    S is={0,v};
    que.push(is);
    static bitset<1<<25> s;
    s.reset();
    s.set(v);
    for(;;){
      S c=que.front();
      if(c.v==0)break;
      que.pop();
      int j,k;
      for(j=0;j<n;j++){
	for(k=0;k<n;k++){
	  if(c.v>>j*n+k&1)goto next;
	}
      }
    next:
      for(int l=j;l<n;l++){
	for(int m=k;m<n;m++){
	  int nv=c.v;
	  for(int o=j;o<=l;o++){
	    for(int p=k;p<=m;p++){
	      nv^=1<<o*n+p;
	    }
	  }
	  if(s.test(nv))continue;
	  s.set(nv);
	  S ns={c.t+1,nv};
	  que.push(ns);
	}
      }
    }
    for(int i=0;i<que.front().t;i++){
      cout<<"myon";
    }
    cout<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 390
memory_kb: 5960
final_rank: 2

code_snippet: //57
#include<iostream>
#include<vector>
#include<set>

using namespace std;

struct S{
  int t,v;
  bool operator<(S a)const{
    if(t!=a.t){
      return t<a.t;
    }else{
      return v<a.v;
    }
  }
};

int main(){
  for(int n;cin>>n,n;){
    int v=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	int b;
	cin>>b;
	v|=b<<i*n+j;
      }
    }
    set<S> que;
    S is={0,v};
    que.insert(is);
    set<int> s;
    for(;;){
      S c=*que.begin();
      if(c.v==0)break;
      que.erase(que.begin());
      if(!s.insert(c.v).second)continue;
      int j,k;
      for(j=0;j<n;j++){
	for(k=0;k<n;k++){
	  if(c.v>>j*n+k&1)goto next;
	}
      }
    next:
      for(int l=j;l<n;l++){
	for(int m=k;m<n;m++){
	  int nv=c.v;
	  for(int o=j;o<=l;o++){
	    for(int p=k;p<=m;p++){
	      nv^=1<<o*n+p;
	    }
	  }
	  if(s.count(nv))continue;
	  S ns={c.t+1,nv};
	  que.insert(ns);
	}
      }
    }
    for(int i=0;i<que.begin()->t;i++){
      cout<<"myon";
    }
    cout<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 5500
memory_kb: 16348
final_rank: 15

code_snippet: #include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
using namespace std;

int N;

vector<int> mem;
vector<int> mas;

vector<int> item[25];


int w[16];
int h[16];
int a[4][4];
int memo[(1<<25)/6+10];

char dfs(int bit){

	if( bit == 0 ) return 0;
	int idx = bit/6;
	int pos = (bit%6)*5;
	//cout << pos << endl;
	char val = memo[idx] >> pos & ((1<<5)-1);
	//cout << (int)val << endl;
	if( val != ((1<<5)-1) ) return val;
	
	char ans = 30;
	for(int p = 0 ; p < 25 ; p++){
		if( bit >> p & 1 ){
			for(int i = 0 ; i < item[p].size() ; i++)
				ans = min(ans,(char)(dfs(bit^item[p][i])+1));
			break;
		}
	}
	memo[idx] &= ~(((1<<5)-1) << pos);
	memo[idx] |= ((int)ans << pos );
	return  ans;
}

int main(){
	memset(memo,-1,sizeof(memo));
	
	for(int w = 1 ; w <= 5 ; w++){
		for(int h = 1 ; h <= 5 ; h++){
			for(int i = 0 ; i <= 5 - h ; i++){
				for(int j = 0 ; j <= 5 - w ; j++){
					int mask = 0;
					for(int k = 0 ; k < h ; k++)
						for(int l = 0 ; l < w ; l++)
							mask |= (1<<((i+k)*5+j+l));
					//cout << init << " " << mask << endl;
					item[i*5+j].push_back(mask);
				}
			}
		}
	}
	while(cin >> N && N){
		int init = 0;
		for(int i = 0 ; i < N ; i++){
			for(int j = 0 ; j < N ; j++){
				int c = 0;
				cin >> c;
				init |= (c<<(i*5+j));
			}
		}
		//cout << init << endl;
		int x = (int)dfs(init);
		for(int i = 0 ; i < x ; i++) cout << "myon";
		cout << endl;
	}
}
accuracy: 1
time_ms: 260
memory_kb: 23060
final_rank: 11

code_snippet: //Name: Mysterious Onslaught
//Level: 4
//Category: DP,ビット演算
//Note:

/*
 * 状態数は全部で 2^25 だが，これはちょうどメモリ制限の値と等しいため
 * 愚直な探索では解を求められない．
 * この手の問題だと上の行の状態を覚えておいて下の行に伝搬させるのが常套手段だが，
 * この問題でもその手法が使える．
 *
 * この問題で上の行から下の行へ伝搬する状態は，上の行でどのように矩形が置かれていたかである．
 * たとえばある行 r で 1〜3 列目を埋めるように矩形が置かれていた場合，その下の行 r+1 でも
 * 同じように 1〜3 列目を埋めるようにすると，これらはまとめて1個の矩形で表現できるため
 * コストが下がる．
 *
 * ある行について，列 x から右に矩形を伸ばしたとき，その幅は N-x 通り存在する．
 * これを各列について合計すると N=5 のときでも 15 通りであるから，1行を覆う矩形の取り方は
 * 高々 2^15 通り．
 * このうちその行を全滅させる置き方は更に少ないと予測できるので，そのような置き方だけを覚えて
 * 直前の状態として使うと計算量が抑えられる．
 * 実際には N=5 の時で 1024 通りになるので，1行の更新は 2^25 ループ程度で完了できる．
 *
 * 以下のコードではビット演算を使って，矩形の正当性(ちゃんと全てのビットを0にできるか)の判定を高速化している．
 * オーダーは O(2^(N^2)) ．
 */
#include <iostream>
#include <vector>

using namespace std;

const int INF = 30;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int N;
        cin >> N;
        if(!N) break;
        vector<int> field(N);
        for(int i = 0; i < N; ++i) {
            int pat = 0;
            for(int j = 0; j < N; ++j) {
                int v;
                cin >> v;
                pat <<= 1;
                pat |= v;
            }
            field[i] = pat;
        }
        // ビット演算で扱いやすくするため，右端を座標 0 として扱う．
        vector<int> myons; // 行にかかるmyon
        for(int c = 0; c < N; ++c) { // 右端の位置
            for(int w = 1; w <= N-c; ++w) {
                int mask = ((1<<w)-1) << c;
                myons.push_back(mask);
                //cout << mask << endl;
            }
        }
        const int M = myons.size();
        // 0: prev
        // 1: cur
        vector<int> valid_pats[2];
        vector<int> dp[2];
        dp[0].resize(1<<M, INF);
        dp[1].resize(1<<M, INF);
        for(int r = 0; r < N; ++r) {
            valid_pats[1].clear();
            fill(dp[1].begin(), dp[1].end(), INF);
            for(int pat = 0; pat < (1<<M); ++pat) {
                int mask = 0;
                for(int i = 0, ord = 1; i < M; ++i, ord <<= 1) {
                    if(pat & ord) mask ^= myons[i];
                }
                if(mask == field[r]) {
                    // Valid pattern
                    int cost = INF;
                    const int bits = __builtin_popcount(pat);
                    if(r != 0) {
                        // コストは
                        //   直前で有効な状態のコスト + 現在のパターンのコスト - 直前と合成する矩形のコスト
                        for(vector<int>::iterator it = valid_pats[0].begin(); it != valid_pats[0].end(); ++it) {
                            cost = min(cost, dp[0][*it] + bits - __builtin_popcount(pat & *it));
                        }
                    } else {
                        cost = bits;
                    }
                    //cout << r << ' ' << pat << ' ' << cost << endl;
                    dp[1][pat] = cost;
                    valid_pats[1].push_back(pat);
                }
            }
            valid_pats[0].swap(valid_pats[1]);
            dp[0].swap(dp[1]);
        }
        int ans = INF;
        for(vector<int>::iterator it = valid_pats[0].begin(); it != valid_pats[0].end(); ++it) {
            ans = min(ans, dp[0][*it]);
        }
        for(int i = 0; i < ans; ++i) {
            cout << "myon";
        }
        cout << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 2430
memory_kb: 1364
final_rank: 8

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

using namespace std;

const int INF = 30;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int N;
        cin >> N;
        if(!N) break;
        vector<int> field(N);
        for(int i = 0; i < N; ++i) {
            int pat = 0;
            for(int j = 0; j < N; ++j) {
                int v;
                cin >> v;
                pat <<= 1;
                pat |= v;
            }
            field[i] = pat;
        }
        vector<int> myons; // ティツ。ツ古」ツ?ォテ」ツ?凝」ツ?凝」ツつ砧yon
        for(int c = 0; c < N; ++c) { // テ・ツ渉ウテァツォツッテ」ツ?ョテ、ツスツ催ァツスツョ
            for(int w = 1; w <= N-c; ++w) {
                int mask = ((1<<w)-1) << c;
                myons.push_back(mask);
                //cout << mask << endl;
            }
        }
        const int M = myons.size();
        // 0: prev
        // 1: cur
        vector<int> valid_pats[2];
        vector<int> dp[2];
        dp[0].resize(1<<M, INF);
        dp[1].resize(1<<M, INF);
        for(int r = 0; r < N; ++r) {
            valid_pats[1].clear();
            fill(dp[1].begin(), dp[1].end(), INF);
            for(int pat = 0; pat < (1<<M); ++pat) {
                int mask = 0;
                for(int i = 0, ord = 1; i < M; ++i, ord <<= 1) {
                    if(pat & ord) mask ^= myons[i];
                }
                if(mask == field[r]) {
                    // Valid pattern
                    int cost = INF;
                    const int bits = __builtin_popcount(pat);
                    if(r != 0) {
                        for(vector<int>::iterator it = valid_pats[0].begin(); it != valid_pats[0].end(); ++it) {
                            cost = min(cost, dp[0][*it] + bits - __builtin_popcount(pat & *it));
                        }
                    } else {
                        cost = bits;
                    }
                    //cout << r << ' ' << pat << ' ' << cost << endl;
                    dp[1][pat] = cost;
                    valid_pats[1].push_back(pat);
                }
            }
            valid_pats[0].swap(valid_pats[1]);
            dp[0].swap(dp[1]);
        }
        int ans = INF;
        for(vector<int>::iterator it = valid_pats[0].begin(); it != valid_pats[0].end(); ++it) {
            ans = min(ans, dp[0][*it]);
        }
        for(int i = 0; i < ans; ++i) {
            cout << "myon";
        }
        cout << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 2430
memory_kb: 1360
final_rank: 7

code_snippet: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)

int n,g,a,b;
int d[1<<20];
vector<int> m[5][5];

int rec(int g, int t){
  if(t == 5){
    if( (g & 31) )return 1000000;
    return d[g>>5];
  }
  int r = rec(g,t+1);
  for(int i=0;i<m[0][t].size();i++)r = min(r,rec(g^m[0][t][i],t+1)+1);
  return r;
}
    
int main(){
  REP(i,0,5)REP(j,0,5)REP(k,i,5)REP(l,j,5){
    int tmp = 0;
    REP(y,i,k+1)REP(x,j,l+1)tmp |= 1<<(y*5+x);
    m[i][j].push_back(tmp);
  }

  for(int i=0;i<(1<<20);i++)d[i] = -1; d[0] = 0;
  queue<int> q; q.push(0);
  while(q.size()){
    int p = q.front(); q.pop();
    REP(i,0,4)REP(j,0,5)REP(k,0,m[i][j].size()){
      if(m[i][j][k]>=1<<20)continue;
      int nxt = p^m[i][j][k];
      if(d[nxt]<0){
	d[nxt] = d[p] + 1;
	q.push(nxt);
      }
    }
  }

  while(cin >> n,n){
    g = 0;
    REP(i,0,5)REP(j,0,5)
      if(i<n && j<n){
	cin >> b;
	g |= b<<(i*5+j);
      }
    
    if(n<5)a = d[g];
    else a = rec(g,0);
    
    REP(i,0,a)cout << "myon";
    cout << endl;
  }
}
accuracy: 1
time_ms: 570
memory_kb: 7804
final_rank: 4

code_snippet: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)

int n,g,bit,res;
int dis[1<<20];
vector<int> mask[5][5];

int rec(int g, int t){
  if(t == 5){
    if( (g & 31) )return 1000000;
    return dis[g>>5];
  }
  int res = rec(g,t+1);
  for(int i=0;i<mask[0][t].size();i++)res = min(res,rec(g^mask[0][t][i],t+1)+1);
  return res;
}
    
int main(){
  REP(i,0,5)REP(j,0,5)REP(k,i,5)REP(l,j,5){
    int tmp = 0;
    REP(y,i,k+1)REP(x,j,l+1)tmp |= 1<<(y*5+x);
    mask[i][j].push_back(tmp);
  }

  for(int i=0;i<(1<<20);i++)dis[i] = -1;
  dis[0] = 0;
  queue<int> q; q.push(0);
  while(q.size()){
    int p = q.front(); q.pop();
    REP(i,0,4)REP(j,0,5)REP(k,0,mask[i][j].size()){
      if(mask[i][j][k]>=1<<20)continue;
      int nxt = p^mask[i][j][k];
      if(dis[nxt]<0){
	dis[nxt] = dis[p] + 1;
	q.push(nxt);
      }
    }
  }

  while(cin >> n,n){
    g = 0;
    REP(i,0,5)REP(j,0,5)
      if(i<n && j<n){
	cin >> bit;
	g |= bit<<(i*5+j);
      }
    
    if(n<5)res = dis[g];
    else res = rec(g,0);
    
    for(int i=0;i<res;i++)cout << "myon";
    cout << endl;
  }
}
accuracy: 1
time_ms: 560
memory_kb: 7804
final_rank: 3

code_snippet: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

int n,g,bit;
int dis[1<<20];
vector<int> mask[5][5];

int rec(int g, int t){
  if(t == 5){
    if( (g & 31) )return 1000000;
    return dis[g>>5];
  }

  int res = rec(g,t+1);
  for(int i=0;i<mask[0][t].size();i++){
    res = min(res,rec(g^mask[0][t][i],t+1)+1);
  }
  return res;
}
    
int main(){
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      for(int k=i;k<5;k++){
	for(int l=j;l<5;l++){
	  int tmp = 0;
	  for(int y=i;y<=k;y++){
	    for(int x=j;x<=l;x++){
	      tmp |= 1<<(y*5+x);
	    }
	  }
	  mask[i][j].push_back(tmp);
	}
      }
    }
  }

  for(int i=0;i<(1<<20);i++)dis[i] = -1;
  dis[0] = 0;
  queue<int> q; q.push(0);
  while(q.size()){
    int p = q.front(); q.pop();
    for(int i=0;i<4;i++)
      for(int j=0;j<5;j++){
	for(int k=0;k<mask[i][j].size();k++){
	  if(mask[i][j][k]>=1<<20)continue;
	  int nxt = p^mask[i][j][k];
	  if(dis[nxt]<0){
	    dis[nxt] = dis[p] + 1;
	    q.push(nxt);
	  }
	}
      }
  }

  while(cin >> n,n){
    g = 0;
    for(int i=0;i<5;i++){
      for(int j=0;j<5;j++){
	if(i<n && j<n){
	  cin >> bit;
	  g |= bit<<(i*5+j);
	}
      }
    }
    if(n<5){
      for(int i=0;i<dis[g];i++)cout << "myon";
      cout << endl;
    }else{
      int tmp = rec(g,0);
      for(int i=0;i<tmp;i++)cout << "myon";
      cout << endl;
    }
  }
}
accuracy: 1
time_ms: 570
memory_kb: 7804
final_rank: 4