Cod sursa(job #3356498)

Utilizator mgntMarius B mgnt Data 1 iunie 2026 21:12:53
Problema Curcubeu Scor 100
Compilator c-64 Status done
Runda Arhiva de probleme Marime 57.27 kb

#define BRACKETS_OPEN {

#define BRACKETS_CLOSE }

static int headers_open (void) {
    
    return 0;
    
BRACKETS_CLOSE


#include <stdio.h>

#include <stdlib.h>

#include <stddef.h>

#include <inttypes.h>

#include <limits.h>

#include <stdbool.h>

#include <string.h>


static int headers_close (void) BRACKETS_OPEN
    
    return 0;
    
}

static int exit_statuses_open (void) {
    
    return 0;
    
BRACKETS_CLOSE


#define EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE  0

#define EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED  1

#define EXIT_STATUS__NAY_FAILURE__INVALID_INPUT  2

#define EXIT_STATUS__NAY_FAILURE__SKILL_ISSUES  3

static int exit_statuses_close (void) BRACKETS_OPEN
    
    return 0;
    
}

static int data_layouts_open (void) {
    
    return 0;
    
BRACKETS_CLOSE


struct paint_operation_its_definition {
    
    uint32_t  field__from;
    
    uint32_t  field__to;
    
    uint32_t  field__time;
    
    uint32_t  field__color;
    
};

struct active_operation_its_definition {
    
    uint32_t  field__to;
    
    uint32_t  field__time;
    
    uint32_t  field__color;
    
};

struct program_state_its_definition {
    
    FILE  * field__input_file_itself;
    
    FILE  * field__output_file_itself;
    
    size_t  field__integer_n_itself;
    
    size_t  field__integer_a_one_itself;
    
    size_t  field__integer_b_one_itself;
    
    size_t  field__integer_c_one_itself;
    
    struct paint_operation_its_definition  * field__operations_array_itself;
    
    size_t  field__operations_array_its_size;
    
    size_t  * field__offset_array_itself;
    
    size_t  field__offset_array_its_size;
    
    struct paint_operation_its_definition  * field__sorted_array_itself;
    
    size_t  field__sorted_array_its_size;
    
    struct active_operation_its_definition  * field__heap_array_itself;
    
    size_t  field__heap_array_its_size;
    
    uint32_t  * field__colors_array_itself;
    
    size_t  field__colors_array_its_size;
    
};


static int data_layouts_close (void) BRACKETS_OPEN
    
    return 0;
    
}

static int core_routines_open (void) {
    
    return 0;
    
BRACKETS_CLOSE


int acquire_all_resources_up_front (struct program_state_its_definition *  * receptacle) {
    
    /* Step is introduce the locals. */ {
        
        BRACKETS_CLOSE
        
        int  exit_status_itself = 0;
        
        struct program_state_its_definition  * program_state_itself = NULL;
        
        FILE  * input_file_itself = NULL;
        
        FILE  * output_file_itself = NULL;
        
        size_t  integer_n_itself = 0;
        
        size_t  integer_a_one_itself = 0;
        
        size_t  integer_b_one_itself = 0;
        
        size_t  integer_c_one_itself = 0;
        
        struct paint_operation_its_definition  * operations_array_itself = NULL;
        
        size_t  operations_array_its_size = 0;
        
        size_t  * offset_array_itself = NULL;
        
        size_t  offset_array_its_size = 0;
        
        struct paint_operation_its_definition  * sorted_array_itself = NULL;
        
        size_t  sorted_array_its_size = 0;
        
        struct active_operation_its_definition  * heap_array_itself = NULL;
        
        size_t  heap_array_its_size = 0;
        
        uint32_t  * colors_array_itself = NULL;
        
        size_t  colors_array_its_size = 0;
        
        exit_status_itself = EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE;
        
        BRACKETS_OPEN
        
    }
    
    /* Step is acquire contingent truth uint32_t ⊆ size_t. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            if (SIZE_MAX < UINT32_MAX) {
                
                /*  This  program  won't budge much
                 *  unless uint32_t values may be
                 *  stored in size_t variables.
                 */
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                
            }
            
        }
        
    }
    
    /* Step is acquire the program state itself. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            size_t  number_of_bytes = 0;
            
            void  * pointer_itself = NULL;
            
            number_of_bytes = sizeof(struct program_state_its_definition);
            
            pointer_itself = malloc(number_of_bytes);
            
            if (NULL == pointer_itself) {
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                
            }
            else {
                
                /* Publish to the outer scope. */
                
                program_state_itself = pointer_itself;
                
            }
            
        }
        
    }
    
    /* Step is acquire the input file itself. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            FILE  * pointer_itself = NULL;
            
            pointer_itself = fopen("curcubeu.in", "r");
            
            if (NULL == pointer_itself) {
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                
            }
            else {
                
                /* Publish to the outer scope. */
                
                input_file_itself = pointer_itself;
                
            }
            
        }
        
    }
    
    /* Step is acquire the output file itself. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            FILE  * pointer_itself = NULL;
            
            pointer_itself = fopen("curcubeu.out", "w");
            
            if (NULL == pointer_itself) {
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                
            }
            else {
                
                /* Publish to the outer scope. */
                
                output_file_itself = pointer_itself;
                
            }
            
        }
        
    }
    
    /* Step is acquire the integers N, A₁, B₁, C₁. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            FILE  * file_f = NULL;
            
            size_t  integer_n_its_value = 0;
            
            size_t  integer_a_one_its_value = 0;
            
            size_t  integer_b_one_its_value = 0;
            
            size_t  integer_c_one_its_value = 0;
            
            int  status_of_sorts = 0;
            
            file_f = input_file_itself;  /* Drip. */
            
            status_of_sorts = fscanf(file_f, "%zu %zu %zu %zu", &integer_n_its_value,
                                                                
                                                                &integer_a_one_its_value,
                                                                
                                                                &integer_b_one_its_value,
                                                                
                                                                &integer_c_one_its_value);
            
            if (4 != status_of_sorts) {
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                
            }
            else {
                
                if ((integer_n_its_value < 2) || ((UINT32_C(1000000)) < integer_n_its_value)) {
                    
                    exit_status_itself = EXIT_STATUS__NAY_FAILURE__INVALID_INPUT;  /* malformed */
                    
                }
                else {
                    
                    /*  1000000 ≤ 2³², and  ⌊√n⌋ ≤ 1000 = ⌊√(1000000)⌋,
                     *  
                     *  so skipping implementing floor_sqrt(n), this time,
                     *  
                     *  simply probe every remainder n % j, j from n to min(n − 1, 1000),
                     *  
                     *  and be done with it, ensuring that indeed, yeah, n is a prime.
                     */
                    
                    bool  is_prime = 0;
                    
                    size_t  probe = 0;
                    
                    is_prime = (2 <= integer_n_its_value) ? true : false;
                    
                    probe = 2;
                    
                    while (is_prime && (probe < integer_n_its_value) && (probe < 1001)) {
                        
                        if (0 == (integer_n_its_value % probe)) {
                            
                            is_prime = false;
                            
                        }
                        else {
                            
                            probe += 1;
                            
                        }
                        
                    }
                    
                    if ( !is_prime) {
                        
                        exit_status_itself = EXIT_STATUS__NAY_FAILURE__INVALID_INPUT;
                        
                    }
                    else {
                        
                        if ( (integer_a_one_its_value < 1) || (integer_n_its_value <= integer_a_one_its_value) ||
                             
                             (integer_b_one_its_value < 1) || (integer_n_its_value <= integer_b_one_its_value) ||
                             
                             (integer_c_one_its_value < 1) || (integer_n_its_value <= integer_c_one_its_value)  )  {
                            
                            exit_status_itself = EXIT_STATUS__NAY_FAILURE__INVALID_INPUT;
                            
                        }
                        else {
                            
                            /* Publish to the outer scope. */
                            
                            integer_n_itself = integer_n_its_value;
                            
                            integer_a_one_itself = integer_a_one_its_value;
                            
                            integer_b_one_itself = integer_b_one_its_value;
                            
                            integer_c_one_itself = integer_c_one_its_value;
                            
                        }
                        
                    }
                    
                }
                
            }
            
        }
        
    }
    
    /* Step is acquire the operations array itself. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            size_t  number_of_elements = 0;
            
            size_t  element_byte_size = 0;
            
            size_t  number_of_bytes = 0;
            
            void  * pointer_itself = NULL;
            
            number_of_elements = integer_n_itself - 1;  /* Drip and chop. */
            
            element_byte_size = sizeof(struct paint_operation_its_definition);
            
            if ((SIZE_MAX / element_byte_size) < number_of_elements) {
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                
            }
            else {
                
                number_of_bytes = number_of_elements * element_byte_size;
                
                pointer_itself = malloc(number_of_bytes);
                
                if (NULL == pointer_itself) {
                    
                    exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                    
                }
                else {
                    
                    /* Publish to the outer scope. */
                    
                    operations_array_itself = pointer_itself;
                    
                    operations_array_its_size = number_of_elements;
                    
                }
                
            }
            
        }
        
    }
    
    /* Step is acquire the offset array itself. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            size_t  number_of_elements = 0;
            
            size_t  element_byte_size = 0;
            
            size_t  number_of_bytes = 0;
            
            void  * pointer_itself = NULL;
            
            number_of_elements = integer_n_itself;  /* Drip. */
            
            element_byte_size = sizeof(size_t);
            
            if ((SIZE_MAX / element_byte_size) < number_of_elements) {
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                
            }
            else {
                
                number_of_bytes = number_of_elements * element_byte_size;
                
                pointer_itself = malloc(number_of_bytes);
                
                if (NULL == pointer_itself) {
                    
                    exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                    
                }
                else {
                    
                    /* Publish to the outer scope. */
                    
                    offset_array_itself = pointer_itself;
                    
                    offset_array_its_size = number_of_elements;
                    
                }
                
            }
            
        }
        
    }
    
    /* Step is acquire the sorted array itself. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            size_t  number_of_elements = 0;
            
            size_t  element_byte_size = 0;
            
            size_t  number_of_bytes = 0;
            
            void  * pointer_itself = NULL;
            
            number_of_elements = integer_n_itself - 1;  /* Drip and chop. */
            
            element_byte_size = sizeof(struct paint_operation_its_definition);
            
            if ((SIZE_MAX / element_byte_size) < number_of_elements) {
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                
            }
            else {
                
                number_of_bytes = number_of_elements * element_byte_size;
                
                pointer_itself = malloc(number_of_bytes);
                
                if (NULL == pointer_itself) {
                    
                    exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                    
                }
                else {
                    
                    /* Publish to the outer scope. */
                    
                    sorted_array_itself = pointer_itself;
                    
                    sorted_array_its_size = number_of_elements;
                    
                }
                
            }
            
        }
        
    }
    
    /* Step is acquire the heap array itself. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            size_t  number_of_elements = 0;
            
            size_t  element_byte_size = 0;
            
            size_t  number_of_bytes = 0;
            
            void  * pointer_itself = NULL;
            
            number_of_elements = integer_n_itself - 1;  /* Drip and chop. */
            
            element_byte_size = sizeof(struct active_operation_its_definition);
            
            if ((SIZE_MAX / element_byte_size) < number_of_elements) {
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                
            }
            else {
                
                number_of_bytes = number_of_elements * element_byte_size;
                
                pointer_itself = malloc(number_of_bytes);
                
                if (NULL == pointer_itself) {
                    
                    exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                    
                }
                else {
                    
                    /* Publish to the outer scope. */
                    
                    heap_array_itself = pointer_itself;
                    
                    heap_array_its_size = number_of_elements;
                    
                }
                
            }
            
        }
        
    }
    
    /* Step is acquire the colors array itself. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            size_t  number_of_elements = 0;
            
            size_t  element_byte_size = 0;
            
            size_t  number_of_bytes = 0;
            
            void  * pointer_itself = NULL;
            
            number_of_elements = integer_n_itself - 1;  /* Drip and chop. */
            
            element_byte_size = sizeof(uint32_t);
            
            if ((SIZE_MAX / element_byte_size) < number_of_elements) {
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                
            }
            else {
                
                number_of_bytes = number_of_elements * element_byte_size;
                
                pointer_itself = malloc(number_of_bytes);
                
                if (NULL == pointer_itself) {
                    
                    exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                    
                }
                else {
                    
                    /* Publish to the outer scope. */
                    
                    colors_array_itself = pointer_itself;
                    
                    colors_array_its_size = number_of_elements;
                    
                }
                
            }
            
        }
        
    }
    
    /* Step is pass the torch. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            program_state_itself->field__input_file_itself = input_file_itself;
            
            program_state_itself->field__output_file_itself = output_file_itself;
            
            program_state_itself->field__integer_n_itself = integer_n_itself;
            
            program_state_itself->field__integer_a_one_itself = integer_a_one_itself;
            
            program_state_itself->field__integer_b_one_itself = integer_b_one_itself;
            
            program_state_itself->field__integer_c_one_itself = integer_c_one_itself;
            
            program_state_itself->field__operations_array_itself = operations_array_itself;
            
            program_state_itself->field__operations_array_its_size = operations_array_its_size;
            
            program_state_itself->field__offset_array_itself = offset_array_itself;
            
            program_state_itself->field__offset_array_its_size = offset_array_its_size;
            
            program_state_itself->field__sorted_array_itself = sorted_array_itself;
            
            program_state_itself->field__sorted_array_its_size = sorted_array_its_size;
            
            program_state_itself->field__heap_array_itself = heap_array_itself;
            
            program_state_itself->field__heap_array_its_size = heap_array_its_size;
            
            program_state_itself->field__colors_array_itself = colors_array_itself;
            
            program_state_itself->field__colors_array_its_size = colors_array_its_size;
            
            /* Publish to the outer scope. */
            
            *receptacle = program_state_itself;
            
        }
        else {
            
            if (NULL != colors_array_itself) {
                
                free(colors_array_itself);
                
                colors_array_itself = NULL;
                
                colors_array_its_size = 0;
                
            }
            
            if (NULL != heap_array_itself) {
                
                free(heap_array_itself);
                
                heap_array_itself = 0;
                
                heap_array_its_size = 0;
            }
            
            if (NULL != sorted_array_itself) {
                
                free(sorted_array_itself);
                
                sorted_array_itself = NULL;
                
                sorted_array_its_size = 0;
                
            }
            
            if (NULL != offset_array_itself) {
                
                free(offset_array_itself);
                
                offset_array_itself = NULL;
                
                offset_array_its_size = 0;
                
            }
            
            if (NULL != operations_array_itself) {
                
                free(operations_array_itself);
                
                operations_array_itself = NULL;
                
            }
            
            if (NULL != output_file_itself) {
                
                int  status_of_sorts = 0;
                
                status_of_sorts = fclose(output_file_itself);
                
                output_file_itself = NULL;
                
                (void) status_of_sorts;
                
            }
            
            if (NULL != input_file_itself) {
                
                int  status_of_sorts = 0;
                
                status_of_sorts = fclose(input_file_itself);
                
                input_file_itself = NULL;
                
                (void) status_of_sorts;
                
            }
            
            if (NULL != program_state_itself) {
                
                free(program_state_itself);
                
                program_state_itself = NULL;
                
            }
            
        }
        
        return exit_status_itself;
        
    }
    
}

