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>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  int n;
  while(cin >> n, n){
    int id, cnt = 0;
    ll a, num, sum[5000];
    fill(sum, sum+5000, 0);
    vector<int> in;
    for(int i = 0; i < n ; i++){
      cin >> id >> a >> num;
      if(sum[id] <= 1000000)
	sum[id] += a*num;
      if(find(in.begin(), in.end(),id)==in.end()){
	in.push_back(id);
      }
    }

    for(int i = 0; i < in.size(); i++){
      if(sum[in[i]] >= 1000000){
	cnt++;
	cout << in[i] << endl;
      }
    }
    if(!cnt) cout << "NA" << endl;
  }
  return 0;
}

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

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) break;
    int number[n];
    bool useN[4000];
    long long int total[4000];
    for (int i = 0; i < n; i++) number[i] = 0;
    for (int i = 0; i < 4000; i++) {
      useN[i] = false;
      total[i] = 0;
    }
    
    for (int i = 0; i < n; i++) {
      int a;
      long long int b,c;
      cin >> a >> b >> c;
      number[i] = a;
      if (!useN[a-1]) useN[a-1] = true;
      total[a-1] += b*c;
    }
    
    bool NA = true;
    for (int i = 0; i < n; i++) {
      if ( useN[number[i]-1] && total[number[i]-1] >= 1000000) {
	cout << number[i] << endl;
	useN[number[i]-1] = false;
	NA = false;
      }
    }
    if (NA) cout << "NA" << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int main()
{
	
	int n;
	long long sn, x, y;
	vector<long long>p;
	map<long, long>m;
	while (1){
		m.clear();
		p.clear();
		cin >> n;

		if (n == 0)break;
		for (int i = 0; i < n; i++){
		cin >> sn >> x >> y;
			if (m.find(sn) == m.end()){
				p.push_back(sn);
			}
				m[sn] += x*y;
		}
		int flag = 0;
		for (int i = 0; i < p.size(); i++){
			if (m[p[i]] >= 1000000){
				cout << p[i] << endl;
				flag++;
			}
		}
		if (flag==0)cout << "NA" << endl;
	}
}

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

int main(){
  int n;
  while(std::cin>>n){
    if(!n)return 0;
    std::vector<int> v;
    int team,price,number;
    for(;n;n--){
      std::cin>>team>>price>>number;
      if(price*number>=1000000)v.push_back(team);
    }
    if(v.empty())std::cout<<"NA"<<std::endl;
    else{
      std::vector<int>::iterator it = v.begin();
      while(it!=v.end()){
        std::cout<<*it<<std::endl;
        it++;
      }
    }
  }
}

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

int main(){
	int n,number;
	long long a,b;
	bool flag;
	map<int,long long> info;
	vector<int> seq;
	
	while(cin >> n && n){
		info.clear();
		seq.clear();
		while(n--){
			cin >> number >> a >> b;
			if(!info[number])seq.push_back(number); // ツ甘ケツ出ツつセツづつスツづァツ表ツ篠ヲツ渉記ツ録ツ配ツ療アツづ可禿シツづェツづ按つ「ツ。ツ単ツ可ソ0ツ円ツケツーツスツづーツ考ツ猟カツつオツづづ慊つケツづアツ。
			info[number] += a*b;
		}
		flag = true;
		for(int i=0;i<seq.size();i++){
			if(info[seq[i]]>=1000000){
				flag = false;
				cout << seq[i] << endl;
			}
		}
		if(flag)cout << "NA" << endl;
	}
}

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

int N, M;

int main() {
	int goal = 1000000;

	for (; cin >> N;) {
		if (!N) break;
		int v[4000];
		memset(v, 0, sizeof(v));
		for (int i = 0; i < N; i++) {
			int e, p, q;
			cin >> e >> p >> q;
			v[e - 1] += p*q;
		}
		bool flag = false;
		for (int i = 0; i < 4000; i++) {
			if (v[i] >= goal) {
				flag = true;
				cout << i + 1 << endl;

			}
		}
		if (!flag) cout << "NA" << endl;
	}

	return 0;
}

C++: #include<iostream>

using namespace std;


int main(){

	unsigned long long all[4001] = {};
	unsigned long long 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>

using namespace std;

int main()
{
    while(1)
    {
        int i=0;
         cin>>i;
        if(i==0)
            break;
        else
        {
            int na=0;
       
            int h[4001];
            for(int k=0;k<=4000;k++)
            {
                h[k]=0;
            }
            for(int kp=1;kp<=i;kp++)
            {
                int j=0;int l=0;int m=0;
                cin>>j>>l>>m;
                h[j]+=(l*m);

            }
            for(int kk=1;kk<=4000;kk++)
            {
                if(h[kk]>=1000000)
                {
                    cout<<kk<<endl;
                    na=1;
                }

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

        }
    }

    return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    map<int, int> t;
    while (n--) {
      int i, p, q;
      cin >> i >> p >> q;
      t[i] += p * q;
    }
    vi v;
    for (auto x : t) {
      if (x.se >= 1000000LL) v.pb(x.fi);
    }
    if (v.size()) {
      rep(i, v.size()) cout << v[i] << endl;
    } else {
      cout << "NA" << endl;
    }
  }
}