title: Finding max of ANDing between two numbers in Python
body: <p>I am a beginner to Python coding. I have two numbers A and B from user.</p>
  
  <p>My problem is to find the <strong>max(P AND Q)</strong> where A &lt;= P &lt; Q &lt;= B</p>
  
  <p>I have two solutions right now for this.</p>
  
  <p><strong>Solution 1</strong> : # ANDing with all combinations, This solution works if combinations are less. For higher values, it throws memory exceeding error.</p>
  
  <pre><code>given = raw_input()
  n= list(map(int,given.split()))
  
  A = n[0]
  B = n[1]
  
  newlist = range(B+1)
  # print newlist
  
  # Finding all combinations
  comb = list(itertools.combinations(newlist,2))
  # print comb
  
  # ANDing 
  l = []
  for i in com:
      x = i[0] &amp; i[1]
      l.append(x)
  # print l
  
  print max(l) 
  </code></pre>
  
  <p><strong>Solution 2</strong>: After observing many input-outputs, when B == Odd, max(value) = B-1 and for B == Even, max(value) = B-2.</p>
  
  <pre><code>given = raw_input()
  n= list(map(int,given.split()))
  
  A = n[0]
  B = n[1]
  if B % 2 == 0:
      print (B - 2)
  else:
      print (B -1)
  </code></pre>
  
  <p>According to the problem statement I am not using any ANDing for Solution 2. Still I am getting correct output.</p>
  
  <p>But I am looking for much easier and Pythonic logic. Is there any other way/logic to solve this?</p>