Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		sales := make([]int, 4000)
		members := make([]int, 0)
		memberCheck := make(map[int]bool)

		for i := 0; i < n; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			e, _ := strconv.Atoi(input[0])
			p, _ := strconv.Atoi(input[1])
			q, _ := strconv.Atoi(input[2])

			if e >= 1 && e <= 4000 && memberCheck[e] == false {
				members = append(members, e)
				memberCheck[e] = true
			}
			sales[e-1] += p * q
		}

		emptyFlag := true
		for _, v := range members {
			if sales[v-1] >= 1000000 {
				fmt.Println(v)
				emptyFlag = false
			}
		}

		if emptyFlag == true {
			fmt.Println("NA")
		}
	}
}

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 <tuple>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(false);

    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 <iostream>
using namespace std;

int n;
int main(){
	cin >> n;
	int id[n];
	int p[n];
	int q[n];
	int num = 0;
	for(int i = 0; i < n; i++){
		cin >> id[i] >> p[i] >> q[i];
		if(p[i] * q[i] >= 1000000){
			cout << id[i] << "\n";
			num++;
		} 
	}
	if(num == 0){
		cout << "NA";
	} 
    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n,ans[4000];
	double a,b;
	
	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		int i,j;
		for(i=0,j=0;i<n;i++)
		{
			int num,flag=1;
			cin >> num >> a >> b ;
			if(a/1000000.0*b>=1.0)
			{
				for(int k=0;k<j;k++)
				{
					if(ans[k]==num)
						flag=0;
				}
				if(flag==1)
				{
					ans[j]=num;
					j++;
				}
			}
		}
		
		if(j!=0)
		{
			for(int i=0;i<j;i++)
			{
				cout << ans[i] << endl;
			}
		}
		else
			cout << "NA" << endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int st[4444];
int stf[4444];
int main(void)
{
  while(1){
    int n;
    bool f = true;
    cin >> n;
    if(!n) break;
    memset(st,0,sizeof(st));
    memset(stf,-1,sizeof(stf));
    for(int i = 0; i < n; i++){
      int a,b,c;
      cin >> a >> b>> c;
      st[a] += b * c;
      if(1000000 <= st[a] && stf[a]){
	cout << a << endl;
	stf[a] = 0;
	f = false;
      }
    }
    if(f) puts("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;

  while(scanf("%d",&n)){
    if(n == 0) break;
    ll a, b;
    int id;
    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()) if(out[ids[i]]){
      printf("%d\n",ids[i]);
      out[ids[i]] = false;
      f = true;
    }
    if(f) puts("NO");
  }

  return 0;
}

C++: #include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
	while(1)
	{
		int n; cin >> n ;
		if(!n) break;
		map<int,long long> a;
		vector<int> ans;
		queue<int> q;
		for(int i=0;i<n;i++)
		{
			long b,c; int num;
			cin >> num >> b	>> c ;
			a[num]+=(long long) b*c;
			bool flag=true;
			for(int j=0;j<q.size();j++)
			{
				int tmp=q.front();
				if(tmp==num) flag=false;
				q.push(tmp); q.pop();
			}
			if(flag==true) q.push(num);
		}
		map<int,long long>::iterator p;
		bool flag=false;
		for(p=a.begin(); p!=a.end();p++)
			if(p->second >= 1000000) {ans.push_back(p->first); flag=true;}
		if(flag==false) cout << "NA" << endl;
		else
		{
			while(!q.empty() && !ans.empty())
			{
				vector<int>::iterator p;
				int tmp=q.front(); q.pop();
				p=find(ans.begin(),ans.end(),tmp);
				if(p!=ans.end()) cout << *p << endl;
			}
		}
	}
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

ll cost[4010];
signed main(void)
{
  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    VI v;
    REP(i, n) {
      ll e, p, q;
      cin >> e >> p >> q;
      if(cost[e] < 1000000 && cost[e]+p*q>=1000000) {
        v.PB(e);
        cost[e] = 1000000;
      } else {
        cost[e] += p*q;
      }
    }
    if(v.size() == 0) cout << "NA" << endl;
    REP(i, v.size()) cout << v[i] << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,s[5000];
	int a,b,c;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<5000;i++)
		s[i]=0;
	for(int i=0;i<n;i++){
		cin>>a>>b>>c;
		s[a]+=b*c;
	}
	bool t=false;
	for(int i=0;i<5000;i++){
		if(s[i]>=1000000){
			cout<<i<<endl;
			t=true;
		}
	}
	if(t==false)
		cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	long long int data[4001];
	long long int n;
	while(1){
		cin>>n;
		if(n==0)break;
		for(int i=1;i<=4000;i++){
			data[i]=0;
		}
		for(int i=0;i<n;i++){
			long long int a,b,c;
			cin>>a>>b>>c;
			data[a]+=b*c;
		}
		bool f=false;
		for(int i=1;i<=4000;i++){
			if(data[i]>=1000000){
				cout<<i<<endl;
				f=true;
			}
		}
		if(!f)cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <iostream>
#define FOR(i,a,b) for(int i=(a); i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;

int main(){
  int n;//入力するデータ
  int check;
  while(cin >> n){
    if(n==0) break;
    check=0;
    ll num[4001]={0};//社員の売り上げ金額
    bool bl[4001]={false};
    ll t[4001]={0};//社員番号
    ll emp,cost,count;
    int k=0;
    REP(i,n){
      cin >> emp >> cost >> count;
      if(bl[emp]==false){
        bl[emp]=true;
        t[k++]=emp;
        num[emp] = cost*count;
      }
      else{
      num[emp] += cost * count;
      }
    }
    REP(i,n){
      if(num[t[i]] >= 1000000){
        cout << t[i] << endl;
        check++;
  }
    }
    if(check==0)
      cout << "NA" << endl;
  }
}