TAMCAM - Tam Cam

This problem is based on the story of Tam and Cam, a well-known Vietnamese fairy tale.

One day, Cam put some rice grains and some paddy grains into the cells of a rectangular table of size mxn. There is at most one grain in each cell. Cam asked Tam to take the minimum number of grains from the table so that in each row and each column of the table, the number of rice grains is the same as the number of paddy grains.

Could you help Tam to do the task?

Input

  • The first line contains two positive integers m,n ≤ 100 separated by a space.
  • The ith line in the next m lines contains n characters. The jth character could be "G", "T", or "." depending on whether the corresponding cell contains a rice grain, a paddy grain, or is empty.

Output

  • The first line contains the minimum number of grains that should be taken from the table.
  • The ith line in the next m lines contains n characters. The jth character could be "G", "T", or "." depending on whether there remains a rice grain, a paddy grain, or nothing in the corresponding cell.

Example

Input
4 5
GT.GG
GGTGT
TTGTG
GTGT.	

Output
6
.T.G.
.GTGT
T.GTG
G..T.


Được gửi lên bởi:Jimmy
Ngày:2009-02-04
Thời gian chạy:0.200s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:VNOI Marathon 2009
Round 1
Problem Setter: Lê Minh Hoàng

hide comments
2015-05-12 05:11:46 Phạm Huỳnh Nhật
oimeoi
2014-09-04 09:13:21 [ND]๖ۣۜMiniString
kho chet mat
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.