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 <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

/*
  AOJ :: 0100
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0100&lang=jp
 */

typedef long long ll;

int main(){
    int n,num,tanka,count,i;
    map<int, pair<int,ll> > mipii;

    while( cin >> n, n ){
        // init
        mipii.clear();

        // input
        rep(i,n){
            cin >> num >> tanka >> count;

            if( mipii.count(num) == 0 ){
                mipii[num] = make_pair(i, (ll)tanka * (ll)count);
            }
            else{
                pair<int,ll> tmp = mipii[num];
                tmp.second = max(tmp.second, (ll)tanka * (ll)count);
                mipii[num] = tmp;
            }
        }

        vector<pair<int,int> > vp;
        foreach(it,mipii){
            if( it->second.second >= 1000000 ){
                vp.push_back(make_pair(it->second.first, it->first));
            }
        }
        sort(all(vp));

        if( vp.size() == 0 ){
            puts("NA");
        }
        else{
            rep(i,vp.size()){
                printf("%d\n",vp[i].second);
            }
        }
    }

    return 0;
}

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

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) return 0;
        vector<int> id;
        // create vector the number of element is 4001
        // initialize all elements with -1
        vector<long long> sale(4001, -1);
        int x, y, z;

       for (int i=0; i < n; i++) {
           cin >> x >> y >> z;
           if (sale[x] == -1) {
               sale[x] = 0;
               id.push_back(x);
           }
           sale[x] += (long long) y * z;
       }
       bool na = true;
       for (int i=0; i < (int)id.size(); i++){
           if (sale[id[i]] >= 1000000) {
               cout << id[i] << endl;
               na = false;
           }
       }
       if (na) cout << "NA" << endl;
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

#define INF 999999
#define MAX_V 999

using namespace std;

int main(){
	int n, id, val, num;
	vector<int> ans;
	vector<int> com(4000);
	while(cin>>n,n){
		ans.clear();
		rep(i,4000)	com[i]=0;
		rep(i,n){
			cin>>id>>val>>num;
			com[id-1]+=val*num;
		}
		rep(i,4000){
			if(com[i]>=1000000){
				ans.push_back(i+1);
			}
		}
		if(ans.size()){
			rep(i,ans.size())
				cout<<ans[i]<<endl;
		}else{
			cout<<"NA"<<endl;
		}
	}
	
	return 0;
	
}

C++: // a.c.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
	int n;
	int ban, tan, suu;
	long long int bango[4001];
	int flg,i;
	while (1){
		for (i = 1; i <= 4000; i++){
			bango[i] = 0;
		}
		scanf_s("%d", &n);
		if (n == 0){
			break;
		}
		for (i = 0; i < n; i++){
			scanf_s("%d %d %d", &ban, &tan, &suu);
			bango[ban] += tan*suu;
		}
		flg = 0;
		for (i = 1; i <= 4000; i++){
			if (bango[i]>=1000000){
				printf("%d\n", i);
				flg = 1;
			}
		}
		if (!flg){
			printf("NA\n");
		}
	}
	return 0;
}

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

int main()
{
	int n;
	while (cin >> n, n) {
		map<int, long long> data;
		map<int, int> seq;
		for (int i = 0; i < n; ++i) {
			int bangou, tanka, kazu;
			cin >> bangou >> tanka >> kazu;
			if (data.find(bangou) == data.end()) {
				data[bangou] = 0;
				seq[bangou] = i;
			}
			data[bangou] += tanka * kazu;
		}
		vector<pair<int, int> > v;
		for (map<int, long long>::iterator it = data.begin(); it != data.end(); ++it)
			if (it->second >= 1000000)
				v.push_back(make_pair(seq[it->first], it->first));
		if (v.empty())
			cout << "NA" << endl;
		else {
			sort(v.begin(), v.end());
			for (int i = 0; i < v.size(); ++i) cout << v[i].second << endl;
		}
	}
	return 0;
}

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

using namespace std;

long long int nums[10000];

int main(){
	
	while(true){
		
		int n;
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < 10000; i++){
			nums[i] = 0;
		}
		
		for(int i = 0; i < n; i++){
			int e, p, q;
			cin >> e >> p >> q;
			nums[e] += p * q;
		}
		
		bool check = false;
		
		for(int i = 0; i <= 4000; i++){
			if(nums[i] >= 1000000){
				cout << i << endl;
				check = true;
			}
		}
		
		if(!check){
			cout << "NA" << endl;
		}
	}
	return 0;
}

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

int main()
{
    int n;
    while(cin >> n,n){
        bool hantei=true,kaburi[n];
        long long number[n],price[n],quantity[n],sale[n];
        for(int i=0 ; i<n ; i++){
            cin >> number[i] >> price[i] >> quantity[i];
            sale[i]=price[i]*quantity[i];
        }
        for(int i=0 ; i<n-1 ; i++){
            for(int j=i+1 ; j<n ; j++){
                if(number[i]==number[j]){
                    kaburi[j]=true;
                    sale[i]+=(price[j]*quantity[j]);
                }
            }
        }
        for(int i=0 ; i<n ; i++){
            if(kaburi[i]){
                continue;
            }
            if(sale[i]>=1000000){
                cout << number[i] << endl;
                hantei=false;
            }
        }
        if(hantei){
            cout << "NA" << endl;
        }
    }
    return 0;
}

C++: //Sale Result
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<string> order;//入力された順番
map<string, ll> mp;

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    vector<string>::iterator it;
    order.clear();
    mp.clear();
    for(int i=0; i<n; i++){
      string p;
      ll u, a;
      cin>>p>>u>>a;
      it=find(order.begin(), order.end(), p);
      if(it==order.end()){
        order.push_back(p);
        mp.insert(make_pair<string, ll>(p, 0));
      }
      mp[p]+=u*a;
    }
    bool flag=true;
    for(it=order.begin(); it!=order.end(); it++){
      if(mp[*it]>=1000000){
        cout<<*it<<endl;
        flag=false;
      }
    }
    if(flag)cout<<"NA"<<endl;
  }
  return 0;
}