1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
#include <stdlib.h>
#include <string>
#include <math.h>

using namespace std;

double search(string);
string decToBin(int, int);
double getActualResult(string, bool[]);

int main()
{
	ios_base::sync_with_stdio(0);
	string in;
	cin >> in;
	int counter = 0;
	cout << search(in);
	return 0;
}

double search(string data)
{
	double result = 0;
	bool overflow[data.size()];
	bool actual[data.size()];
	for (int i = 0; i < data.size(); i++)
	{
		overflow[i] = actual[i] = false;
	}
	int countOverflows = 0;
	for (int i = data.size() - 1; i > 0; i--)
	{
		if (data[i - 1] == '1')
		{
			countOverflows++;
			overflow[i] = true;
		}
	}

	for (int i = 0; i <= pow(countOverflows, 2); i++)
	{
		string number = decToBin(i, countOverflows);
		if (number == "-1")
			break;
		bool canDo = true;
		for (int j = data.size() - 1, o = countOverflows - 1; j >= 0 && o >= 0; j--)
		{
			if (overflow[j])
			{
				if (number[o] == '1')
					actual[j] = true;
				o--;
			}
			if (j != data.size() - 1)
			{
				if (actual[j] && actual[j + 1])
				{
					for (int z = 0; z < data.size(); z++)
					{
						actual[z] = false;
					}
					canDo = false;
					break;
				}
			}
		}
		if (!canDo)
			continue;
		result += getActualResult(data, actual);
		for (int z = 0; z < data.size(); z++)
		{
			actual[z] = false;
		}
	}
	if (countOverflows == 0)
	{
		return getActualResult(data, actual);
	}
	return result;
}

string decToBin(int n, int len)
{
	string toRev = "";
	while (len != 0)
	{
		if (n % 2 == 0)
		{
			toRev += '0';
		}
		else
		{
			toRev += '1';
		}
		n /= 2;
		len--;
	}
	if (n != 0)
		return "-1";
	string result = "";
	for (int i = toRev.size() - 1; i >= 0; i--)
		result += toRev[i];
	return result;
}

double getActualResult(string data, bool actual[])
{
	double result = 1;
	for (int i = data.size() - 1; i >= 0; i--)
	{
		if (actual[i])
		{
			result *= 9 - ((int)data[i] - (int)'0');
			i--;
		}
		else
		{
			result *= ((int)data[i] - (int)'0') + 1;
		}
	}
	return result;
}