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
}

Python: def sort_cmp(x, y):
    if x[2] == y[2]:
        return x[3] < y[3]
    else:
        return x[2] > x[2]


def solve(n):
    teams = []
    for i in range(n):
        teams.append(list(map(int, raw_input().split())))

    teams = sorted(teams, key=lambda x: -1e12 * x[2] + x[3] * 1e6 + x[0])

    A = []
    B = []
    threshold = 3
    for team in teams:
        if len(A) == 10:
            threshold = 2
        elif len(A) == 20:
            threshold = 1

        if B.count(team[1]) < threshold:
            A.append(team[0])
            B.append(team[1])

        if len(A) == 26:
            break

    for a in A:
        print(a)


while True:
    n = int(raw_input())
    if n == 0:
        break
    solve(n)

Python: from collections import defaultdict
while True:
  n = int(input())
  if n == 0:
    break
  teams = []
  for _ in range(n):
    i, u, a, p = map(int, input().split())
    teams.append((-a, p, i, u))
  teams.sort()
  
  u_counter = defaultdict(int)
  all_counter = 0
  selected = []
  for _, _, i, u in teams:
    if all_counter < 10 and u_counter[u] < 3 or\
       all_counter < 20 and u_counter[u] < 2 or\
       all_counter < 26 and u_counter[u] < 1:
       u_counter[u] += 1
       all_counter += 1
       selected.append(i)
  
  [print(s) for s in selected]

Python: def team_sort(teams, n):
    for i in range(n - 1):
        #print(i)
        for j in range(n - i - 1):
            #print(i, j, teams[j][2], teams[j+1][2])
            if (teams[j][2] < teams[j + 1][2]):
                tmp = teams[j]
                teams[j] = teams[j+1]
                teams[j+1] = tmp
            elif (teams[j][2] == teams[j + 1][2]):
                if (teams[j][3] > teams[j + 1][3]):
                    tmp = teams[j]
                    teams[j] = teams[j+1]
                    teams[j+1] = tmp
                elif (teams[j][3] == teams[j + 1][3]) and (teams[j][0] > teams[j + 1][0]):
                    tmp = teams[j]
                    teams[j] = teams[j+1]
                    teams[j+1] = tmp

def select(teams):
    selection = []
    count = {}
    for t in teams:
        g = str(t[1])
        count.setdefault(g, 0)
        #print(t)
            
        if len(selection) < 10:
            if (count[g] < 3):
                selection.append(t)
                count[g] += 1
        
        elif len(selection) < 20:
            if (count[g] < 2):
                selection.append(t)
                count[g] += 1
        
        elif len(selection) < 26:
            if (count[g] < 1):
                selection.append(t)
                count[g] += 1
    #print('selection', selection)
    
    for t in selection:
        print(t[0])

while True:
    n = int(input())
    
    if (n == 0):
        break
    
    teams = []
    
    for i in range(n):
         t = [int(x) for x in input().split()]
         teams.append(t)
    #print(teams)
    team_sort(teams, n)
    #print('sorted', teams)
    select(teams)

Python: while True:
    n = int(input())
    if n == 0:break
    p = [tuple(map(int, input().split())) for _ in range(n)]
    p.sort()
    p.sort(key = lambda x:x[3])
    p.sort(key = lambda x:x[2], reverse = True)
    s = 0
    sg = {}
    for i in p:
        if s < 10:
            try:
                if sg[i[1]] < 3:
                    print(i[0])
                    s += 1
                    sg[i[1]] += 1
            except:
                sg[i[1]] = 1
                print(i[0])
                s += 1
        elif s < 20:
            try:
                if sg[i[1]] < 2:
                    print(i[0])
                    s += 1
                    sg[i[1]] += 1
            except:
                sg[i[1]] = 1
                print(i[0])
                s += 1
        elif s < 26:
            if i[1] not in sg:
                sg[i[1]] = 1
                print(i[0])
                s += 1

Python: def main():
    while True:
        n = int(input())
        if n == 0: break

        teams = []
        for i in range(n):
            teams.append(list(map(int, input().split())))
       
        def same_len(l):
            return len(list(filter(lambda x: x[1] == e[1], ans))) 

        ans = []
        for e in sorted(sorted(teams, key=lambda x: x[0]), key=lambda x: x[2], reverse=True):
            if len(ans) < 10 and same_len(ans) < 3:
                ans.append(e)
            elif len(ans) < 20 and same_len(ans) < 2:
                ans.append(e)
            elif len(ans) < 26 and same_len(ans) == 0:
                ans.append(e)

        for a in ans:
            print(a[0])


if __name__ == "__main__":
    main()

Python: while True :
    n = int(input())
    if n == 0 :
        break
    
    Team = [list(map(int, input().split())) for i in range(n)]
    Team.sort(key=lambda x: (-x[2], x[3], x[0]))
    
    Senbatsu_Syozoku = [0] * 1001
    Senbatsu_amount = 0
    for i in range(n) :
        if Senbatsu_amount < 10 and Senbatsu_Syozoku[Team[i][1]] < 3 :
            Senbatsu_amount += 1
            Senbatsu_Syozoku[Team[i][1]] += 1
            print(Team[i][0])
        elif Senbatsu_amount < 20 and Senbatsu_Syozoku[Team[i][1]] < 2 :
            Senbatsu_amount += 1
            Senbatsu_Syozoku[Team[i][1]] += 1
            print(Team[i][0])
        elif Senbatsu_amount < 26 and Senbatsu_Syozoku[Team[i][1]] == 0 :
            Senbatsu_amount += 1
            Senbatsu_Syozoku[Team[i][1]] += 1
            print(Team[i][0])