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
#include <iostream>
#include <string>
using namespace std;

string addzero(string stri) {
    return "0" + stri;
}

string add(long long int num1, long long int num2)
{
    string result = "";
    string num1s = to_string(num1);
    string num2s = to_string(num2);
    while (num1s.length() != num2s.length() )
    {
        if (num1s.length() > num2s.length() )
        {
            num2s = addzero(num2s);
        }
        else {
            num1s = addzero(num1s);
        }
    }
    for (int i = 0; i < num1s.length()  ; ++i) {
        int n1 = num1s[i] - '0';
        int n2 = num2s[i] - '0';
        result = result + to_string(n1 + n2);
    }


    return result;

}

int sub(long long int num1, long long int num2){
    string result = "";
    string num1s = to_string(num1);
    string num2s = to_string(num2);
    while (num1s.length() != num2s.length() )
    {
        if (num1s.length() > num2s.length() )
        {
            num2s = addzero(num2s);
        }
        else {
            num1s = addzero(num1s);
        }
    }

    int index1 = -1;
    int len1 = num1s.length();
    while (abs(index1) < len1 + 1) {
        int last1 = num1s.back() - '0';
        int last2 = num2s.back() - '0';

        if (last1 >= last2) {
            result = to_string(last1 - last2)  + result;
            index1--;
            num1s.pop_back();
            num2s.pop_back();
        }
        else {
           if ( abs(index1 - 1) > len1 ) {
               return -1;
           }
           string last1c(1, num1s.back());
           num1s.pop_back();
           string new_num(1, num1s.back());
           new_num = new_num + last1c;
           result = to_string(stoi(new_num) - last2)  + result;
            index1--;
            index1--;
            num1s.pop_back();
            num2s.pop_back();
        }
    }
    if (result.find('-') != std::string::npos)
        return -1;

    if (add(num2, stoll(result)) == to_string(num1)) {
        return 1;
    }
    else {
        return -1;
    }


}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    long long int number;
    cin >> number;
   long long int count = number + 1;
    for (long long int i = 0; i < number; ++i) {
        if (sub(number, i) == -1) {
            count--;
        }
    }

    cout << count << "\n";
}