title: "Time Limit Exceeded" error for python file
body: <p>I have a question about how to improve my simple Python file so that it does not exceed the time limit. My code should run in less than 2 seconds, but it takes a long time. I will be glad to know any advice about it. Code receives (n) as an integer from the user, then in n lines, I have to do the tasks. If the input is &quot;Add&quot; I have to add the given number and then arrange them from smallest to largest. If the input is &quot;Ask&quot;, I have to return the asked index of added numbers.</p>
  <p>This is
  <a href="https://i.stack.imgur.com/YvdZp.png" rel="nofollow noreferrer">an example for inputs and outputs.</a>
  I guess the code works well for other examples, but the only problem is time ...</p>
  <pre><code>n = int(input())
  
  def arrange(x):
      for j in range(len(x)):
          for i in range(len(x) - 1):
              if x[i] &gt; x[i + 1]:
                  x[i], x[i + 1] = x[i + 1], x[i]
  
  tasks=[]
  for i in range(n):
      tasks.append(list(input().split()))
  
  ref = []
  for i in range(n):
      if tasks[i][0] == 'Add':
          ref.append(int(tasks[i][1]))
          arrange(ref)
      elif tasks[i][0] == 'Ask':
          print(ref[int(tasks[i][1]) - 1])
  </code></pre>
  <p>For the given example, I get a &quot;Time Limit Exceeded&quot; Error.</p>