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 <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
long long int st[4444];
int stf[4444];
int main(void)
{
  while(1){
    int n;
    bool f = true;
    cin >> n;
    if(!n) break;
    memset(st,0,sizeof(st));
    memset(stf,0,sizeof(stf));
    for(int i = 0; i < n; i++){
      long long int a,b,c;
      cin >> a >> b >> c;
      st[a] += b * c;
      if(1000000 <= st[a] && !stf[a]){
	cout << a << endl;
	stf[a] = 1;
	f = false;
      }
    }
    if(f) puts("NA");
  }
}

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);
		int f = 1;
		//for(int i = 0;i < 4001;i++)a[i] = 0;
		for(int i = 0;i < n;i++){
			cin >> num >> p >> q;
			a[num] += p * q;
			if(a[num]>999999){
                cout << num << endl;
                f = 0;
            }
		}
		if(f)cout << "NA" <<endl;
		/*int f = 1;
		for(int i = 1;i <= 4000;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 <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


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

        ll a[4001]  = {};

        int retu[4000];
        int count = 0;
        int flag[4001] = {};

        rep(i,n){
            int e;
            ll p,q;
            cin >> e >> p >> q;
            a[e] += p*q;
            //cout << a[e];
            if(flag[e]==0){
                retu[count] = e;
                count++;
                flag[e] = 1;
            }
        }
        int f = 0;
        rep(i,count){
            //cout << a[retu[i]];
            if(a[retu[i]]>=1000000){
                cout << retu[i] << endl;
                f = 1;
            }
        }
        if(f==0){
            cout << "NA" << endl;
        }

    }
    return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
using namespace std;
int main(){
int n;
while(cin>>n,n){
long long int tmp[4001]={0};
vector<int>no;
rep(i,n){
int a,b,c;
cin>>a>>b>>c;
pb(no,a);
tmp[a]+=b*c;
}
int co=0;
rep(i,n){
if(tmp[no[i]]>=1000000){
int han=0;
rep(j,i){
if(no[i]==no[j]){
han=1;
break;
}
}
if(han)continue;
co++;
cout<<no[i]<<endl;
}
}
if(!co)cout<<"NA"<<endl;
}
}

C++: #include <cstdio>
#include <cstring>

using namespace std;

int main(void){
	int n, id, value, num, i;
	long long int yen[4000];
	bool f;
	while(1){
		scanf("%d",&n);
		if(n == 0){
			break;
		}
		memset(yen,0ll,sizeof(yen));
		for(i = 0;i < n;i++){
			scanf("%d%d%d",&id,&value,&num);
			yen[id - 1] += (long long int)value * num;
		}
		f = true;
		for(i = 0;i < 4000;i++){
			if(yen[i] >= 1000000ll){
				printf("%d\n",i + 1);
				f = false;
			}
		}
		if(f){
			printf("NA\n");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        bool na = true;
        for(int i=0; i<n; ++i){
            int a, b, c;
            cin >> a >> b >> c;
            if((long long)b * c >= 1000000){
                cout << a << endl;
                na = false;
            }
        }
        if(na)
            cout << "NA" << endl;
    }
}

C++: #include <iostream>
#include <cstring>

using namespace std;

int main(void){
    int i,l,k;
    int n;
    long long id,cost,qty;
    long long data_list[4001];
    int id_list[4000];
    bool id_flag;
    bool na_flag;
    
    while(cin>>n,n!=0){
        memset(data_list,0,sizeof(data_list));
        k=0;
        for(l=0;l<n;l++){
            data_list[id]+=(cost*qty);
            cin>>id>>cost>>qty;
            id_flag=true;
            for(i=0;i<=k+1;i++){
                if(id_list[i]==id){
                    id_flag=false;
                }
            }
            if(id_flag){
                id_list[k]=id;
                k++;
            }
        }
        na_flag=true;
        for(l=0;l<k;l++){
            if(data_list[id_list[l]]>=1000000){
                cout<<id_list[l]<<endl;
                na_flag=false;
            }
        }
        if(na_flag){
            cout<<"NA"<<endl;
        }
    }
    return(0);
}

C++: #include<iostream>
using namespace std;
int main(){
long long n,a,b,c,f,i,j,s[4001];
while(cin>>n){
if(n==0)break;
for(i=1;i<=4000;i++)s[i]=0;
for(i=0;i<n;i++){
cin>>a>>b>>c;
for(j=0;j<c;j++){
if(s[a]>=1000000)break;
s[a]+=b;
}
}
for(f=0,i=1;i<=4000;i++)
if(s[i]>=1000000){cout<<i<<endl;f=1;}
if(f==0)cout<<"NA"<<endl;
}
return 0;
}

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

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