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>
# include <vector>
# include <cstring>

int n;
int a[3];
std::vector<std::pair<int, int>> vec;
bool x[4001];

int main() {
	while (1) {
		std::cin >> n;
		if (n == 0)
			break;
		int count = 0;
		vec.clear();
		std::memset(x, false, sizeof(x));

		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j)
				std::cin >> a[j];
			if (x[a[0]]) {
				for (int k = 0; k < vec.size(); ++k) {
					if (vec[k].first == a[0])
						vec[k].second += a[1] * a[2];
				}
			}
			else {
				vec.push_back(std::make_pair(a[0], a[1] * a[2]));
				x[a[0]] = true;
			}
		}
		for (auto it = vec.begin(); it != vec.end(); ++it) {
			if ((*it).second >= 1000000) {
				std::cout << (*it).first << std::endl;
				++count;
			}
		}
		if (count==0)
			std::cout << "NA" << std::endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int n;
    while (cin >> n, n) {
        vector<ull> s(4010, 0);
        REP(i,n) {
            ll e,p,q;
            cin >> e >> p >> q;
            s[e-1] += p*q;
        }
        bool flag = false;
        REP(i,4000) {
            if (s[i] >= 1000000) {
                cout << i + 1 << endl;
                flag = true;
            }
        }
        if (!flag) cout << "NA" << endl;
    }
    return 0;
}

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

int main()
{
	int n;
	
	while (cin >> n, n){
		bool num[4001] = {false}, flag = false;
		int sum[4001] = {0}, m, ex, a;
		
		for (int i = 0; i < n; i++){
			cin >> m >> ex >> a;
			sum[m] += ex * a;
			if (1000000 <= sum[m]){
				num[m] = true;
				flag = true;
			}
		}
		
		if (flag){
			for (int i = 1; i <= 4000; i++){
				if (num[i]){
					cout << i << endl;
				}
			}
		}
		else {
			cout << "NA" << endl;
		}
	}
	
	return (0);
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#define N 4001
using namespace std;
int main(){

  int n,b;
  int a,num[N],tanka,uriage,jun[N];
  bool judge,nnnn;

  while(cin >> n){
    if(n==0)
      break;

    judge = true;
    for(int i=0;i<N;i++){
      num[i] = 0;
    }

    for(int i=0,b=0;i<n;i++){
      nnnn = true;
      cin >> a >> tanka >> uriage;
      num[a] += tanka * uriage;
      for(int j=0;j<i;j++){
	if(jun[j]==a){
	  nnnn = false;
	  break;
	}
      }
      if(nnnn){
	jun[b] = a;
	b++;
      }
      else
	jun[b] = 0;
    }

    for(a=0;jun[a]!=0;a++){
      if(num[jun[a]]>=1000000){
	cout << jun[a] << endl;
	judge = false;
      }
    }
    if(judge)
      cout << "NA" << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n;
	int number[4000];
	int tanka[4000];
	int ryou[4000];
	long goukei[4000];
	while(cin>>n,n){
		for(int i=0;i<n;i++){
			cin>>number[i];
			cin>>tanka[i];
			cin>>ryou[i];
			goukei[i]=tanka[i]*ryou[i];
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(number[i]==number[j]){
					goukei[i]+=goukei[j];
					goukei[j]=0;
					}
			}
		}
		int flag=-1;
		for(int i=0;i<n;i++){
			if(goukei[i]>=1000000){
				flag=0;
				cout<<number[i]<<endl;
				}
		}
		if(flag==-1)
			cout<<"NA"<<endl;
	}
}

C++: #include<iostream>
#include <sstream>
#include <cstdlib>
#include <cstring>
using namespace std;

struct Saler
{
	int Number;
	int Saled;
};

int main(){
	struct Saler* sl;
	int n, a, b, c, i;
	bool isFound;
	
loop:
	scanf("%d", &n);		// データ個数
	if(n == 0) goto end_scope;
	sl = (struct Saler*)malloc(sizeof(struct Saler) * (n + 1));
	memset(sl, sizeof(struct Saler)*n, 0);
	for(int j = 0; j < n; j++)
	{
		scanf("%d %d %d", &a, &b, &c);
		for(i = 0; i < n; i++)
		{
			if((sl+i)->Number == 0)
			{
				sl[i].Number = a;
				sl[i].Saled = b * c;
				break;
			}
			if((sl+i)->Number == a)
			{
				sl[i].Saled += b * c;
				break;
			}
		}
	}
	isFound = false;
	for(int j = 0; j < n; j++)
	{
		if(sl[j].Saled >= 1000000)
		{
			cout << sl[i].Number << endl;
			isFound = true;
		}
	}
	!isFound && (cout << "NA" << endl);
	free(sl);
end_scope:
    return 0;
}

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

int main(){
	
	int n , id , price , num, cnt;
	while(cin >> n , n!=0){
		vector<long long int> p(4001,0);
		vector<int> a;
		while(n--){
			cin>>id>>price>>num;
			if(find(a.begin(),a.end(),id)==a.end()) a.push_back(id);
			p[id]+=price*num;
			}
		cnt=0;	
		for(int i=0;i<a.size();i++){
			if(p[a[i]]>=1000000){
				cout << a[i] << endl; 
				cnt++;
			} 
		}
		if (cnt==0) cout << "NA" << endl;
	}
		return 0;
}

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

int main(){
	int n, s, m, No;
	int person[4001];
	bool flag;
	
	while( cin >> n, n){
		flag = true;		
		for(int i=0 ; i<4001 ; i++){
			person[i] = 0;
		}
		
		for(int i=0 ; i<n ; i++){
			cin >> No >> s >> m;
			person[No] += s*m; 
		}
		for(int i=0 ; i<4001 ; i++){
			if(person[i] >= 1000000){
				flag = false;
				cout << i << endl;
			}
		}
		
		if(flag){
			cout << "NA" << endl;
		}
	}
	
	return 0;
}

C++: #include <iostream>


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

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

	while( cin >> n && n != 0 ){
		person  = new MAN[n];
		for( int i = 0;i < n;i++ ){
			int target;
			int 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;
		delete[] person;
	}

	return 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 = std::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;
}