Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}
		sales := make(map[string]int)
		existed := make(map[string]bool)
		order := make([]string, 4000)
		flg := false
		for i := 0; i < n; i++ {
			stdin.Scan()
			l := strings.Split(stdin.Text(), " ")
			e := l[0]
			p, _ := strconv.Atoi(l[1])
			q, _ := strconv.Atoi(l[2])
			sales[e] += p * q
			if !existed[e] {
				order = append(order, e)
				existed[e] = true
			}
		}
		for _, v := range order {
			if sales[v] >= 1000000 {
				fmt.Println(v)
				flg = true
			}
		}
		if flg == false {
			fmt.Println("NA")
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <time.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef int ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=1e+5 + 1;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=1e+9 + 7;

int main() {
	int n;
	while(cin >> n && n){
		bool check[4096] = {0};
		LL sum[4096] = {0};
		vector<int> data;
		REP(i,n){
			LL id, money, num; 
			scanf("%lld%lld%lld", &id, &money, &num);
			if(!check[id]){
				check[id] = true;
				data.PB(id);
			}
			sum[id] += money * num;
		}
		bool ok = false;
		REP(i,data.size()){
			if(sum[data[i]] >= 1000000){
				printf("%d\n", data[i]);
				ok = true;
			}
		}
		if(!ok)
			cout << "NA" << endl;
	}
	return 0;
}

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

using namespace std;

int main(void){

	int n,flag,number;
	long double money,sum;
	int data[4001]={0},dataF[4001]={0};
	queue<int> ok;

	while(1){

		for(int i=0;i<4000;i++) data[i]=0,dataF[i]=0;
		flag=0;

		cin>>n;
		if(n==0) break;

		for(int i=0;i<n;i++){
			cin>>number>>money>>sum;
			data[number]+=money*sum;
			if(dataF[number]==0){
				dataF[number]=1;
				ok.push(number);
			}
		}
			while(!ok.empty()){
				if(data[ok.front()]>=1000000){
					cout<<ok.front()<<endl;
					flag=1;
				}
				ok.pop();
			}
			if(flag==0) cout<<"NA"<<endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


struct man{
  int num;
  int money;
};

int main()
{
  int n;
  while(true)
    {
      cin>>n;
      if(n==0)
	exit(0);
      vector<man> d;
      d.clear();
      for(int i=0;i<n;i++)
	{
	  int num,a,b;
	  bool ch=false;
	  cin>>num;
	  cin>>a;
	  cin>>b;
	  for(int j=0;j<d.size();j++)
	    {
	      if(d[j].num==num)
		{
		d[j].money=d[j].money+a*b;
		ch=true;
		break;
		}
	    }
	  if(ch==false)
	    {
	      struct man x;
	      x.num=num;
	      x.money=a*b;
	      d.push_back(x);
	    }
	}

      int count=0;
      for(int j=0;j<d.size();j++)
	if(d[j].money>=1000000)
	  {
	    cout<<d[j].num <<endl;
	    //    cout<<d[j].num << "   "<< d[j].money<<endl;
	    count++;
	  }
      if(count<1)
	cout<<"NA"<<endl;

    }
}

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;
		vector<int> nums;

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

			if ( tmp[ no ] == 0 )
			{
				nums.PB( no );
			}

			tmp[no] += price * num;
		}

		bool flag = false;

		REP( i, 0, nums.size() )
		{
			if ( 1000000 <= tmp[ nums[i] ] )
			{
				cout << nums[i] << endl;
				flag = true;
			}
		}

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

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	ll u[4010];
	vector<int> v;
	bool k;
	while(1)
	{
		for(int i=0;i<4010;i++)
		{
			u[i]=0;
		}
		k=true;
		int n;
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			int x,y,z;
			cin >> x >> y >> z;
			u[x]+=(ll)y*(ll)z;
		}
		for(int i=0;i<4010;i++)
		{
			if(u[i]>=1000000)
			{
				k=false;
				cout << i << endl;
			}
		}
		if(k)
		{
			cout << "NA" << endl;
		}
	}
	return 0;
}

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;
    set<pair<int,int> > S;
    map<int,int> mii;

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

        rep(i,n){
            cin >> num >> tanka >> count;
            if( mii.count(num) == 0 ){
                mii[num] = i;
            }
            if( (ll)tanka * (ll)count >= 1000000 && S.count(make_pair(mii[num],num)) == 0 ){
                S.insert(make_pair(mii[num],num));
            }
        }

        if( S.size() == 0 ){
            puts("NA");
        }
        else{
            foreach(it,S){
                printf("%d\n",it->second);
            }
        }
    }

    return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
main(){
  int n,i,l,a,k,u,s[4000];
  while(1){
    cin >> n;
    if(n==0){
      break;
    }
    l=0;
    for(i=0;i<n;i++){
      cin >> a >> k >> u;
      if(1000000<=k*u){
	s[l]=a;
	l++;
      }
    }
    if(l==0){
      cout << "NA" << endl;
    }
    else{
      for(i=0;i<l;i++){
	cout << s[i] << endl;
      }
    }
  }
}