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<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;
}

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

typedef long long Int;

int main(){
    map<int,Int> table;
    vector<int> ids;
    int n;
    bool flug;

    while(cin >> n, n != 0){
        flug = false;
        table.clear();
        ids.clear();

        for(int i=1; i<=n; i++){
            int id;
            Int tanka;
            Int number;
            cin >> id >> tanka >> number;
            table[id] += (tanka*number);
            vector<int>::iterator fIter = find(ids.begin(), ids.end(), id);
            if(fIter == ids.end()){
                ids.push_back(id);
            }
        }

        for(vector<int>::iterator Iter = ids.begin(); Iter != ids.end(); Iter++){
            if(table[*Iter] >= 1000000){
                cout << *Iter << endl;
                flug = true;
            }
        }

        if(flug == false){
            cout << "NA" << endl;
        }
    }

    return 0;
}

C++: #include<stdio.h>
int main(void)
{
	long long int n,m,flg,i,j,a[1001],b[1001],c[1001];
	long long int e[1001],p[1001],q[1001];
	while(1){
		scanf("%lld",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			a[i]=0; b[i]=0; c[i]=0;
		}	
		for(i=0;i<n;i++){
			scanf("%lld %lld %lld",&e[i],&p[i],&q[i]);
			if(p[i]*q[i]>=1000000) a[i]=1;
			if(a[i]==0) b[i]=p[i]*q[i];
		}	
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(e[i]==e[j]){
					if(a[i]==0){
						b[i]+=b[j];
						b[j]=0;
					}
					if(b[i]>=1000000&&a[i]==0) a[i]=1;
				}
			}
		}
		flg=0;
		for(i=0;i<n;i++){
			if(a[i]!=0){
				printf("%lld\n",e[i]);
				flg=1;
			}
		}	
		if(flg==0) printf("NA\n");
	}
	return 0;
}

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

#define MAX_N 4001

int main(){
  int n;
  unsigned long long ID, price, figure, man[MAX_N], id[MAX_N];

  while(cin >> n, n){
    memset(man, 0, sizeof(man));
    memset(id, 0, sizeof(id));

    for(int i = 1 ; i <= n ; i++){
      cin >> ID >> price >> figure;
      man[ID] += price * figure;
      id[i] = ID;
    }

    bool flag[MAX_N], f = false;
    memset(flag, false, sizeof(flag));
    
    for(int i = 1 ; i <= n ; i++){
      if(man[id[i]] >= 1000000 && flag[id[i]] == false){
	cout << id[i] << endl;
	flag[id[i]] = true;
	f = true;
      }
    }
    if(f == false) cout << "NA" << endl;
  }
  return 0;
}