#include<iostream> #include<string> using namespace std; int D(char a, int n) { int c = 1; int temp = a - '0'; for (int i = 0; i < n; i++) { c = c * 2; } temp = temp * (c-1); return temp; } int main() { string s; while (cin >> s) { if (s == "0") { return 0; } else { int temp = 0; int n = s.size(); for (int i=0; i<n; i++) { temp += D(s[i], n - i); } cout << temp << endl; } } return 0; }