ZhenlongDai/ACPR huggingface dataset:
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
Q = int(input())
for i in range(Q):
  a, b = map(int, input().split())
  sqrt = int(math.sqrt(a * b))
  sub = 0 if math.sqrt(a * b) - sqrt > 0 else 1
  sqrt2 = sqrt + 1 if sqrt * (sqrt + 1) < a * b else sqrt
  add = min(max(sqrt2 - min(a, b) - 1, 0), max(max(a, b) - sqrt - 1, 0))
  print(min(a, b) - 1 + sqrt + add - sub)

Failing test case input:
8
2 4
10 5
3 3
5 11
8 9
22 3
7 36
314159265 541984339

Expected output:
3
12
4
12
14
14
29
825274259


Actual output:
3
12
4
12
15
14
29
825274259


Fixed submission (verdict: Accepted):
import math
Q = int(input())
for i in range(Q):
  a, b = map(int, input().split())
  sqrt = int(math.sqrt(a * b))
  sqrt2 = sqrt + 1 if sqrt * (sqrt + 1) < a * b else sqrt
  sub = 1 if sqrt == max(a, b) or sqrt2 == min(a, b) or sqrt * sqrt2 == a * b else 0
  add = min(max(sqrt2 - min(a, b) - 1, 0), max(max(a, b) - sqrt - 1, 0))
  print(min(a, b) - 1 + sqrt + add - sub)

Problem: p03388
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
q=int(input())
for i in range(q):
 a,b=map(int,input().split())
 if abs(a-b)<2:print(min(a,b)*2-2)
 else:
  s=int(math.sqrt(a*b))
  if s**2+2>=a*b:print(2*s-2)
  else:print(2*s-1)

Failing test case input:
8
1 4
10 5
3 3
4 11
8 9
22 11
8 30
314159265 358979323

Expected output:
1
12
4
11
14
29
28
671644785


Actual output:
2
12
4
11
14
29
29
671644785


Fixed submission (verdict: Accepted):
import math
q=int(input())
for i in range(q):
 a,b=map(int,input().split())
 if abs(a-b)<2:print(min(a,b)*2-2)
 else:
  s=int(math.ceil(math.sqrt(a*b)))-1
  if s**2+s<a*b:print(2*s-1)
  else:print(2*s-2)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q = int(input())
for i in range(Q):
    a,b = (map(int, input().split()))
    if(a == b or a+1 == b):
        print(2*a -2)
    else:
        c = int((a*b) ** 0.5)
        if(c*(c+1) > a*b):
            print(2*c-2)
        else:
            print(2*c-1)


Failing test case input:
8
2 4
10 9
3 7
1 11
8 9
16 1
3 41
314159265 339704264

Expected output:
3
16
7
4
14
5
20
653364343


Actual output:
3
17
7
4
14
6
20
653364343


Fixed submission (verdict: Accepted):
Q = int(input())
for i in range(Q):
    a,b = (map(int, input().split()))
    if(a == b):
        print(2*a -2)
    elif(abs(a-b) == 1):
        print(2 * min(a,b) -2)
    else:
        c = int((a*b) ** 0.5)
        if c == (a*b) ** 0.5:
            c -= 1
        if(c*(c+1) >= a*b):
            print(2*c-2)
        else:
            print(2*c-1)
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q=int(input())
score=[list(map(int,input().split())) for _ in range(Q)]
import math
for i in range(Q):
    max_num=int(math.sqrt(score[i][0]*score[i][1]))
    if score[i][0]*score[i][1]==max_num:
        print(2*max_num-3)
    elif score[i][0]*score[i][1]>max_num*(max_num+1):
        print(2*max_num-1)
    elif score[i][0]==score[i][1]:
        print(2*max_num-2)
    else:
        print(2*max_num-2)


Failing test case input:
8
1 4
10 5
3 3
4 11
8 9
22 11
8 30
314159265 358979323

Expected output:
1
12
4
11
14
29
28
671644785


Actual output:
2
12
4
11
14
29
28
671644785


Fixed submission (verdict: Accepted):
Q=int(input())
score=[list(map(int,input().split())) for _ in range(Q)]
import math
for i in range(Q):
    max_num=int(math.sqrt(score[i][0]*score[i][1]))

    if score[i][0]==score[i][1]:
        print(2*max_num-2)
    elif score[i][0]*score[i][1]==max_num**2:
        print(2*max_num-3)
    elif score[i][0]*score[i][1]>max_num*(max_num+1):
        print(2*max_num-1)
    else:
        print(2*max_num-2)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from math import floor, sqrt, ceil

q, *ab = map(int, sys.stdin.read().split())
ab = zip(*[iter(ab)] * 2)

def main():
    for a, b in ab:
        if a > b:
            a, b = b, a
        res = 0
        res += (a - 1) * 2
        
        if b - a <= 1:
            yield res 
            continue
        
        s = a * b
        res += (floor(sqrt(s - 1)) - a) * 2 + 1
        if floor(sqrt(s - 1)) ** 2 == s - 1:
            res -= 1
        yield res
        continue

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Failing test case input:
8
4 4
10 9
3 7
5 11
8 9
16 1
3 41
314159265 541984339

Expected output:
6
16
7
12
14
5
20
825274259


Actual output:
6
16
7
13
14
5
21
825274259


Fixed submission (verdict: Accepted):
import sys
from math import floor, sqrt, ceil

q, *ab = map(int, sys.stdin.read().split())
ab = zip(*[iter(ab)] * 2)

def main():
    for a, b in ab:
        if a > b:
            a, b = b, a
        res = 0
        res += (a - 1) * 2
        
        if b - a <= 1:
            yield res 
            continue
        
        p = a * b
        c = floor(sqrt(p))
        res += (c - a) * 2 + 1
        if c * (c + 1) >= p:
            res -= 1
        if c * c == p:
            res -= 1
        yield res



if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q = int(input())
for i in range(Q):
    a,b = (map(int, input().split()))
    if(a > b):
        temp = a
        a = b
        b = temp
    if(a == b or a+1 == b):
        print(2*a -2)
    else:
        c = int((a*b) ** 0.5)
        if(c*(c+1) > a*b):
            print(2*c-2)
        else:
            print(2*c-1)


