Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}
		sales := make(map[string]int)
		existed := make(map[string]bool)
		order := make([]string, 4000)
		flg := false
		for i := 0; i < n; i++ {
			stdin.Scan()
			l := strings.Split(stdin.Text(), " ")
			e := l[0]
			p, _ := strconv.Atoi(l[1])
			q, _ := strconv.Atoi(l[2])
			sales[e] += p * q
			if !existed[e] {
				order = append(order, e)
				existed[e] = true
			}
		}
		for _, v := range order {
			if sales[v] >= 1000000 {
				fmt.Println(v)
				flg = true
			}
		}
		if flg == false {
			fmt.Println("NA")
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    int n; cin >> n;
    do {
        int e[n], p[n], q[n];
        int tmp[4001] = {};
        int flag = 0;
        rep(i, n) cin >> e[i] >> p[i] >> q[i];
        for (int i = 0; i < n; i++) {
            tmp[e[i]] += p[i] * q[i];
        }
        for (int i = 0; i < 4001; i++) {
            if (tmp[i] >= 1000000) {
                cout << i << endl;
                flag = 1;
            }
        }
        if (flag == 0) cout << "NA" << endl;
        cin >> n;
    } while(n != 0);

    return 0;
}

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

int main()
{
	array<int, 4000> ar = {};
	vector<int> ans;
	int n,e,p,q;
	
	while (true) {
		cin >> n;
		ar.fill(0);
		if (!n) {
			break;
		}

		bool isNA = true;
		for (int i = 0; i < n; ++i) {
			cin >> e >> p >> q;
			ar[e] += p*q;
		}
		for (int i = 0; i < 4000;++i) {
			if (ar[i] >= 1000000) {
				ans.push_back(i);
				isNA = false;
			}
		}
		if (isNA) {
			ans.push_back(-1);
		}

	}

	for (auto it : ans) {
		if (it != -1) {
			cout << it;
		}
		else {
			cout << "NA";
		}

		if (it != *ans.end()) {
			cout << endl;
		}
	}
	return 0;
}

C++: # include <iostream>
# include <cstring>
# include <vector>

int n;
int a[3];
std::vector<std::pair<int, int>> vec;
bool x[4001];

int main() {
	while (1) {
		std::cin >> n;
		if (n == 0)
			break;
		int count = 0;
		vec.clear();
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j)
				std::cin >> a[j];
			if (x[a[0]]) {
				for (int k = 0; k < vec.size(); ++k) {
					if (vec[k].first == a[0])
						vec[k].second += a[1] * a[2];
				}
			}
			else {
				vec.push_back(std::make_pair(a[0], a[1] * a[2]));
				x[a[0]] = true;
			}
		}
		for (auto it = vec.begin(); it != vec.end(); ++it) {
			if ((*it).second >= 1000000) {
				std::cout << (*it).first << std::endl;
				++count;
			}
		}
		if (count==0)
			std::cout << "NA" << std::endl;
	}
	return 0;
}

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

int main(){

	while (true) {
		int cnt = 0;
		cin >> cnt;
		if (cnt == 0) break;

		typedef std::vector<std::pair<int, int> > dataType;
		dataType data;
		for (int i = 0; i < cnt; ++i) {
			int id, price, amount;
			cin >> id >> price >> amount;
			int g = price * amount;

			bool found = false;
			for (int i = 0; i < data.size(); ++i) {
				if (data[i].first == id) {
					data[i].second += g;
					found = true;
				}
			}
			if (!found) data.push_back(std::pair<int, int>(id, g));
		}
		bool bHitted = false;
		for (dataType::iterator it = data.begin(); it != data.end(); ++it) {
			if (it->second >= 1000000) {
				cout << it->first << "\n";
				bHitted = true;
			}
		}
		if (!bHitted) {
			cout << "NA\n";
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  long long int nin;
  while(1){ 
    scanf("%d",&nin);
    if(!nin)break;

    long long int human[4002]={0};
    long long int no[4002],tanka,kazu,outflag=0;
    
    for(int i=0;i<nin;i++){
      scanf("%d %d %d",&no[i],&tanka,&kazu);
      human[no[i]]+=tanka*kazu;
    }
    
    for(int i=0;i<nin;i++){
      if(human[no[i]]>=1000000 && human[no[i]]!=-1){
	printf("%d\n",no[i]);
	human[no[i]]=-1;
	outflag=1;
      }
    }
    
    if(outflag==0)printf("NA\n");
    
  }
}

C++: #include<stdio.h>

int main(){
  while(1){
    int n;
    scanf("%d", &n);
    if(n!=0){
      int i,k;
      int a, b, c;
      int j=0;
      int d[4001]={};
      double e[4001] ={};
      int flag = 0;
      for(i=0;i<n;i++){
	scanf("%d %d %d", &a, &b, &c);
	int flag1=0;
	for(k=0;k<j;k++){
	  if(d[k]==a)
	    flag1=1;
	}
	if(flag1==0)
	  {d[j]=a;j++;}

	//if(e[a]+b*c<=2147483647)
	e[a]=e[a]+(double)b*(double)c;
	//else
	  //e[a]=(double)2147483647;//printf("aa\n");
	
      }


      for(i=0;i<4001;i++){
	if(e[d[i]]>=1000000.){
	  printf("%d\n", d[i]);
	  flag++;
	}
      }
      if(flag==0)
	printf("NA\n");
      
    }
    else{
      break;
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int N = 4000;
int n;
ll cost[N];
int id;
ll dc, dn;

int main()
{
  while((cin >> n) && n){
    bool flag = true;
    rep(i, N) cost[i] = 0LL;

    rep(i, n){
      cin >> id >> dc >> dn;
      cost[id-1] += dc * dn;
    }

    rep(i, N) if(cost[i] >= 1000000){
      flag = false;
      cout << i + 1 << endl;
    }
    if(flag) puts("NA");
  }

  return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
#define MAX_N 1000000
long long x[MAX_N], a, b, c, n, cnt;
int main() {
	while (1) {
		memset(x, 0, sizeof(x)); cnt = 0;
		cin >> n; if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			x[a] += b*c;
			if (x[a] >= 1000000) { cout << a << endl; cnt++; }
		}
		if (cnt == 0) { 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 unsigned 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){
		vector<vector<ll> > num(n,vector<ll>(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;
		rep(i,n){
			if(num[i][1]>=1000000){cout<<num[i][0]<<endl;cnt++;}
		}
		if(!cnt)cout<<"NA"<<endl;
		//cout<<"NO"<<n<<endl<<endl;;
	}
}