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 <map>

using namespace std;

#define ll long long

int main(void){
  map<int,ll> m;
  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;
	  m[no] += (ll)amount*price;
	}
	map<int,ll>::iterator it = m.begin();
	while(it!=m.end()){
	  if((*it).second >= 1e+6){
		cout << (*it).first << endl;
		exist = true;
	  }
	  ++it;
	}
	if(!exist) cout << "NA" << endl;
	m.clear();
  }
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  vector<string> result;

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

    map<string, long long> m;
    bool hoge = true;
    for (int i = 0; i < n; i++) {
      string id;
      long long a, b;
      cin >> id >> a >> b;
      if (m[id] < 1000000 && m[id] + a * b >= 1000000) {
        result.push_back(id);
        hoge = false;
      }
      m[id] += a * b;
    }
    if (hoge)
      result.push_back("NA");
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << endl;
  return 0;
}

C++: 
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;

#define MAX 5000

int main(){
    for (;;) {
        int n;
        cin >> n;
        if(n==0) break;
        vector<ll> num(4001,0),pre(n,0),data(4001,0);
        for (int i=0; i<n; i++) {
            int a,b,c;
            cin >>a >>b >>c;
            if(data[a]<1000000) data[a]+=b*c;
            if(num[a]==0) num[a]=i+1;
        }
        for (int k=0; k< 4001; k++) {
            if(num[k]!=0) pre[num[k]]=k;
        }
        ll ch=0;
        for (int j=0; j<n; j++) {
            if (data[pre[j]]>=1000000) {
                cout <<pre[j]<<endl;
                ch++;
            }
        }
        if(ch==0) cout << "NA"<<endl;
    }
}

C++: #include<iostream>
#include<stdio.h>
#include<string>
#include<deque>
using namespace std;
int x;
long long n,a,b,c,tmp,flg,t[4001],u[4001],v[4001];
deque<int>deq;
int main(){
	while(1){
		cin>>n;
		if(n==0)break;
		for(int i=0;i<4001;i++){v[i]=t[i]=0;u[i]=9999;}
		flg=x=0;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			t[a]+=(b*c);
			
			if(v[a]==0){
				u[x]=a;
				v[a]=1;
				x++;
			}
		}

		for(int i=0;i<n;i++){
			if(u[i]==9999){
				break;
			}
			if(t[u[i]]>=1000000){
				flg=1;
				cout<<u[i]<<endl;
			}
		}
		if(flg==0)cout<<"NA"<<endl;
		


	}

	return 0;
}

C++: /*
   fuckin fuck fuck
 */

#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef long long int LLI;

int n;
LLI total[1000000];
bool used[1000000];
vector<int> ans;
map<int, int> order;

bool cmp(int a, int b) {
  return order[a] < order[b];
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

    fill(total, total+4010, 0);
    fill(used, used+4010, false);
    ans.clear();
    order.clear();

    for (int i=0; i<n; i++) {
      int id;
      LLI p, q;

      scanf("%d%lld%lld", &id, &p, &q);
      if (!order.count(id)) order[id] = i;

      total[id] += p*q;
      if (total[id] >= 1000000 && !used[id]) {
        ans.push_back(id);
        used[id] = true;
      }
    }

    sort(ans.begin(), ans.end(), cmp);
    for (int i=0; i<ans.size(); i++) {
      printf("%d\n", ans[i]);
    }

    if (ans.empty()) puts("NA");
  }
}

C++: #include <iostream>
using namespace std;
int main()
{
	int n, no, t, num, a[4000], i, j;
	while (cin >> n && n)
	{
		for (i = 0, j = 0; i < n; i++)
		{
			cin >> no >> t >> num;
			if (t * num >= 1000000)
			{
				a[j] = no, j++;
			}
		}
		if (j == 0)
			cout << "NA" << endl;
		else
			for (i = 0; i < j; i++)
				cout << a[i] << endl;
	}
	return 0;
}

C++: #include <stdio.h>
 
 

 
int main(void){
	int i,j,k;
	int n,num[4000];
	long long tanka[4000],sale_num[4000],sale_all[4001];
	int 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<stdio.h>
#include<list>
class hoge{
 public:
  int num;
  long long int v;
  hoge(int n,int va){
    num=n;
    v=va;
  }
};


int main(){
  using namespace std;
  int i,n,v,c,num,flg;
  long long int a;
  list<hoge> ls;
  list<hoge>::iterator pos;
  do{
    scanf("%d",&n);
    if(!n) break;
    for(i=0;i<n;i++){
      scanf("%d %d %d",&num,&v,&c);
      pos=ls.begin();
      while(pos!=ls.end()){
	if((*pos).num==num){
	  (*pos).v+=v*c;
	  break;
	}
	pos++;
      }
      if(pos==ls.end()){
	pos=ls.begin();
	while(pos!=ls.end()){
	  if((*pos).num>num){
	    a=v;
	    a*=c;
	    ls.insert(pos,*(new hoge(num,a)));
	    break;
	  }
	  pos++;
	}
	if(pos==ls.end()){
	  a=v;
	  a*=c;
	  ls.push_back(*(new hoge(num,a)));
	}
      }
    }
    pos=ls.begin();
    flg=1;
    while(pos!=ls.end()){
      if((*pos).v>=1000000){
	printf("%d\n",(*pos).num);
	flg=0;
      }
      pos++;
    }
    if(flg) printf("NA\n");
    ls.clear();
  }while(1);
  return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n, id, p, q;
    while (cin >> n && n) {
        map<int, int> ids;
        vector<pair<int, long long>> sum;
        for (int i=0; i<n; ++i) {
            cin >> id >> p >> q;
            if (ids.count(id)) {
                sum[ids[id]].second += p * q;
            } else {
                sum.push_back(make_pair(id, p * q));
                ids[id] = sum.size() - 1;
            }
        }
        bool na = true;
        for (auto x : sum) {
            if (1000000 <= x.second) {
                cout << x.first << endl;
                na = false;
            }
        }
        if (na) {
            cout << "NA" << endl;
        }
    }

    return 0;
}