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 <map>
#include <algorithm>
#include <stdio.h>

using namespace std;

typedef long long ll;

int n, id, p, q;
ll amount;

const ll MAX = 1000000;

struct Mem {
    int id;
    ll c;

    Mem() {}
    Mem(int _id, ll _c) { id = _id; _c = c; }
};

Mem array[4010];
vector<int> ans;

int main(void) {
    while(~scanf("%d", &n)) {
        if(n == 0) break; ans.clear();
        for(int i = 0; i < n; i++) {
            array[i].c = array[i].id = 0;
            scanf("%d%d%d", &id, &p, &q);
            array[i].c = p * q;
            array[i].id = id;
        }
        for(int i = 0; i < n; i++) {
            ll cost = 0;
            for(int j = 0; j < n; j++) {
                if(array[i].id == array[j].id) {
                    cost += array[j].c;
                }
            }
            if(cost >= MAX && !count(ans.begin(), ans.end(), array[i].id)) {
                ans.push_back(array[i].id);
            }
        }
        if(ans.empty()) {
            printf("NA\n");
        } else {
            for(int i = 0; i < (int) ans.size(); i++) {
                printf("%d\n", ans[i]);
            }
        }
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
using namespace std;
int main(){
int n;
while(cin>>n,n){
long ta[5000]={0};int x[5000]={0};
int cnt=0,a,b,c;
	for(int i=0;i<n;i++){
	cin>>a>>b>>c;
	ta[a]+=b*c;
	bool f=1;
	for(int j=0;j<i;j++)if(x[j]==a)f=0;
	if(f)x[cnt++]=a;
	}
	bool f=1;
	for(int i=0;i<n-1;i++){
	//cout<<x[i]<<" "<<ta[x[i]]<<endl;
	if(ta[x[i]]>=1000000){cout<<x[i]<<endl;f=0;}
	}
	if(f)cout<<"NA"<<endl;
}
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct salary{
	int no;
	long long sell;
	bool b;
};

int main() {
	
	int n;
	while(cin>>n,n){
		vector<salary> vs;
		REP(i, n){
			long long no, sell_n, value;
			cin >> no >> sell_n >> value;
			bool b = false;
			REP(j, vs.size()){
				if (vs[j].no == no){
					b = true;
					vs[j].sell += sell_n*value;
					if (vs[j].sell >= 1000000){
						vs[j].b = true;
					}
				}
			}
			if (!b)vs.push_back({ no, sell_n*value ,false});
		}
		bool b2=false;
		REP(i, vs.size()){
			if (vs[i].b){
				cout << vs[i].no << endl;
				b2 = true;
			}
		}
		if (!b2)cout << "NA"<< endl;
	}
}

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

int main()
{
    int n;
    
    while(cin>>n && n){
        
        map<int,int> mp;
        vector<int> v;
        
        for(int i=0; i<n; i++){
            int e,p,q;
            cin>>e>>p>>q;
            if(!mp[e])
                v.push_back(e);
            
            mp[e]+=p*q;
            
        }
        
        bool flg=false;
        
        for(int i=0; i<v.size(); i++){
            if(mp[v[i]]>=1000000){
                flg=true;
                cout<<v[i]<<endl;
            }
            else if(!flg){
                cout<<"NA"<<endl;
            }
        }
    }

C++: #include <iostream>
//#include <cstdio>
#include <map>
using namespace std;
int main() {
  int n;
  while(cin >> n) {
	if(n == 0) break;
	int e, p, q;
	map<int, long> mp;
	map<int, long>::iterator itr;

	for(int i = 0; i < n; ++i) {
	  cin >> e >> p >> q;
	  itr = mp.find(e);
	  if(itr == mp.end()) {// not found
		mp[e] = p * q;
	  }
	  else {// found
		itr->second += p * q;
	  }
	}
	
	/*
	puts("======================");
	puts("ID\tprofit");
	for(itr = mp.begin(); itr != mp.end(); ++itr) {
	  printf("%d\t%ld\n", itr->first, itr->second);
	}
	puts("======================");
	*/
	
	bool isNA = 1;
	for(itr = mp.begin(); itr != mp.end(); ++itr) {
	  if(itr->second >= 1000000) {
		cout << itr->first << endl;
		isNA = 0;
	  }
	}
	if(isNA) {
	  cout << "NA" << endl;
	}
  }
  return 0;
}

C++: #include <stdio.h>

typedef struct shain{
	int bangou;
	int uriage;
}shain;

int main(void){
	int data_n,i,j,flag,kaburi,hyouji;
	int bangou,tanka,suuryou;
	shain men[4001];
	
	while(1){
		scanf("%d",&data_n);
		if(data_n == 0) break;
		kaburi = 0;
		hyouji = 0;
		for(i=0;i < 4001;i++){
			men[i].bangou = 0;
			men[i].uriage = 0;
		}
		for(i=0;i < data_n;i++){
			scanf("%d %d %d",&bangou,&tanka,&suuryou);
			for(j=0;j <= i;j++){
				if(men[j].bangou == bangou){
					flag = 1;
					kaburi++;
					men[j].uriage += tanka*suuryou;
				}
			}
			if(flag != 1){
				men[i].bangou = bangou;
				men[i].uriage = tanka*suuryou;
			}
			flag = 0;
		}
		j = i;
		for(i=0;i < j;i++){
			if(men[i].uriage >= 1000000){
				printf("%d\n",men[i].bangou);
				hyouji++;
			}
		}
		if(hyouji == 0) printf("NA\n");
	}
	return 0;
}

C++: #include<iostream>
#include<map>
#include<string>
using namespace std;
const int MAXN = 4020;
typedef long long ll;
int i,p,q;
bool isfind = false;
map<int,ll> total;
int a[MAXN];


int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0)return 0;
    for(int k = 0;k < n;k++){
      cin >> i >> p >> q;
      total[i] += p*q;
      a[k] = i;
    }
    for(int j = 0;j < n;j++){
      if(total[a[j]] >= 1000000){
	cout << a[j] << endl;
	total[a[j]] = 0;
	isfind = true;
      }
    }
    if(!isfind)cout << "NA" << endl;
    total.clear();
    isfind =false;
  }
  return 0;
}

C++: #include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int main(void){
	int N;
	int id;
	ll p,q;
	while(cin >> N){
		queue<int> que;
		map<int, ll> map;
		int check = 0;
		if(!N) break;
		for(int i=0; i<N; ++i){
			cin >> id >> p >> q;
			if(map.find(id) == map.end()){
				map[id] = p*q;
				que.push(id);
			} else {
				map[id] += p*q;
			}
		}
		while(que.size()){
			if(map[que.front()] >= 1000000){
				cout << que.front() << endl;
				check = 1;
			}
			que.pop();
		}
		if(check == 0) cout << "NA" << endl;
	}

	return 0;
}