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<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define int_maxvalue numeric_limits<int>::max()
ll mod = 1e9 + 7;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int n;
		cin >> n;
		if (n == 0) { break; }
		ll a[4001];
		rep(i, 4001) { a[i] = 0; }
		rep(i, n) {
			ll d, p, q;
			cin >>  d >> p >> q;
			if (a[d] < 1000000) {
				a[d] += p*q;
				if (p*q >= 1000000) {
					a[d] = 1000000;
				}
			}
		}
		bool flag = false;
		for (int i = 1; i < 4001; i++) {
			if (a[i] >= 1000000) {
				flag = true;
				cout << i << endl;
			}
		}
		if (!flag) { cout << "NA" << endl; }
	}
	return 0;
}

C++: #include <stdio.h>

int main(int argc, char *argv[]){
	int n, f;
	int ID, price, num;
	while(1){
		scanf("%d ", &n);
		if(!n) break;
		f=0;
		while(n--){
			scanf("%d %d %d ", &ID, &price, &num);
			if(1000000 <= price * num){
				printf("%d\n", ID);
				f = 1;
			}
		}
	}
	if(!f) printf("NA\n");
	return 0;
}

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

using namespace std;

int n;
long long id[4000];
long long value[4000];
long long number[4000];

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> id[i] >> value[i] >> number[i];
    }
    vector<long long> v;
    for(int i=0;i<n;i++){
        if(value[i]*number[i] >= 1000000 ){
            v.push_back(id[i]);
        }
    }
    if(v.empty()){
        cout << "NA" <<endl;
        return 0;
    }
    for (vector<long long>::iterator it=v.begin();it!=v.end();++it){
        cout << *it << endl;
    }
}

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