int solve_the_problem_already_and_be_quick_about_it (struct program_state_its_definition  * program_state_itself) {
    
    /* Step is introduce the locals. */ {
        
        BRACKETS_CLOSE
        
        int  exit_status_itself = 0;
        
        exit_status_itself = EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE;
        
        BRACKETS_OPEN
        
    }
    
    /* Step is batch bound check everything, once and for all. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            size_t  integer_n_itself = 0;
            
            size_t  operations_array_its_size = 0;
            
            size_t  sorted_array_its_size = 0;
            
            integer_n_itself = program_state_itself->field__integer_n_itself;  /* Drip. */
            
            operations_array_its_size = program_state_itself->field__operations_array_its_size;  /* Drip. */
            
            sorted_array_its_size = program_state_itself->field__sorted_array_its_size;
            
            if ( (integer_n_itself < 1) ||
                 
                 (operations_array_its_size < (integer_n_itself - 1)) ||
                 
                 (sorted_array_its_size < operations_array_its_size) )  {
                
                /* Faulty logic somewhere, logic error, ageamiu, skill issues. */
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__SKILL_ISSUES;
                
            }
            
        }
        
    }
    
    /* Step is compute the operations array, from integers N, A₁, B₁, C₁. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            struct paint_operation_its_definition  * operations_array_itself = NULL;
            
            size_t  n = 0;
            
            size_t  a = 0;
            
            size_t  b = 0;
            
            size_t  c = 0;
            
            size_t  u = 0;
            
            size_t  w = 0;
            
            size_t  j = 0;
            
            operations_array_itself = program_state_itself->field__operations_array_itself;  /* Drip. */
            
            n = program_state_itself->field__integer_n_itself;  /* Drip. */
            
            a = program_state_itself->field__integer_a_one_itself;  /* Drip. */
            
            b = program_state_itself->field__integer_b_one_itself;  /* Drip. */
            
            c = program_state_itself->field__integer_c_one_itself;  /* Drip. */
            
            j = 1;
            
            while (j < n) {
                
                u = (a < b) ? a : b;
                
                w = (a < b) ? b : a;
                
                operations_array_itself[j - 1].field__from = u;
                
                operations_array_itself[j - 1].field__to = w;
                
                operations_array_itself[j - 1].field__color = c;
                
                operations_array_itself[j - 1].field__time = j;
                
                j += 1;
                
                a = ((a * j) % n);
                
                b = ((b * j) % n);
                
                c = ((c * j) % n);
                
            }
                        
        }
        
    }
    
    /* Step is for each j ∈ ℤₚ⁺, count how many paint operations begin at j. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            struct paint_operation_its_definition  * operations_array_itself = NULL;
            
            size_t  operations_array_its_size = 0;
            
            size_t  * offset_array_itself = NULL;
            
            size_t  offset_array_its_size = 0;
            
            size_t  current_offset_itself = 0;
            
            size_t  current_operation_itself = 0;
            
            operations_array_itself = program_state_itself->field__operations_array_itself;  /* Drip. */
            
            operations_array_its_size = program_state_itself->field__operations_array_its_size;  /* Drip. */
            
            offset_array_itself = program_state_itself->field__offset_array_itself;  /* Drip. */
            
            offset_array_its_size = program_state_itself->field__offset_array_its_size;  /* Drip. */
            
            /* Clear the counters. */
            
            current_offset_itself = 0;
            
            while (current_offset_itself < offset_array_its_size) {
                
                offset_array_itself[current_offset_itself] = 0;
                
                current_offset_itself += 1;
                
            }
            
            /* Count, updating the counters. */
            
            current_operation_itself = 0;
            
            while (current_operation_itself < operations_array_its_size) {
                
                current_offset_itself = operations_array_itself[current_operation_itself].field__from;
                
                offset_array_itself[current_offset_itself] += 1;
                
                current_operation_itself += 1;
                
            }
            
        }
        
    }
    
    /* Step is building upon previous counting, sort the operations, already. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            struct paint_operation_its_definition  * operations_array_itself = NULL;
            
            size_t  operations_array_its_size = 0;
            
            size_t  * offset_array_itself = NULL;
            
            size_t  offset_array_its_size = 0;
            
            struct paint_operation_its_definition  * sorted_array_itself = NULL;
            
            size_t  current_offset_itself = 0;
            
            size_t  current_where_from = 0;
            
            size_t  current_count = 0;
            
            size_t  current_operation_itself = 0;
            
            size_t  current_from_value = 0;
            
            operations_array_itself = program_state_itself->field__operations_array_itself;  /* Drip. */
            
            operations_array_its_size = program_state_itself->field__operations_array_its_size;  /* Drip. */
            
            offset_array_itself = program_state_itself->field__offset_array_itself;  /* Drip. */
            
            offset_array_its_size = program_state_itself->field__offset_array_its_size;  /* Drip. */
            
            sorted_array_itself = program_state_itself->field__sorted_array_itself;  /* Drip. */
            
            /* Compute where the from values, only to be incremented away. */
            
            current_where_from = 0;
            
            current_offset_itself = 0;
            
            while (current_offset_itself < offset_array_its_size) {
                
                current_count = offset_array_itself[current_offset_itself];
                
                if (0 < current_count) {
                    
                    offset_array_itself[current_offset_itself] = current_where_from;
                    
                    current_where_from += current_count;
                    
                }
                
                current_offset_itself += 1;
                
            }
            
            /* Increment away the where from values, count sort, nothing too fancy. */
            
            current_operation_itself = operations_array_its_size;
            
            while (0 < current_operation_itself) {
                
                current_operation_itself -= 1;
                
                current_from_value = operations_array_itself[current_operation_itself].field__from;
                
                current_offset_itself = offset_array_itself[current_from_value];
                
                offset_array_itself[current_from_value] += 1;
                
                sorted_array_itself[current_offset_itself] = operations_array_itself[current_operation_itself];
                
            }
            
        }
        
    }
    
    /* Step is find the colors, with a max heap of active operations, by time. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            /* Region is introduce the locals. */ {
                
                BRACKETS_CLOSE
                
                struct active_operation_its_definition  active_operation_auto_one = {0, 0, 0};
                
                struct active_operation_its_definition  active_operation_auto_two = {0, 0, 0};
                
                struct active_operation_its_definition  active_operation_swaps = {0, 0, 0};
                
                uint32_t  * colors_array_itself = NULL;
                
                struct active_operation_its_definition  * heap_array_itself = NULL;
                
                struct paint_operation_its_definition  * sorted_array_itself = NULL;
                
                size_t  sorted_array_its_size = 0;
                
                struct paint_operation_its_definition  * current_operation_itself = NULL;
                
                struct active_operation_its_definition  * topmost_active_operation = NULL;
                
                struct active_operation_its_definition  * withheld_operation_itself = NULL;
                
                size_t  integer_n_itself = 0;
                
                size_t  current_remainder = 0;
                
                size_t  current_operation_its_index = 0;
                
                size_t  max_heap_its_size = 0;
                
                size_t  current_node = 0;
                
                size_t  current_parent = 0;
                
                size_t  current_subnode = 0;
                
                size_t  last_node = 0;

                BRACKETS_OPEN
                
            }
            
            /* Region is initialize the outer scope dependent locals. */ {
                
                BRACKETS_CLOSE
                
                integer_n_itself = program_state_itself->field__integer_n_itself;  /* Drip. */
                
                colors_array_itself = program_state_itself->field__colors_array_itself;  /* Drip. */
                
                heap_array_itself = program_state_itself->field__heap_array_itself;  /* Drip. */
                
                sorted_array_itself = program_state_itself->field__sorted_array_itself;  /* Drip. */
                
                sorted_array_its_size = program_state_itself->field__sorted_array_its_size;  /* Drip. */
                
                BRACKETS_OPEN
                
            }
            
            /* Region is initialize the variables driving the loop below. */ {
                
                BRACKETS_CLOSE
                
                withheld_operation_itself = &active_operation_auto_two;
                
                max_heap_its_size = 0;
                
                topmost_active_operation = NULL;
                
                current_remainder = 1;
                
                current_operation_its_index = 0;
                
                BRACKETS_OPEN
                
            }
            
            while (current_remainder < integer_n_itself) {
                
                /* Region is drop the topmost active operation, if it had just ended, on repeat. */ {
                    
                    while ( (NULL != topmost_active_operation) && 
                         
                         (topmost_active_operation->field__to < current_remainder) )  {
                         
                        if (0 < max_heap_its_size) {
                            
                            /* Region is pop the top of the heap, into topmost active operation. */ {
                                
                                BRACKETS_CLOSE
                                
                                memcpy(topmost_active_operation, &heap_array_itself[0], sizeof(struct active_operation_its_definition));
                                 
                                memcpy(&heap_array_itself[0], &heap_array_itself[max_heap_its_size - 1], sizeof(struct active_operation_its_definition));
                                 
                                memset(&heap_array_itself[max_heap_its_size - 1], 0, sizeof(struct active_operation_its_definition));
                                 
                                 
                                max_heap_its_size -= 1;
                                 
                                if (2 <= max_heap_its_size) {
                                     
                                     last_node = max_heap_its_size / 2;
                                     
                                     current_node = 1;
                                     
                                    while (current_node <= last_node) {
                                        
                                        current_subnode = current_node * 2;
                                        
                                        if ( (current_subnode < (max_heap_its_size - 1)) &&
                                              
                                              (heap_array_itself[current_subnode - 1].field__time < heap_array_itself[(current_subnode + 1) - 1].field__time) )  {
                                         
                                            current_subnode += 1;
                                            
                                        }
                                        
                                        if (heap_array_itself[current_node - 1].field__time < heap_array_itself[current_subnode - 1].field__time) {
                                            
                                            memcpy(&active_operation_swaps, &heap_array_itself[current_node - 1], sizeof(struct active_operation_its_definition));
                                            
                                            memcpy(&heap_array_itself[current_node - 1], &heap_array_itself[current_subnode - 1], sizeof(struct active_operation_its_definition));
                                            
                                            memcpy(&heap_array_itself[current_subnode - 1], &active_operation_swaps, sizeof(struct active_operation_its_definition));
                                            
                                            current_node = current_subnode;
                                            
                                        }
                                        else {
                                            
                                            current_node = last_node + 1; /* effectively exiting the loop. */
                                            
                                        }
                                        
                                     }
                                    
                                }
                                
                                BRACKETS_OPEN
                                
                            }
                             
                        }
                        else {
                            
                            /* Region is clear the topmost active operation. */ {
                                
                                BRACKETS_CLOSE
                                
                                topmost_active_operation = NULL;
                                
                                BRACKETS_OPEN
                                
                            }
                            
                        }
                         
                    }
                    
                }
                
                /* Region is update the topmost active operation, with all operations from remainder. */ {
                    
                    BRACKETS_CLOSE
                    
                    while ( (current_operation_its_index < sorted_array_its_size) &&
                            
                            (sorted_array_itself[current_operation_its_index].field__from == current_remainder)  )   {
                        
                        current_operation_itself = &sorted_array_itself[current_operation_its_index];
                        
                        if (NULL == topmost_active_operation) {
                            
                            /* Region is designate the current operation, as the topmost active operation. */ {
                                
                                BRACKETS_CLOSE
                                
                                topmost_active_operation = &active_operation_auto_one;
                                
                                topmost_active_operation->field__to    = current_operation_itself->field__to;
                                
                                topmost_active_operation->field__time  = current_operation_itself->field__time;
                                
                                topmost_active_operation->field__color = current_operation_itself->field__color;
                                
                                BRACKETS_OPEN
                                
                            }
                            
                        }
                        else {
                            
                            /* Region is update the topmost and the withheld active operations, accordingly. */ {
                                
                                BRACKETS_CLOSE
                                
                                if (topmost_active_operation->field__time < current_operation_itself->field__time) {
                                    
                                    memcpy(withheld_operation_itself, topmost_active_operation, sizeof(struct active_operation_its_definition));
                                    
                                    topmost_active_operation->field__to    = current_operation_itself->field__to;
                                    
                                    topmost_active_operation->field__time  = current_operation_itself->field__time;
                                    
                                    topmost_active_operation->field__color = current_operation_itself->field__color;
                                    
                                }
                                else {
                                    
                                    withheld_operation_itself->field__to    = current_operation_itself->field__to;
                                    
                                    withheld_operation_itself->field__time  = current_operation_itself->field__time;
                                    
                                    withheld_operation_itself->field__color = current_operation_itself->field__color;
                                    
                                }
                                
                                BRACKETS_OPEN
                                
                            }
                            
                            /* Region is add the withheld active operation, into the by time max heap. */ {
                                
                                BRACKETS_CLOSE
                                
                                max_heap_its_size += 1;
                                
                                heap_array_itself[max_heap_its_size - 1] = *withheld_operation_itself;
                                
                                current_node = max_heap_its_size;
                                
                                while (/* root: */ 1 != current_node) {
                                    
                                    
                                    /* Hey compiler, feel free to shift away the next division, by all means, obrigado. */
                                    
                                    current_parent = current_node / 2;
                                    
                                    if (heap_array_itself[current_parent - 1].field__time <
                                        
                                        heap_array_itself[current_node   - 1].field__time    )   {
                                        
                                        memcpy(&active_operation_swaps, &heap_array_itself[current_parent - 1], sizeof(struct active_operation_its_definition));
                                        
                                        memcpy(&heap_array_itself[current_parent - 1], &heap_array_itself[current_node - 1], sizeof(struct active_operation_its_definition));
                                        
                                        memcpy(&heap_array_itself[current_node - 1], &active_operation_swaps, sizeof(struct active_operation_its_definition));
                                        
                                        current_node = current_parent;
                                        
                                    }
                                    else {
                                        
                                        current_node = /* root: */ 1;  /* Effectively exiting the loop. */
                                        
                                    }
                                    
                                }
                                
                                BRACKETS_OPEN
                                
                            }
                            
                        }
                        
                        current_operation_its_index += 1;
                        
                    }
                    
                    BRACKETS_OPEN
                    
                }
                
                /* Region is update the color, from the topmost operation, if any. */ {
                    
                    BRACKETS_CLOSE
                    
                    if (NULL != topmost_active_operation) {
                        
                        colors_array_itself[current_remainder - 1] = 
                            
                              topmost_active_operation->field__color;
                        
                    }
                    else {
                        
                        colors_array_itself[current_remainder - 1] = 0;
                        
                    }
                    
                    BRACKETS_OPEN
                    
                }
                
                /* Region is increment the current remainder. */ {
                    
                    BRACKETS_CLOSE
                    
                    current_remainder += 1;
                    
                    BRACKETS_OPEN
                    
                }
                
            }
            
        }
        
    }
    
    /* Step is pass the torch. */ {
        
        return exit_status_itself;
        
    }
    
}

