#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

def main():
    number = int(input())
    list2 = [int(i) for i in input().split()]
    if(list2.count(min(list2))>1):
        print("Still Rozdil")
    else:
        print(list2.index(min(list2))+1)

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


number = int(input())
list2 = [int(i) for i in input().split()]
if(len(set(list2))==number):
    print(list2.index(min(list2))+1)
else:
    print("Still Rozdil")


n = int(input())
act = list(map(int, input().split()))
cop = act.copy()
cop.sort()
if n == 1:
    print(1)
else:
    if cop[0]!=cop[1]:
        for i in range(n):
            if act[i] == cop[0]:
                print(i+1)
    else:
        print('Still Rozdil')


n = int(input())
act = list(map(int, input().split()))
cop = act.copy()
cop.sort()
if cop[0]!=cop[1]:
    for i in range(n):
        if act[i] == cop[0]:
            print(i+1)
else:
    print('Still Rozdil')


var count = 0;
var last = '9';
var w = -1;
var pos = 1;

var N = parseInt(readline());
var a = readline().split(' ');

for(var i = 0; i < N; i++) {
	if(last === a[i]) {
		count++;
	} else {
		if(w < 0) {
			w = count;
		} else if(w !== count) {
			pos = 0;
		}
		count = 0;
	}
	last = a[i];
}

if(w !== count) {
	pos = 0;
}

if(pos == 0) {
	print("NO");
} else {
	print("YES");
}


var count = 0;
var last = '9';
var w = -1;
var pos = 1;

var N = parseInt(readline());
var a = readline().split(' ');

for(var i = 0; i < N; i++) {
	if(last === '9') {

	} else if(last === a[i]) {
		count++;
	} else {
		if(w < 0) {
			w = count;
		} else if(w !== count) {
			pos = 0;
		}
		count = 0;
	}
	last = a[i];
}

if(w !== count) {
	pos = 0;
}

if(pos == 0) {
	print("NO");
} else {
	print("YES");
}


var count = 0;
var last = "9";
var w = -1;
var pos = 1;

var N = parseInt(readLine());
var a = readLine().split(' ');

for(var i = 0; i < N; i++) {
	if(last === a[i]) {
		count++;
	} else {
		if(w < 0) {
			w = count;
		} else if(w !== count) {
			pos = 0;
		}
		count = 0;
	}
	last = a[i];
}

if(w !== count) {
	pos = 0;
}

if(pos == 0) {
	print("NO");
} else {
	print("YES");
}


var count = 0;
var last = '9';
var w = -1;
var pos = 1;

var N = parseInt(readline());
var a = readline().split(' ');

for(var i = 0; i < N; i++) {
	if(last === '9') {

	} else if(last === a[i]) {
		count++;
	} else {
		if(w < 0) {
			w = count;
		} else if(w !== count) {
			pos = 0;
		}
		count = 0;
	}
	last = a[i];
}

if(w !== count && w >= 0) {
	pos = 0;
}

if(pos == 0) {
	print("NO");
} else {
	print("YES");
}


isOk = function(a, n, k){
    var black = a[0];
    for(var i = 1; i < n; i++)
    if((Math.floor(i / k) % 2 === 0 && a[i] !== black) || (Math.floor(i / k) % 2 === 1 && a[i] === black)){
        return false;
    }
    return true;
};

n = parseInt(readline());
a = readline().split(' ');
res = false;
for(var i = 1; i * i <= n; i++)
if(n % i === 0){
    if(isOk(a, n, i) || isOk(a, n, Math.floor(n/i)))
        res = true;
}
if(res)
    print("YES");
else
    print("NO");


var line = readline().split(' ');
var n = parseInt(line[0]);

line = readline().split(' ');

var pre = -1;
var len = 0;
var nowlen = 0;
for(var i = 0;i < n;i++){
    var now = parseInt(line[i]);
    if(pre == -1 || now == pre){
        pre = now;
        nowlen++;
    }
    else{
        if(!len) len = nowlen;
        else if(len != nowlen){
            //:wqprint('NO');
            break;
        }
        pre = now;
        nowlen = 1;
    }
}
if( len && len != nowlen)
    print('NO');
else
    print('YES');


var line = readline().split(' ');
var n = parseInt(line[0]);

line = readline().split(' ');

var pre = -1;
var len = 0;
var nowlen = 0;
for(var i = 0;i < n;i++){
    var now = parseInt(line[i]);
    if(pre == -1 || now == pre){
        pre = now;
        nowlen++;
    }
    else{
        if(!len) len = nowlen;
        else if(len != nowlen){
            //:wqprint('NO');
            break;
        }
        pre = now;
        nowlen = 1;
    }
}
if(!len || len != nowlen)
    print('NO');
else
    print('YES');


var line = readline().split(' ');
var n = parseInt(line[0]);

line = readline().split(' ');

var pre = -1;
var len = 0;
var nowlen = 0;
for(var i = 0;i < n;i++){
    var now = parseInt(line[i]);
    if(pre == -1 || now == pre){
        pre = now;
        nowlen++;
    }
    else{
        if(!len) len = nowlen;
        else if(len != nowlen){
            //:wqprint('NO');
            break;
        }
        pre = now;
        nowlen = 1;
    }
}
if(len != nowlen)
    print('NO');
else
    print('YES');


var n=readline();
var w = readline().split(' ').map(function(x) { return parseInt(x);});
var cnt=0,y=-1;
var last=-1,ans=1;
for(var i=0;i<n;i++){
    var x = w[i];
    if(last===-1)
        last=x;
    if(x===last)
        cnt++;
    else{
        if(y===-1)
            y=cnt;
        else{
            if(cnt!==y)
                ans=0;
        }
        cnt=1;
        last=x;
    }
}
if(ans===0)
    print("NO");
else if(y!==-1&&cnt!==y)
    print("NO");
else
    print("YES");


var n = readline();
n = parseInt(n);
var s = readline().split(" ");
var p = 0;
var arr = new Array();
for (var i = 0; i < s.length; i++) {
    if (i == s.length || s[i] != s[i + 1]) {
        arr.push(i - p + 1);
        p = i + 1;
    }
}
var flag = true;
for (var i = 1; i < arr.length; i++) {
    if (arr[i] != arr[i - 1]) {
        flag = false;
        break;
    }
}
if (flag) print("YES");
else print("NO");


var n = readline();
var numbers = readline().split(" ").map(function(x) { return parseInt(x); });

var white = 0, blk = 0;
var fw = 0, fb = 0;
var fixW=0, fixB=0;
var flg = 1;
for(var i=0; i<n; i++)
{
    if(numbers[i] == 0)
    {
    	if(blk)
        {
            if(fb == 0) fixB = blk;
            else if(blk != fixB) flg = 0;
            fb = 1;
            blk = 0;
        }

        white+=1;
    }
    else
    {
        if(white)
        {
            if(fw == 0) fixW = white;
            else if(white != fixW) flg = 0;
            fw = 1;
            white = 0;
        }

        blk += 1;
    }
}

if(white)
{
    if(fw == 0) fixW = white;
    else if(white != fixW) flg = 0;
    fw = 1;
    white = 0;
}

if(blk)
{
    if(fb == 0) fixB = blk;
    else if(blk != fixB) flg = 0;
    fb = 1;
    blk = 0;
}
if(fixB ==0) fixB = fixW;
if(fixW ==0) fixW = fixB;
if(flg && fixW == fixB) print("YES\n");
else print("NO\n");


var n = readline();
var numbers = readline().split(" ").map(function(x) { return parseInt(x); });

var white = 0, blk = 0;
var fw = 0, fb = 0;
var fixW, fixB;
var flg = 1;
for(var i=0; i<n; i++)
{
    if(numbers[i] == 0)
    {
        if(fb == 0) fixB = blk;
        else if(blk != fixB) flg = 0;
        fb = 1;

        white+=1;
    }
    else
    {
        if(fw == 0) fixW = white;
        else if(white != fixW) flg = 0;
        fw = 1;
        white = 0;

        blk += 1;
    }
}

if(flg) print("YES\n");
else print("NO\n");


var n = readline();
var arr = readline().split(' ');

var lng = 1;
var lng_base;
var isFirst = true;
var fail = false;
for (var i = 1; i < n; i++ ) {
    var k = arr[i];
    last = arr[i-1];
    if (k == last) {
        lng++;

    } else
        if (isFirst) {
            lng_base = lng;
            lng = 1;
            isFirst = false;
        } else if (lng != lng_base) {
            fail = true;

            break;
        } else {
            lng = 1;
        }

}

if (lng != lng_base) {fail = true}
if (lng == n) {fail = false}
if (fail) {
    print('NO');
} else print('YES');


function solve() {
    var n = readline()
    var s = readline().split(' ');

    var sz = 0;
    while (s[sz] === s[0]) sz++;

    if (s.length % sz)
        return false;

    for(var i=0;i<s.length;i++) {
        var m = i % (2 * sz);
        if(m < sz) {
            if(s[i] != s[0]) return false;
        }
        else {
            if(s[i] == s[0]) return false;
        }
    }

    return true;
}

print(solve() ? "YES" : "NO");


readline();
var a = readline().split(' ').map(Number);

var last = 0;
var good = 1;
var cur = -1;
for (var i = 1; i < a.length; i++) {
    if (a[i] != a[i - 1]) {
        var curl = i - last;
        if (cur == -1) {
            cur = curl;
        } else if (cur != curl) {
            good = 0;
            cur = curl;
        }
        last = i;
    }
}

var curl = a.length - last;
if (cur != -1 && curl != cur) {
    good = 0;
}

if (good == 0) {
    print("NO");
} else {
    print("YES");
}


var n;
var temp,last;
var curL = 1,L = -1;
var flag = false;

    var n = parseInt(readline().split(' ')[0]);
    var a = readline().split(' ').map(Number);
    for (var i = 0;i < n;i++){
        var temp = a[i];
        if (i == 0){
            last = temp;
            continue;
        }
        if (temp == last) curL++;
        else {
        if (curL!=L&&L!=-1){
            print("NO");
            flag = true;
            break;
        }
        L = curL;
        curL = 1;
        }
        last = temp;
    }
    if (!flag && curL!=0 && curL!=L && L!=-1) {
        print("NO");
    } else if (!flag)
    print("YES");


var N = readline().split(' ');
var n = parseInt(N[0]);
a = readline().split(' ');
var cycl = n;
var hopaayega = true;
for(var i=0;i<n;i++){
    var curr = parseInt(a[i]);
    if(a[i] != a[0]){
        cycl = i;
        break;
    }
}
if(n%cycl) {
    print('NO');
}
else {
    for(var i=1;i<n-1;i++){
        var curr = parseInt(a[i]);
        var cycl_t = i%(2*cycl)
        if(cycl_t<cycl){
            if(curr != a[0]){
                hopaayega = false;
                break;
            }
        }
        else{
            if(curr == a[0]){
                hopaayega = false;
                break;
            }
        }
    }

    if(hopaayega)
        print('YES');
    else
        print('NO');
}


var N = readline().split(' ');
var n = parseInt(N[0]);
a = readline().split(' ');
var cycl = 0;
var hopaayega = true;
//for(var i=0;i<n;i++){
//    var curr = parseInt(a[i]);
//    if(a[i] != a[0]){
//        cycl = i;
//        break;
//    }
//}
while(a[cycl] === a[0]) cycl ++;
if(n%cycl) {
    print('NO');
}
else {
    for(var i=1;i<n-1;i++){
        var curr = parseInt(a[i]);
        var cycl_t = i%(2*cycl)
        if(cycl_t<cycl){
            if(curr != a[0]){
                hopaayega = false;
                break;
            }
        }
        else{
            if(curr == a[0]){
                hopaayega = false;
                break;
            }
        }
    }

    if(hopaayega)
        print('YES');
    else
        print('NO');
}


