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<bits/stdc++.h>
using namespace std;

int main(){
  long long int nin;
  while(1){ 
    scanf("%d",&nin);
    if(!nin)break;

    long long int human[4002]={0};
    long long int no[4002],tanka,kazu,outflag=0;
    
    for(int i=0;i<nin;i++){
      scanf("%d %d %d",&no[i],&tanka,&kazu);
      human[no[i]]+=tanka*kazu;
    }
    
    for(int i=0;i<nin;i++){
      if(human[no[i]]>=1000000 && human[no[i]]!=-1){
	printf("%d\n",no[i]);
	human[no[i]]=-1;
	outflag=1;
      }
    }
    
    if(outflag==0)printf("NA\n");
    
  }
}

C++: #include<stdio.h>

int main(){
  while(1){
    int n;
    scanf("%d", &n);
    if(n!=0){
      int i,k;
      int a, b, c;
      int j=0;
      int d[4001]={};
      double e[4001] ={};
      int flag = 0;
      for(i=0;i<n;i++){
	scanf("%d %d %d", &a, &b, &c);
	int flag1=0;
	for(k=0;k<j;k++){
	  if(d[k]==a)
	    flag1=1;
	}
	if(flag1==0)
	  {d[j]=a;j++;}

	//if(e[a]+b*c<=2147483647)
	e[a]=e[a]+(double)b*(double)c;
	//else
	  //e[a]=(double)2147483647;//printf("aa\n");
	
      }


      for(i=0;i<4001;i++){
	if(e[d[i]]>=1000000.){
	  printf("%d\n", d[i]);
	  flag++;
	}
      }
      if(flag==0)
	printf("NA\n");
      
    }
    else{
      break;
    }
  }
  return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int N = 4000;
int n;
ll cost[N];
int id;
ll dc, dn;

int main()
{
  while((cin >> n) && n){
    bool flag = true;
    rep(i, N) cost[i] = 0LL;

    rep(i, n){
      cin >> id >> dc >> dn;
      cost[id-1] += dc * dn;
    }

    rep(i, N) if(cost[i] >= 1000000){
      flag = false;
      cout << i + 1 << endl;
    }
    if(flag) puts("NA");
  }

  return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
#define MAX_N 1000000
long long x[MAX_N], a, b, c, n, cnt;
int main() {
	while (1) {
		memset(x, 0, sizeof(x)); cnt = 0;
		cin >> n; if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			x[a] += b*c;
			if (x[a] >= 1000000) { cout << a << endl; cnt++; }
		}
		if (cnt == 0) { cout << "NA" << endl; }
	}
}

C++: 
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef unsigned long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()


int main(void){
	int n;	
	while(cin>>n,n){
		vector<vector<ll> > num(n,vector<ll>(3,0));
		rep(i,n){
			//cout<<num[i][0]<<" "<<num[i][1]<<endl;
			cin>>num[i][0];
			int item,code;
			rep(j,i){
				if(num[i][0]==num[j][0]){
					num[j][1]+=item*code;
					num[i][2]=1;
				}
			}
			cin>>item>>code;
			if(!num[i][2])num[i][1]+=item*code;
		}
		//cout<<"star"<<endl;
		int cnt=0;
		rep(i,n){
			if(num[i][1]>=1000000){cout<<num[i][0]<<endl;cnt++;}
		}
		if(!cnt)cout<<"NA"<<endl;
		//cout<<"NO"<<n<<endl<<endl;;
	}
}

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

typedef long long ll;

map<int,ll> mp;

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;
      mp[a] += b * c;
    }
    bool isExist = false;
    for(map<int, ll>::iterator it = mp.begin(); it!=mp.end(); it++) {
      if( it->second >= 1000000 ) {
	isExist = true;
	cout << it->first << endl;
      }
    }
    if( !isExist ) cout << "NA" << endl;
  }
  
  return 0;
}

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

using namespace std;


int main() {
	int n;
	int name, price, number;
	map<int, long long> m_Employee;

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

		for (int i = 0; i < n; i++) {
			cin >> name >> price >> number;

			if (m_Employee.count(name)) {
				m_Employee[name] += price * number;
			}
			else {
				m_Employee.insert(map<int, long long>::value_type(name, price*number));
			}
		}

		map<int, long long>::iterator it = m_Employee.begin();
		bool flag = false;
		while (it != m_Employee.end()) {
			if ((*it).second >= 1000000) {
				flag = true;
				cout << (*it).first << endl;
			}

			it++;
		}

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

		m_Employee.clear();
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    long long bangou,tanka,kosuu;
    long long number; cin >> number;
    long long kuso[number];
    do{
        long long man[4000];
        for(int i=0;i<4000;i++){
            man[i]=0;
        }
        for(int i=0;i<number;i++){
            kuso[i]=0;
        }

        for(int i=0;i<number;i++){
            cin >> bangou >> tanka >> kosuu;
            man[bangou-1] += tanka*kosuu;
            kuso[i]=bangou;
        }
        int count =0;
        if(man[kuso[0]-1]>=1000000){
            cout << kuso[0] << endl;
            count++;
        }
        for(int i=1;i<number;i++){
            int tmp =0;
            for(int j=0;j<i;j++){
                if(kuso[i]==kuso[j]){
                    tmp++;
                    break;
                }
            }
            if(tmp==0 && man[kuso[i]-1]>=1000000){
                cout << kuso[i] << endl;
                count++;
            }
        }
        if(count==0)
            cout<< "NA" << endl;
        cin >> number;
    }while(number !=0);

}

C++: #include<stdio.h>
#include<list>
class hoge{
 public:
  int num;
  int v;
  hoge(int n,int va){
    num=n;
    v=va;
  }
};


int main(){
  using namespace std;
  int i,n,v,c,num,flg;
  list<hoge> ls;
  list<hoge>::iterator pos;
  do{
    scanf("%d",&n);
    if(!n) break;
    for(i=0;i<n;i++){
      scanf("%d %d %d",&num,&v,&c);
      pos=ls.begin();
      while(pos!=ls.end()){
	if((*pos).num==num){
	  (*pos).v+=v*c;
	  break;
	}
	pos++;
      }
      if(pos==ls.end()){
	pos=ls.begin();
	while(pos!=ls.end()){
	  if((*pos).num>num){
	    ls.insert(pos,*(new hoge(num,v*c)));
	    break;
	  }
	  pos++;
	}
	if(pos==ls.end()){
	  ls.push_back(*(new hoge(num,v*c)));
	}
      }
    }
    pos=ls.begin();
    flg=1;
    while(pos!=ls.end()){
      if((*pos).v>=1000000){
	printf("%d\n",(*pos).num);
	flg=0;
      }
      pos++;
    }
    if(flg) printf("NA\n");
    ls.clear();
  }while(1);
  return 0;
}