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<algorithm>
#include<map>

typedef long long ll;

int main()
{
	int n;
	std::map<int, ll> m;

	while( std::cin >> n, n )
	{
		m.clear();

		for( ll a, b, c, i = 0; i < n; ++i )
		{
			std::cin >> a >> b >> c;
			m[a] += b * c;
		}

		bool f = false;
		for( auto it = m.begin(); it != m.end(); ++it )
			if( it->second >= 1000000 )
				std::cout << it->first << std::endl, f = true;

		if( !f )
			std::cout << "NA" << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){
	
	int n;
	
	while(cin>>n,n!=0){
		int a,b,c;
		int f=0;
		long long unsigned s[4001]={0};
		
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			if(s[a]<=1000000)
			s[a]+=b*c;
		}
		for(int i=1;i<4001;i++){
			if(s[i]>=1000000){
				cout<<i<<endl;
				f=1;
			}
			
		}
		if(f!=1)
			cout<<"NA"<<endl;
	
	}
	
}

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

#define ll long long

int main(void){
  map<int,ll> m;
  vector<int> order;
  int n;
  int no,amount,price;

  while(cin >> n){
	bool exist = false;
	if(!n) break;
	for(int i=0;i<n;i++){
	  cin >> no >> amount >> price;
	  if(find(order.begin(), order.end(), no) == order.end()){
		order.push_back(no);
	  }
	  m[no] += (ll)amount*price;
	}
	for(int i=0;i<order.size();i++){
	  if(m[order[i]] >= 1e+6){
		cout << order[i] << endl;
		exist = true;
	  }
	}
	if(!exist) cout << "NA" << endl;
	m.clear();
  }
}

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

int main() {
	long long e, p, q;
	int n;
	while (cin >> n, n) {
		long long number[4001] = {};
		for (int i = 0; i < n; i++) {
			cin >> e >> p >> q;
			number[e - 1] += p*q;
		}

		int x = 0;
		for (int i = 0; i < 4001; i++) {
			if (number[i] >= 1000000) {
				cout << i + 1 << endl;
				x++;
			}
		}
		if (x == 0) { cout << "NA" << endl; }
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)

int main(void){
    int n, i, p, q;
    while(cin >> n && n) {
        bool isExist = false;
        map<int, long long int> emp;
        vector<int> seq;
        rep(l, n) {
            cin >> i >> p >> q;
            if(!emp[i]) seq.push_back(i);
            if(emp[i] != -1) {
                emp[i]+=p*q;
            }
        }
        rep(i, seq.size()) {
            if(emp[seq[i]] >= 1000000) {
                cout << seq[i] << endl;
                isExist = true;
            }
        }
        if(!isExist) cout << "NA" << endl;
    }
}

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

int main() {
	vector<int> emp_nums;
	vector<int> grades;
	
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;
		int e, p, q;
		for (int i = 0; i < n; i++) {
			cin >> e >> p >> q;
			bool be_already = false;
			int same_emp_index;
			for (int j = 0; j < emp_nums.size(); j++) {
				if (emp_nums[j] == e) {
					be_already = true; same_emp_index = j; break;
				}
			}
			if (be_already) {
				grades[same_emp_index] += p*q;
			}
			else {
				emp_nums.push_back(e);
				grades.push_back(p*q);
			}
		}
	}
	for (int i = 0; i < emp_nums.size(); i++) {
		if (grades[i] >= 1000000)cout << emp_nums[i] << endl;
		else cout << "NA" << endl;
	}
}

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

int main()
{
	while (true){
		int n;
		cin >> n;
		if (!n){ break; }

		int sold[4001];
		bool already[4001];
		queue<int> input;
		for (int i = 1; i <= 4000; i++){
			sold[i] = 0;
			already[i] = false;
		}
		for (int i = 0; i < n; i++){
			int number, yen, times;
			cin >> number >> yen >> times;
			if (already[number] == false){
				already[number] = true;
				input.push(number);
			}
			sold[number] += yen * times;
		}
		bool f = false;
		while (!input.empty()){
			if (sold[input.front()] >= 1000000){
				cout << input.front() << endl;
				f = true;
			}
			input.pop();
		}
		if (f == false){
			cout << "NA" << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
int main() {
	int n;
	int x = 0;
	std::vector<int> A;
	while (std::cin >> n, n != 0) {
		int z = 0;
		++x;
		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];
		}
		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]);
				z = 1;
			}
		}
		if (z == 0) {
			A.push_back(0);
		}
	}
	for (int i = 0;A.size()>i;++i) {
		if (A[i] == 0) 
			std::cout << "NA" << std::endl;
		else 
			std::cout << A[i] << std::endl;
	}
	return 0;
}

C++: // 2011/01/12 Tazoe

#include <iostream>
using namespace std;

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

		int emp[4000][3];
		for(int i=0; i<4000; i++){
			emp[i][0] = i+1;
			emp[i][1] = 0;
			emp[i][2] = 5000;
		}

		int ord = 1;
		for(int i=0; i<n; i++){
			int id, p, q;
			cin >> id >> p >> q;
			if(p!=0&&1000000/p+1<=q)
				emp[id-1][1] = 1000000;
			else if(emp[id-1][1]<1000000)
				emp[id-1][1] += p*q;
			if(emp[id-1][2]==5000){
				emp[id-1][2] = ord;
				ord++;
			}
		}

		for(int i=0; i<3999; i++)
			for(int j=i+1; j<4000; j++)
				if(emp[i][2]>emp[j][2]){
					int tmp1 = emp[i][0];
					int tmp2 = emp[i][1];
					int tmp3 = emp[i][2];
					emp[i][0] = emp[j][0];
					emp[i][1] = emp[j][1];
					emp[i][2] = emp[j][2];
					emp[j][0] = tmp1;
					emp[j][1] = tmp2;
					emp[j][2] = tmp3;
				}

		int cnt =0;
		for(int i=0; emp[i][2]!=5000&&i<4000; i++)
			if(emp[i][1]>=1000000){
				cout << emp[i][0] << endl;
				cnt++;
		}
		if(cnt==0)
			cout << "NA" << endl;
	}

	return 0;
}

C++: num=int(input())
emp=[]
cnt=0
for i in range(num):
    emp.append(num)
    emp[i]=[int(k) for k in input().split()]
for i in range(num):
    for q in range(i+1,num):
        if emp[i][0]==emp[q][0]:
            emp[i][1]=emp[i][1]+emp[q][1]
            emp[i][2]=emp[i][2]+emp[q][2]
            emp[q][1],emp[q][2]=0,0
    if emp[i][1]*emp[i][2]>=1000000:
        print(emp[i][0])
        cnt+=1
if cnt==0:
    print('NA')

C++: #include<iostream>
#include<map>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    int a;
    long long b,c;
    map<int, long long> sale;
    sale.clear();
    bool f = true;
    while(n--){
      cin >>a>>b>>c;
      sale[a]+=b*c;
    }
    for(map<int, long long>::iterator pos = sale.begin(); pos!=sale.end(); pos++){
      if(pos->second >= 1000000){cout <<pos->first<<endl;f = false;}
    }
    if(f){cout <<"NA"<<endl;}
  }
  return 0;
}