title: Terminated due to timeout in hacker rank for large inputs
body: <p>This code shows "Terminated due to timeout" error on some large inputs on Hackerrank but works fine for the rest of the cases. Help me improve this code please.</p>
  
  <p>John Watson performs an operation called a right circular rotation on an array of integers, . After performing one right circular rotation operation, the array is transformed from  to .</p>
  
  <p>Watson performs this operation  times. To test Sherlock's ability to identify the current element at a particular position in the rotated array, Watson asks  queries, where each query consists of a single integer, , for which you must print the element at index  in the rotated array (i.e., the value of ).</p>
  
  <p>Input Format</p>
  
  <p>The first line contains  space-separated integers, , , and , respectively. 
  The second line contains  space-separated integers, where each integer  describes array element  (where ). 
  Each of the  subsequent lines contains a single integer denoting .</p>
  
  <p>Constraints</p>
  
  <p>Output Format</p>
  
  <p>For each query, print the value of the element at index  of the rotated array on a new line.</p>
  
  <p>Sample Input</p>
  
  <p>3 2 3
  1 2 3
  0
  1
  2
  Sample Output</p>
  
  <p>2
  3
  1</p>
  
  <p><strong>MY CODE</strong></p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  import java.text.*;
  import java.math.*;
  import java.util.regex.*;
  
  public class Solution {
  
      public static void main(String[] args) {
          /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
          int n,k,q,temp=0,c=0;
          Scanner sc=new Scanner(System.in);
          try{
          n=sc.nextInt();
          k=sc.nextInt();
          q=sc.nextInt();
          int[] arr=new int[n];
          int qrr[]=new int[q];
          for(int i=0;i&lt;n;i++)
              arr[i]=sc.nextInt();
          while(sc.hasNext()){
              qrr[c++]=sc.nextInt();
          }
          for(int j=1;j&lt;=k;j++){
          temp=arr[n-1];
          for(int i=n-2;i&gt;=0;i--){
              arr[i+1]=arr[i];
          }
          arr[0]=temp;
          }
          for(int i=0;i&lt;q;i++){
              System.out.println(arr[qrr[i]]);
          }
      }
      catch(Exception ae){
          System.out.println(ae.getMessage());
      }
  }
  }
  </code></pre>