The easiest way to do this in ModelBuilder is to use the Sort tool to sort by CODE and Shape_Area and then write a python function in Calculate Field tool with a code block with a function that assigns values according to your rules as you navigate through the sorted table.
Or, take what I bet is @DanPatterson's advice and do this in Python/numpy in a Calculate Value function that reads the table, sorts it and does your logic.
I do not follow your logic here.