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>

using namespace std;

int main(void){
  long long x,emp[4001],val[4001];
  long long emp1,val1,con,flag;

  while(1){
    cin >> x;
    if(x==0)break;

    for(int i=0;i<4001;i++){
      emp[i]=0;
      val[i]=0;
    }
    for(int i=0;i<x;i++){
      cin >> emp1 >> val1 >> con;

      flag=0;
      for(int j=0;j<x;j++){
	if(emp[j]==emp1){
	  flag=1;
	  val[j]+=val1*con;
	  break;
	}
      }
      if(flag==0){
	for(int j=0;j<4001;j++){
	  if(emp[j]==0){
	    emp[j]=emp1;
	    val[j]=val1*con;
	    break;
	  }  
	}
      }
    }
      flag=0;
    for(int j=0;j<4001;j++){
      if(val[j]>=1000000){
	cout << emp[j] << endl;
	flag=1;
      }
    }
    if(flag==0)cout << "NA" << endl;
  }
  return 0;
}

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

const long long BORDER = 1000000;

using namespace std;

int main() {
  bool f;
  int i, j, n, number;
  long long price, amount;

  while(cin >> n) {
    if (n == 0) break;
    
    map<int, long long> sales;
    map<int, long long>::iterator it;

    for (i = 0; i < n; i++) {
      cin >> number >> price >> amount;
      it = sales.find(number);
      if (it != sales.end())
        it->second += price * amount;
      else
        sales.insert(pair<int, long long>(number, price * amount));
    }

    for (it = sales.begin(), f = false; it != sales.end(); it++) {
      if (it->second >= BORDER) {
        f = true;
        cout << it->first << endl;
      }
    }
    if (!f) cout << "NA" << endl;
  }

  return 0;
}

C++: #include<iostream>

int main(){
	int n,num[4001];
	while(std::cin>>n){
		int count=0;
		memset(num,0,sizeof(num));
		if(n==0)break;
		for(int a,b,c,i=0;i<n;i++){
			std::cin>>a>>b>>c;
			num[a]+=b*c;
		}
		for(int i=0;i<4001;i++){
			if(num[i]>=1000000)count++,std::cout<<i<<std::endl;
		}
		if(count==0)std::cout<<"NA"<<std::endl;
	}
	return 0;
}

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

int n;
int main(){
	while((cin >> n) != 0){
		int num = 0;
		vector<pair<int, int> > pairs(n);

		for(int i = 0; i < n; i++){
			int p, q;
			cin >> pairs[i].first >> p >> q;
			pairs[i].second = p * q;
		}

		sort(pairs.begin(), pairs.end());

		int sum = 0;
		sum = pairs[0].second;
		for(int i = 1; i < n; i++){
			if(pairs[i].first == pairs[i-1].first){
				sum += pairs[i].second;
			}else{
				if(sum >= 1000000){
					cout << pairs[i].first << "\n";
					num++;
				}
				sum = pairs[i].second;
			}
		}

		if(num == 0){
			cout << "NA\n";
		}
	}
	
    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++){
			long long 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>
#include <vector>

int main(){
  int n;
  while(std::cin>>n){
    if(!n)return 0;
    std::vector<int> v;
    long int team,price,number;
    for(;n;n--){
      std::cin>>team>>price>>number;
      if(price*number>=1000000)v.push_back(team);
    }
    if(v.empty())std::cout<<"NA"<<std::endl;
    else{
      std::vector<int>::iterator it = v.begin();
      while(it!=v.end()){
        std::cout<<*it<<std::endl;
        it++;
      }
    }
  }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

/*
  AOJ :: 0100
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0100&lang=jp
 */

typedef long long ll;

int main(){
    int n,num,tanka,count,i;
    map<int, pair<int,ll> > mipii;

    while( cin >> n, n ){
        // init
        mipii.clear();

        // input
        rep(i,n){
            cin >> num >> tanka >> count;

            if( mipii.count(num) == 0 ){
                mipii[num] = make_pair(i, (ll)tanka * (ll)count);
            }
            else{
                pair<int,ll> tmp = mipii[num];
                tmp.second = max(tmp.second, (ll)tanka * (ll)count);
                mipii[num] = tmp;
            }
        }

        vector<pair<int,int> > vp;
        foreach(it,mipii){
            if( it->second.second >= 1000000 ){
                vp.push_back(make_pair(it->second.first, it->first));
            }
        }
        sort(all(vp));

        if( vp.size() == 0 ){
            puts("NA");
        }
        else{
            rep(i,vp.size()){
                printf("%d\n",vp[i].second);
            }
        }
    }

    return 0;
}

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

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) return 0;
        vector<int> id;
        // create vector the number of element is 4001
        // initialize all elements with -1
        vector<long long> sale(4001, -1);
        int x, y, z;

       for (int i=0; i < n; i++) {
           cin >> x >> y >> z;
           if (sale[x] == -1) {
               sale[x] = 0;
               id.push_back(x);
           }
           sale[x] += (long long) y * z;
       }
       bool na = true;
       for (int i=0; i < (int)id.size(); i++){
           if (sale[id[i]] >= 1000000) {
               cout << id[i] << endl;
               na = false;
           }
       }
       if (na) cout << "NA" << endl;
    }
}