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 <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++;
      }
    }
  }
}

C++: #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;

static const int invalid_order = 1000000;
struct data {
	string ID;
	long long total;
	int order;

	data() {
		ID = -1;
		total = 0;
		order = invalid_order;
	}

	bool operator<(const data d) const {
		return order < d.order;
	}
};

int main() {
	int n;

	while(cin >> n, n) {
		int price, sale;
		string ID;
		data table[4096];
		bool flag = false;
		int order_count = 0;

		/*
		for(int i = 0; i < 4096; i++) {
			table[i].ID = i;
		}
		*/

		for(int i = 0; i < n; i++) {
			char in[128];
			char ID_s[32], price_s[32], sale_s[32];
			int j, k;

			// input
			/*
			fgets(in, 120, stdin);
			for(j = 0,k = 0; in[j + k] != ' ' && in[j + k] != ';'; k++)
				ID_s[k] = in[j + k];
			ID_s[k] = '\0';
			j = k + 1;
			for(k = 0; in[j + k] != ' ' && in[j + k] != ';'; k++)
				price_s[k] = in[j + k];
			price_s[k] = '\0';
			j += k + 1;
			for(k = 0; in[j + k] != ' ' && in[j + k] != ';' && in[j + k] && in[j + k] != '\n'; k++)
				sale_s[k] = in[j + k];
			sale_s[k] = '\0';

			ID = atoi(ID_s);
			price = atoi(price_s);
			sale = atoi(sale_s);
			// */ cin >> ID >> price >> sale;
			
			if(table[atoi(ID.c_str())].order == invalid_order) {
				table[atoi(ID.c_str())].ID = ID;
				table[atoi(ID.c_str())].order = order_count;
				order_count++;
			}
			table[atoi(ID.c_str())].total += price * sale;
		}

		sort(table, table + 4096);

		for(int i = 0; i < order_count; i++) {
			if(table[i].total >= 1000000) {
				cout << table[i].ID << endl;
				flag = true;
			}
		}

		if(!flag)
			cout << "NA" << endl;
	}

	return 0;
}

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

int main() {
    int i, N;
    long long p, q;
    map<int, long long> sales;
    
    while (cin >> N && N != 0) {
        cin.get();
        
        for (int n = 0; n != N; ++n) {
            cin >> i >> p >> q;
            sales[i] += p * q;
        }

        bool printNA = true;
        
        for (map<int, long long>::iterator it=sales.begin(); it!=sales.end(); ++it) {
            if (it->second >= 1000000) {
                cout << it->first << endl;
                printNA = false;
            }
        }

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

        sales.clear();
    }
    return 0;
}