http://acm.hdu.edu.cn/showproblem.php?pid=4403
#include <iostream>
#include <map>
#include <string.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <set>
#include <math.h>
#include <stack>
using namespace std;
typedef long long LL;
void dfs(string text, int pos, LL num, LL sum, map<LL, int> &cnt) {
if (pos >= text.length()) {
cnt[sum + num]++;
return;
}
dfs(text, pos + 1, num * 10 + (text[pos] - '0'), sum, cnt);
dfs(text, pos + 1, text[pos] - '0', sum + num, cnt);
}
map<LL, int> gao(string text) {
map<LL, int> cnt;
dfs(text, 1, text[0] - '0', 0, cnt);
return cnt;
}
LL calc(string text) {
int n = text.length();
if (n <= 1) {
return 0;
}
LL sum = 0;
for (int i = 1; i <= n - 1; i++) {
map<LL, int> lf = gao(text.substr(0, i));
map<LL, int> rt = gao(text.substr(i, n - i));
for (map<LL, int>::iterator it = lf.begin(); it != lf.end(); it++) {
sum += it->second * rt[it->first];
}
}
return sum;
}
int main() {
std::ios::sync_with_stdio(false);
string text;
while (cin >> text) {
if ("END" == text) {
break;
}
cout << calc(text) << endl;
}
return 0;
}