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

using namespace std;

typedef long long ll;

int n, id, p, q;
ll amount;

const ll MAX = 1000000;

struct Mem {
    int id;
    ll c;

    Mem() {}
    Mem(int _id, ll _c) { id = _id; _c = c; }
};

Mem array[4010];
vector<int> ans;

int main(void) {
    while(~scanf("%d", &n)) {
        if(n == 0) break; ans.clear();
        for(int i = 0; i < n; i++) {
            array[i].c = array[i].id = 0;
            scanf("%d%d%d", &id, &p, &q);
            array[i].c += p * q;
            array[i].id = id;
        }
        for(int i = 0; i < n; i++) {
            ll cost = 0;
            for(int j = 0; j < n; j++) {
                if(array[i].id == array[j].id) {
                    cost += array[j].c;
                }
            }
            if(cost >= MAX && !count(ans.begin(), ans.end(), array[i].id)) {
                ans.push_back(array[i].id);
            }
        }
        if(ans.empty()) {
            printf("NA\n");
        } else {
            for(int i = 0; i < (int) ans.size(); i++) {
                printf("%d\n", ans[i]);
            }
        }
    }
    return 0;
}

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

struct staff {
	unsigned long long int num;
	unsigned long long int price;
	unsigned long long int quan;
	unsigned long long int total;
};

int main()
{
	int num, i, k, j, datas;
	int sn, sp, sq;
	map<int, staff> staffs[4000];
	map<int, staff>::iterator staffs_it;

	datas = 0;
	while(1)
	{
		cin >> num; if(num == 0) break;

		for(i = 0; i < num; i++)
		{
			cin >> sn >> sp >> sq;
			staffs[datas][sn].num = sn;
			staffs[datas][sn].price = sp;
			staffs[datas][sn].quan = sq;
			staffs[datas][sn].total += staffs[datas][sn].price * staffs[datas][sn].quan;
		}
		datas++;
	}

	for(i = 0; i < datas; i++)
	{
		staffs_it = staffs[i].begin();
		int over = 0;

		while(staffs_it != staffs[i].end())
		{
			if(staffs[i][(*staffs_it).first].total >= 1000000)
			{
				cout << staffs[i][(*staffs_it).first].num << endl;
				over++;
			}
			staffs_it++;
		}
		if(over == 0) cout << "NA" << endl;
	}
}

C++: #include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
pair<int, long long int> s[4001];

int main() {

    int n, id, p, q, idx;
    for (;;) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i < n; i++) { s[i] = {0, 0}; }
        map<int, int> m;
        idx = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d %d %d", &id, &p, &q);
            if (m.find(id) == m.end()) {
                m.insert({id, idx});
                s[idx++] = {id, p*q};
            }
            else {
                s[m[id]].second += p*q;
            }
        }
        bool flag = false;
        for (int i = 0; i < m.size(); i++) {
            if (s[i].second >= 1000000) { flag = true; printf("%d\n", s[i].first); }
        }
        if (!flag) printf("NA\n");
    }

    return 0;
}

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

const int BORDER = 1000000;

class myMap
{
public:
	myMap() :mSize( 0 ){}

	void insert( int id, int p, int q ){
		bool find = false;
		long long gross = ( long long )p * q;
		for( int i = 0; i < mSize; ++i ){
			if( mIDList[ i ].first == id ){
				if( mIDList[ i ].second < 1000000 ){
					mIDList[ i ].second += gross;
				}
				find = true;
				break;
			}
		}
		if( !find ){
			mIDList.push_back( pair< int, long long >( id, gross ) );
			++mSize;
		}
	}
	void output(){
		bool finded = false;
		for( int i = 0; i < mSize; ++i ){
			if( mIDList[ i ].second >= BORDER ){
				finded = true;
				cout << mIDList[ i ].first << endl;
			}
		}
		if( !finded ){
			cout << "NA" << endl;
		}
	}

	vector< pair< int, long long > > mIDList;
	int mSize;
};

int main()
{
	int n;

	while( cin >> n && n ){
		myMap db;
		int id, unit, amount;
		for( int i = 0; i < n; ++i ){
			cin >> id >> unit >> amount;
			db.insert( id, unit, amount );
		}
		db.output();
	}

	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <bitset>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(false);

    int n;
    while (cin >> n && n) {
        map<int,int> sum;
        for (int i=0; i<n; ++i) {
            int no, price, quantity;
            cin >> no >> price >> quantity;
            sum[no] += price * quantity;
        }

        bool NA = true;
        for (map<int,int>::iterator it = sum.begin(); it != sum.end(); it++) {
            if (it->second >= 1000000) {
                cout << it->first << endl;
                NA = false;
            }
        }
        if (NA)
            cout << "NA" << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(void) {
  int n, flag=0;
  unsigned long long man[4000], num, sale, good[4000];
  
  while(1) {
    flag = 0;
    for(int i = 0 ; i < 4000 ; i++) {
      man[i] = 0;
      good[i] = 0;
    }
    cin >> n;
    if(n == 0) break;
    for(int i = 0 ; i < n ; i++) {
      cin >> man[i] >> num >> sale;
      if(num * sale >= 1000000) { good[i] = man[i]; flag = 1; }
    }
    if(flag == 1) {
      for(int i = 0 ; i < n ; i++) {
	if(good[i] > 0) cout << good[i] << endl;
      }
    }
    else cout << "NA" << endl;
  }
  return 0;
}

C++: /*
	0100:Sale Result
*/
#include	<iostream>
#include	<map>

using namespace std;

int main(void) {
	int n;
	while(1) {
		bool isOK = false;
		map<int, int> MP;
		
		cin >> n;
		
		if(n == 0) { break; }
		
		for(int i = 0; i < n; i++) {
			int n, p, c;
			cin >> n >> p >> c;
			MP[n] += p * c;
		}
		for(map<int, int>::iterator it = MP.begin(); it != MP.end(); it++) {
			if(it->second >= 1000000) {
				cout << it->first << endl;
				isOK = true;
			}
		}
		if(isOK == false) {
			cout << "NA" << endl;
		}
	}
	return 0;
}

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

typedef long long ll;
typedef queue<int> qi;

const int lim = 1000000;

int n; ll en, price, qty, check[4001]; qi que;

int main()
{
    while(cin >> n && n) {
       if (n == 0) break;
       
       for(int i=0; i < n; ++i) {
           cin >> en >> price >> qty;
           if (check[en] >= 0) check[en] += price*qty;
           if (check[en] >= lim) {
               que.push(en);
               check[en]=-1;
           }
       }
        
       if (que.empty()) cout << "NA" << endl;
       else {
           for(int i=0,len=que.size(); i < len; ++i) {
               cout << que.front() << endl;
               que.pop();
           }
       }
    }

    return 0;
}