public String lastPatch(int length, int width, String[] colorList) {
		int colorNum = colorList.length;
		int[] dx = {0,-1,0,1};
		int[] dy = {-1,0,1,0};
		int[] used = new int[200];
		int quilt[][] = new int[200][200];
		int x = 100,y=100,dir=0,gone=0,toGo=1;
		int all = length*width;
		int lx=0,ly=0;
		
		for(int i = 0;i < 200;i++)
			for(int j = 0;j < 200;j++)
				quilt[i][j]= -1; 
		
		for(int i = 0;i < all;i++){
			//find a color to put in (x,y)
			int nb[] = new int[colorNum];
			for(int m=x-1;m<=x+1;m++){
				for(int n = y-1;n <= y+1;n++){
					//System.out.printf("%d %d %d\n",m,n,quilt[m][n]);
					if(!(m==x && n ==y)){
						if(quilt[m][n] >= 0){
							nb[quilt[m][n]]++;
						}
					}
				}
			}
			System.out.println();
			
			int miniColor = 0;
			for(int k = 0;k < colorNum;k++){
				if(nb[k] < nb[miniColor] || nb[k] == nb[miniColor]  && used[k] < used[miniColor])
					miniColor = k;
			}
			quilt[x][y] = miniColor;
			used[miniColor]++;
			
			
			lx = x;
			x = x + dx[dir];
			ly = y;
			y = y + dy[dir];
			
			gone++;
			if(gone == toGo){
				dir = (dir+1)%4;
				if(dir == 2||dir==0)
					toGo++;
				gone=0;
			}
		}
		return colorList[quilt[lx][ly]];
	}