title: StdIn for Reading Inputs Hacker Rank Challenges
body: <p>One thing that has frustrated me the most from the Hackerrank challenges is the part of reading inputs for the functions through <code>stdin</code>.</p>
  
  <p>Hackerrank inputs generally have a <code>\n</code> delimiter, which is provided through <code>sys.stdin</code>. I want to know an efficient way to read the inputs and split them into a <code>list</code>. An example follows:</p>
  
  <p><strong>Input:</strong></p>
  
  <pre><code>3 2
  1 5 3
  3 1
  5 7
  </code></pre>
  
  <p>I want to read each line into a separate <code>list</code>. Below is my attempt:</p>
  
  <pre><code>import sys
  
  arr = sys.stdin.readlines()[1].split()
  arr = list(map(int, arr))
  
  A = sys.stdin.readlines()[2].split()
  A = set(map(int, A))
  
  B = sys.stdin.readlines()[3].split()
  B = set(map(int, B))
  </code></pre>
  
  <p>I'm getting following error:</p>
  
  <pre><code>A = sys.stdin.readlines()[2].split()
  </code></pre>
  
  <p></p>
  
  <pre><code>IndexError: list index out of range
  </code></pre>
  
  <p>Why <code>IndexError</code> on <code>[2]</code> where as <code>[1]</code> works? Is there a better way to read such <code>stdin</code> inputs using loops?</p>