Failing test case input:
8
2 4
10 9
3 7
5 11
8 9
16 1
3 41
314159265 339704264

Expected output:
3
16
7
12
14
5
20
653364343


Actual output:
3
16
7
12
14
6
20
653364343


Fixed submission (verdict: Accepted):
Q = int(input())
for i in range(Q):
    a,b = (map(int, input().split()))
    if(a == b):
        print(2*a -2)
    elif(abs(a-b) == 1):
        print(2 * min(a,b) -2)
    else:
        c = int((a*b) ** 0.5)
        if c == (a*b) ** 0.5:
            c -= 1
        if(c*(c+1) >= a*b):
            print(2*c-2)
        else:
            print(2*c-1)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if b-a < 2:
        print(2*a - 2)
        
    else:
        if int(sqrt(a*b)) * int(sqrt(a*b)) == a*b:
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)
            

Failing test case input:
8
4 4
10 9
3 7
5 11
8 9
16 1
3 41
314159265 541984339

Expected output:
6
16
7
12
14
5
20
825274259


Actual output:
6
18
7
12
14
30
20
825274259


Fixed submission (verdict: Accepted):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if a == b or a == b-1:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    c=int(math.sqrt(a*b))
    if c<2 :
        print('0')
    elif a==1 or b==1:
        print(2*c-3)
    elif c*(c+1)<a*b:
        print(2*c-1)
    else:
        print(2*c-2)

Failing test case input:
8
2 2
3 9
3 7
1 11
10 9
21 1
3 63
236426405 339704264

Expected output:
2
8
7
4
16
7
25
566798226


Actual output:
2
8
7
3
16
5
25
566798226


Fixed submission (verdict: Accepted):
import math
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    c=int(math.sqrt(a*b))
    if c*(c+1)<a*b: print(2*c-1)
    elif a*b==c*c and a!=b:  print(2*c-3)
    else:  print(2*c-2)
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q = int(input())
L = []
for i in range(Q):
    L.append([int(x) for x in input().split()])
    
for i in range(Q):
    a = min(L[i])
    b = max(L[i])
    if a == b:
        ans = 2*a-2
    elif a+1 == b:
        ans = 2*a-1
    else:
        c = int((a*b)**0.5)
        if c**2 == a*b:
            c -= 1
        if c*(c+1) >= a*b:
            ans = 2*c-2
        else:
            ans = 2*c-1
    print(ans)

Failing test case input:
8
2 4
10 1
4 6
7 11
8 9
22 3
3 36
314159265 541984339

Expected output:
3
4
7
15
14
14
18
825274259


Actual output:
3
4
7
15
15
14
18
825274259


Fixed submission (verdict: Accepted):
Q = int(input())
L = []
for i in range(Q):
    L.append([int(x) for x in input().split()])
    
for i in range(Q):
    a = min(L[i])
    b = max(L[i])
    if a == b:
        ans = 2*a-2
    elif a+1 == b:
        ans = 2*a-2
    else:
        c = int((a*b)**0.5)
        if c**2 == a*b:
            c -= 1
        if c*(c+1) >= a*b:
            ans = 2*c-2
        else:
            ans = 2*c-1
    print(ans)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q=int(input())
score=[list(map(int,input().split())) for _ in range(Q)]
import math
for i in range(Q):
    max_num=int(math.sqrt(score[i][0]*score[i][1]))
    if score[i][0]*score[i][1]==max_num**2:
        print(2*max_num-3)
    elif score[i][0]*score[i][1]>max_num*(max_num+1):
        print(2*max_num-1)
    elif score[i][0]==score[i][1]:
        print(2*max_num-2)
    else:
        print(2*max_num-2)


Failing test case input:
8
4 4
10 9
3 7
5 11
8 9
16 1
3 41
314159265 541984339

Expected output:
6
16
7
12
14
5
20
825274259


Actual output:
5
16
7
12
14
5
20
825274259


Fixed submission (verdict: Accepted):
Q=int(input())
score=[list(map(int,input().split())) for _ in range(Q)]
import math
for i in range(Q):
    max_num=int(math.sqrt(score[i][0]*score[i][1]))

    if score[i][0]==score[i][1]:
        print(2*max_num-2)
    elif score[i][0]*score[i][1]==max_num**2:
        print(2*max_num-3)
    elif score[i][0]*score[i][1]>max_num*(max_num+1):
        print(2*max_num-1)
    else:
        print(2*max_num-2)
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q = int(input())
Ans = ""
for i in range(Q):
    A, B = map(int, input().split())
    A, B = min(A, B), max(A, B)
    point = A * B
    limit = int(pow(point, 0.5))
    if point >=5:
        if A != B:
            total = limit * 2 - 1
            lim_op = point 
            if lim_op == limit: total -= 1
        else:
            total = (A-1) * 2
        Ans += str(total) + "\n"
    elif point <= 2: Ans += "0\n"
    else: Ans += "1\n"
print(Ans)

Failing test case input:
8
1 4
20 5
3 3
4 11
8 9
22 11
9 30
314159265 554910206

Expected output:
1
17
4
11
14
29
30
835057319


Actual output:
1
19
4
11
15
29
31
835057319



Fixed submission (verdict: Accepted):
Q = int(input())
Ans = ""
for i in range(Q):
    A, B = map(int, input().split())
    A, B = min(A, B), max(A, B)
    if A == B or A + 1 == B: Ans += str(2 * (A - 1)) + "\n"
    else:
        limit = int(pow(A * B, 0.5))
        if limit ** 2 == A * B: limit -= 1
        if limit * (limit + 1) >= A * B: Ans += str(2 * (limit - 1)) + "\n"
        else:Ans += str(2 * limit - 1) + "\n"

print(Ans)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def f(a,b):
  if a>b:a,b=b,a
  if a==b or a+1==b:
    return 2*a-2
  else:
    c=int((a*b)**(1/2))
    if c*(c+1)>=a*b:
      return 2*c-2
    else:
      return 2*c-1

q=int(input())
for _ in range(q):
  a,b=map(int,input().split())
  print(f(a,b))

