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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

#define INF 999999
#define MAX_V 999

using namespace std;

int main(){
	int n, id, val, num;
	vector<int> ans;
	vector<int> com(4000);
	while(cin>>n,n){
		ans.clear();
		rep(i,4000)	com[i]=0;
		rep(i,n){
			cin>>id>>val>>num;
			com[id-1]+=val*num;
		}
		rep(i,4000){
			if(com[i]>=1000000){
				ans.push_back(i+1);
			}
		}
		if(ans.size()){
			rep(i,ans.size())
				cout<<ans[i]<<endl;
		}else{
			cout<<"NA"<<endl;
		}
	}
	
	return 0;
	
}

C++: // a.c.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
	int n;
	int ban, tan, suu;
	long long int bango[4001];
	int flg,i;
	while (1){
		for (i = 1; i <= 4000; i++){
			bango[i] = 0;
		}
		scanf_s("%d", &n);
		if (n == 0){
			break;
		}
		for (i = 0; i < n; i++){
			scanf_s("%d %d %d", &ban, &tan, &suu);
			bango[ban] += tan*suu;
		}
		flg = 0;
		for (i = 1; i <= 4000; i++){
			if (bango[i]>=1000000){
				printf("%d\n", i);
				flg = 1;
			}
		}
		if (!flg){
			printf("NA\n");
		}
	}
	return 0;
}

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

int main()
{
	int n;
	while (cin >> n, n) {
		map<int, long long> data;
		map<int, int> seq;
		for (int i = 0; i < n; ++i) {
			int bangou, tanka, kazu;
			cin >> bangou >> tanka >> kazu;
			if (data.find(bangou) == data.end()) {
				data[bangou] = 0;
				seq[bangou] = i;
			}
			data[bangou] += tanka * kazu;
		}
		vector<pair<int, int> > v;
		for (map<int, long long>::iterator it = data.begin(); it != data.end(); ++it)
			if (it->second >= 1000000)
				v.push_back(make_pair(seq[it->first], it->first));
		if (v.empty())
			cout << "NA" << endl;
		else {
			sort(v.begin(), v.end());
			for (int i = 0; i < v.size(); ++i) cout << v[i].second << endl;
		}
	}
	return 0;
}

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

using namespace std;

long long int nums[10000];

int main(){
	
	while(true){
		
		int n;
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < 10000; i++){
			nums[i] = 0;
		}
		
		for(int i = 0; i < n; i++){
			int e, p, q;
			cin >> e >> p >> q;
			nums[e] += p * q;
		}
		
		bool check = false;
		
		for(int i = 0; i <= 4000; i++){
			if(nums[i] >= 1000000){
				cout << i << endl;
				check = true;
			}
		}
		
		if(!check){
			cout << "NA" << endl;
		}
	}
	return 0;
}

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

int main()
{
    int n;
    while(cin >> n,n){
        bool hantei=true,kaburi[n];
        long long number[n],price[n],quantity[n],sale[n];
        for(int i=0 ; i<n ; i++){
            cin >> number[i] >> price[i] >> quantity[i];
            sale[i]=price[i]*quantity[i];
        }
        for(int i=0 ; i<n-1 ; i++){
            for(int j=i+1 ; j<n ; j++){
                if(number[i]==number[j]){
                    kaburi[j]=true;
                    sale[i]+=(price[j]*quantity[j]);
                }
            }
        }
        for(int i=0 ; i<n ; i++){
            if(kaburi[i]){
                continue;
            }
            if(sale[i]>=1000000){
                cout << number[i] << endl;
                hantei=false;
            }
        }
        if(hantei){
            cout << "NA" << endl;
        }
    }
    return 0;
}

C++: //Sale Result
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<string> order;//入力された順番
map<string, ll> mp;

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    vector<string>::iterator it;
    order.clear();
    mp.clear();
    for(int i=0; i<n; i++){
      string p;
      ll u, a;
      cin>>p>>u>>a;
      it=find(order.begin(), order.end(), p);
      if(it==order.end()){
        order.push_back(p);
        mp.insert(make_pair<string, ll>(p, 0));
      }
      mp[p]+=u*a;
    }
    bool flag=true;
    for(it=order.begin(); it!=order.end(); it++){
      if(mp[*it]>=1000000){
        cout<<*it<<endl;
        flag=false;
      }
    }
    if(flag)cout<<"NA"<<endl;
  }
  return 0;
}

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

int A[1000000];

signed main()
{
    int N,B,C;
    while(cin >> N,N){
        int cnt[4001]={};
        bool NAflag=true,used[4001]={};
        for(int i=0;i<N;i++){
            cin>>A[i]>>B>>C;
            cnt[A[i]] += B*C;

        }
        for(int i=0;i<N;i++){
            if(cnt[A[i]]>=1000000 && used[A[i]]==false){
                printf("%d\n",A[i]); used[A[i]]=true; NAflag=false;
            }
        }
        if(NAflag==true){
            puts("NA");
        }
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main()
{
    int n;
    long long int ids[4001];
    int id;
    long long price, amount;
    bool exist;
    bool used[4001];
    vector<int> rank;
    while(cin >> n && n)
    {
        exist=false;
        for(int i=1;i<4001;++i)
        {
            ids[i] = 0;
            used[i] = false;
        }
        rank.clear();
        for(int i=0;i<n;++i)
        {
            cin >> id >> price >> amount;
            if(!used[id])
            {
                rank.push_back(id);
                used[id] = true;
            }
            ids[id] += price * amount;
        }
        for(int i=0;i<rank.size();++i)
        {
            if(ids[rank[i]] >= 1000000)
            {
                exist = true;
                cout << rank[i] << endl;
            }
        }
        if(!exist) cout << "NA" << endl;
    }
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

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