int write_the_output_eight_or_more_colors_at_a_time (struct program_state_its_definition  * program_state_itself) {
    
    /* Step is introduce the locals. */ {
        
        BRACKETS_CLOSE
        
        int  exit_status_itself = 0;
        
        size_t  left_off = 0;
        
        exit_status_itself = EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE;
        
        BRACKETS_OPEN
        
    }
    
    /* Step is write the colors, most of them. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            FILE  * file_g = NULL;
            
            uint32_t  * colors_array_itself = 0;
            
            size_t  colors_array_its_size = 0;
            
            size_t  current_index = 0;
            
            int  status_of_sorts = 0;
            
            file_g = program_state_itself->field__output_file_itself;  /* Drip. */
            
            colors_array_itself = program_state_itself->field__colors_array_itself;  /* Drip. */
            
            colors_array_its_size = program_state_itself->field__colors_array_its_size;  /* Drip. */
            
            if (8 <= colors_array_its_size) {
                
                current_index = 0;
                
                while ( (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) && 
                        
                        (current_index < (colors_array_its_size - 7)) )  {
                    
                    status_of_sorts = fprintf(file_g, "%" PRIu32 "\n"
                                                      
                                                      "%" PRIu32 "\n"
                                                      
                                                      "%" PRIu32 "\n"
                                                      
                                                      "%" PRIu32 "\n"
                                                      
                                                      "%" PRIu32 "\n"
                                                      
                                                      "%" PRIu32 "\n"
                                                      
                                                      "%" PRIu32 "\n"
                                                      
                                                      "%" PRIu32 "\n",
                                           
                                           colors_array_itself[current_index + 0],
                                           
                                           colors_array_itself[current_index + 1],
                                           
                                           colors_array_itself[current_index + 2],
                                           
                                           colors_array_itself[current_index + 3],
                                           
                                           colors_array_itself[current_index + 4],
                                           
                                           colors_array_itself[current_index + 5],
                                           
                                           colors_array_itself[current_index + 6],
                                           
                                           colors_array_itself[current_index + 7]);
                    
                    if (status_of_sorts < 8) {
                        
                        exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                        
                    }
                    else {
                        
                        current_index += 8;
                        
                    }
                    
                }
                
                if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
                    
                    left_off = current_index;
                    
                }
                
            }
            
            
        }
        
    }
    
    /* Step is write the colors, the tail of it. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            FILE  * file_g = NULL;
            
            uint32_t  * colors_array_itself = 0;
            
            size_t  colors_array_its_size = 0;
            
            size_t  current_index = 0;
            
            int  status_of_sorts = 0;
            
            file_g = program_state_itself->field__output_file_itself;  /* Drip. */
            
            colors_array_itself = program_state_itself->field__colors_array_itself;  /* Drip. */
            
            colors_array_its_size = program_state_itself->field__colors_array_its_size;  /* Drip. */
            
            current_index = left_off;
            
            while ( (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) &&
                    
                    (current_index < colors_array_its_size) )  {
                
                status_of_sorts = fprintf(file_g, "%" PRIu32 "\n", colors_array_itself[current_index]);
                
                if (status_of_sorts < 2) {
                    
                    exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                    
                }
                else {
                    
                    current_index += 1;
                    
                }
                
            }
            
        }
        
    }
    
    /* Step is pass the torch. */ {
        
        return exit_status_itself;
        
    }
    
}

