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 <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int main()
{
	while ( true )
	{
		int n;
		cin >> n;

		if ( n == 0 )
		{
			break;
		}

		map<int, ull> tmp;

		REP( i, 0, n )
		{
			int no, price, num;
			cin >> no >> price >> num;

			tmp[no] += price * num;
		}

		VI res;

		IREP( tmp, it )
		{
			if ( 1000000 <= (*it).snd )
			{
				res.PB( (*it).fst );
			}
		}

		if ( res.size() == 0 )
		{
			cout << "NA" << endl;
		}
		else
		{
			for ( int &no : res )
			{
				cout << no << endl;
			}
		}
	}

	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<functional>
#define inf 1000000
using namespace std;
long long int p[114514],x,y,z,w;
int main(void)
{
	int i,j,k,f,n,cnt;
	while(1) {
		cin>>n;
		f=0,cnt=0;
		if(!n)break;
		for(i=0;i<4001;i++) p[i]=0;
		for(i=0;i<n;i++) {
			cin>>x>>y>>z;
			if(p[x]>=inf) continue;
			p[x]+=y*z;
			if(p[x]>=inf) f=1,cout<<x<<endl;
		}
		if(f==0) cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct{
    int id;
    long long int cost;
    long long int amount;
    long long int sum;
}employee;

int main(){
    long long int n;
    while(cin >> n,n){
        employee getinp;
        vector<employee> emps;
        for (int i=0;i<n;i++){
            cin >> getinp.id >> getinp.cost >> getinp.amount;
            getinp.sum=getinp.cost*getinp.amount;
            if(emps.empty()) emps.push_back(getinp);
            else{
                for(int j=0;j<emps.size();j++){
                    if(emps[j].id==getinp.id) {
                        emps[j].sum+=getinp.sum;
                        break;
                    }else if(j==emps.size()-1){
                        emps.push_back(getinp);
                        break;
                    }
                }
            }
        }
        int* ids=new int[emps.size()];
        int j=0;
        for (int i=0;i<emps.size();i++){
            if (emps[i].sum>=1000000){
                ids[j]=emps[i].id;
                j++;
            }
        }
        sort(ids,ids+j);
        if(j==0) cout << "NA" << endl;
        else{
            for(int i=0;i<j;i++){
                cout<<ids[i]<<endl;
            }
        }
        delete ids;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int  existnum(vector<int> v,int e){
    for(int i=0;i<v.size();i++){
        if(v[i]==e)return i;
    }
    return -1;
}

int main(void){
    int n,b=0,e,p,q,num;
    vector<int> se,sp,sq;
    while(1){
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>e;
            cin>>p;
            cin>>q;
            if((num=existnum(se,e))!=-1){
                sp[num]+=p;
                sq[num]+=q;
            }else{
                se.push_back(e);
                sp.push_back(p);
                sq.push_back(q);
            }
        }
        for(int i=0;i<n;i++){
            if(sp[i]*sq[i]>=1000000){
                cout<<se[i]<<endl;
                b=1;
            }
        }
        if(b==0){
            cout<<"NA"<<endl;
        }
        sp.clear();
        se.clear();
        sq.clear();
        b=0;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
 
using namespace std;
 
const long long Target = 1000000;
 
struct Shain {
    int no;
    long long sum;
};
 
int main( void )
{
    vector<Shain> shain;
    long long n;
    while(cin >> n, n) {
        shain.clear();
        while(n--) {
            long long no, kin, num;
            cin >> no >> kin >> num;
            bool hit = false;
            vector<Shain>::iterator it = shain.begin();
            while(it != shain.end()) {
                if(it->no == no) {
                    it->sum += (kin * num);
                    hit = true;
                    break;
                }
                ++it;
            }
            if(!hit) {
                Shain tmp;
                tmp.no = no;
                tmp.sum = (kin * num);
                shain.push_back(tmp);
            }
        }
        bool hit = false;
        vector<Shain>::iterator it = shain.begin();
        while(it != shain.end()) {
            if(it->sum >= Target) {
                cout << it->no << endl;
                hit = true;
            }
            ++it;
        }
        if(!hit)
            cout << "NA" << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define fr first
#define sc second
#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 pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
typedef pair<string, int> Psi;
typedef vector<int> Vi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

int main()
{
  int n;
  while( cin >> n, n ) {
    int a, b, c;
    map<ll, ll> m;
    vector<ll> 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;
  }
}