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

#define BUF 100000

typedef struct syaing
{
	int bango[BUF];
	int ne[BUF];
	int kazu[BUF];
} deta;

int main()
{
	deta f;
	int a,i,check[BUF],lek,kof[100000],nl=0;
	while(1)
	{
		memset(check,0,sizeof(int)*BUF);
		memset(f.bango,0,sizeof(int)*BUF);
		memset(f.kazu,0,sizeof(int)*BUF);
		memset(f.ne,0,sizeof(int)*BUF);
		lek=0;
		scanf("%d",&a);
		if(a==0)
			break;
		for(i=0;i<a;i++)
		{
			scanf("%d%d%d",&f.bango[i],&f.kazu[i],&f.ne[i]);
			if(f.kazu[i]*f.ne[i]>=1000000)
				check[i]=f.bango[i];
		}
		for(i=0;i<a;i++)
		{
			if(check[i]!=0)
			{
				lek++;
				kof[nl]=check[i];
				nl++;
			}
		}
		if(lek==0)
		{
			kof[nl]=0;
			nl++;
		}
	}
	for(i=0;i<nl;i++)
	{
		if(kof[i]==0)
			printf("NA\n");
		else
			printf("%d\n",kof[i]);
	}
	return 0;
}

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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  int n;
  while(cin >> n, n) {
    map<int, int> m;
    rep(i, n) {
      int p, q, r; cin >> p >> q >> r;
      if(m.find(p) == m.end()) {
        m[p] = q*r;         
      } else {
        m[p] += q*r;
      }
    }

    bool b = false;
    map<int,int>::iterator it = m.begin();
    while(it != m.end()) {
      if(it->second >= 1000000) {
          cout << it->first << endl;
          b = true;         
      }
      it++;
    }
    if(!b) cout << "NA" << endl;
  }
}

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

using namespace std;

int n, e, p, q;

int main() {
  while(scanf("%d", &n), n) {
    for(int i = 0, i < n; i++) {
      scanf("%d %d %d", e, p, q);
      if(p * q >= 1e6) printf("%d\n", e);
    }
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <sstream>
#include <map>

using namespace std;

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

typedef long long ll;

int main(){
    int n;
    while (cin >> n && n){
        // id, ord, sell
        map<int, pair<int,int>> m;
        int c = 0;
        rep(i, n){
            ll id, unit, num;
            cin >> id >> unit >> num;
            if (m.count(id)==0){
                m[id].first = c++;
            }
            m[id].second += unit * num;
        }
        vector<pair<int,int>> ans;
        for (auto & p : m){
            if (p.second.second >= 1000000){
                ans.push_back(make_pair(p.second.first, p.first));
            }
        }
        sort(ans.begin(), ans.end());
        if (ans.size()){
            rep(i, ans.size()){
                cout << ans[i].second << endl;
            }
        }
        else{
            cout << "NA" << endl;
        }
    }
}

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

static const int invalid_order = 1000000;
struct data {
	int ID;
	long long total;
	int order;

	data() {
		ID = -1;
		total = 0;
		order = invalid_order;
	}
	data(int n) {
		ID = n;
		total = 0;
		order = invalid_order;
	}

	bool operator<(const data d) const {
		return order < d.order;
	}
};

int main() {
	int n;

	while(cin >> n, n) {
		int price, sale;
		int ID;
		data table[4096];
		bool flag = false;
		int order_count = 0;

		for(int i = 0; i < 4096; i++) {
			table[i].ID = i;
		}

		for(int i = 0; i < n; i++) {
			// input
			/*
			char in[128];
			char ID_s[32], price_s[32], sale_s[32];
			int j, k;
			fgets(in, 120, stdin);
			for(j = 0,k = 0; in[j + k] != ' ' && in[j + k] != ';'; k++)
				ID_s[k] = in[j + k];
			ID_s[k] = '\0';
			j = k + 1;
			for(k = 0; in[j + k] != ' ' && in[j + k] != ';'; k++)
				price_s[k] = in[j + k];
			price_s[k] = '\0';
			j += k + 1;
			for(k = 0; in[j + k] != ' ' && in[j + k] != ';' && in[j + k] && in[j + k] != '\n'; k++)
				sale_s[k] = in[j + k];
			sale_s[k] = '\0';

			ID = atoi(ID_s);
			price = atoi(price_s);
			sale = atoi(sale_s);
			// */ cin >> ID >> price >> sale;

			if(table[ID].order == invalid_order) {
				table[ID].order = order_count;
				order_count++;
			}
			table[ID].total += (long long)price * sale;
		}

		sort(table, table + 4096);

		for(int i = 0; i < order_count; i++) {
			if(table[i].total >= 1000000) {
				cout << table[i].ID << endl;
				flag = true;
			}
		}

		if(!flag)
			cout << "NA" << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
	ll t,s,total[4010];
	int sb[100000];
	int n;
	for(;cin>>n,n;){
		bool f=false;
		rep(i,4010)total[i]=0;
		rep(i,n)sb[i]=0;
		rep(i,n){
			int p;
			cin>>p>>t>>s;
			total[p]+=t*s;
			sb[i]=p;
		}
		rep(i,4001){
			if(total[sb[i]]>=1000000){
				cout<<sb[i]<<endl;
				total[sb[i]]=0;
				f=true;
			}
		}
		if(!f)cout<<"NA\n";
	}
	return 0;
}

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

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		vector<long long> id(n),price(n),num(n);
		for(int i=0;i<n;i++)
			cin>>id[i]>>price[i]>>num[i];
		
		int counter=0;
		for(int i=0;i<n;i++){
			if(price[i]*num[i]>=1000000LL){
				cout<<id[i]<<endl;
				counter++;
			}
		}
		if(counter==0)
			cout<<"NA"<<endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vi v(4005,0);
    rep(i,n){
      ll e,p,q;
      cin>>e>>p>>q;
      v[e]+=p*q;
    }
    vi ans;
    rep(i,4005)
      if(v[i]>=1000000)ans.push_back(i);
    if(ans.size())
      rep(i,ans.size())cout<<ans[i]<<endl;
    else
      cout<<"NA"<<endl;
  }
}