Problem:
Sale Result There is data on sales of your company. Your task is to write a program which identifies good workers. The program should read a list of data where each item includes the employee ID i , the amount of sales q and the corresponding unit price p . Then, the program should print IDs of employees whose total sales proceeds (i.e. sum of p × q) is greater than or equal to 1,000,000 in the order of inputting. If there is no such employees, the program should print "NA". You can suppose that n < 4000, and each employee has an unique ID. The unit price p is less than or equal to 1,000,000 and the amount of sales q is less than or equal to 100,000. Input The input consists of several datasets. The input ends with a line including a single 0. Each dataset consists of:  n (the number of data in the list) i  p  q  i  p  q :
 : i  p  q  Output For each dataset, print a list of employee IDs or a text "NA" Sample Input 4
1001 2000 520
1002 1800 450
1003 1600 625
1001 200 1220
2
1001 100 3
1005 1000 100
2
2013 5000 100
2013 5000 100
0 Output for the Sample Input 1001
1003
NA
2013

Solution (Python):
dataCount = int(input())
while dataCount > 0:
    employeeSalesList = []
    for _ in range(dataCount):
        dataList = input().split(" ")
        employeeId, price = dataList[0], int(dataList[1]) * int(dataList[2])
        for data in employeeSalesList:
            if data[0] == employeeId:
                data[1] += price
                continue
        employeeSalesList.append([employeeId, price])

    answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
    if answerList:
        print("\n".join(map(str, answerList)))
    else:
        print("NA")

    dataCount = int(input())

Solution (Python):



dataCount = int(input())
while dataCount > 0:
    employeeSalesList = []
    for _ in range(dataCount):
        dataList = input().split(" ")
        employeeId, price = int(dataList[0]), int(dataList[1]) * int(dataList[2])
        found = False
        for data in employeeSalesList:
            if data[0] == employeeId:
                data[1] += price
                found = True
        if not found:
            employeeSalesList.append([employeeId, price])

    answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
    if answerList:
        print("\n".join(map(str, answerList)))
    else:
        print("NA")

    dataCount = int(input())

Solution (Python):



def parseData(line):
    dataList = line.split(" ")
    return int(dataList[0]), int(dataList[1]) * int(dataList[2])

dataCount = int(input())
while dataCount > 0:
    employeeSalesList = []
    for _ in range(dataCount):
        employeeId, price = parseData(input())
        found = False
        for data in employeeSalesList:
            if data[0] == employeeId:
                data[1] += price
                found = True
        if not found:
            employeeSalesList.append([employeeId, price])

    answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
    if answerList:
        print("\n".join(map(str, answerList)))
    else:
        print("NA")

    dataCount = int(input())

Solution (Python):
from collections import OrderedDict

while True:
    n = int(input())
    if not n:
        break
        
    ds = OrderedDict()
    for _ in range(n):
        i, p, q  = input().split()
        ds[i] = ds.get(i, 0) + int(p) * int(q)
    
    ds = OrderedDict((i, v) for i, v in ds.items() if v >= 1000000)
    if ds:
        print('\n'.join(ds.keys()))
    else:
        print('NA')

Solution (Python):
import sys

while True:
    n = int(sys.stdin.readline().rstrip())
    if n == 0:
        break
    members = []
    sales  = {}
    for i in range(n):
        e,p,q = sys.stdin.readline().rstrip().split(' ')
        if not e in members:
            members.append(e)
            sales[e] = 0
        sales[e] += int(p) * int(q)
    ret = [member for member in members if sales[member] >= 1000000]
    if len(ret) != 0:
        for d in ret:
            print(d)
    else:
        print("NA")

Solution (Python):
while True:
    n=int(input())
    if n==0:break
    res={}
    li=[]
    for i in range(n):
        d=[int(num) for num in input().split(' ')]
        if d[0]-1 in res:
            res[d[0]-1]+=d[1]*d[2]
        else:
            res[d[0]-1]=d[1]*d[2]
            li.append(d[0]-1)
    flag=False
    for i in li:
        if res[i]>=1000000:
            print(i+1)
            flag=True
    if flag==False:print("NA")

