#pragma region Macros
#include <bits/stdc++.h>
#if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG)
#include <atcoder/all>
#endif
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>using vec = vector<T>;
template<class T, class U>using umap = unordered_map<T, U>;
using ll = long long;
using P = pair<ll, ll>;
using vl = vec<ll>;
#define fi first
#define se second
#define el endl
constexpr ll INF = numeric_limits<ll>::max()/2-1;
#pragma endregion

#pragma region IOMacros
template<class T>
istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;}
template<class T>
ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;}

#define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__);
void __i() {}
template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);}

void O() {cout << el;}
template<class T, class... Ts> void O(T&& o, Ts&&... args){cout << o << " ";O(forward<Ts>(args)...);}
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

struct edge{ll to, cost, k;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    fill(ALL(d), INF);
  }

  void add_edge(ll s, ll t, ll cost, ll k){
    edge e;
    e.to = t, e.cost = cost;
    e.k=k;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    fill(ALL(d), INF);
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        ll t = ((d[v]+e.k-1)/e.k)*e.k;
        if(d[e.to]>t+e.cost){
          d[e.to] = t+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};

void Main(){
    I(ll, N, M, X, Y);
    X--;Y--;
    graph g(N);
    REP(i, M){
        I(ll, A, B, T, K);
        A--;B--;
        g.add_edge(A, B, T, K);
        g.add_edge(B, A, T, K);
    }
    g.dijkstra(X);
    if(g.d[Y] == INF){
        cout << -1 << el;return;
    }
    cout << g.d[Y] << el;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll z = 0, mod = 1000000007, MAX = 10000000000;

int main(){
  ll N;
  cin >> N;
  
  vector<ll> data(1, 0);
  ll now = 0;
  for (ll i = 0; i < N; i++){
    ll a;
    cin >> a;
    
    now = a - now;
    if (i % 2 == 1){
      data.push_back(now);
    }
    else{
      data.push_back(now * -1);
    }
  }
  
  sort(data.begin(), data.end());
  
  ll ans = 0, combo = 0, prev = data[0];
  for (ll i : data){
    if (i == prev){
      combo++;
    }
    else{
      ans += (combo * (combo - 1)) / 2;
      combo = 1;
      prev = i;
    }
    //cout << i << ' ' << combo << ' ' << ans << endl;
  }
  ans += (combo * (combo - 1)) / 2;
  
  cout << ans << endl;
}