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<algorithm>
#include<vector>
int main() {
	std::vector<int> v;
	while (1) {
		int count=0;
		int n;
		std::cin >> n;
		if (n == 0) {
			break;
		}
		std::vector<std::vector<int>> a(n, std::vector<int>(3));
		
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j) {
				std::cin >> a[i][j];
			}
		}
		std::vector<int>num(n);
		for (int i = 0; i < n; ++i) {
			for (int j = 1; j < n; ++j) {
				if (a[i][0] == a[j][0]) {
					num[i] += a[i][1] * a[i][2] + a[j][1] * a[j][2];
					++count;
					break;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			if (count == 0) {
				v.push_back(0);
			}
			if (num[i] >= 1000000) {
				if (count >= 2) {
					sort(num.begin(), num.end());
				}
				v.push_back(num[i]);
			}
		}
	}
	for (int i = 0; i < v.size(); ++i) {
		if (v[i] == 0) {
			std::cout << "NA" << std::endl;
		}
		else {
			std::cout << v[i] << std::endl;
		}
	}
	return 0;
}

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

using namespace std;

typedef unsigned long long ll;

ll data[4001];
vector<int> V;

void print(){
  vector<int> M;
  for(int i = 0; i < 4001; i++)
    if(data[i] >= 1000000) M.push_back(i);
  if(M.size()){
    for(int i = 0; i < V.size(); i++)
      if(binary_search(M.begin(),M.end(),V[i])) cout << V[i] << endl;
  }else cout << "NA" << endl;
}
int main(){
  ll in;
  while(cin >> in && in){
    V.clear();
    vector<int> VC;
    fill(data,data+4001,0);
    for(int i = 0; i < in; i++){
      sort(VC.begin(), VC.end());
      ll num,p,q;
      cin >> num >> p >> q;
      if(!binary_search(VC.begin(),VC.end(),num)){
	V.push_back(num);
	VC.push_back(num);
      }
      if(data[num] < 1000000) data[num] += p*q;
    }
    print();
  }
  return 0;
}

C++: /*Kim Jong Il*/
#include<iostream>
#include<cstdio>
#define N1 4000
using namespace std;

int main(){
  int n,id[N1],array[N1][N1],i,j,count;
  
  while(1){
    count = 0;
    cin >> n;
    if(n == 0)break;
    
    for(i=0;i<n;i++){
      cin >> id[i];
      for(j=0;j<2;j++){
	cin >> array[i][j];
      }
    }
    for(i=0;i<n;i++){
      if(array[i][0] * array[i][1] >= 1000000){
	cout << id[i] << endl;
	count++;
      }
    }
    if(count == 0)cout << "NA" << endl;   
  }
}

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

int main(){
	int n;
	int p[4000];
	int count;
	
	while(cin>>n,n){
		for(int i=0;i<4000;++i)p[i]=0;
		
		for(int i=0;i<n;++i){
			int wn,va,cn;
			cin>>wn>>va>>cn;
			p[wn-1] += va*cn;
		}
		count = 0;
		for(int i=0;i<4000;++i){
			if(p[i] >= 1000000){cout<<i+1<<endl;count++;}
		}
		if(!count)cout<<"NA"<<endl;
		
		
		
		
		
	}
	
	
	
}

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

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


int n, p;
long long a, b;
long long tot[10000];

int main() {
    while (cin >> n) {
        if (n == 0) break;
        memset(tot, -1, sizeof(tot));
        vector<int> sya;
        for (int i = 0; i < n; ++i) {
            cin >> p >> a >> b;
            if (tot[p] == -1) {
                sya.PB(p);
                tot[p] = 0;
            }
            tot[p] += a*b;      
        }
        int con = 0;
        for (int i = 0; i < sya.size(); ++i) {
            if ( tot[sya[i]] >= 1000000) {
                cout << sya[i] << endl;
                ++con;
            }
        }
        if (con == 0) puts("NA");
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
	int n;
	int e[1000];
	int p[1000];
	int q[1000];
	int total[1000];
	while (scanf("%d", n) != 0) {
		e[1000] = { 0 };
		p[1000] = { 0 };
		q[1000] = { 0 };
		total[1000] = { 0 };
		for (int i = 0; i < n; i++) {
			scanf("%d%d%d", e[i], p[i], q[i]);
			total[i] = p[i] * q[i];
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i != j && e[i] == e[j]) {
					total[i] += total[j];
					total[j] = 0;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			if (total[i] >= 1000000)printf("%d\n", e[i]);
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    int n; cin >> n;
    do {
        int e[n], p[n], q[n];
        ll tmp[4010] = {};
        int flag = 0;
        rep(i, n) cin >> e[i] >> p[i] >> q[i];
        for (int i = 0; i < n; i++) {
            tmp[e[i]] += p[i] * q[i];
        }
        for (int i = 0; i < 4010; i++) {
            if (tmp[i] >= 1000000) {
                cout << i << endl;
                flag = 1;
            }
        }
        if (flag == 0) cout << "NA" << endl;
        cin >> n;
    } while(n != 0);

    return 0;
}

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

struct data{
    int id;
    long long int sales;
    data(int a, long long int b) : id(a), sales(b) {}
    bool operator<( const data& o ) const{
        return id < o.id;
    }
};

int main(){
    int n;
    while( cin >> n, n ){
        vector< data > ls;
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> a >> b >> c;
            vector<data>::iterator it = ls.begin();
            for(; it != ls.end(); it++){
                if( it->id == a ){
                    it->sales += b*c;
                    break;
                }
            }
            if( it == ls.end() ){
                ls.push_back( data(a, b*c) );
            }
        }
        bool exs = false;
        for(vector<data>::iterator it = ls.begin(); it != ls.end(); it++){
            if( it->sales >= 1000000 ){
                cout << it->id << endl;
                exs = true;
            }
        }
        if( !exs ){
            cout << "NA" << endl;
        }
    }
    return 0;
}