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++: 
//ツ単ツ渉δづ可嘉ーツつッツづ篠つ「ツつ「ツつセツつッツつセツつェ, ツ板?湘」ツ額ツつェintツづ可偲サツづ慊づァツづ按つ「ツ嘉つ能ツ青ォツつェツつ?づゥツづ個づ?陳債暗督つオツづ按つッツづェツづ篠づ按づァツづ按つ「
//ツ姪「ツ妥ィツ閉カツづ可渉堕つゥツづェツづ?つ「ツづゥツ「100ツ鳴?* 10ツ鳴慊」ツづ個湘ーツ個渉づ?づ? intツづ可偲サツづ慊づァツづ按つ「
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

int main(){
  int n;
  ll sum[4002], num[4002];

  while(cin >> n, n){
    //ツ催?渉? ツ全ツ暗オツ板?湘」ツづ?
    fill(sum, sum + 4002, 0);

    //ツ全ツ暗オツづ慊つセツ禿シツ療債つウツづェツづ?つ「ツづ按つ「
    fill(num, num + 4002, -1);

    //ツ渉?氾板づ可湘ョツ陛アツづーツ禿シツ療?
    for(int i = 0; i < n; i++){
      ll m, a, b;
      cin >> m >> a >> b;

      //ツ板?湘」ツづーツ堕ォツつオツつアツづ?
      sum[m] += a * b;

      //ツ渉可づ淞づ?禿シツ療債つウツづェツつスツ偲青暗オツ氾板債?づ按づァツづ? ツ可スツ氾板姪堋づ可禿シツ療債つウツづェツつスツつゥツ記ツ可ッツつオツづ?つィツつュ
      if(num[m] == -1){
        num[m] = i;
      }
    }

    //ツ板?湘」ツつェ100ツ鳴慊暗按湘」ツづ個人ツづーツ療アツ仰督つキツづゥ
    //ツつアツづ個づ?つォ, ツ可スツ氾板姪堋づ可禿シツ療債つウツづェツつスツ人ツづ?つ?づゥツつゥツづ?つ「ツつ、ツ湘ョツ陛アツづ?暗ェツ渉渉づ英ush
    vector<P> ans;

    for(int i = 0; i < 4002; i++){
      if(1000000 <= sum[i]){
        ans.push_back(P(num[i], i));
      }
    }

    //ツ禿シツ療債渉?づ可陛?づ堕妥鳴つヲ
    sort(ans.begin(), ans.end());

    //ツ督堋つヲツ出ツ療?
    for(int i = 0; i < ans.size(); i++){
      cout << ans[i].second << endl;
    }

    //1ツ人ツづ?該ツ督鳴偲陳つェツつ「ツづ按つッツづェツづ晒A
    if(ans.size() == 0){
      cout << "NA\n";
    }
  }
}

C++: #include <cstdio>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;

int n;

int main(){
	while(scanf("%d", &n),n){
		map<int,ll> m;
		map<int,ll>::iterator it;
		rep(i,n){
			int x; ll p, q;
			scanf("%d%lld%lld", &x, &p, &q);
			m[x] += p*q;
		}
		bool ok = true;
		for(it = m.begin(); it != m.end(); it++){
			ll tmp = it->second;
			if(tmp >= 1000000){
				ok = false;
				printf("%d\n", it->first);
			}
		}
		if(ok) printf("NA\n");
	}
	return 0;
}

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

int p[4001];
int result[1000000];

int main(){
	int i ,j=0 , n , id , price , num , cnt;
	while(cin>>n){
		cnt=0;
		memset(p,0 , sizeof(p)/sizeof(p[0]));
		if (n==0) break;
		for(i=0 ; i<4001 ; i++){
			p[i]=false;
		}
		for(i=0 ; i<n ; i++){
			cin >> id >> price >> num;
				p[id]+=price*num;
			}
		for(i=0 ; i<4001 ; i++){
			if(p[i]>=1000000){
				result[j++]=i;
				cnt++;
			}
		}
		if (cnt==0) {
				result[j++]=0;
			}
	}
	for(i=0;i<j;i++){
		if (result[i]==0) {
			cout << "NA" << endl;
		} else {
		cout << result[i] << endl;
		}
	}
	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<long long, long long> > v(n);
		int num = 0;
		for (int i = 0; i < n; ++i){
			long long 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<long long, long long> > sum(c);
		int k = 0;
		for (int i = 0; i < c; ++i){
			sum[i] = make_pair(0, 0);
		}

		long long 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>
#include<queue>

struct data{
	int num;
	long long pri;
	long long cun;
};

struct ret{
	int num;
	long long sales;
};

int main(){
	while (1){
		int n;
		std::cin >> n;
		if (n == 0)break;
		std::queue<data> que;
		for (int i = 0; i < n; ++i){
			data person;
			std::cin >> person.num >> person.pri >> person.cun;
			que.push(person);
		}
		std::vector<ret> lis;
		while (!que.empty()){
			data perso = que.front();
			if (!lis.empty()){
				bool f = false;
				for (auto it = lis.begin(); it != lis.end(); ++it){
					ret pers = *it;
					if (perso.num == pers.num){
						f = true;
						//std::cout << "t" << std::endl;
						//std::cout << pers.sales << std::endl;
						pers.sales += perso.cun * perso.pri;
						//std::cout << pers.sales << std::endl;
						std::swap(pers, *it);
					}
				}
				if (!f){
					ret newperson;
					newperson.num = perso.num;
					newperson.sales = perso.cun * perso.pri;
					lis.push_back(newperson);
				}
			}
			else{
				ret newperson;
				newperson.num = perso.num;
				newperson.sales = perso.cun * perso.pri;
				lis.push_back(newperson);
			}
			que.pop();
		}
		bool exist = false;
		for (auto it = lis.begin(); it != lis.end(); ++it){
			ret per = *it;
			//std::cout << per.num << " " << per.sales << std::endl;
			if (per.sales >= 1000000)std::cout << per.num << std::endl, exist = true;
		}
		if (!exist)std::cout << "NA" << std::endl;
	}
	//std::system("pause");
	return 0;
}

C++: 4
1001 2000 520
1002 1800 450
1003 1600 625
1001 200 1220
2
1001 100 3
1005 1000 100

C++: #include<iostream>
#include<cstdio>
#define long long int
using namespace std;

int A[1000000];

signed main()
{
    int N,B,C;
    while(cin >> N,N){
        int cnt[4001]={};
        bool NAflag=true, used[4001]={};
        for(int i=0;i<N;i++){
            cin>>A[i]>>B>>C;
            cnt[A[i]] += B*C;

        }
        for(int i=0;i<N;i++){
            if(cnt[A[i]]>=1000000 && used[A[i]]==false){
                printf("%d\n",A[i]); used[A[i]]=true; NAflag=false;
            }
        }
    if(NAflag==true) puts("NA");
    }
    return 0;
}