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>

using namespace std;

int n;
long long id[4000];
unsigned long long value[4000];
unsigned long long number[4000];
map<unsigned long long, unsigned long long> total;

int main() {
  while(true){
    cin >> n;
    if(n==0){
        return 0;
    }
    vector<long long> v;
    for (int i = 0; i < n; i++) {
        cin >> id[i] >> value[i] >> number[i];
        if(total.find(id[i])==total.end()){
          total.insert(make_pair(id[i], 0));
        }
        total[id[i]] += value[i] * number[i];
        // if (total[id[i]] > 1000000 && find(v.begin(), v.end(), id[i]) == v.end()) {
        //   v.push_back(id[i]);
        // }
    }
    if(!total.empty()) {
        map<unsigned long long, unsigned long long>::iterator it = total.begin();
        while (it != total.end()) {
            if ((*it).second >= 1000000) {
                v.push_back((*it).first);
            }
            ++it;
        }
    }
    if (v.empty()) {
        cout << "NA" << endl;
    }
    // for (vector<long long>::iterator it = v.begin(); it != v.end(); ++it) {
    //     cout << *it << endl;
    // }
    vector<long long> used;
    for(int i=0; i<n;i++){
      if(find(v.begin(), v.end(), id[i]) != v.end() && find(used.begin(), used.end(), id[i]) == used.end()){
        cout << id[i] << endl;
        used.push_back(id[i]);
      }
    }
    v.clear();
    total.clear();
  }
}

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

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

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

int main(){
	int n,a,b,c,flag,f[4005];
	map<int, long long int> m;
	while (cin >> n, n){
		for (int i = 0; i < 4005; i++) f[i] = 0;
		m.clear();
		flag = 0;
		for (int i = 0; i < n; i++){
			cin >> a >> b >> c;
			if (!f[a]){
				if ((long long int)b * (long long int)c >= 1000000ll) f[a] = 1;
				m[a] += (long long int)b * (long long int)c;
				if (m[a] >= 1000000ll) f[a] = 1;
			}
		}
		for (int i = 0; i < 4005; i++){
			if (f[i]) {
				cout << i << endl;
				flag = 1;
			}
		}
		if (!flag) cout << "NA" << endl;
	}
	return 0;
}

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

struct tEmploy{
	int num;
	int sold;
	tEmploy(){
		num = -1;
		sold = 0;
	}
};

int main(){
	while(1){
		tEmploy *emp;
		int n;
		cin >> n;
		if( n == 0 ){
			break;
		}

		emp = new tEmploy[n];
		for( int i=0; i<n; i++ ){
			int num, val, amo;
			cin >> num >> val >> amo;
			int j=0;
			for( ; j<n; j++ ){
				if( emp[j].num == num )	break;
			}
			if( j == n ){
				for( j=0; j<n; j++ ){
					if( emp[j].num == -1 ){
						emp[j].num = num;
						break;
					}
				}
			}
			emp[j].sold += val * amo;
		}

		bool exist = false;
		for( int i=0; (emp[i].num!=-1)&&(i<n); i++ ){
			if( emp[i].sold >= 1000000 ){
				cout << emp[i].num << endl;
				exist = true;
			}
		}
		if( !exist ){
			cout << "NA" << endl;
		}

		delete[] emp;
		emp = 0;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int ans[100000];
int main(void)
{
    int n; cin >> n;
    int count = 0;
    do {
        int e[n], p[n], q[n];
        ll tmp[4010] = {};
        int flag = 0;
        rep(i, n) cin >> e[i] >> p[i] >> q[i];
        for (int i = 0; i < n; i++) {
            tmp[e[i]] += p[i] * q[i];
        }
        for (int i = 0; i < 4010; i++) {
            if (tmp[i] >= 1000000) {
                ans[count++] = i;
                flag = 1;
            }
        }
        if (flag == 0) ans[count++] = -1;
        cin >> n;
    } while(n != 0);
    for (int i = 0; i < count; i++) {
        if( ans[i] != -1) {
            cout << ans[i] << endl; 
        } else {
            cout << "NA" << endl;
        }
    }

    return 0;
}

C++: #include <stdio.h>


int n;
int num[4000];
int tanka[4000],sale_num[4000];
int sale_all[4001],judge[4000];

int main(void)
{
int i,j,k;
	
while((scanf("%d",&n),n!=0)){
	for(i=0;i<n;i++){
		scanf("%d %d %d",&num[i],&tanka[i],&sale_num[i]);
		sale_all[num[i]]=0;
	}
	k=0;
	for(j=0;j<4001;j++)	judge[j]=0;
	for(i=0;i<n;i++){
		sale_all[num[i]] += tanka[i]*sale_num[i];
	}
	for(i =0; i < n; i++){
		if((sale_all[num[i]] >= 1000000)&&(judge[num[i]]==0)){
			printf("%d\n",num[i]);
			judge[num[i]]=1;
			k=1;
		}
	}
	if(k!=1)printf("NA\n");


}

	return 0;
}

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", &n);		// データ個数
	if(n == 0) goto end_scope;
	sl = (struct Saler*)malloc(sizeof(struct Saler) * n);
	memcpy(sl, 0, sizeof(struct Saler)*n);
	for(int j = 0; j < n; j++)
	{
		scanf("%d %d %d\n", &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[i].Saled >= 1000000)
		{
			cout << sl[i].Number << endl;
			isFound = true;
		}
	}
	!isFound && (cout << "NA" << endl);
end_scope:
    return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


int n;
int id[5000];

int main(){
	while(cin>>n,n!=0){
		vector<int> a;
		rep(i,n){
			int t1,t2,t3;
			a.push_back(t1);
			cin>>t1>>t2>>t3;
			id[t1]+=t2*t3;
		}
		bool f=true;
		rep(i,a.size()){
			if(id[a[i]]>=1000000){
				cout<<a[i]<<endl;
				id[a[i]]=0;
				f=false;
			}
		}
		if(f) cout<<"NA"<<endl;
	}
}