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):
while True:
    n = int(input())
    if n == 0: break

    data = {}
    staff = []
    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]
            staff.append(tmp[0])

    if max(data.values()) < 1000000:
        print('NA')
    else:
        for k in staff:
            if data[k] >= 1000000:
                print(k)

Solution (Python):
while True:
    n = int(raw_input())
    if n == 0:
        break
    sale = {}
    order = []
    
    for i in range(n):
        j,p,q = map(int,raw_input().split())
        if j in sale:
            sale[j] += p * q
        else:
            sale[j] = p * q
            order.append(j)
         
    existflag = False
    for j in order:
        if sale[j] >= 1000000:
            print j
            existflag = True
    if not existflag:
        print 'NA'

Solution (Python):
class sresult():
 def judge(self,n):
  list={}
  list2=[]
  for i in range(0,n):
   str=raw_input()
   array=str.split(" ")
   no=int(array[0])
   x=no
   sale=int(array[1])
   sold=int(array[2])
   
   if x in list:
    list[no]+=sale*sold
    if list[no]>=1000000 and x not in list2:
     list2.append(no)
   
   else :
    list.update({x:sale*sold})
   if list[no]>=1000000 and x not in list2:
     list2.append(no)
  for i in range(0,len(list2)):
   print list2[i]
  if len(list2)==0:
    print "NA"
  
if __name__=="__main__":
 ans=sresult()
 while True:
  
  n=input()
  if n==0:
   break
  ans.judge(n)

Solution (Python):





from collections import OrderedDict

if __name__ == "__main__":

    while True:
        d = OrderedDict()
        n = int(input())
        if not n:
            break  

        for i in range(n):
            s, p, m = map(int, input().strip("\n").split(" "))
            

            if s in d:
                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")

Solution (Python):
import collections
while 1:
	li=collections.defaultdict(int)
	emplist=[]
	n=int(input())
	if n==0:
		break
	for i in range(n):
		(emp,prc,num)=list(map(int,input().split()))
		if emp not in emplist:
			emplist.append(emp)
		li[emp]+=prc*num
	tmp=True
	for i in emplist:
		if li[i]>=1000000:
			print(i)
			tmp=False
	if tmp:
		print("NA")
	li.clear()

Solution (Python):
def f(n):
  D={}
  A=[]
  for _ in range(n):
    a,b,c=map(int,raw_input().split(' '))
    if D.has_key(a): D[a]+=b*c
    else:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  return B

while 1:
  n=input()
  if n==0:break
  x=f(n)
  for e in x: print e

Solution (Python):
def f(n):
  D={}
  A=[]
  for _ in range(n):
    a,b,c=map(int,raw_input().split(' '))
    if D.has_key(a): D[a]+=b*c
    else:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  return B

while 1:
  n=input()
  if n==0:break
  for e in f(n): print e

Solution (Python):
def f(n):
  D={}
  A=[]
  for _ in range(n):
    a,b,c=map(int,raw_input().split(' '))
    try: D[a]+=b*c
    except:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  return B

while 1:
  n=input()
  if n==0:break
  for e in f(n): print e

Solution (Python):
def f(n):
  D={}
  A=[]
  for _ in range(n):
    a,b,c=map(int,raw_input().split(' '))
    if D.has_key(a): D[a]+=b*c
    else:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  return B

while 1:
  n=input()
  if n==0:break
  x=f(n)
  for e in x: print e

Solution (Python):
def f(n):
  D={}
  A=[]
  for _ in range(n):
    a,b,c=map(int,raw_input().split(' '))
    try: D[a]+=b*c
    except:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  return B
 
while 1:
  n=input()
  if n==0:break
  x=f(n)
  for e in x: print e

Solution (Python):
def f(n):
  D={}
  A=[]
  for _ in range(n):
    a,b,c=map(int,raw_input().split(' '))
    if a in D: D[a]+=b*c
    else:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  return B

while 1:
  n=input()
  if n==0:break
  for e in f(n): print e

