Language: C++

#pragma once

#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#include <deque>
#include <string>

using namespace std;

class NyaGadgetPositionalNotation
{	// N進数を表現するクラス
public:
	NyaGadgetPositionalNotation(int cardinal)
	{
		cardinal_ = cardinal;
		symbol_index_collection_.push_back(0);
	}
	void Inc()
	{	// 返り値なしのインクリメント
		bool carry = true;
		int index = (int)symbol_index_collection_.size() - 1;
		while (0 <= index && carry)
		{
			if (symbol_index_collection_[index] != cardinal_ - 1)
			{
				symbol_index_collection_[index]++;
				carry = false;
			}
			else
			{	// 桁上り
				symbol_index_collection_[index] = 0;
				if (index == 0)
					symbol_index_collection_.push_front(1);
				carry = true;
			}
			index--;
		}
	}
	NyaGadgetPositionalNotation operator ++()
	{	// 前置インクリメント
		Inc();
		return *this;
	}
	NyaGadgetPositionalNotation operator ++(int)
	{  // 後置インクリメント
		NyaGadgetPositionalNotation pn = *this;
		Inc();
		return pn;
	}
	/**
	@brief N進数取得関数
	@note
	 d桁のN進数として文字列で取得
	---------------------------------------------------------------------------
	[sample]
	int main()
	{	// 16進数テスト
		NyaGadgetPositionalNotation pn(16);

		for (int i = 0; i < 30; i++)
			pn++;

		cout << pn() << endl;		// 30を16進数で表示
		cout << pn(5) << endl;		// 5桁表示

		return 0;
	}
	---------------------------------------------------------------------------
	[output]
	1E
	0001E
	**/
	string operator()(int d = 0)
	{
		std::string positional_nation;

		for (const auto& e : symbol_index_collection_)
			positional_nation += symbols_[e];

		if (d == 0 || d == (int)positional_nation.size())
			return positional_nation;

		if ((int)positional_nation.size() < d)
		{	// 表示桁に空きがあるときは0で埋める
			std::string zero(d - positional_nation.size(), '0');
			positional_nation = zero + positional_nation;
		}

		return positional_nation;
	}
	/**
	@brief d桁目を取得する演算子
	@note
	 d桁目の数字を文字列で取得する。
	-------------------------------------------------------------------------- -
	[sample]
	int main()
	{	// 16進数テスト
		NyaGadgetPositionalNotation pn(16);

		for (int i = 0; i < 30; i++)
			pn++;

		cout << pn.() << endl;		// 30を16進数で表示
		cout << pn[0] << endl;		// １桁目を表示
		cout << pn[1] << endl;		// ２桁目を表示

		return 0;
	}
	-------------------------------------------------------------------------- -
	[output]
	1E
	E
	1
	**/
	char operator[](int d)
	{	// d桁目の数字を取得する
		int index = (int)symbol_index_collection_.size() - 1 - d;
		if (index < 0)
			return symbols_[0][0];
		return symbols_[symbol_index_collection_[index]][0];
	}
private:
	int cardinal_;	// 基数
	string symbols_[36] =
	{	// 36進数まで対応
		"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
		"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
		"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
		"U", "V", "W", "X", "Y", "Z",
	};
	// シンボルそのものでなく、シンボルに対応するindexを格納していく
	deque<int> symbol_index_collection_;
};

#define all(collection) (collection).begin(), (collection).end()
#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 AGC031A
{
public:
	AGC031A()
	{
		char_type_count_ = 0;
		ans_ = 0;
		char_count_collection_.resize(26);
	}
	void Run(void)
	{
		cin >> n_;
		cin >> s_;
		CharCount();

		if (char_type_count_ == 1)
		{
			cout << s_.size();
			return;
		}

		AllCount();

		cout << ans_;
	}

private:
	int n_;
	string s_;
	int char_type_count_;
	unsigned long long ans_;
	vector<int> char_count_collection_;
	void CharCount(void)
	{
		for (const auto & e : s_)
			char_count_collection_[(int)(e)-97]++;

		for (const auto & e : char_count_collection_)
		{
			if (e != 0)
				char_type_count_++;
		}

	}
	void AllCount(void)
	{
		NyaGadgetPositionalNotation pn(2);
		pn++;
		for(long bit_loop_times = 1; bit_loop_times < 1L << char_type_count_; bit_loop_times++)
		{	// bit全探索で問題を解く
			unsigned long long sum = 1;
			loop(i, char_type_count_)
			{
				if (pn[i] == '1')
				{
					sum = sum * char_count_collection_[i];
					if (1000000007 < sum)
						sum -= 1000000007;
				}
			}

			ans_ += sum;
			if (1000000007 < ans_)
				ans_ -= 1000000007;

			pn++;
		}
	}
};

int main()
{
	ABC99C3 abc993c;
	abc993c.Run();
	return 0;
}


Compiler output:
a.cc:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
a.cc: In function 'int main()':
a.cc:228:9: error: 'ABC99C3' was not declared in this scope
  228 |         ABC99C3 abc993c;
      |         ^~~~~~~
a.cc:229:9: error: 'abc993c' was not declared in this scope
  229 |         abc993c.Run();
      |         ^~~~~~~