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>

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;
        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;
            }
            data_list[id_list[l]]=0;
        }
        if(na_flag){
            cout<<"NA"<<endl;
        }
    }
    return(0);
}

C++: #include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(false);

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

        map<int,int> sum;
        for (int i=0; i<n; ++i) {
            int no, price, quantity;
            cin >> no >> price >> quantity;
            sum[no] += price * quantity;
        }

        bool NA = true;
        map<int,int>::iterator it;
        for (it = sum.begin(); it != sum.end(); ++it) {
            if (it->second >= 1000000) {
                cout << it->first << endl;
                NA = false;
            }
        }
        if (NA) {
            cout << "NA" << endl;
        }
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,now;
	long long int a,b,c;
	while(cin>>n,n){
		now=0;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			if(b*c>=1000000){
				cout<<a<<endl;
				now++;
			}
		}
		if(now>0)
		cout<<"NA"<<endl;
	}
	return 0;
}

C++: //AOJ0100
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
#define __int64 long long
int main(){
	int n;
	while(cin>>n,n!=0){
vector< pair<int,__int64> >ta;
ta.clear();
for(int i=0;i<n;i++){
int a,b,c;
cin>>a>>b>>c;
bool f=0;
int index=0;
for(int j=0;j<ta.size();j++)if(ta[j].first==a)f=1,index=j;
if(f==0)ta.push_back(pair<int,__int64>(a,b*c));
else ta[index].second+=b*c;
}
bool f=0;
for(int i=0;i<ta.size();i++){
	//cout<<ta[i].first<<"   "<<ta[i].second<<endl;
	if(ta[i].second>=1000000){cout<<ta[i].first<<endl;;f=1;}
}
	if(!f)cout<<"NA"<<endl;
}
	return 0;
}

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

int n;
int a[3];
int x[4001];

int main() {
	while (1) {
		std::cin >> n;
		if (n == 0)
			break;
		int count = 0;

		std::memset(x, 0, sizeof(x));

		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j)
				std::cin >> a[j];
			x[a[0]] += a[1] * a[2];
		}
		for (int i = 1; i <= 4000; ++i) {
			if (x[i] >= 1000000) {
				std::cout << i << std::endl;
				++count;
			}
		}
		if (count==0)
			std::cout << "NA" << std::endl;
	}
	return 0;
}

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

using namespace std;

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

    vector<pair<int,int>> data;
    vector<int> nanum;
    for(int i = 0;i < n;++i){
      int num,sa,ko;
      cin>>num;
      cin>>sa;
      cin>>ko;

      int sum = sa * ko;

      if(i == 0){
        nanum.push_back(num);
        data.push_back(make_pair(num,sum));
      }
      else{
        auto a = find(nanum.begin(),nanum.end(),num);
        int b = *a
        if(b == 0){
          nanum.push_back(num);
          data.push_back(make_pair(num,sum));
        }
      }
    }

    int check = 0;
    for(pair<int,int> e : data){
      if(e.second >= 1000000){
        check = 1;
        cout<<e.first<<endl;
      }
    }
    if(check == 0){
      cout<<"NA"<<endl;
    }
  }

  return 0;
}

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

int main(){
	int n;
	int table[4001];

	while(cin>>n,n){
		int printed=0;
		for(int i=0;i<n;i++){
			int b,t,k;
			cin>>b>>t>>k;
			if(table[b]<1000000){
				table[b]+=t*k;
				if(table[b]>=1000000){
					cout<<b<<endl;
					printed=1;
				}
			}
		}
		if(printed==0){
			cout<<"NA"<<endl;
		}
	}

	return 0;
}

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

using namespace std;

int main(){
  int n, i, p, q;
  while(true){
    cin >> n;
    if(n==0)
      break;

    map<int,int> mop;
    vector<int> ord;
    bool check = true;

    for(int j=0; j<n; j++){
      cin >> i >> p >> q;
      if(mop.find(i) == mop.end()){
	mop[i] = p*q;
	ord.push_back(i);
      }
      else{
	mop[i] += p*q;
      }
    }
    
    for(int j=0; j<ord.size(); j++){
      if(mop[ord[j]] >= 1000000){
	cout << ord[j] << endl;
	check = false;
      }
    }
    if(check)
      cout << "NA\n";
  }
  return 0;
}

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

int main() {
	int max,n;
	vector<int> id;
	vector<int> sum;
	vector<int> table;
	
	id.resize(4000);
	sum.resize(4000);
	table.resize(4000);
	
	while(cin>>n,n){
		int i,a,b,f;
		max = 0;
		
		for(int j=0;j<4000;++j){
			id[j] = 0;
			sum[j] = 0;
			table[j] = 0;
		}
		
		for(;n;--n){
			cin>>i>>a>>b;
			
			if(table[i-1]){
				sum[table[i-1]-1] += a*b;
			}else{
				id[max]=i;
				table[i-1] = max+1;
				sum[table[i-1]-1] += a*b;
				++max;
			}
		}
		f=0;
		for(int j=0;j<max;++j){
			if(sum[j]>=1000000){
				cout<<id[j]<<endl;
				f=1;
			}
		}
		if(!f)cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define INF 100000000
#define MAXN 4096
typedef long long ll;
bool done[MAXN];

int main(void) {
    int n;
    while (1) {
        cin >> n;
        int flag = 0;
        if (n == 0) break;
        map<int, ll> m;
        m.clear();
        for (int i = 0; i < MAXN; i++) done[i] = false;
        for (int i = 0; i < n; i++) {
            int bango, tanka, num;
            cin >> bango >> tanka >> num;
            if (!done[bango]) {
                m[bango] += tanka * num;
                if (m[bango] >= 1000000) {
                    cout << bango << endl;
                    done[bango] = true;
                    flag = 1;
                }
            }
        }
        if (flag == 0) cout << "NA" << endl;
    }
    return 0;
}