#include <strings.h>
#include <stdio.h>
struct E {                                                                      
    int id;                                                                         long long sum;                                                              
};

int getNo(struct E *employee, int id) {                                         
    int index = 0;                                                              
                                                                                
    while (employee[index].id != 0 && employee[index].id != id) {               
        index++;                                                                
    }                                                                           
                                                                                
    return index;                                                               
}  

int main(void) {                                                                
    int n, i, index;                                                            
    int id;                                                                     
    long long price, amount;                                                    
    struct E employee[4001];                                                    
    int flag;                                                                   
                                                                                
    while (scanf("%d", &n)) {                                                   
        if (n == 0)                                                             
            break;                                                              
        bzero(employee, sizeof(struct E) * 4001);                               
        for (i = 0; i < n; i++) {                                               
            scanf("%d %lld %lld", &id, &price, &amount);                        
            index = getNo(employee, id);                                        
            employee[index].id = id;                                            
            employee[index].sum += (price * amount);                            
        }                                                                       
        flag = 0;                                                               
        for (i = 0; i < 4001; i++) {                                            
            if (employee[i].sum >= 1000000) {                                   
                printf("%d\n", employee[i].id);                                 
                flag = 1;                                                       
            }                                                                   
        }                                                                       
        if (flag == 0) {                                                        
            printf("NA\n");                                                     
        }                                                                       
    }                                                                           
                                                                                
    return 0;                                                                   
}

Measured memory_bytes: 680