stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<cstring>

#include<cstdio>

#include<algorithm>

#include<vector>

#define N 300010

#define gc getchar()

#define lb(x) (x&-x)

#define debug(x) cerr<<#x<<"="<<x

#define sp <<" "

#define ln <<endl

using namespace std;

inline int inn()

{

    int x,ch;while((ch=gc)<'0'||ch>'9');

    x=ch^'0';while((ch=gc)>='0'&&ch<='9')

        x=(x<<1)+(x<<3)+(ch^'0');return x;

}

int l[N],r[N],b[N],ans[N];vector<int> v[N];

inline int update(int x,int n,int v) { for(;x<=n;x+=lb(x)) b[x]+=v;return 0; }

inline int update(int x,int y,int n,int v) { return update(x,n,v),update(y+1,n,-v); }

inline int query(int x,int v=0) { for(;x;x-=lb(x)) v+=b[x];return v; }

int main()

{

    int n=inn(),m=inn();

    for(int i=1;i<=n;i++)

        l[i]=inn(),r[i]=inn(),v[r[i]-l[i]+1].push_back(i);

    for(int d=1;d<=m;d++)

    {

        for(int i=d;i<=m;i+=d) ans[d]+=query(i);

        for(int i=0,id;i<(int)v[d].size();i++)

            id=v[d][i],update(l[id],r[id],m,1);

    }

    for(int d=m,cnt=0;d;d--)

        cnt+=(int)v[d].size(),ans[d]+=cnt;

    for(int i=1;i<=m;i++) printf("%d\n",ans[i]);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 9.250183789972024x):
#include <bits/stdc++.h>

using namespace std;



#define name ""

#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)

#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)

#define long long long 

#define db double 

#define pii pair <int, int>

#define pll pair <long, long>

#define all(c) c.begin(), c.end()

#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)



const int INF = 1e9+7;

const int MOD = 1e9+7;

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

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



const int N = 3e5+1;

int n, m, Bit[N];



void Update(int p, int val){

	for (; p <= m; p += p&-p) Bit[p] += val;

}



int Get(int p){

	int ans = 0;

	for (; p > 0; p -= p&-p) ans += Bit[p];

	return ans;

}



struct Data{

	int l, r, diff;

	Data(int l_, int r_, int diff_){

		l = l_;

		r = r_;

		diff = diff_;

	}

	Data(){}



};



Data a[N];



bool comp(Data A, Data B){

	return A.diff < B.diff;

}



int main()

