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>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n, id, a, b;

	while( cin >> n , n ){
		map<int,int> employees;
		vector<int> vc;
		bool flag = true;
		
		for(int i=0 ; i<n ; ++i ){
			cin >> id >> a >> b;
			if( !employees[id] ) vc.push_back( id );
			employees[id] += a * b;	
		}
		for(int i=0 ; i<vc.size() ; ++i ){
			if( employees[ vc[i] ] >= 1000000 ){
				cout << vc[i] << endl;
				flag = false;
			}
		}
		if( flag ){
			cout << "NA" << endl;
		}
	}
}

C++: #include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{

    int n=1,num,tanka,suryo;
    long long sum[4001]={0};
    int jyun[100000001]={0};
    bool w[4001]={false};
    bool na=true;
    while(true){
        cin>>n;
        if(n==0){
            return 0;
        }
        for(int i=0;i<n;i++){//ツ禿シツ療債つウツづェツつスツ値ツづーツ各ツ配ツ療ア(ツ偲青暗オツ氾板債づ可格ツ納)
            cin>>num>>tanka>>suryo;
            jyun[i]=num;
            sum[num]+=tanka*suryo;
        }
        for(int i=0;i<=100000000;i++){
            if(sum[jyun[i]]>=1000000){if(!w[jyun[i]]){cout<<jyun[i]<<endl;w[jyun[i]]=true;}na=false;}
            sum[i]=0;//ツ篠淞づ可使ツつ、ツづヲツつ、ツづ可渉可甘コツ可サツづーツつオツづつィツつュ
            jyun[i]=0;
        }
        if(na)cout<<"NA"<<endl;
        na=true;
        for(int i=0;i<=4000;i++){
            w[i]=false;
        }
    }
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define ll long long

