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<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vi v(4005,0);
    rep(i,n){
      ll e,p,q;
      cin>>e>>p>>q;
      v[e]+=p*q;
    }
    vi ans;
    rep(i,4005)
      if(v[i]>=1000000)ans.push_back(i);
    if(ans.size())
      rep(i,ans.size())cout<<ans[i]<<endl;
    else
      cout<<"NA"<<endl;
  }
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<double,double> P;

int main(){
	int n,m,o;
	int num;
	while(~scanf("%d",&num)){
		if(num==0) break;
		bool isok=false;
		map<int,int> val;
		for(int i=0;i<num;i++){
			scanf("%d %d %d",&n,&m,&o);
			val[n] += m*o;
		}

		for(map<int,int>::iterator it = val.begin(); it != val.end(); it++){
			if(it->second >= 1000000){
				cout << it->first << endl;
				isok=true;
			}
		}
		if(!isok) cout <<  "NA" << endl;
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#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>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
	ll t,s;
	int n;
	for(;cin>>n,n;){
		bool f=false;
		rep(i,n){
			int p;
			cin>>p>>t>>s;
			if(t*s>=1000000)cout<<p<<endl,f=true;
		}
		if(!f)cout<<"NA\n";
	}
	return 0;
}

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

int main()
{
	int n = 0;				//  社員の人数;n==0で終了
	bool flag = true;		//  flagはidの重複を確認する
	int id_temp,price_temp,amount_temp;
	vector<int> id;			//  社員のid
	vector<int> price;		//  the corresponding unit price
	vector<int> amount;		//  the amount of sales
	vector<int> result;		//  条件を満たすid郡

	while(true) {
		cin >> n;
		if(n<0) {
			cout << "Error; n must be larger than 0";
			return -1;
		}
		else if(n==0)
			break;
		else {
			result.clear();
			id.clear();
			price.clear();
			amount.clear();
			for(int i=0;i<n;i++) {
				cin >> id_temp >> price_temp >> amount_temp;
				flag = true;
				for(int j=0;j<id.size();j++)
					if(id_temp==id[j]) {
						price[j] += price_temp;
						amount[j] += amount_temp;
						flag = false;
						break;
					}
				if(flag) {
					id.push_back(id_temp);
					price.push_back(price_temp);
					amount.push_back(amount_temp);
				}
			}

			for(int i=0;i<n;i++) 
				if(price[i]*amount[i]>=1000000)
					result.push_back(id[i]);
			
			if(result.size()==0)
				cout << "NA" << endl;
			else
				for(int i=0;i<result.size();i++)
					cout << result[i] << '\n';
		}
	}

	return 0;
}

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,4005,0);
    int cnt=0;
    rep(i,n){
      cin >> a >> b >> c;
      if(v2[a] == 0){
        ++cnt;
        v.push_back(make_pair(cnt,a));
      }
      if(v2[a] < 1000000)
        v2[a] += b * c;
    }
    sort(all(v),[](const pii &p,const pii &p2){return p.fi < p2.fi;});
    bool f = false;
//     debug(v.size());
    REP(i,0,v.size()){
      if(v2[v[i].se] < 1000000){
      }
      else{
        cout << v[i].se<<endl;
//         debug(v2[v[i].se]);
        f = true;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}

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

struct data{
  int a,total;
};

int main(){
  int i,j,n,c,a,yen,ko,f,f2,con;
  data d[4000];
  while(1){
    cin >> n;
    if(n == 0) break;
    c = 0;
    con = 0;
    for(i=0;i<n;i++){
      cin >> a;
      f = 1;
      for(j=0;j<i;j++){
	if(a == d[j].a){
	  cin >> yen >> ko;
	  d[j].total += yen * ko;
	  f = 0;
	  con++;
	  break;
	}
      }
      if(f){
	cin >> yen >> ko;
	d[i-con].a = a;
	d[i-con].total = yen * ko;
	c++;
      }
    }

    f2 = 1;
    for(i=0;i<c;i++){
      if(d[i].total >= 1000000){
	cout << d[i].a << endl;
	f2 = 0;
      }
    }
    if(f2) cout << "NA" << endl;

  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<map>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    map<int, long long> com;
    vector<int> g;
    com.clear();
    g.clear();
    while(n--){
      int a;
      long long b,c;
      cin >>a>>b>>c;
      if(!com[a]){g.push_back(a);}
      com[a]+=b*c;
    }
    bool f = false;
    for(int i=0; i<g.size(); i++){
      if(com[g[i]]>=1000000){cout <<g[i]<<endl;f = true;}
    }
    if(!f){cout <<"NA"<<endl;}
  }
  return 0;
}