Failing test case input:
8
2 4
10 14
3 7
5 11
8 9
16 1
3 36
314159265 345511311

Expected output:
3
21
7
12
14
5
18
658925121


Actual output:
3
21
7
12
14
6
18
658925121


Fixed submission (verdict: Accepted):
def f(a,b):
  if a>b:a,b=b,a
  if a==b or a+1==b:
    return 2*a-2
  else:
    c=int((a*b)**(1/2))
    if c**2==a*b:c-=1
    if c*(c+1)>=a*b:
      return 2*c-2
    else:
      return 2*c-1

q=int(input())
for _ in range(q):
  a,b=map(int,input().split())
  print(f(a,b))

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
for i in range(n):
    a, b = map(int, input().split())
    r = a * b
    q = math.sqrt(r)
    x = int(q)
    if a == r or b == r:
        if q == x:
            print(x - 1)
        else:
            print(x)
    elif abs(x ** 2 - r) > abs((x + 1) ** 2 - r):
        print(x * 2 - 1)
    else:
        print(x * 2 - 2)

Failing test case input:
8
2 4
10 5
3 7
5 11
8 9
16 1
3 36
314159265 541984339

Expected output:
3
12
7
12
14
5
18
825274259


Actual output:
3
12
7
12
14
3
18
825274259


Fixed submission (verdict: Accepted):
import math
n = int(input())

for i in range(n):
    s, t = map(int, input().split())
    a = min(s, t)
    b = max(s, t)
    r = a * b
    q = math.sqrt(r)
    x = int(q)
    if x == q:
        x -= 1

    if a + 1 >= b:
        ans = a * 2 - 2
    elif x * (x + 1) >= a * b:
        ans = x * 2 - 2
    else:
        ans = x * 2 - 1
    print(ans)
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import sqrt, floor
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if b-a < 2:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = floor(sqrt(a*b) - 1)
        else:
            c  = floor(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

Failing test case input:
8
2 7
10 5
6 3
1 11
8 9
22 3
8 27
314159265 539534208

Expected output:
5
12
6
4
14
14
27
823406751


Actual output:
5
18
10
4
14
42
27
823406751


Fixed submission (verdict: Accepted):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if a == b or a == b-1:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
q = int(input())
for _ in range(q):
    R = list(map(int, input().split()))
    a, b = min(R), max(R)
    if b - a <= 1:
        res = 2 * (a-1)

    else:
        c = int((a*b)**0.5)
        if c ** 2 == a * b:
            c -= 1
        if c * (c+1) < a * b:
            res = 2 * (c-1) + 1
        else:
            res = 2 * (c-1) - 1
    print(res)

Failing test case input:
8
1 4
10 5
1 1
1 11
8 6
1 5
8 36
314159265 358979323

Expected output:
1
12
0
4
11
2
31
671644785


Actual output:
1
11
0
3
11
1
31
671644785


Fixed submission (verdict: Accepted):
q = int(input())
for _ in range(q):
    R = list(map(int, input().split()))
    a, b = min(R), max(R)
    if b - a <= 1:
        res = 2 * (a-1)

    else:
        c = int((a*b)**0.5)
        if c ** 2 == a * b:
            c -= 1
        if c * (c+1) < a * b:
            res = 2 * (c-1) + 1
        else:
            res = 2 * (c-1)
    print(res)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q = int(input())
for q in range(Q):
    A, B = map(int, input().split())
    M = int((A*B)**0.5)
    tmp = 2*M - 2
    tmp -= (A < M) or (B < M)
    if A != B and A*B != M*M:
        if M*(M+1) < A*B:
            tmp += 2
        elif M*M < A*B:
            tmp += 1
    print(tmp)

Failing test case input:
8
2 4
10 5
2 3
5 11
8 9
22 3
5 36
314159265 541984339

Expected output:
3
12
2
12
14
14
24
825274259


Actual output:
4
12
3
12
15
14
24
825274259


Fixed submission (verdict: Accepted):
Q = int(input())
ans = []
for q in range(Q):
    A, B = map(int, input().split())
    M = int((A*B)**0.5)
    if M*(M + 1) < A*B: 
        ans.append(2*M - 1)
    elif A*B == M*M and A != B: 
        ans.append(2*M - 3)
    else: 
        ans.append(2*M - 2)

print("\n".join(map(str, ans)))
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
def near_sqrt(a,b):
  c = a * b
  d = math.floor(math.sqrt(c))
  if d*(d+1) < c:
    return d
  else:
    return (d-1)
  
q = int(input())
for i in range(q):
  a,b = map(int, input().split())
  c = near_sqrt(a,b)
  d = (a*b)%(c+1)
  if d == 0 and a!=0:
    print(math.floor((a*b)/(c+1))+c-2)
  else:
    print(math.floor((a*b)/(c+1))+c-1)

Failing test case input:
8
2 4
10 14
1 7
5 5
8 9
31 1
3 36
337061332 345511311

Expected output:
3
21
3
8
14
9
18
682520335


Actual output:
3
21
3
7
14
9
18
682520335


Fixed submission (verdict: Accepted):
import math
def near_sqrt(a,b):
  c = a * b
  d = math.floor(math.sqrt(c))
  if d*(d+1) < c:
    return d
  else:
    return (d-1)
  
q = int(input())
for i in range(q):
  a,b = map(int, input().split())
  c = near_sqrt(a,b)
  d = (a*b)%(c+1)
  if d == 0 and a!=b:
    print(math.floor((a*b)/(c+1))+c-2)
  else:
    print(math.floor((a*b)/(c+1))+c-1)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

n = int(input())
for _ in range(n):
  a,b = input().split(" ")
  a,b = sorted([int(a), int(b)])
  c = int((a*b)**0.5)
  print(2*c-1-(a==b))

Failing test case input:
8
1 4
20 5
3 3
4 11
8 9
22 11
9 30
314159265 554910206

Expected output:
1
17
4
11
14
29
30
835057319


Actual output:
3
19
4
11
15
29
31
835057319


Fixed submission (verdict: Accepted):
import math

n = int(input())
for _ in range(n):
  a,b = input().split(" ")
  a,b = sorted([int(a), int(b)])
  c = math.ceil((a*b)**0.5)-1
  print(2*c-(a!=b)-(c*(c+1)>=a*b))

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if b-a < 2:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)
            

