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<map>
#include<vector>
using namespace std;
int main(){
    int n,a,b,c;
    while(cin>>n){
        if(n==0 || cin.eof())break;
        vector<int>V;
        map<int,long long>M;
        while(n--){
            cin>>a>>b>>c;
            if(M[a]==0)V.push_back(a);
            M[a]+=b*c;

        }

        bool flag=true;
        for(int i=0;i<V.size();i++){
            if(M[V[i]]>=1000000){
                flag=false;
                cout<<V[i]<<endl;
            }
        }
        if(flag)cout<<"NA"<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

int main() {

    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;

        bool na = true;
        set<ll> st;
        map<ll, ll> mp;
        vector<ll> v;

        rep(k, n) {
            ll i, p, q;
            cin >> i >> p >> q;
            if (!st.count(i)) {
                v.push_back(i);
                st.insert(i);
            }
            mp[i] += p*q;
        }

        for (auto vi : v) {
            if (mp[vi] >= 1000000) {
                cout << vi << endl;
                na = false;
            }
        }

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

    return 0;
}

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

using namespace std;

struct syain {
	int name;
	long long int u;
};

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<syain> s;
		for (int i = 0; i < n; i++) {
			int a;
			long long int b, c;
			cin >> a >> b >> c;
			bool hantei = true;
			for (int j = 0; j < s.size(); j++) {
				if (s[j].name == a) {
					s[j].u += b * c;
					hantei = false;
					break;
				}
			}
			if (hantei) {
				syain d;
				d.name = a;
				d.u = b * c;
				s.push_back(d);
			}
		}
		bool hantei2 = true;
		for (int i = 0; i < s.size(); i++) {
			if (s[i].u >= 1000000) {
				cout << s[i].name << endl;
				hantei2 = false;
			}
		}
		if (hantei2) {
			cout << "NA" << endl;
		}
	}
	return 0;
}

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

typedef long long __int64;
#define NOS (4000)

int main()
{
	const __int64 threshold = 1000000;
//	const __int64 NOS = 4000;
	int n;
	
	while (std::cin >> n, n) {
		std::vector<int> inputStaff(n);
		__int64 staff[NOS] = {0};
		
		while (n--) {
			int id;
			__int64 unit, quantity;
			std::cin >> id >> unit >> quantity;
			staff[id - 1] += unit * quantity;
			if (std::find(inputStaff.begin(), inputStaff.end(), id) == inputStaff.end()) inputStaff.push_back(id);
		}
		
		bool naFlag = true;
		std::vector<int>::iterator it = inputStaff.begin(), eit = inputStaff.end();
		for (; it != eit; ++it) {
			if (staff[*it - 1] >= threshold)  {
				naFlag = false;
				std::cout << *it << std::endl;
			}
		}
		if (naFlag) std::cout << "NA" << std::endl;
	}
	
	return 0;
}

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

int main(void)
{
	int n;
	while (cin >> n, n){
		long long a, b, c;
		vector <int> v;
		for (int i = 0; i < n; i++){
			cin >> a >> b >> c;
			if (1000000 <= b * c) v.push_back(a);
		}
		for (int i = 0; i < v.size(); i++){
			cout << v[i] << endl;
		}
		if (v.size() == 0) puts("NA");
	}
	
	return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<string>

using namespace std;
#define mp make_pair
int main(){
  int n;
  string a;
  long long b,c;
  map<string,long> data;
  vector<string> id;
  while(true){
    id.clear();
    data.clear();
    cin>>n;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      c*=b;
      if(data.find(a)==data.end()){
	data.insert(mp(a,c));
	id.push_back(a);
      }
      else{
	data[a]+=c;
      }
    }
    bool empty = true;
    for(int i=0;i<id.size();i++){
      if(data[id[i]]>=1000000){
	cout<<id[i]<<endl;
	empty = false;
      }
    }
    if (empty)
      cout<<"NA"<<endl;

  }
  return 0;
}

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

int main(int argc, char **argv)
{
	int i, p, q, n, size = 0, flag, pri = 1, max;
	int *sum = (int *)calloc(4000, sizeof(int));
	int *pr = (int *)calloc(4000, sizeof(int));
	int *id = (int *)calloc(4000, sizeof(int));

	while(1){
		cin >> n;
		
		if(n == 0){
			cout << "NA" << endl;
			break;
		}
		
		while(n > 0){
			n--;
			cin >> i >> p >> q;
			flag = 0;
			for(int j = 0; j < size; j++){
				if(id[j] == i){
					if(p*q > sum[i] || pri != pr[i]){
						sum[i] = p*q;
						pr[i] = pri;
					}
					flag = 1;
					break;
				}
			}
		
			if(flag == 0){
				id[size] = i;
				sum[i] = p*q;
				pr[i] = pri;
				size++;
			}
		}

		max = id[0];
		for(int j = 1; j < size; j++){
			if(sum[max] < sum[id[j]]){
				max = id[j];
			}
		}
		
		cout << max << endl;
		
		pri++;
	}
	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
void shoki();
	vector<long long> num(4001,0);
	int n,ban,tanka,kazu,i,j;
int main(){
	
	bool y=false;
	for(j=0;j<50;j++){
		cin>>n;
		if(n==0){
			break;
		}
		int count=0;
		for(i=0;i<n;i++){
			cin>>ban>>tanka>>kazu;
			num[ban]+=tanka*kazu;
		}
		//sort(num.begin(),num.end());
		for(int k=0;k<4001;k++){
			if(num[k]==0){
				continue;
			}
			if(num[k]>=1000000){
				y=true;
				cout<<k<<endl;
			}
		}
		if(y==false){
			cout<<"NA"<<endl;
		}
		y=false;
		shoki();
	}
	
	return 0;
}
void shoki(){
	for(int i=0;i<4000;i++){
		num[i]=0;
	}
}

C++: #include<stdio.h>

int main(){

	int n, i, x[4000] = {}, xx[4000] = {}, xxx[4000] = {}, r, y = 0, w=1;

	while (w > 0){
		scanf("%d", &n);

		for (i = 0; i < n; i++){
			scanf("%d %d %d",&x[i],&xx[i],&xxx[i]);
		}

		for (r = 0; r < 4000; r++){
			
			if (xx[r] * xxx[r] > 1000000){
				printf("%d\n", x[r]);
			}	
		}
		if (y == 0){ printf("NA\n"); (y = 0); }		
	}
	return 0;
}

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

int main(){
	int n;
	unsigned long long int p[4000];
	int count;
	
	while(cin>>n,n){
		for(int i=0;i<4000;++i)p[i]=0;
		
		for(int i=0;i<n;++i){
			long long wn,va,cn;
			cin>>wn>>va>>cn;
			p[wn-1] += va*cn;
		}
		count = 0;
		for(int i=0;i<4000;++i){
			if(p[i] >= 1000000){cout<<i+1<<endl;count++;}
		}
		if(!count)cout<<"NA"<<endl;

	}
}