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 &times; 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



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


Sample output:
1001
1003
NA
2013

Submission status: Accepted

Solution code:
# 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

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

Submission status: Accepted

Solution code:
# 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)

Submission status: Accepted

Solution code:
# 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

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)

Submission status: Accepted

Solution code:
# 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 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()

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
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())

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
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())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    #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())
        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:])

Submission status: Accepted

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


def solve(data):
    # ?£???????1,000,000??\????????????ID?????????
    # ??????????????????????????°????????´??????????????????ID?????\??????????????????????????????????????????
    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):
    #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())
        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:])

Submission status: Accepted

Solution code:
# Aizu Problem 0100: Sale Result
#
import sys, math, os

# read input:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding:utf-8

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 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')

Submission status: Accepted

Solution code:
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'

Submission status: Accepted

Solution code:
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]

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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'

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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"

Submission status: Accepted

Solution code:
#!/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()

Submission status: Accepted

Solution code:

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"

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)