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 <vector>
#include <utility>
#include <algorithm>

using namespace std;

// ベクターに売り上げを記録していく。
// 同じ社員が複数のデータを持つこともあるので、
// 記録がある場合には加算していく。
// 1000000以上の場合に社員番号を出力する。
// 該当する社員0人の場合はNAを出力する。

int main() {

	int N;
	while (cin >> N , N != 0) {
		vector<pair<int, int>> data;

		for (int i = 0; i < N; ++i) {
			int number, price, sales;
			cin >> number >> price >> sales;
			auto it = find_if(data.begin(), data.end(), [number](pair<int, int> x) {return x.first == number;});
			if (it != data.end()) {
				it->second += price * sales;
			}
			else {
				data.emplace_back(pair<int, int>{number, price * sales});
			}
		}
		int cnt = 0;
		for (const auto a : data) {
			if (a.second >= 1000000) {
				++cnt;
				cout << a.first << endl;
			}
		}
		if (0 == cnt) {
			cout << "NA" << endl;
		}
	}
	return 0;
}

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

using namespace std;

int n;
long long id[4000];
long long value[4000];
long long number[4000];
map<long long, long long> total;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id[i] >> value[i] >> number[i];
        total[id[i]] += value[i] * number[i];
    }
    vector<long long> v;
    if(!total.empty()) {
        map<long long, long long>::iterator it = total.begin();
        while (it != total.end()) {
            if ((*it).second >= 1000000) {
                v.push_back((*it).first);
            }
            ++it;
        }
    }
    if (v.empty()) {
        cout << "NA" << endl;
        return 0;
    }
    for (vector<long long>::iterator it = v.begin(); it != v.end(); ++it) {
        cout << *it << endl;
    }
}

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

using namespace std
;
int main()
{
	long long n;
	while(scanf("%Ld\n", &n), n){
		vector<pair<long long, long long> > v;
		for(long long i = 0; i < n; i++){
			long long p, q, r, f = 1;
			scanf("%Ld %Ld %Ld\n", &p, &q, &r);
			for(long long j = 0; j < v.size(); j++){
				if(v[j].first == p){
					f = 0;
					v[j].second += q * r;
				}
			}
			if(f){
				pair<long long, long long> pa(p, q * r);
				v.push_back(pa);
			}
			
		}
		long long g = 1;
		for(long long i = 0; i < v.size(); i++){
			if(1000000 <= v[i].second){
				g = 0;
				printf("%Ld\n", v[i].first);
			}
		}
		if(g) puts("NA");
	}
	return 0;
}

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

#define TOTAL_SALES_TH (1000000)

struct SALES_INFO {
  int employeeID;
  int totalSales;
};

void updataSalesInfos(std::vector<SALES_INFO>& salesInfos, 
                      int ID,
                      int unitPrice,
                      int amount)
{
  for (std::vector<SALES_INFO>::iterator it = salesInfos.begin();
    it != salesInfos.end();
    ++it) {
    if (it->employeeID == ID) {
      it->totalSales += unitPrice * amount;
      return;
    }
  }
  SALES_INFO newInfo;
  newInfo.employeeID = ID;
  newInfo.totalSales = unitPrice * amount;
  salesInfos.push_back(newInfo);
}