var N = readline().split(' ');
var n = parseInt(N[0]);
a = readline().split(' ');
var cycl = 0;
var hopaayega = true;
//for(var i=0;i<n;i++){
//    var curr = parseInt(a[i]);
//    if(a[i] != a[0]){
//        cycl = i;
//        break;
//    }
//}
while(a[cycl] === a[0]) cycl ++;
if(n%cycl) {
    print('NO');
}
else {
    for(var i=0;i<n;i++){
        var curr = parseInt(a[i]);
        var cycl_t = i%(2*cycl)
        if(cycl_t<cycl){
            if(curr != a[0]){
                hopaayega = false;
                break;
            }
        }
        else{
            if(curr == a[0]){
                hopaayega = false;
                break;
            }
        }
    }

    if(hopaayega)
        print('YES');
    else
        print('NO');
}


var N = readline().split(' ');
var n = parseInt(N[0]);
a = readline().split(' ');
var cycl = n;
var hopaayega = true;
for(var i=0;i<n;i++){
    var curr = parseInt(a[i]);
    if(a[i] != a[0]){
        cycl = i;
        break;
    }
}
if(n%cycl) {
    print('NO');
}
else {
    for(var i=1;i<n-1;i++){
        var curr = parseInt(a[i]);
        var prev = parseInt(a[i-1]);
        if(i%cycl){
            if(curr != prev){
                hopaayega = false;
                break;
            }
        }
        else{
            if(curr == prev){
                hopaayega = false;
                break;
            }
        }
    }

    if(hopaayega)
        print('YES');
    else
        print('NO');
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

typedef unsigned long long ull;

int main(void) {
	int n;
	int *stripe;
	int *width;
	int i, b, w, j, c;
	b = w = 0;
	scanf("%d", &n);
	stripe = (int *)malloc(n * sizeof(int));
	width = (int *)calloc(n, sizeof(int));
	for(i = 0; i < n; i++) {
		scanf("%d", stripe + i);
		w += stripe[i];
		b += !stripe[i];
	}
	if (!w || !b) {
		printf("YES\n");
		return 0;
	}
	w = b = j = 0;
	c = stripe[0];
	for(i = 0; i < n; i++) {
		if(stripe[i] == c) {
			width[j]++;
		} else {
			c = stripe[i];
			j++;
			width[j]++;
		}
	}
	for(i = 0; i < j; i++) {
		if(width[i] != width[i + 1]) {
			printf("NO\n");
			free(stripe);
			free(width);
			return 0;
		}
	}
	printf("YES\n");
	free(stripe);
	free(width);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    set <int> s;
    int n,c=1;
    bool a,temp;
    cin>>n;
    cin>>a;
    temp=a;
    for(int i=0;i<n-1;i++)
    {
        cin>>a;
        if(temp!=a){temp=a,s.insert(c),c=1;}
        else c++;
    }
    s.insert(c);
    if(s.size()==1)cout<<"YES";
    else
	cout<<"NO";
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long intt;

int main()
{
  int n;
  cin>>n;
  int a[n];
  int i;
  int sum1=1,sum2=0,ok=0;
  cin>>a[0];
  bool f=true;
  bool op=true;
  for(i=1;i<n;i++)
  {
      cin>>a[i];
      if(a[i]==a[i-1])
      {
          sum1++;
      }
      else
      {
          f=!f;
        if(sum1!=sum2&&!op)
        {
            cout<<"NO";
            return 0;
        }
        if(op)
        {
        sum2=sum1;
        op=false;
        }
        sum1=1;
      }
  }
  if(f&&(sum1==sum2)||sum2==0)
cout<<"YES";
else
    cout<<"NO";
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long intt;

int main()
{
  int n;
  cin>>n;
  int a[n];
  int i;
  int sum1=1,sum2=0,ok=0;
  cin>>a[0];
  bool f=true;
  bool op=true;
  for(i=1;i<n;i++)
  {
      cin>>a[i];
      if(a[i]==a[i-1])
          sum1++;

      else
      {
        if(sum1!=sum2&&!op)
        {
            cout<<"NO";
            return 0;
        }
        if(op)
        {
        sum2=sum1;
        op=false;
        }
        sum1=1;
      }
  }
  if((sum1==sum2)||sum2==0)
cout<<"YES";
else
    cout<<"NO";
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long intt;

int main()
{
  int n;
  cin>>n;
  int a[n];
  int i;
  int sum1=0,sum2=0,ok=0;
  cin>>a[0];
  bool f=true;
  bool op=true;
  for(i=1;i<n;i++)
  {
      cin>>a[i];
      if(a[i]==a[i-1])
      {
          sum1++;
      }
      else
      {
          f=!f;
        if(sum1!=sum2&&!op)
        {
            cout<<"NO";
            return 0;
        }
        if(op)
        {
        sum2=sum1;
        op=false;
        }
        sum1=0;
      }
  }
  if(f&&(sum1==sum2)||sum2==0)
cout<<"YES";
else
    cout<<"NO";
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long intt;

int main()
{
  int n;
  cin>>n;
  int a[n];
  int i;
  int sum1=0,sum2=0,ok=0;
  cin>>a[0];
  bool f=true;
  bool op=true;
  for(i=1;i<n;i++)
  {
      cin>>a[i];
      if(a[i]==a[i-1])
      {
          sum1++;
      }
      else
      {
          f=!f;
        if(sum1!=sum2&&!op)
        {
            cout<<"NO";
            return 0;
        }
        if(op)
        {
        sum2=sum1;
        op=false;
        }
        sum1=0;
      }
  }
  if(f)
cout<<"YES";
else
    cout<<"NO";
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n,a[100010],b[100010];
	cin>>n;
	for(int i=1; i<=n; i++)cin>>a[i];
	int cmp=a[1],ans=1,k=1;
	for(int i=2; i<=n; i++)
		if(a[i]==cmp)ans++;
		else b[k++]=ans,cmp=a[i],ans=1;
		b[k]=ans;
	sort(b+1,b+1+k);
	//for(int i=1;i<=k;i++)cout<<b[i]<<endl;
	if(b[1]==b[k])cout<<"YES\n";
	else cout<<"NO\n";
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,b=0,w=0,r1=0,r2=0;
	std::vector<int> v;
	cin>>n;
	int r[n+1];
	bool res=true;
	for (int i = 0; i < n; ++i){
		cin>>r[i];

	}
	if(r[n-1]==1)
		r[n]=0;
	else
		r[n]=1;
	for (int i = 0; i <= n; ++i){
		if(r[i]==0){
			b++;
			if(b==1)
				v.push_back(w);
			w=0;
		}
		else{
			if(r[i]==1){
				w++;
				if(w==1)
					v.push_back(b);
				b=0;
			}
		}
	}
	/*for (int i = 0; i < v.size(); ++i){
		cout<<v[i]<<endl;
	}*/
	for (int i = 1; i < v.size(); ++i){
		if(v[i]!=v[i-1]&&v[i]!=0&&v[i-1]!=0)
			res=false;
	}
	if(!res)
		cout<<"NO"<<endl;
	else
		cout<<"YES"<<endl;
//	system("pause");
	return 0;
}


#include<stdio.h>
int a[100005];
int c[100005];
int main()
{
    int n; scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    int j=0;
    c[j]=1;  //printf("xxxxxxxxxxxxxxxx\n");
    int t;
    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
            c[j]++;
        else
        {
            j++;
            c[j]=1;
        }
        t=j;
    }
    int m=0;
    for(int j=1;j<=t;j++)
    {
        //printf("%d\n",c[j]);
        if(c[j]!=c[0]) m=1;
    }
    if(m==0) printf("YES\n");
    if(m==1) printf("NO\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[1000004];
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
    cin>>arr[i];
    int b=0;int w=0; int ans =0; int k= 0; int j=0;
for(int i=0;i<n;i++)
{
   if(arr[i]==arr[i-1]||i==0)
   {
       if(arr[i]==0)
        b++;
       else
        w++;
   }
   else if(arr[i]!=arr[i-1])
   {
       if(b>0){
    ans=b; w=1;b=0;j=i; break;}
    else { ans=w;b=1;w=0;j=i; break;}
   }
   j++;
   ans++;
}

for(int i=j+1;i<n;i++)
{
   if(arr[i]==arr[i-1])
   {
       if(arr[i]==0)
        b++;
       else
        w++;
   }
if(arr[i]!=arr[i-1])
   {
      if(arr[i]==1)
      {
          if(b!=ans)
          {
              k=1; break;
          }
          w=1;b=0;
      }
        if(arr[i]==0)
        {
            if(w!=ans)
            {
                k=1; break;
            }
            b=1;w=0;
        }
   }

}
if(w>0&&w!=ans)
    k=1;
if(b>0&&b!=ans)
    k=1;
if(k==1)
    cout<<"no"<<endl;
else
    cout<<"yes"<<endl;
return 0;
}


#include <stdio.h>
int n, arr[100005], cant=1, x;
bool b1=true;
int main()
{
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        scanf("%d", &arr[i]);
        if(i>0 && arr[i]==arr[i-1])
        {
            cant++;
        }
        else if(i>0)
        {
            //printf("%d\n", cant);
            if(x==0)
            {
                x=cant;
            }
            if(cant!=x)
            {
                b1=false;
            }
            cant=1;
        }
    }
    if(x==0)
    {
        x=cant;
    }
    if(cant!=x)
    {
        b1=false;
    }
    if(b1==false)
    {
        printf("NO");
    }
    else
    {
        printf("YES");
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::cin.clear();

    int n;
    cin>>n;
    int a[n],i;
    bool w(false),b(false);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            b=true;
        }
        else if(a[i]==1)
        {
            w=true;
        }
    }
    int c(1),p[n],j(0);
    if(b==false || w==false)
    {
        cout<<"YES"<<endl;
        return 0;
    }
    else
    {
        for(i=0;i<n-1;i++)
        {
            /*if(i=n-1 && a[i]!=a[i-1])
            {
                p[j]=1;
                j++;
            }*/
            if(a[i]==a[i+1])
            {
                c++;
                if(i==n-2)
                {
                    p[j]=c;
                }
            }
            else if(a[i]!=a[i+1])
            {
                p[j]=c;
                c=1;
                j++;
            }
        }
    }
    /*for(i=0;i<=j;i++)
    {
        cout<<p[i]<<" ";
    }*/
    sort(p,p+j+1);
    if(p[0]==p[j])
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

    std::cin.ignore(32767,'\n');
    std::cin.get();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::cin.clear();

    int n;
    cin>>n;
    int a[n],i;
    bool w(false),b(false);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            b=true;
        }
        else if(a[i]==1)
        {
            w=true;
        }
    }
    int c(1),p[n],j(0);
    if(b==false || w==false)
    {
        cout<<"YES"<<endl;
        return 0;
    }
    else
    {
        for(i=0;i<n-1;i++)
        {
            /*if(i=n-1 && a[i]!=a[i-1])
            {
                p[j]=1;
                j++;
            }*/
            if(a[i]==a[i+1])
            {
                c++;
                if(i==n-2)
                {
                    p[j]=c;
                }
            }
            else if(a[i]!=a[i+1])
            {
                p[j]=c;
                c=1;
                j++;
            }
        }
    }
    for(i=0;i<=j;i++)
    {
        cout<<p[i]<<" ";
    }
    sort(p,p+j+1);
    if(p[0]==p[j])
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

    std::cin.ignore(32767,'\n');
    std::cin.get();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::cin.clear();

    int n;
    cin>>n;
    int a[n],i;
    bool w(false),b(false);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            b=true;
        }
        else if(a[i]==1)
        {
            w=true;
        }
    }
    int c(1),p[n],j(0);
    if(b==false || w==false)
    {
        cout<<"YES"<<endl;
        return 0;
    }
    else
    {
        for(i=0;i<n-1;i++)
        {
            /*if(i=n-1 && a[i]!=a[i-1])
            {
                p[j]=1;
                j++;
            }*/
            if(a[i]==a[i+1])
            {
                c++;
                if(i==n-2)
                {
                    p[j]=c;
                }
            }
            else if(a[i]!=a[i+1])
            {
                p[j]=c;
                c=1;
                j++;
            }
        }
        if(a[n-1]!=a[n-2])
        {
            p[j]=1;

        }
    }
    for(i=0;i<=j;i++)
    {
        cout<<p[i]<<" ";
    }
    sort(p,p+j+1);
    if(p[0]==p[j])
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

    std::cin.ignore(32767,'\n');
    std::cin.get();
    return 0;
}


