Go: package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}
		sales := make(map[string]int)
		existed := make(map[string]bool)
		order := make([]string, 4000)
		flg := false
		for i := 0; i < n; i++ {
			stdin.Scan()
			l := strings.Split(stdin.Text(), " ")
			e := l[0]
			p, _ := strconv.Atoi(l[1])
			q, _ := strconv.Atoi(l[2])
			sales[e] += p * q
			if !existed[e] {
				order = append(order, e)
				existed[e] = true
			}
		}
		for _, v := range order {
			if sales[v] >= 1000000 {
				fmt.Println(v)
				flg = true
			}
		}
		if flg == false {
			fmt.Println("NA")
		}
	}
}

Python: while True:
    n = int(input())
    if n != 0:
        dic = {}
        initno,initprice,initsales = map(int,input().split(" "))
        total = initsales*initprice
        dic[initno] = total
        for i in range(n-1):
            no, price, sales = map(int, input().split(" "))
            for k,v in dic.items():
                if k == no:
                    total = dic[no]
                    dic[no] = total + price*sales
                    break
                else:
                    dic[no] = price*sales
                    break
        cnt = 0
        for k,v in sorted(dic.items()):
            if v >= 1000000:
                print("%s" %(str(k)))
                cnt += 1
            else:
                pass

        if cnt == 0:
            print("NA")
    else:
        break

Python: while True:
    num = int(input())
    if not num:
        break
    data = [[int(el) for el in input().split(' ')] for _ in range(num)]
    result = [print(i) for i,j,k in data if j*k >= 1e6]
    if not result:
        print('NA')

Python: while True:
    n = int(input())
    if n != 0:
        dic = {}
        initno,initprice,initsales = map(int,input().split(" "))
        total = initsales*initprice
        dic[initno] = total
        for i in range(n-1):
            no, price, sales = map(int, input().split(" "))
            for k,v in dic.items():
                if k == no:
                    dic[no] = total
                    dic[no] = total + price*sales
                    break
                else:
                    dic[no] = price*sales
                    break
        cnt = 0
        for k,v in sorted(dic.items()):
            if v >= 1000000:
                print("%s" %(str(k)))
                cnt += 1
            else:
                pass

        if cnt == 0:
            print("NA")
    else:
        break

Python: while True:
    num=int(input())
    if num==0:
        break
    else:
        d={}
        for i in range (num):
            info=list(map(int,input().split()))
            try:
                d[info[0]]+=info[1]*info[2]
            except:
                d[info[0]]=info[1]*info[2]
    answer=[]
    for i in d.keys():
        if d[i] >=1000000:
            answer.append(i)
    answer=sorted(answer)
    if answer==[]:
        print("NA")
    else:
        for i in answer:
            print(i)

Python: import sys

def sales_result(sales):
    total_sales = {}
    person = []
    for s in sales:
        total_sales[s[0]] = total_sales.get(s[0], 0)
        total_sales[s[0]] += s[1] * s[2]
        if total_sales[s[0]] >= 1000000 and not (s[0] in person):
            person.append(s[0])
    if len(person) == 0:
        print("NA")
    else:
        for p in person:
            print(p)


lineno = 0
n = 0
sales = []
for line in sys.stdin:
    if lineno == 0:
        n = int(line)
        if n == 0:
            break
    elif lineno <= n:
        s = list(map(int, line.strip().split()))
        sales.append(s)
    if lineno == n:
        sales_result(sales)
        lineno = 0
        sales = []
    else:
        lineno += 1

Python: while(True):
    n = int(input())
    if n==0: break
    d = dict()
    s = set()
    c = 0
    for _ in range(n):
        id_,p,q = map(int,input().split())
        if id_ in s:
            d[id_] += p*q
        else:
            s.add(id_)
            d[id_] = p*q
    for i in s:
        if d[i] >= 1000000:
            print(i)
            c+=1
    if c == 0: print("NA")

Python: while True:
    n = int(input())
    if n == 0:
        break
    data = [0] * 4001
    order = []
    for _ in range(n):
        e, p, q = map(int, input().split())
        data[e] += p*q
        if e not in order:
            order.append(e)

    flag = True
    for e in order:
        if data[e] >= 1000000:
            print(e)
            flag = False
    if flag:
        print("NA")

Python: 
while True:
    n = int(input())
    if n != 0:
        dic = {}
        initno,initprice,initsales = map(int,input().split(" "))
        total = initsales*initprice
        dic[initno] = total
        for i in range(n-1):
            no, price, sales = map(int, input().split(" "))
            for k,v in dic.items():
                if k == no:
                    dic[no] = total
                    dic[no] = total + price*sales
                    break
                else:
                    dic[no] = price*sales
                    break
        cnt = 0
        for k,v in sorted(dic.items()):
            if v >= 1000000:
                print("%d" %(k))
                cnt += 1
            else:
                pass

        if cnt == 0:
            print("NA")
    else:
        break

Python: while True:
    num = int(input())
    if not num:
        break
    data = [[int(el) for el in input().split(' ')] for _ in range(num)]
    tmp = [i for i,j,k in data if j*k >= 1e6]
    seen = set()
    seen_add = seen.add
    result = [x for x in tmp if x not in seen and not seen_add(x)]
    if not result:
        print('NA')
    else:
        [print(r) for r in result]

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

    data = {}
    ans = []
    for i in range(n):
        tmp = list(map(int, input().split(' ')))
        if tmp[0] in data:
            data[tmp[0]] += tmp[1] * tmp[2]
        else:
            data[tmp[0]] = tmp[1] * tmp[2]

    for k, v in data.items():
        if v >= 1000000:
            ans.append(str(k))

    if len(ans) == 0:
        print('NA')
    else:
        print('\n'.join(ans))

Python: while True:
    num = 0
    n = int(input())
    E_lis = []
    pri_lis = []
    if n == 0:
        break
    for i in range(n):
        e,p,q = map(int,input().split())
        if e in E_lis:
            pri_lis[E_lis.index(e)] += p*q
        else:
            E_lis.append(e)
            pri_lis.append(p * q)
    for j in range(len(E_lis)):
        if pri_lis[j] >= 1000000:
            print(E_lis[j])
            num += 1
    if num == 0:
        print("NA")

Python: # Edit: 2014/09/25
# Lang: Python3
# Time: 0.xxs
#

if __name__ == "__main__":

    while True:
        d = {}
        n = int(input())
        if not n:
            break  # exit at n=0

        for i in range(n):
            s, p, m = map(int, input().strip("\n").split(" "))
            # s:社員番号, p:価格, m:販売戸数
            # print(s, p, m)

            if s in d:
                d[s] = d[s] + p * m
            else:
                d[s] = p * m

        cnt = 0
        for k, v in d.items():
            if v >= 1000000:
                print(k)
                cnt +=1
        if not cnt:
            print("NA")

        #print(d)

Python: while True:
    n = int(input())
    if n == 0:
        break
    emp = [0] * 4001
    used = set()
    for i in range(n):
        e, p, q = map(int, input().split())
        emp[e] += p * q
        if 1000000 <= emp[e] and e not in used:
            print(e)
            used.add(e)
    if len(used) == 0:
        print("NA")

Python: import sys

input_lines = sys.stdin.readlines()
cnt = 0
dataset = []
for i in input_lines:
    if not(' ' in i):
        dataset.append([int(i)])
        cnt += 1
    else:dataset[cnt-1].append(list(map(int, i.split(' '))))