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 <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define MAX 100000000
#define pb push_back
using namespace std; 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
  
int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0) break;
    ll p[4001];
    for(int i = 0;i < 4001;i++){
      p[i] = 0;
    } 
    for(int i = 0;i < n;i++){
      int b;
      ll t,s;
      cin >> b >> t >> s;
      p[b] += t*s;
    }
    int count = 0;
    for(int i = 1;i < 4001;i++){
      if(p[i] >= 1000000){
	P(i);
	count++;
      }
    }
    if(count == 0){
      P("NA");
    }
  }
  return 0;
}

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

int main()
{
	while ( true )
	{
		int n; cin>>n;
		if ( n == 0 )
			break;
		bool f = false;
		for ( int i=0; i<n; i++ )
		{
			int a, b, c;
			cin>>a>>b>>c;
			if ( (long long)b*c>=1000000 )
				cout << a << endl,
				f = true;
		}
		if ( ! f )
			cout << "NA" << endl;
	}
}

C++: //Name: Sale Reult
//Level: 1
//Category: やるだけ
//Note:

#include <iostream>
#include <map>
#include <vector>

using namespace std;

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    map<int,long long> res;
    vector<int> ord;
    for(int i = 0; i < N; ++i) {
        int id, v, c;
        cin >> id >> v >> c;
        res[id] += ((long long)v)*c;
        ord.push_back(id);
    }

    bool exist = false;
    for(int id : ord) {
        if(res[id] >= 1000000) {
            cout << id << endl;
            res[id] = 0;
            exist = true;
        }
    }
    if(!exist) cout << "NA" << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    while(solve()) ;
    return 0;
}

C++: #include <map>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int id,cost,amount,n;
    while(cin >> n,n){
        map<int,long long> emps;
        vector<int> ids;
        bool exist = false;
        for(int i=0;i<n;i++){
            cin >> id >> cost >> amount;
            if(emps.find(id)!=emps.end()){
                emps[id]+=cost*amount;
            }else{
                emps[id]=cost*amount;
                ids.push_back(id);
            }
        }
        
        for(int i=0;i<ids.size();i++){
            if(emps.at(ids[i])>=1000000){
                cout << ids[i] << endl;
                exist=true;
            }
        }
        if(!exist) cout << "NA" << endl;

    }
    return 0;
}

C++: #include<iostream>
#include<cstring>
#include<vector>
using namespace std;
long long int sales[4010];
#define foreach(r,p,it) for(r::iterator it=p.begin();it!=p.end();++it)

int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0)break;
        vector<int> shains;
        shains.clear();
    
        memset(sales,0,sizeof(sales));
        int num,tanka,kazu;

        for(int i=0;i<n;i++)
        {
            cin>>num>>tanka>>kazu;
            sales[num] += tanka*kazu;
            int f=0;
            for(int j=0;j<shains.size();j++)
            {
                if(shains[j] == num){f=1;break;}
            }
            if(f==0) shains.push_back(num);
        }
        int na = 0;
        for(int i=0;i<shains.size();i++)
        {
            //cout <<"NUMBER"<<*it <<endl;
            if(sales[shains[i]] >= 1000000){cout<<shains[i]<<endl;na=1;}
        }
        if(na==0)cout<< "NA"<<endl;
    }
    return 0;
}

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

int main(){
int in;
while(cin >> in){
int p[in][in * 3],i,ii,c = 0,uri[in],k;	
	for(i = 1;in >= i;i++){ cin >> p[i][0] >> p[i][1] >> p[i][2];uri[i] = 0;}	
	for(i = 1;in >= i;i++){
		for(ii = 1;in >= ii;ii++){if(p[i][0] == p[ii][0]){ uri[ii] = uri[ii] + p[i][1] * p[i][2];}}
	}
	for(i = 1;in >= i;i++){
		k = 0;
		for(ii = 1;i > ii;ii++){if(p[i][0] == p[ii][0]){ k = 1;} }		
			if(uri[i] >= 1000000 and k == 0){cout << p[i][0] << endl; c++;} 
	}
	if(c == 0 and in != 0) cout << "NA" << endl;
}
}

C++: #include <stdio.h>
 
 

 
int main(void){
	int i,j,k;
	int n;
	long long num[4000],tanka[4000],sale_num[4000];
	int sale_all[4001],judge[4001];
	
	while(scanf("%d",&n),n){
		
		for(i=0;i<n;i++){
			scanf("%d%lld%lld",&num[i],&tanka[i],&sale_num[i]);
		}
		
		//初期化
		k=0;
		for(j=0;j<=4001;j++){
			judge[j]=0;
			sale_all[j]=0;
		}
		
		//idに対応したsaleに+
		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;
}