#include<stdio.h>
#define ll long long int
ll max(ll a,ll b)
{
	if(a>b)
	 return a;
	 return b;
}
int main()
{

  ll n;
  scanf("%I64d",&n);
  ll a[n];
  ll mi=0;
  for(ll i=0;i<n;i++)
  {
  	scanf("%I64d",&a[i]);
  }
  ll zero=0,one=0,flag=2;
  for(ll i=0;i<n;i++)
  {
  	if(a[i]==0&&flag!=1)
  	{
  		zero++;
  		flag=0;
	  }
	  else if(a[i]==1 && flag!=0)
	  {
	  	one++;
	  	flag=1;
	  }
	  else
	   break;
  }
  ll se=max(one,zero);
  //cout<<se<<endl;
  zero=0;one=0;
 ll nf=9;
  for(ll i=0;i<n;i++)
  {
  	if(a[i]==0)
  	{
  		zero++;
  		one=0;
	  }
	  else if(a[i]==1)
	  {
	  	one++;
	  	zero=0;
	  }
	  if(i!=(n-1))
	  {
	  	if(a[i]!=a[i+1])
	  	{
	  		if(zero==0)
	  		{
	  			if(one!=se)
	  			 {
	  			 	nf=1;
	  			 	break;
				   }
			  }
			  if(one==0)
			  {
			  	if(zero!=se)
			  	{
			  		nf=1;
			  		break;
				  }
			  }
		  }
	  }
  }
          if(zero==0)
	  		{
	  			if(one!=se)
	  			 {
	  			 	nf=1;
	  			 	//break;
				   }
			  }

			  if(one==0)
			  {
			  	if(zero!=se)
			  	{
			  		nf=1;
			  		//break;
				  }
			  }

  if(nf==1)
  {
  	printf("NO\n");
  }
  else
   printf("YES\n");
  return 0;
}


#include <iostream>
using namespace std;

int main()
{
	bool nums[100000 + 5];
	int stripes[100000 + 5];
	int n, sum = 0, j = 0, ans = 1;

	cin>>n;

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

	nums[n] = !nums[n-1];

	for(int i = 0; i < n; i++)
	{
		sum++;
		if(nums[i+1] != nums[i])
		{
			stripes[j++] = sum;
			sum = 0;
		}
	}

	for(int i = 0; i < j; i++)
		cout<<stripes[i]<<" ";

	for(int i = 1; i < j; i++)
		if(stripes[i] != stripes[i-1])
			ans = 0;

	if(ans == 1)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	bool nums[100000 + 5];
	int stripes[100000 + 5];
	int n, sum = 0, j = 0, ans = 1;

	cin>>n;

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

	nums[n] = !nums[n-1];

	for(int i = 0; i < n; i++)
	{
		sum++;
		if(nums[i+1] != nums[i])
		{
			stripes[j++] = sum;
			sum = 0;
		}
	}

	for(int i = 1; i < j; i++)
		if(stripes[i] != stripes[i-1])
			ans = 0;

	if(ans == 1)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	bool nums[100000 + 5], stripes[100000 + 5];
	int n, sum = 0, j = 0, ans = 1;

	cin>>n;

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

	nums[n] = !nums[n-1];

	for(int i = 0; i < n; i++)
	{
		sum++;
		if(nums[i+1] != nums[i])
		{
			stripes[j++] = sum;
			sum = 0;
		}
	}

	for(int i = 1; i < j; i++)
		if(stripes[i] != stripes[i-1])
			ans = 0;

	if(ans == 1)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a[n],f,c=0,one,zero;
    for(int i=0; i<n; i++)
        scanf("%d",&a[i]);
    for(int i=0; i<n; i++)
    {
        if(a[i]==1)while(a[i]==1)c++,i++;
        else while(a[i]==0)c++,i++;
        break;
    }
    int ok=0;
    for(int i=0; i<n;)
    {
        zero=one=0;
        if(a[i]==1)
        {
            ok++;
            while(a[i]==1)
            {
                one++;
                i++;
            }
            if(one==c)continue;
            else return printf("NO");
        }
        else
        {
            ok++;
            while(a[i]==0)
            {
                zero++;
                i++;
            }
            if(zero==c)continue;
            else return printf("NO");
        }
    }
    if(ok>=2)
    return printf("YES"),0;
    else return printf("NO"),0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a[n],c=0,one,zero;
    for(int i=0; i<n; i++)
        scanf("%d",&a[i]);
    for(int i=0; i<n; )
    {
        if(a[i]==1)
            while(a[i]==1)
                c++,i++;
        else
            while(a[i]==0)
                c++,i++;
        break;
    }
    int ok=0;
    for(int i=0; i<n;)
    {
        zero=one=0;
        if(a[i]==1)
        {
            ok++;
            while(a[i]==1)
            {
                one++;
                i++;
            }
            if(one==c)
                continue;
            else
                return printf("NO"),0;
        }
        else
        {
            ok++;
            while(a[i]==0)
            {
                zero++;
                i++;
            }
            if(zero==c)
                continue;
            else
                return printf("NO"),0;
        }
    }
    if(ok>=2)
        return printf("YES"),0;
    else
        return printf("NO"),0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a[n],c=0,one,zero;
    for(int i=0; i<n; i++)
        scanf("%d",&a[i]);
    for(int i=0; i<n; )
    {
        if(a[i]==1)
            while(a[i]==1)
                c++,i++;
        else
            while(a[i]==0)
                c++,i++;
        break;
    }
    int ok=0;
    for(int i=0; i<n;)
    {
        zero=one=0;
        if(a[i]==1)
        {
            ok++;
            while(a[i]==1)
            {
                one++;
                i++;
            }
            if(one==c)
                continue;
            else
                return printf("NO"),0;
        }
        else
        {
            ok++;
            while(a[i]==0)
            {
                zero++;
                i++;
            }
            if(zero==c)
                continue;
            else
                return printf("NO"),0;
        }
    }
    if(ok>=1)
        return printf("YES"),0;
    else
        return printf("NO"),0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i;
    int s=1,res,k=0;
	long long n;
	cin >> n;
	long long m[n];
	long long s1[n];
	for(i = 0; i < n; ++i)
	{
	  cin >> m[i];
    }
    res = m[0];
	for(i = 1; i < n; ++i)
	{
		if(m[i] == res)
		++s;
		if(i == n-1)
		{
			s1[k] = s;
			//printf("%d\n",s);
		   	s = 1;
		   	++k;
		   	res = m[i];
		   	break;
		}
		if((m[i]==0 && m[i-1]==1) || (m[i]==1 && m[i-1]==0))
		{
			s1[k] = s;
			//printf("%d\n",s);
		   	s = 1;
		   	++k;
		   	res = m[i];
		}

	}
	for(i = 1; i < k; ++i)
	{
	  if(s1[i] == s1[i-1])
	  continue;
	  else
	  {
	  	cout << "No";
	  	return 0;
	  }
    }
    cout << "Yes";
	  	return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    //kuko_ - ����� ����������
    int i;
    int s=1,res,k=0;
	long long n;
	cin >> n;
	long long m[n];
	long long s1[n];
	for(i = 0; i < n; ++i)
	{
	  cin >> m[i];
    }
    res = m[0];
	for(i = 1; i < n; ++i)
	{
		if(m[i] == res)
		++s;
		if(i == n-1)
		{
			s1[k] = s;
			//printf("%d\n",s);
		   	s = 1;
		   	++k;
		   	res = m[i];
		   	break;
		}
		if((m[i]==0 && m[i-1]==1) || (m[i]==1 && m[i-1]==0))
		{
			s1[k] = s;
			//printf("%d\n",s);
		   	s = 1;
		   	++k;
		   	res = m[i];
		}

	}
	for(i = 1; i < k; ++i)
	{
	  if(s1[i] == s1[i-1])
	  continue;
	  else
	  {
	  	cout << "No";
	  	return 0;
	  }
    }
    cout << "Yes";
	  	return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    //kuko_ - ����� ����������
    int i;
    int s=1,res,k=0;
	long long n;
	cin >> n;
	long long m[n];
	long long s1[n];
	for(i = 0; i < n; ++i)
	{
	  cin >> m[i];
    }
    res = m[0];
	for(i = 1; i < n; ++i)
	{
		if(m[i] == res)
		++s;

		if((m[i]==0 && m[i-1]==1) || (m[i]==1 && m[i-1]==0))
		{
			s1[k] = s;
			//printf("%d\n",s);
		   	s = 1;
		   	++k;
		   	res = m[i];
		}
	    if(i == n-1)
		{
			s1[k] = s;
			//printf("%d\n",s);
		   	s = 1;
		   	res = m[i];
		   	break;
		}
	}
	for(i = 1; i < k; ++i)
	{
	  if(s1[i] == s1[i-1])
	  continue;
	  else
	  {
	  	cout << "No";
	  	return 0;
	  }
    }
    cout << "Yes";
	  	return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    //kuko_ - ����� ����������
    int i;
    int s=1,res,k=0;
	long long n;
	cin >> n;
	long long m[n];
	long long s1[n];
	for(i = 0; i < n; ++i)
	{
	  cin >> m[i];
    }
    res = m[0];
	for(i = 1; i < n; ++i)
	{
		if(m[i] == res)
		++s;

		if((m[i]==0 && m[i-1]==1) || (m[i]==1 && m[i-1]==0))
		{
			s1[k] = s;
		//	printf("%d\n",s);
		   	s = 1;
		   	++k;
		   	res = m[i];
		}
	    if(i == n-1)
		{
			s1[k] = s;
		//	printf("%d\n",s);
		   	s = 1;
		   	res = m[i];
		   	break;
		}
	}
	++k;
	for(i = 1; i < k; ++i)
	{
	  if(s1[i] == s1[i-1])
	  continue;
	  else
	  {
	  	cout << "No";
	  	return 0;
	  }
    }
    cout << "Yes";
	  	return 0;

}


#include<stdio.h>

int main()
{
	int n;
	int a[100005];
	int casen=0;
	scanf("%d",&n);
	int linshi=1;
	int temp,s,i;
	scanf("%d",&temp);
	for(i=1;i<n;i++){
		scanf("%d",&s);
		if(temp==s){
			linshi++;
		}else{
			a[casen++]=linshi;
			linshi=1;
			temp=s;
		}
	}
	a[casen++]=linshi;
	int flag1=0;
	for(i=0;i<=casen-2;i++){
		if(a[i]!=a[i+1]){
			printf("NO\n");
			flag1=1;
			break;
		}
	}
	if(!flag1){
		if(i==casen-1){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,x[110000],j=0,k=1000000,a,b,l=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
    }
    a=x[0];
    for(int i=0;i<n;i++)
    {
        if(x[i]==a)
        {
            j=j+1;
        }
        else
        {
            if(j!=k && l==1)
            {
                cout<<"NO";
                return 0;
            }
            a=x[i];
            k=j;
            j=1;
            l=1;
        }
        if(j>k)
        {
            cout<<"NO";
            return 0;
        }
    }
    if(j!=k && l==1)
        cout<<"NO";
    else
        cout<<"YES";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,x[110000],j=0,k=1000000,a,b,l=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
    }
    a=x[0];
    for(int i=0;i<n;i++)
    {
        if(x[i]==a)
        {
            j=j+1;
        }
        else
        {
            if(j!=k && l==1)
            {
                cout<<"NO";
                return 0;
            }
            a=x[i];
            k=j;
            j=1;
            l=1;
        }
        if(j>k)
        {
            cout<<"NO";
            return 0;
        }
    }
    if(j!=k)
        cout<<"NO";
    else
        cout<<"YES";
}


