Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		sales := make([]int, 4000)
		members := make([]int, 0)
		memberCheck := make(map[int]bool)

		for i := 0; i < n; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			e, _ := strconv.Atoi(input[0])
			p, _ := strconv.Atoi(input[1])
			q, _ := strconv.Atoi(input[2])

			if e >= 1 && e <= 4000 && memberCheck[e] == false {
				members = append(members, e)
				memberCheck[e] = true
			}
			sales[e-1] += p * q
		}

		emptyFlag := true
		for _, v := range members {
			if sales[v-1] >= 1000000 {
				fmt.Println(v)
				emptyFlag = false
			}
		}

		if emptyFlag == true {
			fmt.Println("NA")
		}
	}
}

Python: if __name__ == '__main__':

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

			no = []
			total = []
			for i in range(n):
				e,p,q = map(int,input().split())

				if e not in no:
					no.append(e)
					total.append(p*q)
				else:
					ind = no.index(e)
					total[ind] += p*q

			cnt = 0
			for j,k in enumerate(total):
				if k >= 1000000:
					cnt += 1
					print(no[j])
			if cnt == 0:
				print("NA")

		except EOFError:
			break

Python: while 1:
  n=int(input())
  if not n:break
  f=1
  L={}
  for a,b,c in [input().split() for i in range(n)]:
    d=int(b)*int(c)
    if a in L:
      if L[a]>=1e6:continue
      L[a]+=d
    else:L[a]=d
    if L[a]>=1e6:print(a);f=0
  if f:print('NA')

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

Python: while True:
    try:
        n=int(input())
    except:
        break
    if n==0:
        break
    data={}
    staff=[]
    for i in range(n):
        spam=list(map(int,input().split()))
        if spam[0] in data.keys():
            data[spam[0]]+=spam[1]*spam[2]
        else:
            data[spam[0]]=spam[1]*spam[2]
            staff.append(spam[0])
    if max(data.values())<1000000:
        print('NA')
    else:
        for i in staff:
            if data[i] >= 1000000:
                print(i)

Python: while True:
    n=int(input())
    if n==0:break
    d=dict()
    for _ in range(n):
        i,p,q=map(int, input().split())
        d[i] = d[i]+p*q if i in d else p*q
    b=True
    ans=[]
    for k, v in d.items():
        if v >= 1000000:
            ans.append(k)
            b=False
    else:
        if b:print("NA")
        else:print('\n'.join(map(str, ans)))

Python: #!/usr/bin/env python3
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(' '))))

Python: from collections import defaultdict
while True:
    n = int(input())
    if n == 0:
        break

    SALES = defaultdict(int)
    for _ in range(n):
        id, p, num = [int(x) for x in input().split()]
        SALES[id] += p * num
        
    L = [k for k, v  in SALES.items() if v >= 1000000]

    if len(L) > 0:
        for i in L:
            print(i)
    else:
        print("NA")

Python: while True:
    n = int(input())
    if n == 0:
        break
    d = [0]*4000
    for i in range(n):
        e_t,p,q = map(int,input().split())
        d[e_t] += p*q
    flag = 0
    for i in range(4000):
        if d[i] >= 1000000:
            print(i)
            flag = 1
    if flag == 0:
        print('NA')

Python: while True:
  n = int(input())
  if n == 0:
    break
  c = 0
  l = []
  d = {}
  for i in range(n):
    num,x,y = map(int,input().split())
    if num in d:
      d[num] = d[num] + x*y
    else:
      d[num] = x*y
      l.append(num)
  for i in l:
    if d[i] >= 1000000:
      print(i)
      c += 1
  if c == 0:
    print('NA')

Python: # AOJ 0100 Sale Result
# Python3 2018.6.17 bal4u

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

	id = []
	pq = [-1]*4001
	for i in range(n):
		e, p, q = list(map(int, input().split()))
		if pq[e] < 0:
			id.append(e)
			pq[e] = p*q
		else: pq[e] += p*q
		
	f = False
	for e in id:
		if pq[e] >= 1000000:
			print(e)
			f = True
	if not f: print('NA')

Python: #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit
from collections import Counter


def main(readline=stdin.readline):
    count = Counter()
    member = []

    while 1:
        n = int(readline())
        if not n:
            exit()

        count.clear()
        del member[:]

        for _ in range(n):
            i, price, num = (int(s) for s in readline().split())
            count[i] += price * num
            if i not in member:
                member.append(i)

        member = [i for i in member if count[i] >= 1000000]

        if member:
            print(*member, sep='\n')
        else:
            print('NA')


if __name__ == '__main__':
    main()

Python: from collections import OrderedDict
while True:
    n = int(input())
    if n == 0:
        break    
    dic = OrderedDict()
    for i in range(n):
        line = input().split()
        key = line[0]
        sales = int(line[1]) * int(line[2])
        if key in dic:
            dic[key] += sales
        else:
            dic[key] = sales
    res = [k for k in dic if dic[k] >= 1000000]
    if len(res) == 0:
        print("NA")
    else:
        [print(k) for k in res]

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

  inputs=[None]*n
  for t in range(0,n):
    inputs[t] = list(map(int,input().split()))

  sale_result={}
  for t in range(0,n):
    sale_result[inputs[t][0]]=0 # inputs[t][0] means the ID in the "n"th line.

  for t in inputs:
    sale_result[t[0]]+=t[1]*t[2]

  na=True
  for k in sale_result:
    if sale_result[k]>=1000000:
      print(k)
      na=False
  if na:
    print("NA")

Python: while True:
    n = int(input())
    if n == 0: break
    d = dict()
    order = []
    for _ in range(n):
        i, p, q = map(int, input().split())
        d[i] = d[i]+p*q if i in d else p*q
        if i not in order: order.append(i)
    b = True
    for o in order:
        if d[o] > 999999:
            print(o)
            b = False
    if b: print("NA")

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 1:
  n=int(input())
  if not n:break
  f=1
  L={}
  for a,b,c in [input().split() for i in range(n)]:
    if a in L:
      if L[a]>=1e6:continue
      L[a]+=int(b)*int(c)
    else:L[a]=int(b)*int(c)
    if L[a] >= 1e6:print(a);f=0
  if f:print('NA')

Python: while True:
    n=int(input())
    if n==0:
        break
    s=[-1]*4001
    id=[]
    for i in range(n):
        e,p,q=map(int,input().split())
        if s[e]<0:
            id.append(e)
            s[e]=p*q
        else:
            s[e]+=p*q
    ch=True
    for i in id:
        if s[i]>=1000000:
            print(i)
            ch=False
    if ch:
        print("NA")

Python: while True:
	N= int(input())
	if N == 0:
		break
	D = {}
	di = []
	for n in range(N):
		e,p,q = input().split()
		p = int(p)
		q = int(q)
		if e not in di:
			di.append(e)
			D[e] = p * q
		else:
			D[e] = D[e] + p * q
	flag = 0
	for dj in di:
		if D[dj] >= 10**6:
			print(dj)
			flag = 1
	if flag == 0:
		print("NA")