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
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()
{
	string s, input, tempstr;
	int i, j, x, n, r;
	long long int sum = 0, tempsum;
	
	cin >> input;
	
	for(i = 0; i < input.length()/2+1; i++)
	{
		s = "";
		for(j = input.length(); j > 2*i; j--)
			s+='1';
		for(j = 0; j < i; j++)
			s+='2';
		do
		{
			n = 0;
			tempsum = 1;
			for(x = 0; x < s.length(); x++)
			{
				tempstr = input[x+n];
				if(s[x] == '1')
					tempsum *= int(input[x+n])-47;
				if(s[x] == '2')
				{
					tempstr += input[x+n+1];
					if(tempstr <= "18")
					{
						r = (input[x+n]-47) * (input[x+n+1]-47);
						tempsum *= stoi(tempstr)+1 - r;
						n++;
					}					
					else
					{
						tempsum = 0;
						break;
					}
				}

			}

			sum += tempsum;
		}while(next_permutation(s.begin(), s.end()));

	}

	cout << sum;
	
	return 0;

}