Problem:


Score : 700 points

Problem Statement

10^{10^{10}} participants, including Takahashi, competed in two programming contests.
In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.

The score of a participant is the product of his/her ranks in the two contests.

Process the following Q queries:

In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.

Constraints

1 \leq Q \leq 100

1\leq A_i,B_i\leq 10^9(1\leq i\leq Q)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

Q
A_1 B_1
:
A_Q B_Q

Output

For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.

Sample Input 1

8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323

Sample Output 1

1
12
4
11
14
57
31
671644785

Let us denote a participant who was ranked x-th in the first contest and y-th in the second contest as (x,y).

In the first query, (2,1) is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print 1.



Sample input:
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323


Sample output:
1
12
4
11
14
57
31
671644785

Submission status: Accepted

Solution code:
n = int(raw_input())
def f(x, a, b):
    if x < a:
        return 1
    m = x / 2
    mx = 0
    for i in xrange(m - 10, m + 10):
        if 0 <= i < x:
            s = i + 1
            if s >= a:
                s += 1
            if x >= b:
                t = x + 1 - i
                if t <= b:
                    t -= 1
            else:
                t = x - i
            if mx < s * t:
                mx = s * t
    return mx < a * b
for _ in xrange(n):
    a, b = map(int, raw_input().split())
    if a > b:
        a, b = b, a
    lo, hi = -1, 2201001001
    while lo + 1 < hi:
        mid = (lo + hi) / 2
        if f(mid, a, b):
            lo = mid
        else:
            hi = mid
    print lo

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import math
Q=int(input())
for _ in range(Q):
    A,B = list(map(int,input().split()))
    if A<B:
        A,B=B,A
    S=A*B
    a=math.floor(math.sqrt(S-1))
    if a*a>S-1:
        a-=1
#    print(math.sqrt(A*B-1))
#    print('a A B',a,A,B)
    if A-B<=1:
        print(2*(B-1))
    elif a*(a+1) < S:
        print((B-1)+a+max(0,a-B))
    else:
        print((B-1)+a+max(0,a-B-1))

Submission status: Accepted

Solution code:
q = int(input())
for it in range(q):
    a, b = map(int, input().split())
    if a * b <= 2:
        print(0)
        continue
    lo, hi = 1, a*b - 1
    while lo < hi:
        x = (lo + hi + 1) // 2
        #l = list(range(max(1, x // 2 - 2), x // 2 + 3))
        #r = list(range(max(1, x // 2 - 2), x // 2 + 3))
        if x % 2 == 0:
            r1, r2 = x // 2, x // 2 + 1
            l1, l2 = x // 2, x // 2 + 1
        else:
            l, r = (x + 1) // 2, (x + 1) // 2 
            if a <= l:
                l += 1
            if b <= r:
                r += 1
            if l * r < a * b:
                lo = x
            else:
                hi = x - 1
            continue
        if b <= r1:
            r1 += 1
            r2 += 1
        #elif b >= r2 and b <= x:
        #    r1 -= 1
        #    r2 -= 1
        if a <= l1:
            l1 += 1
            l2 += 1
        #elif a >= l2 and a <= x:
        #    l1 -= 1
        #    l2 -= 1
        if l1 * r2 < a*b and l2 * r1 < a*b:
            lo = x
        else:
            hi = x - 1
    print(lo)

Submission status: Accepted

Solution code:
def getKth(x, a, k):
    if(k < a):
        return k
    return k + 1
def getRKth(x, a, k):
    if(x < a):
        return x - k + 1
    if(k < (x - a)):
        return x - k + 1
    return x - k
def NB(x, b):
    if(x < b):
        return x
    return x + 1
def f(x, a, b):
    mv = 25
    half = (x + 1) / 2
    rep = 0
    for delta in xrange(-mv, mv + 1):
        if(half + delta >= 1 and half + delta <= x):
            rep = max(rep, getKth(x, a, half + delta) * getRKth(NB(x, b), b, half + delta))
    half = b - a
    for delta in xrange(-mv, mv + 1):
        if(half + delta >= 1 and half + delta <= x):
            rep = max(rep, getKth(x, a, half + delta) * getRKth(NB(x, b), b, half + delta))
    half = NB(x, b) - b
    for delta in xrange(-mv, mv + 1):
        if(half + delta >= 1 and half + delta <= x):
            rep = max(rep, getKth(x, a, half + delta) * getRKth(NB(x, b), b, half + delta))
    return rep
