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 <bits/stdc++.h>
#define INT(name) int name; scanf("%d",&name);
#define VINT(name,n) vector<int> name(n); for(int i = 0;i < n;i++) scanf("%d",&name[i]);

using namespace std;

int main(int argc, char const *argv[]){
	vector<long long> data(4000);
	int i;
	long long a,b,c;
	bool check;

	cin >> i;
	while(i){

		for(int j = 0;j < 4000;j++){
			data[j] = 0;
		}


		for(int j = 0;j < i;j++){
			cin >> a >> b >> c;
			data[a - 1] += b * c;
		}


		check = false;

		for(int j = 0;j < 4000;j++){
			if(data[j] >= 1000000){
				printf("%d\n",j+1);
				check = true;
			}
		}

		if(!check) printf("NA\n");

		cin >> i;
	}

	return 0;
}

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

int main(){
  int n,i,p,q,f;
  for(;scanf("%d",&n),n;){
    map<int,long long int>m;
    vector<int>v;
    for(;n--;){
      scanf("%d%d%d",&i,&p,&q);
      if(m.find(i)==m.end())v.push_back(i);
      m[i]+=(long long int)p*q;
    }
    for(f=i=0;i<v.size();i++){
      if(m[v[i]]>=1000000)printf("%d\n",v[i]),f=1;
    }
    if(!f)puts("NA");
  }
}

C++: #include<stdio.h>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
long long s[4000];
P p[4000];
int min(int a,int b){return a<b?a:b;}
int main(){
	int n,i;
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		for(i=0;i<4000;i++){
			s[i]=0;
			p[i].first=5000;
			p[i].second=i;
		}
		for(i=0;i<n;i++){
			int a,b,c;
			scanf("%d %d %d",&a,&b,&c);
			s[a-1]+=b*c;
			p[a-1].first=min(p[a-1].first,i);
		}
		sort(p,p+4000);
		bool f=true;
		for(i=0;i<4000;i++){
			if(p[i].first==5000)break;
			if(s[p[i].second]>=1000000){
				printf("%d\n",p[i].second+1);
				f=false;
			}
		}
		if(f)printf("NA\n");
	}
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define MAX 100000000
#define pb push_back
using namespace std; 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
  
int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0) break;
    int p[4001];
    for(int i = 0;i < 4001;i++){
      p[i] = 0;
    } 
    for(int i = 0;i < n;i++){
      int b,t,s;
      cin >> b >> t >> s;
      p[b] += t*s;
    }
    int count = 0;
    for(int i = 1;i < 4001;i++){
      if(p[i] >= 1000000){
	P(i);
	count++;
      }
    }
    if(count == 0){
      P("NA");
    }
  }
  return 0;
}

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

static const long long TOTAL_NORMA = 1000000;
static const int MAX_WORKER_SIZE = 4000;
static long long m[MAX_WORKER_SIZE];
static bool isShow[MAX_WORKER_SIZE];


int main(void) {
    int n;

    while (std::cin >> n) {
        if (n == 0) {
            return 0;
        }

        // init
        bool f = true;
        std::fill(m, m + (sizeof m / sizeof m[0]), 0);
        std::fill(isShow, isShow + (sizeof isShow / sizeof isShow[0]), false);

        for (int i = 0; i < n; ++i) {
            long long number, price, quantity;
            std::cin >> number >> price >> quantity;

            m[number] += (price * quantity);

            if (isShow[number] == false && TOTAL_NORMA <= m[number]) {
                std::cout << number << std::endl;
                isShow[number] = true;
                f = false;
            }
        }

        if (f) {
            std::cout << "NA" << std::endl;
        }

    }

    return 0;
}

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

int main()
{
    while(1)
    {
        int n;
        cin>>n;
        if(n==0) return 0;
        multimap< int,int,greater<int> > sr;
        for(int i=0;i<n;++i)
        {
            int sn,p,q;
            cin>>sn>>p>>q;
            sr.insert(make_pair(sn,p*q));
        }
        multimap<int,int>::iterator it=sr.begin();
        do{
            if(it==sr.begin()&&(*it).second<1000000) {
                cout<<"NA"<<endl;  break;
            }
            cout<<(*it).first<<endl;
            ++it;
        }while((*it).second>=1000000);
    }
}

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

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    map<int, int> data;
    map<int, bool> flag;
    int cnt = 0;
    for(int i = 0; i < n; i++) {
      int id, p, num;
      cin >> id >> p >> num;
      for(int j = 0; j < num; j++) {
	data[id] += p;
	if(data[id] >= 1000000 && !flag[id]) {
	  cout << id << endl;
	  flag[id] = true;
	  cnt++;
	  break;
	}
      }
    }
    if(cnt == 0) cout << "NA" << endl;
  }
  return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct salary{
	int no;
	long long sell;
	bool b;
};

int main() {
	
	int n;
	while(cin>>n,n){
		vector<salary> vs;
		REP(i, n){
			int no, sell_n, value;
			cin >> no >> sell_n >> value;
			bool b = false;
			REP(j, vs.size()){
				if (vs[j].no == no){
					b = true;
					vs[j].sell += sell_n*value;
					
				}
			}
			if (!b)vs.push_back({ no, sell_n*value ,false});
			REP(j, vs.size()){
				if (vs[j].sell >= 1000000){
					vs[j].b = true;
				}
			}
		}
		bool b2=false;
		REP(i, vs.size()){
			if (vs[i].b){
				cout << vs[i].no << endl;
				b2 = true;
			}
		}
		if (!b2)cout << "NA"<< endl;
	}
}