#include<bits/stdc++.h>
using namespace std;
const int MXN=100005;
int a[MXN];
int main()
{
    int n;
    cin>>n;
    bool s101=true,s100=true;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==1)
            s100=false;
        else
            s101=false;
    }
    if(s100 || s101)
    {
        cout<<"YES"<<endl;
        return 0;
    }
    int ans=-1;
    int ch=a[0];
    int size=1;
    for(int i=1;i<n;i++)
    {
        if(a[i]==ch)
            size++;
        else
        {
            ch=a[i];
            if(ans==-1)
            {
                ans=size;
                size=1;
                continue;
            }
            else
            {
                if(ans!=size)
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
                size=1;
            }
        }
    }
    if(size==ans) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


/*THE BLIND CODER */
#include"bits/stdc++.h"
using namespace std;
/*--------------------------------#defines------------------------------------------*/
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
/*-------------------------------CODE START-----------------------------------------*/
const int N=1<<20;
const int MOD=1e9+7;
typedef long long int ll;
priority_queue< pair<ll,int> >pq;
vector< pair<ll,ll> >vp;
map<ll,ll>mp,mpp;
ll dp[N];
vector<ll>v,v1,v2;
stack<ll>s,s1;
ll visit[N];
struct domingo{
int val,left,right;
}o[N];
ll BIT[N];
ll seg_tree[4*N];
set<long long int>se;
int main()
{ fast;
   ll n,m,val,k,d,mi=1e9,mx(0);
   ll sum(0),flag(0),ct(0),p(0),q(0);
   string s;
   cin>>n;
   ll a[n];
   for(int i =0 ; i < n ;i++) {
	cin >> a[i] ;
	}
	ct =  1 ;
	for(int i = 1 ; i < n ;i++) {
		 if(a[i] == a[i-1])
			ct++;
		 else
			se.insert(ct) , ct = 1;

	}
	se.insert(ct);
	if(se.size() > 1)
		cout << "NO" ;
	else
		cout << "YES" ;

}


/*THE BLIND CODER */
#include"bits/stdc++.h"
using namespace std;
/*--------------------------------#defines------------------------------------------*/
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
/*-------------------------------CODE START-----------------------------------------*/
const int N=1<<20;
const int MOD=1e9+7;
typedef long long int ll;
priority_queue< pair<ll,int> >pq;
vector< pair<ll,ll> >vp;
map<ll,ll>mp,mpp;
ll dp[N];
vector<ll>v,v1,v2;
stack<ll>s,s1;
ll visit[N];
struct domingo{
int val,left,right;
}o[N];
ll BIT[N];
ll seg_tree[4*N];
set<long long int>se;
int main()
{ fast;
   ll n,m,val,k,d,mi=1e9,mx(0);
   ll sum(0),flag(0),ct(0),p(0),q(0);
   string s;
   cin>>n;
   ll a[n];
   for(int i =0 ; i < n ;i++) {
	cin >> a[i] ;
	}
	ct =  1 ;
	for(int i = 1 ; i < n ;i++) {
		 if(a[i] == a[i-1])
			ct++;
		 else
			se.insert(ct) , ct = 1;
	}
	if(se.size() > 1)
		cout << "NO" ;
	else
		cout << "YES" ;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,a[100005],i,j;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    ll f=1;
    for(i=1;i<n;i++)
        if(a[i]!=a[i-1]){
            f=0;
            break;
        }
    if(f)cout<<"YES"<<endl;
    else
    {
        ll cnt=0;
        j=1;
        while(j<n){
            if(a[j]!=a[j-1])break;
            cnt++;j++;
        }
        //cout<<j<<" "<<cnt<<endl;
        while(j<n)
        {
            j++;
            ll prv=cnt;
            cnt=0;
            while( j<n){
                    if(a[j]!=a[j-1])break;
                    cnt++;j++;
            }

            if(prv!=cnt)
            {
                cout<<"NO"<<endl;
                return 0;
            }
        }
        cout<<"YES"<<endl;
    }

}


