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 <vector>
#include <algorithm>

using namespace std;

const int Target = 1000000;

struct Shain {
	int no;
	long long sum;
};

bool operator==( const Shain &a, const Shain &b )
{
	return a.no == b.no;
}

int main( void )
{
	vector<Shain> shain;
	int n;
	while(cin >> n, n) {
		shain.clear();
		for(int i=0; i < n; ++i) {
			int no, kin, num;
			cin >> no >> kin >> num;
			bool hit = false;
			vector<Shain>::iterator it = shain.begin();
			while(it != shain.end()) {
				if(it->no == no) {
					if(it->sum < Target) {
						it->sum += (kin * num);
						Shain tmp2 = *it;
						if(it->sum >= Target) {
							shain.erase(it);
							shain.push_back(tmp2);
						}
					}
					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 <iostream>
#include <cstdio>
using namespace std;

typedef pair<int,int> P;

int main(void)
{
	int N;
	while(cin >> N, N){
		P d[4001] = {};
		bool f = false;

		int a,b,c;
		for(int i = 0; i < N; i++){
			cin >> a >> b >> c;

			int j;
			for(j = 0; d[j].first != 0; j++){
				if(d[j].first == a){
					d[j].second += b*c;
					if(d[j].second >= 1000000)
						f = true;
				}
			}
			if(d[j].first == 0){
				d[j].first = a;
				d[j].second += b*c;
			}
		}

		if(!f)
			printf("NA\n");

		else
			for(int i = 0; d[i].first != 0; i++)
				if(d[i].second >= 1000000)
					printf("%d\n", d[i].first);
	}
		





	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,h,h2,ib;
  while(cin>>n){
    if(n==0) break;
    h = 0;
    ib = 0;
    int b[n],p[n],q[n],ansb[n];
    long int ans[n];
    for(int i=0;i<n;i++){
      cin >> b[i] >> p[i] >> q[i];
      h2 = 0;
      for(int j=0;j<i;j++){
	if(ansb[j]==b[i]){
	  ans[j] += p[i] * q[i]; 
	  h2 = 1;
	  break;
	}
      }
      if(h2==0){
	ans[ib] = p[i] * q[i];
	ansb[ib] = b[i];
	ib++;
      }
    } 
    for(int i=0;i<ib;i++){
      if(ans[i]>=1000000){
	cout << ansb[i] << endl;
	if(h==0) h = 1;
      }
    }
    if(h==0) cout << "NA" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
int main(){
  int n,sn,p,c;
  std::vector<int> v;
  while(std::cin>>n){
    if(!n)return 0;
    for(;n;n--){
      std::cin>>sn>>p>>c;
      std::vector<int>::iterator it=std::find(v.begin(),v.end(),sn);
      if(p*c>=1000000){
        if(it==v.end()){
          v.push_back(sn);
        }
      }
    }
    if(v.empty())std::cout<<"NA"<<std::endl;
    else{
    std::vector<int>::iterator it = v.begin();
    while(it!=v.end()){
      std::cout<<*it<<std::endl;
      it++;
    }
    v.clear();
    }
  }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;
 
int main(){
	int N,A,B,C;
	while(cin>>N,N){
		int cnt[4001]={};
		for(int i=0;i<N;i++){
			cin>>A>>B>>C;
			cnt[A] += B*C;
		}
		bool NAflag=true;
		for(int i=1;i<=4000;i++){
			if(cnt[i]>=1000000){
				NAflag = false;
				printf("%d\n",i);
			}
		}
		if(NAflag==true) puts("NA");
	}
    return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include <vector>
#include <map>
#include<cstdlib>
#include<iomanip>
#include<queue>


using namespace std;

void Solution()
{
   	int n;
    
    int number, perPrice, amount;
    
    bool isUsed;
    //long long valueCheck[4000];
    vector<long long> valueCheck(4000, 0);
    queue<int> que;
    
    while(true)
    {
        isUsed = false;
        
        cin>>n;
        
        if (n == 0)
        {
            break;
        }
        
        while(n--)
        {
            cin>>number>>perPrice>>amount;
            
            valueCheck[number] += perPrice * amount;
            que.push(number);
        }
        
        while (!que.empty())
        {
            if (valueCheck[que.front()] >= 1000000)
            {
                cout<<que.front()<<endl;
                isUsed = true;
            }
            
            valueCheck[que.front()] = 0;
            que.pop();
        }
        
        if (!isUsed)
        {
            cout<<"NA"<<endl;
        }
        
//            if ( valueCheck >= 1000000)
//            {
//                cout<<number<<endl;
//            }
//            else
//            {
//                count++;
//            }
//            
//            if (count == m)
//            {
//                cout<<"NA"<<endl;
//            }
        
    }
}

int main()
{
    Solution();
    return 0;
}

C++: #include<cstdio>

int main(){
int a,i,fl;
unsigned long int b,c;
while(1){
scanf("%d",&i);
fl=0;
for(int j=0;j<i;j++){


 scanf("%d",&a);
 if(a==0){
 return 0;
}
 scanf("%ld",&b);
 scanf("%ld",&c);
if(a*c>=1000000) {
 fl=1;
 printf("%d\n",a);
}
if(fl==false) pritnf("NA\n");
}
}
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  bool kai;
  int t[5000]={0};
  long long sum[5000]={0};
  bool NA=true;
  while(cin>>n,n){
    NA=true;
    kai=false;
    for(int i=0;i<5000;i++){
      t[i]=0; sum[i]=0;
    }
    int a,b,c;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      for(int j=0;j<5000;j++){
	if(t[j]==a)break;
	if(t[j]==0){t[j]=a;break;}
      }
      
      if(sum[a]<=1000000)sum[a]+=b*c;
    }
    for(int i=0;i<5000;i++){
      if(sum[t[i]]>=1000000){
	if(kai){cout<<endl; }cout<<t[i]; kai=true;  NA=false;
      }
    }
    if(NA)cout<<"NA"<<endl;
  }
}

C++: #include <stdio.h>

int main(void)
{
	int staff[1000];
	int n;
	int price[1000];
	int num[1000];
	int i;
	int flag[1000];
	int a_flag;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		a_flag = 0;
		for (i = 0; i < n; i++){
			flag[i] = 0;
			scanf("%d %d %d", &staff[i], &price[i], &num[i]);
			if (price[i] * num[i] >= 1000000){
				flag[i] = 1;
				a_flag++;
			}
		}
		
		if (a_flag){
			for (i = 0; i < n; i++){
				if(flag[i]){
					printf("%d\n", staff[i]);
				}
			}
		}
		else {
			printf("NA\n");
		}
	}
	
	return (0);
}

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

const long long BORDER = 1000000;

using namespace std;

int main() {
  bool f;
  int i, j, n, number;
  long long price, amount;
  while(cin >> n) {
    if (n == 0) break;
    
    map<int, long long> m;
    map<int, long long>::iterator it;

    for (i = 0; i < n; i++) {
      cin >> number >> price >> amount;
      it = m.find(number);
      if (it != m.end())
        it->second += price * amount;
      else
        m.insert(pair<int, long long>(number, price * amount));
    }
    for (it = m.begin(), f = false; it != m.end(); it++) {
      if (it->second >= BORDER) {
        f = true;
        cout << it->first << endl;
      }
    }
    if (!f) cout << "NA" << endl;
  }

  return 0;
}