{"problem":{"name":"A. Kalevitch and Chess","description":{"content":"A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":65536},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF7A"},"statements":[{"statement_type":"Markdown","content":"A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.\n\nAs before, the chessboard is a square-checkered board with the squares arranged in a 8 × 8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.\n\nKalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.\n\nIt goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.\n\n## Input\n\nThe input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, _W_ character stands for a white square, and _B_ character — for a square painted black.\n\nIt is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).\n\n## Output\n\nOutput the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"著名画家卡列维奇喜欢震惊公众。他最近的一个痴迷是国际象棋。一千多年来，人们一直用单调乏味的棋盘玩这种古老的游戏。卡列维奇决定终结这一传统，为棋盘引入一种新的理念。\n\n与以往一样，棋盘是一个由 8 × 8 方格组成的方格棋盘，每个方格被涂成黑色或白色。卡列维奇建议棋盘应按以下方式绘制：选择一条由 8 个方格组成的水平或垂直线（即一行或一列），并将其涂成黑色。最初整个棋盘是白色的，可以多次以这种方式进行涂色。允许对同一个方格多次涂色，但第一次涂色后，其颜色不再改变，始终保持黑色。卡列维奇作画非常规范，仅凭单个方格无法判断它是被水平线还是垂直线涂黑的。\n\n卡列维奇希望这种棋盘能广受欢迎，从而获得委托绘制棋盘的任务，帮助他安度晚年。客户会告诉他想要什么样的棋盘，而画家则会用白色棋盘满足客户的需求。\n\n毋庸置疑，在这种生意中应尽可能节约资源——对于每一份委托，他都想知道自己最少需要多少次涂色才能满足客户的要求。你需要帮助卡列维奇完成这项任务。\n\n输入文件包含 8 行，每行包含 8 个字符。给定的矩阵描述了客户的需要，_W_ 字符代表白色方格，_B_ 字符代表黑色方格。\n\n保证客户的需要可以通过一系列允许的涂色操作（垂直/列或水平/行）实现。\n\n请输出一个数字——卡列维奇必须在白色棋盘上涂色的最少行数和列数之和，以满足客户的需要。\n\n## Input\n\n输入文件包含 8 行，每行包含 8 个字符。给定的矩阵描述了客户的需要，_W_ 字符代表白色方格，_B_ 字符代表黑色方格。保证客户的需要可以通过一系列允许的涂色操作（垂直/列或水平/行）实现。\n\n## Output\n\n输出一个数字——卡列维奇必须在白色棋盘上涂色的最少行数和列数之和，以满足客户的需要。\n\n[samples]","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ M \\in \\{W, B\\}^{8 \\times 8} $ be the client's target matrix, where $ M_{i,j} $ denotes the color of the square at row $ i $, column $ j $ ($ 1 \\le i,j \\le 8 $).\n\nLet $ R \\subseteq \\{1, \\dots, 8\\} $ be the set of rows painted black.  \nLet $ C \\subseteq \\{1, \\dots, 8\\} $ be the set of columns painted black.\n\nEach stroke (row or column painting) turns all squares in that row/column to black, and subsequent strokes on the same row/column have no effect.\n\n**Constraints**  \nFor all $ i,j \\in \\{1, \\dots, 8\\} $:  \n$$\nM_{i,j} = B \\iff i \\in R \\lor j \\in C\n$$\n\n**Objective**  \nMinimize $ |R| + |C| $, subject to the above constraint.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF7A","tags":["brute force","constructive algorithms"],"sample_group":[["WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW","3"],["WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW","1"]],"created_at":"2026-03-03 11:00:39"}}