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<iostream>
#include<cstdio>
#include<vector>

using namespace std;

struct data{
  int id;
  int price;
  int amount;
  long rate;
};

int main(){
  int n=0;
  while(1){
    cin>>n;
    if(n==0){return 0;}
    vector<struct data> data(n);
    int c=0;
    for(int i=0;i<n;i++){
      scanf("%d %d %d",&data[i].id,&data[i].price,&data[i].amount);
      data[i].rate=data[i].price*data[i].amount;
    }
    vector<struct data> res(n);
    for(int i=0;i<n;i++){
      res[i].id=0;
    }
    for(int i=0;i<n;i++){
      int find=0;
      for(int j=0;j<i;j++){
	if(data[i].id==res[j].id){
	  res[j].rate+=data[i].rate;
	  find=1;
	  break;
	}
      }
      if(find==0){
	res[i].id=data[i].id;
	res[i].rate=data[i].rate;
      }
    }
    for(int i=0;i<n;i++){
      if(res[i].id!=0&&res[i].rate>=1000000){
	cout<<data[i].id<<"\n";
	c++;
      }
    }
    if(c==0){
      cout<<"NA\n";
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std; 
#define pb push_back
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef vector<int> Vi;

int main()
{
  int n;
  while( cin >> n, n ) {
    int a, b, c;
    map<int, int> m;
    Vi v;
    bool flag = false;
    Rep(i, n) {
      cin >> a >> b >> c;
      if( m[a] == 0 ) {
	v.pb( a );
      }
      m[a] += b * c;
    }
    
    Rep(i, v.size()) {
      if( m[v[i]] >= 1000000 ) {
	cout << v[i] << endl;
	flag = true;
      }
    }

    if( !flag ) cout << "NA" << endl;
  }
}

C++: #include <iostream>
#include <set>
using namespace std;
int main( void )
{
	int n;
	while ( cin >> n && n != 0 )
	{
		set <int> T;

		bool exist = false;
		for ( int i = 0; i < n; i++ )
		{
			int no, price, items;
			cin >> no >> price >> items;

			if ( no < 4000 && price <= 1000000 && items <= 100000 )
			{
				long long profit = (long long)price * items;
				if ( T.find( no ) == T.end() && profit >= 1000000L )
				{
					exist = true;
					cout << no << endl;
					T.insert( no );
				}
			}
		}

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

	return 0;
}

C++: #include<stdio.h>

int main(void) {
	long long int a, b, count = 1, number = 0, syain[4010], tanka[4010], suuryou[4010], score[4010] = { 0 }, noruma = 1000000, sens = 0;
	while (count) {
		scanf("%d", &count);
		for (size_t i = 0; i < count; i++)
		{
			scanf("%lld %lld %lld", &syain[number], &tanka[number], &suuryou[number]);
			score[syain[number]] += tanka[number] * suuryou[number];
			if (score[syain[number]] >= noruma)
			{
				printf("%lld\n", syain[number]);
				sens++;
			}
			number++;
		}
		if (sens == 0 && count != 0)
		{
			printf("NA\n");
		}
		sens = 0;
	}
	return 0;
}

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

using namespace std;

#define ll long long

int main(void){
  map<int,ll> m;
  int n;
  int no,amount,price;

  while(cin >> n){
	bool exist = false;
        if(!n) break;
	for(int i=0;i<n;i++){
	  cin >> no >> amount >> price;
	  m[no] += amount*price;
	}
	map<int,ll>::iterator it = m.begin();
	while(it!=m.end()){
	  if((*it).second >= 1e+6){
		cout << (*it).first << endl;
		exist = true;
	  }
	  ++it;
	}
	if(!exist) cout << "NA" << endl;
	m.clear();
  }
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<double,double> P;

int main(){
	
	int num;
	while(~scanf("%d",&num)){
		if(num==0) break;
		bool isok=false;
		map<string,int> val;
		for(int i=0;i<num;i++){
			char n[16];
			int m,o;
			scanf("%s %d %d",n,&m,&o);
			val[n] += m*o;
		}

		for(map<string,int>::iterator it = val.begin(); it != val.end(); it++){
			if(it->second >= 1000000){
				cout << it->first << endl;
				isok=true;
			}
		}
		if(!isok) cout <<  "NA" << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#define N 4001
using namespace std;
int main(){

  int n,a,b,tanka,uriage,jun[N];
  long long int num[N];
  bool judge;

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

    for(int i=0;i<N;i++){
      num[i] = 0;
      jun[i] = 0;
    }

    for(int i=0,b=0;i<n;i++){
      judge = true;
      cin >> a >> tanka >> uriage;
      num[a] += (long long int)tanka * (long long int)uriage;
      for(int j=0;j<i;j++){
	if(jun[j]==a){
	  judge = false;
	  break;
	}
      }
      if(judge){
	jun[b] = a;
	b++;
      }
    }

    judge = true;
    for(a=0;jun[a]!=0;a++){
      if(num[jun[a]]>=1000000){
	cout << jun[a] << endl;
	judge = false;
      }
    }
    if(judge)
      cout << "NA" << endl;
  }
  return 0;
}

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

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

C++: #include<iostream>
using namespace std;
int ans[4000];

int main(){
	int N;
	int n;
	long long int e, p, q;
	int x;
	while (1){
		x = 0;
		cin >> N;
		n = N;
		if (N == 0){ break; }
		while (N){
			cin >> e >> p >> q;
			cout << N<<x << endl;
			if (p*q >= 1000000){
				ans[x] = e;
				x++;
			}
			N--;
		}
			for (int i = 0; i < n; i++)
			{
				if (i == 0 && ans[i] == 0)cout << "NA" << endl;
				if (ans[i] == 0){ break; }
				cout << ans[i] << endl;
			}
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int target = 1000000;

int main()
{
	int data;
	while (1)
	{
		scanf("%d", &data);
		if (data == 0)break;
		vector<pair<int,int> > company;
		pair<int, int> sells;
		bool hero = false;
		int num, sell, cnt;
		for (int i = 0; i < data; i++)
		{
			scanf("%d %d %d", &num, &sell, &cnt);
			bool search = false;
			for (int j = 0; j < company.size(); j++)
			{
				if (company[j].first == num){
					search = true;
					company[j].second += sell*cnt;
					break;
				}
			}
			if (search == false)
			{
				sells.first = num;
				sells.second = sell*cnt;
				company.push_back(sells);
			}
		}
		for (int i = 0; i < company.size(); i++)
		{
			if (company[i].second >= target)
			{
				hero = true;
				printf("%d\n", company[i].first);
			}
		}
		if (hero == false)
			printf("NA\n");
	}
	return 0;
}