Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		sales := make([]int, 4000)
		members := make([]int, 0)
		memberCheck := make(map[int]bool)

		for i := 0; i < n; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			e, _ := strconv.Atoi(input[0])
			p, _ := strconv.Atoi(input[1])
			q, _ := strconv.Atoi(input[2])

			if e >= 1 && e <= 4000 && memberCheck[e] == false {
				members = append(members, e)
				memberCheck[e] = true
			}
			sales[e-1] += p * q
		}

		emptyFlag := true
		for _, v := range members {
			if sales[v-1] >= 1000000 {
				fmt.Println(v)
				emptyFlag = false
			}
		}

		if emptyFlag == true {
			fmt.Println("NA")
		}
	}
}

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

using namespace std;

struct data{
  int id;
  long  price;
  long  amount;
  long long rate;
};

int main(){
  int n=0;
  while(1){
    cin>>n;
    if(n==0){return 0;}
    vector<struct data> data(n);
    int c=0;
    for(int i=0;i<n;i++){
      scanf("%d %l %l",&data[i].id,&data[i].price,&data[i].amount);
      data[i].rate=data[i].price*data[i].amount;
    }
    vector<struct data> res(n);
    for(int i=0;i<n;i++){
      res[i].id=0;
      res[i].rate=0;
    }
    for(int i=0;i<n;i++){
      int find=0;
      for(int j=0;j<i;j++){
	if(data[i].id==res[j].id){
	  res[j].rate+=data[i].rate;
	  find=1;
	  break;
	}
      }
      if(find==0){
	res[i].id=data[i].id;
	res[i].rate=data[i].rate;
      }
    }
    for(int i=0;i<n;i++){
      if(res[i].id!=0&&res[i].rate>=1000000){
	cout<<data[i].id<<"\n";
	c++;
      }
    }
    if(c==0){
      cout<<"NA\n";
    }
  }
  return 0;
}

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;
}