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>
using namespace std;

int main() {
	int max,n;
	vector<int> id;
	vector<int> sum;
	vector<int> table;
	
	id.resize(4000);
	sum.resize(4000);
	table.resize(4000);
	
	while(cin>>n,n){
		int i,a,b,f;
		max = 0;
		
		for(int j=0;j<4000;++j){
			id[j] = 0;
			sum[j] = 0;
			table[j] = 0;
		}
		
		for(;n;--n){
			cin>>i>>a>>b;
			
			if(table[i-1]==0){
				id[max]=i;
				table[i-1] = max+1;
				++max;
			}
			if(sum[table[i-1]-1]<1000000)sum[table[i-1]-1] += a*b;
			
		}
		f=0;
		for(int j=0;j<max;++j){
			if(sum[j]>=1000000){
				cout<<id[j]<<endl;
				f=1;
			}
		}
		if(!f)cout<<"NA"<<endl;
	}
	return 0;
}

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

#define SHINE_MAX 4000
#define ELITE 1000000
#define AHO "NA"

int shineN,eliteN;
int shineU[SHINE_MAX];	//?£??????????

int num,tanka,suryo;
int i;

int main(){
	while(1){
	 cin>>shineN;
	 if(shineN==0){break;}
	 for(i=0;i<SHINE_MAX;i++){shineU[i]=0;}
	 for(i=0;i<shineN;i++){
	  cin>>num,tanka,suryo;
	  shineU[num]+=tanka*suryo;
	 }
	 //??¨?????????????????¨
	 eliteN=0;
	 for(i=0;i<SHINE_MAX && eliteN<shineN;i++){
	  if(ELITE<=shineU[i]){
	   cout<<i<<endl;
	   eliteN++;
	  }
	 }
	 if(eliteN==0){cout<<AHO<<endl;}
	}
	return 0;
}

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

using namespace std;

vector<int> erase_equal(vector<int> v) {
	vector<int> result;
	map<int, bool> mp;
	for (int i = 0; i < v.size(); i++) {
		auto itr = mp.find(v[i]);
		if (itr == mp.end()) {
			mp[v[i]] = true;
			result.push_back(v[i]);
		}
	}
	return result;
}

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) {
			break;
		}

		map<int, long long> sales;
		vector<int> ids(n);
		for (int i = 0; i < n; i++) {
			int id;
			int sale_val;
			int sale_num;
			cin >> id;
			cin >> sale_val;
			cin >> sale_num;

			ids.push_back(id);
			auto itr = sales.find(id);
			if (itr != sales.end()) {
				sales[id] += (long long)sale_val * (long long)sale_num;
			} else {
				sales[id] = (long long)sale_val * (long long)sale_num;
			}
		}

		vector<int> v = erase_equal(ids);
		bool na_flag = true;
		for (int i = 0; i < v.size(); i++) {
			if (sales[v[i]] >= 1000000) {
				cout << v[i] << endl;
				na_flag = false;
			}
		}
		if (na_flag) {
			cout << "NA" << endl;
		}
	}
}

C++: //AOJ 0100
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;
#define MAX_N 100

unsigned long long int a[4001] = {0}, b, i, j, k, ans, n;
char str[1000];

int sort(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}

int main(){
  while(scanf("%lld", &n) != 0){
    if(n == 0) return 0;
    ans = 0;
    for(i = 0; i < 4001; i++)
      a[i] = 0;
    for(i = 0; i < n; i++){
      scanf("%lld %lld %lld", &b, &k, &j);
      if(a[b] >= 1000000) continue;
      a[b] += k * j;
      if(a[b] >= 1000000){
	printf("%lld\n", b);
	ans++;
      }
    }
    if(ans == 0) printf("NA\n");
  }
  return 0;
}

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

typedef long long ll;

map<int,ll> mp;
vector<ll> v;

int main() {
  int n;
  
  while( cin>>n && n ) {
    mp.clear();
    
    for( int i=0; i<n; i++ ) {
      int a;
      ll b, c;
      cin >> a >> b >> c;
      if( !mp[a] )v.push_back( a );
      mp[a] += b * c;
    }

    bool isExist = false;
    for( int i=0; i<v.size(); i++ ) {
      if( mp[v[i]] >= 1000000 ) {
	isExist = true;
	cout << v[i] << endl;
      }
    }
    if( !isExist ) cout << "NA" << endl;
  }
  
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(void)
{
    int n,A,sult[4001],sell[4001],suu[4001];
    while(1){
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>sult[i]>>sell[i]>>suu[i];
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i!=j&&sult[i]==sult[j]&&sell[i]!=0&&sell[j]!=0){
                    sell[i]=sell[i]*suu[i]+sell[j]*suu[j];
                    suu[i]=1;
                    sell[j]=0;
                }
            }
        }
        for(int i=0;i<n;i++){
            if(sell[i]*suu[i]>=1000000){
                    cout<<sult[i]<<"\n";
                    A=1;
            }
        }
        if(A==0)cout<<"NA\n";
        A=0;
    }
}

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

ll worker[4001];

int main() {
  int n, id;
  long long p, q;
  bool isNA = 1;
  
  while(cin >> n && n) {

	worker[4001] = {0};
	for(int i = 0; i < n; ++i) {
	  cin >> id >> p >> q;
	  if(worker[id] < 1000000 && worker[id] + p*q >= 1000000) {
		cout << id << endl;
		isNA = 0;
	  }
	  worker[id] += p * q;
	}
  }
  
  if(isNA) {
	cout << "NA" << endl;
  }

  return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

int main() {

  int n;
  while (cin >> n, n) {
    int xs[4002];
    calloc(sizeof(xs), sizeof(int));
    vector<int> order;
    rep (i, n) {
      int a,b,c; cin >> a >> b >> c;
      xs[a] = min(1000000, xs[a] + b * c);
      order.push_back(a);
    }
    bool bl = true;
    for (int id : order) {
      if (xs[id] >= 1000000) {
        cout << id << endl;
        bl = false;
        xs[id] = 0;
      }
    }
    if (bl) {
      cout << "NA" << endl;
    }
  }

  return 0;
}

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

int main() {
	int n;
	std::cin >> n;
	while (n != 0) {
		bool flag{ true };
		std::vector<int> crue(4000 + 1, 0);
		std::queue<int> order;
		for (auto i = 0; i < n; ++i) {
			int id, value, size;
			std::cin >> id >> value >> size;
			if (crue.at(id) == 0) {
				order.push(id);
			}
			crue.at(id) += value * size;
		}
		while (order.size() != 0) {
			if (crue.at(order.front()) >= 1000000) {
				std::cout << order.front() << "\n";
				flag = false;
			}
			order.pop();
		}
		if (flag) {
			std::cout << "NA\n";
		}
		std::cin >> n;
	}
	return 0;
}