#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
typedef std::vector<std::uint64_t> DType;

DType SepDigit(std::uint64_t N){
	std::uint64_t V;
	std::uint64_t Radix = 10;
	DType R;
	while (N != 0){
		V = N%Radix;
		N /= Radix;
		R.push_back(V);
	}

	return R;
}

std::uint64_t MakeHoge(std::uint64_t A, std::uint64_t B){
	auto AV = SepDigit(A);
	auto BV = SepDigit(B);

	auto L = std::min(AV.size(), BV.size());
	std::uint64_t C=0;

	AV.resize(L);
	BV.resize(L);

	std::sort(BV.begin(), BV.end());
	BV.erase(std::unique(BV.begin(), BV.end()),BV.end());

	for (auto& o : AV){
		C += std::count(BV.begin(), BV.end(),o);
	}

	return C;
}
std::uint64_t MakeHoge2(std::uint64_t A, std::uint64_t B){
	auto AV = SepDigit(A);
	auto BV = SepDigit(B);

	std::uint64_t j=0;
	auto L = std::min(AV.size(), BV.size());

	AV.resize(L);
	BV.resize(L);

	std::sort(AV.begin(), AV.end());
	std::sort(BV.begin(), BV.end());

	for (std::size_t i = 0; i < std::min(AV.size(),BV.size()); i++)
	{
		if (AV[i] == BV[i]) continue;
		while (AV[i] < j){
			AV.erase(AV.begin() + i);
			if (AV.size() >= i)break;
		}
		while (BV[i] < j){
			BV.erase(BV.begin() + i);
			if (BV.size() >= i)break;
		}
		i--;
		j++;
	}
	return std::min(AV.size(),BV.size());
}
bool Show(std::uint64_t A, std::uint64_t B, std::uint64_t C){
	std::cout << A << ',' << B << " -> " << C << std::endl;
	return true;
}

int main(){
	std::uint64_t A;
	std::uint64_t B;
	std::uint64_t C;
	/**/
	A = 110;
	B = 119;
	C = MakeHoge(A, B);
	Show(A, B, C);

	A = 1234;
	B = 214;
	C = MakeHoge(A, B);
	Show(A, B, C);

	A = 567;
	B = 23;
	C = MakeHoge(A, B);
	Show(A, B, C);

	A = 233;//不可逆。仕様だ！
	B = 333;
	C = MakeHoge(A, B);
	Show(A, B, C);
	C = MakeHoge(B, A);
	Show(B, A, C);
	/**/
	//////////////////////////////////////
	std::cout << std::endl;
	//////////////////////////////////////
	A = 110;
	B = 119;
	C = MakeHoge2(A, B);
	Show(A, B, C);

	A = 1234;
	B = 214;
	C = MakeHoge2(A, B);
	Show(A, B, C);

	A = 567;
	B = 23;
	C = MakeHoge2(A, B);
	Show(A, B, C);

	A = 233;//可逆。になった？！
	B = 333;
	C = MakeHoge2(A, B);
	Show(A, B, C);
	C = MakeHoge2(B, A);
	Show(B, A, C);
	return 0;
}