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: # coding: utf-8
# Here your code !
employeeSalesList = []

def resetDataset():
    del employeeSalesList[0 : len(employeeSalesList) + 1]

def readDataCount():
    return int(input())

def searchEmployeeSales(employeeId):
    for data in employeeSalesList:
        if data[0] == employeeId:
            return data
    
    newData = [employeeId, 0]
    employeeSalesList.append(newData)
    return newData

def checkSales():
    employeeId, price, volume = list(map(int, input().split(" ")))
    employeeSales = searchEmployeeSales(employeeId)
    employeeSales[1] += price * volume

answerList = []
def printEmployeeOfDataset():
    found = False
    for data in employeeSalesList:
        if data[1] >= 1000000:
            answerList.append(data[0])
            found = True
    if not found:
        answerList.append("NA")

resetDataset()
dataCount = readDataCount()
while dataCount > 0:
    for _ in range(dataCount):
        checkSales()
    printEmployeeOfDataset()
    resetDataset()
    dataCount = readDataCount()

for row in answerList:
    print(row)

Python: while True:
    n = int(input())
    if n == 0:
        break
    ID = []
    sales = {}
    for i in range(n):
        ipq = list(map(int, input().split()))
        ID = ipq[0]
        pq = ipq[1] * ipq[2]
        if ID in sales:
            sales[ID][1] += pq
        else:
            sales[ID] = [ID, pq]
    t = -1
    for k, v in sorted(sales.items(), key=lambda x: x[1][0]):
        if v[1] >= 1000000:
            print(k)
            t = 1
    if t == -1:
        print("NA")

Python: import sys

while True:
    n=int(input())
    score={}
    if n==0:
        sys.exit()
    for _ in range(n):
        e,p,q=[int(i) for i in input().split(" ")]
        score[e]=score.get(e,0)+p*q

    employee=[]
    for e in score:
        if score[e]>=1000000:
            employee.append(e)

    if len(employee)==0:
        print("NA")
    else:
        for e in employee:
            print(e)

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]+=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
    data = [0] * 4001
    for _ in range(n):
        e, p, q = map(int, input().split())
        data[e] += p*q
        
    for i in range(1, 4001):
        if data[i] >= 1000000:
            print(i)

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

    rs = {}
    for i in range(n):
        arr = [int(x) for x in input().split(' ')]
        s = arr[1] * arr[2]
        rs[arr[0]] = (rs.get(arr[0]) or 0) + s

    top = [k for k, v in rs.items() if v > 1000000 ]
    if len(top) == 0:
        print('NA')
    else:
        for i in top:
            print(i)

Python: import sys
from collections import OrderedDict
#from me.io import dup_file_stdin

#@dup_file_stdin
def solve():
    while True:
        n = int(sys.stdin.readline())
        if n==0 :
            break
        emps = OrderedDict()
        for i in range(n):
            no,price,amount = map(int,sys.stdin.readline().split(' '))
            emps[no]=emps.get(no,0)+price*amount
        results = [k for k,v in emps.items() if v>=1000000]
        if len(results) > 0:
            [print(emp) for emp in results]
        else:
            print("NA")
solve()

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

    rs = {}
    for i in range(n):
        cid, p, q = map(int, input().strip().split(' '))
        rs[cid] = (rs.get(cid, None) or 0) + p * q

    top = [k for k, v in rs.items() if v >= 1000000]
    if len(top) == 0:
        print('NA')
    else:
        for i in top:
            print(i)

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(' '))))
    
for d in dataset:
    if d == [0]:break
    shain = [[x[0], x[1]*x[2]] for x in d[1:]]
    #score = [ for x in d[1:]]
    slist = []
    for s in shain:
        if not(s[0] in slist):slist.append(s[0])
    newslist = [[x, 0] for x in slist]
    score = []
    for s in shain:
        newslist[slist.index(s[0])][1] += s[1]
    
    flag = False
    for n in newslist:
        if n[1] >= 1000000:
            print(n[0])
            flag = True
    if not flag:print('NA')

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

    flag = True
    for i in range(1, 4001):
        if data[i] >= 1000000:
            print(i)
            flag = False
    if flag:
        print("NA")

Python: while 1:
 a={};b=1
 n=int(input())
 if n==0:break
 for _ in[0]*n:
  e,p,q=map(int,input().split())
  a.setdefault(e,0);a[e]+=p*q
 for e in a:
  if a[e]>=1e6:print(e);b=0
 if b:print('NA')

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

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0100&lang=jp
"""
import sys


def solve(data):
    result = []
    total_sales = [0 for _ in range(4000+1)]
    for id, unit_price, quantity in data:
        total_sales[id] += unit_price * quantity
    for i, sales in enumerate(total_sales):
        if sales >= 1000000:
            result.append(i)
    return result


def main(args):
    #data = []
    #data.append([1001, 2000, 520])
    #data.append([1002, 1800, 450])
    #data.append([1003, 1600, 625])
    #data.append([1001, 200, 1220])

    while True:
        num = int(input().strip())
        if num == 0:
            break
        data = []
        for _ in range(num):
            data.append([int(x) for x in input().strip().split(' ')])
        result = solve(data)
        if result:
            for ele in result:
                print(ele)
        else:
            print('NA')


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

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