#include<iostream>
#include<vector>
using namespace std;
class XorBoardDivTwo{
public:
int theMax(vector<string> board){
int r=board.size();
int res=0,temp=0,best=0;
int rsum[50]={0},csum[50]={0};
int c=board[0].size();
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++){
int tem=(board[i][j]=='0')?0:1;
rsum[i]+=tem;
csum[j]+=tem;
temp+=tem;
}
}
for(int i1=0;i1<r;i1++)
for(int j=0;j<c;j++){
int tem=(board[i1][j]=='0')?0:1;
res=temp+r-2*rsum[i1]+c-2*csum[j]+4*tem-2;
if(res>best)
best=res;
}
return best;
}
};
#include <vector>
#include <iostream>
using namespace std;
class XorBoardDivTwo {
public:
int theMax(vector <string> board) {
//result of the function
int res = 0;
//use tmp as a draft
vector <string> tmp;
//the number of rows and columns of the grid
int r, c;
r = board.size();
c = board[0].size();
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++) {
tmp = board;
//try flipping the ith row
for (int k = 0; k < c; k++)
tmp[i][k] = (tmp[i][k] == '1' ? '0': '1');
//and then flipping column jth
for (int k = 0; k < r; k++)
tmp[k][j] = (tmp[k][j] == '1' ? '0': '1');
//counting the number of '1'
int cnt = 0;
for (int x = 0; x < r; x ++)
for (int y = 0; y < c; y++)
cnt += tmp[x][y] == '1';
//update the result
res = max(res, cnt);
}
return res;
}
};
#include<iostream>
#include<string>
using namespace std;
class CuttingBitString{
public:
bool check(string s){
if(s[0]=='0') return false;
//long long t=0;//long long is 64bite, VC is not stand.
long t=0;
int size=s.size();
for(int i=0;i<size;i++){
t=t*2+(s[i]=='1');
}
while(t%5==0)
t/=5;
return t==1;
}
int getmin(string s){
int F[50];
int n=s.size();
for(int i=0;i<n;i++){
F[i]=-1;
if(check(s.substr(0,i+1))){
F[i]=1;
}
else{
for(int j=1;j<=i;j++){
if(check(s.substr(j,i-j+1))&&F[j-1]!=-1){
if(F[i]>F[j-1]+1||F[i]==-1){
F[i]=F[j-1]+1;
}
}
}
}
}
return F[n-1];
}
};
public class CuttingBitString {
public int getmin(String S) {
Set<Long> powof5 = new HashSet<Long>();
for(long v = 1; v < (1L << 55); v *= 5){
powof5.add(v); }
char[] s = S.toCharArray();
int[] dp = new int[s.length + 1];
Arrays.fill(dp, Integer.MAX_VALUE);
dp[s.length] = 0;
for(int i = s.length - 1; i >= 0; --i){
if(s[i] == '0'){
continue;
}
long val = 0;
for(int j = i + 1; j <= s.length; ++j){
val = (val << 1) + (s[j - 1] - '0');
if(powof5.contains(val)){
if(dp[j] != Integer.MAX_VALUE){
dp[i] = Math.min(dp[i], dp[j] + 1);
}
}
}
}
return dp[0] == Integer.MAX_VALUE ? -1 : dp[0];
}
}