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<stdio.h>
long long d;

int main(){
	int n,i,num,c,k;
	int ar[4000],car;
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		car=0;
		for(i=0;i<n;i++){
			scanf("%d %d %d",&num,&c,&k);
			d=c*k;
			if(d>=1000000)ar[car++]=num;
		}
		if(car==0)printf("NA\n");
		else{for(i=0;i<car;i++)printf("%d\n",ar[i]);}
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main(){
	while (1){
		queue<int> q;
		map<int,lint> m;
		bool f[4010] = {};
		int n;
		cin >> n;
		if (n == 0) break;
		int a, b, c;
		rep(i, 0, n){
			cin >> a >> b >> c;
			q.push(a);
			m[a] += b*c;
		}
		int ct = 0;
		while (!q.empty()){
			int x = q.front(); q.pop();
			if (m[x] >= 1000000 && f[x]==0){
				o(x); ct++; f[x] = 1;
			}
		}
		if (ct == 0){
			o("NA");
		}
	}

}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        long long int syain,kakaku,kosuu,syains[5000]={0};
        long long int bango[5000]={0},flag[5000]={0};
        bool flag2=0;
        for(int i=0;i<n;i++){
            cin>>syain>>kakaku>>kosuu;
            bango[i]=syain;
            syains[syain]+=kakaku*kosuu;
        }
        for(int i=0;i<5000;i++){
            if(syains[bango[i]]>=1000000){
                if(flag[bango[i]]==0){
                        cout<<bango[i]<<endl;
                        flag[bango[i]]=1;
                }
            }
        }
        for(int i=0;i<5000;i++){
            if(flag[i]==1)flag2=1;
        }
    if(flag2==0)cout<<"NA"<<endl;
    }
    return 0;
}

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

int main(){
	while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        long long a[5000] = {0};
        int number;
        int jun[5000] = {0};
        long long tanka,kazu;
        for(int i = 0; i < n; i++){
            cin >> number >> tanka >> kazu;
            a[number] += tanka * kazu;
            jun[i] = number;
        }
        bool flg = 0;
        for(int i = n; i >= 0; i--){
            if(a[jun[i]] >= 1000000){
                cout << jun[i] << endl;
                a[jun[i]] = 0;
                flg = 1;
            }
        }


        if(!flg) cout << "NA" << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cmath>

using namespace std;

int n, e, p, q;

int main() {
  while(scanf("%d", &n), n) {
    for(int i = 0; i < n; i++) {
      scanf("%d %d %d", &e, &p, &q);
      if(p * q >= 1e6) printf("%d\n", e);
    }
  }
}

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

using namespace std;

const int kSum = 1000000;

int getSum(int price, int sales)
{
  return price * sales;
}

int main()
{
  int n_employee;
  int number, price, sales;
  bool flag;
  map<int, int> checkEmp;
  vector<int> empNumbers;

  while(cin >> n_employee){
    if(n_employee == 0){
      break;
    }

    flag = true;

    for(int i = 0; i < n_employee; ++i){
      cin >> number >> price >> sales;

      if(checkEmp.find(number) != checkEmp.end()){
	checkEmp[number] += getSum(price, sales);
      } else {
	checkEmp[number] = getSum(price, sales);
	empNumbers.push_back(number);
      }
    }

    int length = empNumbers.size();
    for(int i = 0; i < length; ++i){
      if(checkEmp[empNumbers[i]] >= kSum){
	cout << empNumbers[i] << endl;
	flag = false;
      }
    }

    if(flag){
      cout << "NA" << endl;
    }
    checkEmp.clear();
  }

  return 0;
}

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

long long worker[4001];

void init() {
  for(int i = 0; i < 4001; ++i) {
	worker[i] = 0;
  }
}

int main() {
  int n, id;
  long long p, q;
  while(cin >> n) {
	if(!n) break;

	init();
	for(int i = 0; i < n; ++i) {
	  cin >> id >> p >> q;
	  worker[id] += p * q;
	}

	bool ret = 0;
	for(int i = 1; i < 4001; ++i) {
	  if(worker[i] >= 1000000) {
		cout << i << endl;
		ret = 1;
	  }
	}
	
	if(!ret) {
	  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 >= 1000000) v.pb(x.fi);
    }
    sort(all(v));
    if (v.size()) {
      rep(i, v.size()) cout << v[i] << endl;
    } else {
      cout << "NA" << endl;
    }
  }
}

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

typedef long long ll;

int main()
{
	int n;
	std::map<int, ll> m;

	while( std::cin >> n, n )
	{
		m.clear();

		for( ll a, b, c, i = 0; i < n; ++i )
		{
			std::cin >> a >> b >> c;
			m[a] += b * c;
		}

		bool f = false;
		for( auto it = m.begin(); it != m.end(); ++it )
			if( it->second >= 1000000 )
				std::cout << it->first << std::endl, f = true;

		if( !f )
			std::cout << "NA" << std::endl;
	}
	return 0;
}