#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;

string S;
int d[80001];
ll dp[80001][2][10];

int main(void) {
  while(cin >> S, S != "0") {

    REP(i, 0, S.length()) d[i] = S[i] - '0';
    REP(i, 0, S.length() + 1) REP(j, 0, 2) REP(k, 0, 10) dp[i][j][k] = 0;

    ll ans = 0;
    for(int i = S.length() - 1; i >= 0; i--) {
      REP(j, 0, 2) REP(k, 0, 10) {
        if(k == d[i] - j && d[i] != 0) ans += dp[i + 1][j][k];
        int nj = 0, nk = d[i] - j - k;
        if(nk < 0) {
          nk += 10;
          nj = 1;
        }
        dp[i][nj][nk] += dp[i + 1][j][k];
      }
      dp[i][0][d[i]]++;
    }
    cout << ans << endl;
  }
  return 0;
}