Language: C++

#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define loop(i, times) for(int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) for(int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) for(int i = start_index; i <= end_index; i++)

class NyaGadgetVector
{
public:
	/**
	@brief 加算関数
	@note
	 collectionの全要素にadd_valueだけ値を加算する
	**/
	template<typename T> static void Add(vector<T>& collection, T add_value)
	{
		for (auto& e : collection)
			e += add_value;
	}
	/**
	@brief 比較関数
	@note
	 collection1とcollection2の中身が同じかどうか調べる。
	 collectionの要素が全て同じなら0を返す。
	 collectionの要素が同じでなkれば、異なる要素の個数を返す。
	**/
	template<typename T> static int Compare(const vector<T>& collection1, const vector<T>& collection2)
	{
		int diff = 0;
		int n = min((int)collection1.size(), (int)collection2.size());
		for (int i = 0; i < n; i++)
		{
			if (collection1[i] != collection2[i])
				diff++;
		}
		diff += abs(collection1.size() - collection2.size());

		return diff;
	}
	/**
	@brief 同じ要素の個数を数える関数
	@note
	 コンテナinput_collectionの同じ要素の個数を数えてoutput_collectionに結果を格納する。
	 output_collectionの第一引数には要素の値、第二引数には要素の個数が格納される。
	-------------------------------------------------------------------------------------
	[sample code]
	int main() {
		vector<long> input_collection = {10000000000, 10000000000, 2, 1, 2, 2, 2};
		vector<pair<long, int>> count_collection;			// p.first=value, p.second=size
		NyaGadgetVector::CountValue<long>(input_collection, count_collection);

		for (const auto& e : count_collection)
			cout << "(" << e.first << "," << e.second << ")";
		return 0;
	}
	[output]
	(1,1)(2,4)(10000000000,2)
	**/
	template<typename T> static void CountValue(const vector<T>& input_collection, vector<pair<T, int>>& output_collection)
	{
		map<T, int> count_collection;
		for (const auto& e : input_collection)
			count_collection[e] += 1;

		for (const auto e : count_collection)
			output_collection.push_back(make_pair(e.first, e.second));
	}
	/**
	@brief 標準入力関数
	@note
	 標準入力から入力されたsize個の値をcollectionに格納する
	**/
	template<typename T> static void InputStream(vector<T>& collection, int size)
	{
		for (int i = 0; i < size; i++)
			cin >> collection[i];
	}
	/**
	@brief pairの引数を反転させる関数
	@note
	 input_collectionのpair.firstとpair.secondを入れ替えて新たなコンテナを作成する。
	**/
	template<typename T, typename U> static void TurnPair(const vector<pair<T, U>>& input_collection, vector<pair<U, T>>& output_collection)
	{
		for (const auto& e : input_collection)
			output_collection.push_back(make_pair(e.second, e.first));
	}
	/**
	@brief 最大値取得関数
	@note
	 collectionの要素の中で最大値を取得する
	**/
	template<typename T> static T Max(const vector<T>& collection)
	{
		T max = collection[0];
		for (const auto& e : collection)
		{
			if (max < e)
				max = e;
		}
		return max;
	}
	/**
	@brief 最小値取得関数
	@note
	 collectionの要素の中で最大値を取得する
	**/
	template<typename T> static T Min(const vector<T>& collection)
	{
		T min = collection[0];
		for (const auto& e : collection)
		{
			if (e < min)
				min = e;
		}
		return min;
	}
	/**
	@brief 置換関数
	@note
	 collectionの全要素をreplace_valueに置き換える
	**/
	template<typename T> static void Replace(vector<T>& collection, T replace_value)
	{
		for (auto& e : collection)
			e = replace_value;
	}
	/**
	@brief 合計関数
	@note
	 collectionの要素を合計して返す(範囲はstart_index以上end_index未満)
	**/
	template<typename T> static T Sum(const vector<T>& collection, int start_index, int end_index)
	{
		int sum = 0;
		for (int i = start_index; i < end_index; i++)
			sum += collection[i];
		return sum;
	}
};



void CreateCharTable(string input, vector<int>& collection)
{
	int index = input.size() - 1;
	collection.resize((int)('z') + 1);
	while (index != -1)
	{
		collection[(int)(input[index])] = index;
		index--;
	}
}

int main()
{
	string s; cin >> s;
	string t; cin >> t;

	if (s.size() != t.size())
	{	// 例外処理 入力文字のサイズが違うとき
		cout << "No";
		return 0;
	}

	// 文字テーブルの作成
	vector<int> s_char_table, t_char_table;
	CreateCharTable(s, s_char_table);
	CreateCharTable(t, t_char_table);

	// 各文字のインデックスコンテナを作成
	int str_size = s.size();
	vector<vector<int>> s_char_index_collection;
	s_char_index_collection.resize(str_size);
	vector<vector<int>> t_char_index_collection;
	t_char_index_collection.resize(str_size);
	loop(i, str_size)
		s_char_index_collection[s_char_table[(int)(s[i])]].push_back(i);
	int t_size = t.size();
	loop(i, str_size)
		t_char_index_collection[t_char_table[(int)(t[i])]].push_back(i);

	loop(i, str_size)
	{	// 各文字のインデックスが異なれば"No"
		if (NyaGadgetVector::Compare<int>(s_char_index_collection[i], t_char_index_collection[i]) != 0)
		{
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}


Compiler output:
a.cc: In instantiation of 'static int NyaGadgetVector::Compare(const std::vector<T>&, const std::vector<T>&) [with T = int]':
a.cc:194:36:   required from here
  194 |                 if (NyaGadgetVector::Compare<int>(s_char_index_collection[i], t_char_index_collection[i]) != 0)
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:45:28: error: call of overloaded 'abs(std::vector<int>::size_type)' is ambiguous
   45 |                 diff += abs(collection1.size() - collection2.size());
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/bits/stl_algo.h:71,
                 from /usr/include/c++/14/algorithm:61,
                 from a.cc:1:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~