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 <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct salary{
	int no;
	long long sell;
};

int main() {
	
	int n;
	while(cin>>n,n){
		vector<salary> vs;
		vector<int> vi;
		REP(i, n){
			int no, sell_n, value;
			cin >> no >> sell_n >> value;
			bool b = false;
			REP(j, vs.size()){
				if (vs[j].no == no){
					b = true;
					vs[j].sell += sell_n*value;
					
				}
			}
			if (!b)vs.push_back({ no, sell_n*value });
			REP(j, vs.size()){
				if (vs[j].sell >= 1000000){
					if (find(vi.begin(), vi.end(), vs[j].no) == vi.end())vi.push_back(vs[j].no);
				}
			}
		}
		REP(i, vi.size()){
			cout << vi[i]<< endl;
		}
		if (vi.size()==0)cout << "NA"<< endl;
	}
}

C++: #include<iostream>
using namespace std;
int ans[4000];

int main(){
	int N;
	long int e, p, q;
	int x;
	while (1){
		x = 0;
		cin >> N;
		if (N == 0){ break; }
		while (N){
			cin >> e >> p >> q;
			cout << N<<x << endl;
			if (p*q >= 1000000){
				ans[x] = e;
				x++;
			}
			N--;
		}
			for (int i = 0; i < N; i++)
			{
				if (i == 0 && ans[i] == 0)cout << "NA" << endl;
				if (ans[i] == 0){ break; }
				cout << ans[i] << endl;
			}
	}
	return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,a,b,c;
    while(cin>>n,n){

        vector<int>V;
        map<int,long long>M;
        while(n--){
            cin>>a>>b>>c;
            if(M[a]==0)V.push_back(a);
            M[a]+=b*c;

        }

        bool flag=true;
        sort(V.begin(),V.end());
        for(int i=0;i<V.size();i++){
            if(M[V[i]]>=1000000){
                flag=false;
                cout<<V[i]<<endl;
            }
        }
        if(flag)cout<<"NA"<<endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <map>
#include <vector>

using namespace std;

int main(){
	int n;
	map<int,long> list;
	vector<int> people;
	while(scanf("%d",&n) != EOF && n){
		int a,b,c;
		list.clear();
		people.clear();
		for(int i=0;i<n;i++){
			scanf("%d %d %d",&a,&b,&c);
			people.push_back(a);
			list[a] += b * c;
		}
		vector<int>::iterator it;
		bool flag = true;
		for(it = people.begin();it != people.end();it++){
			
			if(list[*it] >= 1000000){
				printf("%d\n",*it);
				flag = false;
			}
			
			list[*it] = 0;
		}
		if(flag){
			printf("NA\n");
		}
	}
}

C++: #include<iostream>
#include<queue>
#include<map>
using namespace std;
main(){
  long long a,b,c,n,f;
  while(cin>>n,n){
		map<int,long long> m;
		queue<int> v;
		f=1;
    for(;n;n--){
			cin>>a>>b>>c;
      if(!m[a])v.push(a);
      m[a] += b*c;
    }
    
    while(v.size())
			if(m[v.front()]>999999)f=0,cout<<v.pop()<<endl;
    if(f)cout<<"NA"<<endl;
  }
}

C++: #include <stdio.h>

int output[50000];
int count=0;

void input(int);
int main(void){
	int n,i;
	while(true){
		scanf("%d",&n);
		if(n>0){
			input(n);
		}else{
			break;
		}
	}
	for(i=0;i<count;i++){
		if(output[i]!=0){
			printf("%d\n",output[i]);
		}else{
			printf("NA\n");
		}
	}
	
	return 0;
}
void input(int ns){
	int e[4000];
	int p[1000000];
	int q[100000];
	int c[ns];
	
	int i;
	
	for(i=0;i<ns;i++){
		scanf("%d %d %d",&e[i],&p[i],&q[i]);
		c[i] = p[i]*q[i];
	}
	
	int j;
	
	for(i=0;i<ns-1;i++){
		for(j=1;j<ns;j++){
			if(e[i]==e[j]){
				c[i]=c[i]+c[j];
				c[j]=0;
			}
		}
	}
	int ch = 0;
	
	for(i=0;i<ns-1;i++){
		if(c[i]>=1000000){
			output[count]=e[i];
			count++;
			ch = 1;
		}
	}
	if(ch == 0){
		output[count]=0;
		count++;
	}
}

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

typedef long long ll;
typedef queue<int> qi;

const int lim = 1000000;

int main()
{
    int n; ll en, price, qty, check[4001]={0}; qi que;
    while(cin >> n && n) {
        if (n == 0) break;

        for(int i=0; i < n; ++i) {
            cin >> en >> price >> qty;

            if (check[en] >= 0) {
                check[en] += price*qty;
            }

            if (check[en] >= lim) {
                que.push(en);
                check[en]=-1;
            }
        }

        if (que.empty()) {
            cout << "NA" << endl;
        } else {
            for(int i=0,len=que.size(); i < len; ++i) {
                cout << que.front() << endl;
                que.pop();
            }
        }
    }

    return 0;
}

C++: #include "stdio.h"
#include "string.h"
long long N[4001];
int f[4001];
int main(){
    int x,n,p,i,j,c=0;
    scanf("%d",&i);
    while(i!=0){
        c=0;
        for(j=0;j<i;j++){
            scanf("%d%d%d",&x,&n,&p);
            N[x]+=n*p;
                if(N[x]>=1000000){
                    f[c]=x;
                    c++;
                    N[x]=-10000000000000;
                }
        }
        if(c==0)
            printf("NA\n");
        else 
            for(j=0;j<c;j++)printf("%d\n",f[j]);
        memset(N,0L,4001);
        memset(f,0,4001);
        scanf("%d",&i);
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#define N 4001
using namespace std;
int main(){

  int n;
  int a,num[N],tanka,uriage,jun[N];
  bool judge;

  while(cin >> n){
    if(n==0)
      break;

    judge = true;
    for(int i=0;i<N;i++){
      num[i] = 0;
    }

    for(int i=0;i<n;i++){
      cin >> a >> tanka >> uriage;
      num[a] += tanka * uriage;
      jun[i] = a;
    }

    for(int i=1;i<N;i++){
      if(num[jun[i]]>=1000000){
	cout << jun[i] << endl;
	judge = false;
      }
    }
    if(judge)
      cout << "NA" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define vint vector<int>


int main(){
    int n;
    while(1){
        cin>>n;
        if(n==0) break;

        bool f = false;
        rep(i,n) {
            int a,b,c; cin>>a>>b>>c;
            if(b*c >= (int)1e6){
                cout<<a<<endl;
                f = true;
            }
        }
        if(!f) cout<<"NA"<<endl;
    }

    return 0;
}