仔细观察,凡是01相邻的时候,必然会消去,那么最后的结果一定是只有0或者只有1。
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 10;
int main() {
string s;
cin >> s;
int c = 0, d = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1')
c++;
else
d++;
}
cout << 2 * min(c, d);
return 0;
}