{"problem":{"name":"B. Flag of Berland","description":{"content":"The flag of Berland is such rectangular field _n_ × _m_ that satisfies following conditions: *   Flag consists of three colors which correspond to letters _'R'_, _'G'_ and _'B'_. *   Flag consists of","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF837B"},"statements":[{"statement_type":"Markdown","content":"The flag of Berland is such rectangular field _n_ × _m_ that satisfies following conditions:\n\n*   Flag consists of three colors which correspond to letters _'R'_, _'G'_ and _'B'_.\n*   Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has **exactly one color**.\n*   Each color should be used in **exactly one stripe**.\n\nYou are given a field _n_ × _m_, consisting of characters _'R'_, _'G'_ and _'B'_. Output \"_YES_\" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print \"_NO_\" (without quotes).\n\n## Input\n\nThe first line contains two integer numbers _n_ and _m_ (1 ≤ _n_, _m_ ≤ 100) — the sizes of the field.\n\nEach of the following _n_ lines consisting of _m_ characters _'R'_, _'G'_ and _'B'_ — the description of the field.\n\n## Output\n\nPrint \"_YES_\" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print \"_NO_\" (without quotes).\n\n[samples]\n\n## Note\n\nThe field in the third example doesn't have three parralel stripes.\n\nRows of the field in the fourth example are parralel to each other and to borders. But they have different heights — _2_, _1_ and _1_.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"贝兰的国旗是一个满足以下条件的矩形区域 #cf_span[n × m]：\n\n给你一个由字符 _'R'_、_'G'_ 和 _'B'_ 组成的 #cf_span[n × m] 区域。如果该区域对应贝兰的正确国旗，则输出 \"_YES_\"（不含引号）；否则，输出 \"_NO_\"（不含引号）。\n\n第一行包含两个整数 #cf_span[n] 和 #cf_span[m]（#cf_span[1 ≤ n, m ≤ 100]）——表示区域的尺寸。\n\n接下来的 #cf_span[n] 行，每行包含 #cf_span[m] 个字符 _'R'_、_'G'_ 和 _'B'_——表示区域的描述。\n\n如果给定区域对应贝兰的正确国旗，则输出 \"_YES_\"（不含引号）；否则，输出 \"_NO_\"（不含引号）。\n\n第三个示例中的区域没有三条平行的条纹。\n\n第四个示例中的区域行彼此平行且与边界平行，但它们的高度不同——为 _2_、_1_ 和 _1_。\n\n## Input\n\n第一行包含两个整数 #cf_span[n] 和 #cf_span[m]（#cf_span[1 ≤ n, m ≤ 100]）——表示区域的尺寸。接下来的 #cf_span[n] 行，每行包含 #cf_span[m] 个字符 _'R'_、_'G'_ 和 _'B'_——表示区域的描述。\n\n## Output\n\n如果给定区域对应贝兰的正确国旗，则输出 \"_YES_\"（不含引号）；否则，输出 \"_NO_\"（不含引号）。\n\n[samples]\n\n## Note\n\n第三个示例中的区域没有三条平行的条纹。第四个示例中的区域行彼此平行且与边界平行，但它们的高度不同——为 _2_、_1_ 和 _1_。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n, m \\in \\mathbb{Z} $ denote the dimensions of the field, with $ 1 \\leq n, m \\leq 100 $.  \nLet $ F \\in \\{R, G, B\\}^{n \\times m} $ be the grid representing the flag, where $ F[i][j] $ is the color at row $ i $, column $ j $.\n\n**Constraints**  \n1. Each cell $ F[i][j] \\in \\{R, G, B\\} $.  \n2. The flag must consist of exactly three **horizontal** stripes (i.e., full-width rows), each of uniform color.  \n3. The three stripes must be **parallel to the horizontal borders** (i.e., each stripe spans all $ m $ columns).  \n4. The three stripes must have **distinct colors** from $ \\{R, G, B\\} $, each appearing exactly once.  \n5. The heights of the stripes (number of consecutive rows per stripe) must be **positive integers** summing to $ n $, and **no stripe may be split** across non-consecutive row blocks.\n\n**Objective**  \nDetermine whether $ F $ satisfies all above constraints. Output:  \n$$\n\\begin{cases}\n\\text{\"YES\"} & \\text{if } F \\text{ is a valid Berland flag} \\\\\n\\text{\"NO\"} & \\text{otherwise}\n\\end{cases}\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF837B","tags":["brute force","implementation"],"sample_group":[["6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG","YES"],["4 3\nBRG\nBRG\nBRG\nBRG","YES"],["6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB","NO"],["4 4\nRRRR\nRRRR\nBBBB\nGGGG","NO"]],"created_at":"2026-03-03 11:00:39"}}