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 <algorithm>
using namespace std;

long long member[4000];
bool ached[4000];
vector<int> ach;

int main(void){
  int n;
  while(true){
    cin >> n;
    if(n == 0)  break;
    fill(member, member + 4000, 0);
    fill(ached, ached + 4000, false);
    ach.clear();
    for(int i = 0; i < n; i++){
      int id, tanka, suryo;
      cin >> id >> tanka >> suryo;
      member[id] += tanka * suryo;
      if(member[id] >= 1000000 && ached[id] == false){
        ach.push_back(id);
        ached[id] = true;
      }
    }

    if(ach.empty()){
      cout << "NA" << endl;
    }else{
      for(int i = 0; i < ach.size(); i++){
        cout << ach[i] << endl;
      }
    }
  }
  return 0;
}

C++: //Name: Sale Reult
//Level: 1
//Category: やるだけ
//Note:

#include <iostream>

using namespace std;

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    bool exist = false;
    for(int i = 0; i < N; ++i) {
        int id, v, c;
        cin >> id >> v >> c;
        if(v*c >= 1000000) {
            cout << id << endl;
            exist = true;
        }
    }
    if(!exist) cout << "NA" << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

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

int n;
int main(){
	while((cin >> n) != 0){
		int num = 0;
		vector<pair<int, int> > pairs(n);

		for(int i = 0; i < n; i++){
			int p, q;
			cin >> pairs[i].first >> p >> q;
			pairs[i].second = p * q;
		}

		sort(pairs.begin(), pairs.end());

		int sum = 0;
		sum = pairs[0].second;
		for(int i = 1; i < n; i++){
			if(pairs[i].first == pairs[i-1].first){
				sum += pairs[i].second;
			}else{
				if(sum >= 1000000){
					cout << sum << \n;
					num++;
				}
				sum == pairs[i].second;
			}
		}

		if(num == 0){
			cout << "NA\n";
		}
	}
	
    return 0;
}

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){
    if(n == 0) break;
    set<int> s;
    vector<pair<ll,ll>> v(4001,make_pair(0,0));
    vary(ll,v2,4001,0);
    int cnt=0;
    rep(i,n){
      cin >> a >> b >> c;
      if(s.insert(a).se){
        ++cnt;
        v[a].se = cnt;
        v[a].fi = a;
      }
      if(v2[a] < 1000000)
        v2[a] += b * c;
    }
    sort(all(v),[](const pii &p,const pii &p2){return p.se < p2.se;});
    bool f = false;
    REP(i,1,4001){
      if(v2[v[i].fi] >= 1000000){
        cout << v[i].fi<<endl;
        f = true;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}

C++: 
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;

#define MAX 5000

int main(){
    for (;;) {
        int n;
        cin >> n;
        if(n==0) break;
        vector<ll> num(4001,0),pre(n,0),data(4001,0);
        for (int i=0; i<n; i++) {
            ll a,b,c;
            cin >>a >>b >>c;
            ll inp;
            if(b*c>=1000000){
                inp=1000000;
            }else{
                inp = b*c;
            }
            if(data[a]<1000000) data[a]+=inp;
            if(num[a]==0) num[a]=i+1;
        }
        for (int k=0; k< 4001; k++) {
            if(num[k]!=0) pre[num[k]]=k;
        }
        ll ch=0;
        for (int j=0; j<n; j++) {
            if (data[pre[j]]>=1000000) {
                cout <<pre[j]<<endl;
                ch++;
            }
        }
        if(ch==0) cout << "NA"<<endl;
    }
}

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

	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) {
				if(table[i].order == invalid_order)
					exit(1);
				cout << table[i].ID << endl;
				flag = true;
			}
		}

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

	return 0;
}