# Codeforces Round #354 (Div. 2)

/*************************************************************************
File Name: cf_A.cpp
ID: obsoles1
PROG:
LANG: C++
Mail: 384099319@qq.com
Created Time: 三  5/25 23:08:09 2016
************************************************************************/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)
#define Abs(x,y) ((x)>(y)?((x)-(y)):((y)-(x)))
#define ll long long
#define Mem0(x) memset(x,0,sizeof(x))
#define Mem1(x) memset(x,-1,sizeof(x))
#define MemX(x) memset(x,0x3f,sizeof(x))
#define pb push_back
using namespace std;
const int N=110;
int pos[N];

int main(){
int n,x,i;
scanf("%d",&n);
for(i=1;i<=n;++i){
scanf("%d",&x);
pos[x]=i;
}
int ans;
if(pos[1]==1 || pos[1]==n || pos[n]==1 || pos[n]==n)ans=n-1;
else ans=Max(Max(Abs(pos[1],n),Abs(pos[1],1)),Max(Abs(pos[n],n),Abs(pos[n],1)));
//if(ans<0)ans=-ans;
//ans++;
//cout<<"ans="<<ans<<endl;
//if((pos[1]!=1 && pos[1]!=n) || (pos[n]!=1 && pos[n]!=n))ans++;
printf("%d\n",ans);
}

/*************************************************************************
File Name: cf_B.cpp
ID: obsoles1
PROG:
LANG: C++
Mail: 384099319@qq.com
Created Time: 三  5/25 23:52:58 2016
************************************************************************/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)
#define Abs(x,y) ((x)>(y)?((x)-(y)):((y)-(x)))
#define ll long long
#define Mem0(x) memset(x,0,sizeof(x))
#define Mem1(x) memset(x,-1,sizeof(x))
#define MemX(x) memset(x,0x3f,sizeof(x))
#define pb push_back
using namespace std;
const int N=15;
int bot[N][N];
bool f[N][N];

int main(){
int n,t,i,j,ans;
scanf("%d%d",&n,&t);
ans=0;
bot[1][1]=2048*t;
for(i=1;i<=n;++i){
for(j=1;j<=i;++j){
//cout<<"t="<<k<<endl;
if(bot[i][j]>=2048){
bot[i+1][j]+=(bot[i][j]-2048)/2;
bot[i+1][j+1]+=(bot[i][j]-2048)/2;
ans++;
//cout<<"bot["<<i+1<<"]["<<j<<"]="<<bot[i+1][j]<<endl;
//cout<<"bot["<<i+1<<"]["<<j+1<<"]="<<bot[i+1][j+1]<<endl;
}
}
}
printf("%d\n",ans);
}


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

File Name: cf_C.cpp
ID: obsoles1
PROG:
LANG: C++
Mail: 384099319@qq.com
Created Time: 三  5/25 23:32:36 2016
************************************************************************/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)
#define Abs(x,y) ((x)>(y)?((x)-(y)):((y)-(x)))
#define ll long long
#define Mem0(x) memset(x,0,sizeof(x))
#define Mem1(x) memset(x,-1,sizeof(x))
#define MemX(x) memset(x,0x3f,sizeof(x))
#define pb push_back
using namespace std;
const int N=1e5+10;
char s[N];
int pre_a[N],pre_b[N];

int main(){
int n,i,k;
scanf("%d%d%s",&n,&k,s);
pre_a[0]=pre_b[0]=0;
for(i=1;i<=n;++i){
if(!(s[i-1]-'a')){
pre_a[i]=pre_a[i-1]+1;
pre_b[i]=pre_b[i-1];
}else{
pre_a[i]=pre_a[i-1];
pre_b[i]=pre_b[i-1]+1;
}
}
int low,high,mid,ans=0;
for(i=0;i<=n;++i){
low=i,high=n;
while(low<=high){
mid=(low+high)>>1;
if(pre_a[mid]-pre_a[i]>k && pre_b[mid]-pre_b[i]>k)high=mid-1;
else low=mid+1;
}
ans=Max(ans,high-i);
}
printf("%d\n",ans);
}

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

File Name: cf_D.cpp
ID: obsoles1
PROG:
LANG: C++
Mail: 384099319@qq.com
Created Time: 二  5/31 21:56:49 2016
************************************************************************/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#define Max(x,y) ((x)>(y)?(x):(y))
#define Min(x,y) ((x)<(y)?(x):(y))
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();++it)
#define Abs(x,y) ((x)>(y)?((x)-(y)):((y)-(x)))
#define ll long long
#define Mem0(x) memset(x,0,sizeof(x))
#define Mem1(x) memset(x,-1,sizeof(x))
#define MemX(x) memset(x,0x3f,sizeof(x))
#define pb push_back
using namespace std;
const int N=1010;
char mp[4][N][N];
struct node{
int step,x,y,k;
}s,t;
queue<node> q;
bool vis[4][N][N];
int n,m,sx,sy,ex,ey,mx[]={0,0,1,-1},my[]={1,-1,0,0};

