#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  string n;cin>>n;
  ll X = (ll)n.size();
  string S;
  ll Q = stoll(n);
  if(Q<10){
      cout<<0<<endl;
      return 0;
  }
  if(X%2==1){
      n="";
      for(ll i=0;i<X-1;i++){
          n+='9';
      }
  }
  ll Y = (ll)n.size();
  string B;
  string C;
  for(ll i=0;i<Y/2;i++){
      B+=n[i];
  }
  for(ll i=Y/2;i<Y;i++){
      C+=n[i];
  }
  //cout<<B<<endl;
  ll b = stoll(B);
  ll c = stoll(C);
  if(b>c){
      cout<<b-1<<endl;
  }else{
      cout<<b<<endl;
  }
}

// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder
#include<bits/stdc++.h>
//#include<atcoder/all>
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//ordered_set 重複不可
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// use set_function + find_by_order(select itr-num)

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

template<class T>inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}


char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char Alpha[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

//cout << std::fixed << std::setprecision(15) << y << endl; //小数表示

int main(){
    ll n; cin >> n;
    vector<ll> lis(n+1);
    REP(i,0,n){
        cin >> lis[i+1];
        if((i+1) % 2 == 1){
            lis[i+1] *= -1ll;
        }
    }
    REP(i,1,n+1){
        lis[i] = lis[i] + lis[i-1];

    }
    map<ll, ll> mp;
    REP(i,0,n+1){
        mp[lis[i]]++;
    }
    ll ans = 0;
    for(auto &x:mp){
        ans += (x.second * (x.second-1))/2;
    }
    cout << ans << endl;
}