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 <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;
typedef long long ll;
#define INF 1000000000
#define EPS 0.000001

int n;
struct date{
	int num;
	ll total;
	bool flag;
}D[4000];
 
bool kanri[4001];
int kanri2[4001];
int main(){
 
	while(true){
		fill(kanri, kanri+4001,false);
		fill(kanri2,kanri2+4001, -1);
		cin >> n;
		if(n == 0)
			break;
		int count = 0;
		bool flag = false;
		for(int i = 0; i < n; i++){
			int kari;
			cin >> kari;
			int kari1, kari2;
			cin >> kari1 >> kari2;
			if(!kanri[kari]){
				if(kanri2[kari] != -1){
						flag = true;
						if(D[kanri2[kari]].total + kari1*kari2 >= 1000000){
							D[kanri2[kari]].flag = true;
							kanri[kari] = true;
						}
				}
				if(!flag){
					D[count].num = kari;
					D[count].total = kari1*kari2;
					D[count].flag = false;
					if(D[count].total >= 1000000)
						D[count].flag = true;
					kanri2[kari] = count;
					count++;
				}
			}
		}

		bool flag2 = false;
		for(int i = 0; i < count; i++){
			if(D[i].flag){
				flag2 = true;
				printf("%d\n", D[i].num);
			}
		}
		if(!flag2){
			printf("NA\n");
		}

	}

	


	return 0;
 
}

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

int main() {
  int n;
  
  while(cin>>n, n) {
    map<int,int> mp;

    for(int i=0; i<n; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      mp[a] += b * c;
    }
    bool isExist = false;
    for(map<int, int>::iterator it = mp.begin(); it!=mp.end(); it++) {
      if( it->second >= 1000000 ) {
	isExist = true;
	cout << it->first << endl;
      }
    }
    if( !isExist ) cout << "NA" << endl;
  }
  
  return 0;
}

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

int main()
{
    int n, no;
    long long yen, num;
    bool update = false;
    long long total[4001];
    std::queue<int> que;
    
    for (int i = 0; i < 4001; ++i) {
        total[i] = 0;
    }

    std::cin >> n;
    
    while (n != 0) {
        
        /*input*/
        for (int i = 0; i < n; ++i) {
            scanf("%d %lld %lld", &no, &yen, &num);
            total[no] += yen * num;
            que.push(no);
        }
        /*output*/
        while (!que.empty()) {
            if (total[que.front()] >= 1000000) {
                std::cout << que.front() << std::endl;
                total[que.front()] = 0;
                update = true;
            }
            que.pop();
        }
        if (!update) {
            std::cout << "NA" << std::endl;
        }
        std::cin >> n;
    }
    
    return 0;
}

C++: #include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  bool f;
  vector<pair<int, int> > v;
  int n, a, b, c;
  while (cin >> n && n > 0) {
    v.clear();
    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c;
      f = 0;
      for (int j = 0; j < v.size(); j++) {
        if (v[j].first == a) {
          v[j].second += b * c;
          f = 1;
        }
      }
      if (!f) {
        v.push_back(pair<int, int>(a, b * c));
      }
    }
    f = 0;
    for (int i = 0; i < v.size(); i++) {
      if (v[i].second >= 1000000) {
        cout << v[i].first << endl;
        f = 1;
      }
    }
    if (!f) {
      cout << "NA" << endl;
    }
  }
  return 0;
}

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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while (cin >> n && n){
        string a;
        long long b, c;
        map<string, long long> data;
        vector<string> id;
        rep(i, n){
            cin >> a >> b >> c;
            c *= b;
            if (data.find(a) == data.end()){
                data.insert(make_pair(a, c));
                id.push_back(a);
            }
            else{
                data[a] += c;
            }
        }

        bool NA = true;
        rep(i, id.size()){
            if (data[id[i]] >= 1000000){
                cout << id[i] << endl;
                NA = false;
            }
        }
        if (NA) cout << "NA" << endl;
    }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
int main() {
	std::vector<int> v;
	while (1) {
		int count=0;
		int n;
		std::cin >> n;
		if (n == 0) {
			break;
		}
		std::vector<std::vector<int>> a(n, std::vector<int>(3));
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j) {
				std::cin >> a[i][j];
			}
		}
		std::vector<int>num(n);
		for (int i = 0; i < n; ++i) {
			for (int j = 1; j < n; ++j) {
				if (a[i][0] == a[j][0]) {
					num[i] += a[i][1] * a[i][2] + a[j][1] * a[j][2];
					++count;
					break;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			if (count == 0) {
				v.push_back(0);
			}
			if (num[i] >= 1000000) {
				if (count >= 2) {
					sort(num.begin(), num.end());
				}
				v.push_back(a[i][0]);
			}
		}
	}
	for (int i = 0; i < v.size(); ++i) {
		if (v[i] == 0) {
			std::cout << "NA" << std::endl;
		}
		else {
			std::cout << v[i] << std::endl;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    long long int syain,kakaku,kosuu,syains[5000]={0};
    long long int bango[5000]={0},flag[5000]={0},n;
    while(cin>>n,n){
        for(int i=0;i<n;i++){
            cin>>syain>>kakaku>>kosuu;
            bango[i]=syain;
            syains[syain]+=kakaku*kosuu;
        }
        for(int i=0;i<5000;i++){
            if(syains[bango[i]]>=1000000){
                if(flag[bango[i]]==0){
                        cout<<bango[i]<<endl;
                        flag[bango[i]]=1;
                }
            }
        }

    }
    return 0;
}

C++: #include <stdio.h>
int main(){
    int n,a[5000],m,p,q;
    bool b[5000],f;
    while(1){
        scanf("%d",&n);
        if(n==0)return 0;
        for(int i=0;i<5000;i++)a[i]=b[i]=0;
        f=false;
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&m,&p,&q);
        if(!b[m]){
            a[m]+=p*q;
            if(a[m]>1000000){
                b[m]=true;
                f=true;
                printf("%d\n",m);
            }
        }
    }
        if(!f)printf("NA\n");
    }
}