#include<cstdio>
#include<algorithm>
struct sgt
{
#define len(x,y) ((y)-(x)+(1))
#define mod 1000000007
    struct node
    {
    	int l,r;
		long long val;
	};
	node a[2500005];
	long long w[2000005];
	private:
		node merge(node x,node y)
		{
			node p;
			p.l=x.l;p.r=y.r;
			p.val=(x.val*w[len(y.l,y.r)]+y.val)%mod;
			return p;
		}
		void pushup(int k)
		{
			a[k]=merge(a[k*2],a[k*2+1]);
		}
		void build(int k,int l,int r)
		{
			if (l==r) return a[k].l=l,a[k].r=r,a[k].val=0,void();
			int mid=(l+r)/2;
			build(k*2,l,mid);
			build(k*2+1,mid+1,r);
			pushup(k);
		}
		node query(int k,int x,int y)
		{
			if (x<=a[k].l&&a[k].r<=y) return a[k];
		    int mid=(a[k].l+a[k].r)/2;
		    node lft,rgt;
		    lft.val=rgt.val=0;
		    int flag1=0,flag2=0;
		    if (x<=mid) flag1=1,lft=query(k*2,x,y);
		    if (mid<y) flag2=1,rgt=query(k*2+1,x,y);
		    if (flag1&&!flag2) return lft;
		    else if (!flag1&&flag2) return rgt;
			else return merge(lft,rgt);
		}
		void update(int k,int x)
		{
			if (a[k].l==a[k].r) return a[k].val=1,void();
			int mid=(a[k].l+a[k].r)/2;
			if (x<=mid) update(k*2,x);
			if (mid<x) update(k*2+1,x);
			pushup(k);
		}
	public:
		void prepare(int n)
		{
			w[0]=1;for (int i=1;i<=n;i++) w[i]=w[i-1]*2%mod;
		}
		void make(int n)
		{
			build(1,1,n);
		}
		void add(int x)
		{
			update(1,x);
		}
		long long solve(int x,int y)
		{
			return query(1,x,y).val;
		}
#undef mod
#undef len
};
sgt t1,t2;
int n;
int main()
{
#define op(x) ((n)-(x)+(1))
    scanf("%d",&n);
	t1.prepare(n);t2.prepare(n);
	t1.make(n);t2.make(n);
	for (int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		t1.add(x);t2.add(op(x));
		int ll=x-1,rr=n-x;
		int len=std::min(ll,rr);
		if (!len) continue;
		long long xx=t1.solve(x+1,x+len),yy=t2.solve(op(x-1),op(x-len));
		if (xx!=yy) return puts("YES"),0;
	}
    puts("NO");
	return 0;
#undef op
}


#include<cstdio>
#include<algorithm>
struct sgt
{
#define len(x,y) ((y)-(x)+(1))
#define mod 1000000007
    struct node
    {
    	int l,r;
		long long val;
	};
	node a[1500005];
	long long w[1000005];
	private:
		node merge(node x,node y)
		{
			node p;
			p.l=x.l;p.r=y.r;
			p.val=(x.val*w[len(x.l,x.r)]+y.val)%mod;
			return p;
		}
		void pushup(int k)
		{
			a[k]=merge(a[k*2],a[k*2+1]);
		}
		void build(int k,int l,int r)
		{
//			printf("%d[%d,%d]\n",k,l,r);
			if (l==r) return a[k].l=l,a[k].r=r,a[k].val=0,void();
			int mid=(l+r)/2;
			build(k*2,l,mid);
			build(k*2+1,mid+1,r);
			pushup(k);
		}
		node query(int k,int x,int y)
		{
//			printf("Q %d[%d,%d] %d %d\n",k,a[k].l,a[k].r,x,y);
			if (x<=a[k].l&&a[k].r<=y) return a[k];
		    int mid=(a[k].l+a[k].r)/2;
		    node lft,rgt;
		    int flag1=0,flag2=0;
		    if (x<=mid) flag1=1,lft=query(k*2,x,y);
		    if (mid<y) flag2=1,rgt=query(k*2+1,x,y);
		    if (flag1&&!flag2) return lft;
		    else if (!flag1&&flag2) return rgt;
			else return merge(lft,rgt);
		}
		void update(int k,int x)
		{
			if (a[k].l==a[k].r) return a[k].val=1,void();
			int mid=(a[k].l+a[k].r)/2;
			if (x<=mid) update(k*2,x);
			if (mid<x) update(k*2+1,x);
			pushup(k);
		}
	public:
		void prepare(int n)
		{
			w[1]=1;for (int i=2;i<=n;i++) w[i]=w[i-1]*7%mod;
		}
		void make(int n)
		{
			build(1,1,n);
		}
		void add(int x)
		{
			update(1,x);
		}
		long long solve(int x,int y)
		{
//			printf("solve %d %d\n",x,y);
			return query(1,x,y).val;
		}
#undef mod
#undef len
};
sgt t1,t2;
int n;
int main()
{
#define op(x) ((n)-(x)+(1))
    scanf("%d",&n);
	t1.make(n);t2.make(n);
//	printf("op(3)=%d\n",op(3));
//	return 0;
	for (int i=1;i<=n;i++)
	{
//		printf("%d\n",i);
		int x;
		scanf("%d",&x);
		t1.add(x);t2.add(op(x));
//		puts("qwq");
		int ll=x-1,rr=n-x;
		int len=std::min(ll,rr);
		if (!len) continue;
		long long xx=t1.solve(x+1,x+len),yy=t2.solve(op(x-1),op(x-len));
//		puts("qaq");
//		printf("%d:%lld %lld\n",i,xx,yy);
		if (xx!=yy) return puts("YES"),0;
	}
    puts("NO");
	return 0;
#undef op
}


#include<cstdio>
#include<algorithm>
struct sgt
{
#define len(x,y) ((y)-(x)+(1))
#define mod 1000000007
    struct node
    {
    	int l,r;
		long long val;
	};
	node a[2500005];
	long long w[2000005];
	private:
		node merge(node x,node y)
		{
			node p;
			p.l=x.l;p.r=y.r;
			p.val=(x.val*w[len(x.l,x.r)]+y.val)%mod;
			return p;
		}
		void pushup(int k)
		{
			a[k]=merge(a[k*2],a[k*2+1]);
		}
		void build(int k,int l,int r)
		{
//			printf("%d[%d,%d]\n",k,l,r);
			if (l==r) return a[k].l=l,a[k].r=r,a[k].val=0,void();
			int mid=(l+r)/2;
			build(k*2,l,mid);
			build(k*2+1,mid+1,r);
			pushup(k);
		}
		node query(int k,int x,int y)
		{
//			printf("Q %d[%d,%d] %d %d\n",k,a[k].l,a[k].r,x,y);
			if (x<=a[k].l&&a[k].r<=y) return a[k];
		    int mid=(a[k].l+a[k].r)/2;
		    node lft,rgt;
		    int flag1=0,flag2=0;
		    if (x<=mid) flag1=1,lft=query(k*2,x,y);
		    if (mid<y) flag2=1,rgt=query(k*2+1,x,y);
		    if (flag1&&!flag2) return lft;
		    else if (!flag1&&flag2) return rgt;
			else return merge(lft,rgt);
		}
		void update(int k,int x)
		{
			if (a[k].l==a[k].r) return a[k].val=1,void();
			int mid=(a[k].l+a[k].r)/2;
			if (x<=mid) update(k*2,x);
			if (mid<x) update(k*2+1,x);
			pushup(k);
		}
	public:
		void prepare(int n)
		{
			w[1]=1;for (int i=2;i<=n;i++) w[i]=w[i-1]*10%mod;
		}
		void make(int n)
		{
			build(1,1,n);
		}
		void add(int x)
		{
			update(1,x);
		}
		long long solve(int x,int y)
		{
//			printf("solve %d %d\n",x,y);
			return query(1,x,y).val;
		}
#undef mod
#undef len
};
sgt t1,t2;
int n;
int main()
{
#define op(x) ((n)-(x)+(1))
    scanf("%d",&n);
	t1.make(n);t2.make(n);
//	printf("op(3)=%d\n",op(3));
//	return 0;
	for (int i=1;i<=n;i++)
	{
//		printf("%d\n",i);
		int x;
		scanf("%d",&x);
		t1.add(x);t2.add(op(x));
//		puts("qwq");
		int ll=x-1,rr=n-x;
		int len=std::min(ll,rr);
		if (!len) continue;
		long long xx=t1.solve(x+1,x+len),yy=t2.solve(op(x-1),op(x-len));
//		puts("qaq");
//		printf("%d:%lld %lld\n",i,xx,yy);
		if (xx!=yy) return puts("YES"),0;
	}
    puts("NO");
	return 0;
#undef op
}


#include<cstdio>
#include<algorithm>
struct sgt
{
#define len(x,y) ((y)-(x)+(1))
#define mod 998244353
    struct node
    {
    	int l,r;
		long long val;
	};
	node a[1500005];
	long long w[1000005];
	private:
		node merge(node x,node y)
		{
			node p;
			p.l=x.l;p.r=y.r;
			p.val=(x.val*w[len(x.l,x.r)]+y.val)%mod;
			return p;
		}
		void pushup(int k)
		{
			a[k]=merge(a[k*2],a[k*2+1]);
		}
		void build(int k,int l,int r)
		{
//			printf("%d[%d,%d]\n",k,l,r);
			if (l==r) return a[k].l=l,a[k].r=r,a[k].val=0,void();
			int mid=(l+r)/2;
			build(k*2,l,mid);
			build(k*2+1,mid+1,r);
			pushup(k);
		}
		node query(int k,int x,int y)
		{
//			printf("Q %d[%d,%d] %d %d\n",k,a[k].l,a[k].r,x,y);
			if (x<=a[k].l&&a[k].r<=y) return a[k];
		    int mid=(a[k].l+a[k].r)/2;
		    node lft,rgt;
		    int flag1=0,flag2=0;
		    if (x<=mid) flag1=1,lft=query(k*2,x,y);
		    if (mid<y) flag2=1,rgt=query(k*2+1,x,y);
		    if (flag1&&!flag2) return lft;
		    else if (!flag1&&flag2) return rgt;
			else return merge(lft,rgt);
		}
		void update(int k,int x)
		{
			if (a[k].l==a[k].r) return a[k].val=1,void();
			int mid=(a[k].l+a[k].r)/2;
			if (x<=mid) update(k*2,x);
			if (mid<x) update(k*2+1,x);
			pushup(k);
		}
	public:
		void prepare(int n)
		{
			w[1]=1;for (int i=2;i<=n;i++) w[i]=w[i-1]*7%mod;
		}
		void make(int n)
		{
			build(1,1,n);
		}
		void add(int x)
		{
			update(1,x);
		}
		long long solve(int x,int y)
		{
//			printf("solve %d %d\n",x,y);
			return query(1,x,y).val;
		}
#undef mod
#undef len
};
sgt t1,t2;
int n;
int main()
{
#define op(x) ((n)-(x)+(1))
    scanf("%d",&n);
	t1.make(n);t2.make(n);
//	printf("op(3)=%d\n",op(3));
//	return 0;
	for (int i=1;i<=n;i++)
	{
//		printf("%d\n",i);
		int x;
		scanf("%d",&x);
		t1.add(x);t2.add(op(x));
//		puts("qwq");
		int ll=x-1,rr=n-x;
		int len=std::min(ll,rr);
		if (!len) continue;
		long long xx=t1.solve(x+1,x+len),yy=t2.solve(op(x-1),op(x-len));
//		puts("qaq");
//		printf("%d:%lld %lld\n",i,xx,yy);
		if (xx!=yy) return puts("YES"),0;
	}
    puts("NO");
	return 0;
#undef op
}