int main(void)
{
  while (true) {
    int numOfInput;
    std::cin >> numOfInput;

    if (numOfInput == 0) {
      break;
    }

    int ID, unitPrice, amount;
    char deli;

    std::vector<SALES_INFO> salesInfos;

    for (int i = 0; i < numOfInput; i++) {
      scanf("%d %d %d", &ID, &unitPrice, &amount);
      updataSalesInfos(salesInfos, ID, unitPrice, amount);
    }

    std::vector<int> achieveList;

    for (std::vector<SALES_INFO>::iterator it = salesInfos.begin();
      it != salesInfos.end();
      ++it) {
      if (it->totalSales >= TOTAL_SALES_TH) {
        achieveList.push_back(it->employeeID);
      }
    }

    if (achieveList.size() == 0) {
      std::cout << "NA" << std::endl;
    }
    else {
      for (std::vector<int>::iterator it = achieveList.begin();
        it != achieveList.end();
        ++it) {
        std::cout << *it << std::endl;
      }
    }
  }

  return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<string.h>

int main()
{
	int n;
	std::pair<int, int> v[4001];
	bool used[4001];
	
	while( 1 ){
		std::cin >> n;
	
		if( !n ) break;
	
		memset( v, 0, sizeof( v ) );
		memset( used, false, sizeof( used ) );
		
		while( n-- ){
			int num;
			int a, b;
		 	std::cin >> num >> a >> b;
			
			if( !used[num] ){
				v[num] = std::pair<int,int>( a, b );
				used[num] = true;
			}
			else{
				v[num].first += a;
				v[num].second += b;		
			}
		}
		
		for( int i = 0; i < 4001; i++ ){
			if( v[i].first == 0 && v[i].second == 0 ) continue;
			
			long long p = v[i].first * v[i].second;
			
			if( p < 1000000 ){
			 	v[i].first = v[i].second = 0;
			}
		}
		
		if( std::count( v, v + 4001, std::pair<int,int>( 0, 0 ) ) == 4001 ){
		 	std::cout << "NA" << std::endl;
		}
		else{
		 	for( int i = 1; i < 4001; i++ ){
				if( v[i].first && v[i].second )std::cout << i << std::endl;
			}
		}
	}

 	return 0;
}

C++: #include<cstdio>

using namespace std;
const int target = 1000000;

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)
			{
				printf("%d\n", num);
				hero = true;
			}
		}
		if (hero == false)
			printf("NA\n");
	}
	return 0;
}

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




int n;


void solve()
{
	bool ok=false;
	int total[4000];
	bool check[4000];
	memset(check,false,sizeof(check));
	memset(total,0,sizeof(total));
	for(int i=0;i<n;i++){
		int num,a,b;
		cin>>num>>a>>b;
		total[num]+=a*b;
		if(total[num]>=1000000 && !check[num]){
			cout<<num<<endl;
			check[num]=true;
			ok=true;
		}
	}
	if(!ok) cout<<"NA"<<endl;
}

int main()
{
	while(cin>>n){
		if(n==0) break;
		solve();
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
typedef long long ll;
//vector<pair<bool, ll>> v(4001);
unsigned long long int a[4001];

int main(){
	int n, num, p, q;
	while(cin >> n, n){
		//fill(a, a+4001, 0);
		int f = 1;
		for(int i = 0;i < 4001;i++)a[i] = 0;
		for(int i = 0;i < n;i++){
			cin >> num >> p >> q;
			a[num] += p * q;
			if(a[num]>999999){
                printf("%d\n",num);
                f = 0;
            }
		}
		if(f)cout << "NA" <<endl;
		/*int f = 1;
		for(int i = 1;i <= 4000;i++)if(a[i] >= 1000000)cout << i << endl, f = 0;
		if(f)cout << "NA" << endl;*/
	}
	return 0;
}

/*
4
1001 2000 520
1002 1800 450
1003 1600 625
1001 200 1220
*/

C++: #include <bits/stdc++.h>
#define INT(name) int name; scanf("%d",&name);
#define VINT(name,n) vector<int> name(n); for(int i = 0;i < n;i++) scanf("%d",&name[i]);

using namespace std;

int main(int argc, char const *argv[]){
	vector<long long> data(4000);
	int i;
	long long a,b,c;
	int max;
	bool check;

	cin >> i;
	while(i){

		for(int j = 0;j < 4000;j++){
			data[j] = 0;
		}


		for(int j = 0;j < i;j++){
			cin >> a >> b >> c;
			data[a - 1] += b * c;
		}


		check = false;

		for(int j = 0;j < 4000;j++){
			if(data[j] >= 1000000){
				printf("%d\n",j+1);
				check = true;
			}
		}

		if(!check) printf("NA\n");

		cin >> i;
	}

	return 0;
}