{

	fastio;

	cin >> n >> m;

	for (int i = 1; i <= n; i++){

		cin >> a[i].l >> a[i].r;

		a[i].diff = a[i].r - a[i].l + 1;

	}



	sort(a + 1, a + 1 + n, comp);



	int cnt = 0; int cur = 1;

	for (int i = 1; i <= m; i++){

		while (cur <= n && a[cur].diff < i){

			Update(a[cur].l, 1); Update(a[cur].r + 1, -1);

			cnt++; cur++;

		}

		int ans = 0;

		for (int j = 0; j <= m; j += i){

			ans += Get(j);

		}		

		cout << ans + n - cnt << '\n';

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector>

#include<queue>

#include<unordered_map>

#include<unordered_set>

using namespace std;

typedef long long ll;

#define chmin(a,b) a=min(a,b)

#define chmax(a,b) a=max(a,b)

#define mod 1000000007

#define mad(a,b) a=(a+b)%mod;

#define mul(a,b) a=a*b%mod;

#define N 300010

#define M 100010

namespace bit{

    ll dat[N];

    void init(){

        for(int i=0;i<N;i++)dat[i]=0;

    }

    void add(ll i){

        for(;i<N;i+=i&-i){

            dat[i]++;

        }

    }

    ll sum(ll i){

        ll res=0;

        for(;i>0;i-=i&-i){

            res+=dat[i];

        }

        return res;

    }

}

vector<ll> v[2*M];

ll n,m;

ll ans[2*M];

int main(){

  cin>>n>>m;

  for(int i=0;i<n;i++){

      ll l,r; cin>>l>>r;

      v[r].push_back(l);

  }

  bit::init();

  for(int i=1;i<=2*m;i++){

      vector<ll> di;

      for(ll j=1;j*j<=i;j++){

          if(i%j==0){

              di.push_back(j);

              if(j*j!=i){

                  di.push_back(i/j);

              }

          }

      }

      for(auto d:di){

          ans[d]+=bit::sum(i-1)-bit::sum(i-d);

          //cout<<"---"<<d<<" "<<ans[d]<<endl;

      }

      for(auto l:v[i]){

          bit::add(l);

      }

      //for(int j=1;j<=m;j++)cout<<bit::sum(j)<<" "; cout<<endl;

  }

  for(int i=1;i<=m;i++){

      cout<<n-ans[i]<<endl;

  }

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.5306161504776727x):
#include<iostream>

#include<algorithm>

#include<vector>

#include<queue>

#include<unordered_map>

#include<unordered_set>

using namespace std;

typedef long long ll;

#define chmin(a,b) a=min(a,b)

#define chmax(a,b) a=max(a,b)

#define mod 1000000007

#define mad(a,b) a=(a+b)%mod;

#define mul(a,b) a=a*b%mod;

#define N 200010

namespace bit{

  ll dat[N];

  void init(){

      for(int i=0;i<N;i++){

          dat[i]=0;

      }

  }

  void add(ll i,ll x){

      for(;i<N;i+=i&-i){

          dat[i]+=x;

      }

  }

  ll sum(ll i){

      ll res=0;

      for(;i;i-=i&-i){

          res+=dat[i];

      }

      return res;

  }

};

ll n,m;

struct qry{

    ll l,r,id;

    bool operator<(const qry&key)const{

        if(this->r==key.r)return this->id<key.id;

        return this->r<key.r;

    }

};

ll ans[N];

int main(){

  cin>>n>>m;

  vector<qry> v;

  for(int i=0;i<n;i++){

      qry p;

      cin>>p.l>>p.r;

      p.id=0;

      v.push_back(p);

  }

  for(int d=1;d<=m;d++){

      ans[d]=n;

      for(int i=0;i<=m;i+=d){

          qry p;

          p.l=i,p.r=i+d-1;

          p.id=d;

          v.push_back(p);

      }

  }

  sort(v.begin(),v.end());

  bit::init();

  for(auto p:v){

      if(p.id==0){

          bit::add(p.l,+1);

      }

      else{

          ans[p.id]-=(bit::sum(p.r)-bit::sum(p.l));

      }

  }

  for(int d=1;d<=m;d++)cout<<ans[d]<<endl;

  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>



using namespace  std;

typedef long long int ll;

typedef pair<ll, ll> pll;



int main()

{

	ll N, A, B, C, D;

	cin >> N >> A >> B >> C >> D;



	vector<pll> area(N);

	for (int i = 0; i < N; ++i)

	{

		ll m = std::max((ll)0, 2 * C - (D - C)*(N - 2));

		ll l = (D - C)*(N - 1);

		ll max = D * (N - 1) - (m + l)*i;



		pll p(max, max - l);

		area[i] = p;

	}



	string ans = "NO";

	for (int i = 0; i < N; ++i)

	{

		if (area[i].first >= (B - A) && area[i].second <= (B - A))

		{

			ans = "YES";

			break;

		}

	}

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.2187129150523184x):
#include <bits/stdc++.h>



using namespace std;



typedef long long int ll;

typedef pair<ll, ll> pll;



#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))

#define REP(i, n) FOR(i,n,0)

#define OF64 std::setprecision(10)



const ll MOD = 1000000007;

const ll INF = (ll) 1e15;



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    ll N, A, B, C, D;

    cin >> N >> A >> B >> C >> D;



    B = abs(B - A);

    ll u = D * (N - 1);

    ll d = C * (N - 1);

    REP(i, N) {

        if (d <= B && B <= u) {

            cout << "YES" << endl;

            return 0;

        }

        u -= (C + D);

        d -= (C + D);

    }

    cout << "NO" << endl;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)

#define per(i,n) for ((i)=n;(i)>=(1);(i)--)

using namespace std;

long long n,i,a,b,c,d,t,l,r;

int main()

{

	cin>>n>>a>>b>>c>>d;

	b-=a;n--;

	for(i=0;i<=n;i++)

	{

		t=c*i-c*(n-i);

		l=t-(d-c)*(n-i);

		r=t+(d-c)*i;

		if(l<=b&&b<=r)

		{

			puts("YES");

			return 0;

		}

	}

	puts("NO");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.1226499308588x):
#include <cstdio>

#include <algorithm>

#include <ctime>

using namespace std;



#define int long long



int n,a,b,c,d;



inline int read(){

	int s=0,t=1;

	char c=getchar();

	while((c<'0'||c>'9')&&c!='-')c=getchar(),t=-1;

	if(c=='-')c=getchar(),t=-1;

	while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+(c^48),c=getchar();

	return s*t;

}



signed main(void){

	n=read();

	a=read();

	b=read();

	c=read();

	d=read();

	for(int i=1;i<n;i++){

		if(i*c-(n-1-i)*d<=b-a&&b-a<=i*d-(n-1-i)*c){

			printf("YES");

			return 0;

		}

	}

	printf("NO");

}
// Slower C++ solution:
#pragma GCC optimize("O3")

#include<bits/stdc++.h> 

using namespace std;

using ll=long long;

typedef  unsigned long long int ull;

typedef pair<ll,ll> P;

template<class T> using V=vector<T>; 

#define fi first

#define se second

#define all(v) (v).begin(),(v).end()

const ll inf=(1e18);

//const ll mod=998244353;

const ll mod=1000000007;

//ios_base::sync_with_stdio(false);

//cin.tie(NULL);

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

ll lcm(ll c,ll d){return c/gcd(c,d)*d;}

struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

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 (a>b) { a=b; return 1; } return 0; }

int main(){

ll n,a,b,c,d;

cin>>n>>a>>b>>c>>d;

if(a>b)swap(a,b);

V<ll> suml1(n+1,0),suml2(n+1,0);

suml1[0]=a,suml2[0]=a;

for(int i=0;i<n-1;i++){

    suml1[i+1]+=suml1[i]+d;

    suml2[i+1]+=suml2[i]-d;

}

V<ll> sumr1(n+1,0),sumr2(n+1,0);

sumr1[n-1]=b;sumr2[n-1]=b;

for(int i=n-1;i>0;i--){

    sumr1[i-1]+=sumr1[i]+d;

    sumr2[i-1]+=sumr2[i]-d;

}

bool ch=false;

for(ll i=0;i<n;i++){

    if(!(suml1[i]<sumr1[i]-(n-1-i)*(d-c)||suml1[i]-i*(d-c)>sumr1[i]))ch=true;

    if(!(suml1[i]<sumr2[i]||suml1[i]-i*(d-c)>sumr2[i]+(n-1-i)*(d-c)))ch=true;

}

if(ch)cout<<"YES"<<"\n";

else cout<<"NO"<<"\n";

}




// Faster C++ solution for the same problem (measured speedup: 2.390607051526994x):
#pragma GCC optimize("O3")

#include<bits/stdc++.h> 

using namespace std;

using ll=long long;

using P=pair<ll,ll>;

template<class T> using V=vector<T>; 

#define fi first

#define se second

#define all(v) (v).begin(),(v).end()

const ll inf=(1e18);

//const ll mod=998244353;

const ll mod=1000000007;

ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}

