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<vector>
#include<map>
#include<string>
using namespace std;

int main() {
	int num;
	int data_set = 0;
	bool do_continue = true;
	std::vector<string> result;

	while (do_continue) {
		cin >> num;
		if ((num == 0) || (data_set > 50)) {
			do_continue = false;
		}
		else {
			bool na_flg = true;
			data_set++;
			std::map<int, int> e;
			std::vector<int> employee;
			int fst, snd, thd;

			for (int i = 0; i < num; i++) {
				cin >> fst >> snd >> thd;
				employee.push_back(fst);
				if (e.count(employee[i])) {
					e[employee[i]] += snd * thd;
				}
				else {
					e[employee[i]] = snd * thd;
				}
			}

			for (unsigned int j = 0; j < employee.size(); j++) {
				if (e[employee[j]] >= 1000000) {
					na_flg = false;
					result.push_back(to_string(employee[j]));
				}
			}

			if (na_flg) {
				result.push_back("NA");
			}
		}
	}

	for (unsigned int i = 0; i < result.size()-1; i++) {
		cout << result[i] << endl;
	}


	return 0;
}

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

int n;
int a[3];
int x[4001];

int main() {
	while (1) {
		std::cin >> n;
		if (n == 0)
			break;
		int count = 0;

		std::memset(x, 0, sizeof(x));

		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j)
				std::cin >> a[j];
			x[a[0]] += a[1] * a[2];
		}
		for (int i = 1; i <= 4000; ++i) {
			if (x[i] >= 1000000) {
				std::cout << i << std::endl;
				++count;
			}
		}
		if (count==0)
			std::cout << "NA" << std::endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std; 
#define pb push_back
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef vector<int> Vi;

int main()
{
  int n;
  while( cin >> n, n ) {
    int a, b, c;
    map<int, int> m;
    Vi v;
    bool flag = false;
    Rep(i, n) {
      cin >> a >> b >> c;
      if( m.find( a ) == m.end() ) {
	v.pb( a );
	m[a] = 0;
      }
      m[a] += b * c;
    }
    
    Rep(i, v.size()) {
      if( m[v[i]] >= 1000000 ) {
	cout << v[i] << endl;
	flag = true;
      }
    }

    if( !flag ) cout << "NA" << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<map>
#include<vector>
using namespace std;
typedef unsigned long long ll;
int main(){
  int n,val,num,inindex;
  vector<int> Index;
  map<int,ll> List;
  while(true){
    scanf("%d",&n);
    if(n == 0)break;
    List.clear();
    Index.clear();
    for(int i=0;i<n;i++){
      scanf("%d %d %d",&inindex,&val,&num);
      if(!List[inindex]){
	Index.push_back(inindex);
      }
      List[inindex]+=val*num;
    }
    bool NAf=true;
    for(int i=0;i<Index.size();i++){
      if(List[Index[i]] >= 1000000){
	printf("%d\n",Index[i]);
	NAf=false;
      }
    }
    if(NAf)printf("NA\n");
  }

  return 0;
}

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

int main(){
	int N;
	
	while(cin>>N,N){
		map<int,long long int> mp,mp2;
		vector <int> vi;
		priority_queue<int, vector<int>, greater<int> >pq;
		for(int i=0;i<N;i++){
			int num,tanka,suuryo;
			cin>>num>>tanka>>suuryo;
			mp[num]+=tanka*suuryo;
			vi.push_back(num);
			if(mp[num]>=1000000){
				mp2[num]++;
			}
		}
		vector<int>::iterator it=vi.begin();
		for(;it!=vi.end();it++){
			if(mp2[*it]>=2){
				mp2[*it]--;
			}
			else if(mp2[*it]==1){
				pq.push(*it);
				mp2[*it]--;
			}
		}
		if(pq.empty()){
			cout<<"NA"<<endl;
		}
		else{
			int len=pq.size();
			for(int i=0;i<len;i++){
				cout<<pq.top()<<endl;
				pq.pop();
			}
		}
	}
	return 0;
}

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

typedef unsigned long long int ull;

map<ull,ull> mp;

int main() {
  int n;
  
  while(cin>>n, n) {
    mp.clear();
    
    for(int i=0; i<n; i++) {
      ull a;
      ull b, c;
      cin >> a >> b >> c;
      mp[a] += b * c;
    }
    bool isExist = false;
    for(map<ull, ull>::iterator it = mp.begin(); it!=mp.end(); it++) {
      if( it->second >= 1000000 ) {
	isExist = true;
	cout << it->first << endl;
      }
    }
    if( !isExist ) cout << "NA" << endl;
  }
  
  return 0;
}

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

static const int invalid_order = 1000000;
struct data {
	int ID;
	long total;
	int order;
	bool f;

	data() {
		ID = -1;
		total = 0;
		order = invalid_order;
		f = false;
	}

	data(int n) {
		ID = n;
		total = 0;
		order = invalid_order;
		f = false;
	}

	bool operator<(const data d) const {
		return order < d.order;
	}
};

int main() {
	int n;

	while(cin >> n, n) {
		int ID, price, sale;
		data table[4096];
		bool flag = false;
		int order_count = 0;

		for(int i = 0; i < 4096; i++) {
			table[i].ID = i;
		}

		for(int i = 0; i < n; i++) {
			char in[128];
			char ID_s[32], price_s[32], sale_s[32];
			int j, k;

			// input
			/*
			fgets(in, 120, stdin);
			for(j = 0,k = 0; in[j + k] != ' ' && in[j + k] != ';'; k++)
				ID_s[k] = in[j + k];
			ID_s[k] = '\0';
			j = k + 1;
			for(k = 0; in[j + k] != ' ' && in[j + k] != ';'; k++)
				price_s[k] = in[j + k];
			price_s[k] = '\0';
			j += k + 1;
			for(k = 0; in[j + k] != ' ' && in[j + k] != ';' && in[j + k] && in[j + k] != '\n'; k++)
				sale_s[k] = in[j + k];
			sale_s[k] = '\0';

			ID = atoi(ID_s);
			price = atoi(price_s);
			sale = atoi(sale_s);
			// */ cin >> ID >> price >> sale;
			
			if(table[ID].order == invalid_order) {
				table[ID].order = order_count;
				order_count++;
			}

			table[ID].total += price * sale;
			if(table[ID].total >= 1000000 && !table[ID].f) {
				cout << ID << endl;
				flag = true;
				table[ID].f = true;
			}
		}

		/*
		sort(table, table + 4096);

		for(int i = 0; i < 4000; i++) {
			if(table[i].total >= 1000000) {
				cout << table[i].ID << endl;
				flag = true;
			}
		}
		*/

		if(!flag)
			cout << "NA" << endl;
	}

	return 0;
}