int release_resources_down_back (struct program_state_its_definition  * program_state_itself) {
    
    /* Step is introduce the locals. */ {
        
        BRACKETS_CLOSE
        
        int  exit_status_itself = 0;
        
        exit_status_itself = EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE;
        
        BRACKETS_OPEN
        
    }
    
    /* Step is free the colors array itself. */ {
        
        free(program_state_itself->field__colors_array_itself);
        
        program_state_itself->field__colors_array_itself = NULL;
        
        program_state_itself->field__colors_array_its_size = 0;
        
    }
    
    /* Step is free the heap array itself. */ {
        
        free(program_state_itself->field__heap_array_itself);
        
        program_state_itself->field__heap_array_itself = NULL;
        
        program_state_itself->field__heap_array_its_size = 0;
        
    }
    
    /* Step is free the sorted array itself. */ {
        
        free(program_state_itself->field__sorted_array_itself);
        
        program_state_itself->field__sorted_array_itself = NULL;
        
        program_state_itself->field__sorted_array_its_size = 0;
        
    }
    
    /* Step is free the offset array itself. */ {
        
        free(program_state_itself->field__offset_array_itself);
        
        program_state_itself->field__offset_array_itself = NULL;
        
        program_state_itself->field__offset_array_its_size = 0;
        
    }
    
    /* Step is free the operations array itself. */ {
        
        free(program_state_itself->field__operations_array_itself);
        
        program_state_itself->field__operations_array_itself = NULL;
        
        program_state_itself->field__operations_array_its_size = 0;
        
    }
    
    /* Step is free the output file itself. */ {
        
        int  status_of_sorts = 0;
        
        status_of_sorts = fclose(program_state_itself->field__output_file_itself);
        
        program_state_itself->field__output_file_itself = NULL;
        
        if (0 != status_of_sorts) {
            
            if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                
            }
            
        }
        
    }
    
    /* Step is free the input file itself. */ {
        
        int  status_of_sorts = 0;
        
        status_of_sorts = fclose(program_state_itself->field__input_file_itself);
        
        program_state_itself->field__input_file_itself = NULL;
        
        if (0 != status_of_sorts) {
            
            if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
                
                exit_status_itself = EXIT_STATUS__NAY_FAILURE__RESOURCES_RELATED;
                
            }
            
        }
        
    }
    
    /* Step is free the program state itself. */ {
        
        free(program_state_itself);
        
        program_state_itself = NULL;
        
    }
    
    /* Step is pass the torch. */ {
        
        return exit_status_itself;
        
    }
    
}


