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<bits/stdc++.h>
using namespace std;
int main(){
  int n,num,flag=0,flag2=0;
  long long tanka,sell;
  while(cin>>n,n!=0){
    flag=0;flag2=0;
    vector<int> nu;
    vector<int> vi;
    vector<pair<int,long long> > pii;
    for(int i=0;i<n;i++){
      cin>>num>>tanka>>sell;
      for(int j=0;j<vi.size();j++){
	if(num==vi[j]){
	  flag2=1;
	  break;
	}
      }
      if(flag2==0){
	flag=0;
	for(int j=0;j<pii.size();j++){
	  if(pii[j].first==num){
	    flag=1;
	    pii.push_back(make_pair(num,((tanka*sell)+pii[j].second)));
	    if(((tanka*sell)+pii[i].second)>=1000000)
	      vi.push_back(num);
	    break;
	  }
	}
	if(flag==0){
	  nu.push_back(num);
	  pii.push_back(make_pair(num,tanka*sell));
	  if(tanka*sell>=1000000)
	    vi.push_back(num);
	}
      }
    }
    if(vi.empty())
      cout<<"NA"<<endl;
    else{
      for(int k=0;k<nu.size();k++){
	for(int l=0;l<vi.size();l++){
	  if(nu[k]==vi[l])
	    cout<<nu[k]<<endl;
	}
      }
    }
  }
  return 0;
}

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

int main(){
	int N;
	
	while(cin>>N,N){
		map<int,long long int> mp,mp2;
		vector <int> vi;
		priority_queue<int, vector<int>, greater<int> >pq;
		for(int i=0;i<N;i++){
			int num,tanka,suuryo;
			cin>>num>>tanka>>suuryo;
			mp[num]+=tanka*suuryo;
			vi.push_back(num);
			if(mp[num]>=1000000){
				mp2[num]++;
			}
		}
		vector<int>::iterator it=vi.begin();
		for(;it!=vi.end();it++){
			if(mp2[*it]>=2){
				mp2[*it]--;
			}
			else if(mp2[*it]==1){
				pq.push(*it);
				mp2[*it]--;
			}
		}
		if(pq.empty()){
			cout<<"NA"<<endl;
		}
		else{
			int len=pq.size();
			for(int i=0;i<len;i++){
				cout<<pq.top()<<endl;
				pq.pop();
			}
		}
	}
	return 0;
}

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

int main()
{
	int num, yen, ko;
	
	while (1){
		cin >> num;
		if (!num)	break;

		for (; num > 0; num--){
			cin >> num >> yen >> ko;

			if (yen * ko >= 1000000)
				cout << num << endl;
		}
	}

	return 0;
}

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

