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

int main(){
	int n;
	long long int p[4000];
	int count;
	
	while(cin>>n,n){
		for(int i=0;i<4000;++i)p[i]=0;
		
		for(int i=0;i<n;++i){
			long long wn,va,cn;
			cin>>wn>>va>>cn;
			p[wn-1] += va*cn;
		}
		count = 0;
		for(int i=0;i<4000;++i){
			if(p[i] >= 1000000){cout<<i+1<<endl;count++;}
		}
		if(!count)cout<<"NA"<<endl;
		
		
		
		
		
	}
	
	
	
}

C++: # include<iostream>
# include<string>
#include<conio.h>
using namespace std;

int main(){
	int datasuu = 0;
	int flag[4000][4000];
	int sbangou[4000][4000];
	int hanbai[4000][4000];
	int uriage[4000][4000];
	int goukei[4000][4000];
	int kaisuu = 0;
	for (int j = 0;; j++){
		cin >> datasuu;
		if (datasuu == 0){
			kaisuu = j;
			break;
		}
		for (int i = 0; i < datasuu; i++){
			scanf("%d%d%d", &sbangou[j][i], &hanbai[j][i], &uriage[j][i]);
			for (int z = 0; z < i; z++){
				if (hanbai[j][i] == hanbai[j][z]){
					goukei[j][i] += goukei[j][z];
				}
			}
			goukei[j][i] += hanbai[j][i] * uriage[j][i];
			if (goukei[j][i] >= 1000000){
				flag[j][i] = 1;
				goukei[j][i] = hanbai[j][i] * uriage[j][i];
			}

		}
	}
	int on = 0;
	for (int i = 0; i < 4000; i++){
		for (int j = 0; j < 4000; i++){
			if (flag[i][j] == 1){
				cout << sbangou[i][j] << endl;
				on = 1;
			}
			if (on == 0)cout << "NA";
		}
	}
	return  0;
}

C++: #include <iostream>
#include <map>
#include <vector>
using namespace std;
int main (int argc, char const* argv[]) {
  int saler_number;
  while (true) {
    cin >> saler_number;
    if (saler_number == 0) break;
    map<int,long long> result;
    vector<int> history;
    int id, price, num;
    for (int i = 0; i < saler_number; i += 1) {
      cin >> id >> price >> num;
      long long tmp = price * num;
      if (result.count(id) == 0) {
        result.insert(make_pair(id,tmp));
        history.push_back(id);
      } else {
        result[id] += tmp;
      }
    }
    //
    bool valid_NA = true;
    for (int i = 0; i < history.size(); i += 1) {
      if (result[history[i]] >= 1000000) {
        cout << history[i] << endl;
        valid_NA = false;
      }
    }
    if (valid_NA) cout << "NA" << endl;
  }
  return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))



LL snum[4001];
int main(){
	LL N;
	vector<string>res;
	while(1){
		cin>>N;
		if(N==0)break;
		CLR(snum);
		vector<LL>vn;
		REP(i,N){
			LL num,tanka,suryo;
			cin>>num>>tanka>>suryo;
			vn.PB(num);
			snum[num]+=tanka*suryo;
		}
		bool c=false;
		set <LL>sl;
		REP(i,SZ(vn)){
			if(snum[vn[i]]>=1000000&&sl.find(vn[i])==sl.end()){
				c=true;
				sl.insert(vn[i]);
				res.PB(toString(vn[i]));
			}
		}
		if(!c)res.PB("NA");
	}
	REP(i,SZ(res)){
		cout<<res[i]<<endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(){

	int n=1, i, x[4000] = {}, xx[4000] = {}, xxx[4000] = {}, r, y=0;

	while (n > 0){
		scanf("%d", &n);

		for (i = 0; i < n; i++){
			scanf("%d %d %d",&x[i],&xx[i],&xxx[i]);
		}

		for (r = 0; r < 4000; r++){
			
			if (xx[r] * xxx[r] > 1000000){
				printf("%d\n", x[r]);
			}	
		}
		if (y == 0){ printf("NA\n"); (y = 0); }		
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    int a[4010] = {}, b[4010] = {};
    memset(a, -1, sizeof(a));
    for (int i = 0; i < n; i++) {
      int e, p, q;
      cin >> e >> p >> q;
      b[e] += p * q;
      if (a[e] < 0) a[e] = i;
    }
    vector<int> ans;
    for (int i = 1; i <= 4000; i++) {
      if (b[i] >= 1000000) ans.emplace_back(i);
    }
    sort(ans.begin(), ans.end(), [&](int p, int q) {
      return a[p] < a[q];
    });
    if (ans.empty()) {
      cout << "NA" << endl;
    } else {
      for (auto i : ans) cout << i << endl;
    }
  }

  return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include <vector>
#include <map>
#include<cstdlib>
#include<iomanip>
#include<queue>


using namespace std;

void Solution()
{
   	int n;
    
    long long number, perPrice, amount;
    
    bool isUsed;
    //long long valueCheck[4000];
    vector<long long> valueCheck(4001, 0);
    queue<int> que;
    
    while(true)
    {
        isUsed = false;
        
        cin>>n;
        
        if (n == 0)
        {
            break;
        }
        
        while(n--)
        {
            cin>>number>>perPrice>>amount;
            
            valueCheck[number] += perPrice * amount;
            que.push(number);
        }
        
        while (!que.empty()) //if empty return true
        {
            if (valueCheck[que.front()] >= 1000000) //check the first element
            {
                cout<<que.front()<<endl;
                
                isUsed = true;
            }
            
            valueCheck[que.front()] = 0;
            
            que.pop(); //delete the beginning element, do the next judgement
        }
        
        if (!isUsed)
        {
            cout<<"NA"<<endl;
        }
        
    }
}

int main()
{
    Solution();
    return 0;
}