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>
#include <vector>
#include <map>
#include <algorithm>
#include <stdio.h>

using namespace std;

typedef long long ll;

int n, id, p, q;
ll amount;

const ll MAX = 1000000;

struct Mem {
    int index;
    int id;
    ll c;

    Mem(int _index, int _id, ll _c) { index = _index; id = _id; _c = c; }

    bool operator<(const Mem& m) const {
        return index < m.index;
    }
    bool operator==(const Mem& m) const {
        return id == m.id;
    }
    bool operator!=(const Mem& m) const {
        return id == m.id;
    }
};

map<int, ll> m;
map<int, ll>::iterator it;
vector<Mem> ans;
vector<int> index;

int main(void) {
    while(~scanf("%d", &n)) {
        if(n == 0) break;
        m.clear();
        index.clear();
        for(int i = 0; i < n; i++) {
            scanf("%d%d%d", &id, &p, &q);
            amount = p*q;
            m[id] += amount;
            index.push_back(id);
        }
        ans.clear();
        for(it = m.begin(); it != m.end(); it++) {
            if(it->second >= MAX) {
                ans.push_back(Mem((*find(index.begin(), index.end(), it->first)), it->first, it->second));
            }
        }
        sort(ans.begin(), ans.end());
        if(ans.empty()) {
            printf("NA\n");
        } else {
            for(int i = 0; i < (int) ans.size(); i++) {
                printf("%d\n", ans[i].id);
            }
        }
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
    int i,l,k;
    int n;
    long long id,c,q;
    long long data_list[4001]={0};
    int id_list[4000];
    bool id_flag;
    bool na_flag;
    
    while(cin>>n,n!=0){
        k=0;
        fill(data_list,data_list+4002,0);
        for(l=0;l<n;l++){
            data_list[id]+=(c*q);
            cin>>id>>c>>q;
            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 <iostream>
#include <cstdio>
using namespace std;

#define TAR 1000000

int main() {
	int n,num,ch;
	unsigned long t,k;
	while(cin >> n){
		ch = 0;
		while(n){
			scanf("%d %ld %ld",&num,&t,&k);
			if((t!=0)&&(k!=0)){
				if((k > TAR/t)&&(t > TAR/k)){
					cout << num << endl;
					ch++;
				}else if((t >= TAR/k)&&(TAR%k == 0)){
					cout << num << endl;
					ch++;
				}
				if(((--n)==0)&&(ch==0)){
					cout << "NA" << endl;
				}
			}
		}
	}
	return 0;
}

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

int main()
{
	while (true){
		int n;
		cin >> n;
		if (!n){ break; }

		long long int sold[4001];
		bool already[4001];
		queue<int> input;
		for (int i = 1; i <= 4000; i++){
			sold[i] = 0;
			already[i] = false;
		}
		for (int i = 0; i < n; i++){
			int number, yen, times;
			cin >> number >> yen >> times;
			if (already[number] == false){
				already[number] = true;
				input.push(number);
			}
			sold[number] += (long long int)yen * (long long int)times;
		}
		bool f = false;
		while (!input.empty()){
			if (sold[input.front()] >= 1000000){
				cout << input.front() << endl;
				f = true;
			}
			input.pop();
		}
		if (f == false){
			cout << "NA" << endl;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<map>
#include<vector>
int main() {
	std::map<int, int> mp;
	std::vector<int> v;
	int n, i, e, p, q;
	while (true) {
		mp.clear();
		v.clear();
		scanf("%d", &n);
		if (n == 0)break;
		for (i = 0; i < n; i++) {
			scanf("%d%d%d", &e, &p, &q);
			if (mp.count(e) == 0) mp[e] = p*q;
			else mp[e] += p*q;
		}
		for (std::map<int, int>::iterator itr = mp.begin(); itr != mp.end(); ++itr) {
			if (itr->second >= 1000000)v.push_back(itr->first);
		}
		if (v.size() == 0)printf("NA\n");
		else {
			for (std::vector<int>::iterator itr = v.begin(); itr != v.end(); ++itr) {
				printf("%d\n", *itr);
			}
		}
	}
	return 0;
}

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

int main(void)
{
	int n, num;
	string str;
	long long a;
	
	while (cin >> n, n){
		map <string, long long> m;
		vector <string> data;
		for (int i = 0; i < n; i++){
			cin >> str >> num >> a;
			if (!m[str]) data.push_back(str);
			m[str] += (num * a);
		}
		bool flag = true;
		for (int i = 0; i < data.size(); i++){
			if (1000000 <= m[data[i]]){
				cout << data[i] << endl;
				flag = false;
			}
		}
		if (flag) cout << "NA" << endl;
	}
	
	return 0;
}

C++: #include<stdio.h>

int main(void){
	int x[5000],n,a,b,i,nan,k;
	while(0==0){
		scanf("%d",&n);
		if(n==0)break;
		k=0;
		for(i=0;i<5000;i++) x[i]=0;
		for(i=0;i<n;i++){
			scanf("%d %d %d",&nan,&a,&b);
			x[nan]+=a*b;
			if(x[nan]>999999){
				printf("%d\n",nan);
				k++;
			}
		}
		if(k==0) printf("NA\n");
		k=0;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
	long long n, num, price, sale;

	while(cin>>n, n!=0){
		vector<long long> vec(4001, 0);
		vector<int> a;
		while(n--){
			cin>>num>>price>>sale;
			if(find(a.begin(), a.end(), num)==a.end())a.push_back(num);
			vec[num] += price*sale;
		}
		int count=0;
		for(int i=0; i<a.size(); i++){
			if(vec[a[i]] >= 1000000){
				cout<<a[i]<<"\n";
				count++;
			}
		}
		if(!count)cout<<"NA\n";
	}	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n){
        map<int,int>mp;
        rep(j,n){
            int a,b,c; cin>>a>>b>>c;
            mp[a]+=b*c;
        }
        bool flag=false;
        for(auto itr=mp.begin();itr!=mp.end();itr++)
            if(mp[itr->first]>=1000000){flag=true;cout<<itr->first<<endl;}
        if(!flag)cout<<"NA"<<endl;
    }
}