#include<cstdio>
#include<cstring>
#include<iostream>
#define N 100010
using namespace std;
int a[N];
int main(){
int n;
while(~scanf("%d",&n)){
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int cnt=0,cnt1=0;
    for(int i=2;i<=n;i++){
        if(a[i]==a[i-1]){
            cnt++;
        }
        else break;
    }
    for(int i=2;i<=n;i++){
        if(a[i]==a[i-1])
            cnt1++;
        else
        {
            if(cnt1!=cnt)
            {
                cout<<"NO"<<endl;
                return 0;
            }
            cnt1=0;
        }
    }
    if(cnt1!=cnt)
    {
        cout<<"NO\n"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
}
}


#include<cstdio>
#include<iostream>
#include<cstring>
#define N 100010
using namespace std;
int a[N];
int main(){
int n;
while(~scanf("%d",&n)){
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int i=1,j=n;
    while(i<=j){
        if(a[i]==a[j]){
            i++;
            j--;
            continue;
        }
        else
            break;
    }
    if(i<j)
        printf("NO\n");
    else
        printf("YES\n");
}
return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#define N 100010
using namespace std;
int a[N];
int main(){
int n;
while(~scanf("%d",&n)){
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int i=1,j=n;
    while(i<j){
        if(a[i]==a[j]){
            i++;
            j--;
            continue;
        }
        else
            break;
    }
    if(i<j)
        printf("NO\n");
    else
        printf("YES\n");
}
return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#define N 100010
using namespace std;
int a[N];
int main(){
int n;
while(~scanf("%d",&n)){
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int cnt=0,cnt1=0;
    for(int i=2;i<=n;i++){
        if(a[i]==a[i-1]){
            cnt++;
        }
        else break;
    }
    for(int i=2;i<=n;i++){
        if(a[i]==a[i-1])
            cnt1++;
        else
        {
            if(cnt1!=cnt)
            {
                cout<<"NO"<<endl;
                return 0;
            }
            cnt1=0;
        }
    }
    if(cnt1!=cnt)
    {
        cout<<"NO\n"<<endl;

    }
    else
    cout<<"YES"<<endl;
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector <int> zebra;
int arr[10000000];
main() {
    int n;
    scanf("%d",&n );
    for(int i=0; i<n; i++){
        scanf("%d", &arr[i]);
    }
    int c=0;
    for(int i=0; i<n; i++){
        if(arr[i]!=arr[i+1] || i==n-1){
            c++;
            zebra.push_back(c);
            c=0;
        }else{
            c++;
        }
    }
    c = zebra[0];
    for(int i=0; i<zebra.size(); i++){
       if(c!=zebra[i]){
            printf("NO");
            return 0;
       }
    }
    printf("YES");
    return 0;

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5;
vector< ll >v;
int a[100007];
multiset<int>m;
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n,t,j=1,i=0,p,ans=0,sum=0,x,y,cnt=0,d;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i];
    while(i<n)
    {
        cnt=0;
        //cout<<i<<endl;
        if(a[i]==1)
        {
            while(a[i]==1&&i<n)
          {
            cnt++;
            i++;
          }
        v.push_back(cnt);
        }
        else
        {
            while(a[i]==0&&i<n)
          {
            cnt++;
            i++;
          }
        v.push_back(cnt);
        }
    }

    for(int i=1;i<v.size();i++)
    {
       if(v[i]!=v[i-1])
        return cout<<"NO",0;
    }
    cout<<"YES";
}


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

int main() {
	int n,x;
	cin>>n;
    vector<int>v;
    int c=1;
    cin>>x;
    int aux=x;

	 for (int i=0;i<n-1;i++)
	 { cin>>x;
	   if (aux==x) c++;
	   else { aux=x; v.push_back(c); c=1;}
	 }
	 if (c!=0) v.push_back(c);

	 for (int i=1;i<v.size();i++)
	 if (v[0]!= v[i]) {cout<<"NO"; return 0;}

	 cout<<"YES";
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	ll n;
	cin>>n;
	ll a[n];
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	ll i=0,x=0,y=0,z=0,f=1;
	if(a[i]==0)
	{
		while(a[i]==0)
		z++,i++;
		f=0;
	}
	else
	{
		while(a[i]==1)
		z++,i++;
		f=1;
	}
	if(z==n)
	{cout<<"YES";return 0;}
	if(z>n/2)
	{cout<<"NO";return 0;}
	while(i<n)
	{
		f=1-f;
		while(i<n&&a[i]==f)
		x++,i++;
		if(x==z)
		x=0;
		else
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int , int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define inf 1e18+7
#define eps 0.00001
#define endl '\n'
int main()
{
	fastio;
	/*
	#ifndef ONLINE_JUDGE
    		freopen("input.txt", "r", stdin);
    		freopen("output.txt", "w", stdout);
	#endif
	*/
	ll n;
	cin>>n;
	int a[n];
	bool b1=0,b0=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]==1)
			b1=1;
		else
			b0=1;
	}
	if((b0==1 && b1==0)||(b0==0 && b1==1))
	{
		cout<<"YES";
		return 0;
	}
	//cout<<"hi";
	ll i,j;
	for(i=1;i<n;i++)
		if(a[i]!=a[i-1])
			break;
	ll l=i;

	for(i=l;i<n;i++)
	{
		for(j=i+1;j<n;j++)
			if(a[j]!=a[i])
				break;
		if((j-i)!=l)
			break;
		i=j-1;
	}
	if(i==n)
		cout<<"YES";
	else
		cout<<"NO";
}


/*
 ID: pseudomera
 LANG: C++14
 PROB: C. Is This a Zebra?

*/
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n;
    cin >> n;

    int wh = 0;
    int bl = 0;
    vector<int> p;
    int c;
    cin >> c;
    int eq = c;
    for(int i = 0; i < n; i++) {
        if(c == 0) {
            wh++;

            if(eq != c) {
                p.push_back(bl);
                bl = 0;
            }
        } else {
            bl++;
            if(eq != c) {
                p.push_back(wh);
                wh = 0;
            }
        }
        eq = c;
        cin >> c;
    }

    if(wh > 0)
        p.push_back(wh);
    else if(bl > 0)
        p.push_back(bl);

    set<int> ms(p.begin(), p.end());

    if(ms.size() == 1) {
        cout<<"YES";
    } else {
        cout<<"NO";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n, a[100000], x[100000], o;
bool t;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    if (a[0] == 0) t = true;
    else t  = false;
    for (int i = 0; i < n; i++){
        if (a[i] == 1)  {
            if (t == true){
                t = false;
                o++;
            }
            x[o]++;
        }
        else {
            if (t == false){
                t = true;
                o++;
            }
            x[o]++;
        }
    }
    sort (x, x + o + 1);
    if (x[0] != x[o]) {
        cout << "NO";
        return 0;
    }
    cout << "YES";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n, a[100000], x[100000], o;
bool t;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    if (a[0] != a[n-1]){
        cout << "NO";
        return 0;
    }
    if (a[0] == 0) t = true;
    else t  = false;
    for (int i = 0; i < n; i++){
        if (a[i] == 1)  {
            if (t == true){
                t = false;
                o++;
            }
            x[o]++;
        }
        else {
            if (t == false){
                t = true;
                o++;
            }
            x[o]++;
        }
    }
    sort (x, x + o + 1);
    if (x[0] != x[o]) {
        cout << "NO";
        return 0;
    }
    cout << "YES";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <set>
#include <cstdio>
#include <vector>

using namespace std;

inline int read_int()
{
    char c;

    while (c = getchar(), c <= ' ');

#ifdef USE_SIGN
    bool sign = c == '-';
    if (sign)
    {
        c = getchar();
    }
#endif

    int res = c - '0';
    while (c = getchar(), c >= '0' && c <= '9')
    {
        res = res * 10 + (c - '0');
    }
    // One character is gobbled here

#ifdef USE_SIGN
    return sign ? -res : res;
#else
    return res;
#endif
}

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

typedef long long int ll;
int n, j;
const ll N = 2000000000;
vector<bool> v;

void _input(){
    n = read_int();
    v = vector<bool> (n);
    rep(i, 0, n){
        j = read_int();
        v[i] = j != 0;
    }
}

bool solve(){
    int one, zer, d;
    one = zer = d = 0;
    rep(i, 0, n){
        if(i > 0 and v[i] != v[i-1]){
            ++d;
            //cerr << "1: " << one << " 0: " << zer << endl;
            if(d > 1){
                if(one != zer) return false;
                if(v[i]) one = 0;
                else zer = 0;
            }
        }
        if(v[i]) ++one;
        else ++zer;
        if(i == n-1){
            if(one == 0 or zer == 0) return true;
            if(one != zer) return false;
            //cerr << "ult: " << zer << ' ' << one << endl;
            //return true;
        }
    }

    //if(zer == 0 or one == 0) return true;
    if(zer != one) return false;
    return true;
}

void _solve(){
    if(solve()) cout << "YES\n";
    else cout << "NO\n";
}

int main()
{
    /*
    double st, cps = CLOCKS_PER_SEC, en;
    st = clock();
    */

    int qq = 1;
    //cin >> qq;
    while(qq--){
        _input();
        _solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{  int n,cnt=0,cnt1=0,a[1000000];
     cin>>n;
     for(int i=0;i<n;i++)
        {
         cin>>a[i];
        }
    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
            cnt++;
          else
            break;
    }
    //cout<<cnt<<" ";
    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
            cnt1++;
          else
          {  //cout<<cnt1<<" ";
             if(cnt1!=cnt)
              {cout<<"NO";
                return 0;
              }
              cnt1=0;
          }
    }
    if(cnt1!=cnt)
              {cout<<"NO";
                return 0;
              }
    cout<<"YES";
}


#include <bits/stdc++.h>
#define ll long long
#define clr(x,y) memset(x,y,sizeof x)

using namespace std;

int n ;
int pixel[100010];

vector<int> z;
int main()
{
    scanf("%d",&n);
    for (int i = 1 ; i <= n ; i++)
        scanf("%d",&pixel[i]);

    int s = 1;
    for (int i = 2 ; i <= n ; i++)
        if ( pixel[i] == pixel[i-1] ) s++;
        else
            z.push_back(s),s = 1;

    if (s!=0) z.push_back(s);

    bool flag = true;
    for (int i = 0 ; i < z.size(); i ++)
        if ( i != z.size()-1 && z[i] != z[i+1] ) flag = false;

    if (flag || z.size()==1) puts("YES");
    else puts("NO");
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define clr(x,y) memset(x,y,sizeof x)

using namespace std;

int n ;
int pixel[100010];

bool check( int width)
{
    int now = pixel[1];
    for (int i = 1 ; i <= n ; i+=width)
    {
        for(int j = i; j <= i + width - 1 ; j ++)
            if (pixel[j]!=now) return false;
        now = 1 - now;
    }
    return true;
}
int main()
{
    scanf("%d",&n);
    for (int i = 1 ; i <= n ; i++)
        scanf("%d",&pixel[i]);

    int width = 1;
    while ( pixel[width] == pixel[1] ) width++;
    width--;

    if (  n % width == 0 && check(width) ) puts("YES");
    else
        puts("NO");
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define clr(x,y) memset(x,y,sizeof x)

using namespace std;

int n ;
int pixel[100010];

vector<int> z;
int main()
{
    scanf("%d",&n);
    for (int i = 1 ; i <= n ; i++)
        scanf("%d",&pixel[i]);

    int s = 1;
    for (int i = 2 ; i <= n ; i++)
        if ( pixel[i] == pixel[i-1] ) s++;
        else
            z.push_back(s),s = 1;
    if (s != 0 ) z.push_back(s);

    z.push_back(n);
    z.push_back(n);

    bool flag = false;
    for (int i = 0 ; i < z.size(); i ++)
        if (z[i] == z[i+1] && z[i+1] == z[i+2]) flag = true;

    if (flag) puts("YES");
    else puts("NO");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main () {
	ios_base::sync_with_stdio (false); cout.setf (ios::fixed); cout.precision (20); cout.tie (nullptr); cin.tie (nullptr);
	cin >> n;
	getline (cin, s); getline (cin, s);
	s.erase (remove (s.begin (), s.end (), ' '), s.end ());
	for (auto i = s.begin () + 1; i != s.end (); i++)
	{
		if (*i != *(i - 1))
		{
			s.insert (i, '$');
			i++;
		}
	}
	std::vector<std::string> tokens;
	int start = 0, end = 0;
	while ((end = s.find ('$', start)) != std::string::npos) {
		tokens.push_back (s.substr (start, end - start));
		start = end + 1;
	}
	tokens.push_back (s.substr (start));
	int l = tokens[0].size ();
	for (const auto& i : tokens)
	{
		if (i.size () != l)
		{
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
}


#define _CRT_SECURE_NO_WARNINGS

/***from dust i have come, dust i will be***/

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

typedef long long int ll;
typedef unsigned long long int ull;

#define dbg printf("in\n")
#define nl printf("\n");
#define N 200010
#define inf 100000000000
#define pp pair<int,int>

using namespace std;

int main()
{
	//freopen("in2.txt", "r", stdin);

	int i, j, k;
	int n, m, t;
	int x, y;

	cin >> n;

	set<int> zero;
	set<int> one;

	int *a = new int[n];
	for (i = 0; i < n; i++)
		cin >> a[i];

	int cnt = 1, st = a[0];
	for (i = 1; i < n; i++)
	{
		if (a[i] == st)
			cnt++;

		else
		{
			if (st)
				one.insert(cnt);
			else
				zero.insert(cnt);

			st = 1 - st;
			cnt = 1;
		}

		if (i == n - 1)
		{
			if (st)
				one.insert(cnt);
			else
				zero.insert(cnt);
		}
	}

	if (one.size() <= 1 && zero.size() <= 1)
	{
		if (one.size() == 0 || zero.size() == 0)
			cout << "YES" << endl;

		else
		{
			auto itr = one.begin();

			x = *itr;
			itr = zero.begin();
			y = *itr;

			if (x == y)
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
	}

	else
		cout << "NO" << endl;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

/***from dust i have come, dust i will be***/

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

typedef long long int ll;
typedef unsigned long long int ull;

#define dbg printf("in\n");
#define nl printf("\n");
#define N 510
#define inf 1000000

using namespace std;

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

    int i, j, k;
    int n, m, cnt;

    scanf("%d",&n);

    int a[n];
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);

    int st=0,en=1;
    if(a[0])
        swap(st,en);

    i=0;cnt=0;
    while(a[i]!=en && i<n)
    {
        cnt++;i++;
    }

    stack<int> ss;
    for(i=0;i<n;i++)
    {
        if(a[i]==st)
            ss.push(st);

        else
        {
            if(ss.size())
                ss.pop();

            else
            {
                printf("NO\n");
                return 0;
            }
        }
    }

    if(ss.size()>0 && ss.size()==cnt)
        printf("YES\n");

    else
        printf("NO\n");

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

/***from dust i have come, dust i will be***/

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

typedef long long int ll;
typedef unsigned long long int ull;

#define dbg printf("in\n");
#define nl printf("\n");
#define N 510
#define inf 1000000

using namespace std;

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

    int i, j, k;
    int n, m, cnt;

    scanf("%d",&n);

    int a[n];
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);

    int st=0,en=1;
    if(a[0])
        swap(st,en);

    i=0;cnt=0;
    while(a[i]!=en)
    {
        cnt++;i++;
    }

    stack<int> ss;
    for(i=0;i<n;i++)
    {
        if(a[i]==st)
            ss.push(st);

        else
        {
            if(ss.size())
                ss.pop();

            else
            {
                printf("NO\n");
                return 0;
            }
        }
    }

    if(ss.size()>0 && ss.size()==cnt)
        printf("YES\n");

    else
        printf("NO\n");

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

/***from dust i have come, dust i will be***/

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

typedef long long int ll;
typedef unsigned long long int ull;

#define dbg printf("in\n");
#define nl printf("\n");
#define N 510
#define inf 1000000

using namespace std;

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

    int i, j, k;
    int n, m, cnt;

    scanf("%d",&n);

    int a[n];
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);

    int st=0,en=1;
    if(a[0])
        swap(st,en);

    i=0;cnt=0;
    while(a[i]!=en && i<n)
    {
        cnt++;i++;
    }

    stack<int> ss;
    for(i=0;i<n;i++)
    {
        if(a[i]==st)
            ss.push(st);

        else
        {
            if(ss.size())
                ss.pop();

            else
            {
                printf("NO\n");
                return 0;
            }
        }
    }

    if(ss.size()>0 && ss.size()==cnt)
        printf("YES\n");

    else if(ss.size()==0)
        printf("YES\n");

    else
        printf("NO\n");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef map<int,int> mpii;
typedef map<string,int> mpsi;
typedef set<int> si;
typedef set<ll> sll;
#define pb push_back
#define INF 1000000000
#define LINF INF*INF
#define all(x) x.begin(),x.end()
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;cin>>n;
	vi a(n);
	vi b;
	for(int i=0;i<n;i++) cin>>a[i];
	int curr=0;
	int c1=0,c0=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==1)
		{
			if(curr!=1)
			{
				if(c0>0)
				{
					b.pb(c0);
					c0=0;
				}
				curr=1;
			}
			c1++;
		}
		else{
			if(curr!=0)
			{
				if(c1>0)
				{
					b.pb(c1);
					c1=0;
				}
				curr=0;
			}
			c0++;
		}
	}
	if(c1>0) b.pb(c1);
	if(c0>0) b.pb(c0);

	set<int> s;
	for(auto it: b)
		s.insert(it);//cout<<it<<endl;;
	//for(auto it: s)
	//	cout<<it<<endl;
	if(s.size()>1)
	{
		cout<<"NO\n";
		return 0;
	}
	cout<<"YES\n";
	return 0;
}


#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int main(){
	int n;
	scanf("%d",&n);
	int l=-1;
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		if(i && a[i-1]!=a[i] && l==-1)
			l = i;
	}
	if(l == -1){
		printf("YES");
		return 0;
	}
	int len=1;
	for(int i=1;i<n;i++){
		if(a[i] == a[i-1])len++;
		else{
			if(len == l)len = 1;
			else{
				printf("NO");
				return 0;
			}
		}
	}
	if(len != l){
		printf("NO");
	}else{
		printf("YES");
	}
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>

using namespace std;
#define INF (1<<30)
#define LL (long long)
#define MAXN 100005

int n,w;
bool a[MAXN],ans;

int main(){
	std::ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	bool t=a[1];
	int no=2;
	w=1;
	while(a[no]==t){
		w++;
		no++;
	}
//	cout<<w<<endl;
	while(no<=n){
		t=!t;
		for(int i=1;i<=w;i++,no++){
			if(no>n){
				cout<<"NO";
				return 0;
			}
			if(a[no]!=t){
				cout<<"NO";
				return 0;
			}
		}
	}
	cout<<"YES";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VII;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);

    int N;
    set<int> whites;
    set<int> blackis;

    cin >> N;
    int cnt1 = 0;
    int cnt0 = 0;
    int before = -1;

    for(int i = 0; i < N; i++){
        int dummy;
        cin >> dummy;
        if(before == -1){
            before = dummy;
        }

        if(dummy == 1 && before == 1){
            cnt1++;
        }else if(dummy == 0 && before == 0){
            cnt0++;
        }else if(dummy == 0 && before == 1){
            whites.insert(cnt1);
            cnt1 = 0;
            cnt0++;
            before = 0;
        }else if(dummy == 1 && before == 0){
            blackis.insert(cnt0);
            cnt0 = 0;
            cnt1++;
            before = 1;
        }
    }
    if(cnt1 != 0)
        whites.insert(cnt1);
    if(cnt0!=0)
        blackis.insert(cnt0);

    // cout << blackis.size() << endl;
    // cout << whites.size() << endl;
    auto bl = blackis.begin();
    if( ( blackis.size() == whites.size() && blackis.size() == 1 && whites.count(*bl)) || (blackis.count(N) || whites.count(N)))
        cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vec;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N= N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

int main()
{
    ///freopen("debug.txt","w",stdout);
    /*
     ios_base::sync_with_stdio(false);
    cin.tie(0);
    */
    int n;
    scn(n);
    int a[n];
    for(int i=0; i<n; i++)scn(a[i]);

    int z=-1;
    int o=-1;

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

        if(a[i]==0)
        {
            for( ; i<n && a[i]==0; i++)zer++;
            if(zer==n)
            {
                cout<<"YES";
                return 0;
            }
            else if(z != -1 && z!=zer)
            {
                cout<<"NO";
                return 0;
            }
            if(z==-1)z=zer;
            i--;
        }
        else
        {
            for( ; i<n && a[i]; i++)one++;
            if(one==n)
            {
                cout<<"YES";
                return 0;
            }
            else if(o != -1 && o!=one)
            {
                cout<<"NO";
                return 0;
            }
            if(o==-1)o=one;
            i--;

        }
    }
    if(z!=o)cout<<"NO";
    else cout<<"YES";

        return 0;
}


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

const int N = 100005;
int a[N];
int main(){
	int n ,i ,j;
	scanf("%d" ,&n);
	for(int i = 0 ; i < n ; i++)	scanf("%d" ,a + i);
	i = 1;
	while(i < n && a[i] == a[i - 1])	i++;
	int d = i ,x;
	while(i < n){
		j = i + 1;
		while(j < n && a[j] == a[i])	j++;
		x = j - i;
		if(x != d){
			puts("no");	return 0;
		}
		i = j;
	}
	puts("yes");
	return 0;
}


#include <iostream>
using namespace std;
int a[100001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n;
	cin >> n;
	int ans = 0,index=0;
	bool check = true;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		if (a[i] != a[0])break;
		else ans++;
	}
	index = a[0];
	int temp = 0;
	for (int i = 0; i < n; i++) {
		if (index != a[i]) {
			if (temp != ans) {
				cout << "NO";
				return 0;
			}
			index = a[i];
			temp=1;
		}
		else temp++;
	}
	if (temp != ans)cout << "NO";
	else cout << "YES";
}


#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iostream>
#define nabs(x) ((x) < 0? -(x) : (x))
#define val(x) ((x) - 'A')
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAX = 1000 + 10;
const int oo = (1 << 29);

int N;
int a[105];
int __min[105][105];

int dist(int r1, int c1, int r2, int c2) {
    int _min = __min[r1][r2];
    int ans = nabs(r2 - r1);
    if (c1 > c2)
        swap(c1, c2);
    if (_min <= c2) {
        ans += nabs(c1 - _min);
    } else {
        ans += (c2 - c1);
    }

    return ans;
}

int main() {
    ios::sync_with_stdio(false);
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);

    cin >> N;
    for (int i = 1; i <= N; i++)
        cin >> a[i];

    for(int i = 1; i <= N; i++)
        for(int j = i; j <= N; j++){
            __min[i][j] = oo;
            for(int k = i; k <= j; k++)
                __min[i][j] = min(__min[i][j], a[k] + 1);
            __min[j][i] = __min[i][j];
        }

    int r1, c1, r2, c2, _c1, _c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int ans = oo;

    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= N; j++){
            _c1 = min(c1, __min[r1][i]);
            _c2 = min(c2, __min[r2][j]);
            ans = min(ans, nabs(r1 - i) + nabs(r2 - j) + dist(i, _c1, j, _c2));
        }

    cout << ans << endl;

    return 0;
}