Failing test case input:
8
4 4
10 9
3 7
5 11
8 9
16 1
3 41
314159265 541984339

Expected output:
6
16
7
12
14
5
20
825274259


Actual output:
6
18
7
12
14
30
20
825274259


Fixed submission (verdict: Accepted):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if a == b or a == b-1:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    c=int(math.sqrt(a*b))
    if c<2 : print(0)
    elif a*b==c*c and a!=b:  print(2*c-3)
    elif c*(c+1)<a*b: print(2*c-1)
    else:  print(2*c-2)

Failing test case input:
8
1 4
10 5
3 3
4 11
8 9
1 3
8 36
314159265 358979323

Expected output:
1
12
4
11
14
1
31
671644785


Actual output:
1
12
4
11
14
0
31
671644785


Fixed submission (verdict: Accepted):
import math
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    c=int(math.sqrt(a*b))
    if c*(c+1)<a*b: print(2*c-1)
    elif a*b==c*c and a!=b:  print(2*c-3)
    else:  print(2*c-2)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
Q = int(input())

for _ in range(Q):
    A, B = map(int, input().split())
    score = A*B 
    if A > B:
        A, B = B, A 
    if A == B:
        print  (2 * A -2)
    elif A+1 == B:
        print (2 * A - 2)
    else:
        c = int(math.sqrt(A*B))
        print (2 * c -1)
        

Failing test case input:
8
7 4
10 9
3 7
5 17
2 9
16 1
2 41
314159265 541984339

Expected output:
8
16
7
16
6
5
16
825274259


Actual output:
9
16
7
17
7
7
17
825274259


Fixed submission (verdict: Accepted):
import math
Q = int(input())

for _ in range(Q):
    A, B = map(int, input().split())
    score = A*B 
    if A > B:
        A, B = B, A 
    if A == B:
        print  (2 * A -2)
    elif A+1 == B:
        print (2 * A - 2)
    else:
        c = int(math.sqrt(A*B))
        if c ** 2 == A * B:
            c -= 1
        if c * (c+1) >= A * B:
            print (2 * c -2)
        else:
            print (2 * c -1)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
q=int(input())
for _ in range(q):
  a,b=map(int,input().split())
  if a>b:
    a,b=b,a
  if a==b:
    print(2*a-1)
  elif a==b+1:
    print(2*a-2)
  else:
    c=int((a*b)**0.5)
    if c*(c+1)>=a*b:
      print(2*c-2)
    else:
      print(2*c-1)

Failing test case input:
8
1 4
10 5
3 3
5 11
11 9
22 3
7 36
314159265 541984339

Expected output:
1
12
4
12
17
14
29
825274259


Actual output:
2
12
5
12
17
14
29
825274259


Fixed submission (verdict: Accepted):
q=int(input())
for _ in range(q):
  a,b=map(int,input().split())
  if a>b:
    a,b=b,a
  if a==b:
    print(2*a-2)
  elif a==b+1:
    print(2*a-1)
  else:
    c=int((a*b)**0.5)
    if c*c==a*b:
      c-=1
    if c*(c+1)>=a*b:
      print(2*c-2)
    else:
      print(2*c-1)
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
q = int(input())
a = [list(map(int, input().split())) for i in range(q)]

for i in range(q):
    ans = 0
    AB = a[i][0]*a[i][1]
    if a[i][0]<=a[i][1]:
        A, B = a[i][0], a[i][1]
    else:
        A, B = a[i][1], a[i][0]
    x = int(math.sqrt(AB))
    if A==B:
        ans=2*A-2
    elif A+1==B:
        ans= 2*A-2
    elif x*(x+1)>=AB:
        ans = 2*x-2
    else:
        ans = 2*x-1
    print(ans)

Failing test case input:
8
2 4
10 9
3 1
5 11
4 9
16 1
6 57
314159265 75457060

Expected output:
3
16
1
12
9
5
34
307932032


Actual output:
3
16
1
12
10
6
34
307932032


Fixed submission (verdict: Accepted):
import math
q = int(input())
a = [list(map(int, input().split())) for i in range(q)]

for i in range(q):
    ans = 0
    AB = a[i][0]*a[i][1]
    if a[i][0]<=a[i][1]:
        A, B = a[i][0], a[i][1]
    else:
        A, B = a[i][1], a[i][0]
    x = int(math.sqrt(AB-1))
    while x*x>=AB:
        x-=1
    if A==B:
        ans=2*A-2
    elif A+1==B:
        ans= 2*A-2
    elif x*(x+1)>=AB:
        ans = 2*x-2
    else:
        ans = 2*x-1
    print(ans)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from math import floor
Q = int(input())
AB = [list(map(int, input().split())) for _ in range(Q)]

for A, B in AB:
  C = floor((A*B)**(1/2))
  if C == (A*B)**(1/2):
    C -= 1
  if C*(C+1) >= A*B:
    print(2*C-2)
  elif C*C < A*B:
    print(2*C-1)


Failing test case input:
8
1 4
10 5
3 3
4 11
8 9
22 3
8 36
314159265 539534208

Expected output:
1
12
4
11
14
14
31
823406751


Actual output:
1
12
3
11
14
14
31
823406751


Fixed submission (verdict: Accepted):
import sys
from math import floor
Q = int(input())
AB = [sorted(list(map(int, input().split()))) for _ in range(Q)]

for A, B in AB:
  if A == B or A+1 == B:
    print(2*A-2)
    continue
  C = floor((A*B)**(1/2))
  if C == (A*B)**(1/2):
    C -= 1
  if C*(C+1) >= A*B:
    print(2*C-2)
  elif C*C < A*B:
    print(2*C-1)

Problem: p03388
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def main():
    n = int(input())
    for _ in range(n):
        a, b = map(int, input().split())
        ref = a * b
        rng = int(ref ** 0.5) - 1
        if rng == 0:
            print(0)
        elif a == b or abs(a - b) == 1:
            print(2 * a - 2)
        elif rng * (rng + 1) >= a * b:
            print(2 * rng - 2)
        else:
            print(2 * rng - 1)
