#include #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair P; int n,s,t; ll a[100005]; ll dp[100005]; vector

vec; ll get_len(int p1,int p2){ if(p1>p2)swap(p1,p2); return min(p2-p1,p1+n-p2); } int main(void){ scanf("%d",&n); scanf("%d%d",&s,&t); s--; t--; for(int i=0;i=s && n-(ri-s)<=t))continue; ll val=dp[s+i]; if(ri<=s){ val-=dp[s-ri]; }else{ val+=dp[n]-dp[n-(ri-s)]; } vec.push_back(P(val,i)); }else{ int ri=cn-i; if(s-t<=ri || (i+s-1>=n && (i-1+s-n)>=t))continue; ll val=-dp[s-ri]; if(i+s<=n){ val+=dp[i+s]; }else{ val+=dp[n]+dp[i+s-n]; } vec.push_back(P(val,i)); } } sort(vec.begin(),vec.end()); reverse(vec.begin(),vec.end()); for(int i=0;i=n){ li-=n; } int ri=s-(cn-vec[i].second); if(ri<0){ ri+=n; } //printf("%d %d %d\n",li,ri,vec[i].second); if(vec[i].second==get_len(t,li)+2 && (cn-vec[i].second)==get_len(t,ri)+2){ continue; } if(vec[i].second<=get_len(t,li)+2 && (cn-vec[i].second)<=get_len(t,ri)+2){ printf("%lld\n",vec[i].first*2LL-dp[n]); return 0; } } return 0; }