Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	for n := getNextInt(scanner); n > 0; n = getNextInt(scanner) {
		tt := make([]team, n)
		for i := 0; i < n; i++ {
			tt[i].id = getNextInt(scanner)
			tt[i].uni = getNextInt(scanner)
			tt[i].ac = getNextInt(scanner)
			tt[i].pn = getNextInt(scanner)
		}
		sort.SliceStable(tt, func(i, j int) bool {
			if tt[i].ac == tt[j].ac {
				if tt[i].pn == tt[j].pn {
					return tt[i].id < tt[j].id
				}
				return tt[i].pn < tt[j].pn
			}
			return tt[i].ac > tt[j].ac
		})
		cc := make([]int, 100005)
		ans := make([]int, 0)
		for i := 0; i < n; i++ {
			if cc[0] < 10 && cc[tt[i].uni] < 3 {
				cc[0]++
				cc[tt[i].uni]++
				ans = append(ans, tt[i].id)
				continue
			}
			if cc[0] < 20 && cc[tt[i].uni] < 2 {
				cc[0]++
				cc[tt[i].uni]++
				ans = append(ans, tt[i].id)
				continue
			}
			if cc[0] < 26 && cc[tt[i].uni] < 1 {
				cc[0]++
				cc[tt[i].uni]++
				ans = append(ans, tt[i].id)
				continue
			}
		}
		for i := 0; i < len(ans); i++ {
			fmt.Fprintln(writer, ans[i])
		}
	}
}

