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++: // a.c.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include <stdio.h>
#include <map>
#include <iostream>
using namespace std;
map<int, long long> bango;
// long long int bango[4001];
int main(void){
	int n;
	long long ban, tan, suu;
	int flg,i;
	while (1){
		for (i = 1; i <= 4000; i++){
			bango[i] = 0;
		}
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		for (i = 0; i < n; i++){
			//scanf("%d %ld %d", &ban, &tan, &suu);
			cin >> ban >> tan >> suu;
			bango[ban] += tan*suu;
		}
		flg = 0;
		for (i = 1; i <= 4000; i++){
			if (bango[i]>=1000000){
				printf("%d\n", i);
				flg = 1;
			}
		}
		if (!flg){
			printf("NA\n");
		}
	}
	return 0;
}

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

using namespace std;

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

    vector<pair<int,int>> data;
    vector<int> nanum;
    for(int i = 0;i < n;++i){
      int num,sa,ko;
      cin>>num;
      cin>>sa;
      cin>>ko;

      int sum = sa * ko;

      if(i == 0){
        nanum.push_back(num);
        data.push_back(make_pair(num,sum));
      }
      else{
        auto a = find(nanum.begin(),nanum.end(),num);
        if(*a != num){
          nanum.push_back(num);
          data.push_back(make_pair(num,sum));
        }
      }
    }

    int check = 0;
    for(pair<int,int> e : data){
      if(e.second >= 1000000){
        check = 1;
        cout<<e.first<<endl;
      }
    }
    if(check == 0){
      cout<<"NA"<<endl;
    }
  }

  return 0;
}

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

#define SHINE_MAX 4000
#define ELITE 1000000
#define AHO "NA"

int shineN;
int eliteN;
int elite[SHINE_MAX];

int num,tanka,suryo;
int i;

int main(){
	while(1){
	 cin>>shineN;
	 if(shineN==0){break;}
	 
	 eliteN=0;
	 for(i=0;i<shineN;i++){
	  cin>>num>>tanka>>suryo;
	  if(ELITE<=tanka*suryo){	//??¨???????????????
	   elite[eliteN]=num;
	   eliteN++;
	  }
	 }
	 
	 //??¨???????????????
	 for(i=0;i<eliteN;i++){
	  cout<<elite[i];
	 }
	 if(eliteN==0){cout<<AHO;}
	}
	return 0;
}

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

int main() {
	long long number[4001] = {};
	long long e, p, q;
	int MAX = 0;
	int n;
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> e >> p >> q;
			if (MAX <= e) { MAX = e; }
			number[e - 1] += p*q;
		}
	}
	int x = 0;
	for (int i = 0; i < e; i++) {
		if (number[i] >= 1000000) {
			cout << number[i];
			x++;
		}
	}
	if (x == 0) { cout << "NA" << endl; }
	return 0;
}

C++: #include<iostream>
#include<vector>;
using namespace std;
int main() {
	int n;
	while (cin >> n){
		if (n == 0)break;
		long long u[4010] = { 0 };
		vector<int>l;
		for (int i = 0; i < n; i++){
			long a, b, c;
			cin >> a >> b >> c;
			u[a] += b*c;
			if (u[a] >= 1000000 && find(l.begin(), l.end(), a) == l.end())l.push_back(a);
		}
		for (int i = 0; i < l.size(); i++){
			cout << l[i] << endl;
		}
		if (!l.size())cout << "NA" << endl;
	}
	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    map<int, long> mp;
    vector<int> vec;
    while (cin >> n && n != 0) {
        for (int i = 0; i < n; i++) {
            int id;
            long p, q;
            cin >> id >> p >> q;
            mp[id] += p * q;
        }
        for (auto m : mp)
            if (m.second >= 1000000) vec.push_back(m.first);

        if (vec.size() == 0)
            cout << "NA" << endl;
        else {
            for (auto v : vec) cout << v << endl;
        }

        mp.clear();
        vec.clear();
    }
    return EXIT_SUCCESS;
}

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

using namespace std;

const int Target = 1000000;

struct Shain {
	int no;
	long long sum;
};

int main( void )
{
	vector<Shain> shain;
	int n;
	while(cin >> n, n) {
		shain.clear();
		for(int i=0; i < n; ++i) {
			int no, kin, num;
			cin >> no >> kin >> num;
			bool hit = false;
			vector<Shain>::iterator it = shain.begin();
			while(it != shain.end()) {
				if(it->no == no) {
					if(it->sum < Target) it->sum += (kin * num);
					hit = true;
					break;
				}
				++it;
			}
			if(!hit) {
				Shain tmp;
				tmp.no = no;
				tmp.sum = kin * num;
				shain.push_back(tmp);
			}
		}
		bool hit = false;
		vector<Shain>::iterator it = shain.begin();
		while(it != shain.end()) {
			if(it->sum >= Target) {
				cout << it->no << endl;
				hit = true;
			}
			++it;
		}
		if(!hit)
			cout << "NA" << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef long int lint;
typedef long long int llint;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  
  while (cin >> n, n){
    int p, q;
    int e[1010] = {0}, res[4010] = {0};
    bool judge = false;
    REP(i, n){
      cin >> e[i] >> p >> q;
      res[e[i]] += p * q;
    }
    sort(e, e + n);
    REP(i, n){
      if (res[e[i]] >= 1000000 && e[i] != e[i + 1]){
        cout << e[i] << endl;
        judge = true;
      }
    }
    if (!judge) cout << "NA" << endl;
  }
}

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

int main()
{
	int n;
	while(cin >> n){
		if(n == 0) break;
		map<int, int> officers;
		vector<int> ids;
		for(int i = 0; i < n; i++){
			int id;
			int value;
			int num;
			int need;
			cin >> id >> value >> num;
			if(value > 0){
				need = 1000000 % value == 0 ? 1000000 / value : 1000000 / value + 1;
				if(num >= need){
					officers[id] = 1000000;
					if(find(ids.begin(), ids.end(),id) == ids.end())
						ids.push_back(id);
				} else {
					if(find(ids.begin(), ids.end(),id) == ids.end()){
						ids.push_back(id);
						officers[id] = value * num;
					} else {
						officers[id] += value * num;
						if(officers[id] > 1000000)
							officers[id] = 1000000;
					}
				}
			}
		}
		int count = 0;
		for(vector<int>::const_iterator iter = ids.begin(); 
			iter != ids.end(); iter++){
			if(officers[*iter] >= 1000000){
				cout << *iter << endl;
				count++;
			}
		}
		if(!count) cout << "NA" << endl;
	}
	return 0;

}

C++: #include <iostream>
#include <set>
using namespace std;
int main( void )
{
	int n;
	while ( cin >> n && n != 0 )
	{
		set <int> T;

		bool exist = false;
		for ( int i = 0; i < n; i++ )
		{
			int no, price, items;
			cin >> no >> price >> items;

			if ( price <= 1000000 && items <= 100000 )
			{
				long long profit = (long long)price * items;
				if ( T.find( no ) == T.end() && profit >= 1000000L )
				{
					exist = true;
					cout << no << endl;
					T.insert( no );
				}
			}
		}

		if ( exist == false )
			cout << "NA" << endl;
	}

	return 0;
}