if __name__ == '__main__':
    main()

Failing test case input:
8
1 4
10 5
3 3
1 11
8 9
1 3
8 36
314159265 358979323

Expected output:
1
12
4
4
14
1
31
671644785


Actual output:
1
11
4
3
14
0
29
671644783


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    for _ in range(n):
        a, b = map(int, input().split())
        ref = a * b - 1
        rng = int(ref ** 0.5) - 2
        while rng ** 2 < a * b:
            rng += 1
        rng -= 1
        if a == b or abs(a - b) == 1:
            print(2 * min(a, b) - 2)
        elif rng * (rng + 1) >= a * b:
            print(2 * rng - 2)
        else:
            print(2 * rng - 1)
if __name__ == '__main__':
    main()
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
for i in range(n):
    a, b = map(int, input().split())
    r = a * b
    q = math.sqrt(r)
    x = int(q)
    if a == r or b == r:
        if q == x:
            print(x - 1)
        else:
            print(x)
    elif r > x * (x + 1):
        print(x * 2 - 1)
    else:
        print(x * 2 - 2)

Failing test case input:
8
2 4
10 5
3 3
1 11
8 9
22 3
8 36
314159265 539534208

Expected output:
3
12
4
4
14
14
31
823406751


Actual output:
3
12
4
3
14
14
31
823406751


Fixed submission (verdict: Accepted):
import math
n = int(input())

for i in range(n):
    s, t = map(int, input().split())
    a = min(s, t)
    b = max(s, t)
    r = a * b
    q = math.sqrt(r)
    x = int(q)
    if x == q:
        x -= 1

    if a + 1 >= b:
        ans = a * 2 - 2
    elif x * (x + 1) >= a * b:
        ans = x * 2 - 2
    else:
        ans = x * 2 - 1
    print(ans)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if b-a < 2:
        print(2*a - 2)
        
    else:
        if sqrt(a*b) - int(sqrt(a*b)) == 0:
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)
            

Failing test case input:
8
2 4
10 14
3 7
5 5
8 9
16 1
3 36
314159265 345511311

Expected output:
3
21
7
8
14
5
18
658925121


Actual output:
3
21
7
8
14
30
18
658925121


Fixed submission (verdict: Accepted):
from math import sqrt
import sys
sdin = sys.stdin.readline

q = int(sdin())
ab = []
for i in range(q):
    ab.append(tuple(map(int, sdin().split())))

for a, b in ab:
    if a == b or a == b-1:
        print(2*a - 2)
        
    else:
        if not (sqrt(a*b) - int(sqrt(a*b))):
            c = int(sqrt(a*b) - 1)
        else:
            c  = int(sqrt(a*b))
        
        if c*(c+1) >= a*b:
            print(2*c - 2)
        else:
            print(2*c - 1)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

n = int(input())
for _ in range(n):
  a,b = input().split(" ")
  a,b = sorted([int(a), int(b)])
  c = math.ceil((a*b)**0.5)-1
  print(2*c-(a!=b)-(c*(c+1)>=b*b))

Failing test case input:
8
2 4
2 5
3 6
5 11
8 9
22 3
7 36
314159265 541984339

Expected output:
3
4
6
12
14
14
29
825274259


Actual output:
3
5
7
13
15
15
29
825274259


Fixed submission (verdict: Accepted):
import math

n = int(input())
for _ in range(n):
  a,b = input().split(" ")
  a,b = sorted([int(a), int(b)])
  c = math.ceil((a*b)**0.5)-1
  print(2*c-(a!=b)-(c*(c+1)>=a*b))
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q = int(input())

while Q:
    Q -= 1
    from math import sqrt
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last * (last * 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)


Failing test case input:
8
1 4
10 5
3 3
4 11
8 9
22 3
7 36
314159265 96636036

Expected output:
1
12
4
11
14
14
29
348477291


Actual output:
2
13
4
11
14
15
29
348477291


