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>
 
using namespace std;
 
const long long Target = 1000000;
 
struct Shain {
    int no;
    long long sum;
};
 
int main( void )
{
    vector<Shain> shain;
    int n;
    while(cin >> n, n) {
        shain.clear();
        for(int i=0; i < n; ++i) {
            int no, kin, num;
            cin >> no >> kin >> num;
            bool hit = false;
            vector<Shain>::iterator it = shain.begin();
            while(it != shain.end()) {
                if(it->no == no) {
                    if(it->sum < Target) it->sum += (long long)(kin * num);
                    hit = true;
                    break;
                }
                ++it;
            }
            if(!hit) {
                Shain tmp;
                tmp.no = no;
                tmp.sum = (long long)(kin * num);
                shain.push_back(tmp);
            }
        }
        bool hit = false;
        vector<Shain>::iterator it = shain.begin();
        while(it != shain.end()) {
            if(it->sum >= Target) {
                cout << it->no << endl;
                hit = true;
            }
            ++it;
        }
        if(!hit)
            cout << "NA" << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;



signed main(){
  int n;
  while(cin>>n,n){
    int a,b,c;
    map<int,int> M;
    bool k=false;
    rep(i,n){
      cin>>a>>b>>c;
      M[a]+=b*c;
    }
    for(auto itr:M){
      if((itr.sec)>=1000000){
        cout<<(itr.fir)<<endl;
        k=true;
      }
    }
    if(k==false)cout<<"NA"<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,num,flag=0,flag2=0;
  long long tanka,sell;
  while(cin>>n,n!=0){
    flag=0;flag2=0;
    vector<int> nu;
    vector<int> vi;
    vector<pair<int,long long> > pii;
    for(int i=0;i<n;i++){
      cin>>num>>tanka>>sell;
      for(int j=0;j<vi.size();j++){
	if(num==vi[j]){
	  flag2=1;
	  break;
	}
      }
      if(flag2==0){
	flag=0;
	for(int j=0;j<pii.size();j++){
	  if(pii[j].first==num){
	    flag=1;
	    pii.push_back(make_pair(num,((tanka*sell)+pii[j].second)));
	    if(((tanka*sell)+pii[j].second)>=1000000)
	      vi.push_back(num);
	    break;
	  }
	}
	if(flag==0){
	  nu.push_back(num);
	  pii.push_back(make_pair(num,tanka*sell));
	  if((tanka*sell)>=1000000)
	    vi.push_back(num);
	}
      }
    }
    if(vi.empty())
      cout<<"NA"<<endl;
    else{
      for(int k=0;k<nu.size();k++){
	for(int l=0;l<vi.size();l++){
	  if(nu[k]==vi[l])
	    cout<<nu[k]<<endl;
	}
      }
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
main(){
	int n;
	while(cin>>n,n){
		int c=0,data[4000+1],no[n];
		for(int i=0;i<=4000;++i)data[i]=0;
		for(int i=0;i<n;++i){
			no[i]=0;
			int n2,tan,num;
			cin>>n2>>tan>>num;
			if(!data[n2])no[i]=n2;
			data[n2]+=tan*num;
		}
		for(int i=0;i<n;++i){
			int n2=no[i];
			if(data[n2]>=1000000){
				cout<<n2<<endl;
				c++;
			}
		}
		if(!c)cout<<"NA"<<endl;
	}
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n && n)
	{
		bool f = true;
		set<int> table;
		vector<ll> v(4005, 0);

		rep(i, n)
		{
			int num;
			ll a, s;
			cin >> num >> a >> s;

			if(table.find(num) == table.end())
			{
				v[num] += a * s;
				if(1000000 <= v[num])
				{
					f = false;
					table.insert(num);
					cout << num << endl;
				}
			}
		}

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

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

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

		vector<int> ans;
		rep(i,n)
		{
			cin >> num >> k >> m;
			vector<int>::iterator ite = find(ans.begin(),ans.end(),num);
			if(ite == ans.end())
			{
				value[num] += k*m;
				
				if(value[num] >= 1000000)
				{
					ans.push_back(num);
				}
			}			
		}

		if(ans.size() == 0)
		{
			cout << "NA" << endl;
		}
		else
		{
			rep(i,ans.size())
			{
				cout << ans[i] << endl;
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
int main() {
	std::vector<int> v;
	while (1) {
		int count=0;
		int n;
		std::cin >> n;
		if (n == 0) {
			break;
		}
		std::vector<std::vector<int>> a(n, std::vector<int>(3));
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j) {
				std::cin >> a[i][j];
			}
		}
		std::vector<int>num(n);
		for (int i = 0; i < n; ++i) {
			for (int j = 1; j < n; ++j) {
				if (a[i][0] == a[j][0]) {
					num[i] += a[i][1] * a[i][2] + a[j][1] * a[j][2];
					++count;
					break;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			if (count == 0) {
				v.push_back(0);
			}
			if (num[i] >= 1000000) {
				if (count >= 2) {
					sort(num.begin(), num.end());
				}
				v.push_back(a[i][0]);
			}
		}
	}
	for (int i = 0; i < v.size(); ++i) {
		if (v[i] == 0) {
			std::cout << "NA" << std::endl;
		}
		else {
			std::cout << v[i] << std::endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<map>
#include<utility>
#include<queue>

using namespace std;




int main(){
	int n;
	while (cin >> n&&n != 0)
	{
		map< int, long long int> staff;
		queue< int> Queue;
		bool cnt = false;

		for (size_t i = 0; i < n; i++)
		{
			int num;
			long long b, c;
			cin >> num >> b >> c;

			staff[num] += (long long int) (b*c);
		}
		for (map< int, long long int>::iterator itr = staff.begin(); itr != staff.end(); itr++){
			if (itr->second >= 1000000)
				Queue.push(itr->first);

		}
		if (Queue.size() == 0){
			cout << "NA" << endl;
		}
		else
		{
			while (Queue.size() > 0){

				cout << Queue.front() << endl;
				Queue.pop();

			}

		}

	}

	return 0;
}