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++: #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;
		for (int i = 0; i < n; i++){
			int d,b,c; cin>>d>>b>>c;
			if(b*c >= 1000000) a.push_back(d);
		}
		if(a.size() == 0){ puts("NA"); continue; }
		for (int i = 0; i < a.size(); i++)
			cout << a[i] << endl;
	}
    return 0;
}

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

#define SHINE_MAX 4000
#define ELITE 1000000
#define AHO "NA"

int shineN,eliteN;
long int shineU[SHINE_MAX];	//?£??????????

int num,tanka,suryo;
int i;

int main(){
	while(1){
	 cin>>shineN;
	 if(shineN==0){break;}
	 for(i=0;i<SHINE_MAX;i++){shineU[i]=0;}
	 for(i=0;i<shineN;i++){
	  cin>>num,tanka,suryo;
	  shineU[num-1]+=tanka*suryo;
	 }
	 //??¨?????????????????¨
	 eliteN=0;
	 for(i=0;i<SHINE_MAX && eliteN<shineN;i++){
	  if(ELITE<=shineU[i]){
	   cout<<i<<endl;
	   eliteN++;
	  }
	 }
	 if(eliteN==0){cout<<AHO<<endl;}
	}
	return 0;
}

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

template<typename itr, typename func>
func for_each_withindex(itr fi, itr l, func f){
	unsigned i{};
	for(; fi!=l; ++fi,++i){
		f(*fi,i);
	}
	return f;
}

int main(int argc, char const* argv[])
{
	unsigned n{};
	while (std::cin >> n,n != 0) {
		unsigned long long e{}, p{}, q{};
		bool isna{true};
		std::array<unsigned long long,4001> es{};
		for (unsigned i = 0; i < n; i++) {
			std::cin >> e >> p >> q;
				es.at(e) += p * q;
		}
		for_each_withindex(es.begin(), es.end(), [&isna](auto sell,auto e){ 
				if (sell>=1000000) {
				std::cout << e << std::endl;
				isna = false;
				}});
		if (isna) {
			std::cout << "NA" << std::endl;
		}

	}
	return 0;
}

C++: #include <stdio.h>
 
int n,num[4000];
long long int tanka[4000],sale_num[4000],sale_all[4001];
bool judge[4001];
 
int main(void)
{
int i,j,k;
     
while(scanf("%d",&n),n){
    for(i=0;i<n;i++){
        scanf("%lld %lld %lld",&num[i],&tanka[i],&sale_num[i]);
    }
    k=0;
    for(j=0;j<4001;j++){
    judge[j]=0;
    sale_all[i]=0;
    }
    for(i=0;i<n;i++){
        sale_all[num[i]] = sale_all[num[i]]+ tanka[i]*sale_num[i];
    }
    for(i=0; i < n; i++){
        if((sale_all[num[i]] >= 1000000)&&(judge[num[i]]==0)){
            printf("%d\n",num[i]);
            judge[num[i]]=1;
            k=1;
        }
    }
    if(k!=1)printf("NA\n");
}
 
    return 0;
}

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

int loop(int h, int u);

int main(){
    int id, h, u, n;
    while(cin >>n){
        if(n == 0) break;
        bool flg = false;
        for(int i = 0; i < n; i++){
            cin >>id >>h >>u;
            if(loop(h, u)){
                cout <<id <<endl;
                flg = true;
            }
        }
        if(!flg) cout <<"NA" <<endl;
    }
    return 0;
}

