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 <array>

template<typename itr, typename func>
func for_each_withindex(itr fi, itr l, func f){
	unsigned i{};
	for(; fi!=l; ++fi,++i){
		f(*fi,i);
	}
	return f;
}

int main(int argc, char const* argv[])
{
	unsigned n{};
	while (std::cin >> n,n != 0) {
		long long e{}, p{}, q{};
		bool isna{true};
		std::array<long long,4001> es{};
		std::array<bool,4001> esadup{};
		for (unsigned i = 0; i < n; i++) {
			std::cin >> e >> p >> q;
			es.at(e) += p * q;
			if (es.at(e) >= 1000000 && ! esadup.at(e)) {
				std::cout << e << std::endl;
				esadup.at(e) = true;
				isna = false;
			}
		}
		//for_each_withindex(es.begin(), es.end(), [&isna](long long sell,long long e){ 
		//		if (sell>=1000000) {
		//		std::cout << sell << ":";
		//		std::cout << e << std::endl;
		//		isna = false;
		//		}});
		if (isna) {
			std::cout << "NA" << std::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(1000, 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 <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<ll,ll> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b,c;
  while(cin >> n && n){
    set<int> s;
    vector<pair<ll,ll>> v(4001,make_pair(0,0));
    vary(ll,v2,4001,0);
    int cnt=0;
    rep(i,n){
      cin >> a >> b >> c;
      if(s.insert(a).se){
        ++cnt;
        v[a].se = cnt;
        v[a].fi = a;
      }
      if(v2[a] <= 1000000)
        v2[a] += b * c;
    }
    sort(all(v),[](const pii &p,const pii &p2){return p.se < p2.se;});
    bool f = false;
    REP(i,1,v.size()){
      if(v2[v[i].fi] >= 1000000){
        cout << v[i].fi<<endl;
        f = true;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}

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

int main(){
	long long int n,i,price[4000],a,b,c;
	bool flag;
	while(cin >> n && n){
		flag = false;
		memset(price,'\0',sizeof(price));
		for(i = 0;i < n;++i){
			cin >> a >> b >> c;
			price[a-1] += b * c;
		}
		for(i = 0;i < 4000;++i){
			if(price[i] >= 1000000){
				cout << i + 1 << endl;
				flag = true;
			}
		}
		if(flag == false) cout << "NA" << endl;
	}
	return 0;
}

C++: #include <stdio.h>
 
 
int n;
long long num[4000],tanka[4000],sale_num[4000];
int sale_all[4001],judge[4001];
 
int main(void)
{
int i,j,k;
     
while(scanf("%d",&n),n!=0){

    for(i=0;i<n;i++){
        scanf("%d%d%d",&num[i],&tanka[i],&sale_num[i]);

    }

	//初期化
    k=0;
    for(j=0;j<4001;j++){
		judge[j]=0;
		sale_all[j]=0;
	}

	//idに対応したsaleに+
	for(i=0;i<n;i++){
		sale_all[num[i]] += tanka[i]*sale_num[i];
	}

    for(i =0; i < n; i++){
        if(sale_all[num[i]] >= 1000000){
            printf("%d\n",num[i]);
            judge[num[i]]=1;
            k=1;
        }
    }

    if(k!=1)printf("NA\n");
}
 
    return 0;
}

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

int sale[4001];

int main(){
	int p;
	while(cin >> p, p){
		for(int i=0; i < 4001; i++) sale[i] = 0;
		int id, price, num, result=0;

		for(int i=0; i < p; i++){
			cin >> id >> price >> num;
			sale[id] += price * num;
		}
		for(int i=0; i < 4001; i++){
			if(1000000 <= sale[i]){
				cout << i << endl;
				result++;
			}
		}
		if(result == 0) cout << "NA" << endl;
	}
}

C++: #include<iostream>

using namespace std;

int main(){
	bool tf = 0;
	int n,e,p,q;
	while(cin >> n){
		if(n == 0){
			break;
		}
		int r[4001]={0};
		tf = 0;
		for(int i = 0; i < n; i++){
			cin >> e >> p >> q;
			r[e] += p * q;
			//r[e] = r[e] + p*q;
		}
		for(int i = 1; i <= 4000; i++){
			if(r[i] >= 1000000){
				cout << i << endl;
				tf = 1;
			}
		}
		if(tf != 1){
				cout << "NA" << endl;
			}
	}
	
	return 0;
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define ll long long

int main()
{
    while (1)
    {
	int n,f=0,id;
	ll price,num,p[4000];
	rep(i,4001)p[i]=0;
	cin >> n;
	if (n==0)break;
	rep(i,n)
	{
	    cin >> id >> price >> num;
	    p[id]+=price*num;
	}
	rep(i,4001)
	{
	    if (p[i] >= 1000000)
	    {
		f=1;
		cout << i << endl;
	    }
	}
	if (f==0)cout << "NA" << endl;
    }
    return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n, m;

    while(cin >> n, n){
        long long v[4010];
        rep(j, 4010) v[j] = 0;
        rep(p, n){
            long long  a, b, c;
            cin >> a >> b >> c;
            v[a] += b*c;
        }
        bool isP = false;
        rep(i, 4010) if(1000000 <= v[i]){isP = true; cout << i << endl;}
        if(!isP) cout << "NA" << endl;
}
}