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>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
using namespace std;
void shoki();
void henkan(string);
int tansaku(int);
pair<string,long long> num[10000];
int n,ban,tanka,kazu,i,j,memo;
bool dp[10000]={false};
int main(){
	int al=0;
	bool y=false;
	while(1){
		shoki();
		cin>>n;
		if(n==0){
			break;
		}
		int count=0;
		for(i=0;i<n;i++){
			cin>>num[i].first>>tanka>>kazu;
			henkan(num[i].first);
			if(dp[memo]==true){
				num[tansaku(i)].second+=tanka*kazu;
			}
			else{
			num[i].second+=tanka*kazu;
			}
			dp[memo]=true;
			memo=0;
		}
		for(int k=0;k<=i;k++){
			if(num[k].second==0){
				continue;
			}
			if(num[k].second>=1000000){
				y=true;
				cout<<num[k].first<<endl;
			}
		}
		if(y==false){
			cout<<"NA"<<endl;
		}
		y=false;
		shoki();
		memset(dp,false,sizeof(dp));
	}
	return 0;
}
void shoki(){
	for(int i=0;i<4001;i++){
		num[i].first="0";
		num[i].second=0;
	}
	return;
}
void henkan(string str1){
	long long kake=1;
	for(int i=0;i<str1.size();i++){
		memo+=str1[i]*i;
		i*=10;
	}
	return;
}
int tansaku(int rec){
	int res;
	for(int l=0;l<rec;l++){
		if(num[rec].first==num[l].first){
			return res=l;
		}
	}
}

C++: #include <stdio.h>
#include <stdlib.h>

