Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)
var f = make([]string, 10)
var s, w = make([]int, 10), make([]int, 10)
var n int
func main() {
	for scanner.Scan() {
		n, _ = strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			tmpf :=buf[0]
			tmpw, _ := strconv.Atoi(buf[1])
			tmps, _ := strconv.Atoi(buf[2])
			f[i] = tmpf
			s[i] = tmps
			w[i] = tmpw
		}
		sort()
		for i := 0; i < n; i++ {
			for j := 0; j < n-1; j++ {
				if w[j]<w[j+1] {
					swap(j)
					a := get_weight(j+1)
					if a>s[j] {
						swap(j)
					}
				}
			}
		}
		for i := 0; i < n; i++ {
			fmt.Println(f[i])
		}
	}
}

func sort() {
	for i := n-1; i > 0; i-- {
		for j := 0; j < i; j++ {
			if s[j]<s[j+1] {
				swap(j)
			} else if s[j]==s[j+1]&&w[j]<w[j+1] {
				swap(j)
			}
		}
	}
}

func swap(x int) {
	w[x], w[x+1] = w[x+1], w[x]
	s[x], s[x+1] = s[x+1], s[x]
	f[x], f[x+1] = f[x+1], f[x]
}

func get_weight(x int) int {
	ret := 0
	for i := x; i < n; i++ {
		ret += w[i]
	}
	return ret
}

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0170

"""
import sys
from sys import stdin
input = stdin.readline
from collections import namedtuple
from itertools import permutations


def solve(items):
    total_weight = 0
    for i in items:
        total_weight += i.w

    best_ans = []
    best_gp = float('inf')
    # ???????????????????????????????????????????????°?????????????????§????????????
    for perm in permutations(items):
        ans = []
        squashed = False
        cw = 0
        gp = 0
        n = len(items)

        for p in perm:
            if p.s < cw:
                squashed = True
                break
            cw += p.w
            ans.append(p.name)
            gp += n * p.w
            n -= 1
        # ????????°???????????£?????´????????????????¨???????????????????????????????????????£?????????????????§????????????
        if not squashed:
            gp /= total_weight
            if gp < best_gp:
                best_gp = gp
                best_ans = ans[:]
    # ????????????????????????????????£??????????????§?????????????±?????????????????????????????????????????????????
    best_ans.reverse()
    return best_ans


item = namedtuple('item', ['name', 'w', 's'])
def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        items = []
        for _ in range(n):
            name, w, s = input().split()
            items.append(item(name, int(w), int(s)))

        result = solve(items)
        print('\n'.join(result))


if __name__ == '__main__':
    main(sys.argv[1:])

Python: from collections import namedtuple

Data = namedtuple("Data", "name weight limit")


def search(food_list, select_list, total_weight):
    if len(food_list) == 0:
        return select_list

    limit = select_list[len(select_list) - 1].limit

    for lp, food in enumerate(food_list):

        if total_weight <= limit:

            select_list.append(food)
            food_list.remove(food)
            total_weight -= food.weight

            search(food_list, select_list, total_weight)

            if len(food_list) == 0:
                return select_list
            else:
                select_list.pop()
                food_list.insert(lp, food)
                total_weight += food.weight

    return None


while True:
    input_count = int(input())

    if input_count == 0:
        break

    input_data = [input().split(" ") for _ in range(input_count)]
    input_data = [Data(item[0], int(item[1]), int(item[2])) for item in input_data]

    input_data.sort(key=lambda x: (x.weight, x.limit), reverse=True)

    total_weight = sum([item.weight for item in input_data])

    result = search(input_data, [Data("sentinel", 0, 999999)], total_weight)
    del result[0]

    output = [item.name for item in result]
    print("\n".join(output))

Python: INF = 10 ** 20
while True:
  n = int(input())
  if n == 0:
    break
  names = []
  weights = []
  safes = []
  for _ in range(n):
    f, w, s = input().split()
    names.append(f)
    weights.append(int(w))
    safes.append(int(s))
  all_weight = sum(weights)
  dic = [None] * (2 ** n)
  
  def score(rest, total_weight, count):
    if dic[rest] != None:
      return dic[rest]
    if rest == 0:
      return (0, [])

    ret = (INF, [])
    mask = 1
    for i in range(n):
      if rest & mask:
        if safes[i] >= all_weight - total_weight - weights[i]:
          temp = score(rest & ~mask, total_weight + weights[i], count + 1) 
          ret = min(ret, (temp[0] + weights[i] * (count + 1), [names[i]] + temp[1]))
      mask <<= 1
    dic[rest] = ret
    return ret

  print(*score(2 ** n - 1, 0, 0)[1], sep="\n")

Python: a=list(map(int, input().split()))
x=["A","B","C"]
print(x[a.index(max(a))])

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0170

"""
import sys
from sys import stdin
input = stdin.readline
from collections import namedtuple


def solve(items):
    from itertools import permutations
    total_weight = 0
    for i in items:
        total_weight += i.w
    best_ans = []
    best_gp = float('inf')
    # ???????????????????????????????????????????????°?????????????????§????????????
    for perm in permutations(items):
        ans = []
        squashed = False
        cw = 0
        gp = 0
        n = len(items)
        for p in perm:
            if p.s < cw:
                squashed = True
                break
            cw += p.w
            ans.append(p.name)
            gp += n * p.w
            n -= 1
        # ????????°???????????£?????´????????????????¨???????????????????????????????????????£?????????????????§????????????
        if not squashed:
            gp /= total_weight
            if gp < best_gp:
                best_gp = gp
                best_ans = ans[:]
    # ????????????????????????????????£??????????????§?????????????±?????????????????????????????????????????????????
    best_ans.reverse()
    return best_ans


def solve2(items):
    items.sort(key=lambda x:x.w, reverse=True) # ??????????????????????????????
    total_weight = 0            #  ??¢?????????????????????
    for i in items:
        total_weight += i.w
    ans = []
    # ?????£???????????¢??????????????????????????????????????????????????§???????????¢??????????????????????????????????????????????????????????????????????????¢?????????????????????????????§??°????????????
    while items:
        cap = [x.s - total_weight + x.w for x in items] #  ????????\??????????????¢?????????????????????????????¨????????°??????????????????????????????????????????????????????0??\?????????OK
        for i in range(len(items)):
            if cap[i] >= 0:     #  ??°???????????????????????????????????????????????????????????????????????????
                ans.append(items[i].name)
                i = items.pop(i)
                total_weight -= i.w #  ???????????¢?????????????????????????????????
                break
    return ans


item = namedtuple('item', ['name', 'w', 's'])
def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        items = []
        for _ in range(n):
            name, w, s = input().split()
            items.append(item(name, int(w), int(s)))
        result = solve2(items)
        print('\n'.join(result))


if __name__ == '__main__':
    main(sys.argv[1:])