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<cstdio>
#include<map>
#include<vector>
std::vector<std::pair<int, long long>> pq;
int main() {
	int n, i, e;
	long long p, q;
	bool match;
	while (true) {
		scanf("%d", &n);
		if (n == 0)break;
		for (i = 0; i < n; i++) {
			scanf("%d%lld%lld", &e, &p, &q);
			match = false;
			for (auto itr = pq.begin(); itr != pq.end(); itr++) {
				if (itr->first == e) {
					itr->second += p*q;
					match = true;
					break;
				}
			}
			if (!match)pq.push_back(std::make_pair(e, p*q));
		}
		match = false;
		for (auto itr = pq.begin(); itr != pq.end(); itr++) {
			if (itr->second >= 1000000) {
				printf("%d\n", itr->first);
				match = true;
			}
		}
		if (!match)printf("NA\n");
		pq.clear();
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <utility>
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;


int main() {
	int n;
	while(scanf("%d\n", &n), n){
		vector<pair<int, ll>> v;
		rep(i,n) {
			int x, y, z;
			cin >> x >> y >> z;
			bool f = false;
			for(int j = 0; j < v.size(); ++j) {
				if(v[j].first == x) {
					v[j].second += y * z;
					f = true;
					break;
				}
			}
			if(!f) {
				v.push_back(make_pair(x, (ll)(y * z)));
			}
		}
		bool flag = false;
		for(int j = 0; j < v.size(); ++j) {
			if(v[j].second >= 1000000) {
				flag = true;
				cout << v[j].first << endl;
			}
		}
		if(!flag) cout << "NA" << endl;
	}
	return 0;
}

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

int main() {
  int n;

  while(cin >> n, n) {
    vector<int> ans;
    int e, p, m;

    for(int i = 0; i < n; i++) {
      cin >> e >> p >> m;
      if(p*m >= 1000000) {
	bool b = true;
	auto it = ans.begin(); 
	while(it != ans.end()) {
	  if(*it == e) b = false;;
	  it++;
	}
	if(b) ans.push_back(e);
      }
    }
    

    if(ans.empty()) {
      cout << "NA" << endl;
    } else {
      auto it = ans.begin();
      while(it != ans.end()) {
	cout << *it << endl;
	it++;
      }
    }
  }
}

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

class CMem {
public :
	CMem() { m_sale = 0; m_rank = 0; m_mill = false; }
	void Idata(long long sale);
	void ONmill() { m_mill = true; }
	bool Irank(int rank);
	int Orank() { return m_rank; }
	bool Omill() { return m_mill; }
private :
	bool m_mill;
	long long m_sale;
	int m_rank;
};

void CMem::Idata(long long sale) {
	if(m_mill == false) {
		m_sale += sale;
		if(m_sale >= 1000000) {
			m_mill = true;
		}
	}
}

bool CMem::Irank(int rank) {
	if(m_rank == 0) {
		m_rank = rank;
		return true;
	}
	else {
		return false;
	}
}

int main(void)
{
	while(1) {
		CMem member[4001];
		bool NA = true;
		int n, id, rank = 1, mrank;
		long long asale, scale, sale;

		cin >> n;
		if(n == 0) break;

		for(int i = 0; i < n; i++) {
			cin >> id >> asale >> scale;
			sale = asale * scale;

			if(member[id].Irank(rank) == true) { rank++; }
			if(sale >= (long long)1000000) { member[id].ONmill(); }
			else { member[id].Idata(sale); }
		}

		mrank = rank - 1;

		for(rank = 1; rank <= mrank; rank++) {
			for(int i = 1; i <= 4000; i++) {
				if(member[i].Orank() == rank && member[i].Omill() == true) {
					cout << i << endl;
					NA = false;
				}
			}
		}

		if(NA == true) cout << "NA" << endl;
	}
	return 0;
}

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

int main(){
	int n;
	while(1){
		map<int, long long> mp;
		bool isNA = false;
		cin >> n;
		if(n==0)break;
		while(n){
			int id,price,number;
			cin >> id >> price >> number;
			//cout << number;
			if(mp[id]<1000000 && mp[id]+(long long)price*number>=1000000){
				cout << id << endl;
				isNA =true;
			}
			mp[id]+=(long long)price*number;
			n--;
		}
		if(!isNA) cout << "NA" <<endl;
	}
	return 0;	
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

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

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


ll n;

int main(){
	while(cin>>n,n!=0){
		map <ll,ll> id;
		vector<ll> a;
		rep(i,n){
			ll t1,t2,t3;
			a.push_back(t1);
			cin>>t1>>t2>>t3;
			if(id[t1]>0){
				id[t1]+=t2*t3;
			}
			else{
				id[t1]=t2*t3;
			}
		}
		bool f=true;
		rep(i,a.size()){
			if(id[a[i]]>=1000000){
				cout<<a[i]<<endl;
				id[a[i]]=0;
				f=false;
			}
		}
		if(f) cout<<"NA"<<endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int n;
    while (cin >> n, n) {
        vector<pair<int,ll>> s(4000, {inf, 0});
        vector<bool> ip(4000,false);
        REP(i,n) {
            ll e,p,q;
            cin >> e >> p >> q;
            e--;
            if (ip[e]) {
                s[e].se += p*q;
            }
            else {
                s[e] = make_pair(i,p*q);
                ip[e] = true;
            }
        }
        vector<pair<int,int>> ans;
        REP(i, 4000) {
            if (s[i].se >= 1000000) {
                ans.pb({s[i].fi, i+1});
            }
        }
        sort(ALL(ans));
        REP(i,ans.size()) cout << ans[i].se << endl;
        if (ans.size() == 0) 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;
typedef long long ll;
#define INF 1000000000
#define EPS 0.000001

int n;
struct date{
	int num;
	ll total;
	bool flag;
}D[4000];
 
int main(){
 
	while(true){
	
		cin >> n;
		if(n == 0)
			break;
		int count = 0;
		bool flag = false;
		for(int i = 0; i < n; i++){
			int kari;
			cin >> kari;
			for(int j = 0; j < count; j++){
				if(D[j].num == kari){
					flag = true;
					int kari1, kari2;
					cin >> kari1 >> kari2;
					if(D[j].total + kari1*kari2 >= 1000000){
						D[j].flag = true;
					}
				}
			}
			if(!flag){
				D[count].num = kari;
				int kari1, kari2;
				cin >> kari1 >> kari2;
				D[count].total = kari1*kari2;
				D[count].flag = false;
				if(D[count].total >= 1000000)
					D[count].flag = true;
				count++;
			}
		}

		bool flag2 = false;
		for(int i = 0; i < count; i++){
			if(D[i].flag){
				flag2 = true;
				printf("%d\n", D[i].num);
			}
		}
		if(!flag2){
			printf("NA\n");
		}

	}

	


	return 0;
 
}

C++: #include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
  int n,f;
  long long a,b,c;
  while(std::cin>>n,n){
		map<int,long long> m;
		vector<int> v;
		f=1;
    for(;n;n--){
      std::cin>>a>>b>>c;
      if(!m[a])v.push_back(a);
      m[a] += b*c;
    }
    
    for(int i=0;i<v.size();i++){
      if(m[v[i]]>=1000000){
				f=0;
				cout<<v[i]<<endl;}
    }
    if(f)cout<<"NA"<<endl;
  }
  return 0;
}