int main()
{
	int n;
	while(cin >> n){
		if(!n){
			break;
		}
		bool flag = true;
		unsigned long long int a,b,c;
		for(int i=0;i<n;i++){
			cin >> a >> b >> c;
			if(b*c >= 1000000){
				cout << a << endl;
				flag = false;
			}
		}
		if(flag)
			cout << "NA" << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <map>
using namespace std;
int main()
{
	while(1)
	{
		int n; cin >> n ;
		if(!n) break;
		map<int,long> a;
		for(int i=0;i<n;i++)
		{
			long num,b,c;
			cin >> num >> b	>> c ;
			a[num]+=b*c;
		}
		map<int,long>::iterator p;
		bool flag=false;
		for(p=a.begin(); p!=a.end();p++)
			if(p->second >= 1000000) {cout << p->first << endl; flag=true;}
		if(flag==false) cout << "NA" << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  long long data[2][4000],n,i,f,id,a,b;
  while(1){
    cin>>n;
    if(n==0) break;
    for(i=0; i<4000; i++) data[0][i]=-1,data[1][i]=0;
    for(i=0;i<n;i++){
      cin>>id>>a>>b;
      for(f=0;f<i+1;f++){
	if(data[0][f]==id){
	  (a*b<1000000)? (data[1][f]+=(a*b)) : (data[1][f]=1000000);
	  break;
	}else if(data[0][f]==-1){
	  data[0][f]=id;
	  (a*b<1000000)? (data[1][f]=(a*b)) : (data[1][f]=1000000);
	  break;
	}
      }
    }
    for(i=0,f=0;i<n;i++){
      if(data[1][i]>=1000000)cout<<data[0][i]<<"\n",f=1;
      if(data[0][i]==-1)break;
      //cout<<"id : "<<data[0][i]<<" sale: "<<data[1][i]<<endl;
    }
    if(f==0)cout<<"NA"<<endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main(){
    vector<pair<int, long long int> > data;

    int n;

    while(cin >> n, n){
        for(int i=0; i < n; i++){
            int num, cost, goodsNum;
            cin >> num >> cost >> goodsNum;

            bool exist = false;
            for(int j=0; j < data.size(); j++){
                if(data[j].first == num){
                    data[j].second += cost * goodsNum;
                    exist = true;
                    break;
                }
            }
            if(!exist){
                data.push_back(pair<int, long long int>(num, cost*goodsNum));
            }
        }
        bool exist = false;
        for(int i=0; i < data.size(); i++){
            if(1000000 <= data[i].second){
                cout << data[i].first << endl;
                exist = true;
            }
        }
        if(!exist)cout << "NA" << endl;
        data.clear();
    }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
void shoki();
	vector<long long> num(4001,0);
	int n,ban,tanka,kazu,i,j;
int main(){
	bool y=false;
	for(j=0;j<49;j++){
		cin>>n;
		if(n==0){
			break;
		}
		int count=0;
		for(i=0;i<n;i++){
			cin>>ban>>tanka>>kazu;
			num[ban]+=tanka*kazu;
		} 
		for(int k=0;k<4001;k++){
			if(num[k]==0){
				continue;
			}
			if(num[k]>=1000000){
				y=true;
				cout<<k<<endl;
			}
		}
		if(y==false){
			cout<<"NA"<<endl;
		}
		y=false;
		shoki();
	}
	return 0;
}
void shoki(){
	for(int i=0;i<4000;i++){
		num[i]=0;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef pair<int, long long> pil;

bool cmp(pil lhs, pil rhs)
{
	return (lhs.first < rhs.first);
}

int main()
{
	int n;
	while (cin >> n, n){
	
	vector<pil> p(n);
	
	int cnt = 0;
	for (int i = 0; i < n; i++){
			int a, b, c;
			bool f = true;
			cin >> a >> b >> c;
			for (int j = 0; j <= cnt; j++){
				if (p[j].first == a){
					p[j].second += b * c;
					f = false;
				}
			}
			if (f){
				p[cnt].first += a;
				p[cnt].second += b * c;
				cnt++;
			}
		}
		bool fl = true;
		for (int i = 0; i < cnt; i++){
			if (1000000 <= p[i].second){
				cout << p[i].first << endl;
				fl = false;
			}
		}
		if (fl){
			cout << "NA" << endl;
		}
	}
	return (0);
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
using namespace std;
void shoki();
void henkan(string);
int tansaku(int);
pair<string,long long> num[4001];
int n,ban,tanka,kazu,i,j,memo;
bool dp[4001]={false};
int main(){
	int al=0;
	bool y=false;
	while(1){
		shoki();
		cin>>n;
		if(n==0){
			break;
		}
		int count=0;
		for(i=0;i<n;i++){
			cin>>num[i].first>>tanka>>kazu;
			henkan(num[i].first);
			if(dp[memo]==true){
				num[tansaku(i)].second+=tanka*kazu;
			}
			else{
			num[i].second+=tanka*kazu;
			}
			dp[memo]=true;
			memo=0;
		}
		for(int k=0;k<=i;k++){
			if(num[k].second==0){
				continue;
			}
			if(num[k].second>=1000000){
				y=true;
				cout<<num[k].first<<endl;
			}
		}
		if(y==false){
			cout<<"NA"<<endl;
		}
		y=false;
		shoki();
		memset(dp,false,sizeof(dp));
	}
	return 0;
}
void shoki(){
	for(int i=0;i<4001;i++){
		num[i].first="0";
		num[i].second=0;
	}
	return;
}
void henkan(string str1){
	long long kake=1;
	for(int i=0;i<str1.size();i++){
		memo+=str1[i]*i;
		i*=10;
	}
	return;
}
int tansaku(int rec){
	int res;
	for(int l=0;l<rec;l++){
		if(num[rec].first==num[l].first){
			return res=l;
		}
	}
}