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<bits/stdc++.h>

using namespace std;

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

    vector<pair<int,int>> data;
    for(int i = 0;i < n;++i){
      int num,sa,ko;
      cin>>num;
      cin>>sa;
      cin>>ko;

      int sum = sa * ko;
      data.push_back(make_pair(num,sum));
    }

    int check = 0;
    for(pair<int,int> e : data){
      if(e.second >= 1000000){
        check = 1;
        cout<<e.first<<endl;
      }
    }
    if(check == 0){
      cout<<"NA"<<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]+=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 <bits/stdc++.h>

using namespace std;

int main(){

  int n, id, val, num;
  int member[4000];

  while(cin >> n){

    if(!n) break;

    memset(member, 0, sizeof(member));

    for(int i = 0; i < n; ++i){
      cin >> id >> val >> num;
      member[id - 1] += val * num;
    }

    bool flag = false;

    for(int i = 0; i < 4000; ++i){
      if(member[i] >= 1000000){
        cout << i + 1 << endl;
        flag = true;
      }
    }

    if(!flag) cout << "NA" << endl;

  }

}

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

int main(){
	int n,num,mn,nm,mon;
	while(cin >> n,n){
		int c=0,sc[4001],cn=0,cc=0;
		map<int,int> maps;
		for(int i=0;i<n;i++){
			int cnt=0,j=0;
			cin >> num >> mn >> nm;
			mon = mn*nm;
			maps[num] += mon;
			for(;j<c;j++){
				if(sc[j]==num)cn++;
			}
			if(cn==0||j==0){
				sc[c] = num;
				c++;
				//cout << sc[c] << endl;
			}
		}
		for(int i=0;i<c;i++){
			if(maps[sc[i]]>=1000000){
				cout << sc[i] << endl;
				cc++;
			}
		}
		if(cc==0) cout << "NA" << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	int n;
	while(cin >> n){
		if(n == 0){
			break;
		}
		map<int, int> m;
		for(int i = 0; i < n; i++){
			int id, price, amount;
			cin >> id >> price >> amount;
			m[id] += price * amount;
		}
		bool applicable = false;
		for(map<int, int>::iterator itr = m.begin(); itr != m.end(); itr++){
			if(itr->second >= 1000000){
				applicable = true;
				cout << itr->first << endl;
			}
		}
		if(!applicable){
			cout << "NA" << endl;
		}
	}
	return 0;
}

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

struct data{
    int id;
    long long int sales;
    data(int a, int b) : id(a), sales(b) {}
};

int main(){
    int n;
    while( cin >> n, n ){
        vector< data > ls;
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> a >> b >> c;
            vector<data>::iterator it = ls.begin();
            for(; it!=ls.end(); it++){
                if( it->id == a ){
                    it->sales += b*c;
                    break;
                }
            }
            if( it == ls.end() ){
                ls.push_back( data(a, b*c) );
            }
        }
        bool exs = false;
        for(vector<data>::iterator it = ls.begin(); it != ls.end(); it++){
            if( it->sales >= 1000000 ){
                cout << it->id << endl;
                exs = true;
            }
        }
        if( !exs ){
            cout << "NA" << endl;
        }
    }
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

long long int n,a,b,c;



int main(){
    
        
    while(cin >> n){
        if(n==0)break;
        
        long long int ans[4001]={0};
        
        bool flag=true;
        for(int i=0; i<n; i++){
            cin>>a>>b>>c;
            if(ans[a]<1000000)ans[a]+=b*c;
        }
        
        for(int i=1; i<=4000; i++){
            if(ans[i]>=1000000){
                cout<<i<<endl;
                flag=false;
            }
        }
        
        if(flag)cout<<"NA"<<endl;
    }
            
}

C++: #include<stdio.h>
long long int t[4000];
int k[4000];
bool sub[4000];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<4000;i++){
			t[i]=0;
			k[i]=0;
			sub[i]=false;
		}
		int o=0;
		for(int i=0;i<a;i++){
			int b,c,d;
			
			scanf("%d%d%d",&b,&c,&d);
			t[b-1]+=(long long)c*(long long)d;
			if(!sub[b-1]){
				k[o++]=b-1;
				sub[b-1]=true;
			}
		}
		bool ok=false;
		for(int i=0;i<o;i++){
			if(t[k[i]]>=1000000LL){
				printf("%d\n",k[i]+1);
				ok=true;
			}
		}
		if(!ok)printf("NA\n");
	}
}

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

            M[a]=(long long)b*c;;
        }

        bool flag=true;
        for(map<int,long long int>::iterator ite=M.begin();ite!=M.end();ite++){
            if(ite->second>=1000000){
                cout<<ite->first<<endl;
                flag=false;
            }
        }
        if(flag)cout<<"NA"<<endl;
    }
    return 0;
}

C++: // #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>	// istringstream
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(); it!=c.end(); ++it)

// #defineの初利用にあたって参考にした http://peroon.hatenablog.com/entry/20091123/1258966199
// iteratorのforLoop                   http://bokko.hatenablog.com/entry/20090320/1237494217
// fastIO                              https://gist.github.com/rigibun/7905920

void solveAndOutput(map<int, long long> data, VI bangouList){
	int outputCount = 0;

	FOR(i, 0, bangouList.size()){
		if (data[bangouList[i]] >= 1000000){
			cout << bangouList[i] << endl;
			outputCount++;
		}
	}
	if (outputCount == 0)
		cout << "NA" << endl;
}

int main(){
	// sankou http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=97994#1

	long long n;
	// 重複なし、自動ソート
	map<int, long long> data;
	// 重複あり、ソートなし -> 重複するものは格納しないようにしたい.
	VI bangouList;
	fastIO;

	while (cin >> n, n){
		data.clear();
		bangouList.clear();
		while (n--){
			int bangou = 0, tanka = 0, suu = 0;
			cin >> bangou >> tanka >> suu;
			if(data[bangou] == 0)
				bangouList.push_back(bangou);
			data[bangou] += tanka * suu;
		}
		solveAndOutput(data, bangouList);
	}
	return 0;
}