In how many ways can Irena arrange the integers $1$ through $7$ in a line such that for any three consecutive numbers, the largest is not in the rightmost position?

Let's think step by step and output the final answer within \boxed{}.
user