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>
#include <map>

using namespace std;

int n;
long long id[4000];
 long long value[4000];
 long long number[4000];
map<long long,  long long> total;

int main() {
  while(true){
    cin >> n;
    if(n==0){
        return 0;
    }
    vector<long long> v;
    for (int i = 0; i < n; i++) {
        cin >> id[i] >> value[i] >> number[i];
        if(total.find(id[i])==total.end()){
          total.insert(make_pair(id[i], 0));
        }
        total[id[i]] += value[i] * number[i];
        // if (total[id[i]] > 1000000 && find(v.begin(), v.end(), id[i]) == v.end()) {
        //   v.push_back(id[i]);
        // }
    }
    if(!total.empty()) {
        map< long long,  long long>::iterator it = total.begin();
        while (it != total.end()) {
            if ((*it).second >= 1000000) {
                v.push_back((*it).first);
            }
            ++it;
        }
    }
    if (v.empty()) {
        cout << "NA" << endl;
    }
    // for (vector<long long>::iterator it = v.begin(); it != v.end(); ++it) {
    //     cout << *it << endl;
    // }
    vector<long long> used;
    for(int i=0; i<n;i++){
      if(find(v.begin(), v.end(), id[i]) != v.end() && find(used.begin(), used.end(), id[i]) == used.end()){
        cout << id[i] << endl;
        used.push_back(id[i]);
      }
    }
    v.clear();
    total.clear();
  }
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<ll,ll> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b,c;
  while(cin >> n && n){
    vector<pair<ll,ll>> v;
    vary(ll,v2,4005,0);
    int cnt=0;
    rep(i,n){
      cin >> a >> b >> c;
      if(v2[a] == 0){
        ++cnt;
        v.push_back(make_pair(cnt,a));
      }
      if(v2[a] + b * a >= 1000000)i v2[a] = 1000000;
      if(v2[a] < 1000000)
        v2[a] += b * c;
    }
    sort(all(v),[](const pii &p,const pii &p2){return p.fi < p2.fi;});
    bool f = false;
//     debug(v.size());
    REP(i,0,v.size()){
      if(v2[v[i].se] < 1000000){
      }
      else{
        cout << v[i].se<<endl;
//         debug(v2[v[i].se]);
        f = true;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;
int main() {
    int n;
    while (cin >> n && n) {
        unordered_map<int, int> pos;
        vector<pair<int, ll>> res(4001);
        for (int i=1; i<=n; ++i) {
            int no, price, quantity;
            cin >> no >> price >> quantity;
            if ( ! pos[no]) {
                pos[no] = i;
                res[pos[no]].first = no;
            }
            res[pos[no]].second += price * quantity;
        }

        bool NA = true;
        for (int i=0; i<(int)res.size(); ++i) {
            if (res[i].second >= 1000000) {
                cout << res[i].first << endl;
                NA = false;
            }
        }
        if (NA)
            cout << "NA" << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<map>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    int a;
    long long b,c;
    map<int, long long> sale;
    bool f = true;
    for(int i=0; i<n; i++){
      cin >>a>>b>>c;
      if(sale[a]+b*c > 1000000){sale[a] = 1000000;}
      else{sale[a]+=b*c;}
    }
    for(map<int,long long>::iterator pos = sale.begin(); pos!=sale.end(); pos++){
      if(pos->second >= 1000000){cout <<pos->first<<endl;f = false;}
    }
    if(f){cout <<"NA"<<endl;}
  }
  return 0;
}

C++: // a.c.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include <stdio.h>
long long int bango[4001];
int main(void){
	int n;
	long long ban, tan, suu;
	int flg,i;
	while (1){
		for (i = 1; i <= 4000; i++){
			bango[i] = 0;
		}
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		for (i = 0; i < n; i++){
			scanf("%d %d %d", &ban, &tan, &suu);
			bango[ban] += tan*suu;
		}
		flg = 0;
		for (i = 1; i <= 4000; i++){
			if (bango[i]>=1000000){
				printf("%d\n", i);
				flg = 1;
			}
		}
		if (!flg){
			printf("NA\n");
		}
	}
	return 0;
}

C++: #include <stdio.h>
 
 
int n;
long long num[4000],tanka[4000],sale_num[4000];
int sale_all[4001],judge[4001];
 
int main(void){
	int i,j,k;
	
	while(scanf("%d",&n),n!=0){
		
		for(i=0;i<n;i++){
			scanf("%d%d%d",&num[i],&tanka[i],&sale_num[i]);
			
		}
		
		//初期化
		k=0;
		for(j=0;j<=4001;j++){
			judge[j]=0;
			sale_all[j]=0;
		}
		
		//idに対応したsaleに+
		for(i=0;i<n;i++){
			sale_all[num[i]] = sale_all[num[i]]+ tanka[i]*sale_num[i];
		}
		
		for(i =0; i < n; i++){
			if((sale_all[num[i]] >= 1000000)&&(judge[num[i]]==0)){
				printf("%d\n",num[i]);
				judge[num[i]]=1;
				k=1;
			}
		}
		
		if(k!=1)printf("NA\n");
	}
	
	return 0;
}