Fixed submission (verdict: Accepted):
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last == (M * m) ** 0.5:
        last -= 1
    if last * (last + 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q = int(input())
Ri = [list(map(int, input().split())) for _ in range(Q)]

for r in Ri:
    a = r[0]
    b = r[1]
    if a > b:
        t = b
        b = a
        a = t
    max_score = a * b

    if a == b:
        print(2 * a - 1)
    elif a + 1 == b:
        print(2 * a - 2)
    else:
        r = max_score ** 0.5
        rn = int(r)
        print(2 * rn - 2)

Failing test case input:
8
2 2
3 9
3 7
1 11
8 9
21 1
3 63
236426405 339704264

Expected output:
2
8
7
4
14
7
25
566798226


Actual output:
3
8
6
4
14
6
24
566798226


Fixed submission (verdict: Accepted):
Q = int(input())
Ri = [list(map(int, input().split())) for _ in range(Q)]

for r in Ri:
    a = r[0]
    b = r[1]
    if a > b:
        t = b
        b = a
        a = t
    max_score = a * b

    if a == b:
        print(2 * a - 2)
    elif a + 1 == b:
        print(2 * a - 2)
    else:
        r = max_score ** 0.5
        rn = int(r)
        if rn == r:
            rn -= 1
        if rn * (rn + 1) >= max_score:
            print(2 * rn - 2)
        else:
            print(2 * rn - 1)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
t= int(input())
for i in range(t):
    k=input().split()
    a=int(k[0])
    b=int(k[1])
    c=a*b
    d=int(c**.5)
    print(2*d-1-((d*d)==c)-(c==d*d and a!=b))

Failing test case input:
8
2 4
10 5
3 6
5 11
8 9
22 3
3 36
314159265 541984339

Expected output:
3
12
6
12
14
14
18
825274259


Actual output:
3
13
7
13
15
15
19
825274259


Fixed submission (verdict: Accepted):
t= int(input())
for i in range(t):
    k=input().split()
    a=int(k[0])
    b=int(k[1])
    c=a*b
    d=int(c**.5)
    print(2*d-1-((d*(d+1))>=c)-(c==d*d and a!=b))
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = (M * m) ** 0.5
    if last % 1 != 0:
        last = int(last)
    else:
        last -= 1
        last = int(last)
    if last * (last * 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)


Failing test case input:
8
2 4
7 9
3 5
1 11
8 9
16 1
3 41
314159265 339704264

Expected output:
3
13
5
4
14
5
20
653364343


Actual output:
3
13
5
5
14
5
21
653364343


Fixed submission (verdict: Accepted):
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last == (M * m) ** 0.5:
        last -= 1
    if last * (last + 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last == (M * m) ** 0.5:
        last -= 1
    print(last)
    if last * (last + 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)


Failing test case input:
8
7 4
14 9
3 7
5 17
8 9
16 1
2 41
314159265 541984339

Expected output:
8
20
7
16
14
5
16
825274259


Actual output:
5
8
11
20
4
7
9
16
14
3
5
9
16
412637130
825274259


Fixed submission (verdict: Accepted):
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last == (M * m) ** 0.5:
        last -= 1
    if last * (last + 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve(a,b):
  if a==b:
    return (a-1)+(b-1)
  elif a+1==b or b+1==a:
    return (min(a,b)-1)*2
  else:
    cnt=(a*b-1)**(1/2)
    if cnt!=int(cnt):
      return int(cnt)*2-1
    else:
      return int(cnt)*2-2

Q=int(input())

for i in range(Q):
  a,b=map(int,input().split())
  print(solve(a,b))
  
  

Failing test case input:
8
2 4
1 5
3 6
6 11
8 9
22 3
7 36
314159265 541984339

Expected output:
3
2
6
14
14
14
29
825274259


Actual output:
3
2
7
15
14
15
29
825274259


Fixed submission (verdict: Accepted):
def solve(a,b):
  if a==b:
    return (a-1)+(b-1)
  elif a+1==b or b+1==a:
    return (min(a,b)-1)*2
  else:
    cnt=(a*b)**(1/2)
    if cnt==int(cnt):
      cnt=int(cnt)-1
    else:
      cnt=int(cnt)
    if cnt*(cnt+1)>=a*b:
      return int(cnt)*2-2
    else:
      return int(cnt)*2-1

Q=int(input())

for i in range(Q):
  a,b=map(int,input().split())
  print(solve(a,b))

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import sqrt

Q = int(input())
A_list = []
B_list = []

for i in range(Q):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

for A, B in zip(A_list, B_list):
    if A == B:
        print(2*A-2)
        continue
    if abs( A - B) == 1:
        print(2*min(A, B)-2)
        continue
    C = int(sqrt(A*B))
    if C*C >= A*B:
        C -= 1
    if C * (C + 1) > A*B:
        print(2*C-2)
        continue
    print(2*C-1)

Failing test case input:
8
1 4
10 8
4 3
4 11
8 7
22 6
7 36
314159265 96636036

Expected output:
1
15
4
11
12
20
29
348477291


Actual output:
1
15
4
11
12
21
29
348477291


Fixed submission (verdict: Accepted):
from math import sqrt
from math import floor

Q = int(input())
A_list = []
B_list = []

for i in range(Q):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

for A, B in zip(A_list, B_list):
    if A == B:
        print(2*A-2)
        continue
    if abs( A - B) == 1:
        print(2*min(A, B)-2)
        continue
    C = int(floor(sqrt(A*B)))
    if C*C >= A*B:
        C -= 1
    if C * (C + 1) >= A*B:
        print(2*C-2)
        continue
    print(2*C-1)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q = int(input())
ans = []
for q in range(Q):
    A, B = map(int, input().split())
    M = int((A*B)**0.5)
    tmp = 2*M - 2
    tmp -= (A < M) or (B < M)
    if A != M and B != M and A*B != M*M:
        if M*(M+1) < A*B:
            tmp += 2
        elif M*M < A*B:
            tmp += 1
    ans.append(tmp)

print("\n".join(map(str, ans)))

Failing test case input:
8
1 4
10 8
4 3
4 11
8 7
22 6
7 36
314159265 96636036

Expected output:
1
15
4
11
12
20
29
348477291


Actual output:
1
14
4
11
12
20
29
348477291


Fixed submission (verdict: Accepted):
Q = int(input())
ans = []
for q in range(Q):
    A, B = map(int, input().split())
    M = int((A*B)**0.5)
    if M*(M + 1) < A*B: 
        ans.append(2*M - 1)
    elif A*B == M*M and A != B: 
        ans.append(2*M - 3)
    else: 
        ans.append(2*M - 2)

print("\n".join(map(str, ans)))
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

from math import floor,sqrt
Q = int(input())
for _ in range(Q):
    A,B = map(int,input().split())
    if A > B:
        A,B = B,A
    if A == B:
        print(2*A-2)
    if A+1 == B:
        print(2*A-2)
    else:
        C = floor(sqrt(A*B-1))
        if C*(C+1) >= A*B:
            print(2*C-2)
        else:
            print(2*C-1)


Failing test case input:
8
2 2
3 9
3 7
1 11
8 9
21 1
3 63
236426405 339704264

Expected output:
2
8
7
4
14
7
25
566798226


Actual output:
2
1
8
7
4
14
7
25
566798226


Fixed submission (verdict: Accepted):

from math import floor,sqrt
Q = int(input())
for _ in range(Q):
    A,B = map(int,input().split())
    if A > B:
        A,B = B,A
    if A == B:
        print(2*A-2)
        continue
    if A+1 == B:
        print(2*A-2)
        continue
    C = floor(sqrt(A*B))
    if C == sqrt(A*B):
        C -= 1
    if C*(C+1) >= A*B:
        print(2*C-2)
    else:
        print(2*C-1)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
for i in range(n):
    a, b = map(int, input().split())
    r = a * b
    q = math.sqrt(r)
    x = int(q)
    if a == r or b == r:
        if q == x:
            print(x - 1)
        else:
            print(x)
    elif abs(x ** 2 - r) >= abs((x + 1) ** 2 - r):
        print(x * 2 - 1)
    else:
        print(x * 2 - 2)

Failing test case input:
8
1 4
20 5
3 3
4 11
8 9
22 11
9 30
314159265 554910206

Expected output:
1
17
4
11
14
29
30
835057319


Actual output:
1
18
4
11
14
29
30
835057319


Fixed submission (verdict: Accepted):
import math
n = int(input())

for i in range(n):
    s, t = map(int, input().split())
    a = min(s, t)
    b = max(s, t)
    r = a * b
    q = math.sqrt(r)
    x = int(q)
    if x == q:
        x -= 1

    if a + 1 >= b:
        ans = a * 2 - 2
    elif x * (x + 1) >= a * b:
        ans = x * 2 - 2
    else:
        ans = x * 2 - 1
    print(ans)

Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last == (M * m) ** 0.5:
        last -= 1
    if last * (last * 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)


Failing test case input:
8
1 4
10 5
3 3
7 11
11 9
8 4
7 36
314159265 541984339

Expected output:
1
12
4
15
17
9
29
825274259


Actual output:
1
13
4
15
17
9
29
825274259


Fixed submission (verdict: Accepted):
Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last == (M * m) ** 0.5:
        last -= 1
    if last * (last + 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)
Problem: p03388
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

Q = int(input())

AB = []
for _ in range(Q) :
    a, b = map(int, input().split())
    AB.append((a, b))

for a, b in AB :
    if a == b :
        print(2 * a - 2)
    elif (a + 1) == b :
        print(2 * a - 2)
    else :
        C = int(math.sqrt(a * b))
        if C * (C + 1) >= a * b :
            print(2 * C - 2)
        else :
            print(2 * C - 1)


Failing test case input:
8
1 4
10 8
4 3
4 11
8 7
22 6
7 36
314159265 96636036

Expected output:
1
15
4
11
12
20
29
348477291


Actual output:
2
15
4
11
12
20
29
348477291


Fixed submission (verdict: Accepted):
import math

Q = int(input())

AB = []
for _ in range(Q) :
    a, b = map(int, input().split())
    if a > b :
        a, b = b, a
    AB.append((a, b))

for a, b in AB :
    if a == b :
        print(2 * a - 2)
        continue

    C = int(math.sqrt(a * b))
    if C * C == a * b :
        C -= 1

    if C * (C + 1) >= a * b :
        print(2 * C - 2)
    else :
        print(2 * C - 1)
Problem: p03708
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
a,b=int(input()),int(input())
if a==b:
	print(1)
else:
	r=60
	while (a&(1<<r))==(b&(1<<r)):
		r-=1
	t=(1<<(r+1))
	a&=t-1
	b&=t-1
	k=r-1
	while k>=0 and b&(1<<k)==0:
		k-=1
	print(t-a-(a-(1<<(k+1))*bool(a>(1<<(k+1)))))

Failing test case input:
65
231

Expected output:
191


Actual output:
126


Fixed submission (verdict: Accepted):
a,b=int(input()),int(input())
if a==b:
	print(1)
else:
	r=60
	while (a&(1<<r))==(b&(1<<r)):
		r-=1
	t=(1<<(r+1))
	a&=t-1
	b&=t-1
	k=r-1
	while k>=0 and (b&(1<<k))==0:
		k-=1
	ans=t-a
	if a>(1<<(k+1)):
		ans-=a-(1<<(k+1))
	print(ans)

Problem: p03708
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import math
A = int(input())
B = int(input())
if B < A: A,B = B,A

if A == B:
    print(1)
else:
    t = int(math.floor(math.log2(B)))
    while (A & 2**t) == (B & 2**t):
        if A & 2**t:
            A -= 2**t
            B -= 2**t
        t-=1
    ans = 2**t - A              
    r = t-1
    while 2**t + 2**r > B and r>=0:
        r-=1
    print(r)
    
    C = 2**(r+1)
    if C < A:
        ans += C + 2**t - A
    else:
        ans += 2**t
    print(ans)


Failing test case input:
271828182845904523
1031296135146934819

Expected output:
881093321760942453


Actual output:
58
881093321760942453


Fixed submission (verdict: Accepted):

import math
A = int(input())
B = int(input())
if B < A: A,B = B,A

if A == B:
    print(1)
else:
    t = int(math.floor(math.log2(B)))
    while (A & 2**t) == (B & 2**t):
        if A & 2**t:
            A -= 2**t
            B -= 2**t
        t-=1
    ans = 2**t - A              
    r = t-1
    while 2**t + 2**r > B and r>=0:
        r-=1
    
    C = 2**(r+1)
    if C < A:
        ans += C + 2**t - A
    else:
        ans += 2**t
    print(ans)

Problem: p03708
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a = int(input())
b = int(input())

if a == b:
    print(1)
    exit()

t = a ^ b
n = len(bin(t)) - 2

T = 1 << (n - 1)

a = a & (T * 2 - 1)
b = b & (T * 2 - 1)

sb = b & (T - 1)
len_sb = len(bin(sb)) - 2
b_max = (2 ** len_sb - 1) | T

if (T + a) > b_max:
    print((b_max - a + 1) + (2 * T - 1 - (T + a) + 1))
else:
    print(2 * T - 1 - a + 1)



Failing test case input:
7
128

Expected output:
243


Actual output:
244


Fixed submission (verdict: Accepted):
a = int(input())
b = int(input())

if a == b:
    print(1)
    exit()



def bitlen(x):
    return 1 + bitlen(x >> 1) if x else 0

t = a ^ b
n = bitlen(t)

T = 1 << (n - 1)

a = a & (T * 2 - 1)
b = b & (T * 2 - 1)

sb = b & (T - 1)
b_max = (2 ** bitlen(sb) - 1) | T

if (T + a) > b_max:
    print((b_max - a + 1) + (2 * T - 1 - (T + a) + 1))
else:
    print(2 * T - 1 - a + 1)
Problem: p03708
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a=int(input())
b=int(input())
if a==b:
  print(1)
  exit()
abin=bin(a)[2:]
bbin=bin(b)[2:]
la=len(abin)
lb=len(bbin)
if la==lb:
  while abin[0]==bbin[0]:
    abin=abin[1:]
    bbin=bbin[1:]
  while len(abin)>1 and abin[0]=="0":
    abin=abin[1:]
cbin=bbin[1:]
while len(cbin)>1 and cbin[0]=="0":
  cbin=cbin[1:]
c=2**(len(cbin))-1
a=int(abin,2)
b=int(bbin,2)
lb=len(bbin)
lbnd=2**(lb-1)+c
hbnd=2**(lb-1)+a
if lbnd>=hbnd:
  print(2**lb-a)
else:
  print(2**(lb-1)-a+lbnd-a+1)


Failing test case input:
7
8

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
a=int(input())
b=int(input())
if a==b:
  print(1)
  exit()
abin=bin(a)[2:]
bbin=bin(b)[2:]
la=len(abin)
lb=len(bbin)
if la==lb:
  while abin[0]==bbin[0]:
    abin=abin[1:]
    bbin=bbin[1:]
  while len(abin)>1 and abin[0]=="0":
    abin=abin[1:]
cbin=bbin[1:]
while cbin and cbin[0]=="0":
  cbin=cbin[1:]
c=2**(len(cbin))-1
a=int(abin,2)
b=int(bbin,2)
lb=len(bbin)
lbnd=2**(lb-1)+c
hbnd=2**(lb-1)+a
if lbnd>=hbnd:
  print(2**lb-a)
else:
  print(2**(lb-1)-a+lbnd-a+1)

Problem: p03708
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
a,b=int(input()),int(input())
if a==b:
	print(1)
else:
	r=60
	while (a&(1<<r))==(b&(1<<r)):
		r-=1
	t=(1<<(r+1))
	a&=t-1
	b&=t-1
	k=r-1
	while k>=0 and b&(1<<k)==0:
		k-=1
	print(t-a-(a-(1<<(k+1))*bool(a-(1<<(k+1)))))

Failing test case input:
65
593

Expected output:
959


Actual output:
1022


Fixed submission (verdict: Accepted):
a,b=int(input()),int(input())
if a==b:
	print(1)
else:
	r=60
	while (a&(1<<r))==(b&(1<<r)):
		r-=1
	t=(1<<(r+1))
	a&=t-1
	b&=t-1
	k=r-1
	while k>=0 and (b&(1<<k))==0:
		k-=1
	ans=t-a
	if a>(1<<(k+1)):
		ans-=a-(1<<(k+1))
	print(ans)

Problem: p03708
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a = int(input())
b = int(input())

def bitlen(x):
    return 1 + bitlen(x >> 1) if x else 0

if a == b:
    print(1)
    exit()

t = a ^ b
n = bitlen(t)

T = 2**(n-1)

sb = b & (T - 1)
b_max = (2 ** bitlen(sb) - 1) | T

if t + a > b:
    print((b_max - a + 1) + (2 * T - 1 - (T + a) + 1))
else:
    print(2 * T - 1 - a + 1)



Failing test case input:
271828182845904523
550279025309055192

Expected output:
304632569457518965


Actual output:
321034762763326186


Fixed submission (verdict: Accepted):
a = int(input())
b = int(input())

if a == b:
    print(1)
    exit()



def bitlen(x):
    return 1 + bitlen(x >> 1) if x else 0

t = a ^ b
n = bitlen(t)

T = 1 << (n - 1)

a = a & (T * 2 - 1)
b = b & (T * 2 - 1)

sb = b & (T - 1)
b_max = (2 ** bitlen(sb) - 1) | T

if (T + a) > b_max:
    print((b_max - a + 1) + (2 * T - 1 - (T + a) + 1))
else:
    print(2 * T - 1 - a + 1)
Problem: p03708
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

res = 0

A = int(input())
B = int(input())

def pow2_floor_log2(x):
    res = 1
    while res*2 <= x:
        res *= 2
    return res


while True:
    
    C = pow2_floor_log2(B)
    if A < C:
        
        res += C - A
        if B > C:
            B_ = C + pow2_floor_log2(B - C)*2 - 1
        else:
            B_ = C
        if C + A <= B_:
            res += C
            break
        else:
            res += (C - A) + (B_ - C + 1)
            break
    else:
        A -= C
        B -= C

print(res)

Failing test case input:
7
7

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):

res = 0

A = int(input())
B = int(input())

def pow2_floor_log2(x):
    res = 1
    while res*2 <= x:
        res *= 2
    return res

if A == B:
    res += 1
    
while A < B:
    
    C = pow2_floor_log2(B)
    if A < C:
        
        res += C - A
        if B > C:
            B_ = C + pow2_floor_log2(B - C)*2 - 1
        else:
            B_ = C
        if C + A <= B_:
            res += C
            break
        else:
            res += (C - A) + (B_ - C + 1)
            break
    else:
        A -= C
        B -= C

print(res)

Problem: p03708
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

def solve():
    a = int(input())
    b = int(input())

    if a == b:
        print(1)
        return

    t = a ^ b
    N = len(bin(t)) - 2
    t = 1 << N

    a = a & (t - 1)
    b = b & (t - 1)
    
    blen = len(bin(b)) - 2

    sb = b & (2**(blen - 1) - 1)
    sblen = len(bin(sb)) - 2

    s = (1<<sblen) - 1

    ymax = b | s

    T = 1<<(N - 1)

    ans = T - a

    if ymax < T + a:
        ans += ymax - T + 1 + T - a
    else:
        ans += T

    print(ans)


if __name__ == '__main__':
    solve()

Failing test case input:
7
32

Expected output:
51


Actual output:
52


Fixed submission (verdict: Accepted):
import sys

def solve():
    a = int(input())
    b = int(input())

    if a == b:
        print(1)
        return

    t = a ^ b
    N = len(bin(t)) - 2
    t = 1 << N

    a = a & (t - 1)
    b = b & (t - 1)

    blen = len(bin(b)) - 2

    sb = b & (2**(blen - 1) - 1)

    if sb == 0:
        sblen = 0
    else:
        sblen = len(bin(sb)) - 2

    s = (1<<sblen) - 1

    ymax = b | s

    T = 1<<(N - 1)

    ans = T - a

    if ymax < T + a:
        ans += ymax - T + 1 + T - a
    else:
        ans += T

    print(ans)


if __name__ == '__main__':
    solve()