Go: package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}
		sales := make(map[string]int)
		existed := make(map[string]bool)
		order := make([]string, 4000)
		flg := false
		for i := 0; i < n; i++ {
			stdin.Scan()
			l := strings.Split(stdin.Text(), " ")
			e := l[0]
			p, _ := strconv.Atoi(l[1])
			q, _ := strconv.Atoi(l[2])
			sales[e] += p * q
			if !existed[e] {
				order = append(order, e)
				existed[e] = true
			}
		}
		for _, v := range order {
			if sales[v] >= 1000000 {
				fmt.Println(v)
				flg = true
			}
		}
		if flg == false {
			fmt.Println("NA")
		}
	}
}

C++: // #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>	// istringstream
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(); it!=c.end(); ++it)

// #defineの初利用にあたって参考にした http://peroon.hatenablog.com/entry/20091123/1258966199
// iteratorのforLoop                   http://bokko.hatenablog.com/entry/20090320/1237494217
// fastIO                              https://gist.github.com/rigibun/7905920

void solveAndOutput(map<int, long long> data, VI bangouList){
	int outputCount = 0;

	FOR(i, 0, bangouList.size()){
		if (data[bangouList[i]] >= 1000000){
			cout << bangouList[i] << endl;
			outputCount++;
		}
	}
	if (outputCount == 0)
		cout << "NA" << endl;
}

int main(){
	// sankou http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=97994#1

	long long n;
	// 重複なし、自動ソート
	map<int, long long> data;
	// 重複あり、ソートなし -> 重複するものは格納しないようにしたい.
	VI bangouList;
	fastIO;

	while (cin >> n, n){
		data.clear();
		bangouList.clear();
		while (n--){
			int bangou = 0, tanka = 0, suu = 0;
			cin >> bangou >> tanka >> suu;
			if(data[bangou] == 0)
				bangouList.push_back(bangou);
			data[bangou] += tanka * suu;
		}
		solveAndOutput(data, bangouList);
	}
	return 0;
}

C++: #include<stdio.h>

int main(){
	int num,age,tanka;
	int i,j,n,temp;
	int sya[4000];
	double uriage[4000][2]={ 0 };
	
	
	for(;;temp=0){
		scanf("%d", &n);
		
		for(i=0;i<n;i++){
			scanf("%d%d%d", &num, &tanka, &age);
			
			for(j=0;j<=i;j++){
				if(sya[j]==num){
					uriage[j][0]+=tanka*age;
					break;
				} else {
					sya[i]=num;
					uriage[i][0]+=tanka*age;
					break;
				}
			}
		}
		for(i=0;i<4000;i++){
			if(uriage[i][0]>=1000000 && uriage[i][1] != 1){
				uriage[i][1]=1;
				temp=1;
				break;
			}
		}
		if(temp==1)printf("%d\n",sya[i]);
		else puts("NA");
		if(n==0)break;
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>

int main(void) {
int n;
int employees[4000] = {0};
while (1) {
scanf("%d", &n);
if (!n) break;

for (int i = 0; i < n; i++) {
int id, price, sales;
scanf("%d %d %d\n", &id, &price, &sales);
employees[id] += price * sales;
}

int found = 0;
for (int i = 0; i < 4000; i++) {
if (employees[i] >= 1000000) {
printf("%d\n", i);
found = 1;
}
}
memset(employees, 0, sizeof employees);
if (!found) {
printf("NA\n");
}

}
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<functional>
#define inf 1000000
using namespace std;
long long int p[114514],x,y,z,w;
int main(void)
{
	int i,j,k,f,n,cnt;
	while(1) {
		cin>>n;
		f=0,cnt=0;
		if(!n)break;
		for(i=0;i<4001;i++) p[i]=0;
		for(i=0;i<n;i++) {
			cin>>x>>y>>z;
			if(y>=inf) y=w;
			else w=y*z;
			if(p[x]>=inf) {}
			else p[x]+=y*z;
		}
		for(i=0;i<4001;i++) {
			if(p[i]>=inf) {
				cout<<i<<endl;
				f=1;
			}
		}
		if(f==0) cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <map>
#include <set>
#include <vector>

int main() {
    int n;
    while (~scanf("%d", &n)) {
        if (n == 0) break;
        
        std::vector<unsigned int> v;
        std::map<unsigned int, unsigned long long int> m;
        
        unsigned int a;
        unsigned long long int b, c;
        for (int i = 0; i < n; ++i) {
            scanf("%u %llu %llu", &a, &b, &c);
            v.push_back(a);
            m[a] += b * c;
        }
        
        std::set<unsigned int> dup;
        bool found = false;
        for (auto i : v) {
            if (m[i] >= 1000000 && dup.count(i) == 0) {
                printf("%u\n", i);
                dup.insert(i);
                found = true;
            }
        }
        if (!found) {
            printf("NA\n");
        }
    }
}

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

int main(){
	int N;
	
	while(cin>>N,N){
		map<int,long long int> mp;
		vector <int> vi;
		queue<int >q;
		for(int i=0;i<N;i++){
			int num,tanka,suuryo;
			cin>>num>>tanka>>suuryo;
			if(mp[num]==0){
				vi.push_back(num);
			}
			mp[num]+=tanka*suuryo;
		}
		vector<int>::iterator it=vi.begin();
		for(;it!=vi.end();it++){
			if(mp[*it]>=1000000){
				q.push(*it);
			}
		}
		if(q.empty()){
			cout<<"NA"<<endl;
		}
		else{
			int len=q.size();
			for(int i=0;i<len;i++){
				cout<<q.front()<<endl;
				q.pop();
			}
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<memory.h>
int main(){
	int n,i,j,k,e[100],p[100],q[100];
	int c[100],count=0,count2=0;
	int gokei=0;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%d %d %d",&e[i],&p[i],&q[i]);
			gokei=p[i]*q[i];
			for(j=0;j<i;j++){
				if(e[i]==e[j]){
					gokei+=p[j]*q[j];
				}
			}
			for(k=0;k<count;k++){
				if(e[i]==c[k]){
					goto a;
				}
			}
			if(gokei>=1000000){
				c[count]=e[i];
				count++;
			}
			a:
			gokei=0;
		}
		for(i=0;i<count;i++){
			printf("%d\n",c[i]);
		}
		if(count==0){
			printf("NA\n");
		}
		count=0;
		memset(c,0,sizeof(c));
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <string.h>

int main(void) {
    int n;
    int employees[4000] = {0};
    while (~scanf("%d", &n)) {
        for (int i = 0; i < n; i++) {
            int id, price, sales;
            scanf("%d %d %d", &id, &price, &sales);
            employees[id] += price * sales;
        }

        int found = 0;
        for (int i = 0; i < 4000; i++) {
            if (employees[i] >= 1000000) {
                printf("%d\n", i);
                found = 1;
            }
        }
        memset(employees, 0, sizeof employees);
        if (!found) {
            printf("NA\n");
        }

    }

    return 0;
}

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

int main(){
  int n;
  while(cin >> n,n){
    map<int, long long> m;
    vector<int> order;
    for(int i = 0 ; i < n ; i++ ){
      int id;
      long long a, b;
      cin >> id >> a >> b;
      if( m.find(id) == m.end()){
	order.push_back(id);
	m[id] = a*b;
      }else{
	m[id] += a*b;
      }
    }
    bool isAns = false;
    for(int i = 0; i < (int)order.size(); i++){
      long long money = m[ order[i] ];
      if( money  >= 1000000){
	cout << order[i] << endl;
	isAns = true;
      }
    }
    if( !isAns )cout << "NA" << endl;
  }
  return 0;
}