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<vector>
int main() {
	std::vector<int> a;
	while (true) {
		int n;
		int c = 0;
		std::cin >> n;
		if (n == 0) {
			break;
		}
		std::vector<int> v(n), w(n);
		int t, u;
		for (int i = 0; i < n; ++i) {
			std::cin >> w[i] >> t >> u;
			v[i] = t*u;
		}
		for (int i = 0; i < n; ++i) {
			for (int l = 0; l < n; ++l) {
				if ((v[i] == v[l]) && (i != l)) {
					v[i] += v[l];
					v.erase(v.begin() + l);
					n -= 1;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			if (v[i] >= 1000000) {
				a.push_back(w[i]);
				++c;
			}
			if ((c==0)&&(i==n-1)) {
				a.push_back(0);
			}
		}
		v.clear();
		w.clear();
	}
	for (int i = 0; i < a.size(); ++i) {
		if (a[i] == 0)std::cout << "NA" << std::endl;
		else std::cout << a[i] << std::endl;
	}
}

C++: #include<iostream>

using namespace std;

int main(){
	bool tf = 0;
	int n,e,p,q;
	while(cin >> n){
		if(n == 0){
			return 0;
		}
		int r[4001]={0};
		tf = 0;
		for(int i = 0; i < n; i++){
			cin >> e >> p >> q;
			r[e] += p * q;
			//r[e] = r[e] + p*q;
		}
		for(int i = 1; i <= 4000; i++){
			if(r[i] >= 1000000){
				cout << i << endl;
				tf = 1;
			}
		}
		if(tf != 1){
				cout << "NA" << endl;
			}
	}
	
	return 0;
}

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

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

using namespace std;

int main()
{
	long long value[4001];
	vector<int> v;

	int n,num,k,m;
	while(cin >> n && n)
	{
		memset(value,0,sizeof(value));
		v.clear();

		rep(i,n)
		{
			cin >> num >> k >> m;
			value[num] += k*m;

			vector<int>::iterator ite = find(v.begin(),v.end(),num);
			if(ite == v.end())
			{
				v.push_back(num);
			}
		}

		bool flag = true;
		rep(i,v.size())
		{
			if(value[v[i]] >= 1000000)
			{
				flag = false;
				cout << v[i] << 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;
int main()
{
	int n,x,y,z;
	int a = 0;
	int g[4000];

	while(true){
	    int b=0;
		cin >> n;

		if(n==0){
			break;
		}
		for(int i=0 ;i<n ;i++){

	       cin >> x >> y >> z;

		   a = y*z;
		   if(a>=1000000){
			
			 g[i] = x;
			 b++;  
		     }
		}
	
		
	if(b>0){
	     	for(int i=0 ;i<n ;i++){
			cout << g[i] << endl;			
		}	
	}	
	else	
		cout << "NA" << endl;
	}

	return 0;
}

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


#define rep(i, b) for(int i = 0; i < b; i++)
#define repi(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = a; i > b; i--)

#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

	typedef long long ll;

using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		ll sale[4096] = { 0 };
		bool ok = true;
		rep(i, n) {
			ll s, h, u;
			cin >> s >> h >> u;
			if (sale[s] < 1000000) {
				sale[s] += h * u;
				if (sale[s] >= 1000000) {
					cout << s << endl;
					ok = false;
				}
			}
		}

		if (ok) cout << "NA" << endl;
	}
}

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

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

using namespace std;

typedef long long ll;

int main(){
  int n;
  while(cin>>n, n){
    bool f = false;
    REP(i,n){
      int a;
      ll b,c;
      cin>>a>>b>>c;
      if(b*c >= (ll)1000000){
	cout << a << endl;
	f = true;
      }
    }
    if(!f) cout << "NA" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <stdio.h>

using namespace std;

typedef long long ll;

int n, id, p, q;
ll amount;

const ll MAX = 1000000;

struct Mem {
    int index;
    int id;

    Mem(int _index, int _id) { index = _index; id = _id; }

    bool operator<(const Mem& m) const {
        return index < m.index;
    }
};

map<Mem, ll> m;
map<Mem, ll>::iterator it;
vector<int> ans;

int main(void) {
    freopen("i.in", "r", stdin);
    while(~scanf("%d", &n)) {
        if(n == 0) break;
        m.clear();
        for(int i = 0; i < n; i++) {
            scanf("%d%d%d", &id, &p, &q);
            amount = p*q;
            Mem tmp(i, id);
            m[tmp] += amount;
        }
        ans.clear();
        for(it = m.begin(); it != m.end(); it++) {
            if((*it).second >= MAX) {
                ans.push_back((*it).first.id);
            }
        }
        if(ans.empty()) {
            printf("NA\n");
        } else {
            for(int i = 0; i < (int) ans.size(); i++) {
                printf("%d\n", ans[i]);
            }
        }
    }
    return 0;
}