title: To find adjacent sides of cube
body: <p>I m trying to do a online problem about finding adjacent sides of a cube .The full question is at <a href="http://www.codechef.com/JULY15/problems/CHCUBE" rel="nofollow">http://www.codechef.com/JULY15/problems/CHCUBE</a>.
  it gives correct answer to me, but when i submit it will get wrong answer.</p>
  
  <p>heres my java code</p>
  
  <pre><code> import java.util.*;
  
   class Cube {
  
       public static void main(String[] args)
           {
           long T;
           int blue = 0,black = 0,red=0,green=0,orange=0,yellow=0;
  
           Scanner input=new Scanner(System.in);
              T=input.nextLong();
              int pos=0,checked=0,answer=0;
           String colors[]=new String[6];
              while(T&gt;0){
  
                  for(int temp=0;temp&lt;6;temp++)
                  {
                  colors[temp]=input.next();
  
                  if(colors[temp].equals("blue"))
                  {
  
                      blue++;
                      if(blue&gt;2)
                          pos=temp;
                  }
                  else if(colors[temp].equals("black"))
                      {black++;
                      if(black&gt;2)
                          pos=temp;
                      }
                  else if(colors[temp].equals("yellow"))
                      {yellow++;
                      if(yellow&gt;2)
                          pos=temp;
                      }
                  else if(colors[temp].equals("orange"))
                      {orange++;
                      if(orange&gt;2)
                          pos=temp;
                  }
                  else if(colors[temp].equals("green"))
                      {green++;
                      if(green&gt;2)
                          pos=temp;
                  }
                  else if(colors[temp].equals("red"))
                      {red++;
                      if(red&gt;2)
                          pos=temp;
                  }
                  }
  
                  if(blue&gt;2||black&gt;2||green&gt;2||yellow&gt;2||red&gt;2||orange&gt;2)
                  {       if(pos%2==0)
                      {
                          checked=(pos+2)%6;
                      }
                      else{
  
  
                          checked=(pos+1)%6;
                      }           
  
  
                      if(colors[pos].equals(colors[checked] )||colors[pos].equals(colors[(checked+1)%6]) )
                      {   
                                      if(colors[pos].equals(colors[(checked+3)%6]) ||colors[pos].equals(colors[(checked+2)%6]) )
                          {
  
                                              answer++;
                          }
  
                      }
  
                      }
                  if(answer==1)
                      System.out.println("YES");
                  else
                      System.out.println("NO");
  
                  T--;
              }
  
  
           }
  
  
  
   }
  </code></pre>