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++: #include<iostream>
#include<vector>;
using namespace std;
int main() {
	int n;
	while (cin >> n){
		if (n == 0)break;
		long long u[4010] = { 0 };
		vector<int>l;
		for (int i = 0; i < n; i++){
			long a, b, c;
			cin >> a >> b >> c;
			u[a] += b*c;
			if (u[a] >= 1000000 && find(l.begin(), l.end(), a) == l.end())l.push_back(a);
		}
		for (int i = 0; i < l.size(); i++){
			cout << l[i] << endl;
		}
		if (!l.size())cout << "NA" << endl;
	}
	return 0;
}

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

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

    int n;
    map<int, long> mp;
    vector<int> vec;
    while (cin >> n && n != 0) {
        for (int i = 0; i < n; i++) {
            int id;
            long p, q;
            cin >> id >> p >> q;
            mp[id] += p * q;
        }
        for (auto m : mp)
            if (m.second >= 1000000) vec.push_back(m.first);

        if (vec.size() == 0)
            cout << "NA" << endl;
        else {
            for (auto v : vec) cout << v << endl;
        }

        mp.clear();
        vec.clear();
    }
    return EXIT_SUCCESS;
}

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

using namespace std;

const int Target = 1000000;

struct Shain {
	int no;
	long long sum;
};

int main( void )
{
	vector<Shain> shain;
	int n;
	while(cin >> n, n) {
		shain.clear();
		for(int i=0; i < n; ++i) {
			int no, kin, num;
			cin >> no >> kin >> num;
			bool hit = false;
			vector<Shain>::iterator it = shain.begin();
			while(it != shain.end()) {
				if(it->no == no) {
					if(it->sum < Target) it->sum += (kin * num);
					hit = true;
					break;
				}
				++it;
			}
			if(!hit) {
				Shain tmp;
				tmp.no = no;
				tmp.sum = kin * num;
				shain.push_back(tmp);
			}
		}
		bool hit = false;
		vector<Shain>::iterator it = shain.begin();
		while(it != shain.end()) {
			if(it->sum >= Target) {
				cout << it->no << endl;
				hit = true;
			}
			++it;
		}
		if(!hit)
			cout << "NA" << endl;
	}
	return 0;
}

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

typedef long int lint;
typedef long long int llint;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  
  while (cin >> n, n){
    int p, q;
    int e[1010] = {0}, res[4010] = {0};
    bool judge = false;
    REP(i, n){
      cin >> e[i] >> p >> q;
      res[e[i]] += p * q;
    }
    sort(e, e + n);
    REP(i, n){
      if (res[e[i]] >= 1000000 && e[i] != e[i + 1]){
        cout << e[i] << endl;
        judge = true;
      }
    }
    if (!judge) cout << "NA" << endl;
  }
}

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

int main()
{
	int n;
	while(cin >> n){
		if(n == 0) break;
		map<int, int> officers;
		vector<int> ids;
		for(int i = 0; i < n; i++){
			int id;
			int value;
			int num;
			int need;
			cin >> id >> value >> num;
			if(value > 0){
				need = 1000000 % value == 0 ? 1000000 / value : 1000000 / value + 1;
				if(num >= need){
					officers[id] = 1000000;
					if(find(ids.begin(), ids.end(),id) == ids.end())
						ids.push_back(id);
				} else {
					if(find(ids.begin(), ids.end(),id) == ids.end()){
						ids.push_back(id);
						officers[id] = value * num;
					} else {
						officers[id] += value * num;
						if(officers[id] > 1000000)
							officers[id] = 1000000;
					}
				}
			}
		}
		int count = 0;
		for(vector<int>::const_iterator iter = ids.begin(); 
			iter != ids.end(); iter++){
			if(officers[*iter] >= 1000000){
				cout << *iter << endl;
				count++;
			}
		}
		if(!count) cout << "NA" << endl;
	}
	return 0;

}

C++: #include <iostream>
#include <set>
using namespace std;
int main( void )
{
	int n;
	while ( cin >> n && n != 0 )
	{
		set <int> T;

		bool exist = false;
		for ( int i = 0; i < n; i++ )
		{
			int no, price, items;
			cin >> no >> price >> items;

			if ( price <= 1000000 && items <= 100000 )
			{
				long long profit = (long long)price * items;
				if ( T.find( no ) == T.end() && profit >= 1000000L )
				{
					exist = true;
					cout << no << endl;
					T.insert( no );
				}
			}
		}

		if ( exist == false )
			cout << "NA" << endl;
	}

	return 0;
}

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

using namespace std;

#define ll long long

int main(void){
  map<int,ll> m;
  int n;
  int no,amount,price;

  while(cin >> n){
	bool exist = false;
	if(!n) break;
	for(int i=0;i<n;i++){
	  cin >> no >> amount >> price;
	  m[no] += (ll)amount*price;
	}
	map<int,ll>::iterator it = m.begin();
	while(it!=m.end()){
	  if((*it).second >= 1e+6){
		cout << (*it).first << endl;
		exist = true;
	  }
	  ++it;
	}
	if(!exist) cout << "NA" << endl;
	m.clear();
  }
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  vector<string> result;

  while (true) {
    cin >> n;
    if (n == 0)
      break;

    map<string, long long> m;
    bool hoge = true;
    for (int i = 0; i < n; i++) {
      string id;
      long long a, b;
      cin >> id >> a >> b;
      if (m[id] < 1000000 && m[id] + a * b >= 1000000) {
        result.push_back(id);
        hoge = false;
      }
      m[id] += a * b;
    }
    if (hoge)
      result.push_back("NA");
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << 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++) {
            int a,b,c;
            cin >>a >>b >>c;
            if(data[a]<1000000) data[a]+=b*c;
            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;
    }
}