Solution (Python):
while 1:
  n=input()
  if n==0:break
  D={}
  A=[]
  for _ in range(n):
    a,b,c=map(int,raw_input().split(' '))
    if a in D: D[a]+=b*c
    else:
      D[a]=b*c
      A.append(a)
  f=1
  for i in A:
    if D[i]>=1e6: print i; f=0
  if f: print "NA"

Solution (Python):
while 1:
  n=input()
  if n==0: break
  D={}
  A=[]
  for _ in range(n):
    a,b,c=map(int, raw_input().split(' '))
    if a in D: D[a]+=b*c
    else:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  for e in B: print e

Solution (Python):
def f(n):
  D={}
  A=[]
  for _ in range(n):
    a,b,c=map(int, raw_input().split())
    if a in D: D[a]+=b*c
    else:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  return B

while 1:
  n=input()
  if n==0: break
  for e in f(n): print e

Solution (Python):
while 1:
  n=input()
  if n==0: break
  D={}
  A=[]
  for _ in [0]*n:
    a,b,c=map(int, raw_input().split())
    if D.has_key(a): D[a]+=b*c
    else:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  for e in B: print e

Solution (Python):
while True:
	n=int(input())
	if n==0: break
	l=[]
	d={}
	for _ in range(n):
		a,b,c=list(map(int,input().split()))
		if a in d:
			d[a]+=b*c
		else:
			d[a]=b*c
			l.append(a)
	if max(d.values())<1000000:
		print("NA")
	else:
		for k in l:
			if d[k]>=1000000:
				print(k)

Solution (Python):

while True:
    n = int(raw_input())
    if n == 0:
        break
    else:
        IDdic={}
        for k in range(n):  
            ID, p, q = map(int,raw_input().split())
            if ID not in IDdic:
                IDdic[ID] = [k, p*q]
            elif ID in IDdic:
                IDdic[ID][1] += p*q

        
        temp = []        
        for key in IDdic.keys():
            m=0
            if IDdic[key][1] >=1000000 :
                m+=1
                temp.append((IDdic[key][0],key))
                temp=sorted(temp)
        for sortedID in temp:
            print sortedID[1]
        if temp==[]:
            print "NA"

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

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):
while True:
    num = int(raw_input())
    if num == 0: break

    dic = {}
    odr = []
    for i in range(num):
        uid, p, q = map(int, raw_input().split())
        if dic.has_key(uid): dic[uid] += p * q
        else:
            dic[uid] = p * q
            odr.append(uid)

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

Solution (Python):
while True:
    n = int(input())
    if n == 0: break
 
    data = {}
    staff = []
    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]
            staff.append(tmp[0])
 
    if max(data.values()) < 1000000:
        print('NA')
    else:
        for k in staff:
            if data[k] >= 1000000:
                print(k)

Solution (Python):
while True:
    N = int(raw_input())
    if N == 0: break
    dic = {}
    for i in range(N):
        n, p, q = map(int, raw_input().split())
        if not n in dic:
            dic[n] = [i,p*q]
        else:
            dic[n][1] = dic[n][1]+p*q
            
    lis = [(v[0], k) for k, v in dic.items() if v[1] >= 1000000]
    if lis:
        for t in sorted(lis, key=lambda x: x[0]):
            print t[1]
    else:
        print 'NA'

Solution (Python):
import sys
import collections

thre = 1000000
while 1:
    n = int(raw_input())
    if(n==0):break;
    dic1 = collections.OrderedDict()
    exceed = False
    for i in range(n):
        (a,b,c) = map(int , raw_input().split())
        pre = 0
        if(a in dic1): pre =dic1[a]
        dic1[a] = pre + b * c
        if(dic1[a]>=thre):exceed = True
    if(exceed==False):print "NA"; continue 
    for k in dic1.keys():
        if(dic1[k]>=thre):print k

Solution (Python):
while True:
	n = int(raw_input())
	if n == 0:
		break
	dict = {}
	date = []
	for i in xrange(n):
		num,a,b = map(long,raw_input().split())
		if num in dict:
			dict[num] += a * b
		else:
			dict[num] = a * b
			date.append(num)
	
	judge = True
	for var in date:
		if dict[var] >= 1000000:
			print var
			judge = False
	
	if judge:
		print "NA"