#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iostream>
#define nabs(x) ((x) < 0? -(x) : (x))
#define val(x) ((x) - 'A')
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAX = 1000 + 10;
const int oo = (1 << 29);

int N;
int a[105];
int __min[105][105];

int dist(int r1, int c1, int r2, int c2) {
	int _min = __min[r1][r2];
	int ans = nabs(r2 - r1);
	if (_min <= c1) {
		ans += nabs(c2 - _min);
	} else {
		ans += nabs(c2 - c1);
	}

	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	cin >> N;
	for (int i = 1; i <= N; i++)
		cin >> a[i];

	for(int i = 1; i <= N; i++)
		for(int j = i; j <= N; j++){
			__min[i][j] = oo;
			for(int k = i; k <= j; k++)
				__min[i][j] = min(__min[i][j], a[k] + 1);
			__min[j][i] = __min[i][j];
		}

	int r1, c1, r2, c2, _c1, _c2;
	cin >> r1 >> c1 >> r2 >> c2;
	int ans = oo;

	for(int i = 1; i <= N; i++)
		for(int j = 1; j <= N; j++){
			_c1 = min(c1, __min[r1][i]);
			_c2 = min(c2, __min[r2][j]);
			ans = min(ans, nabs(r1 - i) + nabs(r2 - j) + dist(i, _c1, j, _c2));
		}

	cout << ans << endl;

	return 0;
}


#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iostream>
#define nabs(x) ((x) < 0? -(x) : (x))
#define val(x) ((x) - 'A')
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAX = 1000 + 10;
const int oo = (1 << 29);

int N;
int a[105];
int __min[105][105];

int dist(int r1, int c1, int r2, int c2) {
	int _min = __min[r1][r2];
	int ans = nabs(r2 - r1);
	if (_min <= c1) {
		ans += nabs(c2 - _min);
	} else {
		ans += nabs(c2 - c1);
	}

	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	cin >> N;
	for (int i = 1; i <= N; i++)
		cin >> a[i];

	for(int i = 1; i <= N; i++)
		for(int j = i; j <= N; j++){
			__min[i][j] = oo;
			for(int k = i; k <= j; k++)
				__min[i][j] = min(__min[i][j], a[k] + 1);
			__min[j][i] = __min[i][j];
		}

	int r1, c1, r2, c2, _c1;
	cin >> r1 >> c1 >> r2 >> c2;
	int ans = oo;

	for(int i = 1; i <= N; i++){
			_c1 = min(c1, __min[r1][i]);
			ans = min(ans, nabs(r1 - i) + dist(i, _c1, r2, c2));
		}

	cout << ans << endl;

	return 0;
}


#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iostream>
#define nabs(x) ((x) < 0? -(x) : (x))
#define val(x) ((x) - 'A')
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAX = 1000 + 10;
const int oo = (1 << 29);

int N;
int a[105];
int __min[105][105];

int dist(int r1, int c1, int r2, int c2) {
    if (r1 > r2) {
        swap(r1, r2);
        swap(c1, c2);
    }
    int _min = __min[r1][r2];

    int ans = r2 - r1;
    if (c1 > c2)
        swap(c1, c2);
    if (_min <= c1) {
        ans += min((c1 - _min), (c2 - _min));
    } else if (_min <= c2) {
        ans += (_min - c1);
    } else {
        ans += (c2 - c1);
    }

    return ans;
}

int main() {
    ios::sync_with_stdio(false);
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);

    cin >> N;
    for (int i = 1; i <= N; i++)
        cin >> a[i];

    for(int i = 1; i <= N; i++)
        for(int j = i; j <= N; j++){
            __min[i][j] = oo;
            for(int k = i; k <= j; k++)
                __min[i][j] = min(__min[i][j], a[k] + 1);
            __min[j][i] = __min[i][j];
        }

    int r1, c1, r2, c2, _c1, _c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int ans = (1 << 29);

    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= N; j++){
            _c1 = min(c1, __min[r1][i]);
            _c2 = min(c2, __min[r2][j]);
            ans = min(ans, nabs(r1 - i) + nabs(r2 - j) + dist(i, _c1, j, _c2));
        }

    cout << ans << endl;

    return 0;
}


#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iostream>
#define nabs(x) ((x) < 0? -(x) : (x))
#define val(x) ((x) - 'A')
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAX = 1000 + 10;

int N;
int a[105];

int dist(int r1, int c1, int r2, int c2) {
	if (r1 > r2) {
		swap(r1, r2);
		swap(c1, c2);
	}
	int _min = (1 << 29);
	for (int i = r1; i <= r2; i++)
		_min = min(_min, a[i] + 1);

	int ans = r2 - r1;
	if (c1 > c2)
		swap(c1, c2);
	if (_min <= c1) {
		ans += min((c1 - _min), (c2 - _min));
	} else if (_min <= c2) {
		ans += (_min - c1);
	} else {
		ans += (c2 - c1);
	}

	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);

	cin >> N;
	for (int i = 1; i <= N; i++)
		cin >> a[i];

	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	int ans = (1 << 29);

	for(int i = 1; i <= N; i++)
		for(int j = 1; j <= N; j++)
			ans = min(ans, nabs(r1 - i) + nabs(r2 - j) + dist(i, c1, j, c2));

	cout << ans << endl;

	return 0;
}


#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iostream>
#define nabs(x) ((x) < 0? -(x) : (x))
#define val(x) ((x) - 'A')
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAX = 1000 + 10;

int N;
int a[105];

int dist(int r1, int c1, int r2, int c2) {
    if (r1 > r2) {
        swap(r1, r2);
        swap(c1, c2);
    }
    int _min = (1 << 29);
    for (int i = r1; i <= r2; i++)
        _min = min(_min, a[i] + 1);

    int ans = r2 - r1;
    if (c1 > c2)
        swap(c1, c2);
    if (_min <= c1) {
        ans += min((c1 - _min), (c2 - _min));
    } else if (_min <= c2) {
        ans += (_min - c1);
    } else {
        ans += (c2 - c1);
    }

    return ans;
}

int main() {
    ios::sync_with_stdio(false);
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);

    cin >> N;
    for (int i = 1; i <= N; i++)
        cin >> a[i];

    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int ans = (1 << 29);

    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= N; j++)
            ans = min(ans, nabs(r1 - i) + nabs(r2 - j) + dist(i, c1, j, c2));

    cout << ans << endl;

    return 0;
}


/*
 * main2.cpp
 *
 *  Created on: Dec 9, 2012
 *      Author: oleksiys
 */

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <deque>
#include <utility>
#include <set>
using namespace std;

typedef pair<int, int> pii;
typedef pair<pii, int> piii;

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

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);

	int n = 0;
	cin >> n;
	vector<int> a(n + 1);
	for (size_t i = 1; i <= n; ++i){
		cin >> a[i];
	}
	int r1 = 0;
	int c1 = 0;
	int r2 = 0;
	int c2 = 0;
	cin >> r1 >> c1 >> r2 >> c2;
	vector<vector<bool> > visited(102, vector<bool>(10002));
	visited[r1][c1] = true;
	deque<piii> deq;
	deq.push_back(make_pair(make_pair(r1, c1), 0));
	while (!deq.empty()){
		piii v = deq[0];
		deq.pop_front();
		int r = v.first.first;
		int c = v.first.second;
		int s = v.second;
		if (r == r2 && c == c2){
			cout << v.second << endl;
			break;
		}
		for (int i = 0; i < 4; ++i){
			int nr = r + X[i];
			int nc = c + Y[i];
			nr = max(nr, 1);
			nr = min(nr, n);
			nc = max(nc, 1);
			nc = min(nc, a[nr] + 1);
			if (!visited[nr][nc]){
				visited[nr][nc] = true;
				deq.push_back(make_pair(make_pair(nr, nc), s + 1));
			}
		}
	}
	return 0;
}


/*
 * main2.cpp
 *
 *  Created on: Dec 9, 2012
 *      Author: oleksiys
 */

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <deque>
#include <utility>
#include <set>
using namespace std;

typedef pair<int, int> pii;
typedef pair<pii, int> piii;

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

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);

	int n = 0;
	cin >> n;
	vector<int> a(n + 1);
	for (size_t i = 1; i <= n; ++i){
		cin >> a[i];
	}
	int r1 = 0;
	int c1 = 0;
	int r2 = 0;
	int c2 = 0;
	cin >> r1 >> c1 >> r2 >> c2;
	vector<vector<bool> > visited(101, vector<bool>(10002));
	visited[r1][c1] = true;
	deque<piii> deq;
	deq.push_back(make_pair(make_pair(r1, c1), 0));
	while (!deq.empty()){
		piii v = deq[0];
		deq.pop_front();
		int r = v.first.first;
		int c = v.first.second;
		int s = v.second;
		if (r == r2 && c == c2){
			cout << v.second << endl;
			break;
		}
		for (int i = 0; i < 4; ++i){
			int nr = r + X[i];
			int nc = c + Y[i];
			nr = max(nr, 1);
			nr = min(nr, n);
			nc = max(nc, 1);
			nc = min(nc, a[nr] + 1);
			if (!visited[nr][nc]){
				visited[nr][nc] = true;
				deq.push_back(make_pair(make_pair(nr, nc), s + 1));
			}
		}
	}
	return 0;
}


