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



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


Sample output:
myonmyonmyon
myon
myonmyon

Submission status: Wrong Answer

Solution code:
code="""\
#include <bits/stdc++.h>
using namespace std;

#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define all(c) begin(c),end(c)

int main()
{
	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;
		}
	}
	
	static array<uint8_t,1<<25> ds; ds.fill(-1); ds[0]=0;
	for(int i=0;count(all(ds),i);i++)
		rep(j,1<<25) if(ds[j]==i)
			for(int m:ms) ds[j^m]=min<uint8_t>(ds[j^m],i+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);
		}
		string res;
		rep(i,ds[x]) res+="myon";
		cout<<res<<endl;
	}
}
"""

import os,tempfile
(_,filename)=tempfile.mkstemp(".cpp")

f=open(filename,"w")
f.write(code)
f.close()

os.system("g++ -std=c++0x -O2 {}".format(filename))
os.system("./a.out")

Submission status: Accepted

Solution code:
# AOJ 1059 Mysterious Onslaught
# Python3 2018.7.7 bal4u

def calc(b):
	if b == 0: return 0;
	if memo[b] >= 0: return memo[b]
	f = False
	for r1 in range(n):
		for c1 in range(n):
			if b & (1<<(5*r1+c1)):
				f, rr, cc = True, r1, c1
				break
		if f: break
	if not f:
		memo[b] = 0
		return 0

	ans = 25;
	for r2 in range(rr, n):
		for c2 in range(cc, n):
			k = b ^ arr[rr][cc][r2][c2]
			ans = min(ans, calc(k)+1)
	memo[b] = ans
	return ans

memo = [-1]*(1<<25)
arr = [[[[0 for c2 in range(5)] for r2 in range(5)] \
		    for c1 in range(5)] for r1 in range(5)]
for r1 in range(5):
	for c1 in range(5):
		for r2 in range(r1, 5):
			for c2 in range(c1, 5):
				for r in range(r1, r2+1):
					for c in range(c1, c2+1):
						arr[r1][c1][r2][c2] |= (1<<(r*5+c))

while True:
	n = int(input())
	if n == 0: break
	a = [list(map(int, input().split())) for i in range(n)]
	b = 0;
	for r in range(n):
		for c in range(n):
			if a[r][c]: b |= 1 << (5*r+c)
	print("myon"*calc(b))