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 <map>
using namespace std;
map<int,long long> sl;
int order[4000];
int main()
{
    int n;
    while(1)
    {
        cin>>n;if(!n)return 0;
        int count=0;
        int od=0;
        sl.clear();
        for(int i=0;i<n;++i){
            int sn;
            long long t,v;
            cin>>sn>>t>>v;
            map<int,long long>::iterator it=sl.find(sn);
            if(it==sl.end()){
                order[od++]=sn;
                sl.insert(make_pair(sn,t*v));
            }
            else it->second+=t*v;
        }
        for(int i=0;i<od;++i){
            if(sl[order[i]]>=1000000){cout<<order[i]<<endl;++count;}
        }
        if(!count)cout<<"NA"<<endl;
    }
}

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

struct data{
	int id;
	int value;
	int num;
};

int main(){
	int n;
	int need;
	while(cin >> n){
		if(n == 0) break;
		int count = 0;
		for(int i = 0; i < n; i++){
			data d;
			cin >> d.id >>
				d.value >> d.num;
			if(d.value){
				need = 1000000 % d.value == 0 ? 1000000 / d.value : 1000000 / d.value + 1;
				if(d.num >= need){
					cout << d.id << endl;
					count++;
				}
			}
		}
		if(!count) cout << "NA" << endl;
	}
	return 0;
}

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

int main(){
	int N;
	
	while(cin>>N,N){
		map<int,int> mp,mp2;
		vector <int> vi;
		priority_queue<int, vector<int>, greater<int> >pq;
		for(int i=0;i<N;i++){
			int num,tanka,suuryo;
			cin>>num>>tanka>>suuryo;
			mp[num]+=tanka*suuryo;
			vi.push_back(num);
			if(mp[num]>=1000000){
				mp2[num]++;
			}
		}
		vector<int>::iterator it=vi.begin();
		for(;it!=vi.end();it++){
			if(mp2[*it]>=2){
				mp2[*it]--;
			}
			else if(mp2[*it]==1){
				pq.push(*it);
				mp2[*it]--;
			}
		}
		if(pq.empty()){
			cout<<"NA"<<endl;
		}
		else{
			int len=pq.size();
			for(int i=0;i<len;i++){
				cout<<pq.top()<<endl;
				pq.pop();
			}
		}
	}
	return 0;
}

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



int main(){
	
	int n , id , price , num, cnt;
	while(1){
		vector<int> p(4001,0);
		vector<int> a;
		cin >> n;
		if(n==0) break;
		while(n--){
			cin>>id>>price>>num;
			if(find(a.begin(),a.end(),id)==a.end()) a.push_back(id);
			p[id]+=price*num;
			}
		cnt=0;	
		for(int i=0;i<a.size();i++){
			if(p[a[i]]>=1000000) cout << a[i] << endl; cnt++;
		}
		if (cnt==0) cout << "NA" << endl;
	}
		return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,num,mon,cont,a[4000],nacount;
  while(scanf("%d",&n)!=EOF){
    if(n==0){break;}
    for(int i=0;i<4000;i++){
      a[i]=0;
    }
    nacount=0;
    for(int i=0;i<n;i++){
      cin>>num>>mon>>cont;
      a[num]+=mon*cont;
    }
    for(int i=0;i<3999;i++){
      if(a[i]>=1000000){
	cout<<i<<endl;
	nacount++;
      }
    }if(nacount==0){
      cout<<"NA"<<endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<map>
using namespace std;
main(){
  //mlÛ¶vÛ¶
  long long a,b,c,n,f;
  //aÔbP¿cÊ
  while(cin>>n,n){
		map<int,long long> m;
		vector<int> v;
		f=1;
    for(;n;n--){
			cin>>a>>b>>c
      if(!m[a])v.push_back(a);
      m[a] += b*c;
    }
    
    for(int i=0;i<v.size();i++)
      if(m[v[i]]>999999)f=0;cout<<v[i]<<endl;
    if(f)cout<<"NA"<<endl;
  }
}

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

int num[4001][2];

int main(){
  int n,i,j,id,l,m;
  while(cin>>n){
    if(n==0)break;
    for(i=0;i<n;i++){
      cin>>id;
 	 if(num[id][0]==0){  
	   num[id][0]=id;  
	   cin>>num[id][0]>>num[id][1];}
	 else{
	   cin>>l>>m;
	   num[id][0]+=l;
	   num[id][1]+=m;
	 }
    }
    int c=0;
    for(i=1;i<=4000;i++){
      if(num[i][0]==0&&num[i][1]==0)continue;
      if(num[i][0]*num[i][1]>=1000000){cout<<i<<endl;c++;
      }
	num[i][0]=0;
	num[i][1]=0;
    }
    if(c==0)cout<<"NA"<<endl;
  }
  return 0;
}

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

typedef long long ll;

int n;
ll p[4000];
std::vector<int> ord;
bool used[4000];

int main()
{
	while( std::cin >> n, n )
	{
		memset( p, 0, sizeof( p ) );
		memset( used, false, sizeof( used ) ); 
		ord.clear();

		for( ll a, b, c, i = 0; i < n; ++i )
		{
			std::cin >> a >> b >> c;
			p[a-1] += b * c;
			ord.push_back( a - 1 );
		}

		bool fl = false;
		for( int i = 0; i != ord.size(); ++i )
			if( !used[ord[i]] && p[ord[i]] >= 1000000 )
				std::cout << ord[i] + 1 << std::endl, used[ord[i]] = true, fl = true;

		if( !fl )
			std::cout << "NA" << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main(){
	while (1){
		queue<int> q;
		int d[4010] = {};
		int n;
		cin >> n;
		if (n == 0) break;
		int a, b, c;
		rep(i, 0, n){
			cin >> a >> b >> c;
			if (d[a] == 0){
				q.push(a);
			}
			d[a] += b*c;
		}
		int ct = 0;
		while (!q.empty()){
			int x = q.front(); q.pop();
			if (d[x] >= 1000000){
				o(x); ct++;
			}
		}
		if (ct == 0){
			o("NA");
		}
	}

}

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

long long owData[4001];
std::vector<int> used;

int main(){
  long long x,input[3];
	bool Person;
	while( std::cin>>x , x ){
		Person=false;
		used.clear();
		memset(owData,0,sizeof(owData));
		while( x-- ){
			std::cin>>input[0]>>input[1]>>input[2];
			if( owData[input[0]] == 0 )used.push_back(input[0]);
			owData[input[0]]+=input[1]*input[2];
		}
		for(auto it = used.begin(); it != used.end(); ++it ){
			if( owData[*it] >= 1000000 )
				std::cout<< *it <<std::endl, Person=true ;
		}
		if(!Person)std::cout<<"NA"<<std::endl;
	}
	return 0;
}

C++:  #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int n;
   while(cin>>n&&n)
   {
     long long int arr[10000+5]={0};
     bool flag=false;
     for(int i=0;i<n;i++)
     {
       int id,p,q;
       cin>>id>>p>>q;
       arr[id]+=(p*q);        
     }           
     for(int i=1;i<=10000;i++)
     {
       if(arr[i]>=1000000)
       {
         cout<<i<<endl;
         flag=true;
       }        
     }       
     if(!flag) cout<<"NA"<<endl;
   }
   //while(1);
   return 0;
 }