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 <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

/*
  AOJ :: 0100
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0100&lang=jp
 */

typedef long long ll;

int main(){
    int n,num,tanka,count,i;
    vector<int> jun;
    set<int> S;
    map<int,ll> mll;

    while( cin >> n, n ){
        // init
        jun.clear(); S.clear(); mll.clear();

        rep(i,n){
            cin >> num >> tanka >> count;

            if( S.count(num) == 0 ){
                jun.push_back(num);
                S.insert(num);
            }
            mll[num] += (ll)tanka * (ll)count;
        }

        bool ok = false;
        rep(i,jun.size()){
            if( mll[jun[i]] >= 1000000 ){
                ok = true;
                printf("%d\n",jun[i]);
            }
        }
        if( !ok ){
            puts("NA");
        }
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1)

int main(){
  int n;
  while(cin >> n, n){
    map<int,long long int> e;
    vector<int> num;
    int cntnum[4000] = {0};
    for(int i = 1; i <= 4000; i++){
      e[i] = 0;
    }
    for(int i = 0; i < n; i++){
      int tmp[3];
      cin >> tmp[0] >> tmp[1] >> tmp[2];
      e[tmp[0]] += tmp[1] * tmp[2];
      if(cntnum[tmp[0]] == 0){
        num.push_back(tmp[0]);
        cntnum[tmp[0]]++;
      }
    }
    int cnt = 0;
    for(int i = 0; i < num.size(); i++){
      if(e[num[i]] >= 1000000){
        cout << num[i] << endl;
        cnt++;
      }
    }
    if(cnt == 0){
      cout << "NA" << endl;
    }
  }
}

C++: #include "iostream"
using namespace std;

int LinearSearch(int x, int S[], int N) {
	S[N] = x;
	for (int i = 0; ; i++) {
		if (S[i] == x)
			if (i < N) {
				return 0;
			}
			else
				return 1;
	}
}

int main()
{
	while (1) {
		int h[4000] = { 0 };
		int m[4000] = { 0 };
		int a = 0;
		int n;
		cin >> n;
		if (n == 0)
			break;
		int number, nedan, amount;
		for (int i = 0; i < n; i++) {
			cin >> number >> nedan >> amount;
			h[number] += nedan*amount;
			if (h[number] >= 1000000) {
				if (LinearSearch(number, m, a)) {
					m[a] = number;
					a++;
				}
			}
		}
		if (a == 0)
			cout << "NA"<<endl;
		for (int i = 0; i < a; i++) {
			cout << m[i] << endl;
		}
	}
		return 0;
}

C++: #include<iostream>
#include<cstring>
#include<map>
using namespace std;
int main(){
  long long money,many,ans[4000]={0};
  int n,number,over_many=0,over[4000]={0};
  while(1){
    cin >> n;
    if(n==0)break;
    over_many=0;
    memset(over,0,sizeof(over));
    memset(ans,0,sizeof(ans));
    for(int i=0;i<n;i++){
      cin >> number >> money >> many;
      ans[number]+=money*many;

      if(ans[number]>=1000000){
	if(over[number]==0){
	  over_many++;
	  over[number]=1;
	}
      }

    }
    if(over_many==0){
      cout << "NA" << endl;
    }
    else{
      for(int k=0,j=0;j<over_many;k++){
	if(over[k]==1){
	  cout << k << endl;
	  j++;
	}
      }
    }

  }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
int main() {
	int n;
	std::cin >> n;
	std::vector<int> A;
	while (n != 0) {
		std::vector<int> m(n);
		std::vector<std::vector<int>> V(n, std::vector<int>(3));
		for (int i = 0;i < n;++i) {
			for (int j = 0;j < 3;++j) {
				std::cin >> V[i][j];
			}
		}
		for (int i = 0;i < n;++i) {
			m[i] = V[i][1] * V[i][2];
		}
		sort(V.begin(), V.end());
		for (int i = 0;i < n;i++) {
			for (int j = 0;j < n;++j) {
				if (i < j) {
					if (V[i][0] == V[j][0]) {
						m[i] += m[j];
						m[j] = 0;
					}
				}
			}
		}
		for (int i = 0;i < n;++i) {
			if (m[i] >= 1000000) {
				A.push_back(V[i][0]);
			}
		}
		n = 0;
		std::cin >> n;
	}
	return 0;
}

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

int main(void)
{
	int n, num;
	string str;
	long a;
	
	while (cin >> n, n){
		map <string, long long> m;
		vector <string> data;
		for (int i = 0; i < n; i++){
			cin >> str >> num >> a;
			if (!m[str]) data.push_back(str);
			m[str] += (num * a);
		}
		bool flag = true;
		for (int i = 0; i < data.size(); i++){
			if (1000000 <= m[data[i]]){
				cout << data[i] << endl;
				flag = false;
			}
		}
		if (flag) cout << "NA" << endl;
	}
	
	return 0;
}

C++: #include<stdio.h>

int main(void){
	unsigned long long int x[5000];
	int n,a,b,i,nan,k;
	while(0==0){
		scanf("%d",&n);
		if(n==0)break;
		k=0;
		for(i=0;i<5000;i++) x[i]=0;
		for(i=0;i<n;i++){
			scanf("%d %d %d",&nan,&a,&b);
			x[nan]+=a*b;
			if(x[nan]>999999){
				printf("%d\n",nan);
				k++;
			}
		}
		if(k==0) printf("NA\n");
		k=0;
	}
	return 0;
}

C++: #include <stdio.h>
#include <queue>
using namespace std;

int main()
{
	int n,no;
	long long many,yen;
	long long total[4001];
	bool update;
	queue<int> que;

	for(int i = 0; i <= 4000; i++){
		total[i] = 0;
	}

	scanf("%d",&n);

	while(n != 0){
		
		update = false;

		for(int i = 0; i < n; i++){
			scanf("%d%lld%lld",&no,&many,&yen);
			total[no] += many*yen;
			que.push(no);
		}

		while(!que.empty()){
			if(total[que.front()] >= 1000000){
				printf("%d\n",que.front());
				update = true;
			}
			total[que.front()] = 0;
			que.pop();
		}
		if(!update){
			printf("NA\n");
		}

		scanf("%d",&n);
	}

	return 0;
}

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

int main(){
    int n;
    while(cin>>n,n){
        map<long,long long>m;
        int i,p,q,s=0;
        while(n--){
            cin>>i>>p>>q;
            m[i]+=p*q;
        }
        for (map<long,long long>::iterator it=m.begin(); it!=m.end(); ++it){
            if(it->second>999999){
                s=1;
                cout<<it->first<<endl;
            }
        }
        if(!s)cout<<"NA"<<endl;
    }
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int target = 1000000;

int main()
{
	int data;
	while (1)
	{
		scanf("%d", &data);
		if (data == 0)break;
		vector<pair<int,int>> company;
		pair<int, int> sells;
		bool hero = false;
		int num, sell, cnt;
		for (int i = 0; i < data; i++)
		{
			scanf("%d %d %d", &num, &sell, &cnt);
			bool search = false;
			for (int j = 0; j < company.size(); j++)
			{
				if (company[j].first == num){
					search = true;
					company[j].second += sell*cnt;
					break;
				}
			}
			if (search == false)
			{
				sells.first = num;
				sells.second = sell*cnt;
				company.push_back(sells);
			}
		}
		for (int i = 0; i < company.size(); i++)
		{
			if (company[i].second >= target)
			{
				hero = true;
				printf("%d\n", company[i].first);
			}
		}
		if (hero == false)
			printf("NA\n");
	}
	return 0;
}