stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;



const int MAXN=555;

int n;

char str[MAXN][22];

int vis[255][255];

int in[255];

queue<int> q;



bool topsort()

{

    while(!q.empty())   q.pop();

    for(int i=0;i<255;i++)  if(in[i]==0)   q.push(i);

    int num=0;

    while(!q.empty())

    {

        int u=q.front();q.pop();num++;

        for(int i=0;i<255;i++)

            if(vis[u][i]==1)

            {

                in[i]--;

                if(in[i]==0)   q.push(i);

            }

    }

    return num==255;

}



bool check()

{

    memset(vis,0,sizeof vis);memset(in,0,sizeof in);

    for(int i=2;i<=n;i++)

    {

        for(int j=0;str[i][j] || str[i-1][j];j++)

        {

            if(str[i][j]==str[i-1][j])  continue;

            if(!str[i][j])    return false;

            int x=(int)(str[i-1][j]);

            int y=(int)(str[i][j]);

            if(vis[y][x])   return false;

            if(!vis[x][y])

            {

                vis[x][y]=1;

                in[y]++;

            }

            break;

        }

    }

    return topsort();

}





int main()

{

    //freopen("data.txt","r",stdin);

    while(cin>>n && n)

    {

        memset(str,0,sizeof str);

        for(int i=1;i<=n;i++)

            scanf("%s",str[i]);

//        for(int i=1;i<=n;i++)

//        {

//            int len=strlen(str[i]);

//            for(int j=0;j<len;j++)

//                if(str[i][j]>= 'a' && str[i][j]<='z')

//                    continue;

//                else

//                    while(1){}

//        }

        if(check())

            puts("yes");

        else

            puts("no");

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4700942324786044x):
#include<bits/stdc++.h>

using namespace std;

set<int> G[26];

typedef set<int>::iterator it;

int n;

string s[505];

bool flag;

bool vis[26];

int in[26];

int main()

{

	while(~scanf("%d",&n)&&n)

	{

		for(int i=0;i<n;i++)

			cin>>s[i];

		for(int i=0;i<26;i++)

			G[i].clear(),vis[i] = 0,in[i] = 0;

		flag = true;

		for(int x=1;x<n;x++)

			for(int y=0;y<x;y++)

		    {

			    int len1 = s[y].size();

			    int len2 = s[x].size();

			    bool flag1 = true;

			    for(int i=0;i<min(len1,len2);i++)

				    if(s[y][i]!=s[x][i])

			        {

			    	    flag1 = false;

			    	    G[s[y][i]-'a'].insert(s[x][i]-'a');

			    	    break;

			        }

			    if(flag1&&len1>len2)

				    flag = false;

		    }

		int cnt = 0;

		for(int i=0;i<26;i++)

			for(it p = G[i].begin();p!=G[i].end();p++)

			    in[*p]++,cnt++;

		while(1)

		{

			bool flag1 = true;

			for(int i=0;i<26;i++)

				if(in[i]==0&&!vis[i])

				{

					flag1 = false;

					vis[i] = 1;

				    for(it p = G[i].begin();p != G[i].end();p++)

			        {

			        	int v = *p;

			        	cnt--;

			        	in[v]--;

			        }

				}

			if(flag1) break;

		}

		if(cnt!=0) flag = false;

		puts(flag?"yes":"no");

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>



#define maxv 100000



using namespace std;



int n, len, in[maxv], out[maxv], up[100][maxv];

vector<int> tree[maxv];



void dfs(int u, int p, int &k){

  in[u] = k++;

  up[0][u] = p;

  for(int i = 1; i < len; i++)

    up[i][u] = up[i - 1][up[i - 1][u]];



  for(int i = 0; i < tree[u].size(); i++){

    if(tree[u][i] != p)dfs(tree[u][i],u,k);

  }

  out[u] = k++;

}



void init(int root){

  while((1 << len) <= n)len++;

  int k=0;

  dfs(root,root,k);

}



bool isParent(int parent, int child){

  return in[parent] <= in[child] && out[child] <= out[parent];

}



int lca(int a, int b){

  if(isParent(a,b))return a;

  if(isParent(b,a))return b;

  for(int i = len - 1; i >= 0; i--){

    if(!isParent(up[i][a],b))a = up[i][a];

  }

  return up[0][a];

}



int main(void){

  int k,c,q,u,v;



  cin >> n;

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

    cin >> k;

    for(int j=0;j<k;j++){

      cin >> c;

      tree[i].push_back(c);

    }

  }



  init(0);



  cin >> q;

  while(q--){

    cin >> u >> v;

    cout << lca(u,v) << endl;

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4395421440740974x):
#include<iostream>

#include<vector>

#include<algorithm>



#define REP(i, n) for (int i=0;i<int(n);++i)

#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)

#define EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

#define ALL(A) A.begin(), A.end()



using namespace std;



struct HeavyLight {

  int pathCount,n;

  vector<int>size,parent,in,out,path,pathSize,pathPos,pathRoot;

  vector<vector<int> > tree;



  HeavyLight(int n,vector<vector<int> > t)

    :pathCount(0),n(n),size(n),parent(n),in(n),out(n),

     path(n),pathSize(n),pathPos(n),pathRoot(n),tree(t){

    int time=0;

    dfs(0,-1,time);

    buildPaths(0,newPath(0));

  }



  void dfs(int u, int p, int &k){

    in[u]=k++, parent[u]=p, size[u]=1;

    EACH(v,tree[u])if(*v!=p)dfs(*v, u, k),size[u]+=size[*v];

    out[u]=k++;

  }



  int newPath(int u){ pathRoot[pathCount]=u; return pathCount++; }



  void buildPaths(int u, int pt){

    path[u]=pt, pathPos[u]=pathSize[pt]++;

    EACH(v,tree[u])if(*v != parent[u])

      buildPaths(*v, 2*size[*v] >= size[u] ? pt : newPath(*v));

  }



  bool isAncestor(int p, int ch){

    return in[p] <= in[ch] && out[ch] <= out[p];

  }



  int lca(int a,int b){

    for(int root; !isAncestor(root=pathRoot[path[a]],b);a=parent[root]);

    for(int root; !isAncestor(root=pathRoot[path[b]],a);b=parent[root]);

    return isAncestor(a,b)?a:b;

  }

};



//Usage: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C

int main(void){

  ios::sync_with_stdio(false);



  int n;

  cin >> n;

  vector<vector<int> >tree(n);

  

  REP(i,n){

    int k;

    cin >> k;

    REP(j,k){

      int ch;

      cin >> ch;

      tree[i].push_back(ch);

    }

  }



  HeavyLight hl = HeavyLight(n,tree);



  int q;

  cin >> q;

  while(q--){

    int u,v;

    cin >> u >> v;

    cout << hl.lca(u,v) << "\n";

  }

  

  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>



#define maxv 100000



using namespace std;



int n, len, in[maxv], out[maxv], up[100][maxv];

vector<int> tree[maxv];



void dfs(int u, int p, int &k){

  in[u] = k++;

  up[0][u] = p;

  for(int i = 1; i < len; i++)

    up[i][u] = up[i - 1][up[i - 1][u]];



  for(int i = 0; i < tree[u].size(); i++){

    if(tree[u][i] != p)dfs(tree[u][i],u,k);

  }

  out[u] = k++;

}



void init(int root){

  while((1 << len) <= n)len++;

  int k=0;

  dfs(root,root,k);

}



bool isParent(int parent, int child){

  return in[parent] <= in[child] && out[child] <= out[parent];

}



int lca(int a, int b){

  if(isParent(a,b))return a;

  if(isParent(b,a))return b;

  for(int i = len - 1; i >= 0; i--){

    if(!isParent(up[i][a],b))a = up[i][a];

  }

  return up[0][a];

}



int main(void){

  int k,c,q,u,v;



  cin >> n;

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

    cin >> k;

    for(int j=0;j<k;j++){

      cin >> c;

      tree[i].push_back(c);

    }

  }



  init(0);



  cin >> q;

  while(q--){

    cin >> u >> v;

    cout << lca(u,v) << endl;

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4391389289335055x):
#include<iostream>

#include<vector>

#include<algorithm>



#define REP(i, n) for (int i=0;i<int(n);++i)

#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)

#define EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

#define ALL(A) A.begin(), A.end()



using namespace std;



struct HeavyLight {

  int pathCount,n;

  vector<int>size,parent,in,out,path,pathSize,pathPos,pathRoot;

  vector<vector<int> > tree;



  HeavyLight(vector<vector<int> > t)

    :pathCount(0),n(t.size()),size(n),parent(n),in(n),out(n),

     path(n),pathSize(n),pathPos(n),pathRoot(n),tree(t){

    int time=0;

    dfs(0,-1,time);

    buildPaths(0,newPath(0));

  }



  void dfs(int u, int p, int &k){

    in[u]=k++, parent[u]=p, size[u]=1;

    EACH(v,tree[u])if(*v!=p)dfs(*v, u, k),size[u]+=size[*v];

    out[u]=k++;

  }



  int newPath(int u){ pathRoot[pathCount]=u; return pathCount++; }



  void buildPaths(int u, int pt){

    path[u]=pt, pathPos[u]=pathSize[pt]++;

    EACH(v,tree[u])if(*v != parent[u])

      buildPaths(*v, 2*size[*v] >= size[u] ? pt : newPath(*v));

  }



  bool isAncestor(int p, int ch){

    return in[p] <= in[ch] && out[ch] <= out[p];

  }



  int lca(int a,int b){

    for(int root; !isAncestor(root=pathRoot[path[a]],b);a=parent[root]);

    for(int root; !isAncestor(root=pathRoot[path[b]],a);b=parent[root]);

    return isAncestor(a,b)?a:b;

  }

};



//Usage: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C

int main(void){

  ios::sync_with_stdio(false);



  int n;

  cin >> n;

  vector<vector<int> >tree(n);

  

  REP(i,n){

    int k;

    cin >> k;

    REP(j,k){

      int ch;

      cin >> ch;

      tree[i].push_back(ch);

    }

  }



  HeavyLight hl = HeavyLight(tree);



  int q;

  cin >> q;

  while(q--){

    int u,v;

    cin >> u >> v;

    cout << hl.lca(u,v) << "\n";

  }

  

  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>



#define maxv 100000



using namespace std;



int n, len, in[maxv], out[maxv], up[100][maxv];

vector<int> tree[maxv];



void dfs(int u, int p, int &k){

  in[u] = k++;

  up[0][u] = p;

  for(int i = 1; i < len; i++)

    up[i][u] = up[i - 1][up[i - 1][u]];



  for(int i = 0; i < tree[u].size(); i++){

    if(tree[u][i] != p)dfs(tree[u][i],u,k);

  }

  out[u] = k++;

}



void init(int root){

  while((1 << len) <= n)len++;

  int k=0;

  dfs(root,root,k);

}



bool isParent(int parent, int child){

  return in[parent] <= in[child] && out[child] <= out[parent];

}



int lca(int a, int b){

  if(isParent(a,b))return a;

  if(isParent(b,a))return b;

  for(int i = len - 1; i >= 0; i--){

    if(!isParent(up[i][a],b))a = up[i][a];

  }

  return up[0][a];

}



int main(void){

  int k,c,q,u,v;



  cin >> n;

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

    cin >> k;

    for(int j=0;j<k;j++){

      cin >> c;

      tree[i].push_back(c);

    }

  }



  init(0);



  cin >> q;

  while(q--){

    cin >> u >> v;

    cout << lca(u,v) << endl;

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4779562648582205x):
#include<iostream>

#include<vector>

#include<algorithm>



using namespace std;



struct LinkCutTree {

  vector<int>left,right,parent;



  LinkCutTree(int n):left(n,-1),right(n,-1),parent(n,-1){}



  bool is_root(int id){

    return parent[id]<0 || (left[parent[id]]!=id && right[parent[id]]!=id);

  }



  void connect(int ch, int p, bool isL){

    (isL ? left : right)[p] = ch;

    if(ch >= 0)parent[ch] = p;

  }



  void rotate(int id){

    int p = parent[id], q = parent[p];

    bool isL = id==left[p], isRoot = is_root(p);



    connect((isL ? right : left)[id], p, isL);

    connect(p, id, !isL);



    if(!isRoot)connect(id,q,p==left[q]);

    else parent[id]=q;

  }



  void splay(int id){

    while(!is_root(id)){

      int p = parent[id];

      if(!is_root(p))rotate( (id==left[p])^(p==left[parent[p]]) ? p : id );

      rotate(id);

    }

  }



  int expose(int id){

    int last = -1;

    for(int y=id; y>=0; y=parent[y])

      splay(y), left[y]=last, last=y;

    splay(id);

    return last;

  }



  int find_root(int id){

    expose(id);

    while(right[id]!=-1)id=right[id];

    return id;

  }



  void link(int ch, int p){

    expose(ch);

    if(right[ch]>=0)return;

    parent[ch]=p;

  }



  void cut(int id){

    expose(id);

    if(right[id]<0)return;

    parent[right[id]]=-1;

    right[id]=-1;

  }



  int lca(int ch, int p){

    //if(find_root(ch)!=find_root(p))return -1;

    expose(ch);

    return expose(p);

  }

};



int main(void){

  int n;

  cin >> n;



  LinkCutTree tree(n);

  

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

    int k,t;

    cin >> k;

    for(int j=0;j<k;j++){

      cin >> t;

      tree.link(t,i);

    }

  }

  int q;

  cin >> q;

  for(int i=0;i<q;i++){

    int u,v;

    cin >> u >> v;

    cout << tree.lca(u,v) << endl;

  }

   

  return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector>



using namespace std;



const int MAX=1<<17;



vector<int> G[MAX];

int root;

int V;



int vs[MAX*2-1];

int depth[MAX*2-1];

int id[MAX];



int n;

int dat[MAX*4-1];//0-indexed



void rmq_init(int V)

{

	n=1;

	while(n<V)n<<=1;

	for(int i=0;i<2*n-1;i++)dat[i]=-1;

	return;

}



void update(int k,int a)

{

	k+=n-1;

	dat[k]=a;

	while(k>0)

	{

		k=(k-1)/2;

		int b1=dat[k*2+1],b2=dat[k*2+2];

		if(b1!=-1&&b2!=-1)dat[k]=(depth[b1]<=depth[b2]?b1:b2);

		else if(b2!=-1)dat[k]=b2;

		else dat[k]=b1;

	}

	return;

}



int getmin(int a,int b,int k,int l,int r)//[a,b),vertex-number(0),k's range[l,r)

{

	if(r<=a||b<=l)return -1;

	

	if(a<=l&&r<=b)return dat[k];

	else

	{

		int vl=getmin(a,b,k*2+1,l,(l+r)/2);

		int vr=getmin(a,b,k*2+2,(l+r)/2,r);

		if(vl!=-1&&vr!=-1)return (depth[vl]<=depth[vr]?vl:vr);

		else if(vr!=-1)return vr;

		else return vl;

	}

}



void dfs(int v,int p,int d,int &k)

{

	id[v]=k;

	vs[k]=v;

	depth[k]=d;

	k++;

	for(int i=0;i<G[v].size();i++)

	{

		if(G[v][i]!=p)

		{

			dfs(G[v][i],v,d+1,k);

			vs[k]=v;

			depth[k]=d;

			k++;

		}

	}

	return;

}



void init()

{

	int k=0;

	root=0;

	dfs(root,-1,0,k);

	rmq_init(V*2-1);

	for(int i=0;i<V*2-1;i++)update(i,i);

	return;

}



int lca(int u,int v)

{

	if(id[u]>id[v])swap(u,v);

	return vs[getmin(id[u],id[v]+1,0,0,n)];

}



int main()

{

	cin>>V;

	int k,c;

	for(int i=0;i<V;i++)

	{

		cin>>k;

		for(int j=0;j<k;j++)

		{

			cin>>c;

			G[i].push_back(c);

			G[c].push_back(i);

		}

	}

	init();

	int q;

	cin>>q;

	int u,v;

	for(int i=0;i<q;i++)

	{

		cin>>u>>v;

		cout<<lca(u,v)<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.228432588979567x):
#include<iostream>

#include<algorithm>

#include<vector>

using namespace std;

const int MAX=100000;

const int logMAX=17;//2^17>=100000(=MAX)



int V;

vector<int> G[MAX];

int root;

int parent[logMAX][MAX];

int depth[MAX];



void dfs(int v,int p,int d)

{

	parent[0][v]=p;

	depth[v]=d;

	for(int i=0;i<G[v].size();i++)

	{

		if(G[v][i]!=p)dfs(G[v][i],v,d+1);

	}

	return;

}



void init()

{

	dfs(root,-1,0);

	for(int k=0;k+1<logMAX;k++)

	{

		for(int v=0;v<V;v++)

		{

			if(parent[k][v]<0)parent[k+1][v]=-1;

			else parent[k+1][v]=parent[k][parent[k][v]];

		}

	}

	return;

}



int lca(int u,int v)

{

	if(depth[u]>depth[v])swap(u,v);

	for(int k=0;k<logMAX;k++)

	{

		if((depth[v]-depth[u])>>k&1)

		{

			v=parent[k][v];

		}

	}

	if(u==v)return u;

	for(int k=logMAX-1;k>=0;k--)

	{

		if(parent[k][u]!=parent[k][v])

		{

			u=parent[k][u];

			v=parent[k][v];

		}

	}

	return parent[0][u];

}



int main()

{

	cin>>V;

	root=0;

	int k,c;

	for(int i=0;i<V;i++)

	{

		cin>>k;

		for(int j=0;j<k;j++)

		{

			cin>>c;

			G[i].push_back(c);

			G[c].push_back(i);

		}

	}

	init();

	int q;

	cin>>q;

	int u,v;

	for(int i=0;i<q;i++)

	{

		cin>>u>>v;

		cout<<lca(u,v)<<endl;

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1<<17;// = 131072

const ll INF = (1e9)+10;



/*dat???????????????N?????????*/



class RMQ{

public:

  ll n,dat[2*N-1];



  //?????????

  RMQ(){

    n=N;

    for(int i=0;i<2*n-1;i++) dat[i]=INF;

  }

  

  //k???????????????a????????´

  void update(int k,ll a){

    k+=n-1;

    dat[k]=a;

    while(k>0){

      k=(k-1)/2;

      dat[k]=min(dat[k*2+1],dat[k*2+2]);

    }

  }

  

  //[a,b)???????°????????±??????? query(a,b,0,0,n)

  ll query(int a,int b,int k=0,int l=0,int r=N){

    if(r<=a||b<=l)return INF;

    if(a<=l&&r<=b)return dat[k];



    ll vl=query(a,b,k*2+1,l,(l+r)/2);

    ll vr=query(a,b,k*2+2,(l+r)/2,r);

    return min(vl,vr);

  }

};





ll n,A[N];

vector<int>Idx;

ll L[N],R[N];





void calc(ll arr[]){

  RMQ rmq;

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

    int idx = lower_bound(Idx.begin(),Idx.end(),A[i]) - Idx.begin();

    ll val = -rmq.query(0,idx); //A[i]???????°???????????????§?????§???index?????????

    if(val == -INF) val = -1;



    arr[i] = i - val - 1;

    rmq.update(idx,-i);

  }

}



int main(){

  cin>>n;

  Idx.resize(n);

  for(int i=0;i<n;i++)cin>>A[i],Idx[i] = A[i];

  sort(Idx.begin(),Idx.end());

  Idx.erase(unique(Idx.begin(),Idx.end()),Idx.end());

  

  calc(L);

  reverse(A,A+n);

  calc(R);

  reverse(A,A+n);



  ll ans=0;

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

    ll w = L[i]+R[n-1-i]+1;

    ans = max(ans,w*A[i]);

  }

  cout<<ans<<endl;

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.437980982859472x):
#include <bits/stdc++.h>

#define int long long

#define N 100010

using namespace std;

typedef pair<int,int> P;

int n,A[N];





signed main(){

  

  P Idx[N];

  cin>>n;

  for(int i=0;i<n;i++)cin>>A[i],Idx[i] = P(A[i],i);

  sort(Idx,Idx+n);

  Idx[n] = P(-1,-1);  



  set<int> S;

  S.insert(-1);

  S.insert(n);



  int ans = 0;

  vector<int> ls;

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

    int h = Idx[i].first;

    int idx = Idx[i].second;

    int l =idx-(*(--S.upper_bound(idx)))-1;

    int r =(*S.upper_bound(idx)) -idx-1;

    ans=max(ans,(r+l+1)*h);

    ls.push_back(idx);

    if(Idx[i+1].first!=h){

      for(int j:ls)S.insert(j);

      ls.clear();

    }

  }

  cout<<ans<<endl;

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1<<17;// = 131072

const ll INF = (1e9)+10;



/*dat???????????????N?????????*/



class RMQ{

public:

  ll n,dat[2*N-1];



  //?????????

  RMQ(){

    n=N;

    for(int i=0;i<2*n-1;i++) dat[i]=INF;

  }

  

  //k???????????????a????????´

  void update(int k,ll a){

    k+=n-1;

    dat[k]=a;

    while(k>0){

      k=(k-1)/2;

      dat[k]=min(dat[k*2+1],dat[k*2+2]);

    }

  }

  

  //[a,b)???????°????????±??????? query(a,b,0,0,n)

  ll query(int a,int b,int k=0,int l=0,int r=N){

    if(r<=a||b<=l)return INF;

    if(a<=l&&r<=b)return dat[k];



    ll vl=query(a,b,k*2+1,l,(l+r)/2);

    ll vr=query(a,b,k*2+2,(l+r)/2,r);

    return min(vl,vr);

  }

};





ll n,A[N];

vector<int>Idx;

ll L[N],R[N];





void calc(ll arr[]){

  RMQ rmq;

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

    int idx = lower_bound(Idx.begin(),Idx.end(),A[i]) - Idx.begin();

    ll val = -rmq.query(0,idx); //A[i]???????°???????????????§?????§???index?????????

    if(val == -INF) val = -1;



    arr[i] = i - val - 1;

    rmq.update(idx,-i);

  }

}



int main(){

  cin>>n;

  Idx.resize(n);

  for(int i=0;i<n;i++)cin>>A[i],Idx[i] = A[i];

  sort(Idx.begin(),Idx.end());

  Idx.erase(unique(Idx.begin(),Idx.end()),Idx.end());

  

  calc(L);

  reverse(A,A+n);

  calc(R);

  reverse(A,A+n);



  ll ans=0;

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

    ll w = L[i]+R[n-1-i]+1;

    ans = max(ans,w*A[i]);

  }

  cout<<ans<<endl;

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.763915682860284x):
#include <bits/stdc++.h>

#define int long long

#define N 200000

using namespace std;

int n;

struct dat{int h,i;};



int calc(int A[]){

  stack <dat> S;

  int res = 0;

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

    int h = A[i];

    if(S.empty() || S.top().h < h) S.push((dat){h,i});

    else if(S.top().h > h){

      int ni = i;

      while(!S.empty() && S.top().h > h){

        dat t = S.top(); S.pop();

        ni = t.i;

        int area = (i - t.i) * t.h;

        res = max(res,area);

      }

      res = max(res,(i-ni)*h);

      S.push((dat){h,ni});

    }

  }

  return res;

}



int A[N];

signed main(){

  cin>>n;

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

  cout<<calc(A)<<endl;

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define int long long

#define N 100010

using namespace std;

typedef pair<int,int> P;

int n,A[N];





signed main(){

  

  P Idx[N];

  cin>>n;

  for(int i=0;i<n;i++)cin>>A[i],Idx[i] = P(A[i],i);

  sort(Idx,Idx+n);

  Idx[n] = P(-1,-1);  



  set<int> S;

  S.insert(-1);

  S.insert(n);



  int ans = 0;

  vector<int> ls;

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

    int h = Idx[i].first;

    int idx = Idx[i].second;

    int l =idx-(*(--S.upper_bound(idx)))-1;

    int r =(*S.upper_bound(idx)) -idx-1;

    ans=max(ans,(r+l+1)*h);

    ls.push_back(idx);

    if(Idx[i+1].first!=h){

      for(int j:ls)S.insert(j);

      ls.clear();

    }

  }

  cout<<ans<<endl;

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.6175003200498628x):
#include <bits/stdc++.h>

#define int long long

#define N 200000

using namespace std;

int n;

struct dat{int h,i;};



int calc(int A[]){

  stack <dat> S;

  int res = 0;

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

    int h = A[i];

    if(S.empty() || S.top().h < h) S.push((dat){h,i});

    else if(S.top().h > h){

      int ni = i;

      while(!S.empty() && S.top().h > h){

        dat t = S.top(); S.pop();

        ni = t.i;

        int area = (i - t.i) * t.h;

        res = max(res,area);

      }

      res = max(res,(i-ni)*h);

      S.push((dat){h,ni});

    }

  }

  return res;

}



int A[N];

signed main(){

  cin>>n;

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

  cout<<calc(A)<<endl;

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define FLASH ios_base::sync_with_stdio(0);

#define ll long long

#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;

#define deb(x)cout<<"#x = "<<(x)<<endl;

#define pb push_back

#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define endl "\n"

#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";

#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";





using namespace std;



ll n,r;



int main(){

FLASH;

cin>>n>>r;

if(n<10)cout<<r+(100*(10-n))<<endl;

else cout<<r<<endl;













return 0;

} 


// Faster C++ solution for the same problem (measured speedup: 5.331058013799857x):
#include<stdio.h>



int main(){

int a,b;



scanf("%d%d", &a, &b);

if(a<10)printf("%d\n", (100*(10-a)+b));

else printf("%d\n", b);



	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int a,b;

int main() {

cin>>a>>b;

if(a<10){

	cout<<b+(100*(10-a));

}else{

	cout<<b;

}

}

// Faster C++ solution for the same problem (measured speedup: 5.251331035078426x):
#include<stdio.h>



int main(){

int a,b;



scanf("%d%d", &a, &b);

if(a<10)printf("%d\n", (100*(10-a)+b));

else printf("%d\n", b);



	return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main ()

{

    int N,R,S,A;

    cin>>N>>R;

    if(N<10)

    {

    S=100*(10-N);

    A=R+S;

    cout<<A<<endl;

    }

    else

        cout<<R<<endl;

    return 0;



}

// Faster C++ solution for the same problem (measured speedup: 5.260664467057896x):
#include<stdio.h>



int main(){

int a,b;



scanf("%d%d", &a, &b);

if(a<10)printf("%d\n", (100*(10-a)+b));

else printf("%d\n", b);



	return 0;

}
// Slower C++ solution:
#include <iostream>

using namespace std;

//zakha



int N,R;



int main () {

    cin >> N >> R;

    if (N >= 10) {

        cout << R << endl;

    } else {

        cout << R + 100*(10-N) << endl;

    

    }

}




// Faster C++ solution for the same problem (measured speedup: 5.2604433370995505x):
#include<stdio.h>



int main(){

int a,b;



scanf("%d%d", &a, &b);

if(a<10)printf("%d\n", (100*(10-a)+b));

else printf("%d\n", b);



	return 0;

}
// Slower C++ solution:
#include <iostream>

using namespace std;



// Caleb Faith Adnaka XI105

int main() {



    int N,R;

    cin >> N;

    cin >> R;



    if (N >= 10){

        cout << R << "\n";

    }

    else{

        cout << R + (100 * (10-N)) << "\n";

    }



}

// Faster C++ solution for the same problem (measured speedup: 5.2630537622082505x):
#include<stdio.h>



int main(){

int a,b;



scanf("%d%d", &a, &b);

if(a<10)printf("%d\n", (100*(10-a)+b));

else printf("%d\n", b);



	return 0;

}