#include<cstdio>
#include<algorithm>
struct sgt
{
#define len(x,y) ((y)-(x)+(1))
#define mod 998244353
    struct node
    {
    	int l,r;
		long long val;
	};
	node a[1500005];
	long long w[1000005];
	private:
		node merge(node x,node y)
		{
			node p;
			p.l=x.l;p.r=y.r;
			p.val=(x.val*w[len(x.l,x.r)]+y.val)%mod;
			return p;
		}
		void pushup(int k)
		{
			a[k]=merge(a[k*2],a[k*2+1]);
		}
		void build(int k,int l,int r)
		{
//			printf("%d[%d,%d]\n",k,l,r);
			if (l==r) return a[k].l=l,a[k].r=r,a[k].val=0,void();
			int mid=(l+r)/2;
			build(k*2,l,mid);
			build(k*2+1,mid+1,r);
			pushup(k);
		}
		node query(int k,int x,int y)
		{
//			printf("Q %d[%d,%d] %d %d\n",k,a[k].l,a[k].r,x,y);
			if (x<=a[k].l&&a[k].r<=y) return a[k];
		    int mid=(a[k].l+a[k].r)/2;
		    node lft,rgt;
		    int flag1=0,flag2=0;
		    if (x<=mid) flag1=1,lft=query(k*2,x,y);
		    if (mid<y) flag2=1,rgt=query(k*2+1,x,y);
		    if (flag1&&!flag2) return lft;
		    else if (!flag1&&flag2) return rgt;
			else return merge(lft,rgt);
		}
		void update(int k,int x)
		{
			if (a[k].l==a[k].r) return a[k].val=1,void();
			int mid=(a[k].l+a[k].r)/2;
			if (x<=mid) update(k*2,x);
			if (mid<x) update(k*2+1,x);
			pushup(k);
		}
	public:
		void prepare(int n)
		{
			w[1]=1;for (int i=2;i<=n;i++) w[i]=w[i-1]*26%mod;
		}
		void make(int n)
		{
			build(1,1,n);
		}
		void add(int x)
		{
			update(1,x);
		}
		long long solve(int x,int y)
		{
//			printf("solve %d %d\n",x,y);
			return query(1,x,y).val;
		}
#undef mod
#undef len
};
sgt t1,t2;
int n;
int main()
{
#define op(x) ((n)-(x)+(1))
    scanf("%d",&n);
	t1.make(n);t2.make(n);
//	printf("op(3)=%d\n",op(3));
//	return 0;
	for (int i=1;i<=n;i++)
	{
//		printf("%d\n",i);
		int x;
		scanf("%d",&x);
		t1.add(x);t2.add(op(x));
//		puts("qwq");
		int ll=x-1,rr=n-x;
		int len=std::min(ll,rr);
		if (!len) continue;
		long long xx=t1.solve(x+1,x+len),yy=t2.solve(op(x-1),op(x-len));
//		puts("qaq");
//		printf("%d:%lld %lld\n",i,xx,yy);
		if (xx!=yy) return puts("YES"),0;
	}
    puts("NO");
	return 0;
#undef op
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ls (x<<1)
#define rs (x<<1|1)
#define db double
#define inf 2147483647
#define llinf 9223372036854775807
#define ll long long
#define ull unsigned long long
using namespace std;
typedef pair<int,int> PII;
int inline read(){
    int num=0,neg=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')neg=-1;c=getchar();}
    while(isdigit(c)){num=(num<<3)+(num<<1)+c-'0';c=getchar();}
    return num*neg;
}
const int maxn=300010,mod=998244353;
int n,a[maxn],p[maxn],base=19260817,flg;
int klc[maxn<<2],zz[maxn<<2];
void push_up(int pos,int num){
    int lson=pos<<1,rson=pos<<1|1;
    klc[pos]=(1ll*klc[lson]*p[num/2]%mod+klc[rson])%mod;
    zz[pos]=(1ll*zz[rson]*p[num-num/2]%mod+zz[lson])%mod;
}
void insert(int pos,int l,int r,int num){
    if(l==r){klc[pos]=zz[pos]=1;return;}
    int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
    if(num<=mid)insert(lson,l,mid,num);
    else insert(rson,mid+1,r,num);push_up(pos,r-l+1);
}
int query(int pos,int l,int r,int L,int R){
    if(L==l&&r==R)return klc[pos];int mid=(l+r)>>1;
    if(R<=mid)return query(pos<<1,l,mid,L,R);
    else if(L>mid)return query(pos<<1|1,mid+1,r,L,R);
    else return (1ll*query(pos<<1,l,mid,L,mid)*p[R-mid]%mod+query(pos<<1|1,mid+1,r,mid+1,R))%mod;
}
int query2(int pos,int l,int r,int L,int R){
    if(L==l&&r==R)return zz[pos];int mid=(l+r)>>1;
    if(R<=mid)return query2(pos<<1,l,mid,L,R);
    else if(L>mid)return query2(pos<<1|1,mid+1,r,L,R);
    else return (query2(pos<<1,l,mid,L,mid)+1ll*query2(pos<<1|1,mid+1,r,mid+1,R)*p[mid-L+1]%mod)%mod;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();p[0]=1;
	for(int i=1;i<=n;i++)p[i]=1ll*base*p[i-1]%mod;insert(1,1,n,a[1]);
	for(int i=2;i<n;i++){
		int L=max(1,a[i]*2-n),R=min(n,a[i]*2-1);int mid=L+R>>1;
		if(R-mid!=mid-L+1){if(query(1,1,n,L,mid)!=query2(1,1,n,mid,R))flg=1;}
		else{if(query(1,1,n,L,mid)!=query2(1,1,n,mid+1,R))flg=1;}insert(1,1,n,a[i]);
	}if(flg)printf("YES\n");else printf("NO\n");return 0;
}


#include <bits/stdc++.h>
#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define lll bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (k); ++i)
#define foR(i, j, k) for(R int i = (j); i >= (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll N = 1200011;
const ll INF = 5e16;

ll Q, n, a[N];
ull Base = 131, po[N], Ha[N];

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread (buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using IO::wln;
using IO::read;

namespace Segment_Tree {

	#define ls(x) (x << 1)
	#define rs(x) (x << 1 | 1)
	#define mid ((l + r) >> 1)

	struct Tree {
		ull H1, H2;
	} T[N << 2];

	inline void pushUp ( ll p, ll l, ll r ) {
		ll Len = (r - l + 1) >> 1;
		T[p].H1 = T[ls(p)].H1 * po[Len] + T[rs(p)].H1;
		T[p].H2 = T[rs(p)].H2 * po[r - l + 1 - Len] + T[ls(p)].H2;
	}

	inline void build ( ll p, ll l, ll r ) {
		if (l == r) return (void) (T[p].H1 = T[p].H2 = 0);
		build (ls(p), l, mid); build (rs(p), mid + 1, r); pushUp (p, l, r);
	}

	inline void Update ( ll p, ll l, ll r, ll x ) {
		if (l == r) return (void) (T[p].H1 = T[p].H2 = Base);
		if (mid >= x) Update (ls(p), l, mid, x);
		if (mid < x)  Update (rs(p), mid + 1, r, x); pushUp (p, l, r);
	}

	inline ull Query ( ll p, ll l, ll r, ll ul, ll ur ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p].H1;
		if (mid >= ur) return Query (ls(p), l, mid, ul, ur);
		if (mid < ul)  return Query (rs(p), mid + 1, r, ul, ur);
		return Query (ls(p), l, mid, ul, mid) *
			   po[ur - mid] + Query (rs(p), mid + 1, r, mid + 1, ur);
	}

	inline ull query ( ll p, ll l, ll r, ll ul, ll ur ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p].H2;
		if (mid >= ur) return query (ls(p), l, mid, ul, ur);
		if (mid < ul)  return query (rs(p), mid + 1, r, ul, ur);
		return query (ls(p), l, mid, ul, mid) +
			   query (rs(p), mid + 1, r, mid + 1, ur) * po[mid - ul + 1];
	}

} // namespace Segment_Tree

using namespace Segment_Tree;

namespace Subtask1 {

	inline void main () {
		tr1::unordered_map <ll, ll> Vis, ID;
		For ( i, 1, n ) Vis[a[i]] = 1, ID[a[i]] = i;
		For ( i, 1, n ) For ( j, i + 1, n )
			if (Vis[a[j] + a[j] - a[i]] &&
				ID[a[j] + a[j] - a[i]] > j) goto Cesare;
		puts ("N"); return ; Cesare: puts ("Y");
	}

} // namespace Subtask1

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(); po[0] = 1;
	For ( i, 1, n ) a[i] = read(), po[i] = po[i - 1] * Base;

	build (1, 1, n);

//	Loop: ;
//	if () {
//		while (1) {
//			if () goto Loop;
//		}
//	}

	For ( i, 1, n ) {
		ll Len = min (a[i] - 1, n - a[i]);
		Update (1, 1, n, a[i]);
		if (Query (1, 1, n, a[i] - Len, a[i] - 1) !=
			query (1, 1, n, a[i] + 1, a[i] + Len)) return puts ("YES");
	} return puts ("NO"), 0;
}

/*

*/


#include <bits/stdc++.h>
#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define lll bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (k); ++i)
#define foR(i, j, k) for(R int i = (j); i >= (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll N = 100011;
const ll INF = 5e16;

ll Q, n, a[N];
ull Base = 131, po[N], Ha[N];

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread (buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using IO::wln;
using IO::read;

inline ull Hash ( ll l, ll r ) {
	return Ha[r] - Ha[l - 1] * po[r - l + 1];
}

namespace Segment_Tree {

	#define ls(x) (x << 1)
	#define rs(x) (x << 1 | 1)
	#define mid ((l + r) >> 1)

	struct Tree {
		ull H1, H2;
	} T[N << 2];

	inline void pushUp ( ll p, ll l, ll r ) {
		ll Len = (r - l + 1) >> 1;
		T[p].H1 = T[ls(p)].H1 * po[Len] + T[rs(p)].H1;
		T[p].H2 = T[rs(p)].H2 * po[r - l + 1 - Len] + T[ls(p)].H2;
	}

	inline void build ( ll p, ll l, ll r ) {
		if (l == r) return (void) (T[p].H1 = T[p].H2 = 0);
		build (ls(p), l, mid); build (rs(p), mid + 1, r); pushUp (p, l, r);
	}

	inline void Update ( ll p, ll l, ll r, ll x ) {
		if (l == r) return (void) (T[p].H1 = T[p].H2 = Base);
		if (mid >= x) Update (ls(p), l, mid, x);
		if (mid < x)  Update (rs(p), mid + 1, r, x); pushUp (p, l, r);
	}

	inline ull Query ( ll p, ll l, ll r, ll ul, ll ur ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p].H1;
		if (mid >= ur) return Query (ls(p), l, mid, ul, ur);
		if (mid < ul)  return Query (rs(p), mid + 1, r, ul, ur);
		return Query (ls(p), l, mid, ul, mid) *
			   po[ur - mid] + Query (rs(p), mid + 1, r, mid + 1, ur);
	}

	inline ull query ( ll p, ll l, ll r, ll ul, ll ur ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p].H2;
		if (mid >= ur) return query (ls(p), l, mid, ul, ur);
		if (mid < ul)  return query (rs(p), mid + 1, r, ul, ur);
		return query (ls(p), l, mid, ul, mid) +
			   query (rs(p), mid + 1, r, mid + 1, ur) * po[mid - ul + 1];
	}

} // namespace Segment_Tree

using namespace Segment_Tree;

namespace Subtask1 {

	inline void main () {
		tr1::unordered_map <ll, ll> Vis, ID;
		For ( i, 1, n ) Vis[a[i]] = 1, ID[a[i]] = i;
		For ( i, 1, n ) For ( j, i + 1, n )
			if (Vis[a[j] + a[j] - a[i]] &&
				ID[a[j] + a[j] - a[i]] > j) goto Cesare;
		puts ("N"); return ; Cesare: puts ("Y");
	}

} // namespace Subtask1

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(); po[0] = 1;
	For ( i, 1, n ) a[i] = read(), po[i] = po[i - 1] * Base;

	build (1, 1, n);

	For ( i, 1, n ) {
		ll Len = min (a[i] - 1, n - a[i]);
		Update (1, 1, n, a[i]);
		if (Query (1, 1, n, a[i] - Len, a[i] - 1) !=
			query (1, 1, n, a[i] + 1, a[i] + Len)) return puts ("YES");
	} return puts ("No"), 0;
}

/*

*/


#include <bits/stdc++.h>
#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define lll bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (k); ++i)
#define foR(i, j, k) for(R int i = (j); i >= (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll N = 100011;
const ll INF = 5e16;

ll Q, n, a[N];
ull Base = 131, po[N], Ha[N];

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread (buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using IO::wln;
using IO::read;

inline ull Hash ( ll l, ll r ) {
	return Ha[r] - Ha[l - 1] * po[r - l + 1];
}

namespace Segment_Tree {

	#define ls(x) (x << 1)
	#define rs(x) (x << 1 | 1)
	#define mid ((l + r) >> 1)

	struct Tree {
		ull H1, H2;
	} T[N << 2];

	inline void pushUp ( ll p, ll l, ll r ) {
		ll Len = (r - l + 1) >> 1;
		T[p].H1 = T[ls(p)].H1 * po[Len] + T[rs(p)].H1;
		T[p].H2 = T[rs(p)].H2 * po[r - l + 1 - Len] + T[ls(p)].H2;
	}

	inline void build ( ll p, ll l, ll r ) {
		if (l == r) return (void) (T[p].H1 = T[p].H2 = 0);
		build (ls(p), l, mid); build (rs(p), mid + 1, r); pushUp (p, l, r);
	}

	inline void Update ( ll p, ll l, ll r, ll x ) {
		if (l == r) return (void) (T[p].H1 = T[p].H2 = Base);
		if (mid >= x) Update (ls(p), l, mid, x);
		if (mid < x)  Update (rs(p), mid + 1, r, x); pushUp (p, l, r);
	}

	inline ull Query ( ll p, ll l, ll r, ll ul, ll ur ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p].H1;
		if (mid >= ur) return Query (ls(p), l, mid, ul, ur);
		if (mid < ul)  return Query (rs(p), mid + 1, r, ul, ur);
		return Query (ls(p), l, mid, ul, mid) *
			   po[ur - mid] + Query (rs(p), mid + 1, r, mid + 1, ur);
	}

	inline ull query ( ll p, ll l, ll r, ll ul, ll ur ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p].H2;
		if (mid >= ur) return query (ls(p), l, mid, ul, ur);
		if (mid < ul)  return query (rs(p), mid + 1, r, ul, ur);
		return query (ls(p), l, mid, ul, mid) +
			   query (rs(p), mid + 1, r, mid + 1, ur) * po[mid - ul + 1];
	}

} // namespace Segment_Tree

using namespace Segment_Tree;

namespace Subtask1 {

	inline void main () {
		tr1::unordered_map <ll, ll> Vis, ID;
		For ( i, 1, n ) Vis[a[i]] = 1, ID[a[i]] = i;
		For ( i, 1, n ) For ( j, i + 1, n )
			if (Vis[a[j] + a[j] - a[i]] &&
				ID[a[j] + a[j] - a[i]] > j) goto Cesare;
		puts ("N"); return ; Cesare: puts ("Y");
	}

} // namespace Subtask1

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	po[0] = 1;
	For ( i, 1, N - 5 ) po[i] = po[i - 1] * Base;
	Set (T, 0);
	n = read();
	For ( i, 1, n ) a[i] = read();

	build (1, 1, n);

	For ( i, 1, n ) {
		ll Len = min (a[i] - 1, n - a[i]);
		Update (1, 1, n, a[i]);
		if (Query (1, 1, n, a[i] - Len, a[i] - 1) !=
			query (1, 1, n, a[i] + 1, a[i] + Len)) goto xzy;
	}
	return puts ("NO"), 0;
	xzy: return puts ("YES"), 0;
}

/*

*/


#include <bits/stdc++.h>
#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define lll bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (k); ++i)
#define foR(i, j, k) for(R int i = (j); i >= (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll N = 300011;
const ll INF = 5e16;

ll Q, n, a[N];
ull Base = 131, po[N], Ha[N];

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread (buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using IO::wln;
using IO::read;

inline ull Hash ( ll l, ll r ) {
	return Ha[r] - Ha[l - 1] * po[r - l + 1];
}

namespace Segment_Tree {

	#define ls(x) (x << 1)
	#define rs(x) (x << 1 | 1)
	#define mid ((l + r) >> 1)

	struct Tree {
		ull H1, H2;
	} T[N << 2];

	inline void pushUp ( ll p, ll l, ll r ) {
		ll Len = (r - l + 1) >> 1;
		T[p].H1 = T[ls(p)].H1 * po[Len] + T[rs(p)].H1;
		T[p].H2 = T[rs(p)].H2 * po[r - l + 1 - Len] + T[ls(p)].H2;
	}

	inline void build ( ll p, ll l, ll r ) {
		if (l == r) return (void) (T[p].H1 = T[p].H2 = 0);
		build (ls(p), l, mid); build (rs(p), mid + 1, r); pushUp (p, l, r);
	}

	inline void Update ( ll p, ll l, ll r, ll x ) {
		if (l == r) return (void) (T[p].H1 = T[p].H2 = Base);
		if (mid >= x) Update (ls(p), l, mid, x);
		if (mid < x)  Update (rs(p), mid + 1, r, x); pushUp (p, l, r);
	}

	inline ull Query ( ll p, ll l, ll r, ll ul, ll ur ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p].H1;
		if (mid >= ur) return Query (ls(p), l, mid, ul, ur);
		if (mid < ul)  return Query (rs(p), mid + 1, r, ul, ur);
		return Query (ls(p), l, mid, ul, mid) *
			   po[ur - mid] + Query (rs(p), mid + 1, r, mid + 1, ur);
	}

	inline ull query ( ll p, ll l, ll r, ll ul, ll ur ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p].H2;
		if (mid >= ur) return query (ls(p), l, mid, ul, ur);
		if (mid < ul)  return query (rs(p), mid + 1, r, ul, ur);
		return query (ls(p), l, mid, ul, mid) +
			   query (rs(p), mid + 1, r, mid + 1, ur) * po[mid - ul + 1];
	}

} // namespace Segment_Tree

