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 <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

long long int n,a,b,c;



int main(){
    
        
    while(cin >> n){
        if(n==0)break;
        
        long long int ans[4001]={0};
        
        bool flag=true;
        for(int i=0; i<n; i++){
            cin>>a>>b>>c;
            if(b>=1000&&c>=1000)ans[a]=1000000;
            else if(b>=1000000)ans[a]=1000000;
            else if(ans[a]<1000000)ans[a]+=b*c;
        }
        
        for(int i=1; i<=4000; i++){
            if(ans[i]>=1000000){
                cout<<i<<endl;
                flag=false;
            }
        }
        
        if(flag)cout<<"NA"<<endl;
    }
            
}

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

int main()
{
  int n;
  while (std::cin >> n) {
    if (n == 0) break;
    
    bool na = true;
    std::map<int, long long> id_sales_map;

    for (int i = 0; i < n; ++i) {
      int ID;
      long long price, number;
      std::cin >> ID >> price >> number;

      if (id_sales_map[ID] < 1000000) {
        id_sales_map[ID] += price * number;
        if (id_sales_map[ID] >= 1000000) {
          std::cout << ID << std::endl;
          na = true;
        }
      }
    }

    if (na) {
      std::cout << "NA" << std::endl;
    }
  }

  return 0;
}

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

typedef long long ll;
typedef queue<int> qi;

const int lim = 1000000;

int n; ll en, price, qty, check[4001]; qi que;

int main()
{
    while(cin >> n) {
       if (n == 0) break;
       
       for(int i=0; i < n; ++i) {
           cin >> en >> price >> qty;
           if (check[en] >= 0) check[en] += price*qty;
           if (check[en] >= lim) {
               que.push(en);
               check[en]=-1;
           }
       }
        
       if (que.empty()) cout << "NA" << "\n";
       else {
           for(int i=0,len=que.size(); i < len; ++i) {
               cout << que.front() << "\n";
               que.pop();
           }
       }
    }

    return 0;
}

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

int main(){
	int n;
	while( cin >> n, n ){
		map<int, int> worker;
		queue<int> order;
		for( int i = 0; i < n; i++ ){
			int id, price, num;
			cin >> id >> price >> num;
			if( worker.find(id) == worker.end() ){
				order.push(id);
			}
			worker[id] += (price * num);
		}
		bool flag = true;
		while( !order.empty() ){
			if( worker[order.front()] >= 1000000 ){
				cout << order.front() << endl;
				flag = false;
			}
			order.pop();
		}
		if( flag ){
			cout << "NA" << endl;
		}
	}
}

C++: #include <iostream>
using namespace std;
int main()
{
	int n, no[4000], t[4000], num[4000], a[4000], i, j;
	while (cin >> n && n)
	{
		for (i = 0, j = 0; i < n; i++)
		{
			cin >> no[i] >> t[i] >> num[i];
			if (t[i] * num[i] >= 1000000)
				a[j] = no[i], j++;
		}
		if (j == 0)
			cout << "NA" << endl;
		else
			for (i = 0; i < j; i++)
				cout << a[i] << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;

typedef map<int, pair<int, long long> > mipill;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		mipill data;
		rep(i, n){
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			long long sum = ((long long)b) * c;
			if(data.count(a))
				data[a].second += sum;
			else
				data[a] = make_pair(data.size(), sum);
		}

		vector<pii> v;
		for(mipill::iterator itr = data.begin(); itr != data.end(); ++itr){
			if(itr->second.second >= 1000000ll)
				v.push_back(pii(itr->second.first, itr->first));
		}

		sort(v.begin(), v.end());
		rep(i, v.size()){
			printf("%d\n", v[i].second);
		}
		if(v.empty())
			puts("NA");
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<map>
#include<vector>
using namespace std;
typedef unsigned long long ll;
int main(){
  int n,val,num,inindex;
  vector<int> Index;
  map<int,ll> List;
  while(true){
    scanf("%d",&n);
    if(n == 0)break;
    List.clear();
    Index.clear();
    for(int i=0;i<n;i++){
      scanf("%d %d %d",&inindex,&val,&num);
      if(!List[inindex]){
	Index.push_back(inindex);
      }
      List[inindex]+=val*num;
    }
    bool NAf=true;
    for(int i=0;i<Index.size();i++){
      if(List[Index[i]] >= 1000000){
	printf("%d\n",Index[i]);
	NAf=false;
      }
    }
    if(NAf)printf("NA\n");
  }

  return 0;
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

#define INF 10000000
#define MAX_N 4001

int n;
int meibo[MAX_N];

struct kanri{

	int number;
	int sum;

}syain[MAX_N];

void shoki();

int main(){

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

		if(n == 0)
			break;

		shoki();

		int num = 0;
		int kari;

		for(int i = 0; i < n; i++){
			scanf("%d", &kari);
			bool flag = false;
			for(int j = 0; j < num; j++){
				if(syain[j].number == kari){
					int kari1, kari2;
					scanf("%d%d", &kari1, &kari2);
					syain[j].sum += kari1*kari2;
					flag = true;
					break;
				}
			}

			if(!flag){
				int kari1, kari2;
				syain[num].number = kari;
				scanf("%d%d", &kari1, &kari2);
				syain[num].sum += kari1 * kari2;
				num++;
			}

		}

		bool flag2 = false;

		for(int i = 0; i < n; i++){
			if(syain[i].sum >= 1000000){
				printf("%d\n", syain[i].number);
				flag2 = true;
			}
		}

		if(!flag2){
			printf("NA\n");
		}

	
	}


	return 0;

}

void shoki(){
	for(int i = 0; i < MAX_N; i++){
		syain[i].number = 0;
		syain[i].sum = 0;
	}
}

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

int main()
{
	array<long long, 4000> ar;
	vector<long long> ans;
	long long n;
	int e,p,q;
	
	while (true) {
		cin >> n;
		ar.fill(0);
		if (!n) {
			break;
		}

		bool isNA = true;
		for (int i = 0; i < n; ++i) {
			cin >> e >> p >> q;
			ar[e] += p*q;
		}
		for (int i = 0; i < 4000;++i) {
			if (ar[i] >= 1000000) {
				auto it = ans.begin();
				it = find(it, ans.end(), i);
				if (it == ans.end()) {
					ans.push_back(i);
				}
				isNA = false;
			}
		}
		if (isNA) {
			ans.push_back(-1);
		}

	}

	for (auto it : ans) {
		if (it != -1) {
			cout << it << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}

	return 0;
}