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<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<tuple>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    while(cin >> n, n){
        vector< tuple<lint, int, int> > v(5000);
        rep(i, 5000){
            get<1>(v[i]) = n + 1;
            get<2>(v[i]) = i;
        }

        rep(i, n){
            int e;
            lint p, q;
            cin >> e >> p >> q;
            get<0>(v[e]) = max(get<0>(v[e]) - p * q, -1000000LL);
            chmin(get<1>(v[e]), i);
        }

        SORT(v);

        if(get<0>(v[0]) > -1000000LL){
            cout << "NA" << endl;
        }else{
            for(int i = 0 ; i < 4000 && get<0>(v[i]) <= -1000000LL ; ++i){
                cout << get<2>(v[i]) << endl;
            }
        }
    }

    return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };
unsigned long long xs[4002] = {0};

int main() {

  int n;
  while (cin >> n, n)
  {
    vector<int> order;
    rep (i, n) {
      int a,b,c; cin >> a >> b >> c;
      xs[a] += b * c;
      order.push_back(a);
    }
    bool bl = true;
    for (int id : order) {
      if (xs[id] >= 1000000) {
        cout << id << endl;
        bl = false;
      }
      xs[id] = 0;
    }
    if (bl) {
      cout << "NA" << endl;
    }
  }

  return 0;
}

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

typedef struct {
  int employee_num;
  int sales_price;
  int sales_value;
}employee_list;

int main(){
  int data_num;
  int i_cnt = 0;
  employee_list employee_list_buff;
  employee_list employee[1000];

  cin >> data_num;

  while(data_num > 0){
    cin >> employee_list_buff.employee_num >> employee_list_buff.sales_price >> employee_list_buff.sales_value;

    if(employee_list_buff.sales_price * employee_list_buff.sales_value >=  1000000){
      employee[i_cnt].employee_num = employee_list_buff.employee_num;
      employee[i_cnt].sales_price = employee_list_buff.sales_price;
      employee[i_cnt].sales_value = employee_list_buff.sales_value;
      i_cnt++;
    }
    data_num--;
  }

  if(i_cnt > 0){
    for(int i_array = 0 ; i_array < i_cnt ; i_array++){
      cout << employee[i_array].employee_num << endl;
    }

  }else{
    cout << "NA" << endl;
  }

  return 0;
}

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

struct data {
	int ID;
	long total;
	int order;

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

	data(int n) {
		ID = n;
		total = 0;
		order = 100000;
	}

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

int main() {
	int n;

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

		for(int i = 0; i < sizeof(table) / sizeof(table[0]); i++) {
			table[i] = data(i);
		}

		for(int i = 0; i < n; i++) {
			cin >> ID >> price >> sale;
			if(table[ID].order == 100000) {
				table[ID].order = order_count;
				order_count++;
			}

			table[ID].total += price * sale;
		}

		sort(table, table + 4096);

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

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

	return 0;
}

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

int main() {
	long long int i, n, no[4000], tanka[4000], num[4000];
	bool flg=false;
	while (1) {
		flg=false;
		cin>>n;
		if (n==0) break;
		for (i=0; i<n; i++)
			cin>>no[i]>>tanka[i]>>num[i];
		for (i=0; i<n; i++) {
			if (tanka[i]*num[i]>=1000000)
				flg=true, cout<<no[i]<<endl;
		}
		if (flg==false) cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

typedef pair<int,long> P;

void solve100(int n) {
    
    vector<P> v(4001, make_pair(0,0));
    long o, p, q;
    int cnt = 1;
    REP(i,n) {
        cin >> o >> p >> q;
        if (v[o].first != 0) {
            v[o].second += p * q;
        }else {
            v[o].first = cnt;
            cnt++;
            v[o].second += p * q;
        }
    }
    vector<P> w;
    REP(i,4001) {
        if (v[i].second >= 1000000) w.push_back(make_pair(v[i].first, i));
    }
    sort(ALL(w));
    if (w.size()) {
        REP(i,w.size()) cout << w[i].second << endl;
    }else {
        cout << "NA" << endl;
    }
}

int main() {
    int n;
    while(cin >> n, n) {
        solve100(n);
    }
    return 0;
}