Solution (Python):
while True:
	n = int(raw_input())
	if n == 0:
		break
	dict = {}
	date = []
	for i in xrange(n):
		num,a,b = map(int,raw_input().split())
		if num in dict:
			dict[num] += a * b
		else:
			dict[num] = a * b
			date.append(num)
	
	judge = True
	for var in date:
		if dict[var] >= 1000000:
			print var
			judge = False
	
	if judge:
		print "NA"

Solution (Python):
import sys
from collections import OrderedDict

data = OrderedDict()                                                              
for line in sys.stdin:                     
    lst = line.split(' ')
            
    if len( lst ) < 2:
        cnt = 0            
        for key, val in data.items():
            if val >= 1000000:
                print key
                cnt = cnt + 1
                                               
        if len( data ) != 0 and cnt == 0:
            print "NA"
                                               
        if lst[0] == 0:
            break
                                                         
        data = OrderedDict()
        continue
                                                  
    lst = map(int, lst)
    if lst[0] in data:
        data[ lst[0] ] = data[ lst[0] ] + lst[1]*lst[2]
    else:
        data[ lst[0] ] = lst[1]*lst[2]

sys.exit(0)

Solution (Python):

while True:
	n = int(raw_input())
	if n == 0:
		break
	employee_no = []
	info = {}
	for r in range(n):
		no,unit_price,quantity = map(int, raw_input().split(' '))
		if no in info:
			info[no] += unit_price*quantity
		else:
			info[no] = unit_price*quantity
		if not no in employee_no:
			employee_no.append(no)
	output_flg = False
	for no in employee_no:
		if info[no] >= 10**6:
			output_flg = True
			print no
	if not output_flg:
		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 = {}
    for n in range(N):
        num, p, q = map(int, input().split())
        if num in d:
            d[num][1] += (p*q)
        else:
            d[num] = [n, p*q]
    else:
        fla = False
        for k, v in sorted(d.items(), key=lambda x: x[1][0]):
            if v[1] >= 1000000:
                print(k)
                fla = True
        else:
            if not fla:
                print('NA')

Solution (Python):
def parse(i):
    l = input().strip().split()
    return ((i, l[0]), int(l[1]) * int(l[2]))


n = int(input())

while n:
    ss, d = [parse(_) for _ in range(n)], {}

    for s in ss:
        k = s[0][1]
        d[k] = (d[k][0], d[k][1] + s[1]) if k in d else s

    d = [v[0] for v in d.values() if v[1] >= 1000000]

    if d:
        print('\n'.join(k[1] for k in sorted(d)))
    else:
        print('NA')

    n = int(input())

Solution (Python):
while True:
    n = int(input())
    if n == 0: break
 
    data = {}
    staff = []
    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]
            staff.append(tmp[0])
 
    if max(data.values()) < 1000000:
        print('NA')
    else:
        for k in staff:
            if data[k] >= 1000000:
                print(k)

Solution (Python):
while True:
    n = int(input())
    if n == 0: break
  
    data = {}
    staff = []
    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]
            staff.append(tmp[0])
  
    if max(data.values()) < 1e6:
        print('NA')
    else:
        for k in staff:
            if data[k] >= 1e6:
                print(k)

Solution (Python):
while True:
    n = int(input())
    if n == 0: break
  
    data = {}
    staff = []
    for i in range(n):
        tmp = [int(el) for el in input().split(' ')]
        if tmp[0] in data:
            data[tmp[0]] += tmp[1] * tmp[2]
        else:
            data[tmp[0]] = tmp[1] * tmp[2]
            staff.append(tmp[0])
  
    if max(data.values()) < 1e6:
        print('NA')
    else:
        for k in staff:
            if data[k] >= 1e6:
                print(k)

Solution (Python):
while True:
    n = int(input())
    if n == 0: break
  
    data = {}
    staff = []
    for i in range(n):
        x, y, z = [int(el) for el in input().split(' ')]
        if x in data:
            data[x] += y * z
        else:
            data[x] = y * z
            staff.append(x)
  
    if max(data.values()) < 1e6:
        print('NA')
    else:
        for k in staff:
            if data[k] >= 1e6:
                print(k)

