# AtCoder Grand Contest 015

## A - A+...+B Problem

#include<iostream>
using namespace std;
long long n,a,b,l,r;
int main()
{
cin>>n>>a>>b;
if(a>b){puts("0");return 0;}
l=b+(n-1)*a,r=a+(n-1)*b;
cout<<max(0ll,r-l+1)<<endl;
return 0;
}

## B - Evilator

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n;long long ans;
char S[100010];
int main()
{
scanf("%s",S+1);n=strlen(S+1);
for(int i=1;i<=n;++i)
if(S[i]=='U')ans+=(n-i)+2*(i-1);
else ans+=2*(n-i)+(i-1);
printf("%lld\n",ans);
return 0;
}

## C - Nuske vs Phantom Thnook

#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 2010
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
int n,m,Q;
char g[MAX][MAX];
int s[MAX][MAX],sl[MAX][MAX],su[MAX][MAX];
int Calc(int s[][MAX],int x1,int y1,int x2,int y2)
{
if(x1>x2||y1>y2)return 0;
return s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1];
}
int main()
{
for(int i=1;i<=n;++i)scanf("%s",g[i]+1);
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
s[i][j]=(g[i][j]=='1');
sl[i][j]=(g[i][j]=='1'&&g[i][j-1]=='1');
su[i][j]=(g[i][j]=='1'&&g[i-1][j]=='1');
}
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
sl[i][j]+=sl[i-1][j]+sl[i][j-1]-sl[i-1][j-1];
su[i][j]+=su[i-1][j]+su[i][j-1]-su[i-1][j-1];
}
while(Q--)
{
printf("%d\n",Calc(s,x1,y1,x2,y2)-Calc(sl,x1,y1+1,x2,y2)-Calc(su,x1+1,y1,x2,y2));
}
return 0;
}

## D - A or...or B Problem

$[A,B]$之间的数构成的非空集合的$or$值有多少种。

#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long
ll A,B,ans;
int main()
{
cin>>A>>B;
if(A==B){puts("1");return 0;}
int k=60;
for(;~k;--k)
{
if((A>>k&1)^(B>>k&1))break;
if(A>>k&1)A^=1ll<<k,B^=1ll<<k;
}
int l=k-1;
while((~l)&&!(B&(1ll<<l)))--l;
ll L=(!~l)?B:((1ll<<k)+(1ll<<(l+1))-1);
ll R=(1ll<<k)+A;
ans=(1ll<<(k+1))-A;
if(L+1<R)ans-=R-L-1;
printf("%lld\n",ans);
return 0;
}

## E - Mr.Aoki Incubator

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MOD 1000000007
#define MAX 200200
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
struct Node{int x,v;}p[MAX];
int S[MAX],top;
bool operator<(Node a,Node b){return a.v<b.v;}
struct Line{int l,r;}a[MAX];
bool operator<(Line a,Line b){if(a.r!=b.r)return a.r<b.r;return a.l<b.l;}
int f[MAX],s[MAX],ans,n;
int main()
{
sort(&p[1],&p[n+1]);
for(int i=1;i<=n;++i)
{
if(!top||p[i].x>p[S[top]].x)S[++top]=i;
int l=1,r=top,ret=i;
while(l<=r)
{
int mid=(l+r)>>1;
if(p[S[mid]].x>=p[i].x)r=mid-1,ret=mid;
else l=mid+1;
}
a[i].l=S[ret];
}
top=0;
for(int i=n;i>=1;--i)
{
if(!top||p[i].x<p[S[top]].x)S[++top]=i;
int l=1,r=top,ret=i;
while(l<=r)
{
int mid=(l+r)>>1;
if(p[S[mid]].x<=p[i].x)r=mid-1,ret=mid;
else l=mid+1;
}
a[i].r=S[ret];
}
sort(&a[1],&a[n+1]);
for(int i=1,p=1;i<=n;++i)
{
while(a[p].r<a[i].l-1)++p;
f[i]=(s[i-1]-s[p-1]+MOD)%MOD;
if(a[i].l==1)f[i]=(f[i]+1)%MOD;
if(a[i].r==n)ans=(ans+f[i])%MOD;
s[i]=(s[i-1]+f[i])%MOD;
}
printf("%d\n",ans);
return 0;
}

## F - Kenus the Ancient Greek

#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define ll long long
#define MOD 1000000007
#define pi pair<ll,ll>
#define mp make_pair
{
ll x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
ll f[110];
vector<pi> a[110];
int main()
{
f[0]=f[1]=1;
for(int i=2;i<=100;++i)f[i]=f[i-1]+f[i-2];
a[1].push_back(mp(1,2));a[1].push_back(mp(1,3));a[1].push_back(mp(1,4));
for(int i=1;i<=100;++i)
for(int j=0,l=a[i].size();j<l;++j)
{
ll x=a[i][j].second,y=a[i][j].first+x;
while(y<=f[i+3]+f[i])a[i+1].push_back(mp(x,y)),y+=x;
}
while(T--)
{
}