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 <stdio.h>
 
 

 
int main(void){
	int i,j,k;
	int n,num[4000];
	long long tanka[4000],sale_num[4000];
	int sale_all[4001],judge[4001];
	
	while(scanf("%d",&n),n){
		
		for(i=0;i<n;i++){
			scanf("%d%lld%lld",&num[i],&tanka[i],&sale_num[i]);
		}
		
		//初期化
		k=0;
		for(j=0;j<=4001;j++){
			judge[j]=0;
			sale_all[j]=0;
		}
		
		//idに対応したsaleに+
		for(i=0;i<n;i++){
			sale_all[num[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 <algorithm>
#include <map>
using namespace std;
typedef long long lli;

int main(void){
	int a,b,c;
	int n;
	while(cin>>n,n){
		std::map<int,lli> m;
		while(n--){
			cin>>a>>b>>c;
			m[a]+=b*c;
		}
		for(__typeof(m.begin()) it=m.begin();it!=m.end();it++){
			if(it->second>=1000000)cout<<it->first<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>

#define int64 long long int

using namespace std;
typedef pair<int, int> P;

int main()
{
    int flag[4001];
    int n, c, num, val, sale, na;
    P hoge[4001];
    
    while (1) {
        cin >> n;
        if(n == 0) break;
        
        c = 1;
        na = 1;
        memset(flag, 0, sizeof(int)*4001);
        
        for(int i=0; i<n; i++){
            cin >> num >> val >> sale;
            if(flag[num] == 0){
                flag[num] = c;
                hoge[c].first = num;
                hoge[c].second = val * sale;
                c++;
            } else {
                hoge[flag[num]].second += val * sale;
            }
        }
        for(int i=1; i<c; i++){
            if(hoge[i].second >= 1000000){
                na = 0;
                cout << hoge[i].first << endl;
            }
        }
        if(na == 1) cout << "NA" << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
typedef long long ll;
//vector<pair<bool, ll>> v(4001);
ll a[4001];

int main(){
	int n, num, p, q;
	while(cin >> n, n){
		fill(a, a+4001, 0);
		for(int i = 0;i < n;i++){
			cin >> num >> p >> q;
			a[num] += p * q;
		}
		int f = 1;
		for(int i = 0;i < 4001;i++)if(a[i] >= 1000000)cout << i << endl, f = 0;
		if(f)cout << "NA" << endl;
	}
	return 0;
}

/*
4
1001 2000 520
1002 1800 450
1003 1600 625
1001 200 1220
*/

C++: #include <stdio.h>
#include <vector>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long Int;

int main() {
    for (;;) {
        int n;
        scanf("%d", &n);
        if (n == 0) return 0;
        map<int, Int> of;
        vector<int> ids;
        int c = 0;
        rep (_, n) {
            int id, p, q;
            scanf("%d%d%d", &id, &p, &q);
            ids.push_back(id);
            of[id] += (Int)p*q;
        }
        rep (i, n) if (of[ids[i]] >= 1000000) {
            printf("%d\n", ids[i]);
            of[ids[i]] = 0;
            c++;
        }
        if (c == 0) puts("NA");
    }
    return 0;
}

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

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) break;
    long long int total[4000];
    for (int i = 0; i < 4000; i++) total[i] = 0;
    
    for (int i = 0; i < n; i++) {
      int a;
      long long int b,c;
      cin >> a >> b >> c;
      total[a-1] += b*c;
    }
    
    bool NA = true;
    for (int i = 0; i < 4000; i++) {
      if ( total[i] >= 1000000) {
	cout << i+1 << endl;
	NA = false;
      }
    }
    if (NA) cout << "NA" << endl;
  }
  return 0;
}

C++: #include <queue>
#include <cstdlib>
#include <iomanip>
#include <utility>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

vector<pair<int,int> > v;

int vsearch(int id)
{
    for(int i = 0;i<v.size();i++)
    {
        if(v[i].first==id)
            return i;
    }
    return -1;
}

int main() {
    
    int const price = 1000000;
    int n;
    while(cin >> n && n!=0)
    {
        int e[n],p[n],q[n];
        for(int i = 0; i<n;i++)
        {
            cin >> e[i] >> p[i] >> q[i];
        }
        
        for(int i = 0; i< n; i++)
        {
            int id = vsearch(e[i]);
            if(id < 0)
                v.push_back({e[i],p[i]*q[i]});
            else
                v[id].second += p[i]*q[i];
        }
        bool ch = true;
        for(int i = 0;i<v.size();i++)
        {
            if(v[i].second >= price)
            {
                cout << v[i].first << endl;
                ch = false;
            }
        }
        if(ch) cout << "NA" << endl;
        vector<pair<int,int> >().swap(v);
    }
    
    return 0;
}

C++: #include<stdio.h>
int main()
{
	unsigned long int goukei[4001]={0},kazu,tanka;
	int n,i,j,g=0,kazuz[4001]={0};
	while(scanf("%d",&n))
	{
		if(n==0)
		{
			break;
		}
		for(i=1;i<=n;i++)
		{
			scanf("%d %d %d",&j,&tanka,&kazu);
			kazuz[i]=j;
			goukei[i]=goukei[i]+tanka*kazu;
		}
		for(i=1;i<4001;i++)
		{
			if(goukei[i]>=1000000)
			{
				printf("%d\n",kazuz[i]);
				g++;
			}
			goukei[i]=0;
		}
		if(g==0)
		{
			printf("NA\n");
		}
		g=0;
	}
	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<map>

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define f first
#define s second

using namespace std;

typedef long long ll;

int main(){
  int n;
  while(cin>>n, n){
    map<string,pair<int,ll> > m;
    vector<pair<int,string> > v;
    REP(i,n){
      string a;
      ll b,c;
      cin>>a>>b>>c;
      if(m.find(a) == m.end())
	m[a] = mp(m.size(),b*c);
      else
	m[a].s += b*c;
    }
    FOR(it,m) if(it->s.s >= (ll)1000000) v.push_back(mp(it->s.f,it->f));
    if(v.size() == 0) cout << "NA" << endl;
    else{
      sort(ALL(v));
      FOR(it,v) cout << it->s << endl;
    }
  }
  return 0;
}

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

using namespace std;

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

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id[i] >> value[i] >> number[i];
        total[id[i]] += value[i] * number[i];
    }
    vector<long long> v;
    if(!total.empty()) {
        map<long long, 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;
        return 0;
    }
    for (vector<long long>::iterator it = v.begin(); it != v.end(); ++it) {
        cout << *it << endl;
    }
}