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<stdio.h>
int main(void){
    int n,i,j,k=0,l=0,x,y,z;
    int a[4001]={0};
    long long b[4001]={0};
    int c[4001]={0};
    int flag[4001]={0};
    int flag2[4001]={0};
    for(;;){
        k=0;
        for(j=0;j<n;j++){
            a[j]=0;
            b[j]=0;
            flag[j]=0;
            x=0;
            c[j]=0;
            }
        scanf("%d",&n);
        if(n==0)break;
        k=1;
        for(i=0;i<n;i++){
            scanf("%d",&x);
            scanf("%d",&y);
            scanf("%d",&z);

            if(flag[x]==1)i--;
            else {
                b[x]=b[x]+y*z;
                a[i] = x;
                flag2[i]=1;


                }
            }
            if(b[x]>=1000000){

                flag[x]=1;

                k++;
            }



        if(k!=1){
            for(l=0;l<n;l++){
                if(flag2[l]==1&&flag[a[l]]==1){
                    printf("%d\n",a[l]);
                }
            }
        }
        else if(k==1){
                printf("NA\n");

            }
        }

return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

int main()
{
    int n;

    while (cin >> n) {
        if (!n)
            break;

        int id, p, q;
        bool flag = false;
        long long workers[4000] = {0};
        for (int i = 0; i < n; i++) {
            cin >> id >> p >> q;
            workers[id] += p * q;
        }

        for (int i = 0; i < 4000; i++) {
            if (workers[i] >= 1000000) {
                cout << i << endl;
                flag = true;
            }
        }
        if (!flag)
            cout << "NA" << endl;
    }

    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(b * c >= 1000000 || v2[a] + b*a >= 1000000){
        v2[a] = 1000000;
      }
      else 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){
        cout << v[i].se<<endl;
//         debug(v2[v[i].se]);
        f = true;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int NORMA = 1000000;

int main() {
  int N;
  while(cin >>N && N){
    map<int, int> m;
    REP(i, N){
      int a, b, c; cin >>a >>b >>c;
      m[a] += b * c;
    }
    vector<int> ans;
    for(map<int, int>::iterator it = m.begin(); it != m.end(); ++it) if(it->second >= NORMA) ans.push_back(it->first);
    if(ans.size() == 0) cout <<"NA" <<endl;
    else REP(i, ans.size()) cout <<ans[i] <<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cmath>

using namespace std;

int n, e, p, q;

int main() {
  while(scanf("%d", &n), n) {
    for(int i = 0; i < n; i++) {
      scanf("%d %d %d", e, p, q);
      if(p * q >= 1e6) printf("%d\n", e);
    }
  }
}

C++: #include<stdio.h>
#include<math.h>
#include<string.h>


int main(){
	int uriage[4000][2],n,no,tanka,su,i,j,newflag,naflag;
	
	while(0<=scanf("%d",&n)){
		if(n==0) break;
		memset(uriage,0,sizeof(uriage));
		for(i=0;i<n;i++){
			scanf("%d%d%d",&no,&tanka,&su);
			newflag=0;
			for(j=0;j<n;j++){
				if(uriage[j][0]==no){
					uriage[j][1]+=tanka*su;
					newflag=1;
					break;
				}
			}
			if(newflag==0){
				for(j=0;j<n;j++){
					if(uriage[j][0]==0){
						uriage[j][1]+=tanka*su;
						uriage[j][0]=no;
						break;
					}
				}
			}
		}
		naflag=0;
		for(i=0;i<n;i++){
			if(uriage[i][0]==0)break;
			if(uriage[i][1]>=1000000){
				printf("%d\n",uriage[i][0]);
				naflag=1;
			}
		}
		if(naflag==0)printf("NA\n");
	}
	return 0;
}

C++: #include <deque>
#include <iostream>

using namespace std;

int main() {

	long long int n, num, p, q, c;
	deque<int> x;

	while(cin >> n) {
		if(n==0)
			break;
		c=0;
		for(int i=0; i<n; i++) {
			int f=1;
			cin >> num >> p >> q;
			if(p*q>=1000000) {
				for(int j=0; j<x.size(); j++) {
					if(x[j]==num)
						f=0;
				}
				if(f) {
					x.push_back(num);
					c++;
				}
			}
		}
		if(c==0)
			cout << "NA" << endl;
		else  {
			for(int i=0; i<c; i++) {
				cout << x[i] << endl;
			}
		}
	}
		
	return 0;

}