using namespace Segment_Tree;

namespace Subtask1 {

	inline void main () {
		tr1::unordered_map <ll, ll> Vis, ID;
		For ( i, 1, n ) Vis[a[i]] = 1, ID[a[i]] = i;
		For ( i, 1, n ) For ( j, i + 1, n )
			if (Vis[a[j] + a[j] - a[i]] &&
				ID[a[j] + a[j] - a[i]] > j) goto Cesare;
		puts ("N"); return ; Cesare: puts ("Y");
	}

} // namespace Subtask1

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	po[0] = 1;
	For ( i, 1, N - 5 ) po[i] = po[i - 1] * Base;
	Q = read(); while (Q--) {
		Set (T, 0);
		n = read();
		For ( i, 1, n ) a[i] = read();

		build (1, 1, n);

		For ( i, 1, n ) {
			ll Len = min (a[i] - 1, n - a[i]);
			Update (1, 1, n, a[i]);
			if (Query (1, 1, n, a[i] - Len, a[i] - 1) !=
				query (1, 1, n, a[i] + 1, a[i] + Len)) goto xzy;
		}
		puts ("N"); continue; xzy: puts ("Y");
	} return 0;
}

/*

*/


#include <bits/stdc++.h>
#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define lll bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (k); ++i)
#define foR(i, j, k) for(R int i = (j); i >= (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll N = 1200011;
const ll INF = 5e16;

ll Q, n, a[N];
ull Base = 131, po[N], Ha[N];

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread (buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using IO::wln;
using IO::read;

namespace Segment_Tree {

	#define ls(x) (x << 1)
	#define rs(x) (x << 1 | 1)
	#define mid ((l + r) >> 1)

	struct Tree {
		ull H1, H2;
	} T[N << 2];

	inline void pushUp ( ll p, ll l, ll r ) {
		ll Len = (r - l + 1) >> 1;
		T[p].H1 = T[ls(p)].H1 * po[Len] + T[rs(p)].H1;
		T[p].H2 = T[rs(p)].H2 * po[r - l + 1 - Len] + T[ls(p)].H2;
	}

	inline void build ( ll p, ll l, ll r ) {
		if (l == r) return (void) (T[p].H1 = T[p].H2 = 0);
		build (ls(p), l, mid); build (rs(p), mid + 1, r); pushUp (p, l, r);
	}

	inline void Update ( ll p, ll l, ll r, ll x ) {
		if (l == r) return (void) (T[p].H1 = T[p].H2 = Base);
		if (mid >= x) Update (ls(p), l, mid, x);
		if (mid < x)  Update (rs(p), mid + 1, r, x); pushUp (p, l, r);
	}

	inline ull Query ( ll p, ll l, ll r, ll ul, ll ur ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p].H1;
		if (mid >= ur) return Query (ls(p), l, mid, ul, ur);
		if (mid < ul)  return Query (rs(p), mid + 1, r, ul, ur);
		return Query (ls(p), l, mid, ul, mid) *
			   po[ur - mid] + Query (rs(p), mid + 1, r, mid + 1, ur);
	}

	inline ull query ( ll p, ll l, ll r, ll ul, ll ur ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p].H2;
		if (mid >= ur) return query (ls(p), l, mid, ul, ur);
		if (mid < ul)  return query (rs(p), mid + 1, r, ul, ur);
		return query (ls(p), l, mid, ul, mid) +
			   query (rs(p), mid + 1, r, mid + 1, ur) * po[mid - ul + 1];
	}

} // namespace Segment_Tree

using namespace Segment_Tree;

namespace Subtask1 {

	inline void main () {
		tr1::unordered_map <ll, ll> Vis, ID;
		For ( i, 1, n ) Vis[a[i]] = 1, ID[a[i]] = i;
		For ( i, 1, n ) For ( j, i + 1, n )
			if (Vis[a[j] + a[j] - a[i]] &&
				ID[a[j] + a[j] - a[i]] > j) goto Cesare;
		puts ("N"); return ; Cesare: puts ("Y");
	}

} // namespace Subtask1

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(); po[0] = 1;
	For ( i, 1, n ) a[i] = read(), po[i] = po[i - 1] * Base;

	build (1, 1, n);

//	Loop: ;
//	if () {
//		while (1) {
//			if () goto Loop;
//		}
//	}

	For ( i, 1, n ) {
		ll Len = min (a[i] - 1, n - a[i]);
		Update (1, 1, n, a[i]);
		if (Query (1, 1, n, a[i] - Len, a[i] - 1) !=
			query (1, 1, n, a[i] + 1, a[i] + Len)) return puts ("YES");
	} return puts ("No"), 0;
}

/*

*/


#include <bits/stdc++.h>
#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define lll bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (k); ++i)
#define foR(i, j, k) for(R int i = (j); i >= (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll N = 100011;
const ll INF = 5e16;

ll Q, n, a[N];
ull Base = 131, po[N], Ha[N];

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread (buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using IO::wln;
using IO::read;

inline ull Hash ( ll l, ll r ) {
	return Ha[r] - Ha[l - 1] * po[r - l + 1];
}

namespace Segment_Tree {

	#define ls(x) (x << 1)
	#define rs(x) (x << 1 | 1)
	#define mid ((l + r) >> 1)

	struct Tree {
		ull H1, H2;
	} T[N << 2];

	inline void pushUp ( ll p, ll l, ll r ) {
		ll Len = (r - l + 1) >> 1;
		T[p].H1 = T[ls(p)].H1 * po[Len] + T[rs(p)].H1;
		T[p].H2 = T[rs(p)].H2 * po[r - l + 1 - Len] + T[ls(p)].H2;
	}

	inline void build ( ll p, ll l, ll r ) {
		if (l == r) return (void) (T[p].H1 = T[p].H2 = 0);
		build (ls(p), l, mid); build (rs(p), mid + 1, r); pushUp (p, l, r);
	}

	inline void Update ( ll p, ll l, ll r, ll x ) {
		if (l == r) return (void) (T[p].H1 = T[p].H2 = Base);
		if (mid >= x) Update (ls(p), l, mid, x);
		if (mid < x)  Update (rs(p), mid + 1, r, x); pushUp (p, l, r);
	}

	inline ull Query ( ll p, ll l, ll r, ll ul, ll ur ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p].H1;
		if (mid >= ur) return Query (ls(p), l, mid, ul, ur);
		if (mid < ul)  return Query (rs(p), mid + 1, r, ul, ur);
		return Query (ls(p), l, mid, ul, mid) *
			   po[ur - mid] + Query (rs(p), mid + 1, r, mid + 1, ur);
	}

	inline ull query ( ll p, ll l, ll r, ll ul, ll ur ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p].H2;
		if (mid >= ur) return query (ls(p), l, mid, ul, ur);
		if (mid < ul)  return query (rs(p), mid + 1, r, ul, ur);
		return query (ls(p), l, mid, ul, mid) +
			   query (rs(p), mid + 1, r, mid + 1, ur) * po[mid - ul + 1];
	}

} // namespace Segment_Tree

using namespace Segment_Tree;

namespace Subtask1 {

	inline void main () {
		tr1::unordered_map <ll, ll> Vis, ID;
		For ( i, 1, n ) Vis[a[i]] = 1, ID[a[i]] = i;
		For ( i, 1, n ) For ( j, i + 1, n )
			if (Vis[a[j] + a[j] - a[i]] &&
				ID[a[j] + a[j] - a[i]] > j) goto Cesare;
		puts ("N"); return ; Cesare: puts ("Y");
	}

} // namespace Subtask1

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	po[0] = 1;
	For ( i, 1, N - 5 ) po[i] = po[i - 1] * Base;
	Set (T, 0);
	n = read();
	For ( i, 1, n ) a[i] = read();

	build (1, 1, n);

	For ( i, 1, n ) {
		ll Len = min (a[i] - 1, n - a[i]);
		Update (1, 1, n, a[i]);
		if (Query (1, 1, n, a[i] - Len, a[i] - 1) !=
			query (1, 1, n, a[i] + 1, a[i] + Len)) goto xzy;
	}
	return puts ("No"), 0;
	xzy: return puts ("Yes"), 0;
}

/*

*/


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second

#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 6e5+5, LG = 17, MOD = 998244353;
const int SQ = 320;
const long double EPS = 1e-7;