static int core_routines_close (void) BRACKETS_OPEN
    
    return 0;
    
}

int main (void) {
    
    /* Step is introduce the locals. */ {
        
        BRACKETS_CLOSE
        
        int  exit_status_itself = 0;
        
        struct program_state_its_definition  * program_state_itself = NULL;
        
        exit_status_itself = EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE;
        
        BRACKETS_OPEN
        
    }
    
    /* Step is read the input and acquire all resources, up front. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            struct program_state_its_definition  * pointer_itself = NULL;
            
            int  status_of_sorts = 0;
            
            status_of_sorts = acquire_all_resources_up_front(&pointer_itself);
            
            if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE != status_of_sorts) {
                
                exit_status_itself = status_of_sorts;
                
            }
            else {
                
                /* Publish to the outer scope. */
                
                program_state_itself = pointer_itself;
                
            }
            
        }
        
    }
    
    /* Step is solve the problem, and try not to exceed the time limit. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            int  status_of_sorts = 0;
            
            status_of_sorts = solve_the_problem_already_and_be_quick_about_it(program_state_itself);
            
            if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE != status_of_sorts) {
                
                exit_status_itself = status_of_sorts;
                
            }

        }
        
    }
    
    /* Step is write the answer, eight colors at a time, emphasis on speed. */ {
        
        if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
            
            int  status_of_sorts = 0;
            
            status_of_sorts = write_the_output_eight_or_more_colors_at_a_time(program_state_itself);
            
            if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE != status_of_sorts) {
                
                exit_status_itself = status_of_sorts;
                
            }

        }
        
    }
    
    /* Step is release the resources, down back, if any were acquired, at all. */ {
        
        if (NULL != program_state_itself) {
            
            int  status_of_sorts = 0;
            
            status_of_sorts = release_resources_down_back(program_state_itself);
            
            program_state_itself = NULL;
            
            if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE != status_of_sorts) {
                
                if (EXIT_STATUS__AYE_SUCCESS__ALL_WAS_FINE == exit_status_itself) {
                    
                    exit_status_itself = status_of_sorts;
                    
                }
                
            }
            
        }
        
    }
    
    /* Step is pass the torch. */ {
        
        return exit_status_itself 
                    
                  + headers_open()
                    
                  + headers_close()
                    
                  + exit_statuses_open()
                    
                  + exit_statuses_close()
                    
                  + data_layouts_open()
                    
                  + data_layouts_close()
                    
                  + core_routines_open()
                    
                  + core_routines_close();
        
    }
    
}