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 ;

#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<ll,ll> ;

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);
  ll n,a,b,c;
  while(cin >> n && n){
    vector<pair<ll,ll>> v;
    vary(ll,v2,4001,0);
    vary(ll,t,4001,0);
    ll cnt=0;
    rep(i,n){
      cin >> a >> b >> c;
      if(v2[a] == 0){
        v.push_back(make_pair(cnt,a));
        ++cnt;
        v2[a] = 1;
      }
      t[a] += b * c;
    }
    bool f = false;
    REP(i,0,v.size()){
      if(t[v[i].se] >= 1000000){
        cout << v[i].se<<endl;
        f = true;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vector<ll> v(4005,0);
    rep(i,n){
      ll e,p,q;
      cin>>e>>p>>q;
      v[e]+=p*q;
    }
    vi ans;
    rep(i,4005)
      if(v[i]>=1000000)ans.push_back(i);
    if(ans.size())
      rep(i,ans.size())cout<<ans[i]<<endl;
    else
      cout<<"NA"<<endl;
  }
}

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

int main(){
    int n,i;
    while(cin>>n,n){
        map<int,long long>m;
        long long p,q,s=0;
        while(n--){
            cin>>i>>p>>q;
            m[i]+=p*q;
        }
        for (map<int,long long>::iterator it=m.begin(); it!=m.end(); ++it){
            if(it->second>=1000000){
                s=1;
                cout<<it->first<<endl;
            }
        }
        if(!s)cout<<"NA"<<endl;
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n)
	{
		if(!n) break;

		bool f = true;
		rep(i, n)
		{
			ll a, s, num;
			scanf("%lld %lld %lld", &num, &a, &s);

			if(1000000 <= a * s)
			{
				f = false;
				printf("%d\n", num);
			}
		}
		if(f) cout << "NA" << endl;
	}
}

C++: #include<cstdio>

using namespace std;
const int target = 1000000;

int main()
{
	int data;
	while (1)
	{
		scanf_s("%d", &data);
		if (data == 0)break;
		bool hero = false;
		for (int i = 0; i < data; i++)
		{
			int num, sell, cnt;
			scanf_s("%d %d %d", num, sell, cnt);
			if (sell*cnt >= target)
			{
				printf("%d\n", num);
				hero = true;
			}
		}
		if (hero == false)
			printf("NA\n");
	}
	return 0;
}

C++: #include<stdio.h>
int main(void){
    int n;
    int i=1,j,k;
    int x,y,z,flag=0;
    int a[4001]={0};
    int b[4001]={0};
    int c[4001]={0};
    int o[4001]={0};
    for(;;){
        i=1,flag=0;
        k=0;
        for(k=0;k<=4000;k++){
            a[k]=0;
            b[k]=0;
            c[k]=0;
            o[k]=0;
            }
    scanf("%d",&n);
    if(n==0)break;
    for(j=1;j<=n;j++){
        flag=0;
        scanf("%d%d%d",&x,&y,&z);
        if(a[x]!=0){
            a[x]=a[x]+y*z;

            }
        else {
            c[i]=x;
            a[x]=y*z;
            i++;
        }
        if(o[x]==0&&a[x]>=1000000){
            b[j]=1;
            o[x]=1;
            }
        }
	for(i=1;i<=n;i++){
	    if(b[i]==1){
        printf("%d\n",c[i]);
        flag=1;
        }

	}
	if(flag==0){
            printf("NA\n");
            }
    }
return 0;
}

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

int main(){

  int num, v, n, m, len, cnt;
  vector<long long> vc[2];

  while(cin >> n){
    if(n == 0) break;
    vc[0].clear();
    vc[1].clear();
    len = 0;

    for(int i=0; i<n; i++){
      cin >> num >> v >> m;
      for(int j=0; j<=len; j++){
        if(j == len){
          vc[0].push_back(num);
          vc[1].push_back(v * m);
          len++;
          break;
        }
        if(vc[0][j] == num){
          if(vc[1][j] < 1000000){
            vc[1][j] += (long long)v * m;
          }
          break;
        }
      }
    }
    
    cnt = 0;
    for(int i=0; i<len; i++){
      if(vc[1][i] >= 1000000){
        cout << vc[0][i] << endl;
        cnt++;
      }
    }
    if(cnt == 0) cout << "NA" << endl;

  }

  return 0;

}

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

int main() {
	int n;
	while(std::cin >> n){
		if(!n){
			return 0;
		}
		std::map<int, long long> sales;
		while(n--){
			int id;
			long long unit, num;
			std::cin >> id >> unit >> num;
			sales[id] += unit * num;
		}
		map<int, long long>::iterator it;
		bool found = false;
		for(it = sales.begin(); it != sales.end(); it++){
			if(it->second >= 1000000){
				found = true;
				std::cout << it->first << std::endl;
			}
		}
		if(!found){
			std::cout << "NA" << std::endl;
		}
	}
	return 0;
}