#
# Queue: FIFO data structure
# 
Q = [None]*100                  
head = 0 
tail = 0

def is_empty ():
    global head, tail
    return head == tail

def is_full ():
    global head, tail
    return (tail + 1) % len(Q) == head

def enqueue (x):
    global head, tail, Q
    new_tail = tail + 1
    if new_tail == len(Q):
        new_tail = 0
    if new_tail == head:
        raise Exception('queue full!')
    Q[tail] = x
    tail = new_tail

def enqueue (x):
    global head, tail, Q
    if is_full():
        raise Exception('queue full!')
    Q[tail] = x
    tail = tail + 1
    if tail == len(Q):
        tail = 0

def dequeue ():
    global head, tail, Q
    if is_empty():
        raise Exception ('queue empty!')
    result = Q[head]
    head = head + 1
    if head == len(Q):
        head = 0
    return result
