#include <bits/stdc++.h>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define L(n) (n << 1)
#define R(n) (n << 1 | 1)
#define print_vector(n) for(auto a0 : n) cout << a0 << ' '; cout << endl;
#define vector_sort(n) sort(n.begin(), n.end())
#define print_array(n, l, r) for(int a0 = l; a0 <= r; a0++) cout << n[a0] << ' '; cout << '\n';
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define ABS(a) ((a) > 0 ? (a) : -(a))
using namespace std;

template<class T>
istream & operator >> (istream &in, pair<T, T> &p) {
  in >> p.first >> p.second;
  return in;
}

template<class T>
ostream & operator <<(ostream &out, pair<T, T> &p) {
  out << p.first << ' ' << p.second;
  return out;
}

template<class Tuple, std::size_t N>
struct TuplePrinter {
  static void print(ostream &out, const Tuple& t) {
    TuplePrinter<Tuple, N-1>::print(out, t);
    out << ' ' << get<N-1>(t);
  }
};

template<class Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(ostream &out, const Tuple& t) {
    out << get<0>(t);
  }
};

template<class... Args>
ostream & operator <<(ostream &out, const tuple<Args...> &p) {
  TuplePrinter<decltype(p), sizeof...(Args)>::print(out, p);
  return out;
}

int N;
long long A[300005];
map<pll, int> cnt;

int main() {
  ios_base::sync_with_stdio(0);
  cin >> N;
  pll offset = {};
  long long ans = 0;
  for (int i = 1; i <= N; i++) cin >> A[i];
  
  for (int i = 1; i <= N; i++) {
    pll now = offset;
    pll new_start = offset;
    // cout << offset << "\n";
    if (i & 1) {
      now.second -= A[i];
      // now.first = -now.first;
      // now.second = -now.second;
      ans += cnt[now];

      new_start.first -= A[i];
      cnt[new_start]++;

      offset.second += A[i + 1] - A[i];
    }else {
      now.first -= A[i];
      // now.first = -now.first;
      // now.second = -now.second;
      ans += cnt[now];
      
      new_start.second -= A[i];
      cnt[new_start]++;

      offset.first += A[i + 1] - A[i];
    }
    // cout <<  " -> " << new_start << "\n";
    // cout <<  " -> " << now << "\n";
  }
  cout << ans << "\n";
}
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000



int main(void) {
	unsigned long long x, y, a, b; cin >> x >> y >> a >> b;
	unsigned long long e = 0;
	if(x>=1000000000){
		e += (y - x) / b;
		if ((y - x) % b == 0) {
			e--;
		}
		cout << e << endl;
		return 0;
	}

	while (true) {
		if (a*x < x + b) {
			x *= a;
			e++;
		}
		else {
			break;
		}
		if (x >= y) {
			e--;
			cout << e << endl;
			return  0;
		}
	}
	e += (y - x) / b;
	if ((y - x) % b == 0) {
		e--;
	}
	cout << e << endl;
	return 0;
	
}
