C++#include<bits/stdc++.h>
using namespace std;
string st[1000001],tmp;
int flag[1000001];
int main(){
int n,res=0,ans;
scanf("%d",&n);
for(int i=1;i<=n;i++){
cin>>st[i];
}
int f=1;
while(f!=0){
f=0;
for(int i=1;i<=n;i++){
while(st[i][flag[i]]=='0'){
tmp+='0';
flag[i]++;
f=1;
}
}
for(int i=1;i<=n;i++){
while(st[i][flag[i]]=='1'){
tmp+='1';
flag[i]++;
f=1;
}
}
}
int len=tmp.length();
for(int i=0;i<len-1;i++){
if(tmp[i]==tmp[i+1])res++;
}
ans=max(res,res);
res=0;
tmp=' ';
f=1;
memset(flag,0,sizeof(flag));
while(f!=0){
f=0;
for(int i=1;i<=n;i++){
while(st[i][flag[i]]=='1'){
tmp+='1';
flag[i]++;
f=1;
}
}
for(int i=1;i<=n;i++){
while(st[i][flag[i]]=='0'){
tmp+='0';
flag[i]++;
f=1;
}
}
}
len=tmp.length();
for(int i=0;i<len-1;i++){
if(tmp[i]==tmp[i+1])res++;
}
ans=max(res,ans);
printf("%d",ans);
return 0;
}
C++#include<bits/stdc++.h>
using namespace std;
string st[1000001],tmp;
int he[1000001],ta[1000001];
int main(){
int n,res=0,f=1,i,ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
cin>>st[i];
}
while(f=1)
{
f=0;
for(i=1;i<=n;i++)
{
while(str[i][he[i]]=='0'&&str[i][ta[i]]=='0')
{
he[i]++;
h=1;
}
while(str[i][he[i]]=='0'&&str[i][ta[i]]=='1')
{
he[i]++;
h=1;
}
while(str[i][he[i]]=='1'&&str[i][ta[i]]=='1')
}
}
}