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 <cstdio>
#include <vector>
using namespace std;
int main()
{
	long long n;
	while(scanf("%Ld\n", &n), n){
		vector<pair<long long, long long> > v;
		for(long long i = 0; i < n; i++){
			long long p, q, r, f = 1;
			scanf("%Ld %Ld %Ld\n", &p, &q, &r);
			for(long long j = 0; j < v.size(); j++){
				if(v[j].first == p){
					f = 0;
					v[j].second += q * r;
				}
			}
			if(f){
				pair<long long, long long> pa(p, q * r);
				v.push_back(pa);
			}
			
		}
		long long g = 1;
		for(long long i = 0; i < v.size(); i++){
			if(1000000 <= v[i].second){
				g = 0;
				printf("%Ld\n", v[i].first);
			}
		}
		if(g) puts("NA");
	}
	return 0;
}

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




int main(){
	int n;
	cin >> n;

	while(n != 0){
		vector < pair<int, int> > v(n);
		int num = 0;
		for (int i = 0; i < n; ++i){
			int id, p, q;
			cin >> id >> p >> q;
			v[i] = make_pair(id, p * q);
		}

		sort(v.begin(), v.end());
		int c = 1;

		for (int i = 0; i < n - 1; ++i){
			if(v[i].first != v[i+1].first){
				c++;
			}
		}

		vector < pair<int, int> > sum(c);
		int k = 0;
		for (int i = 0; i < c; ++i){
			sum[i] = make_pair(0, 0);
		}

		int s = 0;
		for (int i = 0; i < n ; ++i){
			s += v[i].second;
			if(i < n - 1){
				if(v[i].first != v[i+1].first){
					sum[k] = make_pair(v[i].first, s);
					s = 0;
					k++;
				}
			}else{
				sum[k] = make_pair(v[i].first, s);
			}
		}

		for (int i = 0; i < c; ++i){
			if(sum[i].second >= 1000000){
				cout << sum[i].first << endl;
				num++;
			}
		}

		if(num == 0){
			cout << "NA" << endl;
		}

		cin >> n;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	int n;
	int number[4000]={0};
	int tanka;
	int ryou;
	long long goukei[4000]={0};
	while(cin>>n,n){
		for(int i=0;i<n;i++){
			cin>>number[i];
			cin>>tanka;
			cin>>ryou;
			goukei[i]=tanka*ryou;
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(number[i]==number[j]){
					goukei[i]+=goukei[j];
					goukei[j]=0;
					}
			}
		}
		int flag=-1;
		for(int i=0;i<n;i++){
			if(goukei[i]>=1000000){
				flag=0;
				cout<<number[i]<<endl;
				}
		}
		if(flag==-1)
			cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
static const int M = 1000000;

int main()
{
  int N;
  while (cin >> N && N != 0) {
    map<int,pair<int,int> > m;
    vector<pair<int,int> > ans;
    for (int i = 0; i < N; i++) {
      int id, sell, cnt;
      cin >> id >> sell >> cnt;
      const long long n = static_cast<long long>(sell) * cnt;
      map<int,pair<int,int> >::iterator it = m.find(id);
      if (it == m.end()) {
        if (n >= static_cast<long long>(M)) {
          ans.push_back(make_pair(i, id));
          m.insert(make_pair(id, make_pair(i, M)));
        } else {
          m.insert(make_pair(id, make_pair(i, n)));
        }
      } else if (it->second.second < M) {
        if (n >= static_cast<long long>(M)) {
          ans.push_back(make_pair(it->second.first, it->first));
          it->second.second = M;
        } else {
          it->second.second += n;
          if (it->second.second > M) {
            ans.push_back(make_pair(it->second.first, it->first));
          }
        }
      }
    }
    if (ans.empty()) {
      cout << "NA" << endl;
    } else {
      sort(ans.begin(), ans.end());
      for (vector<pair<int,int> >::const_iterator it(ans.begin()); it != ans.end(); ++it) {
        cout << it->second << endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
int main(){
  int n;

  while(std::cin>>n){
    if(!n)break;
    std::map<int,long long int> m;
    std::vector<int> v;
    //mlÛ¶vÛ¶
    for(;n;n--){
      int a,b,c;
      //aÔbP¿cÊ
      std::cin>>a>>b>>c;
      if(!m[a])v.push_back(a);
      m[a]+=b*c;
    }
    std::vector<int>::iterator it = v.begin();
    bool f = true;
    while(it!=v.end()){
      if(m[(*it)]>=1000000)f=false,std::cout<<(*it)<<std::endl;
      it++;
    }
    if(f)std::cout<<"NA"<<std::endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <numeric>
#include <sstream>

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

using namespace std;

//================================================

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int N;
	while (cin >> N) {
		vector<LL>price(4001, 0);
		REP(i, N) {
			int A, B;

			int num;
			cin >> num >> A >> B;
			price[num] += A * B;
		}

		bool flag = false;
		REP(i, 4001) {
			if (price[i] >= 1000000) {
				flag = true;
				cout << i << "\n";
			}
		}

		if (!flag) cout << "NA" << "\n";
	}
	return 0;
}

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

using namespace std;

int main()
{
	
	while(1)
	{
		int sum = 0;
		int n;
		cin >> n;
		if(n == 0) break;
		
		queue<int> q;
		bool checked[4000];
		int list[4000];
		for(int i = 0;i < 4000;i++)
		{
			checked[i] = false;
			list[i] = 0;
		}
		for(int i = 0;i < n;i++)
		{
			int no, x, y;
			cin >> no >> x >> y;
			list[no] += x * y;
			if(!checked[no] && list[no] >= 1000000)
			{
				q.push(no);
				checked[no] = true;
			}
		}
		
		if(q.empty()) cout << "NA" << endl;
		while(!q.empty())
		{
			cout << q.front() << endl;
			q.pop();
		}
	}
	return 0;
}

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

using namespace std;

int main(void){

	int n,flag,number;
	double money,sum;
	int data[4001]={0},dataF[4001]={0};
	queue<int> ok;

	while(1){

		for(int i=0;i<4000;i++) data[i]=0,dataF[i]=0;
		flag=0;

		cin>>n;
		if(n==0) break;

		for(int i=0;i<n;i++){
			cin>>number>>money>>sum;
			data[number]+=money*sum;
			if(dataF[number]==0){
				dataF[number]=1;
				ok.push(number);
			}
		}
			while(!ok.empty()){
				if(data[ok.front()]>=1000000){
					cout<<ok.front()<<endl;
					flag=1;
				}
				ok.pop();
			}
			if(flag==0) cout<<"NA"<<endl;
	}

	return 0;
}

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

using namespace std;

int main(){
	int n;
	while(cin >> n){
		map<int, int> m;
		for(int i = 0; i < n; i++){
			int id, price, amount;
			cin >> id >> price >> amount;
			m[id] += price * amount;
		}
		bool applicable = false;
		for(map<int, int>::iterator itr = m.begin(); itr != m.end(); itr++){
			if(itr->second >= 1000000){
				applicable = true;
				cout << itr->first << endl;
			}
		}
		if(!applicable){
			cout << "NA" << endl;
		}

	}
	return 0;
}