q = int(raw_input())
while(q > 0):
    a, b = map(int, raw_input().split())
    if(a > b):
        a, b = b, a
    lo = 1
    hi = 10**19
    res = 0
    # print f(1, a, b)
    # print f(2, a, b)
    # print f(3, a, b)
    # print getKth(2, a, 1), getRKth(NB(2, b), b, 1)
    # print getKth(2, a, 2), getRKth(NB(2, b), b, 2)
    while(lo <= hi):
        mid = (lo + hi)/2
        if(f(mid, a, b) < a * b):
            lo = mid + 1
            res = mid
        else:
            hi = mid - 1
    print res
    q -= 1

Submission status: Accepted

Solution code:
def getKth(x, a, k):
    if(k < a):
        return k
    return k + 1
def getRKth(x, a, k):
    if(x < a):
        return x - k + 1
    if(k < (x - a)):
        return x - k + 1
    return x - k
def NB(x, b):
    if(x < b):
        return x
    return x + 1
def f(x, a, b):
    half = (x + 1) / 2
    rep = 0
    for delta in xrange(-50, 51):
        if(half + delta >= 1 and half + delta <= x):
            rep = max(rep, getKth(x, a, half + delta) * getRKth(NB(x, b), b, half + delta))
    half = b - a
    for delta in xrange(-50, 51):
        if(half + delta >= 1 and half + delta <= x):
            rep = max(rep, getKth(x, a, half + delta) * getRKth(NB(x, b), b, half + delta))
    half = NB(x, b) - b
    for delta in xrange(-50, 51):
        if(half + delta >= 1 and half + delta <= x):
            rep = max(rep, getKth(x, a, half + delta) * getRKth(NB(x, b), b, half + delta))
    return rep
q = int(raw_input())
while(q > 0):
    a, b = map(int, raw_input().split())
    if(a > b):
        a, b = b, a
    lo = 1
    hi = 10**19
    res = 0
    # print f(1, a, b)
    # print f(2, a, b)
    # print f(3, a, b)
    # print getKth(2, a, 1), getRKth(NB(2, b), b, 1)
    # print getKth(2, a, 2), getRKth(NB(2, b), b, 2)
    while(lo <= hi):
        mid = (lo + hi)/2
        if(f(mid, a, b) < a * b):
            lo = mid + 1
            res = mid
        else:
            hi = mid - 1
    print res
    q -= 1

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def isqrt(n):
    x = n
    y = (x + 1) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

def solve(f):
    q = f.read_int()

    res = []
    for _ in xrange(q):
        a, b = f.read_int_list()
        if a*b == 1:
            res.append("0")
            continue
        sq = isqrt(a*b-1)
        ans = sq*2
        if (a*b-1)/sq == sq: ans -= 1
        if a <= sq: ans -= 1
        if b <= sq: ans -= 1
        res.append(str(ans))

    return "\n".join(res)


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    rr = []
    for _ in range(n):
        a,b = LI()
        t = a*b
        s = int(t ** 0.5)
        if t < 3:
            rr.append(0)
        elif a == b:
            if (a-1) * (b+1) < t:
                rr.append((a-1)*2)
            else:
                rr.append((a-1)*2-1)
        elif s*s == t:
            rr.append((s-1)*2-1)
        elif s*(s+1) < t:
            rr.append(s*2-1)
        else:
            rr.append((s-1)*2)


    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
from math import sqrt

q = int(input())
for _ in range(q):
    a, b = map(int, input().split())
    m = a * b
    s = int(sqrt(m))
    ans = 2 * s - 1
    if s * (s + 1) >= m:
        ans -= 1
    if s * s == m and a != b:
        ans -= 1
    print(ans)

