#include<bits/stdc++.h>
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db double
#define ll long long
#define str string
#define re return
using namespace std;
void bai1()
{
ll s1,s2,v1,v2;
cin>>s1>>v1>>s2>>v2;
if(v1==v2) cout<<-1;
else
{
int t=(s1-s2)/(v2-v1);
if(t<0) cout<<-1;
else cout<<t;
}
}
void bai2()
{
str s,x;
ll res=0;
cin>>s>>x;
while(s.find(x)!= str :: npos)
{
int k=s.find(x);
s.replace(k,x.size(),"_");
res++;
}
cout<<res;
}
void bai3()
{
double x,y,z,h;
cin>>x>>y>>z;
h=z*(x-y);
cout<<(ll)ceil(h/y);
}
ll n,m,k,res;
pair<ll,ll> toado[1002];
void tkiem(ll p,ll &a,pair<ll,ll> &b,pair<ll,ll> &c, ll &d,const map<ll,ll> &pos)
{
c=*pos.upper_bound(p);
if(c.first<n+1) d=(pos.upper_bound(c.first))->first;
b=*(--pos.lower_bound(p));
if(b.first>0) a=(--pos.lower_bound(b.first))->first;
}
void in(ll p,map<ll,ll> &pos,set<pair<ll,ll>,greater<pair<ll,ll>>> &s)
{
ll d=n+10,a=-1,res=++pos[p];
pair<ll,ll> c={0,0},b={0,0};
tkiem(p,a,b,c,d,pos);
if(res>1)
{
s.erase({c.first-b.first-1,b.first});
return;
}
if(a>-1&&b.second==1)
{
s.erase({c.first-a-1,a});
s.insert({p-a-1,a});
}
if(d<n+10&&c.second==1)
{
s.erase({d-b.first-1,b.first});
s.insert({d-p-1,p});
}
s.insert({c.first-b.first-1,b.first});
}
void bai4()
{
ll i,r1,r2,r,c,ma,j;
cin>>m>>n>>k;
for(i=1;i<=k;i++)
{
cin>>r>>c;
toado[i]={r,c};
}
sort(toado+1,toado+k+1);
toado[k+1]={m+1,0};
for(i=1;i<=k;i++)
{
if(toado[i].first>toado[i-1].first)
{
r1=-1;
if(toado[i].first>toado[i-1].first) r1=toado[i-1].first+1;
map<ll,ll> pos;
set<pair<ll,ll>,greater<pair<ll,ll>>> s;
ma=0;
pos.insert({0,1});
pos.insert({n+1,1});
for(j=i;j<=k+1;j++)
{
if(toado[j].first>toado[j-1].first)
{
if(j>1)
{
r2=toado[j].first-1;
ma=(s.begin())->first;
res=max(res,(r2-r1+1)*ma);
if(j<=k) in(toado[j].second,pos,s);
}
else
{
pos[toado[j].second]=1;
s.insert({n,0});
}
}
else in(toado[j].second,pos,s);
}
}
}
cout<<res;
}
void bai5()
{
ll n,i,q,x;
cin>>n;
vector<ll> a(n+1),f(n+1),g(n+1);
for(i=1;i<=n;i++) cin>>a[i];
f[n]=0;
g[n]=a[n];
for(i=n-1;i>0;i--)
{
f[i]=f[i+1]+max(g[i+1]-a[i],0LL);
g[i]=max(g[i+1],a[i]);
}
cin>>q;
while(q--)
{
cin>>x;
cout<<f[x]<<"\n";
}
}
int main()
{
faster
// freopen("DRB.INP","r",stdin);
// freopen("DRB.OUT","w",stdout);
// bai1(); /*max*/
// freopen("ARN.INP","r",stdin);
// freopen("ARN.OUT","w",stdout);
// bai2(); /*max*/
// freopen("TBG.INP","r",stdin);
// freopen("TBG.OUT","w",stdout);
// bai3(); /*max*/
// freopen("HCN.INP","r",stdin);
// freopen("HCN.OUT","w",stdout);
// bai4(); /*max*/
// freopen("VNI.INP","r",stdin);
// freopen("VNI.OUT","w",stdout);
// bai5(); /*max*/
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBmYXN0ZXIgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTtjaW4udGllKDApO2NvdXQudGllKDApOwojZGVmaW5lIGRiIGRvdWJsZQojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIHN0ciBzdHJpbmcKI2RlZmluZSByZSByZXR1cm4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdm9pZCBiYWkxKCkKewoJbGwgczEsczIsdjEsdjI7CgljaW4+PnMxPj52MT4+czI+PnYyOwoJaWYodjE9PXYyKSBjb3V0PDwtMTsKCWVsc2UKC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