stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod=998244353;

ll ksm(ll a,ll b)

{

	ll ans=1;

	while(b)

	{

		if(b&1) ans=ans*a%mod;

		b/=2;

		a=a*a%mod;

	}

	return ans;

}

int main()

{

	ll n,x,ans=1,s[100100],num[100100];

	memset(num,0,sizeof num);

	cin>>n;

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

	{

		cin>>x;

		if(!i&&x) ans=0;

		else if(i&&!x) ans=0;

		num[x]++;

	}

	if(ans)

	{

//		ans=num[1];

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

			if(num[i]&&num[i-1])

				ans=ans*ksm(num[i-1],num[i])%mod;

			else if(num[i]&&!num[i-1]) ans=0;

	}

	cout<<ans;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<iostream>

#include<cmath>

#include<algorithm>

#include<cstring>

#include<cctype>

#include<vector>

#include<stack>

#include<queue>

#include<ctime>

#include<map>

#define ll long long

#define ld long double

#define ull unsigned long long

using namespace std;

const ll mod = 998244353;

const int maxn = 101001;

ll a[maxn];

ll mul(ll x,ll y,ll z)

{

    ll sm = (ld)x/z*y;

    return ((ull)x*y-(ull)sm*z+z)%z;

}

ll qpow(ll x,ll y,ll z)

{

    ll ans = 1;

    x %= z;

    for(ll i=y;i;i>>=1){

        if(i&1) ans = mul(ans,x,z);

        x = mul(x,x,z);

    }

    return ans%z;

}

int main(void)

{

    int n,x;

    scanf("%d",&n);

    cin>>x;	//判断首位是否为0

    if(x!=0){

        printf("0\n");

        return 0;

    }

    a[x]++;

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

        scanf("%d",&x);

        a[x]++;

    }

    if(a[0]>1){	//判断是否多个0

        printf("0\n");

        return 0;

    }

    int ret = 0;

    ll ans = 1,pr = 1;

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

        if(a[i]==0){	//判断是否有间隔

            if(ret!=n)  ans = 0;

            break;

        }

        ans = mul(ans,qpow(pr,a[i],mod),mod);

        pr = a[i];

        ret += (int)a[i];

    }

    printf("%lld\n",ans);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ll long long

#define double long double

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

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

#define mod (ll)(1e9+7)

#define inf (ll)(3e18+7)

#define pi (double) acos(-1)

#define P pair<int,int>

#define PiP pair<int,pair<int,int>>

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

using namespace std;

 

int main() {

    ll n, ans=1, mo = 998244353;

    cin >> n;

    vector<ll> d(n), num(100004, 0);

    rep(i, n){

        cin >> d.at(i);

        num[d.at(i)]++;

    }

    if(d.at(0) != 0)ans=0;

    sort(all(d));

    if(num[0] != 1)ans=0;

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

        if(d.at(i) - d.at(i-1) > 1)ans=0;

        ans = ans*num[d.at(i)-1]%mo;

    }

    cout << ans << endl;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define ll long long

#define double long double

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

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

#define mod (ll)(1e9+7)

#define inf (ll)(3e18+7)

#define pi (double) acos(-1)

#define P pair<int,int>

#define PiP pair<int,pair<int,int>>

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

using namespace std;

 