ll LCM(ll c,ll d){return c/GCD(c,d)*d;}

struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

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 (a>b) { a=b; return 1; } return 0; }

int main(){

    ll n,a,b,c,d;

    cin>>n>>a>>b>>c>>d;

    for(ll i=0;i<n;i++){

        ll acu=a+i*d,acd=a+i*c;

        if(!(acu<b+c*(n-i-1)||acd>b+d*(n-i-1))||!(acu<b-d*(n-i-1)||acd>b-c*(n-i-1))){

            cout<<"YES"<<"\n";

            return 0;

        }

        acu=a-i*c,acd=a-i*d;

        if(!(acu<b+c*(n-i-1)||acd>b+d*(n-i-1))||!(acu<b-d*(n-i-1)||acd>b-c*(n-i-1))){

            cout<<"YES"<<"\n";

            return 0;

        }

    }

    cout<<"NO"<<"\n";

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define FOR(i,a,b) for(int i = (a); i < (b); i++)

#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)

#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a, value) memset(a, value, sizeof(a))



#define SZ(a) (int) a.size()

#define ALL(a) a.begin(),a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const LL INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 500500;



LL L[MAX], R[MAX];

LL U[MAX], D[MAX];



bool intersect(LL x1, LL y1, LL x2, LL y2)

{

	if (y1 < x2) return false;

	if (y2 < x1) return false;

	return true;

}



int main()

{

	//freopen("in.txt", "r", stdin);

	//ios::sync_with_stdio(false); cin.tie(0);



	LL n, a, b, c, d;

	cin>>n>>a>>b>>c>>d;



	L[0] = R[0] = a;

	FOR (i, 1, n)

	{

		L[i] = L[i-1] + c;

		R[i] = R[i-1] + d;

	}



	U[n-1] = D[n-1] = b;

	RFOR(i, n-1, 0)

	{

		D[i] = D[i+1] + c;

		U[i] = U[i+1] + d;

	}



	FOR (i, 0, n)

	{

		if (intersect(L[i], R[i], D[i], U[i]))

		{

			cout<<"YES"<<endl;

			return 0;

		}

	}



	cout<<"NO"<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 2.506329658414588x):
#include <bits/stdc++.h>



using namespace std;



//#define _FILES

#define PB push_back

#define MP make_pair

#define X first

#define Y second



int main()

{

    ios_base::sync_with_stdio(false);



    #ifdef _FILES

        freopen("","r",stdin);

        freopen("","w",stdout);

    #endif // _FILES



    long long n, a, b, c, d;

    cin >> n >> a >> b >> c >> d;



    if (a > b) swap(a, b);

    for (int i=0; i < n;i++)

    {

        if ((b - a >= c *(n - 1 - i) - i * d) && (b - a <= -c * i + (n - 1 - i) * d))

        {

            cout << "YES" << endl;

            return 0;

        }

    }

    cout << "NO" << endl;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define FOR(i,a,b) for(int i = (a); i < (b); i++)

#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)

#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a, value) memset(a, value, sizeof(a))



#define SZ(a) (int) a.size()

#define ALL(a) a.begin(),a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const LL INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 500500;



LL L[MAX], R[MAX];

LL U[MAX], D[MAX];



bool intersect(LL x1, LL y1, LL x2, LL y2)

{

	if (y1 < x2) return false;

	if (y2 < x1) return false;

	return true;

}



int main()

{

	//freopen("in.txt", "r", stdin);

	//ios::sync_with_stdio(false); cin.tie(0);



	LL n, a, b, c, d;

	cin>>n>>a>>b>>c>>d;



	L[0] = R[0] = a;

	FOR (i, 1, n)

	{

		L[i] = L[i-1] + c;

		R[i] = R[i-1] + d;

	}



	U[n-1] = D[n-1] = b;

	RFOR(i, n-1, 0)

	{

		D[i] = D[i+1] + c;

		U[i] = U[i+1] + d;

	}



	FOR (i, 0, n)

	{

		if (intersect(L[i], R[i], D[i], U[i]))

		{

			cout<<"YES"<<endl;

			return 0;

		}

	}



	cout<<"NO"<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 2.509366587892905x):
/* ***********************************************

Author        :ACagain

Created Time  :2018/4/21 11:50:24

File Name     :dong.cpp

************************************************ */



#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <string>

#include <stack>

#include <cmath>

#include <cstdlib>

#include <vector>

#include <queue>

#include <set>

#include <map>

using namespace std;



#define lson o<<1,l,m

#define rson o<<1|1,m+1,r

#define pii pair<int,int>

#define mp make_pair

#define ll long long

#define INF 0x3f3f3f3f

const int maxn=55;



int main()

{

    std::ios::sync_with_stdio(false);

    std::cin.tie(0);

    //freopen("in.txt","r",stdin);

    //freopen("out.txt","w",stdout);

	ll n,a,b,c,d;

	cin>>n>>a>>b>>c>>d;

	if(a>b)

	  swap(a,b);

	ll dis=b-a,num=n-1;

	ll r=num*d,l=num*c;

	int flag=0;

	int tt=c+d;

	if(dis>=l&&dis<=r)

	  flag=1;

	else

	for(int i=1;i<=num;i++)

	{

		l-=tt;

		r-=tt;

		if(dis>=l&&dis<=r)

		{

			flag=1;

			break;

		}

	}

	if(flag)

	  cout<<"YES"<<endl;

	else

	  cout<<"NO"<<endl;

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define FOR(i,a,b) for(int i = (a); i < (b); i++)

#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)

#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a, value) memset(a, value, sizeof(a))



#define SZ(a) (int) a.size()

#define ALL(a) a.begin(),a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const LL INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 500500;



LL L[MAX], R[MAX];

LL U[MAX], D[MAX];



bool intersect(LL x1, LL y1, LL x2, LL y2)

{

	if (y1 < x2) return false;

	if (y2 < x1) return false;

	return true;

}



int main()

{

	//freopen("in.txt", "r", stdin);

	//ios::sync_with_stdio(false); cin.tie(0);



	LL n, a, b, c, d;

	cin>>n>>a>>b>>c>>d;



	L[0] = R[0] = a;

	FOR (i, 1, n)

	{

		L[i] = L[i-1] + c;

		R[i] = R[i-1] + d;

	}



	U[n-1] = D[n-1] = b;

	RFOR(i, n-1, 0)

	{

		D[i] = D[i+1] + c;

		U[i] = U[i+1] + d;

	}



	FOR (i, 0, n)

	{

		if (intersect(L[i], R[i], D[i], U[i]))

		{

			cout<<"YES"<<endl;

			return 0;

		}

	}



	cout<<"NO"<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 9.23767587682387x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll long long

using namespace std;

inline ll in(){

    ll x=0;bool f=0; char c;

    for (;(c=getchar())<'0'||c>'9';f=c=='-');

    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');

    return f?-x:x;

}

ll n,a,b,c,d,mxp,mnp,mxn,mnn;

int main()

{

	n=in();a=in();b=in();c=in();d=in();

	for (int i=0;i<n;++i){

		mnp=c*i;mxp=d*i;

		mxn=-c*(n-1ll-i);mnn=-d*(n-1ll-i);

		if (mnp+mnn<=b-a&&mxp+mxn>=b-a) {printf("YES");return 0;}

	}printf("NO");return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



//#define _FILES

#define PB push_back

#define MP make_pair

#define X first

#define Y second



int main()

{

    ios_base::sync_with_stdio(false);



    #ifdef _FILES

        freopen("","r",stdin);

        freopen("","w",stdout);

    #endif // _FILES



    long long n, a, b, c, d;

    cin >> n >> a >> b >> c >> d;



    if (a > b) swap(a, b);

    for (int i=0; i < n;i++)

    {

        if ((b - a >= c *(n - 1 - i) - i * d) && (b - a <= -c * i + (n - 1 - i) * d))

        {

            cout << "YES" << endl;

            return 0;

        }

    }

    cout << "NO" << endl;

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 3.1412514245371006x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll long long

using namespace std;

inline ll in(){

    ll x=0;bool f=0; char c;

    for (;(c=getchar())<'0'||c>'9';f=c=='-');

    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');

    return f?-x:x;

}

ll n,a,b,c,d,mxp,mnp,mxn,mnn;

int main()

{

	n=in();a=in();b=in();c=in();d=in();

	for (int i=0;i<n;++i){

		mnp=c*i;mxp=d*i;

		mxn=-c*(n-1ll-i);mnn=-d*(n-1ll-i);

		if (mnp+mnn<=b-a&&mxp+mxn>=b-a) {printf("YES");return 0;}

	}printf("NO");return 0;

}
// Slower C++ solution:
/* ***********************************************

Author        :ACagain

Created Time  :2018/4/21 11:50:24

File Name     :dong.cpp

************************************************ */



#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <string>

#include <stack>

#include <cmath>

#include <cstdlib>

#include <vector>

#include <queue>

#include <set>

#include <map>

using namespace std;



#define lson o<<1,l,m

#define rson o<<1|1,m+1,r

#define pii pair<int,int>

#define mp make_pair

#define ll long long

#define INF 0x3f3f3f3f

const int maxn=55;



int main()

{

    std::ios::sync_with_stdio(false);

    std::cin.tie(0);

    //freopen("in.txt","r",stdin);

    //freopen("out.txt","w",stdout);

	ll n,a,b,c,d;

	cin>>n>>a>>b>>c>>d;

	if(a>b)

	  swap(a,b);

	ll dis=b-a,num=n-1;

	ll r=num*d,l=num*c;

	int flag=0;

	int tt=c+d;

	if(dis>=l&&dis<=r)

	  flag=1;

	else

	for(int i=1;i<=num;i++)

	{

		l-=tt;

		r-=tt;

		if(dis>=l&&dis<=r)

		{

			flag=1;

			break;

		}

	}

	if(flag)

	  cout<<"YES"<<endl;

	else

	  cout<<"NO"<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.13351749374712x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll long long

using namespace std;

inline ll in(){

    ll x=0;bool f=0; char c;

    for (;(c=getchar())<'0'||c>'9';f=c=='-');

    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');

    return f?-x:x;

}

ll n,a,b,c,d,mxp,mnp,mxn,mnn;

int main()

{

	n=in();a=in();b=in();c=in();d=in();

	for (int i=0;i<n;++i){

		mnp=c*i;mxp=d*i;

		mxn=-c*(n-1ll-i);mnn=-d*(n-1ll-i);

		if (mnp+mnn<=b-a&&mxp+mxn>=b-a) {printf("YES");return 0;}

	}printf("NO");return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please





int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N;

	cin >> N;



	int P[100001];

	rep1(i, N) {

		int p;

		cin >> p;

		P[p] = i;

	}

	set<int> ST;

	ST.insert(N + 1);

	ST.insert(0);

	ll kotae = 0;

	for (int i = N; i >= 1; i--) {

		int p = P[i];



		auto itr1 = ST.lower_bound(p);

		auto itr2 = itr1--;



		int l = *itr1;

		int r = *itr2;



		int kari = 0;

		if (r != N + 1) {

			int r2 = *(++itr2);

			kari += (ll)(p - l) * (r2 - r);

		}

		if (l != 0) {

			int l2 = *(--itr1);

			kari += (ll)(r - p) * (l - l2);

		}

		kotae += (ll)kari * i;

		ST.insert(p);

	}



	co(kotae);



	Would you please return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.736461786832183x):
//#include<bits/stdc++.h>

#include<cstdio>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';

	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';

	return A;

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint();

	int A[100001];

	rep1(i, N) A[getint()] = i + 1;

	int daishou[100004] = {};

	daishou[0] = 2;

	daishou[N + 3] = N + 1;



	ll kotae = 0;

	rep1(i, N) {

		int a = A[i];

		int l = daishou[a - 1];

		if (!l) l = a;

		int r = daishou[a + 1];

		if (!r) r = a;

		int l2 = daishou[l - 2];

		if (!l2) l2 = l - 1;

		int r2 = daishou[r + 2];

		if (!r2) r2 = r + 1;



		kotae += ((ll)(r2 - r) * (a - l + 1) + (ll)(l - l2) * (r - a + 1)) * i;



		daishou[l] = r;

		daishou[r] = l;

	}



	printf("%lld", kotae);



	Would you please return 0;

}