int a[N];
int pos[N];
int32_t main(){

  int n;
  cin >> n;

  f(i,0,n){
    cin >> a[i];
    pos[a[i] + a[i]] = i;
  }

  f(i,0,min(10000,n))
    f(j,max(i+1,n-10000),n)
      if(i<pos[a[i]+a[j]] && pos[a[i] + a[j]] < j){
        cout << "YES\n";
        return 0;
      }
  cout << "NO\n";

  return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second

#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 6e5+5, LG = 17, MOD = 998244353;
const int SQ = 320;
const long double EPS = 1e-7;

int a[N];
int pos[N];
int pos2[N];
inline void kill(){cout << "YES\n"; exit(0);}
int32_t main(){

  int n;
  cin >> n;

  f(i,0,n){
    cin >> a[i];
    pos[a[i] + a[i]] = i;
    pos2[a[i]] = i;
  }

  f(i,0,min(1000,n))
    f(j,max(i+1,n-1000),n)
      if(i<pos[a[i]+a[j]] && pos[a[i] + a[j]] < j){
        kill();
      }
  f(i,0,n)
    f(j,i+1,min(n,i+100)){
      if(i<pos[a[i]+a[j]] && pos[a[i] + a[j]] < j)kill();
      if(a[j] + a[j] - a[i] > 0 && a[j] + a[j] - a[i] <= n && pos2[a[j] + a[j] - a[i]] > j)kill();
      if(a[i] + a[i] - a[j] > 0 && a[i] + a[i] - a[j] <= n && pos2[a[i] + a[i] - a[j]] < i)kill();
    }
  cout << "NO\n";
  return 0;

  return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second

#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 6e5+5, LG = 17, MOD = 998244353;
const int SQ = 320;
const long double EPS = 1e-7;

int a[N];
int pos[N];
int pos2[N];
inline void kill(){cout << "YES\n"; exit(0);}
int32_t main(){

  int n;
  cin >> n;

  f(i,0,n){
    cin >> a[i];
    pos[a[i] + a[i]] = i;
    pos2[a[i]] = i;
  }

  f(i,0,min(10000,n))
    f(j,max(i+1,n-10000),n)
      if(i<pos[a[i]+a[j]] && pos[a[i] + a[j]] < j){
        kill();
      }
  f(i,0,n)
    f(j,i+1,min(n,i+1000)){
      if(i<pos[a[i]+a[j]] && pos[a[i] + a[j]] < j)kill();
      if(a[j] + a[j] - a[i] > 0 && a[j] + a[j] - a[i] <= n && pos2[a[j] + a[j] - a[i]] > j)kill();
      if(a[i] + a[i] - a[j] > 0 && a[i] + a[i] - a[j] <= n && pos2[a[i] + a[i] - a[j]] < i)kill();
    }
  cout << "NO\n";
  return 0;

  return 0;
}


#include <bits/stdc++.h>
#define int long long
#define inf 0x3f3f3f3f
#define re register
#define N 40000
#define base 131
#define mod 998244353
#define ls(k) (k<<1)
#define rs(k) (k<<1|1)
#define pushup(k) a[k]=a[ls(k)]+a[rs(k)],b[k]=b[rs(k)]+b[ls(k)]
using namespace std;
int po[N];
struct node{
	int val,len;
	inline void init(){val=0,len=0;};
	friend node operator +(node a,node b){
		return (node){(a.val*po[b.len]%mod+b.val)%mod,a.len+b.len};
	}
}a[N],b[N];
inline int read(){
    int x=0,w=0;char ch=getchar();
    while (!isdigit(ch))w|=ch=='-',ch=getchar();
    while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
    return w?-x:x;
}
void build(int k,int l,int r){
	if (l==r){
		a[k]=b[k]=(node){0,1};
		return;
	}
	int mid=(l+r)>>1;
	build(ls(k),l,mid);
	build(rs(k),mid+1,r);
	pushup(k);
}
void change(int k,int l,int r,int x){
	if (l==r){
		a[k]=b[k]=(node){1,1};
		return;
	}
	int mid=(l+r)>>1;
	if (x<=mid)change(ls(k),l,mid,x);
	else change(rs(k),mid+1,r,x);
	pushup(k);
}
node query1(int k,int l,int r,int x,int y){
	if (x<=l&&r<=y)
		return a[k];
	int mid=(l+r)>>1;node res;res.init();
	if (x<=mid)res=res+query1(ls(k),l,mid,x,y);
	if (mid<y) res=res+query1(rs(k),mid+1,r,x,y);
	return res;
}
node query2(int k,int l,int r,int x,int y){
	if (x<=l&&r<=y)
		return b[k];
	int mid=(l+r)>>1;node res;res.init();
	if (mid<y) res=res+query2(rs(k),mid+1,r,x,y);
	if (x<=mid)res=res+query2(ls(k),l,mid,x,y);
	return res;
}
signed main(){
	po[0]=1;
	int n=read(),flag=0;
	for (int i=1;i<=n;++i)po[i]=po[i-1]*base%mod;
	build(1,1,n);
	for (int i=1;i<=n;++i){
		int x=read();
		if (flag)continue;
		change(1,1,n,x);
		int len=min(x-1,n-x);
		if (len<=0)continue;
		if (query1(1,1,n,x-len,x-1).val!=query2(1,1,n,x+1,x+len).val){flag=1;continue;}
	}
	puts(flag?"YES":"NO");
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define re register
#define N 560000
using namespace std;

inline int read(){
    int x=0,w=0;char ch=getchar();
    while (!isdigit(ch))w|=ch=='-',ch=getchar();
    while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
    return w?-x:x;
}
int n,a[N];
bool check(){
	bitset<10060>b,c;b.reset();
	for (int i=1;i<=n;++i)c.set(i);
	for (int i=1;i<=n;++i){
		b.set(a[i]);c.reset(n-a[i]+1);
		if (((b>>(a[i]+1))&(c>>(n-a[i]+1+1))).any()){
			return 1;
		}
	}
	return 0;
}
signed main(){
	n=read();
	for (int i=1;i<=n;++i)a[i]=read();
	if (check()){puts("YES");return 0;}
	reverse(a+1,a+1+n);
	if (check())puts("YES");
	else puts("NO");
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define re register
#define N 560000
using namespace std;

inline int read(){
    int x=0,w=0;char ch=getchar();
    while (!isdigit(ch))w|=ch=='-',ch=getchar();
    while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
    return w?-x:x;
}
int n,a[N];
bool check(){
	bitset<10060>b,c;b.reset();
	for (int i=1;i<=n;++i)c.set(i);
	for (int i=1;i<=n;++i){
		b.set(a[i]);c.reset(n-a[i]+1);
		if (((b>>(a[i]+1))&(c>>(n-a[i]+1+1))).any()){
			return 1;
		}
	}
	return 0;
}
signed main(){
	int T=read();
	while (T--){
		n=read();
		for (int i=1;i<=n;++i)a[i]=read();
		if (check()){puts("YES");continue;}
		reverse(a+1,a+1+n);
		if (check())puts("YES");
		else puts("NO");
	}
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define re register
#define N 560000
using namespace std;

inline int read(){
    int x=0,w=0;char ch=getchar();
    while (!isdigit(ch))w|=ch=='-',ch=getchar();
    while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
    return w?-x:x;
}
int n,a[N];
bool check(){
	bitset<10060>b,c;b.reset();
	for (int i=1;i<=n;++i)c.set(i);
	for (int i=1;i<=n;++i){
		b.set(a[i]);c.reset(n-a[i]+1);
		if (((b>>(a[i]+1))&(c>>(n-a[i]+1+1))).any()){
			return 1;
		}
	}
	return 0;
}
signed main(){
	int T=read();
	while (T--){
		n=read();
		for (int i=1;i<=n;++i)a[i]=read();
		if (check()){puts("Y");continue;}
		reverse(a+1,a+1+n);
		if (check())puts("Y");
		else puts("N");
	}
    return 0;
}


#include <bits/stdc++.h>
#define int long long
#define inf 0x3f3f3f3f
#define re register
#define N 1200000
#define base 131
#define mod 998244353
#define ls(k) (k<<1)
#define rs(k) (k<<1|1)
#define pushup(k) a[k]=a[ls(k)]+a[rs(k)],b[k]=b[rs(k)]+b[ls(k)]
using namespace std;
int po[N];
struct node{
	int val,len;
	inline void init(){val=0,len=0;};
	friend node operator +(node a,node b){
		return (node){(a.val*po[b.len]%mod+b.val)%mod,a.len+b.len};
	}
}a[N],b[N];
inline int read(){
    int x=0,w=0;char ch=getchar();
    while (!isdigit(ch))w|=ch=='-',ch=getchar();
    while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
    return w?-x:x;
}
void build(int k,int l,int r){
	if (l==r){
		a[k]=b[k]=(node){0,1};
		return;
	}
	int mid=(l+r)>>1;
	build(ls(k),l,mid);
	build(rs(k),mid+1,r);
	pushup(k);
}
void change(int k,int l,int r,int x){
	if (l==r){
		a[k]=b[k]=(node){1,1};
		return;
	}
	int mid=(l+r)>>1;
	if (x<=mid)change(ls(k),l,mid,x);
	else change(rs(k),mid+1,r,x);
	pushup(k);
}
node query1(int k,int l,int r,int x,int y){
	if (x<=l&&r<=y)
		return a[k];
	int mid=(l+r)>>1;node res;res.init();
	if (x<=mid)res=res+query1(ls(k),l,mid,x,y);
	if (mid<y) res=res+query1(rs(k),mid+1,r,x,y);
	return res;
}
node query2(int k,int l,int r,int x,int y){
	if (x<=l&&r<=y)
		return b[k];
	int mid=(l+r)>>1;node res;res.init();
	if (mid<y) res=res+query2(rs(k),mid+1,r,x,y);
	if (x<=mid)res=res+query2(ls(k),l,mid,x,y);
	return res;
}
signed main(){
	po[0]=1;
	int n=read(),flag=0;
	for (int i=1;i<=n;++i)po[i]=po[i-1]*base%mod;
	build(1,1,n);
	for (int i=1;i<=n;++i){
		int x=read();
		if (flag)continue;
		change(1,1,n,x);
		int len=min(x-1,n-x);
		if (len<=0)continue;
		if (query1(1,1,n,x-len,x-1).val!=query2(1,1,n,x+1,x+len).val){flag=1;continue;}
	}
	puts(flag?"YES":"NO");
    return 0;
}


#include<bits/stdc++.h>
#define maxn 300000
#define mod 998244353
#define For(i, a, b) for(int i = a; i <= b; ++i)
#define Rof(i, a, b) for(int i = a; i >= b; --i)
using namespace std;

int n, a[maxn + 5], tr[2][maxn + 5], pw[2][maxn + 5];

void ins(int ty, int x, int y){while(x <= n) tr[ty][x] = (tr[ty][x] + y) % mod, x += x & -x;}
int que(int ty, int x){if(!x) return 0; int asi = 0; while(x) asi = (asi + tr[ty][x]) % mod, x -= x & -x; return asi;}

int fp(int x, int y){
	int asi = 1;
	while(y){
		if(y & 1) asi = 1ll * asi * x % mod;
		x = 1ll * x * x % mod;
		y >>= 1;
	}
	return asi;
}

int main(){
	scanf("%d", &n);
	pw[0][0] = pw[1][0] = 1; pw[0][1] = 31; pw[1][1] = fp(31, mod - 2);
	For(i, 2, n)
		pw[0][i] = 1ll * pw[0][i - 1] * pw[0][1] % mod, pw[1][i] = 1ll * pw[1][i - 1] * pw[1][1] % mod;
	For(i, 1, n){
		scanf("%d", &a[i]);
		ins(0, a[i], pw[0][a[i]]);
		ins(1, a[i], pw[0][n - a[i] + 1]);
		if(a[i] - 1 <= n - a[i]){
			if(que(0, a[i] - 1) != 1ll * (que(1, 2 * a[i] - 1) - que(1, a[i]) + mod) * pw[1][n - (2 * a[i] - 1)] % mod){puts("YES"); return 0;}
		}
		else{
			if(1ll * (que(0, a[i] - 1) - que(0, 2 * a[i] - n - 1) + mod) % mod * pw[1][2 * a[i] - n - 1] % mod != (que(1, n) - que(1, a[i]) + mod) % mod){puts("YES"); return 0;}
		}
	}
	puts("NO");
	return 0;
}


#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
#define DEBUG(x) cerr << "DEBUG" << x << " >>> " << endl;
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 3e5 + 5;
const int base1 = 103, base2 = 107;
const int md1 = 998244353, md2 = 98765431;

inline int fpow(int x, int y, int md) {
    int ans = 1;
    while(y) {
        if(y & 1) ans = 1ll * ans * x % md;
        x = 1ll * x * x % md; y >>= 1;
    }
    return ans;
}

struct fenwick {
    int f[N], n, md;

    inline int lowbit(int x) { return x & -x; }

    void add(int x, int y) {
        for(register int i = x; i <= n; i += lowbit(i))
            f[i] = (f[i] + y) % md;
    }

    int query(int x) {
        int ans = 0;
        for(register int i = x; i; i -= lowbit(i))
            ans = (ans + f[i]) % md;
        return ans;
    }
} tr[2][2];

int pw1[N], pw2[N], inv1[N], inv2[N], a[N];
int n;

int main() {
    freopen("poem.in", "r", stdin);
    freopen("poem.out", "w", stdout);
    read(n);
    tr[0][0].n = tr[0][1].n = tr[1][0].n = tr[1][1].n = n;
    tr[0][0].md = tr[0][1].md = md1;
    tr[1][0].md = tr[1][1].md = md2;
    pw1[0] = pw2[0] = inv1[0] = inv2[0] = 1;
    for(register int i = 1; i <= n; i++) {
        pw1[i] = 1ll * pw1[i - 1] * base1 % md1;
        pw2[i] = 1ll * pw2[i - 1] * base2 % md2;
        inv1[i] = fpow(pw1[i], md1 - 2, md1);
        inv2[i] = fpow(pw2[i], md2 - 2, md2);
        read(a[i]);
    }
    for(register int i = 1; i <= n; i++) {
        int big = min(a[i], n - a[i] + 1);
        int l1 = a[i] - big + 1, r1 = a[i];
        int l2 = a[i], r2 = a[i] + big - 1;
        int ans[2][2];
        ans[0][0] = 1ll * (tr[0][0].query(r1) - tr[0][0].query(l1 - 1) + md1) * inv1[l1 - 1] % md1;
        ans[1][0] = 1ll * (tr[1][0].query(r1) - tr[1][0].query(l1 - 1) + md2) * inv2[l1 - 1] % md2;
        ans[0][1] = 1ll * (tr[0][1].query(r2) - tr[0][1].query(l2 - 1) + md1) * inv1[n - r2] % md1;
        ans[1][1] = 1ll * (tr[1][1].query(r2) - tr[1][1].query(l2 - 1) + md2) * inv2[n - r2] % md2;
        if(ans[0][0] != ans[0][1] || ans[1][0] != ans[1][1]) {
            cout << "YES" << endl;
            return 0;
        }
        tr[0][0].add(a[i], pw1[a[i]]); tr[1][0].add(a[i], pw2[a[i]]);
        tr[0][1].add(a[i], pw1[n - a[i] + 1]); tr[1][1].add(a[i], pw2[n - a[i] + 1]);
    }
    cout << "NO" << endl;
    return 0;
}


#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
#define DEBUG(x) cerr << "DEBUG" << x << " >>> " << endl;
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 3e5 + 5;
const int base1 = 103, base2 = 107;
const int md1 = 998244353, md2 = 98765431;

inline int fpow(int x, int y, int md) {
    int ans = 1;
    while(y) {
        if(y & 1) ans = 1ll * ans * x % md;
        x = 1ll * x * x % md; y >>= 1;
    }
    return ans;
}

struct fenwick {
    int f[N], n, md;

    inline int lowbit(int x) { return x & -x; }

    void add(int x, int y) {
        for(register int i = x; i <= n; i += lowbit(i))
            f[i] = (f[i] + y) % md;
    }

    int query(int x) {
        int ans = 0;
        for(register int i = x; i; i -= lowbit(i))
            ans = (ans + f[i]) % md;
        return ans;
    }
} tr[2][2];

int pw1[N], pw2[N], inv1[N], inv2[N], a[N];
int n;

int main() {
    read(n);
    tr[0][0].n = tr[0][1].n = tr[1][0].n = tr[1][1].n = n;
    tr[0][0].md = tr[0][1].md = md1;
    tr[1][0].md = tr[1][1].md = md2;
    pw1[0] = pw2[0] = inv1[0] = inv2[0] = 1;
    for(register int i = 1; i <= n; i++) {
        pw1[i] = 1ll * pw1[i - 1] * base1 % md1;
        pw2[i] = 1ll * pw2[i - 1] * base2 % md2;
        inv1[i] = fpow(pw1[i], md1 - 2, md1);
        inv2[i] = fpow(pw2[i], md2 - 2, md2);
        read(a[i]);
    }
    for(register int i = 1; i <= n; i++) {
        int big = min(a[i], n - a[i] + 1);
        int l1 = a[i] - big + 1, r1 = a[i];
        int l2 = a[i], r2 = a[i] + big - 1;
        int ans[2][2];
        ans[0][0] = 1ll * (tr[0][0].query(r1) - tr[0][0].query(l1 - 1) + md1) * inv1[l1 - 1] % md1;
        ans[1][0] = 1ll * (tr[1][0].query(r1) - tr[1][0].query(l1 - 1) + md2) * inv2[l1 - 1] % md2;
        ans[0][1] = 1ll * (tr[0][1].query(r2) - tr[0][1].query(l2 - 1) + md1) * inv1[n - r2] % md1;
        ans[1][1] = 1ll * (tr[1][1].query(r2) - tr[1][1].query(l2 - 1) + md2) * inv2[n - r2] % md2;
        if(ans[0][0] != ans[0][1] || ans[1][0] != ans[1][1]) {
            cout << "YES" << endl;
            return 0;
        }
        tr[0][0].add(a[i], pw1[a[i]]); tr[1][0].add(a[i], pw2[a[i]]);
        tr[0][1].add(a[i], pw1[n - a[i] + 1]); tr[1][1].add(a[i], pw2[n - a[i] + 1]);
    }
    cout << "NO" << endl;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int n;
vector <int> niz;

vector <int> pot;
const int P = 10007;
const int MOD = 100000007;
const int MAXN = 300100;

struct logaritamska {
	int niz[MAXN];

	int sum(int i) {
		int res = 0;
		while(i > 0) {
			res += niz[i];
			res %= MOD;
			i -= (i & -i);
		}
		return res;
	}

	void add(int i, int val) {
		while(i < MAXN) {
			niz[i] += val;
			niz[i] %= MOD;
			i += (i & -i);
		}
	}
};

logaritamska L1, L2;

bool solve() {
	pot.resize(MAXN);
	pot[0] = 1;
	for(int i = 1; i < MAXN; i++)
		pot[i] = ((long long)pot[i - 1] * P) % MOD;

	int maska = 0, palin = 0;

	for(int i = 0; i < n; i++) {
		L1.add(niz[i], pot[niz[i]]);
		L2.add(n - niz[i] + 1, pot[n - niz[i] + 1]);

		if(niz[i] <= (n + 1) / 2) {
			int a, k;
			a = niz[i];
			k = a - 1;
			if(((long long)L1.sum(niz[i]+k) * pot[n - (k * 2 + 1)]) % MOD != (L2.sum(n) - L2.sum(n - (k * 2 + 1)) + MOD) % MOD)  {
				cout << i << endl;
				return true;
			}
		}
		else {
			int a, k;
			a = niz[i];
			k = n - a;
			if((L1.sum(n) - L1.sum(n - (2 * k + 1)) + MOD) % MOD != ((long long)L2.sum(k * 2 + 1) * pot[n - (k * 2 + 1)]) % MOD)
				return true;
		}

	}

	return false;
}

int main() {
	cin >> n;
	niz.resize(n);

	for(int i = 0; i < n; i++)
		cin >> niz[i];

	if(solve())
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int n;
vector <int> niz;

vector <int> pot;
const int P = 17;
const int MOD = 100000007;
const int MAXN = 300100;

struct logaritamska {
	int niz[MAXN];

	int sum(int i) {
		int res = 0;
		while(i > 0) {
			res += niz[i];
			res %= MOD;
			i -= (i & -i);
		}
		return res;
	}

	void add(int i, int val) {
		while(i < MAXN) {
			niz[i] += val;
			niz[i] %= MOD;
			i += (i & -i);
		}
	}
};

logaritamska L1, L2;

bool solve() {
	pot.resize(MAXN);
	pot[0] = 1;
	for(int i = 1; i < MAXN; i++)
		pot[i] = ((long long)pot[i - 1] * P) % MOD;

	int maska = 0, palin = 0;

	for(int i = 0; i < n; i++) {
		L1.add(niz[i], pot[niz[i]]);
		L2.add(n - niz[i] + 1, pot[n - niz[i] + 1]);

		if(niz[i] <= (n + 1) / 2) {
			int a, k;
			a = niz[i];
			k = a - 1;
			if(((long long)L1.sum(niz[i]+k) * pot[n - (k * 2 + 1)]) % MOD != (L2.sum(n) - L2.sum(n - (k * 2 + 1)) + MOD) % MOD)  {
				return true;
			}
		}
		else {
			int a, k;
			a = niz[i];
			k = n - a;
			if((L1.sum(n) - L1.sum(n - (2 * k + 1)) + MOD) % MOD != ((long long)L2.sum(k * 2 + 1) * pot[n - (k * 2 + 1)]) % MOD)
				return true;
		}

	}

	return false;
}

int main() {
	cin >> n;
	niz.resize(n);

	for(int i = 0; i < n; i++)
		cin >> niz[i];

	if(solve())
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int n;
vector <int> niz;

vector <int> pot;
const int P = 10007;
const int MOD = 100000007;
const int MAXN = 300100;

struct logaritamska {
	int niz[MAXN];

	int sum(int i) {
		int res = 0;
		while(i > 0) {
			res += niz[i];
			res %= MOD;
			i -= (i & -i);
		}
		return res;
	}

	void add(int i, int val) {
		while(i < MAXN) {
			niz[i] += val;
			niz[i] %= MOD;
			i += (i & -i);
		}
	}
};

logaritamska L1, L2;

bool solve() {
	pot.resize(MAXN);
	pot[0] = 1;
	for(int i = 1; i < MAXN; i++)
		pot[i] = ((long long)pot[i - 1] * P) % MOD;

	int maska = 0, palin = 0;

	for(int i = 0; i < n; i++) {
		L1.add(niz[i], pot[niz[i]]);
		L2.add(n - niz[i] + 1, pot[n - niz[i] + 1]);

		if(niz[i] <= (n + 1) / 2) {
			int a, k;
			a = niz[i];
			k = a - 1;
			if(((long long)L1.sum(niz[i]+k) * pot[n - (k * 2 + 1)]) % MOD != (L2.sum(n) - L2.sum(n - (k * 2 + 1)) + MOD) % MOD)  {
				return true;
			}
		}
		else {
			int a, k;
			a = niz[i];
			k = n - a;
			if((L1.sum(n) - L1.sum(n - (2 * k + 1)) + MOD) % MOD != ((long long)L2.sum(k * 2 + 1) * pot[n - (k * 2 + 1)]) % MOD)
				return true;
		}

	}

	return false;
}

int main() {
	cin >> n;
	niz.resize(n);

	for(int i = 0; i < n; i++)
		cin >> niz[i];

	if(solve())
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int a[300005],pos[300005];
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=1;i<=n;++i)
		{
			scanf("%d",a+i);
			pos[a[i]]=i;
		}
		bool flag=false;
		for(int i=1;i<=n&&!flag;++i)
			for(int j=i+1;j<=min(n,i+5)&&!flag;++j)
			{
				int temp=2*a[j]-a[i];
				if(temp<=n&&temp>0&&pos[temp]>j)
					flag=1;
				temp=2*a[i]-a[j];
				if(temp<=n&&temp>0&&pos[temp]<i)
					flag=1;
			}
			if(flag) puts("YES");
			else puts("NO");
	}
}


#include<cstdio>
#include<cstring>
using namespace std;
int n;
int a[300005],pos[300005];
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=1;i<=n;++i)
		{
			scanf("%d",a+i);
			pos[a[i]]=i;
		}
		bool flag=false;
		for(int i=1;i<=n&&!flag;++i)
			for(int j=i+1;j<=min(n,i+5)&&!flag;++j)
			{
				int temp=2*a[j]-a[i];
				if(temp<=n&&temp>0&&pos[temp]>j)
					flag=1;
				temp=2*a[i]-a[j];
				if(temp<=n&&temp>0&&pos[temp]<i)
					flag=1;
			}
			if(flag) puts("YES");
			else puts("NO");
	}
}


#include <bits/stdc++.h>
using namespace std;
const int N=30000+5;
#define int long long
#define MOD 20040901
#define Is(c) ('0'<=c && c<='9')
inline int read(){
	int x=0,f=1;char c=getchar();
	while(!Is(c)){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(Is(c)) x=x*10+c-48,c=getchar();
	return x*f;
}
int T,n,b=103;
int po[N],val[N*4][2];
inline int ls(int x){return x<<1;}
inline int rs(int x){return x<<1|1;}
void insert(int x,int l,int r,int p,int v,int id){
	if(l==r){
		val[x][id]=v%MOD;
		return ;
	}
	int mid=(l+r)>>1;
	if(p<=mid) insert(ls(x),l,mid,p,v,id);
	else insert(rs(x),mid+1,r,p,v,id);
	val[x][id]=(val[ls(x)][id]+val[rs(x)][id])%MOD;
}
int ask(int x,int l,int r,int L,int R,int id){
	if(L<=l && R>=r) return val[x][id]%MOD;
	int mid=(l+r)>>1,ans=0;
	if(L<=mid) ans=(ans+ask(ls(x),l,mid,L,R,id))%MOD;
	if(R>mid) ans=(ans+ask(rs(x),mid+1,r,L,R,id))%MOD;
	return ans;
}
signed main(){
//	T=read();
	po[0]=1;
	n=read();
	for(int i=1;i<=n;i++) po[i]=po[i-1]*(n+1)%MOD;
//	while(T--){
//		memset(val,0,sizeof(val));
//		n=read();
//		bool flag=false;
		for(int i=1;i<=n;i++){
			int num=read(),len=min(num-1,n-num);
			int l=num-len,_l=n-num-len+1;
			int ans1=ask(1,1,n,l,num,0),ans2=ask(1,1,n,_l,n-num+1,1);
			if(l>_l) ans2=ans2*po[l-_l];
			else ans1=ans1*po[_l-l];
			if(ans1!=ans2){ printf("YES\n"); return 0; }
			insert(1,1,n,num,po[num],0);insert(1,1,n,n-num+1,po[n-num+1],1);
		}
		printf("NO\n");
//	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=30000+5;
#define int long long
#define MOD 20040901
#define Is(c) ('0'<=c && c<='9')
inline int read(){
	int x=0,f=1;char c=getchar();
	while(!Is(c)){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(Is(c)) x=x*10+c-48,c=getchar();
	return x*f;
}
int n;
int po[N],val[N*4][2];
inline int ls(int x){return x<<1;}
inline int rs(int x){return x<<1|1;}
void insert(int x,int l,int r,int p,int v,int id){
	if(l==r){
		val[x][id]=v%MOD;
		return ;
	}
	int mid=(l+r)>>1;
	if(p<=mid) insert(ls(x),l,mid,p,v,id);
	else insert(rs(x),mid+1,r,p,v,id);
	val[x][id]=(val[ls(x)][id]+val[rs(x)][id])%MOD;
}
int ask(int x,int l,int r,int L,int R,int id){
	if(L<=l && R>=r) return val[x][id]%MOD;
	int mid=(l+r)>>1,ans=0;
	if(L<=mid) ans=(ans+ask(ls(x),l,mid,L,R,id))%MOD;
	if(R>mid) ans=(ans+ask(rs(x),mid+1,r,L,R,id))%MOD;
	return ans;
}
signed main(){
//	T=read();
	po[0]=1;
	n=read();
	for(int i=1;i<=n;i++) po[i]=po[i-1]*(n+1)%MOD;
//	while(T--){
//		memset(val,0,sizeof(val));
//		n=read();
//		bool flag=false;
		for(int i=1;i<=n;i++){
			int num=read(),len=min(num-1,n-num);
			int l=num-len,_l=n-num-len+1;
			int ans1=ask(1,1,n,l,num,0),ans2=ask(1,1,n,_l,n-num+1,1);
			if(l<_l) ans1=ans1*po[_l-l]%MOD;
			else ans2=ans2*po[l-_l]%MOD;
			if(ans1!=ans2){ printf("YES\n"); return 0; }
			insert(1,1,n,num,po[num],0);insert(1,1,n,n-num+1,po[n-num+1],1);
		}
		printf("NO\n");
//	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=30000+5;
#define int long long
#define MOD 20040901
#define Is(c) ('0'<=c && c<='9')
inline int read(){
	int x=0,f=1;char c=getchar();
	while(!Is(c)){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(Is(c)) x=x*10+c-48,c=getchar();
	return x*f;
}
int n;
int po[N],val[N*4][2];
inline int ls(int x){return x<<1;}
inline int rs(int x){return x<<1|1;}
void insert(int x,int l,int r,int p,int v,int id){
	if(l==r){
		val[x][id]=v%MOD;
		return ;
	}
	int mid=(l+r)>>1;
	if(p<=mid) insert(ls(x),l,mid,p,v,id);
	else insert(rs(x),mid+1,r,p,v,id);
	val[x][id]=(val[ls(x)][id]+val[rs(x)][id])%MOD;
}
int ask(int x,int l,int r,int L,int R,int id){
	if(L<=l && R>=r) return val[x][id]%MOD;
	int mid=(l+r)>>1,ans=0;
	if(L<=mid) ans=(ans+ask(ls(x),l,mid,L,R,id))%MOD;
	if(R>mid) ans=(ans+ask(rs(x),mid+1,r,L,R,id))%MOD;
	return ans;
}
signed main(){
//	T=read();
	po[0]=1;
	n=read();
	for(int i=1;i<=n;i++) po[i]=po[i-1]*(n+1)%MOD;
//	while(T--){
//		memset(val,0,sizeof(val));
//		n=read();
//		bool flag=false;
		for(int i=1;i<=n;i++){
			int num=read(),len=min(num-1,n-num);
			int l=num-len,_l=n-num-len+1;
			int ans1=ask(1,1,n,l,num,0),ans2=ask(1,1,n,_l,n-num+1,1);
			if(l<_l) ans1=ans1*po[_l_l]%MOD;
			else ans2=ans2*po[l-_l]%MOD;
			if(ans1!=ans2){ printf("YES\n"); return 0; }
			insert(1,1,n,num,po[num],0);insert(1,1,n,n-num+1,po[n-num+1],1);
		}
		printf("NO\n");
//	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=300000+5;
#define int long long
#define MOD 20040901
#define Is(c) ('0'<=c && c<='9')
inline int read(){
	int x=0,f=1;char c=getchar();
	while(!Is(c)){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(Is(c)) x=x*10+c-48,c=getchar();
	return x*f;
}
int n;
int po[N],val[N*4][2];
inline int ls(int x){return x<<1;}
inline int rs(int x){return x<<1|1;}
void insert(int x,int l,int r,int p,int v,int id){
	if(l==r){
		val[x][id]=v%MOD;
		return ;
	}
	int mid=(l+r)>>1;
	if(p<=mid) insert(ls(x),l,mid,p,v,id);
	else insert(rs(x),mid+1,r,p,v,id);
	val[x][id]=(val[ls(x)][id]+val[rs(x)][id])%MOD;
}
int ask(int x,int l,int r,int L,int R,int id){
	if(L<=l && R>=r) return val[x][id]%MOD;
	int mid=(l+r)>>1,ans=0;
	if(L<=mid) ans=(ans+ask(ls(x),l,mid,L,R,id))%MOD;
	if(R>mid) ans=(ans+ask(rs(x),mid+1,r,L,R,id))%MOD;
	return ans;
}
signed main(){
//	T=read();
	po[0]=1;
	n=read();
	for(int i=1;i<=n;i++) po[i]=po[i-1]*(n+1)%MOD;
//	while(T--){
//		memset(val,0,sizeof(val));
//		n=read();
//		bool flag=false;
		for(int i=1;i<=n;i++){
			int num=read(),len=min(num-1,n-num);
			int l=num-len,_l=n-num-len+1;
			int ans1=ask(1,1,n,l,num,0),ans2=ask(1,1,n,_l,n-num+1,1);
			if(l<_l) ans1=ans1*po[_l-l]%MOD;
			else ans2=ans2*po[l-_l]%MOD;
			if(ans1!=ans2){ printf("YES\n"); return 0; }
			insert(1,1,n,num,po[num],0);insert(1,1,n,n-num+1,po[n-num+1],1);
		}
		printf("NO\n");
//	}
	return 0;
}


// Mivik 2020.9.5
#include <iostream>
#include <cstring>
#include <cstdio>

#define d isdigit(c)
#define g c=t.get();
#define L return
#define K break
#define A(c,a,b)if(c)a else b;
#define I(c,a)if(c)a;
#define Y goto E
struct MI{private:char bb[4096];FILE*f;char*bs,*be;char e;bool o,l;public:MI():f(stdin){}MI(FILE*f):f(f),bs(0),be(0){}
#ifdef __linux__
MI(const char*s):f(fmemopen(const_cast<char*>(s),strlen(s),"r")){}
#endif
inline operator bool(){L!l;}inline char get(){if(o){o=0;L e;}
#ifdef MIVIK
char c=fgetc(f);I(c==-1,l=1)L c;
#else
I(bs==be,be=(bs=bb)+fread(bb,1,sizeof(bb),f))I(bs==be,{l=1;L-1;})L*bs++;
#endif
}inline void unget(char c){o=1;e=c;}template<typename T>inline T read(){T r;*this>r;L r;}template<typename T>inline MI&operator>(T&);};template<typename T>struct Q{const static bool U=T(-1)>=T(0);inline void operator()(MI&t,T&r)const{r=0;char c;bool y=0;A(U,for(;;){g I(c==-1,Y)I(d,K)},for(;;){g I(c==-1,Y)A(c=='-',{g I(d,{y=1;K;})},I(d,K))})for(;;){I(c==-1,Y)A(d,r=r*10+(c^48);,K)g}t.unget(c);E:;I(y,r=-r)}};template<>struct Q<char>{inline void operator()(MI&t,char&r){int c;for(;;){g I(c==-1,{r=-1;L;})I(!isspace(c),{r=c;L;})}}};template<typename T>inline MI&MI::operator>(T&t){Q<T>()(*this,t);L*this;}
#undef d
#undef g
#undef L
#undef K
#undef A
#undef I
#undef Y
template<typename T>std::ostream& operator<(std::ostream&out,const T&t){return out<<t;}
#define endl ('\n')
#define P(x) cout < #x" = " < (x) < endl
#define R (cin.read<int>())

using std::cout;

#ifdef MIVIK
MI cin(popen("xsel -ob", "r"));
#else
MI cin;
#endif

typedef unsigned long long uqe;

const int nmax = 300001;
const int tmax = 1048565;
const uqe B = 31;

int n;
int a[nmax];
uqe ps[nmax];
template<bool F>
struct seg {
uqe sum[tmax];
int ll, rr;
uqe vv;
#define ls (x << 1)
#define rs (ls | 1)
#define GM const int mid = (l + r) >> 1
#define LL ls, l, mid
#define RR rs, mid + 1, r
#define SS x, r - l + 1
inline void pu(int x, int l) {
	if (F) sum[x] = sum[ls] * ps[l >> 1] + sum[rs];
	else sum[x] = sum[ls] + sum[rs] * ps[(l + 1) >> 1];
}
inline void _update(int x, int l, int r) {
	if (l == r) {
		sum[x] += vv;
		return;
	}
	GM;
	if (ll <= mid) _update(LL);
	else _update(RR);
	pu(SS);
}
inline void update(int i, uqe v) { ll = i; vv = v; _update(1, 1, n); }
inline void _query(int x, int l, int r) {
	if (l == r) {
		vv *= ps[r - l + 1];
		vv += sum[x];
		return;
	}
	GM;
	if (F) {
		if (ll <= mid) _query(LL);
		if (mid < rr) _query(RR);
	} else {
		if (mid < rr) _query(RR);
		if (ll <= mid) _query(LL);
	}
}
inline uqe query(int l, int r) { ll = l; rr = r; vv = 0; _query(1, 1, n); return vv; }
};
seg<0> t1;
seg<1> t2;
int main() {
	cin>n;
	for (int i = 1; i <= n; ++i) cin>a[i];
	ps[0] = 1;
	for (int i = 1; i <= n; ++i) ps[i] = ps[i - 1] * B;
	for (int i = 1; i <= n; ++i) {
		const int x = a[i];
		const int l = std::min(x - 1, n - x);
		const uqe h1 = t1.query(x - l, x), h2 = t2.query(x, x + l);
		if (h1 != h2) {
			cout<"YES\n";
			return 0;
		}
		t1.update(x, 1); t2.update(x, 1);
	}
	cout<"NO\n";
	return 0;
}


// Mivik 2020.9.5
#include <iostream>
#include <cstring>
#include <cstdio>

#define d isdigit(c)
#define g c=t.get();
#define L return
#define K break
#define A(c,a,b)if(c)a else b;
#define I(c,a)if(c)a;
#define Y goto E
struct MI{private:char bb[4096];FILE*f;char*bs,*be;char e;bool o,l;public:MI():f(stdin){}MI(FILE*f):f(f),bs(0),be(0){}
#ifdef __linux__
MI(const char*s):f(fmemopen(const_cast<char*>(s),strlen(s),"r")){}
#endif
inline operator bool(){L!l;}inline char get(){if(o){o=0;L e;}
#ifdef MIVIK
char c=fgetc(f);I(c==-1,l=1)L c;
#else
I(bs==be,be=(bs=bb)+fread(bb,1,sizeof(bb),f))I(bs==be,{l=1;L-1;})L*bs++;
#endif
}inline void unget(char c){o=1;e=c;}template<typename T>inline T read(){T r;*this>r;L r;}template<typename T>inline MI&operator>(T&);};template<typename T>struct Q{const static bool U=T(-1)>=T(0);inline void operator()(MI&t,T&r)const{r=0;char c;bool y=0;A(U,for(;;){g I(c==-1,Y)I(d,K)},for(;;){g I(c==-1,Y)A(c=='-',{g I(d,{y=1;K;})},I(d,K))})for(;;){I(c==-1,Y)A(d,r=r*10+(c^48);,K)g}t.unget(c);E:;I(y,r=-r)}};template<>struct Q<char>{inline void operator()(MI&t,char&r){int c;for(;;){g I(c==-1,{r=-1;L;})I(!isspace(c),{r=c;L;})}}};template<typename T>inline MI&MI::operator>(T&t){Q<T>()(*this,t);L*this;}
#undef d
#undef g
#undef L
#undef K
#undef A
#undef I
#undef Y
template<typename T>std::ostream& operator<(std::ostream&out,const T&t){return out<<t;}
#define endl ('\n')
#define P(x) cout < #x" = " < (x) < endl
#define R (cin.read<int>())

using std::cout;

#include <algorithm>
#include <cstdlib>
#include <ctime>

#ifdef MIVIK
MI cin(popen("xsel -ob", "r"));
#else
MI cin;
#endif

#define IO(n) freopen(#n".in", "r", stdin), freopen(#n".out", "w", stdout)

const int nmax = 300001;

int n;
int a[nmax];
int o[nmax];
inline bool work() {
	for (int i = 1; i <= n; ++i) {
		const int x = o[i];
		const int lim = (n - x) >> 1;
		for (int j = 1; j <= lim; ++j)
			if ((a[x] < a[x + j]) == (a[x + j] < a[x + (j << 1)]))
				return true;
	}
	return false;
}
int main() {
#ifndef MIVIK
	IO(triple);
#endif
	srand(time(0));
	cin>n;
	for (int i = 1; i <= n; ++i) {
		a[R] = i;
		o[i] = i;
	}
	std::random_shuffle(o + 1, o + n + 1);
	for (int i = 1; i <= n; ++i) {
		const int x = o[i];
		if (x == 1) continue;
		if ((a[x] > a[x - 1]) == (a[x + 1] > a[x])) {
			cout<"YES\n";
			return 0;
		}
	}
	cout<(work()? "YES\n": "NO\n");
	return 0;
}


// Mivik 2020.9.5
#include <iostream>
#include <cstring>
#include <cstdio>

#define d isdigit(c)
#define g c=t.get();
#define L return
#define K break
#define A(c,a,b)if(c)a else b;
#define I(c,a)if(c)a;
#define Y goto E
struct MI{private:char bb[4096];FILE*f;char*bs,*be;char e;bool o,l;public:MI():f(stdin){}MI(FILE*f):f(f),bs(0),be(0){}
#ifdef __linux__
MI(const char*s):f(fmemopen(const_cast<char*>(s),strlen(s),"r")){}
#endif
inline operator bool(){L!l;}inline char get(){if(o){o=0;L e;}
#ifdef MIVIK
char c=fgetc(f);I(c==-1,l=1)L c;
#else
I(bs==be,be=(bs=bb)+fread(bb,1,sizeof(bb),f))I(bs==be,{l=1;L-1;})L*bs++;
#endif
}inline void unget(char c){o=1;e=c;}template<typename T>inline T read(){T r;*this>r;L r;}template<typename T>inline MI&operator>(T&);};template<typename T>struct Q{const static bool U=T(-1)>=T(0);inline void operator()(MI&t,T&r)const{r=0;char c;bool y=0;A(U,for(;;){g I(c==-1,Y)I(d,K)},for(;;){g I(c==-1,Y)A(c=='-',{g I(d,{y=1;K;})},I(d,K))})for(;;){I(c==-1,Y)A(d,r=r*10+(c^48);,K)g}t.unget(c);E:;I(y,r=-r)}};template<>struct Q<char>{inline void operator()(MI&t,char&r){int c;for(;;){g I(c==-1,{r=-1;L;})I(!isspace(c),{r=c;L;})}}};template<typename T>inline MI&MI::operator>(T&t){Q<T>()(*this,t);L*this;}
#undef d
#undef g
#undef L
#undef K
#undef A
#undef I
#undef Y
template<typename T>std::ostream& operator<(std::ostream&out,const T&t){return out<<t;}
#define endl ('\n')
#define P(x) cout < #x" = " < (x) < endl
#define R (cin.read<int>())

using std::cout;

#ifdef MIVIK
MI cin(popen("xsel -ob", "r"));
#else
MI cin;
#endif

typedef unsigned long long uqe;

const int nmax = 300001;
const int tmax = 1048565;
const uqe B = 31;

int n;
int a[nmax];
uqe ps[nmax];
template<bool F>
struct seg {
uqe sum[tmax];
int ll, rr;
uqe vv;
#define ls (x << 1)
#define rs (ls | 1)
#define GM const int mid = (l + r) >> 1
#define LL ls, l, mid
#define RR rs, mid + 1, r
#define SS x, r - l + 1
inline void pu(int x, int l) {
	if (F) sum[x] = sum[ls] * ps[l >> 1] + sum[rs];
	else sum[x] = sum[ls] + sum[rs] * ps[(l + 1) >> 1];
}
inline void _update(int x, int l, int r) {
	if (l == r) {
		sum[x] += vv;
		return;
	}
	GM;
	if (ll <= mid) _update(LL);
	else _update(RR);
	pu(SS);
}
inline void update(int i, uqe v) { ll = i; vv = v; _update(1, 1, n); }
inline void _query(int x, int l, int r) {
	if (l == r) {
		vv *= sum[r - l + 1];
		vv += sum[x];
		return;
	}
	GM;
	if (F) {
		if (ll <= mid) _query(LL);
		if (mid < rr) _query(RR);
	} else {
		if (mid < rr) _query(RR);
		if (ll <= mid) _query(LL);
	}
}
inline uqe query(int l, int r) { ll = l; rr = r; vv = 0; _query(1, 1, n); return vv; }
};
seg<0> t1;
seg<1> t2;
int main() {
	cin>n;
	for (int i = 1; i <= n; ++i) cin>a[i];
	ps[0] = 1;
	for (int i = 1; i <= n; ++i) ps[i] = ps[i - 1] * B;
	for (int i = 1; i <= n; ++i) {
		const int l = std::min(i - 1, n - i);
		const uqe h1 = t1.query(i - l + 1, i), h2 = t2.query(i, i + l - 1);
		if (h1 != h2) {
			cout<"YES\n";
			return 0;
		}
		t1.update(a[i], 1);
		t2.update(a[i], 1);
	}
	cout<"NO\n";
	return 0;
}


// Mivik 2020.9.5
#include <iostream>
#include <cstring>
#include <cstdio>

#define d isdigit(c)
#define g c=t.get();
#define L return
#define K break
#define A(c,a,b)if(c)a else b;
#define I(c,a)if(c)a;
#define Y goto E
struct MI{private:char bb[4096];FILE*f;char*bs,*be;char e;bool o,l;public:MI():f(stdin){}MI(FILE*f):f(f),bs(0),be(0){}
#ifdef __linux__
MI(const char*s):f(fmemopen(const_cast<char*>(s),strlen(s),"r")){}
#endif
inline operator bool(){L!l;}inline char get(){if(o){o=0;L e;}
#ifdef MIVIK
char c=fgetc(f);I(c==-1,l=1)L c;
#else
I(bs==be,be=(bs=bb)+fread(bb,1,sizeof(bb),f))I(bs==be,{l=1;L-1;})L*bs++;
#endif
}inline void unget(char c){o=1;e=c;}template<typename T>inline T read(){T r;*this>r;L r;}template<typename T>inline MI&operator>(T&);};template<typename T>struct Q{const static bool U=T(-1)>=T(0);inline void operator()(MI&t,T&r)const{r=0;char c;bool y=0;A(U,for(;;){g I(c==-1,Y)I(d,K)},for(;;){g I(c==-1,Y)A(c=='-',{g I(d,{y=1;K;})},I(d,K))})for(;;){I(c==-1,Y)A(d,r=r*10+(c^48);,K)g}t.unget(c);E:;I(y,r=-r)}};template<>struct Q<char>{inline void operator()(MI&t,char&r){int c;for(;;){g I(c==-1,{r=-1;L;})I(!isspace(c),{r=c;L;})}}};template<typename T>inline MI&MI::operator>(T&t){Q<T>()(*this,t);L*this;}
#undef d
#undef g
#undef L
#undef K
#undef A
#undef I
#undef Y
template<typename T>std::ostream& operator<(std::ostream&out,const T&t){return out<<t;}
#define endl ('\n')
#define P(x) cout < #x" = " < (x) < endl
#define R (cin.read<int>())

using std::cout;

#include <algorithm>
#include <cstdlib>
#include <ctime>

#ifdef MIVIK
MI cin(popen("xsel -ob", "r"));
#else
MI cin;
#endif

#define IO(n) freopen(#n".in", "r", stdin), freopen(#n".out", "w", stdout)

const int nmax = 300001;

int n;
int a[nmax];
int o[nmax];
inline bool work() {
	for (int i = 1; i <= n; ++i) {
		const int x = o[i];
		const int lim = (n - x) >> 1;
		for (int j = 1; j <= lim; ++j)
			if ((a[x] < a[x + j]) == (a[x + j] < a[x + (j << 1)]))
				return true;
	}
	return false;
}
int main() {
	srand(time(0));
	cin>n;
	for (int i = 1; i <= n; ++i) {
		a[R] = i;
		o[i] = i;
	}
	std::random_shuffle(o + 1, o + n + 1);
	cout<(work()? "YES\n": "NO\n");
	return 0;
}


// Mivik 2020.9.5
#include <iostream>
#include <cstring>
#include <cstdio>

#define d isdigit(c)
#define g c=t.get();
#define L return
#define K break
#define A(c,a,b)if(c)a else b;
#define I(c,a)if(c)a;
#define Y goto E
struct MI{private:char bb[4096];FILE*f;char*bs,*be;char e;bool o,l;public:MI():f(stdin){}MI(FILE*f):f(f),bs(0),be(0){}
#ifdef __linux__
MI(const char*s):f(fmemopen(const_cast<char*>(s),strlen(s),"r")){}
#endif
inline operator bool(){L!l;}inline char get(){if(o){o=0;L e;}
#ifdef MIVIK
char c=fgetc(f);I(c==-1,l=1)L c;
#else
I(bs==be,be=(bs=bb)+fread(bb,1,sizeof(bb),f))I(bs==be,{l=1;L-1;})L*bs++;
#endif
}inline void unget(char c){o=1;e=c;}template<typename T>inline T read(){T r;*this>r;L r;}template<typename T>inline MI&operator>(T&);};template<typename T>struct Q{const static bool U=T(-1)>=T(0);inline void operator()(MI&t,T&r)const{r=0;char c;bool y=0;A(U,for(;;){g I(c==-1,Y)I(d,K)},for(;;){g I(c==-1,Y)A(c=='-',{g I(d,{y=1;K;})},I(d,K))})for(;;){I(c==-1,Y)A(d,r=r*10+(c^48);,K)g}t.unget(c);E:;I(y,r=-r)}};template<>struct Q<char>{inline void operator()(MI&t,char&r){int c;for(;;){g I(c==-1,{r=-1;L;})I(!isspace(c),{r=c;L;})}}};template<typename T>inline MI&MI::operator>(T&t){Q<T>()(*this,t);L*this;}
#undef d
#undef g
#undef L
#undef K
#undef A
#undef I
#undef Y
template<typename T>std::ostream& operator<(std::ostream&out,const T&t){return out<<t;}
#define endl ('\n')
#define P(x) cout < #x" = " < (x) < endl
#define R (cin.read<int>())

using std::cout;

#ifdef MIVIK
MI cin(popen("xsel -ob", "r"));
#else
MI cin;
#endif

typedef unsigned long long uqe;

const int nmax = 300001;
const int tmax = 1048565;
const uqe B = 31;

int n;
int a[nmax];
uqe ps[nmax];
namespace seg {
uqe sum[tmax][2];
int ll, rr;
uqe vv;
#define ls (x << 1)
#define rs (ls | 1)
#define GM const int mid = (l + r) >> 1
#define LL ls, l, mid
#define RR rs, mid + 1, r
inline void pu(int x, int l) {
	sum[x][0] = sum[ls][0] + sum[rs][0] * ps[(l + 1) >> 1];
	sum[x][1] = sum[ls][1] * ps[l >> 1] + sum[rs][1];
}
inline void _update(int x, int l, int r) {
	if (l == r) {
		sum[x][0] += vv;
		sum[x][1] += vv;
		return;
	}
	GM;
	if (ll <= mid) _update(LL);
	else _update(RR);
	pu(x, r - l + 1);
}
inline void update(int i, uqe v) { ll = i; vv = v; _update(1, 1, n); }
template<bool D>
void _query(int x, int l, int r) {
	if (ll <= l && r <= rr) {
		vv *= ps[r - l + 1];
		vv += sum[x][D];
		return;
	}
	GM;
	if (D) {
		if (ll <= mid) _query<D>(LL);
		if (mid < rr) _query<D>(RR);
	} else {
		if (mid < rr) _query<D>(RR);
		if (ll <= mid) _query<D>(LL);
	}
}
template<bool D> inline uqe query(int l, int r) { ll = l; rr = r; vv = 0; _query<D>(1, 1, n); return vv; }
}
int main() {
	cin>n;
	for (int i = 1; i <= n; ++i) cin>a[i];
	ps[0] = 1;
	for (int i = 1; i <= n; ++i) ps[i] = ps[i - 1] * B;
	for (int i = 1; i <= n; ++i) {
		const int x = a[i];
		const int l = std::min(x - 1, n - x);
		const uqe h1 = seg::query<1>(x - l, x), h2 = seg::query<0>(x, x + l);
		if (h1 != h2) {
			cout<"YES\n";
			return 0;
		}
		seg::update(x, 1);
	}
	cout<"NO\n";
	return 0;
}


// Mivik 2020.9.5
#include <iostream>
#include <cstring>
#include <cstdio>

#define d isdigit(c)
#define g c=t.get();
#define L return
#define K break
#define A(c,a,b)if(c)a else b;
#define I(c,a)if(c)a;
#define Y goto E
struct MI{private:char bb[4096];FILE*f;char*bs,*be;char e;bool o,l;public:MI():f(stdin){}MI(FILE*f):f(f),bs(0),be(0){}
#ifdef __linux__
MI(const char*s):f(fmemopen(const_cast<char*>(s),strlen(s),"r")){}
#endif
inline operator bool(){L!l;}inline char get(){if(o){o=0;L e;}
#ifdef MIVIK
char c=fgetc(f);I(c==-1,l=1)L c;
#else
I(bs==be,be=(bs=bb)+fread(bb,1,sizeof(bb),f))I(bs==be,{l=1;L-1;})L*bs++;
#endif
}inline void unget(char c){o=1;e=c;}template<typename T>inline T read(){T r;*this>r;L r;}template<typename T>inline MI&operator>(T&);};template<typename T>struct Q{const static bool U=T(-1)>=T(0);inline void operator()(MI&t,T&r)const{r=0;char c;bool y=0;A(U,for(;;){g I(c==-1,Y)I(d,K)},for(;;){g I(c==-1,Y)A(c=='-',{g I(d,{y=1;K;})},I(d,K))})for(;;){I(c==-1,Y)A(d,r=r*10+(c^48);,K)g}t.unget(c);E:;I(y,r=-r)}};template<>struct Q<char>{inline void operator()(MI&t,char&r){int c;for(;;){g I(c==-1,{r=-1;L;})I(!isspace(c),{r=c;L;})}}};template<typename T>inline MI&MI::operator>(T&t){Q<T>()(*this,t);L*this;}
#undef d
#undef g
#undef L
#undef K
#undef A
#undef I
#undef Y
template<typename T>std::ostream& operator<(std::ostream&out,const T&t){return out<<t;}
#define endl ('\n')
#define P(x) cout < #x" = " < (x) < endl
#define R (cin.read<int>())

using std::cout;

#include <algorithm>
#include <cstdlib>
#include <ctime>

#ifdef MIVIK
MI cin(popen("xsel -ob", "r"));
#else
MI cin;
#endif

#define IO(n) freopen(#n".in", "r", stdin), freopen(#n".out", "w", stdout)

const int nmax = 300001;

int n;
int a[nmax];
int o[nmax];
inline bool work() {
	for (int i = 1; i <= n; ++i) {
		const int x = o[i];
		const int lim = (n - x) >> 1;
		for (int j = 1; j <= lim; ++j)
			if ((a[x] < a[x + j]) == (a[x + j] < a[x + (j << 1)]))
				return true;
	}
	return false;
}
int main() {
	srand(time(0));
	cin>n;
	for (int i = 1; i <= n; ++i) {
		a[R] = i;
		o[i] = i;
	}
	std::random_shuffle(o + 1, o + n + 1);
	for (int i = 1; i <= n; ++i) {
		const int x = o[i];
		if (x == 1) continue;
		if ((a[x] > a[x - 1]) == (a[x + 1] > a[x])) {
			cout<"YES\n";
			return 0;
		}
	}
	cout<(work()? "YES\n": "NO\n");
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int_t;

#ifndef local
char getch(){
    static char buf[100000],*s,*t;
    return (s == t) && (t = (s = buf) + fread(buf,1,100000,stdin)), s == t ? EOF : *s++;
}
#else
char getch(){return getchar();}
#endif

int_t read(){
    int_t x = 0,w = 1;char ch = 0;
    while(!isdigit(ch)) {ch = getch(); if(ch == '-') w = -1;}
    while(isdigit(ch)) x = x * 10 + ch - '0', ch = getch();
    return x * w;
}

int_t add(int_t a,int_t b,int_t p){return ((a += b) >= p ? a - p : a);}
int_t sub(int_t a,int_t b,int_t p){return (a -= b) <  0 ? a + p : a;}

// templates above

const int_t maxn = 300100,mod = 133;

int_t seg1[maxn << 3],seg2[maxn << 3];

#define lson rt << 1
#define rson lson | 1

void modify(int_t rt,int_t l,int_t r,int_t pos,int_t v,int_t* arr){
    if(l == r) {arr[rt] = v; return;}
    int_t mid = (l + r) >> 1;
    if(mid >= pos) modify(lson,l,mid,pos,v,arr);
    else modify(rson,mid+1,r,pos,v,arr);
    arr[rt] = arr[lson] + arr[rson];
}

int_t query(int_t rt,int_t l,int_t r,int_t x,int_t y,int_t* arr){
    if(x <= l && r <= y) return arr[rt];
    int_t mid = (l + r) >> 1,ans = 0;
    if(x <= mid) ans = query(lson,l,mid,x,y,arr);
    if(mid <  y) ans += query(rson,mid+1,r,x,y,arr);
    return ans;
}

int_t arr[maxn],forHash[maxn] = {1};

int main() {
    int_t n = read();
    for(int_t i=1;i<=n;i++) arr[i] = read();
    for(int_t i=1;i<=n;i++) forHash[i] = forHash[i-1] * mod;
    for(int_t i=1;i<=n;i++){
        int_t len = min(arr[i] - 1,n - arr[i]),l = arr[i] - len,r = n - arr[i] - len + 1;
        int_t x = query(1,1,n,l,arr[i], seg1), y = query(1,1,n,r,n - arr[i] + 1,seg2);
        if(l < r) x *= forHash[r - l]; else y *= forHash[l - r];
        if(x != y) {cout<<"YES"; return 0;}
        modify(1,1,n,arr[i],forHash[arr[i]],seg1);
        modify(1,1,n,n - arr[i] + 1,forHash[n - arr[i] + 1],seg2);
    }
    cout<<"NO";
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int_t;

#ifndef local
char getch(){
    static char buf[100000],*s,*t;
    return (s == t) && (t = (s = buf) + fread(buf,1,100000,stdin)), s == t ? EOF : *s++;
}
#else
char getch(){return getchar();}
#endif

int_t read(){
    int_t x = 0,w = 1;char ch = 0;
    while(!isdigit(ch)) {ch = getch(); if(ch == '-') w = -1;}
    while(isdigit(ch)) x = x * 10 + ch - '0', ch = getch();
    return x * w;
}

int_t add(int_t a,int_t b,int_t p){return ((a += b) >= p ? a - p : a);}
int_t sub(int_t a,int_t b,int_t p){return (a -= b) <  0 ? a + p : a;}

// templates above

const int_t maxn = 3010,mod = 133;

int_t seg1[maxn << 3],seg2[maxn << 3];

#define lson rt << 1
#define rson lson | 1

void modify(int_t rt,int_t l,int_t r,int_t pos,int_t v,int_t* arr){
    if(l == r) {arr[rt] = v; return;}
    int_t mid = (l + r) >> 1;
    if(mid >= pos) modify(lson,l,mid,pos,v,arr);
    else modify(rson,mid+1,r,pos,v,arr);
    arr[rt] = arr[lson] + arr[rson];
}

int_t query(int_t rt,int_t l,int_t r,int_t x,int_t y,int_t* arr){
    if(x <= l && r <= y) return arr[rt];
    int_t mid = (l + r) >> 1,ans = 0;
    if(x <= mid) ans = query(lson,l,mid,x,y,arr);
    if(mid <  y) ans += query(rson,mid+1,r,x,y,arr);
    return ans;
}

int_t arr[maxn],forHash[maxn] = {1};

int main() {
    int_t n = read();
    for(int_t i=1;i<=n;i++) arr[i] = read();
    for(int_t i=1;i<=n;i++) forHash[i] = forHash[i-1] * mod;
    for(int_t i=1;i<=n;i++){
        int_t len = min(arr[i] - 1,n - arr[i]),l = arr[i] - len,r = n - arr[i] - len + 1;
        int_t x = query(1,1,n,l,arr[i], seg1), y = query(1,1,n,r,n - arr[i] + 1,seg2);
        if(l < r) x *= forHash[r - l]; else y *= forHash[l - r];
        if(x != y) {cout<<"YES"; return 0;}
        modify(1,1,n,arr[i],forHash[arr[i]],seg1);
        modify(1,1,n,n - arr[i] + 1,forHash[n - arr[i] + 1],seg2);
    }
    cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
#define next Next
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
#define ll unsigned long long
const int N=1e6+5;
ll t[N*4][2],bin[N];
int n,a[N],flag;
void change(int x,int l,int r,int p)
{
    if(l==r)
    {
        t[x][0]=t[x][1]=233;
        return;
    }
    int mid=l+r>>1;
    if(p<=mid)change(x<<1,l,mid,p);
    else change(x<<1|1,mid+1,r,p);
    t[x][0]=t[x<<1][0]*bin[r-mid]+t[x<<1|1][0];
    t[x][1]=t[x<<1|1][1]*bin[mid-l+1]+t[x<<1][1];
}
ll ask(int x,int L,int R,int l,int r,int d)
{
    if(L==l&&R==r)return t[x][d];
    int mid=L+R>>1;
    if(r<=mid)return ask(x<<1,L,mid,l,r,d);
    else if(l>mid)return ask(x<<1|1,mid+1,R,l,r,d);
    else if(d==0) return ask(x<<1,L,mid,l,mid,d)*bin[r-mid]+ask(x<<1|1,mid+1,R,mid+1,r,d);
    else if(d==1) return ask(x<<1|1,mid+1,R,mid+1,r,d)*bin[mid-l+1]+ask(x<<1,L,mid,l,mid,d);
}
void solve(int x)
{
    int L=min(x-1,n-x);
    change(1,1,n,x);
    if(x==1||x==n)return;
    ll ls=ask(1,1,n,x-L,x-1,0);
    ll rs=ask(1,1,n,x+1,x+L,1);
    if(ls!=rs)flag=1;
}
int main()
{
    bin[0]=1;for(int i=1;i<=300000;i++)bin[i]=bin[i-1]*233;
    int T=1;
    while(T--)
    {
        //memset(t,0,sizeof(t));
        flag=0;n=read();
        for(int i=1;i<=n;i++)
        {
            int x=read();
            if(!flag)solve(x);
        }
        if(flag)puts("YES");
		else puts("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define next Next
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
#define ll unsigned long long
const int N=1e6+5;
ll t[N*4][2],bin[N];
int n,a[N],flag;
void change(int x,int l,int r,int p)
{
    if(l==r)
    {
        t[x][0]=t[x][1]=233;
        return;
    }
    int mid=l+r>>1;
    if(p<=mid)change(x<<1,l,mid,p);
    else change(x<<1|1,mid+1,r,p);
    t[x][0]=t[x<<1][0]*bin[r-mid]+t[x<<1|1][0];
    t[x][1]=t[x<<1|1][1]*bin[mid-l+1]+t[x<<1][1];
}
ll ask(int x,int L,int R,int l,int r,int d)
{
    if(L==l&&R==r)return t[x][d];
    int mid=L+R>>1;
    if(r<=mid)return ask(x<<1,L,mid,l,r,d);
    else if(l>mid)return ask(x<<1|1,mid+1,R,l,r,d);
    else if(d==0) return ask(x<<1,L,mid,l,mid,d)*bin[r-mid]+ask(x<<1|1,mid+1,R,mid+1,r,d);
    else if(d==1) return ask(x<<1|1,mid+1,R,mid+1,r,d)*bin[mid-l+1]+ask(x<<1,L,mid,l,mid,d);
}
void solve(int x)
{
    int L=min(x-1,n-x);
    change(1,1,n,x);
    if(x==1||x==n)return;
    ll ls=ask(1,1,n,x-L,x-1,0);
    ll rs=ask(1,1,n,x+1,x+L,1);
    if(ls!=rs)flag=1;
}
int main()
{
    bin[0]=1;for(int i=1;i<=300000;i++)bin[i]=bin[i-1]*233;
    int T=1;
    while(T--)
    {
        memset(t,0,sizeof(t));
        flag=0;n=read();
        for(int i=1;i<=n;i++)
        {
            int x=read();
            if(!flag)solve(x);
        }
        if(flag)puts("YES");
		else puts("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define next Next
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
#define ll unsigned long long
#define N 300005
ll t[N][2],bin[N];
int n,a[N],flag;
void change(int x,int l,int r,int p)
{
    if(l==r)
    {
        t[x][0]=t[x][1]=233;
        return;
    }
    int mid=l+r>>1;
    if(p<=mid)change(x<<1,l,mid,p);
    else change(x<<1|1,mid+1,r,p);
    t[x][0]=t[x<<1][0]*bin[r-mid]+t[x<<1|1][0];
    t[x][1]=t[x<<1|1][1]*bin[mid-l+1]+t[x<<1][1];
}
ll ask(int x,int L,int R,int l,int r,int d)
{
    if(L==l&&R==r)return t[x][d];
    int mid=L+R>>1;
    if(r<=mid)return ask(x<<1,L,mid,l,r,d);
    else if(l>mid)return ask(x<<1|1,mid+1,R,l,r,d);
    else if(d==0) return ask(x<<1,L,mid,l,mid,d)*bin[r-mid]+ask(x<<1|1,mid+1,R,mid+1,r,d);
    else if(d==1) return ask(x<<1|1,mid+1,R,mid+1,r,d)*bin[mid-l+1]+ask(x<<1,L,mid,l,mid,d);
}
void solve(int x)
{
    int L=min(x-1,n-x);
    change(1,1,n,x);
    if(x==1||x==n)return;
    ll ls=ask(1,1,n,x-L,x-1,0);
    ll rs=ask(1,1,n,x+1,x+L,1);
    if(ls!=rs)flag=1;
}
int main()
{
    bin[0]=1;for(int i=1;i<=300000;i++)bin[i]=bin[i-1]*233;
    int T=1;
    while(T--)
    {
        memset(t,0,sizeof(t));
        flag=0;n=read();
        for(int i=1;i<=n;i++)
        {
            int x=read();
            if(!flag)solve(x);
        }
        if(flag)puts("YES");
		else puts("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define next Next
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
#define ll unsigned long long
#define N 1e6+5
ll t[N][2],bin[N];
int n,a[N],flag;
void change(int x,int l,int r,int p)
{
    if(l==r)
    {
        t[x][0]=t[x][1]=233;
        return;
    }
    int mid=l+r>>1;
    if(p<=mid)change(x<<1,l,mid,p);
    else change(x<<1|1,mid+1,r,p);
    t[x][0]=t[x<<1][0]*bin[r-mid]+t[x<<1|1][0];
    t[x][1]=t[x<<1|1][1]*bin[mid-l+1]+t[x<<1][1];
}
ll ask(int x,int L,int R,int l,int r,int d)
{
    if(L==l&&R==r)return t[x][d];
    int mid=L+R>>1;
    if(r<=mid)return ask(x<<1,L,mid,l,r,d);
    else if(l>mid)return ask(x<<1|1,mid+1,R,l,r,d);
    else if(d==0) return ask(x<<1,L,mid,l,mid,d)*bin[r-mid]+ask(x<<1|1,mid+1,R,mid+1,r,d);
    else if(d==1) return ask(x<<1|1,mid+1,R,mid+1,r,d)*bin[mid-l+1]+ask(x<<1,L,mid,l,mid,d);
}
void solve(int x)
{
    int L=min(x-1,n-x);
    change(1,1,n,x);
    if(x==1||x==n)return;
    ll ls=ask(1,1,n,x-L,x-1,0);
    ll rs=ask(1,1,n,x+1,x+L,1);
    if(ls!=rs)flag=1;
}
int main()
{
    bin[0]=1;for(int i=1;i<=300000;i++)bin[i]=bin[i-1]*233;
    int T=1;
    while(T--)
    {
        memset(t,0,sizeof(t));
        flag=0;n=read();
        for(int i=1;i<=n;i++)
        {
            int x=read();
            if(!flag)solve(x);
        }
        if(flag)puts("YES");
		else puts("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define next Next
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
#define ll unsigned long long
const int N=1e6+5;
ll t[N][2],bin[N];
int n,a[N],flag;
void change(int x,int l,int r,int p)
{
    if(l==r)
    {
        t[x][0]=t[x][1]=233;
        return;
    }
    int mid=l+r>>1;
    if(p<=mid)change(x<<1,l,mid,p);
    else change(x<<1|1,mid+1,r,p);
    t[x][0]=t[x<<1][0]*bin[r-mid]+t[x<<1|1][0];
    t[x][1]=t[x<<1|1][1]*bin[mid-l+1]+t[x<<1][1];
}
ll ask(int x,int L,int R,int l,int r,int d)
{
    if(L==l&&R==r)return t[x][d];
    int mid=L+R>>1;
    if(r<=mid)return ask(x<<1,L,mid,l,r,d);
    else if(l>mid)return ask(x<<1|1,mid+1,R,l,r,d);
    else if(d==0) return ask(x<<1,L,mid,l,mid,d)*bin[r-mid]+ask(x<<1|1,mid+1,R,mid+1,r,d);
    else if(d==1) return ask(x<<1|1,mid+1,R,mid+1,r,d)*bin[mid-l+1]+ask(x<<1,L,mid,l,mid,d);
}
void solve(int x)
{
    int L=min(x-1,n-x);
    change(1,1,n,x);
    if(x==1||x==n)return;
    ll ls=ask(1,1,n,x-L,x-1,0);
    ll rs=ask(1,1,n,x+1,x+L,1);
    if(ls!=rs)flag=1;
}
int main()
{
    bin[0]=1;for(int i=1;i<=300000;i++)bin[i]=bin[i-1]*233;
    int T=1;
    while(T--)
    {
        memset(t,0,sizeof(t));
        flag=0;n=read();
        for(int i=1;i<=n;i++)
        {
            int x=read();
            if(!flag)solve(x);
        }
        if(flag)puts("YES");
		else puts("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
#define Mod 19260817
#define Maxn 300005
using namespace std;
inline void read(int &x)
{
	int f=1;x=0;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=(x<<3)+(x<<1)+(ch&15);ch=getchar();}
	x*=f;
}
int n,fac[Maxn];
struct Seg_Tree
{
	int sum[Maxn<<2][2];
	inline int get(int root,int l,int r,int ql,int qr,int opt)
	{
		if (ql==l&&qr==r) {return sum[root][opt]%Mod;}
		int mid=l+r>>1;
		if (qr<=mid) return get(root<<1,l,mid,ql,qr,opt)%Mod;
		if (ql>mid) return get(root<<1|1,mid+1,r,ql,qr,opt)%Mod;
		if (ql<=mid&&mid<qr)
		{
			if (opt==0) return (get(root<<1,l,mid,ql,mid,opt)+get(root<<1|1,mid+1,r,mid+1,qr,opt)*(qr-mid)%Mod)%Mod;
			else(get(root<<1,l,mid,ql,mid,opt)*(mid-ql+1)%Mod+get(root<<1|1,mid+1,r,mid+1,qr,opt))%Mod;
		}
	}
	inline void update(int root,int l,int r,int wz,int x)
	{
		if (l==r) {sum[root][0]=sum[root][1]=x;return;}
		int mid=l+r>>1;
		if (wz<=mid) update(root<<1,l,mid,wz,x);
		else update(root<<1|1,mid+1,r,wz,x);
		sum[root][0]=(sum[root<<1][0]+sum[root<<1|1][0]*fac[r-mid]%Mod)%Mod;
		sum[root][1]=(sum[root<<1][1]*fac[mid-l+1]%Mod+sum[root<<1|1][1]%Mod)%Mod;
	}
}T;
int main()
{
	read(n);
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=((fac[i-1]<<3)+(fac[i-1]<<1))%Mod;
	for (int a,i=1;i<=n;i++)
	{
		cin>>a;
		if (a==1||a==n) {T.update(1,1,n,a,1);continue;}
		if (n-a<=a-1){if (T.get(1,1,n,a+1,n,0)!=T.get(1,1,n,2*a-n,a-1,1)) {puts("YES");return 0;}}
		else{if (T.get(1,1,n,1,a-1,0)!=T.get(1,1,n,a+1,2*a-1,1)) {puts("YES");return 0;}}
		T.update(1,1,n,a,1);
	}
	puts("NO");
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<vector>
using namespace std;
int n,x;
bool p[300005];
inline int read()
{
	int x=0,y=1;char z=getchar();
	while(z<'0'||z>'9'){if(z=='-')y=-1;z=getchar();}
	while(z>='0'&&z<='9'){x=x*10+z-'0';z=getchar();}
	return x*y;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		x=read();
		for(int j=1;j<=min(x-1,n-x);j++)
			if(p[x-j]&&!p[x+j])
				{printf("YES\n");return 0;}
		p[x]=1;
	}
	printf("NO\n");
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<vector>
using namespace std;
int n,x,a[300005];
bool p[300005];
inline int read()
{
	int x=0,y=1;char z=getchar();
	while(z<'0'||z>'9'){if(z=='-')y=-1;z=getchar();}
	while(z>='0'&&z<='9'){x=x*10+z-'0';z=getchar();}
	return x*y;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=n;i>=1;i--)
	{
		x=a[i];
		for(int j=1;j<=min(x-1,n-x);j++)
			if(p[x-j]&&!p[x+j])
				{printf("YES\n");return 0;}
		p[x]=1;
	}
	printf("NO\n");
	return 0;
}


//Code by : Y-k-y
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#define ll long long
const int N=600010;
#define lowbit(x) x&(-x)
using namespace std;
inline int rnd(){
	int res=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){res=res*10+ch-'0';ch=getchar();}
	return res*f;
}
inline void wr(int x){
	if(x<0){putchar('-');x=-x;}if(x>9) wr(x/10);putchar(x%10+'0');
}
int n,a[N],t[N],l[N],r[N];
inline void add(int x,int y){
	while(x<=n){
		t[x]+=y;
		x+=lowbit(x);
	}
}
inline int ask(int x){
	int sum=0;
	while(x){
		sum+=t[x];
		x-=lowbit(x);
	}
	return sum;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)a[i]=rnd();
	for(int i=1;i<=n;i++){
		if(2*a[i]-1<=n)l[i]=ask(2*a[i]-1);
		else l[i]=ask(n)-ask(2*a[i]-n-1);
		add(a[i],a[i]);
	}
	memset(t,0,sizeof(t));
	for(int i=n;i>=1;i--){
		if(2*a[i]-1<=n)r[i]=ask(2*a[i]-1);
		else r[i]=ask(n)-ask(2*a[i]-n-1);
		add(a[i],a[i]);
	}
	for(int i=2;i<n;i++){
		if(l[i]%(2*a[i])!=0&&r[i]%(2*a[i])!=0&&l[i]!=0&&r[i]!=0){
			puts("YES");return 0;
		}
	}
	puts("NO");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define re register

inline long long read()
{
    char ch = getchar(); long long x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
int tong [1000001];	//表示每一个点出现的位置
int a [1000001];
int main () {
		int n = read ();
		//直接枚举
		for (re int i = 1;i <= n;++ i) {
			a [i] = read ();
			tong [a [i]] = i;
		}
		bool ok = false;
		//枚举公差
		for (int d = 1;d <= n / 2;++ d) {
			//枚举首项
			for (int t = 1;t + 2 * d <= n;++ t) {
				if (t + d + d <= n && tong [t + d] > tong [t] && tong [t + d + d] > tong [t + d]) {
					ok = true;
					break ;
				}
				if (t + d + d <= n && tong [t + d] > tong [t + d + d] && tong [t] > tong [t + d]) {
					ok = true;
					break;
				}
			}
			if (ok) {
				break ;
			}
		}
		if (ok) {
			printf ("YES\n");
		}else {
			printf ("NO\n");
		}
	return 0;
}


#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int Mo = 1e9 + 7;
const int MAXN = 3e5 + 5;
struct Node {
    LL Num;
    int len;
    Node (LL num, int Len) {Num = num, len = Len;}
    Node (){}
} Tr[2][MAXN * 4];
int N;
LL Pow[MAXN];
Node Merge(Node L, Node R) {
    Node New;
    New.len = L.len + R.len;
    New.Num = (1ll * L.Num * Pow[R.len] + R.Num) % Mo;
    return New;
}
void Build(int Ord, int Now, int l, int r) {
    Tr[Ord][Now].len = r - l + 1;
    if (l == r) return;
    int Mid = (l + r) >> 1;
    Build(Ord, Now * 2, l, Mid), Build(Ord, Now * 2 + 1, Mid + 1, r);
}
void Modify(int Ord, int Now, int l, int r, int Side) {
    if (l == r) {
        Tr[Ord][Now].Num = 1;
        return;
    }
    int Mid = (l + r) >> 1;
    if (Side <= Mid) Modify(Ord, Now * 2, l, Mid, Side); else
        Modify(Ord, Now * 2 + 1, Mid + 1, r, Side);
    if (!Ord) Tr[Ord][Now] = Merge(Tr[Ord][Now * 2], Tr[Ord][Now * 2 + 1]); else
        Tr[Ord][Now] = Merge(Tr[Ord][Now * 2 + 1], Tr[Ord][Now * 2]);
}
Node Query(int Ord, int Now, int l, int r, int lx, int rx) {
    if (lx > rx) return Node(0, 0);
    if (l == lx && r == rx) return Tr[Ord][Now];
    int Mid = (l + r) >> 1;
    if (rx <= Mid) return Query(Ord, Now * 2, l, Mid, lx, rx); else
    if (lx > Mid) return Query(Ord, Now * 2 + 1, Mid + 1, r, lx, rx); else {
        Node L = Query(Ord, Now * 2, l, Mid, lx, Mid);
        Node R = Query(Ord, Now * 2 + 1, Mid + 1, r, Mid + 1, rx);
        if (!Ord) return Merge(L, R); else
            return Merge(R, L);
    }
}
int main() {
    scanf("%d", &N);
    Pow[0] = 1;
    Build(0, 1, 1, N), Build(1, 1, 1, N);
    for (int i = 1; i <= N; i ++) Pow[i] = 1ll * Pow[i - 1] * 2 % Mo;
    for (int i = 1; i <= N; i ++) {
        int Now;
        scanf("%d", &Now);
        int len = min(Now - 1, N - Now);
        if (Query(0, 1, 1, N, Now - len, Now - 1).Num != Query(1, 1, 1, N, Now + 1, Now + len).Num) {
            printf("YES\n");
            return 0;
        }
        Modify(0, 1, 1, N, Now);
        Modify(1, 1, 1, N, Now);
    }
    printf("NO\n");
    return 0;
}