Solution (Python):
from collections import OrderedDict
while True:
    num = int(input())
    if not num: break
    result = OrderedDict()
    for _ in range(num):
        x, y, z = [int(el) for el in input().split(' ')]
        if x in result:
            result[x] += y*z
        else:
            result[x] = y*z
    res = [print(k) for k,v in result.items() if v >= 1e6]
    if not res: print('NA')

Solution (Python):
from collections import OrderedDict
while True:
    num = int(input())
    if not num: break
    result = OrderedDict()
    for _ in range(num):
        x, y, z = [int(el) for el in input().split(' ')]
        if x in result:
            result[x] += y*z
        else:
            result[x] = y*z
    res = [print(k) for k,v in result.items() if v >= 1e6]
    if not res: print('NA')

Solution (Python):
n = int(raw_input())
while n != 0:
    pass_flag = 0
    sales_dict = {}
    id_list = []
    for x in range(0, n):
        data = raw_input()
        data_list = map(int, data.split(' '))
        if not data_list[0] in sales_dict:
            sales_dict[data_list[0]] = data_list[1] * data_list[2]
            id_list.append(data_list[0])
        else:
            sales_dict[data_list[0]] += data_list[1] * data_list[2]
    for x in id_list:
        if  sales_dict[x] >= 1000000:
            print x
            pass_flag = 1
    if pass_flag == 0:
        print 'NA'
    n = int(raw_input())

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    flag = False
    dic = {}
    for j in range(n):
        i,p,q = map(int, input().split())
        if i not in dic:
            dic[i] = [p*q, 0]
        else:
            dic[i][0] += p*q
        
        if dic[i][0] >= 10**6 and dic[i][1] == 0:
            print(i)
            dic[i][1] = 1
            flag = True
    if flag == False:
        print("NA")

Solution (Python):
from sys import stdin

if __name__ == '__main__':
    for line in stdin:
        if int(line) == 0:
            break

        isEmpty = True
        record = {}
        for _ in range(int(line)):
            employee = input().split(' ')
            total = int(employee[1]) * int(employee[2])

            if total >= 1000000:
                print(employee[0])
                isEmpty = False
            else:
                e_t = record.get(employee[0])

                if e_t:
                    e_t = record.get(employee[0]) + total
                    if e_t >= 1000000:
                        print(employee[0])
                        isEmpty = False
                    else:
                        record[employee[0]] = e_t

                else:
                    record[employee[0]] = total

        record.clear()

        if isEmpty:
            print('NA')

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

Solution (Python):
from collections import OrderedDict

while True:
    n = int(input())
    if n == 0:
        break
    ans = OrderedDict()
    for i in range(n):
        e, p, q = [int(x) for x in input().split()]
        if e in ans:
            ans[e] += p * q
        else:
            ans[e] = p * q
    flag = True
    for k, v in ans.items():
        if v >= 1000000:
            flag = False
            print(k)
    if flag:
        print('NA')

Solution (Python):
while True:
    num=int(input())
    if num==0:
        break
    else:
        li=[]
        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]
                li.append(info[0])
    answer=[]
    for i in li:
        if d[i] >=1000000:
            answer.append(i)
    if answer==[]:
        print("NA")
    else:
        for i in answer:
            print(i)

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
	workers = {}
	workernames = []
	greatworkers = 0
	for i in range(n):
		person, price, number = map(int, input().split())
		if person in workers:
			workers[person] += price * number
		else:
			workers[person] = price * number
			workernames.append(person)
	for worker in workernames:
		if workers[worker] >= 1000000:
			print(worker)
			greatworkers += 1	
	if greatworkers == 0:
		print('NA')

