Problem:
 Score : 100 points   Problem Statement  A professor invented Cookie Breeding Machine for his students who like cookies very much.  When one cookie with the taste of x is put into the machine and a non-negative integer y less than or equal to 127 is input on the machine,
        it consumes the cookie and generates two cookies with the taste of y and ( x XOR y ).  Here, XOR represents Bitwise Exclusive OR .  At first, there is only one cookie and the taste of it is D .  Find the maximum value of the sum of the taste of the exactly N cookies generated after the following operation is conducted N-1 times.   Put one of the cookies into the machine.  Input a non-negative integer less than or equal to 127 on the machine.     Constraints   1 \leq T \leq 1000  1 \leq N_t \leq 1000  (1 \leq t \leq T)  1 \leq D_t \leq 127  (1 \leq t \leq T)       Input  The input is given from Standard Input in the following format:   T  N_1  D_1 : N_T  D_T   The input consists of multiple test cases. An Integer T that represents the number of test cases is given on line 1 . Each test case is given on the next T lines. In the t -th test case ( 1 \leq t \leq T ), N_t that represents the number of cookies generated through the operations and D_t that represents the taste of the initial cookie are given separated by space.     Output  For each test case, print the maximum value of the sum of the taste of the N cookies generated through the operations on one line.      Sample Input 1  3
3 1
4 108
1 10    Sample Output 1  255
400
10  On the 1st test case, if the machine is used as follows, three cookies with the taste of 61 , 95 and 99 are generated.
        Since the sum of these values is maximum among all possible ways, the answer is 255 .  Put the cookie with the taste of 1 and input an integer 60 on the machine, lose the cookie and get two cookies with the taste of 60 and 61 .  Put the cookie with the taste of 60 and input an integer 99 on the machine, lose the cookie and get two cookies with the taste of 99 and 95 .    On the 3rd test case, the machine may not be used.

Solution (Python):
N=int(input())
for i in range(N):
    A,B=map(int,input().split())
    if A%2==1:
        ans=B+127*(A-1)
    else:
        ans=127*A-B
    print(ans)

Solution (Python):
N,T=0,0
for i in range(int(input())):
  N,T=map(int,input().split())
  if N&1==0:
    T^=127
  print(T+(N-1)*127)

Solution (Python):
def solve(N,D):
    N-=1
    if  (N)%2==0:
        return 127*N+D
    else:
        return 127*N+(127-D)
T=int(input())
for _ in range(T):
    a,b=map(int,input().split())
    print(solve(a,b))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

"""
全体のxorが不変量。
N-1数が127のときに等号
"""

T = int(input())
ND = [[int(x) for x in input().split()] for _ in range(T)]

answer = []
for N,D in ND:
    x = 127 * (N-1)
    if N&1:
        x += D
    else:
        x += 127^D
    answer.append(x)

print('\n'.join(map(str,answer)))

Solution (Python):
def inpl(): return list(map(int, input().split()))

for _ in range(int(input())):
    N, D = inpl()
    ans = 0
    for i in range(7):
        D, m = divmod(D, 2)
        ans += (N-(N%2!=m))*(2**i)
    print(ans)

Solution (Python):
for i in range(int(input())):
    n,d=map(int,input().split())
    print([(n-1)*127+d,n*127-d][n%2==0])

Solution (Python):
T = int(input())
ts = [tuple(map(int,input().split())) for i in range(T)]

def solve(n,d):
    if n%2:
        return d + 127*(n-1)
    else:
        return 127*n - d

for n,d in ts:
    print(solve(n,d))

Solution (Python):
T = int(input())
for _ in range(T):
    N,D = map(int,input().split())
    if N%2==0:
        print(N*127-D)
    else:
        print((N-1)*127+D)

Solution (Python):
n = int(input())
for _ in range(n):
	i,j = (int(k) for k in input().split())
	if i%2==0: print(127*i-j)
	else: print(127*(i-1)+j)

Solution (Python):
from heapq import heappush, heappop
T = int(input())
A = []
for i in range(T):
    N, D = map(int, input().split())
    ans = D
    h = []
    heappush(h,D)
    for _ in range(N - 1):
        k = heappop(h)
        t = 127 ^ k
        heappush(h,t)
        ans += (127 + t - k)
    A.append(ans)
for i in range(len(A)):
    print(A[i])

Solution (Python):
def solve(N_t, D_t):
    ans = D_t
    for i in range(N_t - 1):
        ans -= D_t
        ans += 127
        D_t = 127 ^ D_t
        ans += D_t
    return ans

T = int(input())
for i in range(T):
    N_t, D_t = map(int, input().split())
    print(solve(N_t, D_t))

Solution (Python):
for i in[0]*input():n,d=map(int,raw_input().split());print~-n*127+(127*(n+1&1)^d)

Solution (Python):
t=int(input())
for i in range(t):
    n,d=map(int,input().split())
    ans=127*(n-1)
    if n%2==1:
        ans+=d
    else:
        ans+=127^d
    print(ans)

Solution (Python):
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    t = read()
    for _ in range(t):
        n, d = reads()
        
        if n == 1:
            print(d)
        elif n % 2 == 0:
            print(127*(n-1) + (d^127))
        else:
            print(127*(n-1) + d)
        
        
        

main()

Solution (Python):
T = int(input())
for _ in range(T):
    n, d = map(int, input().split())
    print(127*(n-1) + (d if n%2==1 else 127-d))

Solution (Python):
T = int(raw_input())
N_list = list()
D_list = list()
for t in range(T):
    N, D = map(int, raw_input().split())
    N_list.append(N)
    D_list.append(D)
    
for t in range(T):
    N = N_list[t]
    D = D_list[t]
    if N % 2 == 0:
        res = N * 127 - D
    else:
        res = 127*(N-1) + D
    print res

Solution (Python):
f = [[], [[1, 0], [0, 1]]]
dp = [[], [0, 1]]
for i in xrange(1, 1010):
    a = []
    d = []
    for j in xrange(2):
        b = f[i][j]
        g = [0] * (i + 2)
        for k, l in enumerate(b):
            if not l:
                continue
            if k > 0:
                g[k] = i
            if k < i:
                g[k+2] = i
        a.append(g)
        t = 0
        for k, l in enumerate(g):
            if l:
                t = k
        d.append(t)
    f.append(a)
    dp.append(d)
t = int(raw_input())
for _ in xrange(t):
    n, d = map(int, raw_input().split())
    s = 0
    for i in xrange(7):
        s += dp[n][d>>i&1] << i
    print s

Solution (Python):
def solve(): 
	T = int(raw_input())
	for i in xrange(T):
		N,D = map(int,raw_input().split())
		print 127*(N-1) + (D if N % 2 == 1 else D^127)
solve()

Solution (Python):

import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

T = int(raw_input())
for loop in xrange(T):
    N, D = map(int, raw_input().split())
    ans = 0
    for i in xrange(N - 2):
        ans += 127
        D ^= 127

    mx = 0
    if N > 1:
        for i in xrange(1, 128):
            mx = max(mx, i + (D^i))
        print ans + mx
    else:
        print D