Submission status: Runtime Error

Solution code:

Q = int(input())

for i in range(Q):

    A,B = map(int,input().split())

    #print (((A*B-1) // int((A*B-1)**0.5)),int((A*B-1)**0.5))
    if ((A*B-1) // int((A*B-1)**0.5)) == int((A*B-1)**0.5):
        print (int((A*B-1) ** 0.5) * 2 - 2)
        

    elif A != B:
        print (int((A*B-1) ** 0.5) * 2 - 1)

    else:
        print (int((A*B-1) ** 0.5) * 2)

Submission status: Runtime Error

Solution code:
from math import sqrt

def func(a, b):
	if a == b:
		return (a - 1) * 2
	else:
		sq = int(sqrt(a * b))
		if a * b == sq ** 2:
			return (sq - 1) * 2 - 1
		elif sq * (sq + 1) >= a * b:
            return (sq - 1) * 2
		else:
			return sq * 2 - 1

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

Submission status: Runtime Error

Solution code:
#t=int(input())
t=1
for i in range(t):
	x,y,z=map(int,input().split())
	ma=max(x,y,z)
	mi=min(x,y,z)
	if(x==ma):
		if(y<z):
			m=x-y
			n=x-z
		else:
			m=x-z
			n=x-y
	elif(y==ma):
		if(x<z):
			m=y-x
			n=y-z
		else:
			m=y-z
			n=y-x
	else:
		if(x<y):
			m=z-x
			n=z-y
		else:
			m=z-y
			n=z-x
	ans=n+(m-n)//2
	if((m-n)%2==1):
		ans+=2
	print(ans)

Submission status: Runtime Error

Solution code:
#N = int(input())
lis = []
N = 1
for T in range(N):
	c = list(map(int, input().split()))
	pro = c[0] * c[1]
	sq = int(pro**0.5)
	if c[0] == c[1]:
		n = (sq - 1) * 2
	elif (c[0]%2 != 0 and c[1]%2 == 0) or (c[1]%2 != 0 and c[0]%2 == 0):
		n = (sq - 1) * 2
	elif (c[0]%2 == 0 and c[1]%2 == 0):
		n = (sq * 2) - 1 
	else: 
		n = (sq * 2) - 2
	lis.append(n)
for i in lis:
	print(i)

Submission status: Runtime Error

Solution code:
import numpy as np
def f(a, b):
    if a > b:
        a, b = b, a
    t = int(np.sqrt(a*b - 1))
    l = (a*b-1) / (b+1)
    r = (a*b-1) / (b-1)
    if a == b:
        return 2*t
    if (a+1) == b:
        return 2*t-2
    if t*(t+1) < a*b:
        return 2*t-1
    return 2*t-2

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

Submission status: Runtime Error

Solution code:
import math
q=int(input())
for j in range(q):
	AB=[int(i) for i in input().split()]
	AB.sort()#4,11
	ab=AB[0]*AB[1] #44
	for i in range(int(math.sqrt(ab))-1,AB[1]+2):
		if i*i>=ab:
			x=i-1
			break
	for i in range(int(ab/x)-1,ab+2):
		if x*i>=ab:
			y=i-1
			break
	cnt1=2*x
	cnts=1 if x==y else 0
	cntdd=1 if x-AB[0]>=0 else 0
	cntdu=1 if AB[1]-y>=0 and (AB[1]+1)*(x-AB[1]+y)>=ab else 0 #x-i, y+i=c,b->c,b+1
	print(cnt1-cnts-cntdd-cntdu)

Submission status: Runtime Error

Solution code:
import math
q=int(input())
for j in range(q):
	AB=[int(i) for i in input().split()]
	AB.sort()#4,11
	ab=AB[0]*AB[1] #44
	for i in range(int(math.sqrt(ab)),AB[1]+1):
		if i*i>=ab:
			x=i-1
			break
	for i in range(int(ab/x),ab+1):
		if x*i>=ab:
			y=i-1
			break
	cnt1=2*x
	cnts=1 if x==y else 0
	cntdd=1 if x-AB[0]>=0 else 0
	cntdu=1 if AB[1]-y>=0 and (AB[1]+1)*(x-AB[1]+y)>=ab else 0 #x-i, y+i=c,b->c,b+1
	print(cnt1-cnts-cntdd-cntdu)

Submission status: Runtime Error

Solution code:
import math
q=int(input())
for j in range(q):
	AB=[int(i) for i in input().split()]
	AB.sort()#4,11
	ab=AB[0]*AB[1] #44
	for i in range(int(sqrt(ab)),AB[1]+1):
		if i*i>=ab:
			x=i-1
			break
	for i in range(int(ab/x),ab+1):
		if x*i>=ab:
			y=i-1
			break
	cnt1=2*x
	cnts=1 if x==y else 0
	cntdd=1 if x-AB[0]>=0 else 0
	cntdu=1 if AB[1]-y>=0 and (AB[1]+1)*(x-AB[1]+y)>=ab else 0 #x-i, y+i=c,b->c,b+1
	print(cnt1-cnts-cntdd-cntdu)

Submission status: Runtime Error

Solution code:
import math
q=int(input())
for j in range(q):
	AB=[int(i) for i in input().split()]
	AB.sort()#4,11
	ab=AB[0]*AB[1] #44
	for i in range(AB[0],AB[1]+1):
		if i*i>=ab:
			x=i-1
			break
	for i in range(x,ab+1):
		if x*i>=ab:
			y=i-1
			break
	cnt1=2*x
	cnts=1 if x==y else 0
	cntdd=1 if x-AB[0]>=0 else 0
	cntdu=1 if AB[1]-y>=0 and (AB[1]+1)*(x-AB[1]+y)>=ab else 0 #x-i, y+i=c,b->c,b+1
	print(cnt1-cnts-cntdd-cntdu)

Submission status: Runtime Error

Solution code:
from math import sqrt

Q = int(input())

for i in range(Q):
    A,B = map(int, input().split())
    m=A*B
    if A==B or B==A+1:
        ans = 2*A-2
    elif A==B+1
        ans = 2*B-2

    C = int(sqrt(m))
    if C*C==m:
        C=C-1

    if C*(C+1)<m:
        ans = 2*C-1
    else:
            ans = 2*C-2
    print(ans)

Submission status: Runtime Error

Solution code:
from math import sqrt

Q = int(input())

for i in range(Q):
    A,B = map(int, input().split())
    m=A*B
    if A==B or B=A+1:
        ans = 2*A-2
    elif A=B+1
        ans = 2*B-2

    C = int(sqrt(m))
    if C*C==m:
        C=C-1

    if C*(C+1)<m:
        ans = 2*C-1
    else:
            ans = 2*C-2
    print(ans)

Submission status: Runtime Error

Solution code:
q=int(input())
for i in range(q):
    a,b=map(int,input().split())
    left=0
    right=a*b
    for i in range(100):
        mid=(left+right)//2
        if mid*mid<a*b:
            left=mid
        else:
            right=mid
    ret=left*2
    if (a*b-1)//left==left:
        ret-=1
    if min(a,b)<=left:
        ret-=1
    print(ret)

Submission status: Runtime Error

Solution code:
^C⏎
import math

q = int(input())
for _ in range(q):
    a, b = map(int, input().split())
    c = int(math.sqrt(a * b))
    if a * b < 1000:
        ans = 0
        prv = a * b
        for i in range(1, a * b):
            if i == a:
                 continue
            for j in range(prv - 1, 0, -1):
                if j == b:
                    continue
                if i * j < a * b:
                    ans += 1
                    prv = j
                    break
    elif a == b:
        ans = 2 * c - 2
    elif a * b == c * c:
        ans = 2 * c - 1
    elif c * (c + 1) < a * b:
        ans = 2 * c - 1
    else:
        ans = 2 * c - 2
    print(ans)

Submission status: Runtime Error

Solution code:
q=int(input())
while q>0:
    q-=1
    a,b=map(int,input().split())
    s=int((a*b-1)**0.5)
    ret=2*s
    if (a*b-1)//s==s:
        ret-=1
    if min(a,b)<=s:
        ret-=1
    print(ret)

Submission status: Runtime Error

Solution code:
import math

Q = int(input())
ABs = [list(map(int, input().split())) for i in range(Q)]

for A, B in ABs:
    n = math.floor(math.sqrt(A * B - 1))
    ans = 2 * n

    if (A * B - 1) // n == n:
        ans -= 1
    if A <= n:
        ans -= 1
    if B <= n - 1:
        ans -= 1

    print(ans)

Submission status: Runtime Error

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
y=[]
for i in range(q):
 y.append(i2())

for a,b in y:
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if  (x//c)==c:
   z-=1
 if x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)

Submission status: Runtime Error

Solution code:
def dfs(v, visited):

    for u in edges[v]:
        if u in visited:
            continue
        visited.add(u)
        if matched[u] == -1 or dfs(matched[u], visited):
            matched[u] = v
            return True
    return False

Q = int(input())
a = []
b = []
for _ in range(Q):
    inp = input().split()
    a.append(int(inp[0]))
    b.append(int(inp[1]))


for i in range(Q):
    ma = max(a[i], b[i])
    mi = min(a[i], b[i])
    edges = [set()]
    matched = [-1] * ma * mi

    for j in range(1, ma * mi):
        if j == ma:
            edges.append([])
            continue

        max_num = ma * mi // j
        if max_num * j == ma * mi:
            max_num -= 1

        edges.append(list(range(1, max_num + 1)))
        if mi in edges[j]:
            edges[j].remove(mi)

    print(sum(dfs(s, set()) for s in range(ma * mi)))

Submission status: Runtime Error

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
for i in range(q):
 [a,b]=i2()
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if  (x//c)==c:
   z-=1
 if x%c==0 and (x//c-1)==c:
   z-=1
 if a<=c:
   z-=1
 if b<=c:
   z-=1
 print(z)

Submission status: Runtime Error

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

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

def reads():
  return [int(x) for x in input().split()]

Q = read()

for _ in range(Q):
  (A, B) = reads()
  P = A * B - 1
  sqrt = int(P ** 0.5)
  
  if P // sqrt == sqrt:
    ans = sqrt * 2 - 1
  else:
    ans = sqrt * 2

  if A <= sqrt:
    ans -= 1
  if B <= sqrt:
    ans -= 1

  print(ans)

Submission status: Runtime Error

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
q=i1()
import math
for i in range(q):
 [a,b]=i2()
 x=a*b
 c=int(math.sqrt(x))
 if c**2==x:
    c-=1
 z=2*c
 if  int(x//c)==c:
   z-=1
 if x%c==0 and (int(x//c)-1)==c:
   z-=1
 if a<=c :
   z-=1
 if b<=c:
   z-=1
 print(z)

Submission status: Runtime Error

Solution code:
Q = int(input())
for i in range(Q):
	A,B = map(int,input().split())
	score = A * B
	root = int((score-1) ** 0.5)
	ans = 2 * root
	if root >= A:
		ans -= 1
	if root >= B:
		ans -= 1
	if (score - 1) // root == root:
		ans -= 1
	if (score - 1) // root == A or (score - 1) // root == B:
		ans -= 1
	print(ans)

Submission status: Runtime Error

Solution code:
Q = int(input())
for i in range(Q):
	A,B = map(int,input().split())
	score = A * B
	root = int((score-1) ** 0.5)
	ans = 2 * root
	if root >= A:
		ans -= 1
	if root >= B:
		ans -= 1
	if root * root == score - 1:
		ans -= 1
	if (score - 1) // root == A or (score - 1) // root == B:
		ans -= 1
	print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    q = f.read_int()

    res = []
    for _ in xrange(q):
        a, b = f.read_int_list()
        sq = int(math.sqrt(a*b-1))
        ans = sq*2
        if (a*b-1)/sq == sq: ans -= 1
        if a <= sq: ans -= 1
        if b <= sq: ans -= 1
        res.append(str(ans))

    return "\n".join(res)


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)