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 <cstdio>
using namespace std;

#define TAR 1000000

int main() {
	int n,num,ch;
	unsigned long t,k;
	while(cin >> n){
		ch = 0;
		while(n){
			scanf("%d %ld %ld",&num,&t,&k);
			if(k!=0){
				if(t > TAR/k){
					ch++;
				}else if((t == TAR/k)&&(TAR%k == 0)){
					ch++;
				}
				if(((--n)==0)&&(ch==0)){
					cout << "NA" << endl;
				}
			}
		}
	}
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;
int main() {
    int n;
    while (cin >> n && n) {
        unordered_map<int, int> pos;
        vector<pair<int, int>> res(4001);
        for (int i=1; i<=n; ++i) {
            int no, price, quantity;
            cin >> no >> price >> quantity;
            if ( ! pos[no]) {
                pos[no] = i;
                res[pos[no]].first = no;
            }
            res[pos[no]].second += price * quantity;
        }

        bool NA = true;
        for (int i=0; i<(int)res.size(); ++i) {
            if (res[i].second >= 1000000) {
                cout << res[i].first << endl;
                NA = false;
            }
        }
        if (NA)
            cout << "NA" << endl;
    }
    return 0;
}

C++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
template<class _T>
inline void _prfe(const char *_n, _T _c, bool _p = false){
    ITER(_c) _it=_c.begin();
    if(_p){ cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{ cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

const int limit = 1000000;

int main(){
    int n;
    while(cin >> n){
        if(n == 0) break;
        map<int,int> idtbl;
        map<int,ll> valtbl;
        REP(i,n){
            int id,v,n;
            cin >> id >> v >> n;
            if(valtbl.find(id) != valtbl.end()){
                valtbl[id] += (ll)v*n;
            } else {
                idtbl[i] = id;
                valtbl[id] = (ll)v*n;
            }
        }
        bool flag = false;
        FOREACH(it,idtbl){
            if(valtbl[it->second] >= limit){
                cout << it->second << endl;
                flag = true;
            }
        }
        if(!flag){
            cout << "NA" << endl;
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    int n; cin >> n;
    do {
        int e[n], p[n], q[n];
        int tmp[4001] = {};
        int flag = 0;
        rep(i, n) cin >> e[i] >> p[i] >> q[i];
        for (int i = 0; i < n; i++) {
            tmp[e[i]] += p[i] * q[i];
        }
        for (int i = 0; i < 4001; i++) {
            if (tmp[i] >= 1000000) {
                cout << i << endl;
                flag = 1;
            }
        }
        if (flag == 0) cout << "NA" << endl;
        cin >> n;
    } while(n != 0);

    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


typedef int ll;


using namespace std;

int main()
{
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0) break;

		vector<int> order;
		map<int, ll> sale;
		while (n--)
		{
			int no, value, num;
			scanf("%d %d %d", &no, &value, &num);
			if (!sale[no])
			{
				sale.insert(make_pair(no, 0));
				order.push_back(no);
			}
			ll t = (ll)value * num;
			sale[no] += t;
		}
		bool any = false;
		for (int i = 0; i < order.size(); ++i)
		{
			if (sale[order[i]] >= 1000000)
			{
				printf("%d\n", order[i]);
				any = true;
			}
		}
		if (!any)
			printf("NA\n");
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{

    int n=1,num,tanka,suryo;
    long long sum[4001]={0};
    int jyun[100000000]={0};
    bool w[4001]={false};
    bool na=true;
    while(true){
        cin>>n;
        if(n==0){
            return 0;
        }
        for(int i=0;i<n;i++){//ツ禿シツ療債つウツづェツつスツ値ツづーツ各ツ配ツ療ア(ツ偲青暗オツ氾板債づ可格ツ納)
            cin>>num>>tanka>>suryo;
            jyun[i]=num;
            sum[num]+=tanka*suryo;
        }
        for(int i=0;i<=100000000;i++){
            if(sum[jyun[i]]>=1000000){if(!w[jyun[i]]){cout<<jyun[i]<<endl;w[jyun[i]]=true;}na=false;}
            sum[i]=0;//ツ篠淞づ可使ツつ、ツづヲツつ、ツづ可渉可甘コツ可サツづーツつオツづつィツつュ
            jyun[i]=0;
        }
        if(na)cout<<"NA"<<endl;
        na=true;
        for(int i=0;i<=4000;i++){
            w[i]=false;
        }
    }
}