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 <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<ll, ll> m;
        m.clear();
        syain.clear();
        for (int i = 0; i < MAXN; i++) done[i] = false;
        for (int i = 0; i < n; i++) {
            ll 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 <stdio.h>
int main()
{
  int n,sn,tann,un,to,cou,i;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    cou=0;
    for(i=0;i<n;i++){
      scanf("%d %d %d",&sn,&tann,&un);
      to=tann*un;
      if(to>=1000000){
	printf("%d\n",sn);
	cou++;
      }
    }
    if(cou==0)printf("NA\n");
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

 
int main(){
	int n;
	while(cin>>n,n){
		vector<int> a;
		vector<ll> x;
		for (int i = 0; i < n; i++){
			int d; ll b,c; cin>>d>>b>>c;
			int id = find(a.begin(),a.end(),d) - a.begin();
			if(id == (int)a.size()){
				a.push_back(d);
				x.push_back(0L);
			}
			x[id] += b*c;
		}

		vector<int> ans;
		for (int i = 0; i < (int)a.size(); i++){
			if(x[i] >= 1000000L) ans.push_back(a[i]);
		}
		
		if(ans.size() == 0){ cout << "NA" << endl; continue; }

		for (int i = 0; i < (int)ans.size(); i++)
			cout << ans[i] << endl;
	}
    return 0;
}

C++: #include <iostream>
#include <map>
using namespace std;
int main() {
  int n, e;
  long long int p, q;

  while(cin >> n) {
	if(n == 0) break;
	map<int, long long int> mp;
	map<int, long long int>::iterator itr;

	for(int i = 0; i < n; ++i) {
	  cin >> e >> p >> q;
	  if(mp.find(e) != mp.end()) {// found
		mp[e] += p * q;
	  }
	  else {// not found
		mp[e] = p * q;
	  }
	}

	bool isNA = true;
	for(itr = mp.begin(); itr != mp.end(); ++itr) {
	  if(itr->second >= 1000000) {
		cout << itr->first << endl;
		isNA = false;
	  }
	}
	if(isNA) {
	  cout << "NA" << endl;
	}
  }
  return 0;
}

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

int main(){
  int n ,flag=0 ,num[4001] ,price[4001] ,earnings[4001] ,total[4001] ,overlap;
  while( true ){
    cin >> n;
    if( n == 0 ){
      break;
    }
    for( int i=0 ; i<n ; i++ ){ // 入力と合計を計算
      cin >> num[i] >> price[i] >> earnings[i];
      total[i] = price[i] * earnings[i];
    }

    for( int i=0 ; i<n ; i++ ){ // 重複を無くす
      overlap = num[i]; // 重複したかの判定
      for( int j=0 ; j<n ; j++ ){
	if( num[j] == overlap && i != j ){ // 重複したか
	  total[i] += total[j];
	  num[j] = -1;
	}
      }
    }

    for( int i=0 ; i<n ; i++ ){ // 出力
      if( total[i] >= 1000000 ){
	cout << num[i] << endl;
	flag = 1;
      }
    }

    if( flag == 0 ){ // いなかったら
      cout << "NA" << endl;
    }
    flag = 0;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    int n; cin >> n;
    do {
        int e[n], p[n], q[n];
        ll tmp[4010] = {};
        int Flag[4010] = {};
        int flag = 0;
        rep(i, n) cin >> e[i] >> p[i] >> q[i];
        for (int i = 0; i < n; i++) {
            tmp[e[i]] += p[i] * q[i];
        }
        for (int i = 0; i < n; i++) {
            if (tmp[e[i]] >= 1000000 && Flag[e[i]] == 0) {
                cout << e[i] << endl;
                flag = 1;
                Flag[e[i]]++;
            }
        }
        if (flag == 0) cout << "NA" << endl;
        cin >> n;
    } while(n != 0);

    return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)

const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int n;
	int ban, tan, suu;
	vector<ll> table(4001, 0);

	while(cin >> n, n) {
		bool flag = true;

		REP(i, 4001) {
			table[i] = 0;
		}

		REP(i, n) {
			cin >> ban >> tan >> suu;
			table[ban] += tan*suu;
		}

		REP(i, 4001) {
			if(table[i] >= 1000000) {
				cout << i << endl;
				flag = false;
			}
		}
		if(flag) {
			cout << "NA" << endl;
		}
	}

	return 0;
}

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

int main() {

	int  n;
	int id, t, s;
	

	while (1) {

		int max = -100;
		int maxer=0;
		int a[5000];//?????????????????????
		int b[5000];//?£???????????????????

		a[5000] = 0;
		b[5000] = 0;

		cin >> n;
		  
		if (n == 0)
			break;
		//n=0???????????????


		for (int i = 0; i < n; i++) {
			cin >>a[i] >> t >> s;
			b[i] = t*s;
		}
		//???????????????????£?????????????????????\???
		


		for (int i = 0; i < n; i++) {
			if (max <= b[i]) {
				max = b[i];
			}

		}

		for (int i = 0; i < n; i++) {
			if (max == b[i]&&max>=1000000) {
				cout << a[i] << endl;
			}
		}
		



		if (max< 1000000) {
			cout << "NA" << endl;
		}
		


	}
	return 0;
}