char change(char x){
if(x=='-')return '|';
if(x=='|')return '-';
if(x=='^')return '>';
if(x=='>')return 'v';
if(x=='v')return '<';
if(x=='<')return '^';
if(x=='L')return 'U';
if(x=='U')return 'R';
if(x=='R')return 'D';
if(x=='D')return 'L';
return x;
}

bool left(char x){
if(x=='-' || x=='>' || x=='L' || x=='U' || x=='D' || x=='+')return 1;
return 0;
}

bool right(char x){
if(x=='-' || x=='<' || x=='R' || x=='U' || x=='D' || x=='+')return 1;
return 0;
}

bool up(char x){
if(x=='|' || x=='v' || x=='L' || x=='R' || x=='U' || x=='+')return 1;
return 0;
}

bool down(char x){
if(x=='|' || x=='^' || x=='L' || x=='R' || x=='D' || x=='+')return 1;
return 0;
}

bool deal(node s,node t){
char sw=mp[s.k][s.x][s.y],tw=mp[t.k][t.x][t.y];
//cout<<"sw="<<sw<<" tw="<<tw<<endl;
if(sw=='+'){
if(s.x-1==t.x)return up(tw);
if(s.x+1==t.x)return down(tw);
if(s.y-1==t.y)return left(tw);
if(s.y+1==t.y)return right(tw);
}else if(sw=='-'){
if(s.y-1==t.y)return left(tw);
if(s.y+1==t.y)return right(tw);
}else if(sw=='|'){
if(s.x-1==t.x)return up(tw);
if(s.x+1==t.x)return down(tw);
}else if(sw=='^' && s.x-1==t.x)
return up(tw);
else if(sw=='v' && s.x+1==t.x)
return down(tw);
else if(sw=='>' && s.y+1==t.y)
return right(tw);
else if(sw=='<' && s.y-1==t.y)
return left(tw);
else if(sw=='L'){
if(s.x-1==t.x)return up(tw);
if(s.x+1==t.x)return down(tw);
if(s.y+1==t.y)return right(tw);
}else if(sw=='R'){
if(s.x-1==t.x)return up(tw);
if(s.x+1==t.x)return down(tw);
if(s.y-1==t.y)return left(tw);
}else if(sw=='U'){
if(s.x+1==t.x)return down(tw);
if(s.y-1==t.y)return left(tw);
if(s.y+1==t.y)return right(tw);
}else if(sw=='D'){
if(s.x-1==t.x)return up(tw);
if(s.y-1==t.y)return left(tw);
if(s.y+1==t.y)return right(tw);
}
return 0;
}

void bfs(){
Mem0(vis);
while(!q.empty())q.pop();
s.x=sx,s.y=sy,s.step=0,s.k=0;
vis[0][sx][sy]=1;
q.push(s);
while(!q.empty()){
s=q.front();
//cout<<"s("<<s.x<<','<<s.y<<")   step="<<s.step<<"   k="<<s.k<<endl;
q.pop();
if(s.x==ex && s.y==ey){
printf("%d\n",s.step);
return;
}
for(int i=0;i<4;++i){
t=s;
t.x+=mx[i],t.y+=my[i];
t.step++;
if(t.x<0 || t.x>=n || t.y<0 || t.y>=m || vis[t.k][t.x][t.y] || mp[t.k][t.x][t.y]=='*')continue;
if(deal(s,t)){
q.push(t);
vis[t.k][t.x][t.y]=1;
}
}
t=s;
t.k=(t.k+1)%4;
t.step++;
if(vis[t.k][t.x][t.y])continue;
vis[t.k][t.x][t.y]=1;
q.push(t);
}
puts("-1");
}

int main(){
int i,j,k;
scanf("%d%d",&n,&m);
for(i=0;i<n;++i){
scanf("%s",mp[0][i]);
for(k=1;k<4;++k){
for(j=0;j<m;++j)
mp[k][i][j]=change(mp[k-1][i][j]);
}
}
scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
sx--,sy--,ex--,ey--;
bfs();
}


#### Codeforces Round #444 (Div. 2)-贪心&尺取-Ratings and Reality Shows

2017-11-11 20:11:11

#### Codeforces Round #482 (Div. 2)

2018-05-15 12:51:24

#### Codeforces Round #354 (Div. 2)（B）模拟

2016-05-26 10:25:50

#### Codeforces Round #354 (Div. 2) ABC

2016-05-26 16:22:29

#### Codeforces Round #354 (Div. 2)-Nicholas and Permutation

2016-06-02 22:36:54

#### 【解题报告】Codeforces Round #354 (Div. 2)

2016-06-03 15:55:29

#### Codeforces Round #446 (Div. 2) D. Gluttony

2017-11-18 21:07:25

#### Codeforces Round #354 (Div. 2) A （水题）

2016-05-26 22:28:42

#### Codeforces Round #354 (Div. 2) D

2016-05-23 21:16:27

#### Codeforces Round #354 (Div. 2) E （数学题）

2016-05-26 23:24:08