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 <map>
using namespace std;
typedef long long int lli;
typedef map<int, int> M;

int main() {
  lli sum[4000];
  int gid[4000];
  int n, i, j, p, q, lid;
  M m;
  bool b;

  while (1) {
    scanf("%d", &n);
    if (!n) break;
    m.clear();
    for (j=0; j<n; j++) sum[j] = 0;
    for (j=0; j<n; j++) {
      scanf("%d %d %d", &i, &p, &q);
      lid = j;
      pair<M::iterator, bool> res = m.insert(M::value_type(i, lid));
      if (!res.second) {
        M::iterator it = m.find(i);
        lid = it->second;
      }
      gid[lid] = i;
      sum[lid] += (lli)p*q;
    }
    b = false;
    for (j=0; j<(int)m.size(); j++) {
      if (sum[j] >= 1000000) {
        printf("%d\n", gid[j]);
        b = true;
      }
    }
    if (!b) {
      printf("NA\n");
    }
  }

  return 0;
}

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

using namespace std;

int main()
{
	int N, X, Y, Z;

	while (true)
	{
		cin >> N;

		if (N == 0) { break; }

		vector<long long> P(4001);

		for (int i = 0; i < N; i++)
		{
			cin >> X >> Y >> Z;

			P[X] += (long long)Y * Z;
		}

		int count_ = 0;

		for (int i = 1; i <= 4000; i++)
		{
			if (P[i] >= 1000000)
			{
				cout << i << endl; count_++;
			}
		}

		if (!count_)
		{
			cout << "NA" << endl;
		}
	}

	return 0;
}

C++: #include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 

using namespace std;

int main()
{
	int n,a,f;
	long long b,c;

	while(1){
		f=1;
		cin>>n; if(n==0) return 0;

		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			if(b*c>=1000000){ cout<<a<<endl; f=0;}
		}
		if(f) cout<<"NA"<<endl;
	}
}

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

int main(){
	while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        long long a[5000] = {0};
        long long int number;
        long long int jun[5000] = {0};
        long long tanka,kazu;
        for(int i = 0; i < n; i++){
            cin >> number >> tanka >> kazu;
            a[number] += tanka * kazu;
            jun[i] = number;
        }
        bool flg = 0;
        for(int i = n; i >= 0; i--){
            if(a[jun[i]] >= 1000000){
                cout << jun[i] << endl;
                a[jun[i]] = 0;
                flg = 1;
            }
        }


        if(!flg) cout << "NA" << endl;
	}
	return 0;
}

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

int main(){
	int n,a,b,c,flag;
	map<int, long long int> m;
	vector<int> v;
	while (cin >> n, n){
		m.clear();
		flag = 0;
		for (int i = 0; i < n; i++){
			cin >> a >> b >> c;
			if(m[a] == 0) v.push_back(a);
			m[a] += (long long int)b * (long long int)c;
		}
		for (int i = 0; i < v.size(); i++){
			if (m[v[i]] >= 1000000ll){
				flag = 1;
				cout << v[i] << endl;
			}
		}
		if (!flag) cout << "NA" << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<math.h>
#include<string.h>


int main(){
	long long int uriage[4000][3],n,no,tanka,su,i,j,newflag,naflag;
	
	while(0<=scanf("%lld",&n)){
		if(n==0) break;
		
		memset(uriage,0,sizeof(uriage));
		
		for(i=0;i<n;i++){
			scanf("%lld%lld%lld",&no,&tanka,&su);
			
			newflag=0;
			
			for(j=0;j<n;j++){
				if(uriage[j][0]==no && uriage[j][2]==1){
					uriage[j][1]+=tanka*su;
					newflag=1;
					break;
				}
			}
			
			if(newflag==0){
				for(j=0;j<n;j++){
					if(uriage[j][2]==0){
						uriage[j][1]+=tanka*su;
						uriage[j][0]=no;
						uriage[j][2]=1;
						break;
					}
				}
			}
		}
		naflag=0;
		for(i=0;i<n;i++){
			if(uriage[i][2]==0)break;
			if(uriage[i][1]>=1000000){
				printf("%lld\n",uriage[i][0]);
				naflag=1;
			}
		}
		if(naflag==0)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;

        vector<long long> sale(4001, -1);
        vector<int> id;

        for(int i=0; i<n; ++i){
            int a, b, c;
            cin >> a >> b >> c;
            if(sale[a] == -1){
                sale[a] = 0;
                id.push_back(a);
            }
            sale[a] += (long long)b * c;
        }


        bool na = true;
        for(unsigned i=0; i<id.size(); ++i){
            if(sale[id[i]] >= 1000000){
                cout << id[i] << endl;
                na = false;
            }
        }
        if(na)
            cout << "NA" << endl;
    }
}

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

C++: #include <stdio.h>

int member[4010][3] ;

int main ( )
{
	int n ; 
	bool na = false ;
	while ( scanf ( "%d" , &n ) == 1 && n ){
		na = false ;
		for ( int i = 0 ; i < n ; i++ ){
			scanf ( "%d %d %d" , &member[i][0] , &member[i][1] , &member[i][2] ) ;
			int tmp = member[i][1] * member[i][2] ;
			if ( tmp > 1000000 ){
				printf ( "%d\n" , member[i][0] ) ;
				na = true ;
			}
		}
		if ( ! na ){
			printf ( "NA\n" ) ;
		}
	}
	return 0 ;
}

C++: #include<iostream>

using namespace std;

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