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: Wrong Answer)

#include <stdio.h>

char S[80001], A[80001], B[11];

int char_to_int(char c){
	return (int)c - (int)'0';
}

int main(){
	int N, i, j, ans;
	while(1){
		scanf("%s", S);
		for(N = 0; S[N] != '\0'; N++){}
		if(N == 1 && S[0] == '0'){
			return 0;
		}
		A[N] = 0;
		for(i = N - 1; i >= 0; i--){
			if(i % 2 == 0){
				A[i] = (A[i + 1] + char_to_int(S[i])) % 11;
			}
			else{
				A[i] = (A[i + 1] - char_to_int(S[i]) + 11) % 11;
			}
		}
		for(j = 0; j < 11; j++){
			B[j] = 0;
		}
		B[0] = 1;
		ans = 0;
		for(i = N - 1; i >= 0; i--){
			if(S[i] != '0'){
				ans += B[A[i]];
			}
			B[A[i]]++;
		}
		printf("%d\n", ans);
	}
}