Cod sursa(job #3138856)

Utilizator mgntMarius B mgnt Data 22 iunie 2023 22:20:03
Problema Order Scor 100
Compilator c-64 Status done
Runda Arhiva de probleme Marime 197.39 kb
                                                                                                                                                                                
#define ORDER_PROGRAM__MACRO__FOLD_SCOPE                                                                                                                                        
                                                                                                                                                                                
#if defined(ORDER_PROGRAM__MACRO__FOLD_SCOPE)  /*  Folding, first!       */                                                                                                     
                                                                                                                                                                                
                                                                                                                                                                                
#define  ORDER_PROGRAM__MACRO__FOLDING__BLOCK_BRACKETS_OPEN     {                                                                                                               
#define  ORDER_PROGRAM__MACRO__FOLDING__BLOCK_BRACKETS_CLOSE    }                                                                                                               
                                                                                                                                                                                
#define  ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_OPEN    ORDER_PROGRAM__MACRO__FOLDING__BLOCK_BRACKETS_CLOSE                                                     
#define  ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_CLOSE   ORDER_PROGRAM__MACRO__FOLDING__BLOCK_BRACKETS_OPEN                                                      
                                                                                                                                                                                
                                                                                                                                                                                
#endif                                                                                                                                                                          
#if defined(ORDER_PROGRAM__MACRO__FOLD_SCOPE)  /*  Headers, first!       */                                                                                                     
                                                                                                                                                                                
                                                                                                                                                                                
#include <stdlib.h>                                                                                                                                                             
#include <stdio.h>                                                                                                                                                              
#include <stddef.h>                                                                                                                                                             
#include <stdint.h>                                                                                                                                                             
#include <stdbool.h>                                                                                                                                                            
#include <inttypes.h>                                                                                                                                                           
#include <string.h>                                                                                                                                                             
                                                                                                                                                                                
                                                                                                                                                                                
#endif                                                                                                                                                                          
#if defined(ORDER_PROGRAM__MACRO__FOLD_SCOPE)  /*  Exit status, first!   */                                                                                                     
                                                                                                                                                                                
                                                                                                                                                                                
#define  ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY     0                                                                                                       
#define  ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__INPUT_FILE         1                                                                                                       
#define  ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__INVALID_INPUT      2                                                                                                       
#define  ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__OUT_OF_MEMORY      3                                                                                                       
#define  ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__OUTPUT_FILE        4                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
#endif                                                                                                                                                                          
#if defined(ORDER_PROGRAM__MACRO__FOLD_SCOPE)  /*  Data layout, first!   */                                                                                                     
                                                                                                                                                                                
                                                                                                                                                                                
#define  ORDER_PROGRAM__MACRO__CONSTANTS__MAX_NUMBER_OF_NODES  30000   /*  max N        */                                                                                      
                                                                                                                                                                                
#define  ORDER_PROGRAM__MACRO__CONSTANTS__MAX_NUMBER_OF_BLOCKS   174   /*  ⌈√{max N}⌉   */                                                                                      
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
struct OrderProgramProblemInstanceData {                                                                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
    size_t   order_program__data__instance__number_of_nodes;                                                                                                                    
                                                                                                                                                                                
            /*                                                                                                                                                                  
             *  This one, number_of_nodes, is the  n  from next block comments.                                                                                                 
             */                                                                                                                                                                 
                                                                                                                                                                                
                                                                                                                                                                                
    size_t   order_program__data__instance__block_size;                                                                                                                         
                                                                                                                                                                                
            /*                                                                                                                                                                  
             *  block_size is  ⌈√n⌉, i.e. ceiling(sqrt(n)).                                                                                                                     
             *                                                                                                                                                                  
             *  This is the block size in the square root decomposition.                                                                                                        
             */                                                                                                                                                                 
                                                                                                                                                                                
                                                                                                                                                                                
    size_t   order_program__data__instance__number_of_blocks;                                                                                                                   
                                                                                                                                                                                
            /*                                                                                                                                                                  
             *  number_of_blocks  is  ⌈n / block_size⌉ = ⌈n / ⌈√n⌉⌉, i.e. ceiling(n / ceiling(sqrt(n))).                                                                        
             *                                                                                                                                                                  
             *  This is how many blocks we have in the square root decomposition of the sequence of nodes.                                                                      
             */                                                                                                                                                                 
                                                                                                                                                                                
                                                                                                                                                                                
    uint8_t  order_program__data__instance__eliminated[ORDER_PROGRAM__MACRO__CONSTANTS__MAX_NUMBER_OF_NODES];                                                                   
                                                                                                                                                                                
            /*                                                                                                                                                                  
             *  For node  j ← 0 … number_of_nodes − 1, maintain the invariant that                                                                                              
             *                                                                                                                                                                  
             *      eliminated[j] ∈ {0} ⇔ node j  was not eliminated, until the current step, from the circular list.                                                           
             */                                                                                                                                                                 
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
    size_t   order_program__data__instance__block_set_size[ORDER_PROGRAM__MACRO__CONSTANTS__MAX_NUMBER_OF_BLOCKS];                                                              
                                                                                                                                                                                
            /*                                                                                                                                                                  
             *  block_set_size[s] ⇔ the number of nodes j in the  s -th block, currently not eliminated, equivalently                                                           
             *                                                                                                                                                                  
             *                      the number of nodes j,  j ∈ ℤ,  s·⌈√n⌉ ≤ j ≤ min {(s + 1)·⌈√n⌉, n} − 1,  currently not eliminated.                                          
             *                                                                                                                                                                  
             *  s ∈ ℤ, 0 ≤ s ≤ ⌈√n⌉ − 1.                                                                                                                                        
             */                                                                                                                                                                 
                                                                                                                                                                                
                                                                                                                                                                                
    size_t   order_program__data__instance__elimination_sequence[ORDER_PROGRAM__MACRO__CONSTANTS__MAX_NUMBER_OF_NODES];                                                         
                                                                                                                                                                                
};                                                                                                                                                                              
                                                                                                                                                                                
typedef  struct OrderProgramProblemInstanceData                                                                                                                                 
                OrderProgramProblemInstanceData;                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
#endif                                                                                                                                                                          
#if defined(ORDER_PROGRAM__MACRO__FOLD_SCOPE)  /*  Coding, first!        */                                                                                                     
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
static  size_t order_program__code__floor_sqrt(size_t  n) {                                                                                                                     
                                                                                                                                                                                
    /*  Given a  size_t,  nonnegative integer  n, it computes and it returns ⌊√n⌋ as a size_t value  */                                                                         
                                                                                                                                                                                
    size_t  result = n;                                                                                                                                                         
                                                                                                                                                                                
    if (n == 0) {                                                                                                                                                               
                                                                                                                                                                                
        result = 0;                                                                                                                                                             
    }                                                                                                                                                                           
    else {                                                                                                                                                                      
                                                                                                                                                                                
        size_t  p = 1;                                                                                                                                                          
                                                                                                                                                                                
        size_t  s = 0;                                                                                                                                                          
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Compute  p = 2ᵏ  so that  p² ≤ n < (2·p)².  */  {                                                                                                                   
                                                                                                                                                                                
            size_t  q = p + p;                                                                                                                                                  
                                                                                                                                                                                
            while (((q * q) <= n) && ((q * q) != 0)) {                                                                                                                          
                                                                                                                                                                                
                p = q;                                                                                                                                                          
                                                                                                                                                                                
                q = p + p;                                                                                                                                                      
            }                                                                                                                                                                   
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Determine  s ∈ ℤ  so that  1 ≤ s  and  s² ≤ n < (s + 1)².  */  {                                                                                                    
                                                                                                                                                                                
            size_t  z = 0;                                                                                                                                                      
                                                                                                                                                                                
            while (0 < p) {                                                                                                                                                     
                                                                                                                                                                                
                z = s + p;                                                                                                                                                      
                                                                                                                                                                                
                if ((z * z) <= n) {                                                                                                                                             
                                                                                                                                                                                
                    s = z;                                                                                                                                                      
                }                                                                                                                                                               
                                                                                                                                                                                
                p >>= 1;                                                                                                                                                        
            }                                                                                                                                                                   
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        result = s;                                                                                                                                                             
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
  return result;                                                                                                                                                                
}                                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
static  size_t order_program__code__ceiling_sqrt (size_t  n) {                                                                                                                  
                                                                                                                                                                                
  /*  Given a  size_t,  nonnegative integer  n, it computes and it returns ⌈√n⌉, as a size_t value.  */                                                                         
                                                                                                                                                                                
  size_t  const floor__square_root   = order_program__code__floor_sqrt(n);                                                                                                      
                                                                                                                                                                                
  size_t  const ceiling__square_root = (((floor__square_root * floor__square_root) == n) ? floor__square_root : (1 + floor__square_root));                                      
                                                                                                                                                                                
  return ceiling__square_root;                                                                                                                                                  
                                                                                                                                                                                
}                                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
static void  order_program__code__make_preparations (OrderProgramProblemInstanceData  * order_program__problem_instance_data) {                                                 
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  initialize the square root decomposition, step 1, for each block, the initial number of elements it contains.  */  {                                           
                                                                                                                                                                                
        size_t  const number_of_nodes = order_program__problem_instance_data->order_program__data__instance__number_of_nodes;                                                   
                                                                                                                                                                                
        size_t  * const block_set_size = order_program__problem_instance_data->order_program__data__instance__block_set_size;                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        size_t  const block_size = order_program__code__ceiling_sqrt(number_of_nodes);                                                                                          
                                                                                                                                                                                
        size_t  block_index = 0;                                                                                                                                                
                                                                                                                                                                                
        size_t  block_base = 0;                                                                                                                                                 
                                                                                                                                                                                
                                                                                                                                                                                
        while ((number_of_nodes - block_base) >= block_size) {                                                                                                                  
                                                                                                                                                                                
            block_set_size[block_index] = block_size;                                                                                                                           
                                                                                                                                                                                
            block_index += 1;                                                                                                                                                   
                                                                                                                                                                                
            block_base += block_size;                                                                                                                                           
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        if (number_of_nodes > block_base) {                                                                                                                                     
                                                                                                                                                                                
            block_set_size[block_index] = (number_of_nodes - block_base);                                                                                                       
                                                                                                                                                                                
            block_index += 1;                                                                                                                                                   
                                                                                                                                                                                
            block_base = number_of_nodes;                                                                                                                                       
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        order_program__problem_instance_data->order_program__data__instance__number_of_blocks = block_index;                                                                    
                                                                                                                                                                                
        order_program__problem_instance_data->order_program__data__instance__block_size = block_size;                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  initialize the square root decomposition, step 2, globally for all blocks, mark in a bitset each element is in a block.  */  {                                 
                                                                                                                                                                                
                                                                                                                                                                                
        size_t  const number_of_nodes = order_program__problem_instance_data->order_program__data__instance__number_of_nodes;                                                   
                                                                                                                                                                                
        uint8_t *  const eliminated  = order_program__problem_instance_data->order_program__data__instance__eliminated;                                                         
                                                                                                                                                                                
        size_t  j = 0;                                                                                                                                                          
                                                                                                                                                                                
                                                                                                                                                                                
        j = 0;                                                                                                                                                                  
                                                                                                                                                                                
        while (j < number_of_nodes) {                                                                                                                                           
                                                                                                                                                                                
            eliminated[j] = 0;                                                                                                                                                  
                                                                                                                                                                                
            j += 1;                                                                                                                                                             
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
}                                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
static void  order_program__code__solve_current_round (OrderProgramProblemInstanceData  * order_program__problem_instance_data,                                                 
                                                                                                                                                                                
                                                       size_t  number_of_edges_in_the_circular_list,                                                                            
                                                                                                                                                                                
                                                       size_t  active_node,  size_t  number_of_edges,                                                                           
                                                                                                                                                                                
                                                       size_t  * eliminated_node, size_t  * next_active_node) {                                                                 
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  describe in a few words, what the function does.  */  {                                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
        ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_OPEN                                                                                                             
                                                                                                                                                                                
                                                                                                                                                                                
        /*                                                                                                                                                                      
         *  This function is all about walking the edges of the remaining circular list, moving from the current node, a given number of edges,                                 
         *                                                                                                                                                                      
         *  reaching a node  x  that it will eliminate, moving, before eliminating x from the circular list, to node y, the next current node.                                  
         *                                                                                                                                                                      
         *                                                                                                                                                                      
         *                                                                                                                                                                      
         *  This circular list is always traversed left to right.                                                                                                               
         *                                                                                                                                                                      
         *  It initially contains the nodes j, j starting from 0, ending at n − 1, step 1.                                                                                      
         *                                                                                                                                                                      
         *  Say node  j  is  at  distance  j,  from  0,  on the x axis,  thus, visually,  node  j − 1  is  node j’s  left neighbour,                                            
         *                                                                                                                                                                      
         *  node  j  is  node  j − 1’s right neighbour.                                                                                                                         
         *                                                                                                                                                                      
         *  Conventionally, say  node  n − 1  is the left neighbour of node 0,  and  node  0  is  the right neighbour of node  n  −  1.                                         
         *                                                                                                                                                                      
         *  All this talk just to say what moving left to right can be described with words.                                                                                    
         *                                                                                                                                                                      
         *  If  x  is said to be the current node, and  y is the right neighbour of node x,  then                                                                               
         *                                                                                                                                                                      
         *  moving right one edge  could be just to  switch to saying that  y is the current node,                                                                              
         *                                                                                                                                                                      
         *  x  no longer being said to be the current node, but y in its stead.                                                                                                 
         *                                                                                                                                                                      
         *                                                                                                                                                                      
         *                                                                                                                                                                      
         *  When  node  q, having  node  p  as its left neighbour  and  node  r  as its right neighbour, is removed,,                                                           
         *                                                                                                                                                                      
         *  the right neighbour of node  p  changes  from node  q,  to node r,  and                                                                                             
         *                                                                                                                                                                      
         *  the left  neighbour of node  r  changes  from node  q,  to node p,  the well known properties of circular lists.                                                    
         *                                                                                                                                                                      
         *                                                                                                                                                                      
         *                                                                                                                                                                      
         *  So this function does not actually uses the classical circular list implementation, but uses the block decomposition of indicator function,                         
         *                                                                                                                                                                      
         *  initially  bitset[j] = c,  c any constant ≠ 0,  encoding that  j  was not yet eliminated,  and the plan is to mark the eliminated nodes                             
         *                                                                                                                                                                      
         *  in this “bitset”, with  bitset[j] := 0,  and to keep  cardinal[b] := ♯ of nodes j not yet eliminated,  b·⌈√n⌉ ≤ j ≤ min {(b + 1)·⌈√n⌉, n} − 1,                      
         *                                                                                                                                                                      
         *  maintaining these 2 arrays, the “bitset”,  and  the  “cardinal”,  is to give  O(n·√n) execution time!                                                               
         */                                                                                                                                                                     
                                                                                                                                                                                
                                                                                                                                                                                
        ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_CLOSE                                                                                                            
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  define and O(1) initialize a handful of variables local to the current scope.  */  {                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
        ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_OPEN                                                                                                             
                                                                                                                                                                                
                                                                                                                                                                                
        size_t  number_of_remaining_edges = 0;                                                                                                                                  
                                                                                                                                                                                
        size_t  the_one_just_eliminated = 0;                                                                                                                                    
                                                                                                                                                                                
        size_t  the_next_active_node = 0;                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_CLOSE                                                                                                            
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  reduce the number of edges to move around, by shortcutting returning to the starting node, in the circular list.  */  {                                        
                                                                                                                                                                                
                                                                                                                                                                                
        number_of_remaining_edges = (number_of_edges % number_of_edges_in_the_circular_list);                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  traverse quickly the circular list, no wrap arounds, by using the square root decomposition, to reach the node to eliminate.  */  {                            
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  define and O(1) initialize a handful of variables local to the current scope.  */  {                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
            ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_OPEN                                                                                                         
                                                                                                                                                                                
                                                                                                                                                                                
            size_t  const number_of_nodes = order_program__problem_instance_data->order_program__data__instance__number_of_nodes;                                               
                                                                                                                                                                                
            size_t  const block_size = order_program__problem_instance_data->order_program__data__instance__block_size;                                                         
                                                                                                                                                                                
            size_t  const number_of_blocks = order_program__problem_instance_data->order_program__data__instance__number_of_blocks;                                             
                                                                                                                                                                                
            size_t const  * const block_set_size = order_program__problem_instance_data->order_program__data__instance__block_set_size;                                         
                                                                                                                                                                                
            uint8_t const  * const eliminated = order_program__problem_instance_data->order_program__data__instance__eliminated;                                                
                                                                                                                                                                                
                                                                                                                                                                                
            size_t  the_node_to_eliminate_itself_finally = 0;                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
            ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_CLOSE                                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  if no edge traversal is necessary, modulo the number of current edges, keep the current active node.  */  {                                                
                                                                                                                                                                                
                                                                                                                                                                                
            if (0 == number_of_remaining_edges) {                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
                the_node_to_eliminate_itself_finally = active_node;                                                                                                             
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  traverse the nodes after the current node, in the block containing the current node.  */  {                                                                
                                                                                                                                                                                
                                                                                                                                                                                
            if (0 < number_of_remaining_edges) {                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
                size_t  const active_block = (active_node / block_size);                                                                                                        
                                                                                                                                                                                
                size_t  const one_past_the_last = (((number_of_blocks - 1) == active_block) ? number_of_nodes : ((active_block + 1) * block_size));                             
                                                                                                                                                                                
                        /*                                                                                                                                                      
                         *  This one_past_the_last is to be the  1 +  the largest  j,  with  j  any node  in  current_node ’s block.                                            
                         */                                                                                                                                                     
                                                                                                                                                                                
                                                                                                                                                                                
                if (active_node < (one_past_the_last - 1)) {                                                                                                                    
                                                                                                                                                                                
                                                                                                                                                                                
                    size_t  current_node = 1 + active_node;                                                                                                                     
                                                                                                                                                                                
                    while ((0 < number_of_remaining_edges) && (current_node < one_past_the_last)) {                                                                             
                                                                                                                                                                                
                        if (0 == eliminated[current_node]) {                                                                                                                    
                                                                                                                                                                                
                            number_of_remaining_edges -= 1;                                                                                                                     
                        }                                                                                                                                                       
                                                                                                                                                                                
                        if (0 < number_of_remaining_edges) {                                                                                                                    
                                                                                                                                                                                
                            current_node += 1;                                                                                                                                  
                        }                                                                                                                                                       
                                                                                                                                                                                
                    }                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
                    if (0 == number_of_remaining_edges) {                                                                                                                       
                                                                                                                                                                                
                        the_node_to_eliminate_itself_finally = current_node;                                                                                                    
                    }                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
                }                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  traverse remaining circular list edges, if any, from the last current node, in the same direction.  */  {                                                  
                                                                                                                                                                                
                                                                                                                                                                                
            if (0 < number_of_remaining_edges) {                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
                size_t  const active_block = (active_node / block_size);                                                                                                        
                                                                                                                                                                                
                size_t  current_block = ((1 + active_block) % number_of_blocks);                                                                                                
                                                                                                                                                                                
                size_t  current_node = 0;                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
                while (block_set_size[current_block] < number_of_remaining_edges) {                                                                                             
                                                                                                                                                                                
                    number_of_remaining_edges -= block_set_size[current_block];                                                                                                 
                                                                                                                                                                                
                    current_block = ((1 + current_block) % number_of_blocks);                                                                                                   
                }                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
                current_node = (current_block * block_size);                                                                                                                    
                                                                                                                                                                                
                while (0 < number_of_remaining_edges) {                                                                                                                         
                                                                                                                                                                                
                                                                                                                                                                                
                    if (0 == eliminated[current_node]) {                                                                                                                        
                                                                                                                                                                                
                        number_of_remaining_edges -= 1;                                                                                                                         
                    }                                                                                                                                                           
                                                                                                                                                                                
                    if (0 < number_of_remaining_edges) {                                                                                                                        
                                                                                                                                                                                
                        current_node += 1;                                                                                                                                      
                    }                                                                                                                                                           
                                                                                                                                                                                
                }                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
                the_node_to_eliminate_itself_finally = current_node;                                                                                                            
                                                                                                                                                                                
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  eliminate the current node, just reached, from the circular list, and put aside its value, to publish at a later time, to the caler routine.  */  {        
                                                                                                                                                                                
            order_program__problem_instance_data->order_program__data__instance__eliminated[the_node_to_eliminate_itself_finally] = 1;                                          
                                                                                                                                                                                
            order_program__problem_instance_data->order_program__data__instance__block_set_size[the_node_to_eliminate_itself_finally / block_size] -= 1;                        
                                                                                                                                                                                
            the_one_just_eliminated = the_node_to_eliminate_itself_finally;                                                                                                     
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  traverse quickly the circular list, by using the square root decomposition, to reach the node to count next.  */  {                                            
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  define and O(1) initialize a handful of variables local to the current scope.  */  {                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
            ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_OPEN                                                                                                         
                                                                                                                                                                                
            size_t  const number_of_nodes = order_program__problem_instance_data->order_program__data__instance__number_of_nodes;                                               
                                                                                                                                                                                
            size_t  const block_size = order_program__problem_instance_data->order_program__data__instance__block_size;                                                         
                                                                                                                                                                                
            size_t  const number_of_blocks = order_program__problem_instance_data->order_program__data__instance__number_of_blocks;                                             
                                                                                                                                                                                
            size_t const  * block_set_size = order_program__problem_instance_data->order_program__data__instance__block_set_size;                                               
                                                                                                                                                                                
            uint8_t const  * eliminated = order_program__problem_instance_data->order_program__data__instance__eliminated;                                                      
                                                                                                                                                                                
            size_t  the_local_copy_of_the_next_active_node = 0;                                                                                                                 
                                                                                                                                                                                
            ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_CLOSE                                                                                                        
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  continue one more edge, same direction, in the active block, if it is the case.  */  {                                                                     
                                                                                                                                                                                
                                                                                                                                                                                
            size_t  const shrinked_block = the_one_just_eliminated / block_size;                                                                                                
                                                                                                                                                                                
            size_t  current_node = ((the_one_just_eliminated + 1) % number_of_nodes);                                                                                           
                                                                                                                                                                                
            size_t  current_block = current_node / block_size;                                                                                                                  
                                                                                                                                                                                
            size_t  solution_node = number_of_nodes;  /*  number_of_nodes, to encode that the node is not yet known or found.  */                                               
                                                                                                                                                                                
                                                                                                                                                                                
            if (shrinked_block == current_block) {                                                                                                                              
                                                                                                                                                                                
                size_t  const one_past_the_last = ((current_block == (number_of_blocks - 1)) ? number_of_nodes : ((current_block + 1) * block_size));                           
                                                                                                                                                                                
                while ((current_node < one_past_the_last) && (0 != eliminated[current_node])) {                                                                                 
                                                                                                                                                                                
                    current_node += 1;                                                                                                                                          
                }                                                                                                                                                               
                                                                                                                                                                                
                if (one_past_the_last > current_node) {                                                                                                                         
                                                                                                                                                                                
                    solution_node = current_node;                                                                                                                               
                }                                                                                                                                                               
                else {                                                                                                                                                          
                                                                                                                                                                                
                    current_block = ((current_block + 1) % number_of_blocks);                                                                                                   
                }                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
            if (number_of_nodes == solution_node) {                                                                                                                             
                                                                                                                                                                                
                while (0 == block_set_size[current_block]) {                                                                                                                    
                                                                                                                                                                                
                    current_block = ((1 + current_block) % number_of_blocks);                                                                                                   
                }                                                                                                                                                               
                                                                                                                                                                                
                current_node = (current_block * block_size);                                                                                                                    
                                                                                                                                                                                
                while (0 != eliminated[current_node]) {                                                                                                                         
                                                                                                                                                                                
                    current_node += 1;                                                                                                                                          
                }                                                                                                                                                               
                                                                                                                                                                                
                solution_node = current_node;                                                                                                                                   
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
            the_local_copy_of_the_next_active_node = solution_node;                                                                                                             
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  put aside, or publish to the outer scope, the just found value, the next active node.  */  {                                                               
                                                                                                                                                                                
            the_next_active_node = the_local_copy_of_the_next_active_node;                                                                                                      
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  return the out values, all, at once, in one fell swoop.  */  {                                                                                                 
                                                                                                                                                                                
        *eliminated_node = the_one_just_eliminated;                                                                                                                             
                                                                                                                                                                                
        *next_active_node = the_next_active_node;                                                                                                                               
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
}                                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
static int  order_program__code__read_input (OrderProgramProblemInstanceData  *  * order_program__problem_instance_data) {                                                      
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  define and O(1) initialize a handful of variables local to the current scope.  */  {                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
        ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_OPEN                                                                                                             
                                                                                                                                                                                
                                                                                                                                                                                
        int  exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY;                                                                                          
                                                                                                                                                                                
        OrderProgramProblemInstanceData  * instance_data = NULL;                                                                                                                
                                                                                                                                                                                
        FILE  * input_file = NULL;                                                                                                                                              
                                                                                                                                                                                
                                                                                                                                                                                
        ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_CLOSE                                                                                                            
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  allocate the memory for the worst possible case.  */  {                                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
        if (ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) {                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
            instance_data = malloc(sizeof(OrderProgramProblemInstanceData));                                                                                                    
                                                                                                                                                                                
            if (NULL == instance_data) {                                                                                                                                        
                                                                                                                                                                                
                exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__OUT_OF_MEMORY;                                                                                        
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  open the input file.  */  {                                                                                                                                    
                                                                                                                                                                                
                                                                                                                                                                                
        if (ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) {                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
            input_file = fopen("order.in", "r");                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
            if (NULL == input_file) {                                                                                                                                           
                                                                                                                                                                                
                exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__INPUT_FILE;                                                                                           
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  scan the integer  n.  */  {                                                                                                                                    
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  define and O(1) initialize a handful of variables local to the current scope.  */  {                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
            ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_OPEN                                                                                                         
                                                                                                                                                                                
                                                                                                                                                                                
            size_t  n = 0;                                                                                                                                                      
                                                                                                                                                                                
                                                                                                                                                                                
            ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_CLOSE                                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  scanf  the integer  n,  from the input file.  */  {                                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
            if (ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) {                                                                                    
                                                                                                                                                                                
                                                                                                                                                                                
                size_t  f_code = 0;                                                                                                                                             
                                                                                                                                                                                
                f_code = fscanf(input_file, "%zu", &n);                                                                                                                         
                                                                                                                                                                                
                if (1 != f_code) {                                                                                                                                              
                                                                                                                                                                                
                    exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__INPUT_FILE;                                                                                       
                                                                                                                                                                                
                }                                                                                                                                                               
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  validate than n is properly constrained, precisely as is promised in the problem statement.  */  {                                                         
                                                                                                                                                                                
                                                                                                                                                                                
            if (ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) {                                                                                    
                                                                                                                                                                                
                                                                                                                                                                                
                if ((2 > n) || (30000 < n)) {                                                                                                                                   
                                                                                                                                                                                
                    exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__INVALID_INPUT;                                                                                    
                }                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  publish the integer n, provided there was no error reading from the input file, and the value is valid.  */  {                                             
                                                                                                                                                                                
                                                                                                                                                                                
            if (ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) {                                                                                    
                                                                                                                                                                                
                instance_data->order_program__data__instance__number_of_nodes = n;                                                                                              
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  perform cleanup, closing the input file.  */  {                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
        if (NULL != input_file) {                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
            int  c_code = 0;                                                                                                                                                    
                                                                                                                                                                                
                                                                                                                                                                                
            c_code = fclose(input_file);                                                                                                                                        
                                                                                                                                                                                
            input_file = NULL;                                                                                                                                                  
                                                                                                                                                                                
                                                                                                                                                                                
            if ((ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) && (0 != c_code)) {                                                                 
                                                                                                                                                                                
                exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__INPUT_FILE;                                                                                           
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  publish the instance data, if all was aokay.  */  {                                                                                                            
                                                                                                                                                                                
                                                                                                                                                                                
        if (ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) {                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
            *order_program__problem_instance_data = instance_data;                                                                                                              
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  return the exit status, to the outside world.  */  {                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
        return exit_status;                                                                                                                                                     
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
}                                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
static  void order_program__code__solve (OrderProgramProblemInstanceData  * order_program__problem_instance_data) {                                                             
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  prepare for solving all the steps, one by one, the square root decomposition preprocessing, O(n) time.  */  {                                                  
                                                                                                                                                                                
                                                                                                                                                                                
        order_program__code__make_preparations(order_program__problem_instance_data);                                                                                           
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  evaluate the eliminations, O(√n) time units per elimination, thus O(n·√n) time, in total.  */  {                                                               
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  define and O(1) initialize a handful of variables local to the current block.  */  {                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
            ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_OPEN                                                                                                         
                                                                                                                                                                                
                                                                                                                                                                                
            size_t  const number_of_nodes = order_program__problem_instance_data->order_program__data__instance__number_of_nodes;                                               
                                                                                                                                                                                
            size_t  * const elimination_order = order_program__problem_instance_data->order_program__data__instance__elimination_sequence;                                      
                                                                                                                                                                                
            size_t  active_node = 0;                                                                                                                                            
                                                                                                                                                                                
            size_t  number_of_edges_to_traverse = 0;                                                                                                                            
                                                                                                                                                                                
            size_t  number_of_nodes_currently_in_the_circular_list = number_of_nodes;                                                                                           
                                                                                                                                                                                
            size_t  eliminated_node = 0;                                                                                                                                        
                                                                                                                                                                                
            size_t  j = 0;                                                                                                                                                      
                                                                                                                                                                                
            size_t  one_minus = 0;                                                                                                                                              
                                                                                                                                                                                
                                                                                                                                                                                
            ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_CLOSE                                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        /*  Step is  eliminate, eliminate, eliminate, eliminate, and  eliminate some more.  */  {                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
            while (1 < number_of_nodes_currently_in_the_circular_list) {                                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
                number_of_edges_to_traverse = j + 1 + one_minus;                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
                order_program__code__solve_current_round(order_program__problem_instance_data, number_of_nodes_currently_in_the_circular_list,                                  
                                                                                                                                                                                
                                                         active_node, number_of_edges_to_traverse, &eliminated_node, &active_node);                                             
                                                                                                                                                                                
                                                                                                                                                                                
                elimination_order[j] = eliminated_node;                                                                                                                         
                                                                                                                                                                                
                number_of_nodes_currently_in_the_circular_list -= 1;                                                                                                            
                                                                                                                                                                                
                one_minus = -1;                                                                                                                                                 
                                                                                                                                                                                
                j += 1;                                                                                                                                                         
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
            elimination_order[j] = active_node;                                                                                                                                 
                                                                                                                                                                                
            j += 1;   /*  and  j  has just became equal to number_of_nodes  */                                                                                                  
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
}                                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
static  int order_program__code__write_answer (OrderProgramProblemInstanceData  * order_program__problem_instance_data) {                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  define and O(1) initialize a handful of variables local to the current block.  */  {                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
        ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_OPEN                                                                                                             
                                                                                                                                                                                
                                                                                                                                                                                
        int  exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY;                                                                                          
                                                                                                                                                                                
        FILE  * output_file = NULL;                                                                                                                                             
                                                                                                                                                                                
                                                                                                                                                                                
        ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_CLOSE                                                                                                            
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  open the output file, or, more precisely, create this file.  */  {                                                                                             
                                                                                                                                                                                
                                                                                                                                                                                
        if (ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) {                                                                                        
                                                                                                                                                                                
            output_file = fopen("order.out", "w");                                                                                                                              
                                                                                                                                                                                
            if (NULL == output_file) {                                                                                                                                          
                                                                                                                                                                                
                exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__OUTPUT_FILE;                                                                                          
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  write the elimination order, out into the output file.  */  {                                                                                                  
                                                                                                                                                                                
                                                                                                                                                                                
        if (ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) {                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
            size_t const  * const elimination_order = order_program__problem_instance_data->order_program__data__instance__elimination_sequence;                                
                                                                                                                                                                                
            size_t  const n = order_program__problem_instance_data->order_program__data__instance__number_of_nodes;                                                             
                                                                                                                                                                                
            size_t  j = 0;                                                                                                                                                      
                                                                                                                                                                                
            size_t  x = 0;                                                                                                                                                      
                                                                                                                                                                                
            int  p_code = 0;                                                                                                                                                    
                                                                                                                                                                                
                                                                                                                                                                                
            if (0 < n) {                                                                                                                                                        
                                                                                                                                                                                
                x = elimination_order[j];                                                                                                                                       
                                                                                                                                                                                
                p_code = fprintf(output_file, "%zu", (1 + x));                                                                                                                  
                                                                                                                                                                                
                if (0 >= p_code) {                                                                                                                                              
                                                                                                                                                                                
                    exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__OUTPUT_FILE;                                                                                      
                }                                                                                                                                                               
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
            j = 1;                                                                                                                                                              
                                                                                                                                                                                
            while ((ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) && (n > j)) {                                                                    
                                                                                                                                                                                
                x = elimination_order[j];                                                                                                                                       
                                                                                                                                                                                
                p_code = fprintf(output_file, " %zu", (1 + x));                                                                                                                 
                                                                                                                                                                                
                if (0 >= p_code) {                                                                                                                                              
                                                                                                                                                                                
                    exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__OUTPUT_FILE;                                                                                      
                }                                                                                                                                                               
                else {                                                                                                                                                          
                                                                                                                                                                                
                    j += 1;                                                                                                                                                     
                }                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
            if (ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) {                                                                                    
                                                                                                                                                                                
                p_code = fprintf(output_file, "\n");                                                                                                                            
                                                                                                                                                                                
                if (0 >= p_code) {                                                                                                                                              
                                                                                                                                                                                
                    exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__OUTPUT_FILE;                                                                                      
                }                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  close the output file, if opened.  */  {                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        if (NULL != output_file) {                                                                                                                                              
                                                                                                                                                                                
            int  c_code = 0;                                                                                                                                                    
                                                                                                                                                                                
                                                                                                                                                                                
            c_code = fclose(output_file);                                                                                                                                       
                                                                                                                                                                                
            output_file = NULL;                                                                                                                                                 
                                                                                                                                                                                
            if ((ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) && (0 != c_code)) {                                                                 
                                                                                                                                                                                
                exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__FAILURE__OUTPUT_FILE;                                                                                          
                                                                                                                                                                                
            }                                                                                                                                                                   
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  return the much expected exit_status, to the routine caller.  */  {                                                                                            
                                                                                                                                                                                
        return exit_status;                                                                                                                                                     
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
}                                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
static  void order_program__code__cleanup (OrderProgramProblemInstanceData  * order_program__problem_instance_data) {                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    if (NULL != order_program__problem_instance_data) {                                                                                                                         
                                                                                                                                                                                
                                                                                                                                                                                
        free(order_program__problem_instance_data);                                                                                                                             
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
}                                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
static  int order_program__code__demo (void) {                                                                                                                                  
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  define and O(1) initialize a handful of variables local to the current scope.  */  {                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
        ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_OPEN                                                                                                             
                                                                                                                                                                                
                                                                                                                                                                                
        int  exit_status = ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY;                                                                                          
                                                                                                                                                                                
        OrderProgramProblemInstanceData  * order_program__problem_instance_data = NULL;                                                                                         
                                                                                                                                                                                
                                                                                                                                                                                
        ORDER_PROGRAM__MACRO__FOLDING__INVERTED_BLOCK_BRACKETS_CLOSE                                                                                                            
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  read the input data, the problem instance, from the input file, the ./order.in file system file.  */  {                                                        
                                                                                                                                                                                
                                                                                                                                                                                
        if (ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) {                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
            exit_status = order_program__code__read_input(&order_program__problem_instance_data);                                                                               
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  solve the given problem instance.  */  {                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
        if (ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) {                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
            order_program__code__solve(order_program__problem_instance_data);                                                                                                   
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  write the answer, to the output file, if any.  */  {                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
        if (ORDER_PROGRAM__MACRO__EXIT_STATUS__SUCCESS__ALL_HONKY_DORY == exit_status) {                                                                                        
                                                                                                                                                                                
            exit_status = order_program__code__write_answer(order_program__problem_instance_data);                                                                              
                                                                                                                                                                                
                                                                                                                                                                                
        }                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  cleanup all the problem instance, at once, if any.  */  {                                                                                                      
                                                                                                                                                                                
                                                                                                                                                                                
        order_program__code__cleanup(order_program__problem_instance_data);                                                                                                     
                                                                                                                                                                                
        order_program__problem_instance_data = NULL;                                                                                                                            
                                                                                                                                                                                
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
    /*  Step is  return the exit status, to the expecting caller.  */  {                                                                                                        
                                                                                                                                                                                
                                                                                                                                                                                
        return exit_status;                                                                                                                                                     
    }                                                                                                                                                                           
                                                                                                                                                                                
                                                                                                                                                                                
}                                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
int main (void) {                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
    int const exit_status = order_program__code__demo();                                                                                                                        
                                                                                                                                                                                
    return exit_status;                                                                                                                                                         
                                                                                                                                                                                
                                                                                                                                                                                
}                                                                                                                                                                               
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
#endif