{"raw_statement":[{"iden":"statement","content":"You are given an image, that can be represented with a 2\\-d _n_ by _m_ grid of pixels. Each pixel of the image is either on or off, denoted by the characters \"_0_\" or \"_1_\", respectively. You would like to compress this image. You want to choose an integer _k_ > 1 and split the image into _k_ by _k_ blocks. If _n_ and _m_ are not divisible by _k_, the image is padded with only zeros on the right and bottom so that they are divisible by _k_. Each pixel in each individual block must have the same value. The given image may not be compressible in its current state. Find the minimum number of pixels you need to toggle (after padding) in order for the image to be compressible for some _k_. More specifically, the steps are to first choose _k_, then the image is padded with zeros, then, we can toggle the pixels so it is compressible for this _k_. The image must be compressible in that state."},{"iden":"input","content":"The first line of input will contain two integers _n_, _m_ (2 ≤ _n_, _m_ ≤ 2 500), the dimensions of the image.\n\nThe next _n_ lines of input will contain a binary string with exactly _m_ characters, representing the image."},{"iden":"output","content":"Print a single integer, the minimum number of pixels needed to toggle to make the image compressible."},{"iden":"example","content":"Input\n\n3 5\n00100\n10110\n11001\n\nOutput\n\n5"},{"iden":"note","content":"We first choose _k_ = 2.\n\nThe image is padded as follows:\n\n001000\n101100\n110010\n000000\n\nWe can toggle the image to look as follows:\n\n001100\n001100\n000000\n000000\n\nWe can see that this image is compressible for _k_ = 2."}],"translated_statement":"[{\"iden\":\"statement\",\"content\":\"给你一张图像，可以用一个大小为 #cf_span[n] × #cf_span[m] 的二维像素网格表示。每个像素要么开启（用字符 \\\"_0_\\\" 表示），要么关闭（用字符 \\\"_1_\\\" 表示）。你希望压缩这张图像。你需要选择一个整数 #cf_span[k > 1]，并将图像分割为 #cf_span[k] × #cf_span[k] 的块。如果 #cf_span[n] 和 #cf_span[m] 不能被 #cf_span[k] 整除，则在图像的右侧和底部填充仅由零组成的像素，使得其尺寸能被 #cf_span[k] 整除。每个块内的所有像素必须具有相同的值。当前图像可能无法直接压缩。请找出在填充后，最少需要翻转多少个像素，才能使图像对于某个 #cf_span[k] 可压缩。更具体地说，步骤为：首先选择 #cf_span[k]，然后对图像进行填充，接着翻转一些像素，使得图像对该 #cf_span[k] 可压缩。最终图像必须满足可压缩条件。\\n\\n输入的第一行包含两个整数 #cf_span[n, m] (#cf_span[2 ≤ n, m ≤ 2 500])，表示图像的尺寸。\\n\\n接下来的 #cf_span[n] 行，每行包含一个恰好有 #cf_span[m] 个字符的二进制字符串，表示图像。\\n\\n请输出一个整数，表示使图像可压缩所需的最少翻转像素数。\"}},{\"iden\":\"input\",\"content\":\"输入的第一行包含两个整数 #cf_span[n, m] (#cf_span[2 ≤ n, m ≤ 2 500])，表示图像的尺寸。接下来的 #cf_span[n] 行，每行包含一个恰好有 #cf_span[m] 个字符的二进制字符串，表示图像。\"},{\"iden\":\"output\",\"content\":\"请输出一个整数，表示使图像可压缩所需的最少翻转像素数。\"},{\"iden\":\"note\",\"content\":\"我们首先选择 #cf_span[k = 2]。图像填充后如下：001000101100110010000000我们可以翻转图像使其变为如下形式：001100001100000000000000可以看出，该图像对于 #cf_span[k = 2] 是可压缩的。\"}]","sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n, m \\in \\mathbb{Z} $ be the dimensions of the image grid, with $ 2 \\leq n, m \\leq 2500 $.  \nLet $ G \\in \\{0,1\\}^{n \\times m} $ be the input binary grid, where $ G[i][j] \\in \\{0,1\\} $ denotes the pixel at row $ i $, column $ j $.  \n\nFor a chosen integer $ k > 1 $, define the padded dimensions:  \n$$\nn' = \\left\\lceil \\frac{n}{k} \\right\\rceil \\cdot k, \\quad m' = \\left\\lceil \\frac{m}{k} \\right\\rceil \\cdot k\n$$  \nThe padded grid $ G' \\in \\{0,1\\}^{n' \\times m'} $ is formed by appending $ n' - n $ rows and $ m' - m $ columns of zeros to $ G $.  \n\nThe grid $ G' $ is **compressible** for $ k $ if it can be partitioned into $ \\frac{n'}{k} \\times \\frac{m'}{k} $ disjoint $ k \\times k $ blocks, such that **all pixels in each block are equal** (i.e., each block is monochromatic).  \n\n**Constraints**  \n1. $ k \\in \\mathbb{Z} $, $ k > 1 $  \n2. $ n' \\geq n $, $ m' \\geq m $, and $ k \\mid n' $, $ k \\mid m' $  \n3. The number of toggles is the Hamming distance between $ G' $ and a compressible grid $ H \\in \\{0,1\\}^{n' \\times m'} $, where $ H $ is constant on each $ k \\times k $ block.  \n\n**Objective**  \nFind the minimum number of pixel toggles over all valid $ k > 1 $:  \n$$\n\\min_{\\substack{k > 1 \\\\ k \\in \\mathbb{Z}}} \\left( \\min_{\\substack{H \\in \\{0,1\\}^{n' \\times m'} \\\\ H \\text{ is } k\\text{-compressible}}} \\sum_{i=1}^{n'} \\sum_{j=1}^{m'} \\left| G'[i][j] - H[i][j] \\right| \\right)\n$$  \nwhere $ G' $ is the zero-padded version of $ G $ for the chosen $ k $.","simple_statement":null,"has_page_source":false}