Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

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

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

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

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

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

C++: #include <bits/stdc++.h>

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint lin(){ lint x; scanf("lld", &x); return (x); }

int main()
{
	list<int> staffList;
	map<int, lint> saleResult;
	int n;
	int staffNum;
	lint unitPrice;
	lint quantity;
	while( 1 )
	{
		n = in();
		if( n == 0 )break;

		staffList.clear();
		saleResult.clear();
		loop(i, 0, n)
		{
			staffNum = in();
			unitPrice = lin();
			quantity = lin();
			staffList.push_back(staffNum);
			saleResult[staffNum] += unitPrice * quantity;
		}
		bool flag = false;
		for(list<int>::iterator it = staffList.begin(); it != staffList.end(); it++)
		{
			if( saleResult[*it] >= 1000000 )
			{
				printf("%d\n", *it);
				saleResult[*it] = 0;
				flag = true;
			}
		}
		if( !flag )
		{
			cout << "NA" << endl;
		}
	}
	return (0);
}

C++: #include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int findNum(vector<pair<int,int> > comm, int num) {
    for(int i=0; i<comm.size(); i++)  {
      if(comm[i].first == num) {
	return i;
      }
    }
    return comm.size();
  }

int main() {
  int n;
  cin>>n;
  while(n != 0) {
    int m = n;
    vector<pair<int,int> > comm;
    while(m--) {
      int num, price, unit;
      cin>>num>>price>>unit;
      int dataNum = findNum(comm, num);
      if(dataNum == comm.size()) {
        comm.push_back(make_pair(num, price*unit));
      }
      else {
        comm[dataNum].second += price*unit;
      }
    }

    bool flag = true;
    for(int i=0; i<comm.size(); i++) {
      if(comm[i].second >= 1000000) {
        cout<<comm[i].first<<endl;
        flag = false;
      }
    }
    if(flag == true) {
      cout<<"NA"<<endl;
    }
    cin>>n;
  }
}

C++: #include<stdio.h>
int main(void)
{
    int n,flg,j,i,a[1000];
	double b[1000],c[1000],d[1000];
	while(1){
	    scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
		    scanf("%d %lf %lf",&a[i],&b[i],&c[i]);
		}
		for(i=0;i<n;i++){
		    d[i]=b[i]*c[i];
		}
		for(i=0;i<n-1;i++){
		    for(j=i+1;j<n;j++){
			    if(a[i]==a[j]){
				    d[i]=d[i]+d[j];
					d[j]=0;
				}
			}
		}
		flg=0;
		for(i=0;i<n;i++){
		    if(d[i]>=1000000){
			    printf("%d\n",a[i]);
				flg=1;
			}
		}
		if(flg==0) printf("NA\n");
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main(){
	long long n,a,b,c;
	vector<long long >g;
	while(cin >> n && n){
		g.clear();
		for(int i=0;i<n;i++){
			cin >> a >> b >> c;
			if(b>10000&&c>10000)g.push_back(a);
			else if(b*c>=1000000)g.push_back(a);
		}
		if(!g.size())cout << "NA" << endl;
		for(int i=0;i<g.size();i++){
			cout << g[i] << endl;
		}
	}
}

C++: #include <iostream>
#include <cstring>
#include <map>
using namespace std;

int main() {
	int n;
	while(std::cin >> n){
		if(!n){
			return 0;
		}
		std::map<int, long long> sales;
		while(n--){
			int id, unit, num;
			std::cin >> id >> unit >> num;
			sales[id] += unit * num;
		}
		map<int, long long>::iterator it;
		bool found = false;
		for(it = sales.begin(); it != sales.end(); it++){
			if(it->second >= 1000000){
				found = true;
				std::cout << it->first << std::endl;
			}
		}
		if(!found){
			std::cout << "NA" << std::endl;
		}
	}
	return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	while (cin >> n&&n) {
		long long member[4001] = {0};
		long long a, b, c;
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			member[a] += b*c;
		}
		int count = 0;
		for (int i = 0; i < 4001; i++) {
			if (member[i] >= 1000000) {
				count++;
				cout << i << endl;
			}
		}
		if (count == 0)cout << "NA" << endl;
	}
}

C++: #include <cstdio>
#include <queue>
using namespace std;

bool employee[4000]={false}; 
const int sales = 1000000;

int main()
{
	int n;
	while(scanf("%d",&n)!=EOF) {
		if(n==0){break;}
		queue<int> employee_n;
		for(int i=0;i<n;++i) {
			int number,a,b;
			scanf("%d %d %d",&number,&a,&b);
			if(sales>a*b||employee[number-1]) continue;
			employee[number-1]=true;
			employee_n.push(number);
		}
		if(employee_n.empty()) puts("NA");
		else {
			while(!employee_n.empty()){
				printf("%d\n",employee_n.front());
				employee_n.pop();
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <map>
using namespace std;

int main(){
	int n;
	while( cin >> n, n ){
		map<int, int> worker;
		queue<int> order;
		for( int i = 0; i < n; i++ ){
			int id, price, num;
			cin >> id >> price >> num;
			if( worker.find(id) == worker.end() ){
				order.push(id);
			}
			worker[id] += price * num;
		}
		bool flag = true;
		while( !order.empty() ){
			if( worker[order.front()] >= 1000000 ){
				cout << order.front() << endl;
				flag = false;
			}
			order.pop();
		}
		if( flag ){
			cout << "NA" << endl;
		}
	}
}

C++: #include <cstdio>
using namespace std;

typedef long long Int;

int main(){
	const int AIM = 1000000;
	int n;
	int num, per, sum;
	bool exist;
	bool comp[4001];
	Int pro[4001];
	
	while(true){
		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 1; i <= 4000; i++){
			comp[i] = false;
			pro[i] = 0;
		}
		exist = false;
		for(int i = 0; i < n; i++){
			scanf("%d%d%d", &num, &per, &sum);
			if(comp[num]) continue;
			if(pro[num] + (Int)per * sum >= AIM){
				exist = true;
				comp[num] = true;
				printf("%d\n", num);
			}
			else{
				pro[num] += (Int)per * sum;
			}
		}
		if(!exist) printf("NA\n");
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    while(true){
        int n; cin>>n;
        if(n==0)break;
        map<ll,ll> m;
        REP(i,n){
            ll e,p,q; cin>>e>>p>>q;
            if(m.find(e)==m.end())m[e]=p*q;
            else m[e]+=p*q;
        }
        int cnt=0;
        for(auto itr=m.begin();itr!=m.end();itr++){
            if(itr->second>=1000000){
                cout<<itr->first<<endl;
                cnt++;
            }
        }
        if(cnt==0)cout<<"NA"<<endl;
    }
    
    
    
    return 0;
}