int main()
{
    while (1)
    {
	int n,f=0,id,f2[4001];
	ll price,num,p[4001];
	rep(i,4001){p[i]=0;f2[i]=0;}
	cin >> n;
	if (n==0)break;
	rep(i,n)
	{
	    cin >> id >> price >> num;
	    p[id]+=price*num;
	    if (p[id] >= 1000000 && f2[id]==0)
	    {
		cout << id << endl;
		f=1;
		f2[id]=1;
	    }
	}
	if (f==0)cout << "NA" << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
long long n,a,b,c,f,i,j,k,s[4001],aa[4001];
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)s[i]=0;
for(i=0;i<n;i++){
cin>>a>>b>>c;
k=i;
for(j=0;j<i-1;j++)if(a==aa[j]){k=j;break;}
aa[i]=a;
for(j=0;j<c;j++){
if(s[k]>=1000000)break;
s[k]+=b;
}
}
for(f=0,i=0;i<n;i++)
if(s[i]>=1000000){cout<<aa[i]<<endl;f=1;}
if(f==0)cout<<"NA"<<endl;
}
return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	long x,y;
	int n,num;
	while(cin>>n&&n!=0){
		int cnt=0,sum=0;
		bool a[4000]={0};
		long long p[4000]={0};
		for(int i=0;i<n;i++){
			cin>>num>>x>>y;
			if(a[num]==0)cnt++;
			a[num]=1,p[num]+=x*y;
		}
		for(int i=1;i<=4000;i++){
			if(a[i]==1&&p[i]>=1000000){
				cout<<i<<endl;
			}else if(a[i]==1){
				sum++;
			}
			if(cnt==sum){
				cout<<"NA"<<endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <iostream>

int main()
{
	//const __int64 threshold = 1000000;
	const long long threshold = 1000000;
	int n;
	
	while (std::cin >> n, n) {
		bool naFlag = true;
		while (n--) {
			int id;
			//__int64 unit, quantity;
			long long unit, quantity;
			std::cin >> id >> unit >> quantity;
			
			if (unit * quantity >= threshold)  {
				naFlag = false;
				std::cout << id << std::endl;
			}
		}
		if (naFlag) std::cout << "NA" << std::endl;
	}
	
	return 0;
}

C++: #include<stdio.h>


int main(){
	int n;
	int id[4000],cid;
	long long int price,num,sale[4000];
	bool f;
	int i,j,idcount;
	while(scanf("%d",&n),n){

		f=true;
		idcount=0;

		for(i=0;i<n;i++){
			scanf("%d %lld %lld",&cid,&price,&num);
			for(j=0;j<idcount;j++){
				if(id[j]==cid){
					sale[j]=sale[j]+price*num;
					break;
				}
			}

			if(j==idcount){
				id[idcount]=cid;
				sale[idcount]=price*num;
				idcount++;
			}

		}



		for(i=0;i<idcount;i++){
			if(sale[i]>=1000000){
				printf("%d\n",id[i]);
				f=false;
			}
		}
		if(f)printf("NA\n");
	}
	return 0;
}

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

using namespace std;

int main()
{
	
	while(1)
	{
		int sum = 0;
		int n;
		cin >> n;
		if(n == 0) break;
		
		queue<int> q;
		bool checked[4000];
		long long list[4000];
		for(int i = 0;i < 4000;i++)
		{
			checked[i] = false;
			list[i] = 0;
		}
		for(int i = 0;i < n;i++)
		{
			long long no, x, y;
			cin >> no >> x >> y;
			list[no - 1] += x * y;
			if(!checked[no - 1])
			{
				q.push(no);
				checked[no - 1] = true;
			}
		}
		
		while(!q.empty())
		{
			int no = q.front();
			q.pop();
			if(list[no - 1] >= 1000000)
			{
				cout << no << endl;
				sum++;
			}
		}
		if(sum == 0) cout << "NA" << endl;
	}
	return 0;
}

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

int member[4000];
vector<int> ach;

int main(void){
  int n;
  while(true){
    cin >> n;
    if(n == 0)  break;
    fill(member, member + 4000, 0);
    ach.clear();
    for(int i = 0; i < n; i++){
      int id, tanka, suryo;
      cin >> id >> tanka >> suryo;
      member[id] += tanka * suryo;
    }

    for(int i = 0; i < 4000; i++){
      if(member[i] >= 1000000){
        ach.push_back(i);
      }
    }

    if(ach.empty()){
      cout << "NA" << endl;
    }else{
      for(int i = 0; i < ach.size(); i++){
        cout << ach[i] << endl;
      }
    }
  }
  return 0;
}

C++: #include <cstdlib>
#include <iostream>
#include <math.h>



void Eratosthenes(int N){

}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);

    int n;
    while (std::cin >> n) {
        if (n==0){
            return EXIT_SUCCESS;
        }
        int Nw = 4000;
        int ar[Nw];
        for( int i=0; i < Nw; i++){
            ar[i] = -1;
        }
        int br[Nw];
        for( int i=0; i < Nw; i++){
            br[i] = 0;
        }
        int e,p,q;
        for(int i = 0; i < n; i++){
            std::cin >> e >> p >> q;
            int b = -1;
            for(int k=0; k<Nw; k++){
                if (ar[k] == e) {
                    br[k] += p*q;
                    b = 1;
                    break;
                }
            }
            if (b==-1){
                for(int k=0; k<Nw; k++){
                    if (ar[k] == -1) {
                        ar[k] = e;
                        br[k] = p*q;
                        break;
                    }
                }
            }
        }
        int f = 0;
        for(int i =0; i < Nw; i++){
            if (br[i] >= 1000000){
                std::cout << ar[i] << std::endl;
                f = 1;
            }
        }
        if ( f == 0 ){
            std::cout << "NA" << std::endl;
        }
        // for(int i = 0; i< 5; i++){
        //     fprintf(stderr,"i=%2d, ar[i]=%5d, br[i]=%9d\n",i,ar[i],br[i]);
        // }
        // return EXIT_SUCCESS;
    }
    return EXIT_SUCCESS;
}