Problem:
Problem H: Eleven Lover

Edward Leven loves multiples of eleven very much. When he sees a number, he always tries
to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such
subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819.

He thinks a number which has many 11-sequences is a good number. He would like to find out
a very good number. As the first step, he wants an easy way to count how many 11-sequences
are there in a given number. Even for him, counting them from a big number is not easy.
Fortunately, one of his friends, you, is a brilliant programmer. He asks you to write a program
to count the number of 11-sequences. Note that an 11-sequence must be a positive number
without leading zeros.

Input

The input is a sequence of lines each of which contains a number consisting of less than or equal
to 80000 digits.

The end of the input is indicated by a line containing a single zero, which should not be processed.

Output

For each input number, output a line containing the number of 11-sequences.

You can assume the answer fits in a 32-bit signed integer.

Sample Input

17819
1111
11011
1234567891011121314151617181920
0

Output for the Sample Input

1
4
4
38

Solution in C (judge verdict: Accepted)

// AOJ 2182: Eleven Lover
// 2017.9.20 bal4u@uu
// 2017.11.22

#include <stdio.h>
#include <string.h>

char a[80005];
int dp[2][11];
int t[11][10];

int main()
{
	int i, d, k1, k2, ans;
	char *p;

	for (i = 0; i < 11; i++) for (d = 0; d < 10; d++) t[i][d] = (10*i+d) % 11;
	while (fgets(a, 80005, stdin) && *a != '0') {
		memset(dp, 0, sizeof(dp)); ans = 0;
		for (k1 = 0, k2 = 1, p = a; *p >= ' '; k1 = k2, k2 = !k2) {
			for (i = 0; i < 11; i++) dp[k2][i] = 0;
			d = *p++ & 0xf;
			for (i = 0; i < 11; i++) dp[k2][t[i][d]] += dp[k1][i]; 
			ans += dp[k2][0];
			if (d > 0) dp[k2][d]++;
		}
		printf("%d\n", ans);
	}
	return 0;
}