RT。
#include <bits/stdc++.h>
using namespace std;
const string a = "100001", b = "999998";
string x, z;
long long zs;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> x >> z;
zs = stoll(z);
if (z.size() < 6 || (z.size() == 6 && z < x)){
cout << stoll("100000" + x)-stoll(z);
return 0;
}
if (z.size() == 13){
cout << zs - stoll("999999"+x);
return 0;
}else if (z.size() == 12) x = z.substr(0, 6) + x;
else{
string tmp = "1";
for (int i(1); i<=11-z.size(); ++i) tmp += '0';
x = tmp + z.substr(0, z.size()-6) + x;
}
// cout << x << '\n';
if (x.substr(0, 6) == "999999") cout << min(abs(stoll(x)-zs), abs(stoll(a+x.substr(6, 6))-zs));
else if (x.substr(0, 6) == "100000") cout << min(abs(stoll(x)-zs), abs(stoll(b+x.substr(6, 6))-zs));
else cout << min({abs(stoll(x)-zs), abs(stoll(to_string(stoll(x.substr(0, 6))+1)+x.substr(6, 6))-zs), abs(stoll(to_string(stoll(x.substr(0, 6))-1)+x.substr(6, 6))-zs)});
return 0;
}