Insert an element in a doubly linked list.
Asked in the round 1 stage. Represent the list as an array of node dictionaries. Each node contains value, prev, and next, where pointers store array indices or null.
Implement insert_element(nodes, head, value, position). Insert the new value before the current element at position; position == 0 inserts at the head, and position == length appends. Return a dictionary containing the updated nodes array and head index. The input list is valid, and position is within [0, length].
def insert_element(nodes, head, value, position):