void fun(apmatrix<int> &m, const apstring &s)
{
int i;
for (i = 1; i<s.length(); i++)
m[s[i] - '0'][s[i-1] - '0']++;
}
apmatrix<int> m(10,10,0);
apstring s = "20012002";
int k, sum = 0;
fun(m, s);
for (k=0; k<10; k++)
sum+= m[k][k];
cout << sum << endl;