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,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;
    }
  }
}

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

int main(){
  int n ,flag=0 ,num[4001] ,price[4001] ,earnings[4001] ,total[4001] ,overlap;
  while( true ){
    cin >> n;
    if( n == 0 ){
      break;
    }
    for( int i=0 ; i<n ; i++ ){ // 入力と合計を計算
      cin >> num[i] >> price[i] >> earnings[i];
      total[i] = price[i] * earnings[i];
    }

    for( int i=0 ; i<n ; i++ ){ // 重複を無くす
      overlap = num[i]; // 重複したかの判定
      for( int j=0 ; j<n ; j++ ){
	if( num[j] == overlap && i != j ){ // 重複したか
	  total[i] += total[j];
	  num[j] = -1;
	  total[j] = 0;
	}
      }
    }

    for( int i=0 ; i<n ; i++ ){ // 出力
      if( total[i] >= 1000000 ){
	cout << num[i] << endl;
	flag = 1;
      }
    }

    if( flag == 0 ){ // いなかったら
      cout << "NA" << endl;
    }
    flag = 0;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    map<int,long long int>m;
    vector<int>num;
    rep(i,n){
      long long int a,b,c;
      cin>>a>>b>>c;
      if(m.find(a)==m.end()){
	num.pb(a);
	m.insert(mp(a,b*c));
      }else{
	m[a]+=b*c;
      }
    }
    bool h=false;
    rep(i,num.size()){
      if(m[num[i]]>=1000000){
	cout<<num[i]<<endl;
	h=true;
      }
    }
    if(!h)cout<<"NA"<<endl;
  }
}

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

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;
}