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 <stdio.h>
 
int n,num[4000];
long long int tanka[4000],sale_num[4000],sale_all[4001];
bool judge[4001];
 
int main(void)
{
int i,j,k;
     
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[i]=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 <algorithm>
#include <vector>
using namespace std;

struct data{
    int id;
    long long int sales;
    data(int a, int b) : id(a), sales(b) {}
    bool operator<( const data& o ) const{
        return id < o.id;
    }
};

int main(){
    int n;
    while( cin >> n, n ){
        vector< data > ls;
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> a >> b >> c;
            vector<data>::iterator it = ls.begin();
            for(; it!=ls.end(); it++){
                if( it->id == a ){
                    it->sales += b*c;
                    break;
                }
            }
            if( it == ls.end() ){
                ls.push_back( data(a, b*c) );
            }
        }
        sort(ls.begin(), ls.end());
        bool exs = false;
        for(vector<data>::iterator it = ls.begin(); it != ls.end(); it++){
            if( it->sales >= 1000000 ){
                cout << it->id << endl;
                exs = true;
            }
        }
        if( !exs ){
            cout << "NA" << endl;
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

#define MP make_pair<int,int>

ll score[4001];

int main(){
  while(true){
    int n;
    cin>>n;
    if(!n)break;
    REP(i,4001)score[i]=0;
    REP(i,n){
      int id;
      ll val,num;
      cin>>id>>val>>num;
      score[id] += val*num;
    }
    bool flag = true;
    REP(i,4001){
      if(score[i]>=1000000ll){
        flag = false;
        cout<<i<<endl;
      }
    }
    if(flag)cout<<"NA"<<endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
	int n;
	int a,b,c,d;
	int num[4001],tan[4001],data[4001];
	bool flag=false;
	while(1){
		for(a=0;a<=4000;a++){
			data[a]=0;
			num[a]=0;
			tan[a]=0;
		}
		flag=false;
		cin >> n;
		if(n==0)break;
		for(a=1;a<=n;a++){
			cin >> b >> c >> d;
			data[a]=b,num[a]=c,tan[a]=d;
		}
		for(a=1;a<=n;a++){
			if(num[a]*tan[a]>=1000000)printf("%d\n",data[a]),flag=true;
		}
		if(flag==false)printf("NA\n");
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <string>
#include <map>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

int n, bg, tn, su;
	
	while(cin >> n){
		if(n==0 || cin.eof()) break;
		map<int,int> sk;
		rep(i,n){
			cin >> bg >> tn >> su;
			sk[bg] += tn * su;
		}
		int cnt=0;
		map<int, int>::iterator it = sk.begin();
		while(it != sk.end()){
			if((*it).second >= 1000000){
				cout << (*it).first << endl;
				cnt++;
			}
			it++; 
		}
		if(cnt==0) cout << "NA" << endl;
	}
	return 0;
	
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (int j = 0; j < 50; j++)
	{cout << endl;
		long n,e[4000],x[4000],y[4000],co[100];

		cin >> n;
		if (n == 0)
		{
			break;
		}

		for (int i = 0; i < n; i++)
		{
			cin >> e[i] >> x[i] >> y[i];
		}

		for (int i = 0; i < n; i++)
		{
			co[i] = 0;
			for (int k = 0; k < n; k++)
			{
				if (i <= k && e[i] == e[k])
				{
					co[i] += x[k] * y[k];
					if (i != k)
					{
						e[k] = -1;
					}
				}
			}
		}
	int gg = 0;
		for (int i = 0; i < n; i++)
		{
			if (e[i] != -1 && co[i] >= 1000000)
			{	gg += -1;
				cout << e[i] << endl;
			}
			if (i == n - 1 && gg == 0)
			{
				cout << "NA" << endl;
			}
		}
	}
}

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

class CMem {
public :
	CMem() { m_check = false; m_sale = 0; m_rank = 0; }
	void Idata(long long sale) { m_sale += sale; m_check = true; }
	void Irank(int rank) { m_rank = rank; }
	int Orank() { return m_rank;}
	bool Ocheck() { return m_check; }
	long long Osale() { return m_sale; }
private :
	bool m_check;
	long long m_sale;
	int m_rank;
};

int main(void)
{
	while(1) {
		CMem member[4001];
		bool NA = true;
		int n, id, asale, scale, rank = 1, mrank;
		long long sale;

		cin >> n;
		if(n == 0) break;

		for(int i = 0; i < n; i++) {
			cin >> id >> asale >> scale;
			sale = asale * scale;

			if(member[id].Ocheck() == false) { member[id].Irank(rank++); }
			member[id].Idata(sale);
		}

		mrank = rank - 1;

		for(rank = 1; rank <= mrank; rank++) {
			for(int i = 1; i <= 4000; i++) {
				if(member[i].Orank() == rank && member[i].Osale() >= 1000000) {
					cout << i << endl;
					NA = false;
				}
			}
		}

		if(NA == true) cout << "NA" << endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main()
{
	int i,ryou,bangou[4000],nedan[4000],kazu[4000],check;
	while(1)
	{
		check=0;
		scanf("%d",&ryou);
		if(ryou==0)
			break;
		for(i=0;i<ryou;i++)
		{
			scanf("%d%d%d",&bangou[i],&nedan[i],&kazu[i]);
			{
				if(nedan[i]*kazu[i]>=1000000)
				{
					printf("%d",bangou[i]);
					check=1;
				}
			}
		}
		if(check==0)
				printf("NA");
	}
}

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

int main(){
	
	long long int n , id , price , num, cnt;
	while(cin >> n , n!=0){
		vector<long long int> p(4001,0);
		vector<int> a;
		while(n--){
			cin>>id>>price>>num;
			if(find(a.begin(),a.end(),id)==a.end()) a.push_back(id);
			p[id]+=price*num;
			}
		cnt=0;	
		for(int i=0;i<a.size();i++){
			if(p[a[i]]>=1000000){
				cout << a[i] << endl; 
				cnt++;
			} 
		}
		if (cnt==0) cout << "NA" << endl;
	}
	return 0;
}

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

int main(){
	int n,num[4001];
	while(std::cin>>n){
		int count=0;
		memset(num,0,sizeof(num));
		if(n==0)break;
		for(int a,b,c,i=0;i<n;i++){
			std::cin>>a>>b>>c;
			num[a]+=b*c;
		}
		for(int i=0;i<4001;i++){
			if(num[i]>=1000000)count++,std::cout<<i<<std::endl;
		}
		if(count==0)std::cout<<"NA"<<std::endl;
	}
	return 0;
}