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 <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<long long> sale(4001, -1);
        vector<int> id;

        for(int i=0; i<n; ++i){
            int a, b, c;
            cin >> a >> b >> c;
            if(sale[a] == -1){
                sale[a] = 0;
                id.push_back(a);
            }
            sale[a] += (long long)b * c;
        }


        bool na = true;
        for(unsigned i=0; i<id.size(); ++i){
            if(sale[id[i]] >= 1000000){
                cout << id[i] << endl;
                na = false;
            }
        }
        if(na)
            cout << "NA" << endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,b,t,s;
  while(cin>>n){
    if(n==0) break;
    int h[4000];
    int index = 0;
    int h2 = 0;
    long long int p[4001]={0};
    for(int i=0;i<n;i++){
      cin >> b >> t >> s;
      if(p[b]==0){
	h[index] = b;
	index++;
      } 
      p[b] += t * s;
    }
    /*for(int i=0;i<index;i++){
      cout << p[h[i]] << endl;
      cout << h[i] << endl;
      }*/
    for(int i=0;i<index;i++){
      if(p[h[i]]>=1000000){
	cout << h[i] << endl;
	h2 = 1;
      }
    }
    if(h2==0) cout << "NA" << endl;
    //cout << endl;
  }
  return 0;
}

C++: #include <stdio.h>

int member[4010][3] ;

int main ( )
{
	int n ; 
	bool na = false ;
	while ( scanf ( "%d" , &n ) == 1 && n ){
		na = false ;
		for ( int i = 0 ; i < n ; i++ ){
			scanf ( "%d %d %d" , &member[i][0] , &member[i][1] , &member[i][2] ) ;
			int tmp = member[i][1] * member[i][2] ;
			if ( tmp > 1000000 ){
				printf ( "%d\n" , member[i][0] ) ;
				na = true ;
			}
		}
		if ( ! na ){
			printf ( "NA\n" ) ;
		}
	}
	return 0 ;
}

C++: #include<iostream>

using namespace std;

int main(void){
	int n;
	int a,b,c,d;
	int num[4001],tan[4001];
	bool flag=false;
	while(1){
		for(a=0;a<=4000;a++){
			num[a]=0;
			tan[a]=0;
		}
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> b >> c >> d;
			num[b]+=c,tan[b]+=d;
		}
		for(a=1;a<4000;a++){
			if(num[a]*tan[a]>=1000000)printf("%d\n",a),flag=true;
		}
		if(flag==false)printf("WA\n");
	}
	return 0;
}

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;
}