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 <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;
  int id;
  ll a, b;

  while(scanf("%d",&n)){
    if(n == 0) break;
    bool f = false;
    memset(out,true,sizeof(out));
    memset(data,0,sizeof(data));

    while(n--){
      scanf("%d %lld %lld",&id,&a,&b);
      data[id] += a * b;
      if(data[id] >= 1000000LL && out[id]){
        out[id] = false;
        printf("%d\n",id);
        f = true;
      }
    }
    if(f) puts("NA");
  }

  return 0;
}

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

int main(){
	int n;
	while(cin >> n){
		if(n == 0) break;
		int id, price, amount;
		vector<int> v;
		for(int i = 0; i < n; i++){
			cin >> id >> price >> amount;
			if(price * amount >= 10000){
				vector<int>::iterator itr = find(v.begin(), v.end(), id);
				if(itr == v.end()){
					v.push_back(id);
				}
			}
		}
		if(v.empty()){
			cout << "NA" << endl;
		}
		else{
			for(int i = 0; i < v.size(); i++){
				cout << v[i] << endl;
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long int lli;

lli employees[4001];
bool checked[4001];

signed main()
{
	lli n;
	while (cin >> n, n) {
		for (lli i = 1; i <= 4000; ++i) employees[i] = checked[i] = false;

		vector<lli> ans;

		for (lli i = 0; i < n; ++i) {
			lli num, a, b; cin >> num >> a >> b;

			if (checked[num]) continue;

			employees[num] += a * b;

			if (employees[num] >= 1000000) {
				ans.push_back(num);
				checked[num] = true;
			}
		}

		if (ans.empty()) cout << "NA" << endl;

        for (lli i = 0; i < ans.size(); ++i) {
            cout << ans[i] << endl;
        }
	}
}

C++: #include <cstdio>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;

int n;

int main(){
	while(scanf("%d", &n),n){
		map<int,ll> m;
		map<int,ll>::iterator it;
		rep(i,n){
			int x; ll p, q;
			scanf("%d%lld%lld", &x, &p, &q);
			m[x] += p*q;
		}
		bool ok = true;
		for(it = m.begin(); it != m.end(); it++){
			if(it->second >= 1000000){
				ok = false;
				printf("%d\n", it->first);
			}
		}
		if(ok) printf("NA\n");
	}
}

C++: #include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{

    int n=1,num,tanka,suryo;
    long long sum[4001]={0};
    int jyun[10000000001]={0};
    bool w[4001]={false};
    bool na=true;
    while(true){
        cin>>n;
        if(n==0){
            return 0;
        }
        for(int i=0;i<n;i++){//ツ禿シツ療債つウツづェツつスツ値ツづーツ各ツ配ツ療ア(ツ偲青暗オツ氾板債づ可格ツ納)
            cin>>num>>tanka>>suryo;
            jyun[i]=num;
            sum[num]+=tanka*suryo;
        }
        for(int i=0;i<=10000000000;i++){
            if(sum[jyun[i]]>=1000000){if(!w[jyun[i]]){cout<<jyun[i]<<endl;w[jyun[i]]=true;}na=false;}
            sum[i]=0;//ツ篠淞づ可使ツつ、ツづヲツつ、ツづ可渉可甘コツ可サツづーツつオツづつィツつュ
            jyun[i]=0;
        }
        if(na)cout<<"NA"<<endl;
        na=true;
        for(int i=0;i<=4000;i++){
            w[i]=false;
        }
    }
}

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

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

    vector<pair<int, long>> vec;
    int n;
    while (cin >> n && n > 0) {
        for (int i = 0; i < n; i++) {
            int id;
            long p, q;
            cin >> id >> p >> q;

            auto pre = find_if(
                vec.begin(), vec.end(),
                [&](const pair<int, long> &tar) { return tar.first == id; });
            if (pre != vec.end())
                pre->second += p * q;
            else
                vec.push_back(make_pair(id, p * q));
        }
        int count = 0;
        for (auto v : vec) {
            if (v.second >= 1000000) {
                cout << v.first << endl;
                count++;
            }
        }
        if (count == 0) cout << "NA" << endl;
        vec.clear();
    }
    return EXIT_SUCCESS;
}

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

int main(){
  const int Sale = 1000000;
  while(true){
    int n; //????????°
    int counter = 0;
    cin >> n;
    if(n == 0){
      break;
    }
    int id[n],sale[n],result[n];
    for(int i=0; i<n; i++){
      cin >> id[i] >>sale[i] >> result[i];
      if(sale[i]*result[i] >= Sale){
        cout << id[i] << endl;
        counter++;
      }
    }
    if(counter == 0){
        cout << "NA" << endl;
    }
  }
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<double,double> P;

int main(){
	
	int num;
	
	while(~scanf("%d",&num)){
		if(num==0) break;
		bool isok=false;
		map<int,ll> val;
		vector<int> order;
		for(int i=0;i<num;i++){
			int n;
			ll p,q;
			scanf("%d %lld %lld",&n,&p,&q);
			val[n] += p*q;
			if(find(order.begin(),order.end(),n) == order.end()){
				order.push_back(n);
			}
		}

		for(vector<int>::iterator it = order.begin(); it != order.end(); it++){
			if(val[*it] >= 1000000){
				cout << *it << endl;
				isok=true;
			}
		}
		if(!isok) cout <<  "NA" << endl;
	}
}

C++: #include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <bitset>
using namespace std;
typedef long long ll;
int main() {
    int n;
    while (cin >> n && n) {
        map<int,int> sum;
        for (int i=0; i<n; ++i) {
            int no, price, quantity;
            cin >> no >> price >> quantity;
            sum[no] += price * quantity;
        }

        bool NA = true;
        for (map<int,int>::iterator it = sum.begin(); it != sum.end(); it++) {
            if (it->second >= 1000000) {
                cout << it->first << endl;
                NA = false;
            }
        }
        if (NA)
            cout << "NA" << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll>P;

int main() {
	ll n;
	while (cin >> n, n) {
		map<ll, ll>mp;
		map<ll, ll>pos;
		rep(i, n) {
			ll e, p, q; cin >> e >> p >> q;
			mp[e] += p*q; pos[e] = i;
		}
		vector<P>v;
		for (P i : mp)v.push_back(i);
		sort(v.begin(), v.end(), [&](P a, P b) {return pos[a.first] <= pos[b.first]; });
		bool flag = true;
		for (P i : v) {
			if (i.second >= 1000000) {
				cout << i.first << endl;
				flag = false;
			}
		}
		if (flag)puts("NA");
	}
}