{ "56dc2b01": "def solve(grid):\n import copy\n R = len(grid)\n C = len(grid[0])\n two_cells = [(r,c) for r in range(R) for c in range(C) if grid[r][c] == 2]\n three_cells = [(r,c) for r in range(R) for c in range(C) if grid[r][c] == 3]\n two_rows = set(r for r,c in two_cells)\n two_cols = set(c for r,c in two_cells)\n out = [[0]*C for _ in range(R)]\n for r,c in two_cells:\n out[r][c] = 2\n if len(two_rows) == 1:\n line_row = list(two_rows)[0]\n shape_rows = set(r for r,c in three_cells)\n min_r = min(r for r,c in three_cells)\n max_r = max(r for r,c in three_cells)\n shape_h = max_r - min_r + 1\n if all(r < line_row for r in shape_rows):\n new_start_r = line_row - shape_h\n eight_row = new_start_r - 1\n else:\n new_start_r = line_row + 1\n eight_row = new_start_r + shape_h\n for r,c in three_cells:\n new_r = r - min_r + new_start_r\n out[new_r][c] = 3\n for c in range(C):\n if 0 <= eight_row < R:\n out[eight_row][c] = 8\n else:\n line_col = list(two_cols)[0]\n shape_cols = set(c for r,c in three_cells)\n min_c = min(c for r,c in three_cells)\n max_c = max(c for r,c in three_cells)\n shape_w = max_c - min_c + 1\n if all(c < line_col for c in shape_cols):\n new_start_c = line_col - shape_w\n eight_col = new_start_c - 1\n else:\n new_start_c = line_col + 1\n eight_col = new_start_c + shape_w\n for r,c in three_cells:\n new_c = c - min_c + new_start_c\n out[r][new_c] = 3\n for r in range(R):\n if 0 <= eight_col < C:\n out[r][eight_col] = 8\n return out", "57aa92db": "def solve(grid):\n import copy\n R=len(grid); C=len(grid[0]); out=copy.deepcopy(grid)\n visited=set(); objects=[]\n for r in range(R):\n for c in range(C):\n if grid[r][c]!=0 and (r,c) not in visited:\n obj=[]\n stk=[(r,c)]; visited.add((r,c))\n while stk:\n cr,cc=stk.pop(); obj.append((cr,cc,grid[cr][cc]))\n for dr,dc in [(-1,0),(1,0),(0,-1),(0,1)]:\n nr,nc=cr+dr,cc+dc\n if 0<=nrbest_ratio: best_ratio=ratio; tobj=o\n iobjs=[o for o in h2 if o is not tobj]\n tc={}\n for r,c,v in tobj: tc.setdefault(v,[]).append((r,c))\n t2=tc[2]; t2r,t2c=t2[0]; toc=(set(tc)-{2}).pop()\n rp=[(r-t2r,c-t2c) for r,c in tc[toc]]\n for io in iobjs:\n ic={}\n for r,c,v in io: ic.setdefault(v,[]).append((r,c))\n if 2 not in ic: continue\n i2=ic[2]; ioc=(set(ic)-{2}).pop()\n i2mr=min(r for r,c in i2); i2mc=min(c for r,c in i2)\n i2xr=max(r for r,c in i2); i2xc=max(c for r,c in i2)\n bh=i2xr-i2mr+1; bw=i2xc-i2mc+1\n if bh==1 and bw==1:\n for dr,dc in rp:\n tr2=i2mr+dr; tc2=i2mc+dc\n if 0<=tr2