/*
 * main2.cpp
 *
 *  Created on: Dec 9, 2012
 *      Author: oleksiys
 */

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <deque>
#include <utility>
#include <set>
using namespace std;

typedef pair<int, int> pii;
typedef pair<pii, int> piii;

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

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);

	int n = 0;
	cin >> n;
	vector<int> a(n + 1);
	for (size_t i = 1; i <= n; ++i){
		cin >> a[i];
	}
	int r1 = 0;
	int c1 = 0;
	int r2 = 0;
	int c2 = 0;
	cin >> r1 >> c1 >> r2 >> c2;
	vector<vector<bool> > visited(101, vector<bool>(10001));
	visited[r1][c1] = true;
	deque<piii> deq;
	deq.push_back(make_pair(make_pair(r1, c1), 0));
	while (!deq.empty()){
		piii v = deq[0];
		deq.pop_front();
		int r = v.first.first;
		int c = v.first.second;
		int s = v.second;
		if (r == r2 && c == c2){
			cout << v.second << endl;
			break;
		}
		for (int i = 0; i < 4; ++i){
			int nr = r + X[i];
			int nc = c + Y[i];
			nr = max(nr, 1);
			nr = min(nr, n);
			nc = max(nc, 1);
			nc = min(nc, a[nr] + 1);
			if (!visited[nr][nc]){
				visited[nr][nc] = true;
				deq.push_back(make_pair(make_pair(nr, nc), s + 1));
			}
		}
	}
	return 0;
}


/*
 * main2.cpp
 *
 *  Created on: Dec 9, 2012
 *      Author: oleksiys
 */

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <deque>
#include <utility>
#include <set>
using namespace std;

typedef pair<int, int> pii;
typedef pair<pii, int> piii;

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

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);

	int n = 0;
	cin >> n;
	vector<int> a(n + 1);
	for (size_t i = 1; i <= n; ++i){
		cin >> a[i];
	}
	int r1 = 0;
	int c1 = 0;
	int r2 = 0;
	int c2 = 0;
	cin >> r1 >> c1 >> r2 >> c2;
	vector<vector<bool> > visited(101, vector<bool>(100001));
	visited[r1][c1] = true;
	deque<piii> deq;
	deq.push_back(make_pair(make_pair(r1, c1), 0));
	while (!deq.empty()){
		piii v = deq[0];
		deq.pop_front();
		int r = v.first.first;
		int c = v.first.second;
		int s = v.second;
		if (r == r2 && c == c2){
			cout << v.second << endl;
			break;
		}
		for (int i = 0; i < 4; ++i){
			int nr = r + X[i];
			int nc = c + Y[i];
			nr = max(nr, 1);
			nr = min(nr, n);
			nc = max(nc, 1);
			nc = min(nc, a[nr] + 1);
			if (!visited[nr][nc]){
				visited[nr][nc] = true;
				deq.push_back(make_pair(make_pair(nr, nc), s + 1));
			}
		}
	}
	return 0;
}


/*
 * main2.cpp
 *
 *  Created on: Dec 9, 2012
 *      Author: oleksiys
 */

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <deque>
#include <utility>
using namespace std;

const int MAX = 101;

typedef pair<int, int> pii;
typedef pair<pii, int> piii;

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

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);

	int n = 0;
	cin >> n;
	vector<int> a(n + 1);
	for (size_t i = 1; i <= n; ++i){
		cin >> a[i];
	}
	int r1 = 0;
	int c1 = 0;
	int r2 = 0;
	int c2 = 0;
	cin >> r1 >> c1 >> r2 >> c2;
	int visited[MAX][MAX];
	memset(visited, 0, sizeof(visited));
	visited[r1][c1] = 1;
	deque<piii> deq;
	deq.push_back(make_pair(make_pair(r1, c1), 0));
	while (!deq.empty()){
		piii v = deq[0];
		deq.pop_front();
		int r = v.first.first;
		int c = v.first.second;
		int s = v.second;
		if (r == r2 && c == c2){
			cout << v.second << endl;
			break;
		}
		for (int i = 0; i < 4; ++i){
			int nr = r + X[i];
			int nc = c + Y[i];
			nr = max(nr, 1);
			nr = min(nr, n);
			nc = max(nc, 1);
			nc = min(nc, a[nr] + 1);
			if (visited[nr][nc] == 0){
				visited[nr][nc] = 1;
				deq.push_back(make_pair(make_pair(nr, nc), s + 1));
			}
		}
	}
	return 0;
}


/*
 * main2.cpp
 *
 *  Created on: Dec 9, 2012
 *      Author: oleksiys
 */

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
#include <utility>
#include <set>
using namespace std;

typedef pair<int, int> pii;
typedef pair<pii, int> piii;

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

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);

	int n = 0;
	cin >> n;
	vector<int> a(n + 1);
	for (size_t i = 1; i <= n; ++i){
		cin >> a[i];
	}
	int r1 = 0;
	int c1 = 0;
	int r2 = 0;
	int c2 = 0;
	cin >> r1 >> c1 >> r2 >> c2;
	vector<vector<bool> > visited(101, vector<bool>(100001));
	visited[r1][c1] = true;
	queue<piii> q;
	q.push(make_pair(make_pair(r1, c1), 0));
	while (!q.empty()){
		piii v = q.front();
		q.pop();
		int r = v.first.first;
		int c = v.first.second;
		int s = v.second;
		if (r == r2 && c == c2){
			cout << v.second << endl;
			break;
		}
		for (int i = 0; i < 4; ++i){
			int nr = r + X[i];
			int nc = c + Y[i];
			nr = max(nr, 1);
			nr = min(nr, n);
			nc = max(nc, 1);
			nc = min(nc, a[nr] + 1);
			if (!visited[nr][nc]){
				visited[nr][nc] = true;
				q.push(make_pair(make_pair(nr, nc), s + 1));
			}
		}
	}
	return 0;
}


/*
 * main2.cpp
 *
 *  Created on: Dec 9, 2012
 *      Author: oleksiys
 */

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <deque>
#include <utility>
#include <set>
using namespace std;

typedef pair<int, int> pii;
typedef pair<pii, int> piii;

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

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);

	int n = 0;
	cin >> n;
	vector<int> a(n + 1);
	for (size_t i = 1; i <= n; ++i){
		cin >> a[i];
	}
	int r1 = 0;
	int c1 = 0;
	int r2 = 0;
	int c2 = 0;
	cin >> r1 >> c1 >> r2 >> c2;
	set<pii> visited;
	visited.insert(make_pair(r1, c1));
	deque<piii> deq;
	deq.push_back(make_pair(make_pair(r1, c1), 0));
	while (!deq.empty()){
		piii v = deq[0];
		deq.pop_front();
		int r = v.first.first;
		int c = v.first.second;
		int s = v.second;
		if (r == r2 && c == c2){
			cout << v.second << endl;
			break;
		}
		for (int i = 0; i < 4; ++i){
			int nr = r + X[i];
			int nc = c + Y[i];
			nr = max(nr, 1);
			nr = min(nr, n);
			nc = max(nc, 1);
			nc = min(nc, a[nr] + 1);
			if (visited.insert(make_pair(nr, nc)).second){
				deq.push_back(make_pair(make_pair(nr, nc), s + 1));
			}
		}
	}
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;

int i,r1,r2,c1,c2,j,n,qx[100900],qy[100900],a[100900],d[500][100900];

void go(int x , int y)
{
    	if (d[x][y] > 0) return;

	j++;

	qx[j] = x;

	qy[j] = y;

	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;
	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;
	cin >> r1 >> c1 >> r2 >> c2;

	i = j = d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] != a[qx[i]]) 	go(qx[i],qy[i]+1);

		if (qy[i] != 1) 	go(qx[i],qy[i]-1);

		if (qx[i] != n) 	go(qx[i]+1,min(qy[i], a[qx[i]+1]));

		if (qx[i] != 1) 	go(qx[i]-1,min(qy[i], a[qx[i]-1]));

		i++;
	}
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;
int i,r1,r2,c1,c2,j,n,qx[100500],qy[100500],a[100500],d[109][100500];
void go(int x , int y)
{
    if (d[x][y] > 0) return;
	j++;
	qx[j] = x;
	qy[j] = y;
	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;
	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;
	cin >> r1 >> c1 >> r2 >> c2;

	i = j = 1; d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] <= a[qx[i]]) go(qx[i],qy[i]+1);

		if (qy[i] > 1) go(qx[i],qy[i]-1);

		if (qx[i] <= n) go(qx[i]+1,min(qy[i], a[qx[i]+1]));

		if (qx[i] > 1) go(qx[i]-1,min(qy[i], a[qx[i]+1]));

		i++;
	}
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;
int i,r1,r2,c1,c2,j,n,qx[100500],qy[100500],a[100500],d[200][100500];
void go(int x , int y)
{
    if (d[x][y] > 0) return;
	j++;
	qx[j] = x;
	qy[j] = y;
	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;
	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;
	cin >> r1 >> c1 >> r2 >> c2;

	i = j = 1; d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] != a[qx[i]]) go(qx[i],qy[i]+1);

		if (qy[i] != 1) go(qx[i],qy[i]-1);

		if (qx[i] != n) go(qx[i]+1,min(qy[i], a[qx[i]+1]));

		if (qx[i] != 1) go(qx[i]-1,min(qy[i], a[qx[i]-1]));

		i++;
	}
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;
int i,r1,r2,c1,c2,j,n,qx[100500],qy[100500],a[100500],d[109][100500];
void go(int x , int y)
{
    if (d[x][y] > 0) return;
	j++;
	qx[j] = x;
	qy[j] = y;
	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;
	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;
	cin >> r1 >> c1 >> r2 >> c2;

	i = j = 1; d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] < a[qx[i]]) go(qx[i],qy[i]+1);

		if (qy[i] > 1) go(qx[i],qy[i]-1);

		if (qx[i] < n) go(qx[i]+1,min(qy[i], a[qx[i]+1]));

		if (qx[i] > 1) go(qx[i]-1,min(qy[i], a[qx[i]-1]));

		i++;
	}
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;

int i,r1,r2,c1,c2,j,n,qx[1000100],qy[1000100],a[190],d[500][100010];

void go(int x , int y)
{
    	if (d[x][y] > 0) return;

	j++;

	qx[j] = x;

	qy[j] = y;

	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;

	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;

	cin >> r1 >> c1 ;

	i = j = 1;

	d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] != a[qx[i]]) 	go(qx[i],qy[i]+1);

		if (qy[i] != 1) 	go(qx[i],qy[i]-1);

		if (qx[i] != n) 	go(qx[i]+1, min(qy[i] , a[qx[i]+1]) );

		if (qx[i] != 1) 	go(qx[i]-1, min(qy[i] , a[qx[i]-1]) );

		i++;
	}
	cin >> r2 >> c2;
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;

int i,r1,r2,c1,c2,j,n,qx[100900],qy[100900],a[190],d[500][100900];