int main() {

    ll n, now=-1, ans=1, mo = 998244353, bf=1, ne=0;

    cin >> n;

    vector<ll> d(n);

    rep(i, n)cin >> d.at(i);

    if(d.at(0) != 0)ans=0;

    sort(all(d));

    rep(i, n){

        if(d.at(i) == now)ne++;

        else{

            if(now+1 != d.at(i)){

                ans = 0;

                break;        

            }

            else{

                now++;

                bf=ne;

                ne=1;

            }

        }

        if(i){

            ans *= bf;

            ans %= mo;

        }

    }

    cout << ans;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <stdio.h>

#include <vector>

#include <algorithm>

#include<math.h>

#include<string.h>

#include<queue>



using namespace std;



#define M  100000+100

#define mod 998244353

typedef long long ll;



ll a[M];

ll b[M];



ll pow_mod(ll a, ll n)

{

    ll ans = 1;

    a=a%mod;

    while(n){

        if(n&1){

            ans = (ans * a) % mod;

        }

        a = (a * a) % mod;

        n >>= 1;

    }

    return ans;

}

int main()

{



    ll n;

    cin>>n;

    memset(b,0,sizeof(b));

    ll c,sum=1;

    ll maxx=-1;

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

    {

        cin>>a[i];

        b[a[i]]++;

        maxx=max(maxx,a[i]);

    }

    if(a[1]||b[0]>1) cout<<"0";

    else

    {

        sum=1;

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

        {

            if(!b[i-1])

            {

                sum=0;

                break;

            }

            else

            {

                ll k=pow_mod(b[i-1],b[i]);

                sum=(sum*k)%mod;

            }

        }

        cout<<sum;

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<iostream>

#include<algorithm>

#include<string.h>

#include<math.h>

#define ll long long

using namespace std;

int main()

{

    int n;

    scanf("%d",&n);

    ll a[100005],i;

    ll b[100005];

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

        scanf("%lld",&a[i]),b[i]=0;

    if(a[0]!=0)

            printf("0\n");

    else

    {

        ll ans=1;

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

            b[a[i]]++;

         if(b[0]>1) cout << "0" ; 

        else{

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

        {

            ans*=b[a[i]-1];

            ans%=998244353;

        }

            

        printf("%lld\n",ans);}

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

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

#define MOD 998244353



long long pow_mod(long long x, long long y){



    long long tmp = 1;

    for(int i=1; i<=y; i++){

        tmp *= x;

        tmp %= MOD;

    }

    return tmp;

}



int main()

{

    long long n;

    cin >> n;

    vector<int> d(n);

    int v[100000] = {0};

    int max_n = 0;

    rep(i, n){

        cin >> d[i];

        max_n = max(max_n, d[i]);

        v[d[i]]++;

    }



    if(d[0] != 0 || v[0] != 1){

        cout << 0;

        return 0;

    }



    long long hen = v[1], youso;

    long long ans = 1;

    for(int i=2; i<=max_n; i++){

        youso = v[i];

        if(v[i] == 0){

            cout << 0;

            return 0;

        }

        ans *= pow_mod(hen, youso);

        ans %= MOD;

        hen = youso;

    }



    cout << ans;



    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

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

#define MOD 998244353



long long pow_mod(long long x, long long y){



    long long res = x;

    for(int i=1; i<y; i++){

        res *= x;

        res %= MOD;

    }

    return res;

}



int main()

{

    long long n;

    cin >> n;

    vector<int> v(n, 0);

    int max_n = 0;

    rep(i, n){

        int d;

        cin >> d;

        if(i == 0 && d != 0){

            cout << 0;

            return 0;

        }

        max_n = max(max_n, d);

        v[d]++;

    }



    if(v[0] != 1){

        cout << 0;

        return 0;

    }



    long long pre = v[1], now;

    long long ans = 1;

    for(int i=2; i<=max_n; i++){

        now = v[i];

        if(v[i] == 0){

            cout << 0;

            return 0;

        }

        ans *= pow_mod(pre, now);

        ans %= MOD;

        pre = now;

    }



    cout << ans;



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<vector>

#include<iostream>



using namespace std;



class Cake;



vector<Cake> pieces;



class Cake {

public:

  int w;

  int d;



  Cake(int w, int d) {

    this->w = w;

    this->d = d;

  }



  void cut(int s) {

    int t = s%(w+d);

    int a, b;

    if(t<w) {

      // vertical

      if(t<w-t) {

	a = t;

	b = w-t;

      } else {

	a = w-t;

	b = t;

      }

      pieces.push_back(Cake(a, d));

      pieces.push_back(Cake(b, d));

    }

    else {

      // horizontal

      t -= w;

      if(t<d-t) {

	a = t;

	b = d-t;

      } else {

	a = d-t;

	b = t;

      }

      pieces.push_back(Cake(w, a));

      pieces.push_back(Cake(w, b));

    }

  }

};



bool area(const Cake &a, const Cake &b) {

  return a.w*a.d < b.w*b.d;

}



int main() {

  while(1) {

    int n, w, d;

    cin >> n;

    cin >> w;

    cin >> d;



    if(n==0 && w==0 && d==0) break;



    pieces.clear();

    pieces.push_back(Cake(w, d));



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

      int p, s;

      cin >> p;

      cin >> s;

      // p Í 1` ÈÌÅ

      p-=1;

      vector<Cake>::iterator it = pieces.begin()+p;

      Cake cake = pieces.at(p);

      pieces.erase(it);

      cake.cut(s);

    }



    // sort

    int count=0;

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

      for(int j=0; j<pieces.size(); j++) {

	int s = pieces.at(j).w * pieces.at(j).d;

	if(s==i) {

	  cout << s;

	  count++;

	  if(pieces.size()!=count) {

	    cout << ' ';

	  }

	}

      }

      //sort(pieces.begin(), pieces.end(), area);

    }





    /*

    for(int i=0; i<pieces.size(); i++) {

      cout << (pieces.at(i).w * pieces.at(i).d);

      cout << ' ';

    }

    */

    cout << "\n";

  }

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int> pii;



int main(){

  int n,w,d;

  while(cin >> n >> w >> d, w){

    vector<pii> v;

    v.push_back(pii(w,d));



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

      int id,s;

      cin >> id >> s; id--;

      pii cut = v[id];

      w = cut.first, d = cut.second;

      v.erase(v.begin() + id);



      s %= w+d;

      if(s<w){

	int nw1 = min(s,w-s), nw2 = max(s,w-s);

	v.push_back(pii(nw1,d));

	v.push_back(pii(nw2,d));

      }else{

	int nd1 = min(s-w,d-s+w), nd2 = max(s-w,d-s+w);

	v.push_back(pii(w,nd1));

	v.push_back(pii(w,nd2));

      }

    }



    vector<int> p;

    for(int i=0;i<(int)v.size();i++)p.push_back(v[i].first*v[i].second);

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

    for(int i=0;i<(int)v.size();i++){

      cout << p[i] << (i+1==(int)p.size()?"\n":" ");

    }

  }

}

// Fastest known solution for this problem:
// Original C++ solution (slower):


#include<algorithm>

#include<iostream>

#include<vector>



using namespace std;



const int MAXN = 300010;

int cnt[MAXN];

int f[MAXN];

int main(){

    int n;

    cin >> n;

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

        int a;

        cin >> a;

        cnt[a]++;

    }



    vector<int> v;

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

        if(cnt[i] > 0){

            v.push_back(cnt[i]);

        }

    }



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



    int p = 0;

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

        while(p<v.size() && v[p]<i){

            p++;

        }



        f[i] = f[i-1] + v.size() - p;

    }



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

        f[i] /= i;

    }



    p = n;

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

        while(p>0 && f[p] < i)

            p--;

        cout << p<<"\n";

    }



}




