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 <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<ll,ll> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b,c;
  while(cin >> n && n){
    vector<pair<ll,ll>> v;
    vary(ll,v2,4001,0);
    vary(ll,t,4001,0);
    int cnt=0;
    rep(i,n){
      cin >> a >> b >> c;
      if(v2[a] == 0){
        v.push_back(make_pair(cnt,a));
        ++cnt;
        v2[a] = 1;
      }
      t[a] += b * c;
    }
    bool f = false;
    REP(i,0,v.size()){
      if(t[v[i].se] >= 1000000){
        cout << v[i].se<<endl;
        f = true;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}

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

int main() {
	long long e, p, q;
	int n;
	while (cin >> n, n) {
		long long number[4001] = {};

		for (int i = 0; i < n; i++) {
			cin >> e >> p >> q;
			number[e] += p*q;
		}

		int x = 0;
		for (int i = 1; i < 4001; i++) {
			if (number[i] >= 1000000) {
				cout << i << endl;
				x++;
			}
		}
		if (x == 0) { cout << "NA" << endl; }
	}
	return 0;
}

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

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) {break;};
    unsigned long int price[4000], value[4000];
    for (int i = 0; i < 4000; i++) {
      price[i] = 0;
      value[i] = 0;
    }
    
    for (int i = 0; i < n; i++) {
      int a,b,c;
      cin >> a >> b >> c;
      price[a-1] += b;
      value[a-1] += c;
    }
    
    bool NA = true;
    for (int i = 0; i < 4000; i++) {
      if ( price[i] * value[i] >= 1000000) {
	cout << i+1 << endl;
	NA = false;
      }
    }
    if (NA) {
      cout << "NA" << endl;
    }
  }
  return 0;
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define INF 100000000
#define MAXN 4096
typedef long long ll;
bool done[MAXN];
vector<int> syain;
int main(void) {
    int n;
    while (1) {
        cin >> n;
        int flag = 0;
        if (n == 0) break;
        map<int, ll> m;
        m.clear();
        for (int i = 0; i < MAXN; i++) done[i] = false;
        for (int i = 0; i < n; i++) {
            int bango, tanka, num;
            cin >> bango >> tanka >> num;
            if (!done[bango]) {
                done[bango] = true;
                syain.push_back(bango);
            }
            m[bango] += (m[bango] >= 1000000) ? 0 : tanka * num;
        }
        for (int i = 0; i < syain.size(); i++) {
            if (m[syain[i]] >= 1000000) {
                cout << syain[i] << endl;
                flag = 1;
            }
        }
        if (flag == 0) cout << "NA" << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
	int a, b, c, n, i, f;
	while (cin >> n && n)
	{
		int m[4000];
		f = 0;
		for (i = 0; i < n; i++)
		{
			cin >> a >> b >> c;
			if (b * c >= 1000000)
			{
				m[f] = a;
				f++;
			}
		}
		if (f <= 0)
			cout << "NA" << endl;
		else
			for (i = 0; i < f; i++)
				cout << m[i] << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n;

int main(){
	while(scanf("%d", &n)){
		if(n == 0) break;
		map<int,ll> m;
		map<int,ll>::iterator it;
		rep(i,n){
			int x; ll p,q; scanf("%d%lld%lld", &x, &p, &q);
			if(m.find(x) == m.end()) m[x] = p*q;
			else m[x] += p*q;
		}
		bool ok = true;
		for(it = m.begin(); it != m.end(); it++){
		//	cout << it->first << " " << it->second << endl;
			if(it->second >= 1000000){
				ok = false;
				cout << it->first << endl;
			}
		}
		if(ok) cout << "NA" << endl;
	}
}