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 <map>
#include <algorithm>
using namespace std;

typedef long long int lli;

int main() {
  int n;
  map<int,lli> mp;
  
  while(cin>>n, n) {
    mp.clear();
    
    for(int i=0; i<n; i++) {
      int a;
      lli b, c;
      cin >> a >> b >> c;
      mp[a] += b * c;
    }
    bool isExist = false;
    for(map<int, lli>::iterator it = mp.begin(); it!=mp.end(); it++) {
      if( it->second >= 1000000 ) {
	isExist = true;
	cout << it->first << endl;
      }
    }
    if( !isExist ) cout << "NA" << endl;
  }
  
  return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b,c;
  while(cin >> n){
    if(n == 0) break;
    set<int> s;
    vary(pii,v,4001,make_pair(0,0));
    vary(ll,v2,4001,0);
    int cnt=0;
    rep(i,n){
      cin >> a >> b >> c;
      if(s.insert(a).se){
        ++cnt;
        v[a].se = cnt;
        v[a].fi = a;
      }
      v2[a] += b * c;
    }
    sort(all(v),[](const pii &p,const pii &p2){return p.se < p2.se;});
    bool f = false;
    REP(i,1,4001){
      if(v2[v[i].fi] >= 1000000){
        cout << v[i].fi<<endl;
        f = true;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
using namespace std;
int main(){
	map<int,int> mp;
	vector<int> vec;
	int n,now;
	int a,b,c;
	while(cin>>n,n){
		now=0;
		mp.clear();
		vec.clear();
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			if(!mp[a]){
				vec.push_back(a);
			}
			mp[a]+=b*c;
		}
		for(int i=0;i<vec.size();i++)
			if(mp[vec[i]]>=1000000){
			cout<<vec[i]<<endl;
				now++;
			}
		if(now==0)
		cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


struct man{
  ll num;
  ll money;
};

int main()
{
  int n;
  while(true)
    {
      cin>>n;
      if(n==0)
	exit(0);
      vector<man> d;
      d.clear();
      for(int i=0;i<n;i++)
	{
	  ll num,a,b;
	  bool ch=false;
	  cin>>num;
	  cin>>a;
	  cin>>b;
	  for(int j=0;j<d.size();j++)
	    {
	      if(d[j].num==num)
		{
		d[j].money=d[j].money+a*b;
		ch=true;
		break;
		}
	    }
	  if(ch==false)
	    {
	      struct man x;
	      x.num=num;
	      x.money=a*b;
	      d.push_back(x);
	    }
	}
      int count=0;
      for(int j=0;j<d.size();j++)
	if(d[j].money>=1000000)
	  {
	    cout<<d[j].num <<endl;
	    //    cout<<d[j].num << "   "<< d[j].money<<endl;
	    count++;
	  }
      if(count<1)
	cout<<"NA"<<endl;

    }
}

C++: #include<stdio.h>

int main(){
	int num,age,tanka;
	int i,j,n,temp;
	int sya[4000];
	double uriage[4000];
	
	
	for(;;temp=0){
		for(i=0;i<n;i++)uriage[i]=0;
		scanf("%d", &n);
		if(n==0)break;
		
		for(i=0;i<n;i++){
			scanf("%d%d%d", &num, &tanka, &age);
			
			for(j=0;j<=i;j++){
				if(sya[j]==num){			//ÐõÔª êÎ½·B
					uriage[j]+=tanka*age;
					break;
				} else {					//»ÌÐõÔªÈ¯êÎVKÂ­éB
					sya[i]=num;
					uriage[i]+=tanka*age;
					break;
				}
			}
		}
		for(i=0;i<n;i++){
			if(uriage[i]>=1000000){			//POOÈãÍ\¦
				printf("%d\n",sya[i]);
				temp=1;
			}
		}
		if(temp==0)puts("NA");				//POOÈãªÈ¯êÎ\¦
	}
	return 0;
}

C++: #include <iostream>
#include <cstring>
#define STA 1000000
using namespace std;

int main(){
    int n;
    long long num,price,value;
    long long total[4001]={0};
    bool judge;
    while(1){
        memset(total,0,sizeof(total));
        cin >> n;
        if(n == 0) break;
        judge = false;
        while(n--){
            cin >> num >> price >> value;
            total[num] += price * value;
        }
        for(int i=1;i<=4001;i++){
            if(total[i] >= STA){
                cout << i << endl;
                judge = true;
            }
        }
        if(!judge) cout << "NA" << endl;
    }
}

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

int main(){
  int n;
  while(cin >> n, n){
    vector<int> num;
    set<int> used;
    map<int, long long> sales;
    int a, b, c;
    for(int i = 0;i < n;i++){
      cin >> a >> b >> c;
      num.push_back(a);
      if(sales.count(a) == 0)sales[a] = 0;
      sales[a] += b * c;
    }
    bool ok = false;
    for(int i = 0;i < n;i++){
      int p = num[i];
      if(used.count(p))continue;
      used.insert(p);
      if(sales[p] >= 1000000){
	cout << p << endl;
	ok = true;
      }
    }
    if(!ok)cout << "NA" << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
typedef long long ll;
//vector<pair<bool, ll>> v(4001);
unsigned ll a[4001];

int main(){
	int n, num, p, q;
	while(cin >> n, n){
		fill(a, a+4001, 0);
		for(int i = 0;i < n;i++){
			cin >> num >> p >> q;
			a[num] += p * q;
		}
		int f = 1;
		for(int i = 1;i <= 4000;i++)if(a[i] >= 1000000)cout << i << endl, f = 0;
		if(f)cout << "NA" << endl;
	}
	return 0;
}

/*
4
1001 2000 520
1002 1800 450
1003 1600 625
1001 200 1220
*/