// one one

#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>  //log10
#include <algorithm>
using std::ofstream;
using std::ifstream;
using std::cout;
using std::cin;
using std::vector;
using std::find;


int counter(vector<int> v, int numeral) {
	int cntr{};
	for(int i = 0; i < v.size(); ++i) {
		int x = v[i];
		do {
			if (x % 10 == numeral) ++cntr;
			x /= 10;
		} while (x);
	}
	return cntr;
}

int main() {
	vector<int> digits(10);
	int64_t x{};
	cout << "Enter an int: ";
	cin >> x;
	int sz = int(log10(x));
	vector<int> number(sz+1), nextNumber;
	vector<vector<int>> history;
	/* int pow10{ 1 };
	for (int i = 0; i < sz; ++i) pow10 * 10; */
	for (int i = sz; i >= 0; --i) {
		number[sz - i] = x % 10;
		x /= 10;
	}
	for (int i = sz; i >= 0; --i)
		cout << number[i];
	cout << '\n';
	//cin.get();
	ofstream outFile("sequence1111111111.txt");
	if (!outFile) cout << "failed to create file.";
	int times{ 10 };
	while (find(history.begin(), history.end(), number) == history.end()) {
		history.push_back(number);
		nextNumber.clear();
		for (int i = 0; i < 10; ++i)
			digits[i] = counter(number, i);
		for (int i = 0; i < 10; ++i) {
			if (digits[i] != 0) {
				nextNumber.push_back(digits[i]);
				nextNumber.push_back(i);
			}
		}
		for (int i = 0; i < nextNumber.size(); ++i)
			outFile << nextNumber[i];
		outFile << '\n';
		number = nextNumber;
	}
	outFile.close();
	ifstream ifs("sequence1111111111.txt");
	int64_t y{};
	while (ifs >> y) cout << y << '\n';
	
}