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>
#include <map>
using namespace std;
int main(){
  int n,f;
  //mlÛ¶vÛ¶
  long long a,b,c;
  //aÔbP¿cÊ
  while(cin>>n,n){
		map<int,long long> m;
		vector<int> v;
		f=1;
    for(;n;n--){
      std::cin>>a>>b>>c;
      if(!m[a])v.push_back(a);
      m[a] += b*c;
    }
    
    for(int i=0;i<v.size();i++){
      if(m[v[i]]>999999){
				f=0;
				cout<<v[i]<<endl;}
    }
    if(f)cout<<"NA"<<endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<math.h>
#include<string.h>


int main(){
	int uriage[4000][3],n,no,tanka,su,i,j,newflag,naflag;
	
	while(0<=scanf("%d",&n)){
		if(n==0) break;
		memset(uriage,0,sizeof(uriage));
		for(i=0;i<n;i++){
			scanf("%d%d%d",&no,&tanka,&su);
			newflag=0;
			for(j=0;j<n;j++){
				if(uriage[j][0]==no && uriage[j][2]==1){
					uriage[j][1]+=tanka*su;
					newflag=1;
					break;
				}
			}
			if(newflag==0){
				for(j=0;j<n;j++){
					if(uriage[j][2]==0){
						uriage[j][1]+=tanka*su;
						uriage[j][0]=no;
						uriage[j][2]=1;
						break;
					}
				}
			}
		}
		naflag=0;
		for(i=0;i<n;i++){
			if(uriage[i][2]==0)break;
			if(uriage[i][1]>=1000000){
				printf("%d\n",uriage[i][0]);
				naflag=1;
			}
		}
		if(naflag==0)printf("NA\n");
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	long long value[4001];

	int n,num,k,m;
	while(cin >> n && n)
	{
		memset(value,0,sizeof(value));

		rep(i,n)
		{
			cin >> num >> k >> m;
			value[num] += k*m;
		}

		bool flag = true;
		rep(i,4001)
		{
			if(value[i] >= 1000000)
			{
				flag = false;
				cout << i << endl;
			}
		}

		if(flag) cout << "NA" << endl;
	}
	return 0;
}

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

int main()
{
  int n, num;
  long long int price, count;
  while (cin >> n) {
    if (n == 0)
      break;

    vector<int> index;
    vector<long long int> sale(4000, 0);
    for (int i = 0; i < n; ++i) {
      cin >> num >> price >> count;
      sale[num] += price * count;
      if (find(index.begin(), index.end(), num) == index.end())
	index.push_back(num);
    }

    bool found = false;
    for (unsigned int i = 0; i < index.size(); ++i) {
      if (sale[index[i]] >= 1000000LL) {
	cout << index[i] << endl;
	found = true;
      }
    }
    if (!found)
      cout << "NA" << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int i, n, q;
  long long int p;
  while(cin >> n, n){
    bool NAflg = false;
    while(n--){
      cin >> i >> p >> q;
      if((p * q) >= static_cast<int>(1e6)){
	cout << i << endl;
	NAflg = true;
      }
    }
    if(NAflg)
      cout << "NA" << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    unsigned long long a[5000]={0},c=0,p,o,u;
    rep(i,5000)cout<<a[i];
    rep(i,n){
      cin>>p>>o>>u;
      a[p]+=o*u;
      if(a[p]>=1000000){cout<<p<<endl;c++;}
    }
    if(!c)cout<<"NA"<<endl;
  }
}

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

struct data{
	int id;
	int value;
	int num;
};

int main(){
	int n;
	int need;
	while(cin >> n){
		if(n == 0) break;
		int count = 0;
		for(int i = 0; i < n; i++){
			data d;
			cin >> d.id >>
				d.value >> d.num;
			if(!d.value){
				need = 1000000 % d.value == 0 ? 1000000 / d.value : 1000000 / d.value + 1;
				if(d.num >= need){
					cout << d.id << endl;
					count++;
				}
			}
		}
		if(!count) cout << "NA" << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n;

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

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

using namespace std;
#define mp make_pair
int main(){
  int n;
  string a;
  long long b,c;
  map<string,long long> data;
  vector<string> id;
  while(true){
    data.clear();
    id.clear();
    cin>>n;
    if(!n)
      break;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      c*=b;
      if(data.find(a)==data.end()){
	data.insert(mp(a,c));
	id.push_back(a);
      }
      else{
	data[a]+=c;
      }
    }
    bool empty = true;
    for(int i=0;i<id.size();i++){
      if(data[id[i]]>=1000000){
	cout<<id[i]<<endl;
	empty = false;
      }
    }
    if (empty)
      cout<<"NA"<<endl;
  }
  return 0;
}

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

using namespace std;

int n;
long long id[4000];
 long long value[4000];
 long long number[4000];
map<long long,  long long> total;

int main() {
  while(true){
    cin >> n;
    if(n==0){
        return 0;
    }
    vector<long long> v;
    for (int i = 0; i < n; i++) {
        cin >> id[i] >> value[i] >> number[i];
        if(total.find(id[i])==total.end()){
          total.insert(make_pair(id[i], 0));
        }
        total[id[i]] += value[i] * number[i];
        // if (total[id[i]] > 1000000 && find(v.begin(), v.end(), id[i]) == v.end()) {
        //   v.push_back(id[i]);
        // }
    }
    if(!total.empty()) {
        map< long long,  long long>::iterator it = total.begin();
        while (it != total.end()) {
            if ((*it).second >= 1000000) {
                v.push_back((*it).first);
            }
            ++it;
        }
    }
    if (v.empty()) {
        cout << "NA" << endl;
    }
    // for (vector<long long>::iterator it = v.begin(); it != v.end(); ++it) {
    //     cout << *it << endl;
    // }
    vector<long long> used;
    for(int i=0; i<n;i++){
      if(std::find(v.begin(), v.end(), &(id[i])) != v.end() && std::find(used.begin(), used.end(), &(id[i])) == used.end()){
        cout << id[i] << endl;
        used.push_back(id[i]);
      }
    }
    v.clear();
    total.clear();
  }
}