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++: #include <stdio.h>
#include <string.h>

int member[4010][3] ;
int price[4010] ;
bool vis[4010] ;

int main ( )
{
	int n ; 
	bool na ;
	int low ;
	int high ;
	while ( scanf ( "%d" , &n ) == 1 && n ){
		low = 2147483600 ;
		high = -1 ;
		na = false ;
		memset ( vis , false , sizeof ( vis ) ) ;
		memset ( price , 0 , sizeof ( price ) ) ;
		for ( int i = 0 ; i < n ; i++ ){
			scanf ( "%d %d %d" , &member[i][0] , &member[i][1] , &member[i][2] ) ;
			int tmp = member[i][1] * member[i][2] ;
			price[member[i][0]] += tmp ;
			vis[member[i][0]] = true ;
			high = ( member[i][0] > high ) ? member[i][0] : high ;
			low = ( member[i][0] < low ) ? member[i][0] : low ;
		}
		for ( int i = low ; i <= high ; i++ ){
			if ( vis[i] == true && price[i] >= 1000000 ){
				printf ( "%d\n" , i ) ;
				na = true ;
			}
		}
		if ( ! na ){
			printf ( "NA\n" ) ;
		}
	}
	return 0 ;
}

C++: #include<cstdio>
#include<vector>

using namespace std;
const int target = 1000000;
vector<int> heros;

int main()
{
	int data;
	while (1)
	{
		scanf("%d", &data);
		if (data == 0)break;
		bool hero = false;
		for (int i = 0; i < data; i++)
		{
			int num, sell, cnt;
			scanf("%d %d %d", &num, &sell, &cnt);
			if (sell*cnt >= target)
			{
				bool already = false;
				for (int j = 0; j < heros.size(); j++)
				{
					if (heros[j] == num)
						already = true;
				}
				if (already == false)
				{
					printf("%d\n", num);
					heros.push_back(num);
					hero = true;
				}
			}
		}
		if (hero==false)
			printf("NA\n");
	}
	return 0;
}

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

int main(){
    int n;
    while( cin >> n ){
        if( !n ) break;
        vector< long long > ls(4001, 0);
        bool NA = true;
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> a >> b >> c;
            if( ls[a] >= 0 ){
                ls[a] += b*c;
                if( ls[a] >= 1000000){
                    cout << a << endl;
                    NA = false;
                    ls[a] = -1;
                }
            }
        }
        if( NA ) cout << "NA" << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    int data_num;
    while (cin >> data_num && data_num != 0) {
        vector<int> idx;
        map<int, long long> sale;

        while (data_num--) {
            int no, price, num;
            cin >> no >> price >> num;

            long long sum = static_cast<long long>(price) * num;
            if (sale.find(no) == sale.end()) {
                idx.push_back(no);
                sale.insert(make_pair(no, sum));
            } else {
                sale.at(no) += sum;
            }
        }

        bool is_NA = true;
        for (size_t i = 0; i < idx.size(); i++) {
            if (sale.at(idx.at(i)) >= 1000000) {
                cout << idx.at(i) << endl;
                is_NA = false;
            }
        }

        if (is_NA) {
            cout << "NA" << endl;
        }
    }

    return 0;
}

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;
typedef map<int, long int> mapILI;

#define MP make_pair
//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 fastIO	cin.tie(0); ios::sync_with_stdio(false);

// #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(mapILI data){
	int outputCount = 0;
	// for (map<int, long int>::iterator it = data.begin(); it != data.end();it++){
	foreach_it(mapILI,it,data){
		if ((*it).second >= 1000000){
			cout << (*it).first << endl;
			outputCount++;
		}
	}
	if (outputCount == 0)
		cout << "NA" << endl;
}

int main(){
	int n;
	map<int, long int> data;
	fastIO;

	while (cin >> n, n){
		data.clear();
		while (n--){
			int bangou = 0, tanka = 0, suu = 0;
			cin >> bangou >> tanka >> suu;
			// data.insert(pair<int, LL>(bangou, tanka*suu));
			// long intに収まるように、出力確定のものはもう足さない.
			if (data[bangou] < 1000000)
				data[bangou] += tanka * suu;
		}
		solveAndOutput(data);
	}
	return 0;
}

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

int main() {
	int tmp=0, tmpi=0, tmpp=0, tmpq=0, n=1, tmpn=0, ans0=0;
	long long int ans[4001];
	while (1) {
		ans0=0;
		scanf("%d", &n);
		if (n==0) break;
		for (tmp=0;tmp<4001;tmp++) ans[tmp]=0;
		for (tmpn=0;tmpn<n;tmpn++) {
			scanf("%d %d %d", &tmpi, &tmpp, &tmpq);
			ans[tmpi]+=(long long int)tmpp*tmpq;
		}
		for (tmp=0;tmp<4001;tmp++) {
			if (ans[tmp]>=1000000) {
				ans0++;
				printf("%d\n", tmp);
			}
		}
		if (ans0==0) puts("NA");
	}
	return 0;
}

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

int main() {
  int n;

  while(cin >> n, n) {
    vector<int> ans;
    long long int e, p, m;

    for(int i = 0; i < n; i++) {
      cin >> e >> p >> m;
      if(p*m >= 1000000) {
	bool b = true;
	auto it = ans.begin(); 
	while(it != ans.end()) {
	  if(*it == e) b = false;;
	  it++;
	}
	if(b) ans.push_back(e);
      }
    }
    
    if(ans.empty()) {
      cout << "NA" << endl;
    } else {
      auto it = ans.begin();
      while(it != ans.end()) {
	cout << *it << endl;
	it++;
      }
    }
  }
}