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 <iostream>
#include<cstdio>
#include<vector>
#include<map>

using namespace std;

int main()
{
    while(1){
        int n;
        scanf(" %d",&n);
        if(n==0)break;

        vector<int> bangoulist;
        map<int,long> alldata;
        alldata.clear();
        for(int i=0;i<n;i++){
                int bangou,tanka,num;
                scanf(" %d %d %d",&bangou,&tanka,&num);
                if(!alldata[bangou]){
                        alldata[bangou]+=tanka*num;
                }else{
                        bangoulist.push_back(bangou);
                        alldata[bangou]=tanka*num;
                }
        }
        bool flag=true;
        for(int i=0;i<(int)bangoulist.size();i++){
                if(alldata[bangoulist[i]]>=1000000){
                        cout<<bangoulist[i]<<"\n";
                        flag=false;
                }
        }
        if(flag)cout<<"NA\n";
    }
    return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	while (1) {
		/*for (int i = 0; i < n; i++) {
			e[i] = 0;
		}
		for (int i = 0; i < 4000; i++) {
			m[i] = 0;
			pr[i] = 0;
		}
		na = 1;*/
		int n = 0, p, q, na = 1, e[4000] = {}, pr[4000] = {};
		unsigned long long int m[4000] = {};

		cin >> n;
		if (n == 0)
			break;

		for (int i = 0; i < n; i++) {
			cin >> e[i] >> p >> q;
			m[e[i] - 1] += p * q;
			if (m[e[i] - 1] >= 1000000 && pr[e[i] - 1] == 0) {
				cout << e[i] << endl;
				pr[e[i] - 1] = 1;
				na = 0;
			}
		}
		
		if (na)
			cout << "NA\n";

	}
	return 0;
}

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

int main(){
    int n,i;
    while(cin>>n,n){
        map<int,long long>m;
        vector<int>vec;
        long long p,q,s=0;
        while(n--){
            cin>>i>>p>>q;
            if(!m[i])vec.push_back(i);
            m[i]+=p*q;
        }
        for (map<int,long long>::iterator it=m.begin(); it!=m.end(); ++it){
            if(it->second>=1000000){
                s=1;
                cout<<it->first<<endl;
            }
        }
        for (int i=0;i<vec.size();i++){
            map<int,long long>::iterator it=m.find(vec[i]);
            if(it->second>=1000000){
                s=1;
                cout<<it->first<<endl;
            }
        }
        if(!s)cout<<"NA"<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
typedef long long ll;
using namespace std;
const int MAX = 101;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

int main(){
	int n;
	while(cin >> n && n!=0){
		map<int, ll> ans;
		vector<int> idx;
		int id, price, num;
		for(int i = 0; i < n; i++){
			cin >> id >> price >> num;
			if(!ans.count(id)) idx.push_back(id);
			ans[id] += price*num;
		}

		vector<int> ans_id;
		for(int i = 0; i < idx.size(); i++){
			if(ans[idx[i]]>=1000000) ans_id.push_back(idx[i]);
		}
		if(ans_id.size()==0){
			cout << "NA" << endl;
		}else{
			for(int i = 0; i < ans_id.size(); i++){
				cout << ans_id[i] << endl;
			}
		}
	}
	return 0;
}

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

int main() {
	ll n;
	while (cin >> n, n) {
		map<ll, ll>mp;
		rep(i, n) {
			ll e, p, q; cin >> e >> p >> q;
			mp[e] += p*q;
		}
		bool flag = false;
		for (auto i : mp) {
			if (i.second >= 1000000) {
				flag = true;
				cout << i.first << endl;
			}
		}
		if (!flag)puts("NA");
	}
}

C++: #include <algorithm>
#include <cstdio>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

int main() {
  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 0) { break; }

    int insert_order = 0;
    unordered_map<int, int> insert_orders;
    unordered_map<int, int> sales;
    for (int i = 0; i < n; ++i) {
      int id, unit_cost, count;
      scanf("%d %d %d", &id, &unit_cost, &count);
      if (insert_orders.count(id) == 0) {
        insert_orders[id] = ++insert_order;
      }
      sales[id] += unit_cost * count;
    }
    typedef pair<int, int> Record;
    vector<Record> sales_result(sales.cbegin(), sales.cend());
    sort(
        sales_result.begin(),
        sales_result.end(),
        [&](const Record& a, const Record& b) {
          return insert_orders[a.first] < insert_orders[b.first];
        });
    bool exists = false;
    for (const auto& record : sales_result) {
      if (record.second < 1000000) { continue; }
      exists = true;
      printf("%d\n", record.first);
    }
    if (!exists) { puts("NA"); }
  }

  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n, m;

    while(cin >> n, n){
        long long v[4010];
        vi id;
        rep(j, 4010) v[j] = 0;
        rep(p, n){
            long long  a, b, c;
            cin >> a >> b >> c;
            if(v[a] == 0) id.pb(a);
            v[a] += b*c;
        }
        bool isP = false;
        rep(i, id.size()) if(1000000 <= v[id[i]]){isP = true; cout << id[i] << endl;}
        if(!isP) cout << "NA" << endl;
}
}

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

std::vector<std::string> split(const std::string& ref,char c){
std::vector<std::string> res;
size_t current=0, found;
while((found=ref.find_first_of(c,current))!=std::string::npos){
res.push_back(std::string(ref,current,found-current));
current=found+1;
}
res.push_back(std::string(ref,current,ref.size()-current));
return res;
}

int main(void){

int it_num=0;
std::string str="";
std::vector<std::string> ref;
std::vector<std::string> res;

std::cin >> str;
if(str!="") it_num=std::stoi(str);

while(it_num!=0){
for(int i=0;i<it_num;i++){
std::getline(std::cin,str);
ref=split(str,' ');
if((std::stoi(ref[1])*std::stoi(ref[2]))>=1000000){
res.push_back(ref[0]);
}
if(res.size()==0){
std::cout << "NA" << std::endl;
}else{
for(int j=0;j<res.size();j++){
std::cout << res[j] << std::endl;
}
}
}
res.clear()
std::cin >> it_num;
}

return 0;
}