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>
using namespace std;
int main(void){
    int n;
    std::map<int, long long int> map;
    std::deque<int> ans;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            int e;
            long long int p,q;
            map.clear();
            ans.clear();
            for (int i=0;i<n;i++) {
                cin>>e>>p>>q;
                if (map[e]==0) {
                    ans.emplace_back(e);
                }
                map[e]+=p*q;
            }
            int flag=0;
            for (int i=0;i<n;i++) {
                if (map[ans[i]]>=1000000) {
                    cout<<ans[i]<<endl;
                    flag=1;
                }
            }
            if (flag==0) {
                cout<<"NA"<<endl;
            }
        }
    }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
int main() {
	std::vector<int> v;
	while (1) {
		int count=0;
		int n;
		std::cin >> n;
		if (n == 0) {
			break;
		}
		std::vector<std::vector<int>> a(n, std::vector<int>(3));
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j) {
				std::cin >> a[i][j];
			}
		}
		std::vector<int>num(n);
		for (int i = 0; i < n; ++i) {
			for (int j = 1; j < n; ++j) {
				if (a[i][0] == a[j][0]) {
					num[i] += a[i][1] * a[i][2] + a[j][1] * a[j][2];
					++count;
					break;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			if (count == 0) {
				v.push_back(0);
			}
			if (num[i] >= 1000000) {
				if (count >= 2) {
					sort(num.begin(), num.end());
				}
				v.push_back(num[i]);
			}
		}
	}
	for (int i = 0; i < v.size(); ++i) {
		if (v[i] == 0) {
			std::cout << "NA" << std::endl;
		}
		else {
			std::cout << v[i] << std::endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

void solve100(int n) {
    long officer[4001] = {0};
    long o, p, q;
    REP(i,n) {
        cin >> o >> p >> q;
        officer[o] += p * q;
    }
    int cnt = 0;
    REP(i,4001) {
        if (officer[i] >= 1000000) {
            cnt++;
            cout << i << endl;
        }
    }
    if (cnt == 0) cout << "NA" << endl;
}

int main() {
    int n;
    while(cin >> n, n) {
        solve100(n);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
typedef long long ll;
using namespace std;
const int MAX = 101;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

int main(){
	int n;
	while(cin >> n && n!=0){
		map<int, ll> ans;
		vector<int> idx;
		int id, price, num;
		for(int i = 0; i < n; i++){
			cin >> id >> price >> num;
			if(!ans.count(id)) idx.push_back(id);
			ans[id] += (ll)price*num;
		}

		vector<int> ans_id;
		for(int i = 0; i < idx.size(); i++){
			if(ans[idx[i]]>=1000000) ans_id.push_back(idx[i]);
		}
		if(ans_id.size()==0){
			cout << "NA" << endl;
		}else{
			for(int i = 0; i < ans_id.size(); i++){
				cout << ans_id[i] << endl;
			}
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define ll long long

ll data[4010];
bool out[4010];

int main(){
  int i,j,k,n;
  ll a, b;
  int id;

  while(scanf("%d",&n)){
    if(n == 0) break;
    vector<int> ids;
    bool f = false;

    rep(i,4010) data[i] = 0;
    rep(i,4010) out[i] = false;

    while(n--){
      scanf("%d %lld %lld",&id,&a,&b);

      ids.push_back(id);
      data[id] += a * b;
      if(data[id] >= 1000000LL) out[id] = true;
    }

//    rep(i,ids.size()) cout << "debug " << ids[i] << endl;
    rep(i,ids.size()) if(out[ids[i]]){
      printf("%d\n",ids[i]);
      out[ids[i]] = false;
      f = true;
    }

    if(!f) puts("NA");
  }

  return 0;
}

C++: #include<iostream>
#include<vector>
int main() {
	std::vector<int> a;
	while (true) {
		int n;
		int c = 0;
		std::cin >> n;
		if (n == 0) {
			break;
		}
		std::vector<int> v(n), w(n);
		int t, u;
		for (int i = 0; i < n; ++i) {
			std::cin >> w[i] >> t >> u;
			v[i] = t*u;
		}
		for (int i = 0; i < n; ++i) {
			for (int l = 0; l < n; ++l) {
				if ((v[i] == v[l]) && (i != l)) {
					v[i] += v[l];
					v.erase(v.begin() + l);
					n -= 1;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			if (v[i] >= 1000000) {
				a.push_back(w[i]);
				++c;
			}
			if ((c == 0) && (i == n - 1)) {
				a.push_back(0);
			}
		}
		v.clear();
		w.clear();
	}
	for (int i = 0; i < a.size(); ++i) {
		if (a[i] == 0)std::cout << "NA" << std::endl;
		else std::cout << a[i] << std::endl;
	}
	return 0;
}

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

int main()
{
    int n;
    while(cin >> n,n){
        bool hantei=true,border[n];
        long long number[n],price[n],quantity[n];
        for(int i=0 ; i<n ; i++){
            border[i]=false;
            cin >> number[i] >> price[i] >> quantity[i];
            if(price[i]*quantity[i]>=1000000){
                border[i]=true;
            }
        }
        for(int i=0 ; i<n ; i++){
            if(border[i]){
                cout << number[i] << endl;
                hantei=false;
            }
        }
        if(hantei){
            cout << "NA" << endl;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		map<ll,ll>in;
		vector<ll>name;
		rep(i,n){
			ll a,b,c;
			cin>>a>>b>>c;
			if(!in[a])name.pb(a);
			in[a]+=b*c;
		}
		bool h=false;
		rep(i,name.size()){
			if(in[name[i]]>=1e6){
				h=true;
				cout<<name[i]<<endl;
			}
		}
		if(!h)cout<<"NA"<<endl;
	}
}