Solution (Python):
while True:
	time=input()

	if time==0:
		break

	worr={}
	mem=[]

	for i in range(time):
		shain=map(int, raw_input().split())
		if shain[0] not in worr:
			worr[shain[0]]=shain[1]*shain[2]
			mem.append(shain[0])
		else:
			worr[shain[0]]+=shain[1]*shain[2]

	check=1
	for i in mem:
		if worr[i]>=1000000:
			print i
			check=0
	if check==1:
		print "NA"

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

Solution (Python):
n = int(input())
while n != 0:
    score = {}
    j = 0
    for i in range(n):
        e,p,q = list(map(int,input().split()))
        if e in score:
            score[e]["value"] += p*q
        else:
            score[e] = {"value":p*q, "index":j}
            j += 1
    f = {}
    for e,v in score.items():
        if v["value"] >= 1000000:
            f[v["index"]] = e
    if len(f)==0:
        print("NA")
    else:
        for w in sorted(f.items(), key = lambda x:x[0]):
            print(w[1])
    n = int(input())

Solution (Python):
while True:
    n = int(input())
    if n == 0:
        break
    d = {}
    e = []
    for i in range(n):
        tmp = list(map(int, input().split(' ')))
        if tmp[0] in d:
            d[tmp[0]] += tmp[1] * tmp[2]
        else:
            d[tmp[0]] = tmp[1] * tmp[2]
            e.append(tmp[0])
 
    if max(d.values()) < 1000000:
        print('NA')
    else:
        for k in e:
            if d[k] >= 1000000:
                print(k)

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

Solution (Python):
l = int(input())
while l != 0:
	k = 0
	A = []
	B = []
	for l in range(0,l):
		li = input().split()
		if li[0] in A:
			i = A.index(li[0])
			B[i] = B[i] + (int(li[1]) * int(li[2]))
		else:
			A.append(li[0])
			B.append(int(li[1]) * int(li[2]))
	for j,b in enumerate(B):
		if b >= 10**6:
			print(A[j])
			k = 1
		
	if k == 0:
		print("NA")
	l = int(input())

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

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

Solution (Python):


import sys
import os
import math
from collections import defaultdict

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    d = defaultdict(int)
    keys = []
    for i in range(n):
        e, p, q = map(int, input().split())
        d[e] += p * q
        if e not in keys:
            keys.append(e)

    
    is_exist = False

    for key in keys:
        v = d[key]
        if v >= 1000000:
            print(key)
            is_exist = True

    if not is_exist:
        print('NA')

Solution (Python):


employeeSalesList = []

def resetDataset():
    for count in range(len(employeeSalesList)):
        employeeSalesList.pop(0)

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

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

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

Solution (Python):


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

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

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

Solution (Python):


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)

Solution (Python):


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

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):
        employeeId, price, volume = list(map(int, input().split(" ")))
        employeeSales = searchEmployeeSales(employeeId)
        employeeSales[1] += price * volume
    printEmployeeOfDataset()
    resetDataset()
    dataCount = readDataCount()

for row in answerList:
    print(row)

Solution (Python):


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 printEmployeeOfDataset():
    answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
    if len(answerList) == 0:
        print("NA")
    else:
        print("\n".join(map(str, answerList)))

resetDataset()
dataCount = readDataCount()
while dataCount > 0:
    for _ in range(dataCount):
        employeeId, price, volume = list(map(int, input().split(" ")))
        employeeSales = searchEmployeeSales(employeeId)
        employeeSales[1] += price * volume
    printEmployeeOfDataset()
    resetDataset()
    dataCount = readDataCount()

Solution (Python):


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

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

dataCount = int(input())
while dataCount > 0:
    employeeSalesList = []
    for _ in range(dataCount):
        employeeId, price, volume = list(map(int, input().split(" ")))
        employeeSales = searchEmployeeSales(employeeId)
        employeeSales[1] += price * volume
    printEmployeeOfDataset()
    dataCount = int(input())

Solution (Python):


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

dataCount = int(input())
while dataCount > 0:
    employeeSalesList = []
    for _ in range(dataCount):
        dataList = input().split(" ")
        employeeId, price = dataList[0], int(dataList[1]) * int(dataList[2])
        employeeSales = searchEmployeeSales(employeeId)
        employeeSales[1] += 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())