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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n && n)
	{
		bool f = true;
		set<int> table;

		rep(i, n)
		{
			ll a, s, num;
			cin >> num >> a >> s;

			if(1000000 <= a * s && table.find(num) == table.end())
			{
				f = false;
				table.insert(num);
				cout << num << endl;
			}
		}

		if(f) cout << "NA" << endl;
	}
}

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

using namespace std;

int main(void){
    int i,j,k,l;
    int n;
    int id,cost,qty;
    int data_list[5000];
    int id_list[5000];
    bool id_flag;
    bool na_flag;
    
    while(cin>>n,n!=0){
        fill(data_list,data_list+4000,0);
        k=0;
        for(l=0;l<n;l++){
            data_list[id]+=(cost*qty);
            cin>>id>>cost>>qty;
            id_flag=true;
            for(i=0;i<=k+1;i++){
                if(id_list[i]==id){
                    id_flag=false;
                }
            }
            if(id_flag){
                id_list[k]=id;
                k++;
            }
        }
        na_flag=true;
        for(l=0;l<k;l++){
            if(data_list[id_list[l]]>=1000000){
                cout<<id_list[l]<<endl;
                na_flag=false;
            }
        }
        if(na_flag){
            cout<<"NA"<<endl;
        }
    }
    return(0);
}

C++: #include <stdio.h>
#include <map>
#include <set>

using namespace std;

int main(){
	while(1){
		int n;
		scanf("%d", &n);
		if(n==0){
			puts("NA");
			break;
		}

		for(int i=0;i<n;i++){
			map<int,int> m;
			map<int,int>::iterator it;
			set<int> v;
			int a,b,c;
			scanf("%d%d%d", &a,&b,&c);
			if((it=m.find(a)) != m.end()){
				m[a] += b*c;
			}else {
				m.insert(pair<int,int>(a,b*c));
			}

			if(m[a] >= 1000000 && v.find(a) == v.end()){
				printf("%d\n", a);
				v.insert(a);
			}
		}
	}
}

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

int main()
{
	int n;
	int No;
	long long int value, num;
	long long int mas;

	int a[4000];
	while(true)
	{
		cin >> n;
		if(n == 0) break;

		int x = 0;
		for(int i=0; i<n; i++){
			cin >> No >> value >> num;
			mas = value*num;
			if(mas >= 1000000){
				a[x] = No;
				x++;
			}
		}

		if(x == 0)
			cout << "NA" << '\n';
		else
			for(int i=0; i<x; i++)
				cout << a[i] << '\n';
	}
	return 0;
}

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

typedef pair<int,int> P; //社員番号、売上

int main(void)
{
	int n;

	while(cin >> n,n){
		vector<P> d;
	
		int no,m,k;
		bool f = false;

		for(int i = 0; i < n; i++){
			cin >> no >> m >> k;
			
			int j;
			for(j = 0; j < d.size(); j++){
				if(d[j].first == no){
					d[j].second += m*k;
				}
			}

			if(j == d.size()){
				d.push_back(P(no,m*k));
			}
		}
		int j;
		for(j = 0; j < d.size(); j++)
			if(d[j].second >= 1000000){
				f = true;
				break;
			}
		if(!f)
			cout << "NA" << endl;

		else{
			for(j = 0; j < d.size(); j++)
				if(d[j].second >= 1000000){
					cout << d[j].first << endl;
				}
		}
	}

	

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	while(true){
		int n;
		cin>>n;
		int a[4001][2]={};
		if(n==0){
			break;
		}
		int e,p,q;
		for(int w=0;w<n;w++){
			cin>>e>>p>>q;
			for(int l=0;l<w;l++){
				if(a[l][0]==e){
					a[l][1]+=p*q;
				}
			}
			a[w][0]=e;
			a[w][1]+=p*q;
		}
		bool ans=true;
		for(int m=0;m<4000;m++){
			if(a[m][1]>=1000000){
				cout<<a[m][0]<<endl;
				ans=false;
			}
		}
		if(ans){
			cout<<"NA"<<endl;
		}
	}
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n,ans[4000];
	double a,b;
	
	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		int i,j;
		for(i=0,j=0;i<n;i++)
		{
			int num;
			cin >> num >> a >> b ;
			if(a/1000000.0*b>=1.0)
			{
				ans[j]=num;
				j++;
			}
		}
		
		if(j!=0)
		{
			for(int i=0;i<j;i++)
			{
				cout << ans[i] << endl;
			}
		}
		else
			cout << "NA" << endl;
	}
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	long long int n,m,flg,i,j,a[1001],b[1001],c[1001];
	long long int e[1001],p[1001],q[1001];
	while(1){
		scanf("%lld",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			a[i]=0; b[i]=0; c[i]=0;
		}	
		for(i=0;i<n;i++){
			scanf("%lld %lld %lld",&e[i],&p[i],&q[i]);
			if(p[i]*q[i]>=1000000) a[i]=1;
			if(a[i]==0) b[i]=p[i]*q[i];
		}	
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(e[i]==e[j]){
					if(a[i]==0){
						b[i]+=b[j];
						b[j]=0;
					}
					if(b[i]>=1000000&&a[i]==0) a[i]=1;
				}
			}
		}
		flg=0;
		for(i=0;i<n;i++){
			if(a[i]!=0){
				printf("%lld\n",e[i]);
				flg=1;
			}
		}	
		if(flg==0) printf("NA\n");
	}
	return 0;
}

C++: #include<iostream>

using namespace std;


int main(){

	int all[4001] = {};
	int code, a, b, n, i,j;

	while (1){
		j = 0;
		for (i = 0; i < 4001; i++){
			all[i] = 0;
		}


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

		for (i = 0; i < n; i++){
			cin >> code >> a >> b;
			all[code] += a*b;
			
		}

		for (i = 0; i < 4001; i++){
			if (all[i] >= 1000000){
				cout << i << endl;
				j++;
			}
		}

		if (j == 0){
			cout << "NA" << endl;
		}

	}
}

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

struct sale{
	long price;
	long num;
};

int main(){

	while(1){
		int n, cost, piece, num, count = 0;
		cin>>n;
		if(n == 0)
			break;

		sale a[N];
		for(int i=0;i<N;i++){
			a[i].price = 0;
			a[i].num = 0;
		}

		for(int i=0;i<n;i++){
			cin>>num>>cost>>piece;
			a[num-1].price += cost;
			a[num-1].num   += piece;
		}

		for(int i=0;i<N;i++){
			if(a[i].price * a[i].num >= 1000000){
				cout<<i+1<<endl;
				count++;
			}
		}

		if(count == 0)
			cout<<"NA"<<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<map>
 
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define f first
#define s second
 
using namespace std;
 
typedef long long ll;
 
int main(){
  int n;
  while(cin>>n, n){
    map<string,pair<int,ll> > m;
    vector<pair<int,string> > v;
    REP(i,n){
      string a;
      ll b,c;
      cin>>a>>b>>c;
      if(m.find(a) == m.end())
    m[a] = mp(m.size(),b*c);
      else
    m[a].s += b*c;
    }
    FOR(it,m) if(it->s.s >= (ll)1000000) v.push_back(mp(it->s.f,it->f));
    if(v.size() == 0) cout << "NA" << endl;
    else{
      sort(ALL(v));
      FOR(it,v) cout << it->s << endl;
    }
  }
  return 0;
}