Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}
		sales := make(map[string]int)
		existed := make(map[string]bool)
		order := make([]string, 4000)
		flg := false
		for i := 0; i < n; i++ {
			stdin.Scan()
			l := strings.Split(stdin.Text(), " ")
			e := l[0]
			p, _ := strconv.Atoi(l[1])
			q, _ := strconv.Atoi(l[2])
			sales[e] += p * q
			if !existed[e] {
				order = append(order, e)
				existed[e] = true
			}
		}
		for _, v := range order {
			if sales[v] >= 1000000 {
				fmt.Println(v)
				flg = true
			}
		}
		if flg == false {
			fmt.Println("NA")
		}
	}
}

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

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

using namespace std;

struct data{
  int id;
  int price;
  int amount;
  long rate;
};

int main(){
  int n=0;
  while(1){
    cin>>n;
    if(n==0){return 0;}
    vector<struct data> data(n);
    int c=0;
    for(int i=0;i<n;i++){
      scanf("%d %d %d",&data[i].id,&data[i].price,&data[i].amount);
      data[i].rate=data[i].price*data[i].amount;
    }
    vector<struct data> res(n);
    for(int i=0;i<n;i++){
      res[i].id=0;
    }
    for(int i=0;i<n;i++){
      int find=0;
      for(int j=0;j<i;j++){
	if(data[i].id==res[j].id){
	  res[j].rate+=data[i].rate;
	  find=1;
	  break;
	}
      }
      if(find==0){
	res[i].id=data[i].id;
	res[i].rate=data[i].rate;
      }
    }
    for(int i=0;i<n;i++){
      if(res[i].id!=0&&res[i].rate>=1000000){
	cout<<data[i].id<<"\n";
	c++;
      }
    }
    if(c==0){
      cout<<"NA\n";
    }
  }
  return 0;
}