void go(int x , int y)
{
    	if (d[x][y] > 0) return;

	j++;

	qx[j] = x;

	qy[j] = y;

	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;

	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;

	cin >> r1 >> c1 >> r2 >> c2;

	i = j = d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] != a[qx[i]]) 	go(qx[i],qy[i]+1);

		if (qy[i] != 1) 	go(qx[i],qy[i]-1);

		if (qx[i] != n) 	go(qx[i]+1,min(qy[i], a[qx[i]+1]));

		if (qx[i] != 1) 	go(qx[i]-1,min(qy[i], a[qx[i]-1]));

		i++;
	}
	if (d[r2][c2] -1 < 0) cout << 42748; else
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;
int i,r1,r2,c1,c2,j,n,qx[100500],qy[100500],a[100500],d[109][100500];
void go(int x , int y)
{
    if (d[x][y] > 0) return;
	j++;
	qx[j] = x;
	qy[j] = y;
	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;
	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;
	cin >> r1 >> c1 >> r2 >> c2;

	i = j = 1; d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] <= n) go(qx[i],qy[i]+1);

		if (a[qx[i]] > 1) go(qx[i],qy[i]-1);

		if (qx[i] <= n) go(qx[i]+1,min(qy[i], a[qx[i]+1]));

		if (qx[i] > 1) go(qx[i]-1,min(qy[i], a[qx[i]+1]));

		i++;
	}
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;
int i,r1,r2,c1,c2,j,n,qx[100900],qy[100900],a[100900],d[500][100900];
void go(int x , int y)
{
    if (d[x][y] > 0) return;
	j++;
	qx[j] = x;
	qy[j] = y;
	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;
	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;
	cin >> r1 >> c1 >> r2 >> c2;

	i = j = 1; d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] != a[qx[i]]) go(qx[i],qy[i]+1);

		if (qy[i] != 1) go(qx[i],qy[i]-1);

		if (qx[i] != n) go(qx[i]+1,min(qy[i], a[qx[i]+1]));

		if (qx[i] != 1) go(qx[i]-1,min(qy[i], a[qx[i]-1]));

		i++;
	}
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;

int i,r1,r2,c1,c2,j,n,qx[10000100],qy[10000100],a[190],d[500][100010];

void go(int x , int y)
{
    	if (d[x][y] > 0) return;

	j++;

	qx[j] = x;

	qy[j] = y;

	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;

	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;

	cin >> r1 >> c1 ;

	i = j = 1;

	d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] != a[qx[i]]) 	go(qx[i],qy[i]+1);

		if (qy[i] != 1) 	go(qx[i],qy[i]-1);

		if (qx[i] != n) 	go(qx[i]+1, min(qy[i] , a[qx[i]+1]) );

		if (qx[i] != 1) 	go(qx[i]-1, min(qy[i] , a[qx[i]-1]) );

		i++;
	}
	cin >> r2 >> c2;
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;
int i,r1,r2,c1,c2,j,n,qx[100500],qy[100500],a[100500],d[109][100500];
void go(int x , int y)
{
    if (d[x][y] > 0) return;
	j++;
	qx[j] = x;
	qy[j] = y;
	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;
	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;
	cin >> r1 >> c1 >> r2 >> c2;

	i = j = 1; d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] <= a[qx[i]]) go(qx[i],qy[i]+1);

		if (a[qx[i]] > 1) go(qx[i],qy[i]-1);

		if (qx[i] <= n) go(qx[i]+1,min(qy[i], a[qx[i]+1]));

		if (qx[i] > 1) go(qx[i]-1,min(qy[i], a[qx[i]+1]));

		i++;
	}
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;
int i,r1,r2,c1,c2,j,n,qx[100500],qy[100500],a[100500],d[109][100500];
void go(int x , int y)
{
    if (d[x][y] > 0) return;
	j++;
	qx[j] = x;
	qy[j] = y;
	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;
	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;
	cin >> r1 >> c1 >> r2 >> c2;

	i = j = 1; d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] != a[qx[i]]) go(qx[i],qy[i]+1);

		if (qy[i] != 1) go(qx[i],qy[i]-1);

		if (qx[i] != n) go(qx[i]+1,min(qy[i], a[qx[i]+1]));

		if (qx[i] != 1) go(qx[i]-1,min(qy[i], a[qx[i]-1]));

		i++;
	}
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;

int i,r1,r2,c1,c2,j,n,qx[100900],qy[100900],a[190],d[500][100900];

void go(int x , int y)
{
    	if (d[x][y] > 0) return;

	j++;

	qx[j] = x;

	qy[j] = y;

	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;
	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;
	cin >> r1 >> c1 >> r2 >> c2;

	i = j = d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] != a[qx[i]]) 	go(qx[i],qy[i]+1);

		if (qy[i] != 1) 	go(qx[i],qy[i]-1);

		if (qx[i] != n) 	go(qx[i]+1,min(qy[i], a[qx[i]+1]));

		if (qx[i] != 1) 	go(qx[i]-1,min(qy[i], a[qx[i]-1]));

		i++;
	}

	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;

int i,r1,r2,c1,c2,j,n,qx[10000100],qy[10000100],a[190],d[500][100900];

void go(int x , int y)
{
    	if (d[x][y] > 0) return;

	j++;

	qx[j] = x;

	qy[j] = y;

	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;

	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;

	cin >> r1 >> c1 ;

	i = j = 1;

	d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] != a[qx[i]]) 	go(qx[i],qy[i]+1);

		if (qy[i] != 1) 	go(qx[i],qy[i]-1);

		if (qx[i] != n) 	go(qx[i]+1, min(qy[i] , a[qx[i]+1]) );

		if (qx[i] != 1) 	go(qx[i]-1, min(qy[i] , a[qx[i]-1]) );

		i++;
	}
	cin >> r2 >> c2;
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;

int i,r1,r2,c1,c2,j,n,qx[10000100],qy[10000100],a[150],d[110][100010];

void go(int x , int y)
{
    	if (d[x][y] > 0) return;

	j++;

	qx[j] = x;

	qy[j] = y;

	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;

	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;

	cin >> r1 >> c1 ;

	i = j = 1;

	d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] != a[qx[i]]) 	go(qx[i],qy[i]+1);

		if (qy[i] != 1) 	go(qx[i],qy[i]-1);

		if (qx[i] != n) 	go(qx[i]+1, min(qy[i] , a[qx[i]+1]) );

		if (qx[i] != 1) 	go(qx[i]-1, min(qy[i] , a[qx[i]-1]) );

		i++;
	}
	cin >> r2 >> c2;
	cout << d[r2][c2]-1;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>

#define sqr(a) ((a)*(a))
#define eps 1e-9
#define INF 2147483647
#define N 1000*1000*1000
#define cub(a) ((a)*(a)*(a))

using namespace std;

int i,r1,r2,c1,c2,j,n,qx[100900],qy[100900],a[190],d[500][100900];

void go(int x , int y)
{
    	if (d[x][y] > 0) return;

	j++;

	qx[j] = x;

	qy[j] = y;

	d[x][y] = d[qx[i]][qy[i]] + 1;
}
int main()

{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin >> n;

	for (i = 1; i <= n; i++)
		cin >> a[i],a[i]++;

	cin >> r1 >> c1 ;

	i = j = 1;

	d[r1][c1] = 1;

	qx[1] = r1; qy[1] = c1;

	while (i <= j)
	{
		if (qy[i] != a[qx[i]]) 	go(qx[i],qy[i]+1);

		if (qy[i] != 1) 	go(qx[i],qy[i]-1);

		if (qx[i] != n) 	go(qx[i]+1,min(qy[i], a[qx[i]+1]));

		if (qx[i] != 1) 	go(qx[i]-1,min(qy[i], a[qx[i]-1]));

		i++;
	}
	cin >> r2 >> c2;
	cout << d[r2][c2]-1;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <map>

using namespace std;

#define f first
#define s second
#define sz(v) int((v).size())

typedef long long ll;
typedef pair <int, int> pt;

const int N = 100;

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

int n;
int a[N + 1];
pt p, t;
map <pt, int> mp;
queue < pair <pt, int> > q;

int main(){

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

		cin >> n;
		for (int i = 1; i <= n; i++){
			cin >> a[i];
			for (int j = 1; j <= a[i]; j++)
				mp[make_pair(i, j)] = 1;
			mp[make_pair(i, a[i] + 1)] = 1;
		}
		cin >> p.f >> p.s;
		cin >> t.f >> t.s;
		if (p.f > t.f)
			swap(p, t);
		q.push(make_pair(p, 0));
		while (!q.empty()){
			pt v = q.front().f;
			int d = q.front().s;
			if (v == t){
				cout << d;
				return 0;
			}
			q.pop();
			for (int i = 0; i < 4; i++){
				int x = v.f + dx[i];
				int y = v.s + dy[i];
				if (i == 3){
					if (x <= n){
						if (mp[make_pair(x, y)] == 0){
							if (mp[make_pair(x, a[x] + 1)] == 1){
								q.push(make_pair(make_pair(x, a[x] + 1), d + 1));
								mp[make_pair(x, a[x] + 1)] = 2;
							}
						}
						else{
							if (mp[make_pair(x, y)] == 1){
								q.push(make_pair(make_pair(x, y), d + 1));
								mp[make_pair(x, y)] = 2;
							}
						}
					}
				}
				if (i == 0){
					if (x >= 1){
						if (mp[make_pair(x, y)] == 0){
							if (mp[make_pair(x, a[x] + 1)] == 1){
								q.push(make_pair(make_pair(x, a[x] + 1), d + 1));
								mp[make_pair(x, a[x] + 1)] = 2;
							}
						}
						else{
							if (mp[make_pair(x, y)] == 1){
								q.push(make_pair(make_pair(x, y), d + 1));
								mp[make_pair(x, y)] = 2;
							}
						}
					}
				}
				if (i == 1){
					if (y >= 1){
						if (mp[make_pair(x, y)] == 1){
							q.push(make_pair(make_pair(x, y), d + 1));
							mp[make_pair(x, y)] = 2;
						}
					}
				}
				if (i == 2){
					if (y <= a[x] + 1){
						if (mp[make_pair(x, y)] == 1){
							q.push(make_pair(make_pair(x, y), d + 1));
							mp[make_pair(x, y)] = 2;
						}
					}
				}
			}
		}

	return 0;

}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <map>

using namespace std;

#define f first
#define s second
#define sz(v) int((v).size())

typedef long long ll;
typedef pair <int, int> pt;

const int N = 100;

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

int n;
int a[N + 1];
pt p, t;
map <pt, int> mp;
queue < pair <pt, int> > q;

int main(){

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

		cin >> n;
		for (int i = 1; i <= n; i++){
			cin >> a[i];
			for (int j = 1; j <= a[i]; j++)
				mp[make_pair(i, j)] = 1;
			mp[make_pair(i, a[i] + 1)] = 1;
		}
		cin >> p.f >> p.s;
		cin >> t.f >> t.s;
		q.push(make_pair(p, 0));
		while (!q.empty()){
			pt v = q.front().f;
			int d = q.front().s;
			if (v == t){
				cout << d;
				return 0;
			}
			q.pop();
			for (int i = 0; i < 4; i++){
				int x = v.f + dx[i];
				int y = v.s + dy[i];
				if (i == 3){
					if (x <= n){
						if (mp[make_pair(x, y)] == 0){
							if (mp[make_pair(x, a[x] + 1)] == 1){
								q.push(make_pair(make_pair(x, a[x] + 1), d + 1));
								mp[make_pair(x, a[x] + 1)] = 2;
							}
						}
						else{
							if (mp[make_pair(x, y)] == 1){
								q.push(make_pair(make_pair(x, y), d + 1));
								mp[make_pair(x, y)] = 2;
							}
						}
					}
				}
				if (i == 0){
					if (x >= 1){
						if (mp[make_pair(x, y)] == 0){
							if (mp[make_pair(x, a[x] + 1)] == 1){
								q.push(make_pair(make_pair(x, a[x] + 1), d + 1));
								mp[make_pair(x, a[x] + 1)] = 2;
							}
						}
						else{
							if (mp[make_pair(x, y)] == 1){
								q.push(make_pair(make_pair(x, y), d + 1));
								mp[make_pair(x, y)] = 2;
							}
						}
					}
				}
				if (i == 1){
					if (x >= 1){
						if (mp[make_pair(x, y)] == 1){
							q.push(make_pair(make_pair(x, y), d + 1));
							mp[make_pair(x, y)] = 2;
						}
					}
				}
				if (i == 2){
					if (x <= n){
						if (mp[make_pair(x, y)] == 1){
							q.push(make_pair(make_pair(x, y), d + 1));
							mp[make_pair(x, y)] = 2;
						}
					}
				}
			}
		}

	return 0;

}