int main(void){
  int i, j, c, num, data;
  int staff[4000], n, value;
  int state[4000], state_n;
  char buf[8];

  while(1){
    num = j = 0;
    while((c = getchar()) != '\n'){
      buf[j++] = c;
      if(j == 1 && c == '0') break;
    }
    buf[j] = '\0';
    num = atoi(buf);
    if(num == 0) break;

    for(i = 0; i < 4000; i++){
      staff[i] = 0;
      state[i] = 0;
    }
    state_n = 0;

    for(i = 0; i < num; i++){
      data = j = 0;
      while((c = getchar()) != '\n'){
        buf[j] = c;
        if(c == ' ' && data == 0){
          buf[j] = '\0';
          n = atoi(buf);
          j = 0;
          data++;
          continue;
        }
        if(c == ' ' && data == 1){
          buf[j] = '\0';
          value = atoi(buf);
          j = 0;
          data++;
          continue;
        }
        j++;
      }
      buf[j] = '\0';
      staff[n-1] += atoi(buf) * value;
      if(staff[n-1] >= 1000000 && state[n-1] == 0){
        state[n-1] = ++state_n;
      }
    }

    if(state_n == 0){
      printf("NA\n");
    }
    for(j = 1; j <= state_n; j++){
      for(i = 0; i < 4000; i++){
        if(state[i] == j){
          printf("%d\n", i+1);
        }
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(void){
	int n;
	while(1){
		cin >> n;
		if(n==0)
			break;
		int c[4001]={} , id[100000];
		for (int i=0; i<n; i++){
			int p , q;
			cin >> id[i] >> p >> q;
			c[id[i]] += p*q;
		}
		bool f=1;
		for (int i=0; i<n; i++){
			if (c[id[i]]>=1000000){
				cout << id[i] << endl;
				c[id[i]]=0;
				f=0;
			}
		}
		if (f)
			cout << "NA" << endl;

	}

	return 0;
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int n,b,m,s,l,d[4000];
  for(;;){
    cin>>n;
    if(n==0)
      break;
    l=0;
    for(i=0;i<n;i++){
      cin>>b>>m>>s;
      if((long long)m*(long long)s>=1000000){
	d[l]=b;
	l++;
      }
    }
    if(l){
      for(i=0;i<l;i++)
	cout<<d[i]<<endl;
    }else
      cout<<"NA"<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)

int main(void){
    int n, i;
    long long int p, q;
    map<int, long long int> emp;
    vector<int> seq;
    while(cin >> n && n) {
        bool isExist = false;
        emp.clear();
        seq.clear();
        rep(l, n) {
            cin >> i >> p >> q;
            if(!emp[i]) seq.push_back(i);
            emp[i]+=p*q;
        }
        rep(i, seq.size()) {
            if(emp[seq[i]] >= 1000000) {
                cout << seq[i] << endl;
                isExist = true;
            }
        }
        if(!isExist) cout << "NA" << endl;
    }
}

C++: 
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()


int main(void){
	int n;	
	while(cin>>n,n){
		vvi num(n,vi(3,0));
		rep(i,n){
			//cout<<num[i][0]<<" "<<num[i][1]<<endl;
			cin>>num[i][0];
			int item,code;
			rep(j,i){
				if(num[i][0]==num[j][0]){
					num[j][1]+=item*code;
					num[i][2]=1;
				}
			}
			cin>>item>>code;
			if(!num[i][2])num[i][1]+=item*code;
		}
		//cout<<"star"<<endl;
		int cnt=0;
		vi ans;
		rep(i,n){
			//cout<<num[i][0]<<" "<<num[i][1]<<endl;
			if(num[i][1]>=1000000){ans.push_back(num[i][0]);cnt++;}
		}
		sort(all(ans));
		rep(i,ans.size())cout<<ans[i]<<endl;
		if(!cnt)cout<<"NA"<<endl;
		//cout<<"NO"<<n<<endl<<endl;;
	}
}

C++: #include<iostream>
using namespace std;
int main(void) {
	int a, b, c,d,e=0,f=0;
	while(1){
		cin >> a;
		if (a == 0) break;
		while (1) {
			cin >> b >> c >> d;
			if (c*d >= 1000000) {
				cout << b << endl;
				e++;
			}
			f++;
			if (a == f) break;
		}
		if (e == 0) cout << "NA\n";
		f = 0;
		e = 0;
	}
}

C++: #include<stdio.h>


int main(){
	int n;
	int id[4000],cid;
	long long int price,num,sale[4000];
	bool f;
	int i,j,idcount;
	while(scanf("%d",&n),n){

		f=true;
		idcount=0;

		for(i=0;i<n;i++){
			scanf("%d %lld %lld",&cid,&price,&num);
			for(j=0;j<idcount;j++){
				if(id[j]==cid){
					sale[j]=sale[j]+price*num;
				}
			}

			if(j==idcount){
				id[idcount]=cid;
				sale[idcount]=price*num;
				idcount++;
			}

		}



		for(i=0;i<idcount;i++){
			if(sale[i]>=1000000){
				printf("%d\n",id[i]);
				f=false;
			}
		}
		if(f!=false)printf("NA\n");
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
	int n,id,i,f,a,b,da[4001];
	while (cin >> n) {
		if (n==0) break;
		memset(da,0,sizeof(da));
		for (i=0;i<n;i++) {
			cin >> id >> a >> b;
			da[id]+=a*b;
			}
		f=0;
		for (i=1;i<=4000;i++) if (da[i]>=1000000) { cout << i << endl; f=1; }
		if (f==0) cout << "NA" << endl;
	}
	return 0;
}

C++: /*Kim Jong Il*/

#include<iostream>
#include<cstdio>
#define N1 1000
using namespace std;

int main(){
  int n,id[N1],array[N1][N1],i,j,count;
  
  while(1){
    count = 0;
    cin >> n;
    if(n == 0)break;
    
    for(i=0;i<n;i++){
      cin >> id[i];
      for(j=0;j<2;j++){
	cin >> array[i][j];
      }
    }
    for(i=0;i<n;i++){
      if(array[i][0] * array[i][1] >= 1000000){
	cout << id[i] << endl;
	count++;
      }
    }
    if(count == 0)cout << "NA" << endl;   
  }
}