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: # -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter

while 1:
  n = int(stdin.readline().rstrip())
  if n == 0:
    break
  teams = []
  #選抜されたチーム
  Selected_team_id = []
  cnt_selected_teams = 0
  #所属ごとのランキング（所属ごとの選抜チーム数）
  dic_shozoku_and_cntSelected = {}

  for i in range(n):
    * t, = map(int, stdin.readline().split())
    teams.append(t)
    if not dic_shozoku_and_cntSelected.__contains__(t[1]):
      dic_shozoku_and_cntSelected[t[1]] = 0

  sorted_teams1 = sorted(teams, key=itemgetter(3, 0))  # ペナルティ、ID
  sorted_teams = sorted(sorted_teams1, key=itemgetter(2), reverse=True)  # 正解数
  for t in sorted_teams:
    cnt_same_shozoku = dic_shozoku_and_cntSelected[t[1]]
    if cnt_selected_teams < 10:
      if cnt_same_shozoku < 3:
        Selected_team_id.append(t[0])
        dic_shozoku_and_cntSelected[t[1]] += 1
        cnt_selected_teams += 1
    elif cnt_selected_teams < 20:
      if cnt_same_shozoku < 2:
        Selected_team_id.append(t[0])
        dic_shozoku_and_cntSelected[t[1]] += 1
        cnt_selected_teams += 1
    elif cnt_selected_teams < 26:
      if cnt_same_shozoku < 1:
        Selected_team_id.append(t[0])
        dic_shozoku_and_cntSelected[t[1]] += 1
        cnt_selected_teams += 1

  print("\n".join(map(str,Selected_team_id)))

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 = []
        rank = sorted(sorted(sorted(teams, key=lambda x: x[0]), key=lambda x: x[3]), key=lambda x: x[2], reverse=True) 
        for e in rank:
            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: 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 = 1e8

        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: # AOJ 1043: Selecting Teams Advanced to Regional
# Python3 2018.7.6 bal4u

def pr(i, u):
    global total
    print(team[i][0])
    total, affi[u] = total + 1, affi[u] + 1


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]))
    total, affi = 0, [0] * 1002
    for i in range(n):
        u = team[i][1]
        if   total < 10 and affi[u] < 3: pr(i, u)
        elif total < 20 and affi[u] < 2: pr(i, u)
        elif total < 26 and affi[u] < 1: pr(i, u)

Python: # AOJ 1043: Selecting Teams Advanced to Regional
# Python3 2018.7.6 bal4u

def pr(i, u):
	global total
	print(team[i][0])
	total, affi[u] = total+1, affi[u]+1

while True:
	n = int(input())
	if n == 0: break
	team = []
	for i in range(n):
		id, u, a, p = map(int, input().split())
		team.append((id, u, a, p))
	team.sort(key=lambda x:(-x[2],x[3],x[0]))
	total, affi = 0, [0]*1002
	for i in range(n):
		u = team[i][1]
		if   total < 10 and affi[u] < 3: pr(i, u)
		elif total < 20 and affi[u] < 2: pr(i, u)
		elif total < 26 and affi[u] < 1: pr(i, u)

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, 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 = 1e8

        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(input())
    if n == 0:
        break
    solve(n)

Python: while 1:
    in_tmp = input()
    if (in_tmp == "0"):
        break
    list_team = []
    for i in range(int(in_tmp)):
        list_team.append(list(map(int,input().split())))
    list_sorted = sorted(list_team, key=lambda x:(-x[2], x[3], x[0]))
    
    cnt_passed = 0
    dict_passed = {}
    for item in list_sorted:
        if (item[1] not in dict_passed.keys()):
            dict_passed[item[1]] = 0
        if (cnt_passed < 10):
            if(dict_passed[item[1]] < 3):
                print(item[0])
                dict_passed[item[1]] += 1
                cnt_passed += 1
        elif (cnt_passed < 20):
            if(dict_passed[item[1]] < 2):
                print(item[0])
                dict_passed[item[1]] += 1
                cnt_passed += 1
        elif (cnt_passed < 26):
            if(dict_passed[item[1]] < 1):
                print(item[0])
                dict_passed[item[1]] += 1
                cnt_passed += 1
        else:
            break