#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    string s;
    cin >> s;
    int len = s.size();
    map<char, int> num;
    vector<char> can;
    vector<int> res;
    ll ans = 0;
    char ko = '1';
    for(int i = len-1; i >= 0; i--){
        if(i-1 >= 0){
            if(s[i-1] == s[i]){
                if(ko == '1' || ko == s[i]){
                    ko = s[i];
                }else{
                    int tmp = num[s[i]];
                    num.erase(begin(num), end(num));
                    num[s[i]] = tmp;
                    ko = s[i];
                }
                int tmp = num[s[i]];
                num.erase(begin(num), end(num));
                num[s[i]] = tmp;
                ans += (len-1-i)-num[s[i]];
                num[s[i]]+= (len-1-i)-num[s[i]];
                //cout << "num: " << num[s[i]] << endl;
                //cout << (len-1-i)-num[s[i]] << endl;
            }
        }
        num[s[i]]++;
        //cout << "saishuu" << num[s[i]] << endl;
    }
    cout << ans << endl;
    return 0;
}
#include <bits/stdc++.h>
#include<sstream>
#include<string>
#include<vector>
#include <set>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
long long M=1000000007;
using namespace std;
ll fact[10000];
ll power(ll x, unsigned ll y, unsigned ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y / 2, m) % m; 
    p = (p * p) % m; 
  
    return (y % 2 == 0) ? p : (x * p) % m; 
} 
unsigned long long modInverse(unsigned long long n,  
                                            int p)
{
    return power(n, p - 2, p);
}
unsigned long long nCrModPFermat(unsigned long long n,
                                 int r, int p)
{
    // If n<r, then nCr should return 0
    if (n < r)
        return 0;
    // Base case
    if (r == 0)
        return 1;
    return (fact[n] * modInverse(fact[r], p) % p
            * modInverse(fact[n - r], p) % p)
           % p;
}
int32_t main()
{
  IOS
  ll n,count=0;
  cin>>n;
  ll m=n,cnt=0;
  while(m>0)
  {
      m/=10;
      cnt++;
  }
  for(ll i=4;i<=cnt-1;i++)
  {
    count+=(((i+2)/3)-1)*(9*(pow(10,i-1)));  
  }
  ll u=(n-(pow(10,cnt-1)))+1;
  count+=(((cnt+2)/3)-1)*(u);
  cout<<count<<endl;
  return 0;
}