// Optimized solution to the same problem (faster):
#include <iostream>

#include <bits/stdc++.h>



using namespace std;

int a[500000],b[500000],n;

long long sums,ans;



int main()

{

    scanf("%d",&n);

    long long sums = 0;int tmp;

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

        scanf("%d",&tmp);++a[tmp-1];

    }



    vector<int> vn;

    sort(a,a+n);reverse(a,a+n);

    int j = n-1;

    int rs = 0;

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

        while(j>=0&&a[j]<i){

            rs += a[j--];

        }

        b[i] = rs/i + (j+1);

    }



    j = n;

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

        while(j>=1&&b[j]<i) --j;

        printf("%d\n",j);

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

inline void rd(int &x) {

	char ch; for(;!isdigit(ch=getchar()););

	for(x=ch-'0';isdigit(ch=getchar());)x=x*10+ch-'0';

}

typedef long long LL;

const int MAXN = 300005;

int N, n, a[MAXN], cnt[MAXN];

LL sum[MAXN];

int ans[MAXN];



inline bool chk(int k, int x) {

	int pos = upper_bound(a + 1, a + n + 1, x) - a;

	return sum[pos-1] + 1ll*(n-pos+1)*x >= 1ll*k*x;

}



int main() {

	rd(N);

	for(int i = 1, x; i <= N; ++i) rd(x), ++cnt[x];

	for(int i = 1; i <= 300000; ++i) if(cnt[i]) a[++n] = cnt[i];

	sort(a + 1, a + n + 1);

	for(int i = 1; i <= n; ++i) sum[i] = sum[i-1] + a[i];

	int now = 0;

	for(int k = n; k >= 1; --k) {

		while(now < N && chk(k, now+1)) ++now;

		ans[k] = now;

	}

	for(int i = 1; i <= N; ++i) printf("%d\n", ans[i]);

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

inline void rd(int &x) {

	char ch; for(;!isdigit(ch=getchar()););

	for(x=ch-'0';isdigit(ch=getchar());)x=x*10+ch-'0';

}

typedef long long LL;

const int MAXN = 300005;

int n, cnt[MAXN];

LL sum[MAXN];

int ans[MAXN];



inline bool chk(int k, int x) { return sum[x] >= 1ll*k*x; }



int main() {

	rd(n);

	for(int i = 1, x; i <= n; ++i) rd(x), ++cnt[x], ++sum[cnt[x]];

	for(int i = 1; i <= n; ++i) sum[i] += sum[i-1];

	int now = 0;

	for(int k = n; k >= 1; --k) {

		while(now < n && chk(k, now+1)) ++now;

		ans[k] = now;

	}

	for(int i = 1; i <= n; ++i) printf("%d\n", ans[i]);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<string>

#include<vector>

#include<algorithm>



using namespace std;



typedef struct

{

    string name;

    int point;

    int num;

}food;

food A[10001];

bool paixu(const food &a,const food &b)

{

    if(a.name != b.name)

        return a.name<b.name;

    return a.point > b.point;

    

}

int main()

{

    int n;

    cin>>n;

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

    {

        cin>>A[i].name>>A[i].point;

        A[i].num = i+1;

    }

    sort(A,A+n,paixu);

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

        cout<<A[i].num<<endl;

        return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

const int N = 100 + 3;

char buffer[N];

int main() {

#ifndef ONLINE_JUDGE

//	freopen("input.in", "r", stdin);

//	freopen("output.out", "w", stdout);

#endif

	int n;

	scanf("%d", &n);

	pair<string, pair<int, int>> p[N];

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

		int a;

		scanf("%s %d", buffer, &a);

		p[i] = {buffer, make_pair(-a, i + 1)};

	}

	sort(p, p + n);

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

		printf("%d\n", p[i].second.second);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<stdio.h>

#include<bits/stdc++.h>

using namespace std;

struct node

{

    string s;

    int x,num;

}a[100000];

int cmp1(node a,node b)

{

    if(a.s==b.s)

    {

        return a.x>b.x;

    }

    else

    {

        return a.s<b.s;

    }

}

int main()

{

    int n;

    scanf("%d",&n);

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

    {

        a[i].num=i;

        cin>>a[i].s;

        scanf("%d",&a[i].x);

    }

    sort(a+1,a+n+1,cmp1);

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

    {

        printf("%d\n",a[i].num);

    }



    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



int main() {

    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);



    int n;

    cin >> n;



    vector<int> score(n);

    vector<string> name(n);

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

        cin >> name[i] >> score[i];





    vector<int> order(n);

    iota(order.begin() , order.end() , 0);



    sort(order.begin() , order.end() , [&](int i , int j){

        if (name[i] != name[j])

            return name[i] < name[j];

        return score[i] > score[j];

    });



    for (int x : order)

        cout << x + 1 << '\n';

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<iostream>

#include<string>

#include<algorithm>

using namespace std;

int n;

struct node{

	string nm; int sc,id;

	bool operator <(const node &j) const {

		return nm<j.nm||(nm==j.nm&&sc>j.sc);

	}

}re[200010];

int main(){

	scanf("%d",&n);

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

		cin>>re[i].nm>>re[i].sc;

		re[i].id=i;

	}

	sort(re+1,re+n+1);

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

		cout<<re[i].id<<endl;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<iostream>

#include<algorithm>

#include<string.h>

using namespace std;

typedef struct{

	char str[101];

	int pri;

	int no;

}node;

node p[101];

bool cmp(node a,node b)

{

	if(a.str!=b.str)

    return strcmp(a.str,b.str)<0;

    else

    return a.pri<b.pri;

}

int main()

{

	int n;

	cin>>n;

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

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

		cin>>p[i].pri;

		p[i].no = i+1;

	}

	

	sort(p, p+n, cmp);

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

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

		if(strcmp(p[j].str,p[j+1].str)==0 && p[j].pri<p[j+1].pri)

			swap(p[j],p[j+1]);

	}

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

	cout<<p[i].no<<endl;

	return 0;

 } 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<string>

#include<iostream>

#include<algorithm>

using namespace std;

struct node

{

    string a;

    int b;

    int y;

} m[10005];

int main()

{

    int n;

    cin>>n;

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

    {

        cin>>m[i].a>>m[i].b;

        m[i].y=i;

    }

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

    {

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

        {

            if(m[j].a<m[i].a)

            {

                node h;

                h=m[j];

                m[j]=m[i];

                m[i]=h;

            }

            if(m[j].a==m[i].a)

            {

                if(m[j].b>m[i].b)

                {

                    node h;

                    h=m[j];

                    m[j]=m[i];

                    m[i]=h;

                }

            }

        }

    }

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

    {

        cout<<m[i].y+1<<endl;

    }

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include<cstdio>

#include<algorithm> 

#include<cstring>

using namespace std;



//#pragma warning(disable:4996)



struct res

{

	char ch[21];

	int s = -1;

	int i = -1;

};



res r[101];



bool comp(res& r1, res& r2)

{

	int c = strcmp(r1.ch, r2.ch);

	if (c < 0)return true;

	if (c > 0)return false;

	return r1.s > r2.s;

}



int n;

int main()

{

	//cin >> n;

	scanf("%d", &n);

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

	{

		scanf("%s", r[i].ch);

		scanf("%d", &r[i].s);

		r[i].i = i;

	}

	sort(&r[1], &r[n]+1, comp);



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

		printf("%d\n", r[i].i);



	return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

#include <string>

using namespace std;

struct r{

	string na;

	int s,a;

};

r x[10000];

bool cmp(r x,r y){

	string a=x.na,b=y.na;

	if(b.size()>a.size())a=b;

	for(int i=0;i<a.size();i++){

		if(x.na[i]!=y.na[i])return x.na<y.na;

	}

	return x.s>y.s;

}

int main(){

	int n;

	cin>>n;

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

		cin>>x[i].na>>x[i].s;

		x[i].a=i+1;

	}

	sort(x,x+n,cmp);

	for(int i=0;i<n;i++)cout<<x[i].a<<endl;

} 

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

struct re

{

	int id;

	char name[105];

	int sc;

}a[105];

bool cmp(const re&a,const re&b)

{

	return(strcmp(a.name, b.name) < 0 || (strcmp(a.name, b.name) == 0 && a.sc > b.sc));

}

int main()

{

	int n;

	scanf("%d", &n);

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

	{

	

		scanf("%s",&a[i].name);

		scanf("%d", &a[i].sc);

		a[i].id = i + 1;

	}

	sort(a, a + n, cmp);

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

		printf("%d\n", a[i].id);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int n;

struct Rest

{

    int i,p;

    string s;

};

Rest rest[100+10];

bool comp(Rest a,Rest b)

{

    if(a.i!=b.i)

    {

        if(a.s!=b.s) return a.s<b.s;

        else

        {

            if(a.i!=b.i)

            {

                return a.p>b.p;

            }

        }

    }

    return a.p>b.p;

}

int main()

{

    cin>>n;

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

    {

        rest[i].i=i;

        cin>>rest[i].s>>rest[i].p;

    }

    sort(rest+1,rest+n+1,comp);

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

    {

        cout<<rest[i].i<<endl;

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

struct re

{

	int id;

	char name[105];

	int sc;

}a[105];

bool cmp(const re&a,const re&b)

{

	return(strcmp(a.name, b.name) < 0 || (strcmp(a.name, b.name) == 0 && a.sc > b.sc));

}

int main()

{

	int n;

	scanf("%d", &n);

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

	{

	

		scanf("%s",&a[i].name);

		scanf("%d", &a[i].sc);

		a[i].id = i + 1;

	}

	sort(a, a + n, cmp);

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

		printf("%d\n", a[i].id);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int N = 1e5+100;

int n,m;

struct node{

	char s[230];

	int sc, id;

	bool operator < (node &A ) const{

		if (strcmp(s, A.s) != 0) return strcmp(s, A.s) < 0;

		return sc > A.sc;

	}

}f[N];



int main(){

	scanf("%d",&n);

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

		scanf("%s%d",f[i].s,&f[i].sc), f[i].id = i+1;

	sort(f,f+n);

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

		printf("%d\n",f[i].id);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

struct re

{

	int id;

	char name[105];

	int sc;

}a[105];

bool cmp(const re&a,const re&b)

{

	return(strcmp(a.name, b.name) < 0 || (strcmp(a.name, b.name) == 0 && a.sc > b.sc));

}

int main()

{

	int n;

	scanf("%d", &n);

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

	{

	

		scanf("%s",&a[i].name);

		scanf("%d", &a[i].sc);

		a[i].id = i + 1;

	}

	sort(a, a + n, cmp);

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

		printf("%d\n", a[i].id);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <vector>

#include <string>

#include <algorithm>

using namespace std;



struct Rest {

	int score;

	string name;

	int id;

} rest[10000];



int n;



bool cmp(const Rest& a, const Rest& b) {

	if(a.name == b.name) return a.score > b.score;

	return a.name < b.name;

}



void in() {

	cin >> n;

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

		cin >> rest[i].name >> rest[i].score;

		rest[i].id = i+1;

	}

}



void solve() {

	sort(rest, rest+n, cmp);

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

		cout << rest[i].id << endl;

	}

}



int main() {

	in();

	solve();

	return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

struct re

{

	int id;

	char name[105];

	int sc;

}a[105];

bool cmp(const re&a,const re&b)

{

	return(strcmp(a.name, b.name) < 0 || (strcmp(a.name, b.name) == 0 && a.sc > b.sc));

}

int main()

{

	int n;

	scanf("%d", &n);

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

	{

	

		scanf("%s",&a[i].name);

		scanf("%d", &a[i].sc);

		a[i].id = i + 1;

	}

	sort(a, a + n, cmp);

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

		printf("%d\n", a[i].id);

	return 0;

}

// Fastest known solution for this problem: