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<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
using namespace std;

int main(){
  int n;
  while(cin >> n, n){
    vector<int> num;
    set<int> used;
    map<int, long long> sales;
    int a, b, c;
    for(int i = 0;i < n;i++){
      cin >> a >> b >> c;
      num.push_back(a);
      if(sales[a] >= 1000000)continue;
      sales[a] += b * c;
    }
    bool ok = false;
    for(int i = 0;i < n;i++){
      int p = num[i];
      if(used.count(p))continue;
      used.insert(p);
      if(sales[p] >= 1000000){
	cout << p << endl;
	ok = true;
      }
    }
    if(!ok)cout << "NA" << endl;
  }
  return 0;
}

C++: #include <stdio.h>
 
 

 
int main(void){
	int i,j,k;
	int n,num[4000];
	long long int tanka[4000],sale_num[4000],sale_all[4001];
	bool judge[4001];
	
	while(scanf("%d",&n),n){
		
		//初期化

		k=0;
		for(j=0;j<=4001;j++){
			judge[j]=0;
			sale_all[j]=0;
		}
		
		for(i=0;i<n;i++){
			scanf("%d%lld%lld",&num[i],&tanka[i],&sale_num[i]);
		}
		
		
		//idに対応したsaleに+
		for(i=0;i<n;i++){
			sale_all[num[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>
using namespace std;
int main() {
  bool f;
  int n, a, b, c, d, e;
  while (cin >> n && n > 0) {
    d = e = f = 0;
    while (n--) {
      cin >> a >> b >> c;
      if (a != d) {
        e = 0;
      }
      e += b * c;
      if (e >= 1000000) {
        cout << a << endl;
        f = 1;
      }
      d = a;
    }
    if (!f) {
      cout << "NA" << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

struct EmployeeSale {
	long employee_number;
	long long sales;
};

int main()
{
	int data_count = 0;
	while (std::cin >> data_count) {
		if (data_count == 0) {
			break;
		}
		std::vector<EmployeeSale> sales_per_employee;
		for (int i = 0; i < data_count; ++i) {
			long employee_number = 0;
			long unit_price = 0;
			long quantity = 0;
			if (std::cin >> employee_number >> unit_price >> quantity) {
				double each_sales = static_cast<long long>(unit_price) * quantity;
				auto it = std::find_if(
					sales_per_employee.begin(),
					sales_per_employee.end(),
					[=](EmployeeSale const& sale){ return sale.employee_number == employee_number; });
				if (it != sales_per_employee.end()) {
					it->sales += each_sales;
				} else {
					EmployeeSale sales = { employee_number, each_sales };
					sales_per_employee.push_back(sales);
				}
			}
		}

		std::vector<EmployeeSale> sales_achieved;
		std::copy_if(
			sales_per_employee.begin(),
			sales_per_employee.end(),
			std::back_inserter(sales_achieved),
			[](EmployeeSale const& sale){ return sale.sales >= 1000000; });
		if (!sales_achieved.empty()) {
			std::for_each(
				sales_achieved.begin(),
				sales_achieved.end(),
				[](EmployeeSale const& sale){ std::cout << sale.employee_number << std::endl; });
		} else {
			std::cout << "NA\n";
		}
	}

	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<functional>
#define inf 1000000
using namespace std;
long long int p[114514],x,y,z,w;
int main(void)
{
	int i,j,k,f,n,cnt;
	while(1) {
		cin>>n;
		f=0,cnt=0;
		if(!n)break;
		for(i=0;i<4001;i++) p[i]=0;
		for(i=0;i<n;i++) {
			cin>>x>>y>>z;
			if(p[x]>=inf) continue;
			p[x]+=y*z;
		}
		for(i=0;i<4001;i++) {
			if(p[i]>=inf) {
				cout<<i<<endl;
				f=1;
			}
		}
		if(f==0) cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;
class MAN{
public:
	long long uriage;
	int number;
};

int main(int argc, char const* argv[])
{
	MAN person[4000];
	int n;
	bool flag;

	while( cin >> n && n != 0 ){
		for( int i = 0;i < n;i++ ){
			int target;
			long long a,b;
			cin >> target >> a >> b;

			int j;
			for( j = 0;j < i;j++ ){
				if( person[j].number == target ){
					person[j].uriage += a*b;
					break;
				}
			}
			if( j == i ){
				person[i].number = target;
				person[i].uriage = a * b;
			}
		}
		flag = false;
		for( int i = 0;i < n;i++ ){
			if( person[i].uriage >= 1000000 ){
				cout << person[i].number << endl;
				flag = true;
			}
		}
		if( flag == false ) cout << "NA" << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int  existnum(vector<int> v,int e){
    for(int i=0;i<v.size();i++){
        if(v[i]==e)return i;
    }
    return -1;
}

int main(void){
    int n,b=0,e,p,q,num;
    vector<int> se,sp,sq;
    while(1){
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>e;
            cin>>p;
            cin>>q;
            //cout<<existnum(se,e)<<endl;
            if((num=existnum(se,e))!=-1){
                sp[num]+=p;
                //cout<<sp[num]<<endl;
                sq[num]+=q;
                //cout<<sq[num]<<endl;
            }else{
                se.push_back(e);
                sp.push_back(p);
                sq.push_back(q);
            }
            //cout<<se.back()<<endl;
        }
        for(int i=0;i<n;i++){
            if(sp[i]*sq[i]>=1000000){
                cout<<se[i]<<endl;
                b=1;
            }
        }
        if(b==0){
            cout<<"NA"<<endl;
        }
        sp.clear();
        se.clear();
        sq.clear();
        b=0;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

string int_to_str(int n) {
	stringstream ss;
	string ret;

	ss << n;
	ss >> ret;

	return ret;
}


int keta(int n) {
	string str = int_to_str(n);

	return str.size();
}

int main() {
	int n;
	while (cin >> n, n) {
		bool f = false;
		map<int, ll> datas;
		vector<int> noes;
		for (int i = 0; i < n; ++i) {
			int no, a, b; cin >> no >> a >> b;

			if ( find( noes.begin(), noes.end(), no) == noes.end() )
				noes.push_back(no);

			if (datas[no] < 1000000) {
				if (keta(a) + keta(b) - 2 >= 6)
					datas[no] = 1000000,
					f = true;

				else if ((datas[no] += a * b) >= 1000000)
					f = true;
			}
		}
		for (int i = 0; i < noes.size(); ++i)
			if (datas[noes[i]] >= 1000000)
				cout << noes[i] << endl;

		if (!f) cout << "NA" << endl;
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS 1

#include <cstdio>
#include <vector>
using namespace std;
int main()
{
	long long n;
	while (scanf("%Ld\n", &n), n) {
		vector<pair<long long, long long> > v;
		for (long long i = 0; i < n; i++) {
			long long p, q, r, f = 1;
			scanf("%Ld %Ld %Ld\n", &p, &q, &r);
			for (long long j = 0; j < v.size(); j++) {
				if (v[j].first == p) {
					f = 0;
					v[j].second += q * r;
				}
			}
			if (f) {
				pair<long long, long long> pa(p, q * r);
				v.push_back(pa);
			}

		}
		long long g = 1;
		for (long long i = 0; i < v.size(); i++) {
			if (1000000 <= v[i].second) {
				g = 0;
				printf("%Ld\n", v[i].first);
			}
		}
		if (g) puts("NA");
	}
	return 0;
}