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 <map>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    map<int,long long int> emps;
    vector<int> ids;
    int id,cost,amount,n;
    while(cin >> n,n){
        for(int i=0;i<n;i++){
            cin >> id >> cost >> amount;
            if(emps.find(id)!=emps.end()){
                emps[id]+=cost*amount;
            }else{
                emps[id]=cost*amount;
                ids.push_back(id);
            }
        }
        sort(ids.begin(),ids.end());
        for(int i=0;i<ids.size();i++){
            if(emps.at(ids[i])>=1000000) cout << ids[i] << endl;
        }
    }
    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 <stdio.h>
 
 
int n;
long long num[4000],tanka[4000],sale_num[4000];
int sale_all[4001],judge[4001];
 
int main(void){
	int i,j,k;
	
	while(scanf("%d",&n),n!=0){
		
		for(i=0;i<n;i++){
			scanf("%d%d%d",&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]] += 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 <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <bitset>
#include <complex>
using namespace std;
 
const double EPS = 1e-9;
const double PI = 3.14159265359;
 
typedef complex<double> P;

typedef long long int li;

int main(){
	int n;

	while(cin >> n, n){
		vector<li> sales(4001);
		int num;
		li tanka, kazu;
		for(int i = 0; i < n; i++){
			cin >> num >> tanka >> kazu;
			sales[num] += tanka*kazu;
		}

		bool NA = true;
		for(int i = 1; i <= 4000; i++){
			if(sales[i] >= 1000000){
				cout << i << endl;
				NA = false;
			}
		}
		if(NA){
			cout << "NA" << endl;
		}
	}

    return 0;
}

C++: #include<stdio.h>

int main(){
int N;
int n,m,p;
int P[4001][3]={};
int PT[4001][4]={};

while(1){
scanf("%d",&N);if(N==0)break;

for(int i=1;i<=N;i++){
scanf("%d %d %d",&n,&m,&p);
P[n][0]+=m*p;if(P[n][1]==0)P[n][1]=i;
}
int c=0;
for(int i=0;i<4000;i++)
if(1000000<=P[i][0]){PT[c][0]=P[i][0];PT[c][1]=P[i][1];PT[c][2]=i;c++;}

for(int i=0;i<c;i++)
for(int j=c-1;j>i;j--)
if(PT[j][1]<PT[j-1][1])
{int TT=PT[j][1];PT[j][1]=PT[j-1][1];PT[j-1][1]=TT;
 int TTT=PT[j][2];PT[j][2]=PT[j-1][2];PT[j-1][2]=TTT;}

for(int i=0;i<c;i++)
printf("%d\n",PT[i][2]);
if(c==0)printf("NA\n");
for(int i=0;i<4000;i++)
{P[i][0]=0;P[i][1]=0;P[i][2]=0;
 PT[i][0]=0;PT[i][1]=0;PT[i][2]=0;PT[i][3]=0;}

}
return  0;
}

C++: #include <vector>
#include <map>
#include <algorithm>
#include <stdio.h>

#include<iostream>

using namespace std;

typedef long long ll;

struct data{
  int id;
  ll sum;
};

int main(void)
{

  int n;
  lll num, cost;
  data d[10000];

  while(cin >> n && n){
    int flag = true;
    for(int i = 0; i < n; i++){
      cin >> d[i].id >> cost >> num;
      d[i].sum = cost*num;
    }

    for(int i = 0; i < n-1; i++){
      for(int j = i+1; j < n; j++){
        if(d[i].id == d[j].id && d[j].id){
          d[i].sum += d[j].sum;
          d[j].id = false;
        }
      }
    }

    for(int i = 0; i < n; i++){
      if(d[i].sum >= 1000000 && d[i].id){
        cout << d[i].id << endl;
        flag = false;
      }
    }
    if(flag){
        cout << "NA" << endl;
    }
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int bangou,tanka,kosuu;
    int number; cin >> number;
    do{
        int man[4000];
        for(int i=0;i<4000;i++){
            man[i]=0;
        }
        for(int i=0;i<number;i++){
            cin >> bangou >> tanka >> kosuu;
            man[bangou] += tanka*kosuu;
        }
        int count =0;
        for(int i=0;i<4000;i++){
            if(man[i]>=1000000){
                cout << i;
                count++;
            }
        }
        if(count==0)
            cout<< "NA" << endl;
        cin >> number;
    }while(number !=0);

}

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

int main(){
    int n;
    
    while(true){
        int cnt = 0;
        unsigned long long int s[4002]={0},gs[4002]={0};
        
        cin >> n;
        if(!n) break;
        
        int t,cost;
        int num;
        for(int i = 0 ; i < n ; i++){
            cin >> num >> t >> cost;
            s[num] += t*cost;
            gs[i] = num;
        }
        
       for(int i = 0 ; i < n ; i++){
            for(int j = i+1 ; j < n ; j++){
                if(gs[i]==gs[j]&&i < j){
                    gs[j] = 4001;
                }
            }
        }
        
        for(int i = 0 ; i < n ; i++){
            if(s[gs[i]] >= 1000000){
                cout << gs[i] << endl;
                cnt++;
            }
        }
        if(!cnt) cout << "NA" << endl;
    }
    
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,h;
  while(cin>>n){
    if(n==0) break;
    h = 0;
    int b[n],p[n],q[n];
    for(int i=0;i<n;i++){
      cin >> b[i] >> p[i] >> q[i];
      for(int j=0;j<i;j++){
	if(b[j]==b[i]){
	  p[j] += p[i];
	  q[j] += q[i];
	  p[i] = 0;
	  q[i] = 0;
	  b[i] = 0;
	  break;
	}
      }
    }
    //for(int i=0;i<n;i++) cout << b[i] << ' ' << p[i] << ' ' << q[i] << endl;; 
    for(int i=0;i<n;i++){
      if(p[i]*q[i]>=1000000){
	cout << b[i] << endl;
	if(h==0) h = 1;
      }
    }
    if(h==0) cout << "NA" << endl;
  }
  return 0;
}