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 <algorithm>
#include <cstdio>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

int main() {
  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 0) { break; }

    int insert_order = 0;
    unordered_map<int, int> insert_orders;
    unordered_map<int, unsigned long> sales;
    for (int i = 0; i < n; ++i) {
      int id, unit_cost, count;
      scanf("%d %d %d", &id, &unit_cost, &count);
      if (insert_orders.count(id) == 0) {
        insert_orders[id] = ++insert_order;
      }
      sales[id] += unit_cost * count;
    }
    typedef pair<int, unsigned long> Record;
    vector<Record> sales_result(sales.cbegin(), sales.cend());
    sort(
        sales_result.begin(),
        sales_result.end(),
        [&](const Record& a, const Record& b) {
          return insert_orders[a.first] < insert_orders[b.first];
        });
    bool exists = false;
    for (const auto& record : sales_result) {
      if (record.second < 1000000) { continue; }
      exists = true;
      printf("%d\n", record.first, record);
    }
    if (!exists) { puts("NA"); }
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	
	int n;
	long sn, x, y;

	while (1){
		vector<int>nm;
		long p[4001] = { 0 };
		cin >> n;
		if (n == 0)break;
		for (int i = 0; i < n; i++){
			cin >> sn >> x >> y;
			p[sn] += x*y;
		}
		long maxn = 0;
		long maxc = 0;
		for (int i = 1; i <= 4000; i++){
			if (maxn < p[i]){
				nm.clear();
				swap(maxn, p[i]);
				nm.push_back(i);
			}
			else if (maxn == p[i]){
				nm.push_back(i);
			}
		}
		if (maxn >= 1000000){
			for (int i = 0; i < nm.size(); i++){
				cout << nm[i] << endl;
			}
		}
		else
			cout << "NA" << endl;
	}
}

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));
      }
      v2[a] += b * c;
    }
    sort(all(v));
    bool f = false;
    REP(i,0,v.size()){
      if(v2[v[i].se] >= 1000000){
        cout << v[i].se<<endl;
        f = true;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}

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

static const int invalid_order = 1000000;
struct data {
	int ID;
	long long total;
	int order;

	data() {
		ID = -1;
		total = 0;
		order = invalid_order;
	}

	data(int n) {
		ID = n;
		total = 0;
		order = invalid_order;
	}

	bool operator<(const data d) const {
		return order < d.order;
	}
};

int main() {
	int n;

	while(cin >> n, n) {
		int ID, price, sale;
		data table[4096];
		bool flag = false;
		int order_count = 0;

		for(int i = 0; i < 4096; i++) {
			table[i].ID = i;
		}

		for(int i = 0; i < n; i++) {
			char in[128];
			char ID_s[32], price_s[32], sale_s[32];
			int j, k;

			// input
			/*
			fgets(in, 120, stdin);
			for(j = 0,k = 0; in[j + k] != ' ' && in[j + k] != ';'; k++)
				ID_s[k] = in[j + k];
			ID_s[k] = '\0';
			j = k + 1;
			for(k = 0; in[j + k] != ' ' && in[j + k] != ';'; k++)
				price_s[k] = in[j + k];
			price_s[k] = '\0';
			j += k + 1;
			for(k = 0; in[j + k] != ' ' && in[j + k] != ';' && in[j + k] && in[j + k] != '\n'; k++)
				sale_s[k] = in[j + k];
			sale_s[k] = '\0';

			ID = atoi(ID_s);
			price = atoi(price_s);
			sale = atoi(sale_s);
			// */ cin >> ID >> price >> sale;
			
			if(table[ID].order == invalid_order) {
				table[ID].order = order_count;
				order_count++;
			}
			table[ID].total += price * sale;
		}

		sort(table, table + 4096);

		for(int i = 0; i < order_count; i++) {
			if(table[i].total >= 1000000) {
				cout << table[i].ID << endl;
				flag = true;
			}
		}

		if(!flag)
			cout << "NA" << endl;
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

int order[4000];
map<int, ll> sums;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		int optr = 0;
		sums.clear();
		while(n--){
			int a;
			ll b, c;
			cin >> a >> b >> c;
			map<int, ll>::iterator it = sums.find(a);
			if(it == sums.end()){
				order[optr++] = a;
				sums.insert(pair<int, ll>(a, b * c));
			}else{
				(*it).second += b * c;
			}
		}
		bool isNA = true;
		for(int i = 0; i < optr; ++i){
			if(sums[order[i]] >= 1000000){
				cout << order[i] << endl;
				isNA = false;
			}
		}
		if(isNA){ cout << "NA" << endl; }
	}
	return 0;
}

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

using namespace std;


int main()
{
    int n;
    while(cin >> n && n) {
        set<string> list;
        string id;
        int a,b;
        for(int i = 0; i < n; i++) {
            cin >> id >> a >> b;
            if(a*b >= 1000000 && list.find(id) == list.end()) {
                list.insert(id);
                cout << id << endl;
            }
        }
        if(list.size() == 0) cout << "NA" << endl;
    }
}