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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    map<int, int> t;
    while (n--) {
      int i, p, q;
      cin >> i >> p >> q;
      t[i] += p * q;
    }
    vi v;
    for (auto x : t) {
      if (x.se >= 1000000) v.pb(x.fi);
    }
    sort(all(v));
    if (v.size()) {
      rep(i, v.size()) cout << v[i] << endl;
    } else {
      cout << "NA" << endl;
    }
  }
}

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

typedef long long ll;

int main()
{
	int n;
	std::map<int, ll> m;

	while( std::cin >> n, n )
	{
		m.clear();

		for( ll a, b, c, i = 0; i < n; ++i )
		{
			std::cin >> a >> b >> c;
			m[a] += b * c;
		}

		bool f = false;
		for( auto it = m.begin(); it != m.end(); ++it )
			if( it->second >= 1000000 )
				std::cout << it->first << std::endl, f = true;

		if( !f )
			std::cout << "NA" << std::endl;
	}
	return 0;
}

C++: #include <map>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    map<int,long long int> emps;
    vector<int> ids;
    int id,cost,amount,n;
    while(cin >> n,n){
        for(int i=0;i<n;i++){
            cin >> id >> cost >> amount;
            if(emps.find(id)!=emps.end()){
                emps[id]+=cost*amount;
            }else{
                emps[id]=cost*amount;
                ids.push_back(id);
            }
        }
        sort(ids.begin(),ids.end());
        for(int i=0;i<ids.size();i++){
            if(emps.at(ids[i])>=1000000) cout << ids[i] << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        bool na = true;
        for(int i=0; i<n; ++i){
            int a, b, c;
            cin >> a >> b >> c;
            if(long long(b) * c >= 1000000){
                cout << a << endl;
                na = false;
            }
        }
        if(na)
            cout << "NA" << endl;
    }
}

C++: #include <stdio.h>
 
 
int n;
long long num[4000],tanka[4000],sale_num[4000];
int sale_all[4001],judge[4001];
 
int main(void){
	int i,j,k;
	
	while(scanf("%d",&n),n!=0){
		
		for(i=0;i<n;i++){
			scanf("%d%d%d",&num[i],&tanka[i],&sale_num[i]);
			
		}
		
		//初期化
		k=0;
		for(j=0;j<=4001;j++){
			judge[j]=0;
			sale_all[j]=0;
		}
		
		//idに対応したsaleに+
		for(i=0;i<n;i++){
			sale_all[num[i]] += tanka[i]*sale_num[i];
		}
		
		for(i =0; i < n; i++){
			if((sale_all[num[i]] >= 1000000)&&(judge[num[i]]==0)){
				printf("%d\n",num[i]);
				judge[num[i]]=1;
				k=1;
			}
		}
		
		if(k!=1)printf("NA\n");
	}
	
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <bitset>
#include <complex>
using namespace std;
 
const double EPS = 1e-9;
const double PI = 3.14159265359;
 
typedef complex<double> P;

typedef long long int li;

int main(){
	int n;

	while(cin >> n, n){
		vector<li> sales(4001);
		int num;
		li tanka, kazu;
		for(int i = 0; i < n; i++){
			cin >> num >> tanka >> kazu;
			sales[num] += tanka*kazu;
		}

		bool NA = true;
		for(int i = 1; i <= 4000; i++){
			if(sales[i] >= 1000000){
				cout << i << endl;
				NA = false;
			}
		}
		if(NA){
			cout << "NA" << endl;
		}
	}

    return 0;
}

C++: #include<stdio.h>

int main(){
int N;
int n,m,p;
int P[4001][3]={};
int PT[4001][4]={};

while(1){
scanf("%d",&N);if(N==0)break;

for(int i=1;i<=N;i++){
scanf("%d %d %d",&n,&m,&p);
P[n][0]+=m*p;if(P[n][1]==0)P[n][1]=i;
}
int c=0;
for(int i=0;i<4000;i++)
if(1000000<=P[i][0]){PT[c][0]=P[i][0];PT[c][1]=P[i][1];PT[c][2]=i;c++;}

for(int i=0;i<c;i++)
for(int j=c-1;j>i;j--)
if(PT[j][1]<PT[j-1][1])
{int TT=PT[j][1];PT[j][1]=PT[j-1][1];PT[j-1][1]=TT;
 int TTT=PT[j][2];PT[j][2]=PT[j-1][2];PT[j-1][2]=TTT;}

for(int i=0;i<c;i++)
printf("%d\n",PT[i][2]);
if(c==0)printf("NA\n");
for(int i=0;i<4000;i++)
{P[i][0]=0;P[i][1]=0;P[i][2]=0;
 PT[i][0]=0;PT[i][1]=0;PT[i][2]=0;PT[i][3]=0;}

}
return  0;
}

C++: #include <vector>
#include <map>
#include <algorithm>
#include <stdio.h>

#include<iostream>

using namespace std;

typedef long long ll;

struct data{
  int id;
  ll sum;
};

int main(void)
{

  int n;
  lll num, cost;
  data d[10000];

  while(cin >> n && n){
    int flag = true;
    for(int i = 0; i < n; i++){
      cin >> d[i].id >> cost >> num;
      d[i].sum = cost*num;
    }

    for(int i = 0; i < n-1; i++){
      for(int j = i+1; j < n; j++){
        if(d[i].id == d[j].id && d[j].id){
          d[i].sum += d[j].sum;
          d[j].id = false;
        }
      }
    }

    for(int i = 0; i < n; i++){
      if(d[i].sum >= 1000000 && d[i].id){
        cout << d[i].id << endl;
        flag = false;
      }
    }
    if(flag){
        cout << "NA" << endl;
    }
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int bangou,tanka,kosuu;
    int number; cin >> number;
    do{
        int man[4000];
        for(int i=0;i<4000;i++){
            man[i]=0;
        }
        for(int i=0;i<number;i++){
            cin >> bangou >> tanka >> kosuu;
            man[bangou] += tanka*kosuu;
        }
        int count =0;
        for(int i=0;i<4000;i++){
            if(man[i]>=1000000){
                cout << i;
                count++;
            }
        }
        if(count==0)
            cout<< "NA" << endl;
        cin >> number;
    }while(number !=0);

}