{"raw_statement":[{"iden":"statement","content":"You are given a rectangular matrix representing a picture made by Peter. The '#' character represents a black pixel and the '.' character a white pixel. You should count how many stones are on the picture with the respective letters A, B, and C.\n\nThe first line contains two integers $W$ and $H$. The next $H$ lines each contain a string of length $W$. The strings are composed of '.' and '#'.\n\n*Limits* \n\nThe output should consist of a single line, whose content is three integers $A$, $B$, and $C$ separated with single spaces, indicating the number of stones with the respective marks A, B, and C.\n\n*Sample Explanation*\n\nThere are black pixels forming a letter C. These pixels, however, belong to the region around the stones and do not form a mark since they are not surrounded by white pixels.\n\n"},{"iden":"input","content":"The first line contains two integers $W$ and $H$. The next $H$ lines each contain a string of length $W$. The strings are composed of '.' and '#'.*Limits*   $7 <= W <= 1000$;  $9 <= H <= 1000$. "},{"iden":"output","content":"The output should consist of a single line, whose content is three integers $A$, $B$, and $C$ separated with single spaces, indicating the number of stones with the respective marks A, B, and C."},{"iden":"note","content":"*Sample Explanation*There are black pixels forming a letter C. These pixels, however, belong to the region around the stones and do not form a mark since they are not surrounded by white pixels."}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ W, H \\in \\mathbb{Z}^+ $ denote the width and height of the matrix.  \nLet $ M \\in \\{ \\text{`.`}, \\text{`#`} \\}^{H \\times W} $ be the binary matrix representing the picture, where `#` denotes a black pixel and `.` denotes a white pixel.  \n\nLet $ R \\subseteq \\{ (i,j) \\mid 1 \\le i \\le H, 1 \\le j \\le W \\} $ be the set of all connected components of black pixels under 4-directional connectivity (up, down, left, right).  \n\nFor each connected component $ c \\in R $, define its **bounding box** as the minimal axis-aligned rectangle enclosing all pixels in $ c $.  \n\nDefine a **stone** as a connected component $ c \\in R $ such that:  \n- All pixels in $ c $ are part of a **closed contour** forming one of the letters A, B, or C.  \n- The contour is **fully surrounded by white pixels** (i.e., no black pixel touches the matrix boundary).  \n- The shape of $ c $ matches the topological structure of one of the letters A, B, or C (as defined by standard pixel-based glyph recognition: A has a triangular top and a horizontal bar; B has two half-circles and a vertical bar; C is a concave curve open to the right).  \n\n**Constraints**  \n1. $ 1 \\le W, H \\le 100 $  \n2. Each connected component $ c \\in R $ consists of at least 3 pixels.  \n3. Only components fully enclosed by white pixels (i.e., no pixel in $ c $ is on the matrix boundary) are considered valid stones.  \n\n**Objective**  \nCount the number of valid stone components matching the shapes of letters A, B, and C:  \nLet $ A = |\\{ c \\in R \\mid c \\text{ matches shape A} \\}| $,  \n$ B = |\\{ c \\in R \\mid c \\text{ matches shape B} \\}| $,  \n$ C = |\\{ c \\in R \\mid c \\text{ matches shape C} \\}| $.  \n\nOutput: $ A \\ B \\ C $","simple_statement":"Count the number of stone shapes labeled A, B, and C in a grid of '#' (black) and '.' (white) pixels. Each stone is a connected group of '#' pixels shaped like one of the letters A, B, or C. Only count shapes that are fully surrounded by '.' — ignore outer '#' that are part of the background.","has_page_source":false}