int loop(int h, int u){
    int sum = 0;
    for(int i = 0; i < u; i++){
        sum += h;
        if(sum >= 1000000) return 1;
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long int aa[10000]={0},x=0,y=0,z=0,flg=0,a,flgg[4050]={0};
    while(cin>>a)
    {
        if(a==0)break;
        for(int i=0;i<a;i++)
        {
            cin>>x>>y>>z;
            aa[x]+=y*z;
            if(aa[x]>=1000000)
            {
                if(flgg[x]==0)
                {
                    cout<<x<<endl;
                }
            }
        }
        //for(int i=0;i<4010;i++)
        //{
        //    if(aa[i]>=1000000)
        //    {
        //        flg=1;
        //        cout<<i<<endl;
        //    }
        //}
        if(flg==0)cout<<"NA"<<endl;
        for(int i=0;i<4010;i++)
        {
            aa[i]=0;
            flg=0;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#define int long long
using namespace std;

class Input {
public:
	int n;
	vector<int> numbers, tanka, num;
	
	bool input() {
		scanf("%d", &n);
		if (!n) {
			return false;
		}
		for (int i = 0; i < n; i++) {
			int s, t, u;
			scanf("%d%d%d", &s, &t, &u);
			numbers.push_back(s);
			tanka.push_back(t);
			num.push_back(u);
		}
		return true;
	}
};
class Solver : public Input {
public:

	vector<int> solve() {
		typedef pair<int, int> P;
		map<int, int> data;
		for (int i = 0; i < n; i++) {
			int value = tanka[i] * num[i];
			int number = numbers[i];
			
			if (data.find(number) == data.end() ) {
				data[number] = 0;
			}
			data[number] += value;
		}
		
		vector<int> ret;
		for (map<int, int>::iterator it = data.begin(); it != data.end(); it++) {
			if ((*it).second >= 1000000 ) {
				ret.push_back((*it).first);
			}
		}
		return ret;
	}
};

signed main() {
	while (true) {
		Solver solver;
		if (!solver.input() ) {
			break;
		}
		
		vector<int> res = solver.solve();
		if (res.size() == 0) {
			cout << "NA" << endl;
		}
		else {
			for (int i = 0; i < res.size(); i++) {
				cout << res[i] << endl;
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define INT(name) int name; scanf("%d",&name);
#define VINT(name,n) vector<int> name(n); for(int i = 0;i < n;i++) scanf("%d",&name[i]);

using namespace std;

int main(int argc, char const *argv[]){
	vector<long long> data(4000);
	int i;
	long long a,b,c;
	bool check;

	cin >> i;
	while(i){

		for(int j = 0;j < 4000;j++){
			data[j] = 0;
		}


		for(int j = 0;j < i;j++){
			cin >> a >> b >> c;
			data[a - 1] += b * c;
		}


		check = false;

		for(int j = 0;j < 4000;j++){
			if(data[j] >= 1000000){
				printf("%d\n",j+1);
				check = true;
			}
		}

		if(!check) printf("NA\n");

		cin >> i;
	}

	return 0;
}

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

int main(){
  int n,i,p,q,f;
  for(;scanf("%d",&n),n;){
    map<int,long long int>m;
    vector<int>v;
    for(;n--;){
      scanf("%d%d%d",&i,&p,&q);
      if(m.find(i)==m.end())v.push_back(i);
      m[i]+=(long long int)p*q;
    }
    for(f=i=0;i<v.size();i++){
      if(m[v[i]]>=1000000)printf("%d\n",v[i]),f=1;
    }
    if(!f)puts("NA");
  }
}

C++: #include<stdio.h>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
long long s[4000];
P p[4000];
int min(int a,int b){return a<b?a:b;}
int main(){
	int n,i;
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		for(i=0;i<4000;i++){
			s[i]=0;
			p[i].first=5000;
			p[i].second=i;
		}
		for(i=0;i<n;i++){
			int a,b,c;
			scanf("%d %d %d",&a,&b,&c);
			s[a-1]+=b*c;
			p[a-1].first=min(p[a-1].first,i);
		}
		sort(p,p+4000);
		bool f=true;
		for(i=0;i<4000;i++){
			if(p[i].first==5000)break;
			if(s[p[i].second]>=1000000){
				printf("%d\n",p[i].second+1);
				f=false;
			}
		}
		if(f)printf("NA\n");
	}
}