Solution (Python):
from pip._vendor.distlib.compat import raw_input
while True:
    n = int(raw_input())
    if n == 0: break
    data = {}
    order = []
    for i in range(n):
        id,price,quant = map(int, raw_input().split())
        if id in data:
            data[id] += price * quant
        else:
            data[id] = price * quant
            order.append(id)

    if max(data.values()) < 1000000: print("NA")
    else:
        for i in order:
            if data[i] >= 1000000:
                print(i)

Solution (Python):
from collections import OrderedDict

while True :
    n = int(input())
    if n == 0 : break
    
    box = OrderedDict()
    for _ in ([None]*n) :
        e, p, q = map(int, input().split())
        if e in box : box[e] += p * q
        else        : box[e]  = p * q
    
    check = 0
    for _ in box :
        if box[_] >= (10**6) :
            print(_)
            check = 1
    if check == 0 : print('NA')

Solution (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')

Solution (Python):
n = int(input())
while n != 0:
	earnings = []
	for i in range(0,n):
		a = str.split(input(),' ')
		if i > 0 :
			for j in range(0,len(earnings)):
				if a[0] == earnings[j][0]:
					earnings[j][1] = str(int(earnings[j][1])+(int(a[1])*int(a[2])))
					break
				if j == len(earnings) - 1:earnings.append([a[0],str(int(a[1])*int(a[2]))])
		else:earnings.append([a[0],str(int(a[1])*int(a[2]))])
	milionear = []
	for i in range(0,len(earnings)):
		if int(earnings[i][1]) >= 1e6:
			milionear.append(earnings[i][0])
	if len(milionear) == 0 : print('NA')
	else:
		for i in range(0,len(milionear)):
			print(milionear[i])
	n = int(input())

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    d = dict()
    sep = []
    for _ in range(n):
        i, p, q = map(int, input().split())
        if i in d:
            d[i] += p*q
        else:
            d[i] = p*q
            sep.append(i)
    tmp = list(filter(lambda x: x[1] >= 1000000, d.items()))
    if len(tmp):
        tmp = {t[0]: t[1] for t in tmp}
        for s in sep:
            if s in tmp:
                print(s)
    else:
        print("NA")

Solution (Python):
import sys
 
while True:
    n = int(sys.stdin.readline().rstrip())
    if n == 0:
        break
    members = []
    sales  = {}
    for i in range(n):
        e,p,q = sys.stdin.readline().rstrip().split(' ')
        if not e in members:
            members.append(e)
            sales[e] = 0
        sales[e] += int(p) * int(q)
    ret = [member for member in members if sales[member] >= 1000000]
    if len(ret) != 0:
        for d in ret:
            print(d)
    else:
        print("NA")

Solution (Python):

"""
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
        if total_sales[id] >= 1000000:
            if id not in result:
                result.append(id)

    
    
    
    return result


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


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

Solution (Python):

"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0100&lang=jp
"""
import sys
from collections import OrderedDict


def solve(data):
    
    
    sums = OrderedDict()
    for id, p, q in data:
        if id in sums:
            sums[id] += p * q
        else:
            sums[id] = p * q
    result = [key for key, value in sums.items() if value >= 1000000]
    return result



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


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

Solution (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')

Solution (Python):


import sys, math, os


PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    N = int(input())
    if N == 0:
        break
    sales = {}
    good = False
    order = []
    for n in range(N):
        i, p, q = [int(_) for _ in input().split()]
        if i not in order:
            order.append(i)
        sales[i] = sales.get(i, 0) + p * q
    good = False
    for i in order:
        if sales[i] >= 1000000:
            print(i)
            good = True
    if not good:
        print("NA")

Solution (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')

Solution (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')

Solution (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')

Solution (Python):
import sys
import math

data =[0 for i in range(4000)]
p_data = []
while True:
	n = int(input())
	count = 0
	if n == 0:
		break
	for i in range(n):
		e,p,q = map(int, input().split())
		data[e] = data[e] + p * q
		if p_data.count(e) == 0:
			p_data.append(e)
	for i in range(len(p_data)):
		if data[p_data[i]] >= 1000000:
			print(p_data[i])
			count = count + 1
			data[p_data[i]] = 0
		elif data[p_data[i]] != 0:
			data[p_data[i]] = 0
	if count == 0:
		print('NA')
	p_data.clear()

Solution (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')

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

Solution (Python):
while 1:
  n=int(input())
  if not n:break
  f=1
  L={}
  for a,b,c in [map(int,input().split()) for i in range(n)]:
    a=str(a)
    d=b*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')

Solution (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')

Solution (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')

Solution (Python):
import sys
from collections import OrderedDict



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()

Solution (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")

Solution (Python):


while (True):
    inputCount = int(input())

    if inputCount == 0:
        break

    employeeNumber = []
    employeePrice = []

    while 0 < inputCount:
        inputNum = [int(item) for item in input().split(" ")]

        price = inputNum[1] * inputNum[2]

        if inputNum[0] in employeeNumber:
            index = employeeNumber.index(inputNum[0])
            employeePrice[index] += price
        else:
            employeeNumber.append(inputNum[0])
            employeePrice.append(price)

        inputCount -= 1

    isExist = False

    for index in range(0, len(employeeNumber)):
        if 1000000 <= employeePrice[index]:
            print(employeeNumber[index])
            isExist = True

    if not isExist:
        print("NA")

Solution (Python):
while True:
  n = int(input())
  if n == 0:
    break
  c = 0
  l = []
  d = {}
  for i in range(n):
    num,x,y = [int(i) for i in 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')

Solution (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')

Solution (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')

Solution (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')

Solution (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')

Solution (Python):
while True:
    no = {}
    n = int(input())
    if (n == 0):
        break
    
    for i in range(n):
        datas = map(int, input().split())
        li = list(datas) 
        e = li[0]
        p = li[1]
        q = li[2]

        s = p * q
        if (e not in no):
            no[e] = s
        else:
            no[e] += s

    na = True    
    for k in no.keys():
        if (1000000 <= no[k]):
            print(k)
            na = False
    
    if (na == True):
        print("NA")

Solution (Python):
while True:
  n = int(input())
  if not n:
    break
  
  dic = {}

  for i in range(n):
    e, p, q = map(int, input().split())    
    if e in dic:
      dic[e] = (dic[e][0], dic[e][1] + p * q)
    else:
      dic[e] = (i, p * q)

  lst = []

  for k in dic:
    if dic[k][1] >= 1000000:
      lst.append((dic[k][0], k))
  
  lst.sort()

  if lst:
    for e in lst:
      print(e[1])
  else:
    print("NA")

Solution (Python):
e=[]
while 1:
  l=[list(map(int,input().split())) for i in range(int(input()))]
  if not l:break
  d={}
  for i in l:
    if i[0] not in d:
      d[i[0]]=i[1]*i[2]
    else:
      d[i[0]]+=i[1]*i[2]
  e.append(d)
f=0
for i in e:
  f=0
  for j in i.items():
    if j[1]>=1000000:
      print(j[0])
      f=1
  if not f:
    print("NA")

Solution (Python):



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')

Solution (Python):
while 2 > 1:
    line_num = int(raw_input())
    if line_num < 1:
        break
    mydict = {}
    mydict_distinct = {}
    myIDlist = []
    for n in range(line_num):
        dat = map(int, raw_input().split(" "))
        if dat[0] in mydict_distinct:
            mydict[dat[0]] += dat[1] * dat[2]
        else:
            mydict[dat[0]] = dat[1] * dat[2]
            mydict_distinct[dat[0]] = 1
            myIDlist.append(dat[0])
    flg = 0
    for n in myIDlist:
        if mydict[n] > 999999:
            print n
            flg = 1
    if flg == 0:
        print 'NA'

Solution (Python):
import sys
while True:
  a=int(input())
  if a==0: break
  ans,name1,name2=[],[],[]
  hogehoge=0
  for i in range(a):
    hoge=map(int,raw_input().split())
    if hoge[0] in name2:
      ww = hoge[1]*hoge[2]
      r = name2.index(hoge[0])
      if len(str(ans[r]+ww)) >= 7: 
        hogehoge+=1
        name1.append(hoge[0])
      else:
        ans[r]+=ww
    else:
      qq = hoge[1]*hoge[2]
      if len(str(qq)) >= 7: 
        hogehoge+=1
        name1.append(hoge[0])
      else: 
        name2.append(hoge[0])
        ans.append(qq)
  if hogehoge == 0: print "NA"
  else: 
    for i in range(len(name1)):
      print name1[i]

Solution (Python):
while True:
    n=input()
    if n==0:
        break
    sale=[0]*4000
    raw=[]
    for unused in xrange(n):
        a,b,c=map(int,raw_input().split())
        sale[a]+=b*c
        if a not in raw:
            raw.append(a)
    ans=[i for i in raw if sale[i]>=1000000]
    if not ans:
        print "NA"
    else:
        print "\n".join(map(str,ans))

Solution (Python):
while 1:
    n = int(raw_input())
    if n == 0: break
    table = []
    index = {}
    for k in range(n):
        i, p, q = raw_input().split()
        record = index.get(i)
        if not record:
            record = [i, 0]
            table.append(record)
            index[i] = record
        record[1] += int(p) * int(q)
    found = False
    for record in table:
        if record[1] >= 1000000:
            print record[0]
            found = True
    if not found:
        print 'NA'

Solution (Python):

import sys


class Person:
    def __init__(self, number):
        self.number = number
        self.total_sales = 0

    def sales(self, price, quantity):
        self.total_sales += price * quantity


while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    persons = []
    for i in range(n):
        num, price, quantity = tuple(map(int, sys.stdin.readline().split(' ')))
        person = filter(lambda x: x.number == num, persons)
        if person:
            person[0].sales(price, quantity)
        else:
            person = Person(num)
            person.sales(price, quantity)
            persons.append(person)
    over_million = filter(lambda x: x.total_sales >= 1000000, persons)
    if not over_million:
        print 'NA'
    else:
        for p in over_million:
            print p.number

Solution (Python):
while 1:
    n=input()
    if n==0: break
    ans={}
    x=[raw_input().split() for _ in range(n)]
    w=[]
    for a,b,c in x:
        if not a in w: w.append(a)
        ans.setdefault(a,0)
        ans[a]+=int(b)*int(c)
    y=[k for k,v in ans.items() if v>=1000000]
    if len(y)==0:
        print 'NA'
    else:
        for z in w:
            if z in y: print z

Solution (Python):
class Member():
	def __init__(self, mi):
		self.member_id	= int(mi)
		self.datalist = []
		
	def addData(self, pr, sn):
		self.datalist.append([int(pr), int(sn)])

	def calc(self):
		sum = 0
		for p, s in self.datalist:
			sum += p * s
		
		return sum
			

output_list = []
members = []
member_dict = {}

while 1:
	n = int(raw_input())
	if n == 0:
		break
	
	dataset = [raw_input() for i in range(n)]
	
	for item in dataset:
		rawlist = map(int, item.split())
		
		if rawlist[0] not in [mem.member_id for mem in members]:
			member_dict[rawlist[0]] = Member(rawlist[0])
			members.append( member_dict[rawlist[0]] )
		
		member_dict[rawlist[0]].addData(rawlist[1], rawlist[2])
		
	output_list_length = len(output_list)
	for mem in members:
		if mem.calc() >= 1000000:
			output_list.append(mem.member_id)
		
		if output_list_length == len(output_list):
			output_list.append("NA")
			
	members = []
	member_dict = {}
			

for s in output_list:
	print s

Solution (Python):
while 1:
    n = int(raw_input())
    if n == 0: break
    table = []
    index = {}
    for k in range(n):
        i, p, q = raw_input().split()
        record = index.get(i)
        if not record:
            record = [i, 0]
            table.append(record)
            index[i] = record
        record[1] += int(p) * int(q)
    found = False
    for record in table:
        if record[1] >= 1000000:
            print record[0]
            found = True
    if not found:
        print 'NA'

Solution (Python):
from sys import stdin


while True:
    n = int(stdin.readline())
    if n==0: break
    ps = []
    prd = {}
    for gomi in xrange(n):
        p,a,b = map(int,stdin.readline().split())
        if p in ps: r = prd.pop(p)+a*b
        else:
            ps.append(p)
            r = a*b
        prd.update({p:r})
    isNA = True
    for p in ps:
        if prd[p]>=1000000:
            print p
            isNA = False
    if isNA: print "NA"

Solution (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()

Solution (Python):

def add(lis,check_list):
    for index in range(len(lis)):
        if lis[index][0]==check_list[0]:
            lis[index][1]+=int(check_list[1])*int(check_list[2])
            return
    lis.append([check_list[0],int(check_list[1])*int(check_list[2])])

while True:
    num=int(raw_input())
    if num==0: break
    lis=[]
    for i in range(num):
        l=raw_input().split(" ")
        add(lis,l)
    c=0
    for ele in lis:
        if ele[1]>=1000000:
            print ele[0]
            c+=1
    if c==0: print "NA"

Solution (Python):
while True:
	n = int(raw_input())
	if n == 0: break
	data = {}
	order = []
	for i in range(n):
		id,price,quant = map(int, raw_input().split())
		if id in data:
			data[id] += price*quant
		else:
			data[id] = price*quant
			order.append(id)
	if max(data.values()) < 1000000:
		print "NA"
	else:
		for k in order:
			if data[k] >= 1000000: print k

Solution (Python):
import sys

datasetnum=[]
n=-1

def calculatebillionare(n):
    global datasetnum
    scores={}
    billionares=[]
    if n==-1:
        return None
    else:
        for salesdata in datasetnum:
            if not salesdata[0] in billionares:
                if salesdata[0] in scores:
                    scores[salesdata[0]]=scores[salesdata[0]]+salesdata[1]*salesdata[2]
                else:
                    scores[salesdata[0]]=salesdata[1]*salesdata[2]
                if scores[salesdata[0]]>=1000000:
                    billionares.append(salesdata[0])
                    del(scores[salesdata[0]])
        if len(billionares)==0:
            print "NA"
        else:
            for people in billionares:
                print people
        datasetnum=[]
        return None
                    
for line in sys.stdin:
    line=line.strip()
    line=line.split(" ")
    lineelement=map(int,line)
    if len(lineelement)==1:
        calculatebillionare(n)
        if lineelement[0]==0:
            break
        else:
            n=lineelement[0]
    else:
        datasetnum.append(lineelement)

Solution (Python):
while True:
    ans = []
    data = {}
    r = input()
    if r == 0:
        break
    for i in xrange(r):
        tmp = map(int, raw_input().split())
        
        if tmp[0] in data.keys():
            data[tmp[0]] += tmp[1] * tmp[2]
        else:
            data.update({tmp[0]:tmp[1]*tmp[2]})
    
        if data[tmp[0]] >= 1000000 and tmp[0] not in ans:
            ans.append(tmp[0])
    if len(ans) == 0:
        print "NA"
    else:
        print "\n".join(map(str, ans))

Solution (Python):
while True:
  N = input()
  if not N:
    break
  m = dict()
  o = []
  for i in range(N):
    a, b, c = map(int, raw_input().split())
    o.append(a)
    m[a] = (m[a] if a in m else 0) + b * c
  oo = []
  for x in o:
    if x not in oo:
      oo.append(x)
  for i in oo:
    if m[i] >= 1000000:
      print(i)
  if max(m.values()) < 1000000:
    print('NA')

Solution (Python):

while True:
    n = int(input())
    if n == 0:break
    sya = {}
    
    
    for _ in range(n):
        try:
            a,b,c = map(int,input().split())
            sya[a] = sya[a]+b*c
        except KeyError:
            sya[a] = b*c
    k =[]
    
    
    for i in sya:
        if sya[i] >= 1000000:print(i)
        k.append(sya[i] >= 1000000)
    if not any(k) == True:print("NA")

Solution (Python):
while True:
    flg = True
    inf = []
    dic = {}
    n = int(input())
    if n==0:
        break
    for i in range(n):
        inf.append(list(map(int,input().split())))
        if inf[i][0] in dic:
            tmp = dic[inf[i][0]] + inf[i][1]*inf[i][2]
            dic[inf[i][0]] = tmp
        else:
            dic[inf[i][0]] = inf[i][1]*inf[i][2]

    for shain_id,sale in dic.items():
        if sale >= 1000000:
            print(shain_id)
            flg = False
    if flg:
        print("NA")

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

    lst = [0]*4001
    elst = []
    ans = []
    for i in range(n):
        e, p, q = map(int, input().split())
        if lst[e]:
            pass
        else:
            elst.append(e)

        lst[e] = lst[e] + p*q

    for i in elst:
        if lst[i] >= 1000000:
            ans.append(i)

    if ans == []:
        print('NA')
    
    else:
        for i in ans:
            print(i)

Solution (Python):
def solve():
    N = int(input())
    if N == 0:
        return False
    E = []
    D = {}
    for i in range(N):
        e, p, q = map(int, input().split())
        E.append(e)
        D[e] = D.get(e, 0) + p*q
    cnt = 0
    for e in E:
        if D.get(e, 0) >= 1000000:
            print(e)
            del D[e]
            cnt += 1
    if cnt == 0:
        print("NA")
    return True
while solve():
    ...

Solution (Python):
while True:
    input_n = int(input())
    key = 0
    if input_n == 0:
        break
    id_list = [[0 for i in range(2)]for i in range(input_n)]
    for i in range(input_n):
        id_line = input().split()
        for j in id_list:
            if j[0] == int(id_line[0]):
                j[1] += int(id_line[1]) * int(id_line[2])
                uriage = j[1]
                break
        else:
            id_list[i][0] = int(id_line[0])
            id_list[i][1] = int(id_line[1]) * int(id_line[2])
            uriage = id_list[i][1]
        if uriage >= 1000000:
            key = 1
    
    for i in id_list:
        if key == 0:
            print("NA")
            break
        if i[1] >= 1000000:
            print(i[0])

Solution (Python):
from collections import defaultdict

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

    dv = defaultdict(int)
    for _ in range(n):
        e, p, q = list(map(int, input().split()))
        dv[e] += p * q
    
    count = 0
    for k, v in dv.items():
        if v >= 1000000:
            print(k)
            count += 1
    if count == 0:
        print("NA")

Solution (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")

Solution (Python):
while 1:
    n=int(input())
    if n==0:break
    a={};c=[]
    for _ in range(n):
        b=list(map(int,input().split()))
        if b[0] in a:a[b[0]]+=b[1]*b[2]
        else:a[b[0]]=b[1]*b[2];c.append(b[0])
    if max(a.values())<=999999:print('NA' )
    for i in c:
        if a[i]>999999:print(i)

Solution (Python):
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")

Solution (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")

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    save_list=[0]*4001
    display_list = []
    for i in range(n):
        a,b,c =  map(int, input().split())
        save_list[a] += b * c
        if a not in display_list:
            display_list.append(a)
    ans = []
    for i in display_list:
        if save_list[i] >= 1000000:
            ans.append(i)
    if not ans:
        print("NA")
    else:
        for i in ans:
            print(i)