type team struct {
	id, uni, ac, pn int
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

struct T
{
    int i, u, a, p;
};

bool operator<( T const& lhs, T const& rhs )
{
    return ( lhs.a > rhs.a )
        || ( lhs.a == rhs.a && lhs.p < rhs.p )
        || ( lhs.a == rhs.a && lhs.p == rhs.p && lhs.i < rhs.i );
}
ostream& operator<<( ostream& os, T const& t )
{
    os << t.i << " " << t.u << " " << t.a << " " << t.p;
    return os;
}

int main()
{
    for(;;) {
        int n;
        cin >> n;

        if ( n == 0 )
            break;

        vector<T> v;
        for( int iii=0; iii<n; ++iii ) {
            T t;
            cin >> t.i >> t.u >> t.a >> t.p;
            v.push_back( t );
        }

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


        map<int, int> teams;
        vector<T> selected;
        for( int i=0; i<v.size(); ++i ) {
            T const& t = v[i];

            if ( selected.size() < 10 ) {
                if ( teams[t.i] < 3 ) {
                    selected.push_back( t );
                    ++teams[t.i];
                }
            } else if ( selected.size() < 20 ) {
                if ( teams[t.i] < 2 ) {
                    selected.push_back( t );
                    ++teams[t.i];
                }
            } else if ( selected.size() < 26 ) {
                if ( teams[t.i] < 1 ) {
                    selected.push_back( t );
                    ++teams[t.i];
                }
            }
        }


        for( int i=0; i<selected.size(); ++i )
            cout << selected[i].i << endl;    
    }
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<map>

using namespace std;

class team {
public:
	int kasu[4];
	team(int a, int b, int c, int d){
		
		kasu[0] = a;//id
		kasu[1] = b;//????±?
		kasu[2] = c;//??£?§£
		kasu[3] = d;//??????
	}
	int back(int a) {
		return kasu[a];
	}
};

vector<team> t;
map<int, int> mp;
vector<int> res;
vector<vector<int>> l (10, vector<int>(0));
int n;

int val(int x, int y) {
	for (int i = 0; i < y; i++) {
		x /= 10;
	}
	return x % 10;
}

void kitei(int x, int y) {//???????????????????????°, ???
	for (int i = 0; i < 10; i++) {
		l[i].push_back(-1);
	}
	for (int i = 0; i < 10; i++) {
		while (l[i][0] != -1) {
			l[val(t[l[i][0]].kasu[x], y)].push_back(l[i][0]);//?????°??????????????????????????£??????
			l[i].erase(l[i].begin());//?¶????
		}
		l[i].erase(l[i].begin());
	}
	return;
}

int main() {
	while (1) {
		cin >> n;
		if (n == 0)
			break;
		for (int i = 0; i < n; i++) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			t.emplace_back(a, b, c, d);
			l[0].push_back(i);
		}

		for (int i = 0; i < 6; i++) {
			kitei(0, i);
		}

		for (int i = 0; i < 6; i++) {//??????????????£????????????
			kitei(3, i);
		}
		kitei(2, 0);
		int num = 0;
		for (int i = 9; i >= 0; i--) {
			for (int j = 0; j < l[i].size(); j++) {
				if (num < 10) {
					if (mp[t[l[i][j]].kasu[1]] < 3) {
						res.push_back(t[l[i][j]].kasu[0]);
						num++;
						mp[t[l[i][j]].kasu[1]]++;
					}
				}
				else if (num < 20) {
					if (mp[t[l[i][j]].kasu[1]] < 2) {
						res.push_back(t[l[i][j]].kasu[0]);
						num++;
						mp[t[l[i][j]].kasu[1]]++;
					}
				}
				else if (num < 26) {
					if (mp[t[l[i][j]].kasu[1]] < 1) {
						res.push_back(t[l[i][j]].kasu[0]);
						num++;
						mp[t[l[i][j]].kasu[1]]++;
					}
				}
			}
		}
		for (auto q : res) {
			cout << q << endl;
		}
		res.clear();
		mp.clear();
		t.clear();
		for (int i = 0; i < 10; i++) {
			l[i].clear();
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
struct po{
  int I,U,A,P,sum;
};
 
int main (){
  int n;
 
  while(1) {
  cin >> n;
  if (n == 0) break;
  vector <po> D;
  D.resize(n);
  for(int i=0;i<n;i++) cin >> D[i].I >> D[i].U >> D[i].A >> D[i].P;
 
  po t;
  for(int i=0;i<n;i++) {
    for(int j=n-1;j>i;j--){
      if(D[j].A > D[j-1].A){
    t = D[j];
    D[j] = D[j-1];
    D[j-1] = t;
      }
      if(D[j].A == D[j-1].A) {
    if(D[j].P < D[j-1].P) {
      t = D[j];
      D[j] = D[j-1];
      D[j-1] = t;
    }
    if(D[j].P == D[j-1].P && D[j].U <= D[j-1].U) {
      t  = D[j];
      D[j] = D[j-1];
      D[j-1] = t;
    }
      }
    }
  }
 
  int goukei = 0;
  int flg[1001] = {};
 
  for(int i=0;i<n;i++) {
    if(goukei < 10 && flg[D[i].U] < 3) {
      cout << D[i].I << endl;
      flg[D[i].U]++;
      goukei++;
    }
    else if(goukei < 20 && flg[D[i].U]< 2) {
      cout << D[i].I << endl;
      flg[D[i].U]++;
      goukei++;
    }
    else if(goukei < 26 && flg[D[i].U] == 0) {
      cout << D[i].I << endl;
      flg[D[i].U]++;
      goukei++;
    }
  }
 
  }
 
  return 0;

}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAX = 1001;
typedef pair<int,int> QQ;
typedef pair<int,int> PP;
typedef pair<PP,QQ> P;

int main(){
  int n;

  while(cin >> n ,n){
    int id,uni,ac,pe;
    int tc[MAX+1];
    fill(tc,tc+MAX,0);
    vector<P> v;

    while(n--){
      cin >> id >> uni >> ac >> pe;
      v.push_back(P(PP(-ac,pe),QQ(id,uni)));
    } 
    sort(v.begin(),v.end());

    int cnt = 0;
    int size = v.size();
    for(int i = 0; i < size ; i++){
      int u = v[i].second.second;
   
      if(cnt < 10){
	if(tc[u] < 3){
	  cout << v[i].second.first << endl;
	  cnt++;
	}
      }
      else if(cnt < 20){
	if(tc[u] < 2){
	  cout << v[i].second.first << endl;
	  cnt++;
	}
      }
      else if(cnt < 26){
	if(tc[u] < 1){
	  cout << v[i].second.first << endl;
	  cnt++;
	}
      }
      tc[u]++;
    } 
  }

  return 0;
}