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>

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("lld", &x); return (x); }

int main()
{
	list<int> staffList;
	map<int, int> saleResult;
	int n;
	int staffNum;
	int unitPrice;
	int quantity;
	while( 1 )
	{
		n = in();
		if( n == 0 )break;

		staffList.clear();
		saleResult.clear();
		loop(i, 0, n)
		{
			staffNum = in();
			unitPrice = in();
			quantity = in();
			staffList.push_back(staffNum);
			saleResult[staffNum] += unitPrice * quantity;
		}
		bool flag = false;
		for(list<int>::iterator it = staffList.begin(); it != staffList.end(); it++)
		{
			if( saleResult[*it] >= 1000000 )
			{
				printf("%d\n", *it);
				saleResult[*it] = 0;
				flag = true;
			}
		}
		if( !flag )
		{
			cout << "NA" << endl;
		}
	}
	return (0);
}

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

int main() {
	long long e, p, q;
	int n;
	while (cin >> n, n) {
		long long number[4001] = {};
		for (int i = 0; i < n; i++) {
			cin >> e >> p >> q;

			if (number[e - 1] <= 1000000) {
				number[e - 1] += p*q;
			}
		}

		int x = 0;
		for (int i = 0; i < 4000; i++) {
			if (number[i] >= 1000000) {
				cout << i + 1 << endl;
				x++;
			}
		}
		if (x == 0) { cout << "NA" << endl; }
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
typedef struct result{
  int nam;
  int mon;
  int cont;
  int sum;
}P;
int main(){
  P a[4000];
  int n,nacount;
  while(1){
    cin >> n;
    nacount=0;
    if(n==0){break;}
    for(int i=0;i<n;i++){
      cin>>a[i].nam>>a[i].mon>>a[i].cont;
      a[i].sum=a[i].mon*a[i].cont;
    }
    for(int i=0;i<n;i++){
      for(int j=n-1;j>i;j--){
	if(a[i].nam==a[j].nam){
	  a[i].sum+=a[j].sum;
	  a[j].sum=0;
	}
      }
    }
    for(int i=0;i<n;i++){
      if(a[i].sum>=1000000){
	cout<<a[i].nam<<endl;
	nacount++;
      }
    }if(nacount==0){
      cout<<"NA"<<endl;
    }
  }
  return 0;
}

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

#define TAR 1000000

int main() {
	unsigned long n,num,t,k,ch;
	while(cin >> n){
		ch = 0;
		while(n){
			scanf("%ld %ld %ld",&num,&t,&k);
			if((t!=0)&&(k!=0)){
				if((k >= TAR/t)&&(TAR%t == 0)){
					cout << num << endl;
					ch++;
				}else if((t >= TAR/k)&&(TAR%k == 0)){
					cout << num << endl;
					ch++;
				}else if((k > TAR/t)&&(t > TAR/k)){
					cout << num << endl;
					ch++;
				}
				if(((--n)==0)&&(ch==0)){
					cout << "NA" << endl;
				}
			}
		}
	}
	return 0;
}

C++: /*
	0100:Sale Result
*/
#include	<iostream>
#include	<map>

using namespace std;

int main(void) {
	int n;
	while(1) {
		bool isOK = false;
		map<int, long long> MP;
		
		cin >> n;
		
		if(n == 0) { break; }
		
		for(int i = 0; i < n; i++) {
			int n, p, c;
			cin >> n >> p >> c;
			MP[n] += p * c;
		}
		for(map<int, long long>::iterator it = MP.begin(); it != MP.end(); it++) {
			if(it->second >= 1000000) {
				cout << it->first << endl;
				isOK = true;
			}
		}
		if(isOK == false) {
			cout << "NA" << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


ll n;

int main(){
	while(cin>>n,n!=0){
		ll id[4005]={0};
		int a[8000]={0};
		
		int cou;
		rep(i,n){
			ll t1,t2,t3;
			cin>>t1>>t2>>t3;
			a[i]=t1;
			//if(id[t1]>0){
				id[t1]+=t2*t3;
			//}
			/*
			else{
				id[t1]=t2*t3;
			}
			*/
			cou=i;
		}
		bool f=true;
		rep(i,cou+100){
			if(id[a[i]]>=1000000){
				cout<<a[i]<<endl;
				id[a[i]]=0;
				f=false;
			}
		}
		if(f) cout<<"NA"<<endl;
	}
	return 0;
}

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

int main(){
	int n,number;
	long long a,b;
	bool flag;
	map<int,long long> info;
	vector<int> seq;
	
	while(cin >> n && n){
		info.clear();
		seq.clear();
		while(n--){
			cin >> number >> a >> b;
			if(!info[number])seq.push_back(number); // ??¢????????£????????¨???????¨???????????????\??????????????????0?????±?????????????????????????????????
			info[number] += a*b;
		}
		flag = true;
		for(int i=0;i<seq.size();i++){
			if(info[seq[i]]>=1000000){
				flag = false;
				cout << seq[i] << endl;
			}
		}
		if(flag)cout << "NA" << endl;
	}
}

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



signed main(){
  while(true){
    int n;cin >> n;
    if(n == 0)break;
    
    // mp[e].first: 社員番号
    // mp[e].second.first: 売上の合計
    // mp[e].second.second: 入力に最初に入ったときの順番
    map<int, pair<int, int>> mp;
    for(int i = 0;i < n;i++){
      int e, p, q;cin >> e >> p >> q;
      if(mp.find(e) == mp.end()){
        mp[e] = make_pair(p*q, i);  // 一回目の処理
      }else{
        mp[e] = make_pair(mp[e].first+p*q, mp[e].second); // 二回目以降の処理
      }
    }
    
    // 条件を満たす社員をソートするためのvector
    // vec[i].first: 入力に最初に入ったときの順番
    // vec[i].second: 社員番号
    vector<pair<int, int>> vec;
    for(auto x: mp)if(x.second.first >= 1000000){
      vec.push_back(make_pair(x.second.second, x.first)); // 条件を満たす社員を追加
    }
    sort(vec.begin(), vec.end()); // ソート実行
    
    if(vec.size() == 0){
      cout << "NA" << endl;   // 該当する社員がいなかった時
      continue;
    }
    for(int i = 0;i < vec.size();i++){
      cout << vec[i].second << endl; // 社員出力
    }
  }
  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int E[4010] = {};
	for (int n; cin >> n&&n;) {
		memset(E, 0, sizeof(E));
		rep(i, 0, n) {
			int e, p, q; cin >> e >> p >> q;
			E[e] += p*q;
		}
		bool flag = true;
		rep(i, 0, 4010) {
			if (E[i] >= 1000000) {
				flag = false;
				cout << i << endl;
			}
		}
		if (flag)cout << "NA" << endl;
	}
	return 0;
}