Problem:


Score : 300 points

Problem Statement

You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:

Choose two among A, B and C, then increase both by 1.

Choose one among A, B and C, then increase it by 2.

It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.

Constraints

0 \leq A,B,C \leq 50

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the minimum number of operations required to make A, B and C all equal.

Sample Input 1

2 5 4

Sample Output 1

2

We can make A, B and C all equal by the following operations:

Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.

Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.

Sample Input 2

2 6 3

Sample Output 2

5

Sample Input 3

31 41 5

Sample Output 3

23



Sample input:
2 5 4


Sample output:
2

Submission status: Accepted

Solution code:
a,b,c=sorted([int(x) for x in raw_input().split()])
tmp=c-b
ans=tmp
a+=tmp
if (c-a)%2:
    ans+=1
    c+=1
ans+=(c-a)/2
print ans

Submission status: Accepted

Solution code:
n = list(map(int, input().split()))
count = 0
while len(set(n)) != 1:
    n.sort()
    if n[2] - n[0] >= 2:
        n[0] += 2
    else:
        n[2] -= 1
    count += 1
print(count)

Submission status: Accepted

Solution code:
a = sorted(list(map(int, input().split())))
op = 0
while a[0] < a[1]:
    op += 1
    if a[1] < a[2]:
        a[0] += 1
        a[1] += 1
    else:
        a[0] += 2
    a.sort()
print(op + a[2] - a[0])

Submission status: Accepted

Solution code:
# C
ABC = sorted(list(map(int, input().split())))

res = 0

res += ABC[2] - ABC[1]
ABC[0] += ABC[2] - ABC[1]
ABC[1] = ABC[2]

if (ABC[2] - ABC[0]) % 2 == 0:
    res += (ABC[2] - ABC[0]) // 2
else:
    res += (ABC[2] - ABC[0]) // 2 + 2
    
print(res)

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 solve(f):
    nums = f.read_int_list()

    mi = min(nums)
    ma = max(nums)

    ans = float('inf')
    for i in xrange(mi, ma+1):
        cnt = 0
        for a in nums:
            if i < a:
                cnt += a-i
            elif (i-a)%2 == 0:
                cnt += (i-a)/2
            else:
                cnt += (i-a)/2 + 2

        ans = min(cnt, ans)

    return ans


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:
arr = sorted(list(map(int, input().split())))

ans = 0
if (arr[1] - arr[0]) % 2 == 1:
  arr[1] += 1
  arr[2] += 1
  ans += 1

ans += (arr[1] - arr[0]) // 2
ans += arr[2] - arr[1]
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

def dist(x,y):
    if x>y:
        return x-y
    else:
        d=y-x
        if d%2==0:
            return d//2
        else:
            return d//2 +2
        
A,B,C = list(map(int,input().split()))

aa = 100000
for N in range(52):
    aa = min(aa,dist(A,N)+dist(B,N)+dist(C,N))
print(aa)

Submission status: Accepted

Solution code:
def cost(fr, to):
    if to <= fr:
        return fr - to
    else:
        d = to - fr
        return (d + 1) // 2 + d % 2


def main():
    a, b, c = map(int, input().split())
    ans = 9999999
    for m in range(min(a, b, c) - 5, max(a, b, c) + 5):
        ans = min(ans, cost(a, m) + cost(b, m) + cost(c, m))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
L=[int(i) for i in input().split()]
L.sort()
L[2]-=L[0]
L[1]-=L[0]
L[0]-=L[0]
M=L[2]-L[1]
L[0]+=M
L[1]+=M
if (L[1]-L[0])%2==0:
    N=(L[1]-L[0])//2
    print(M+N)
else:
    N=(L[1]-L[0])//2
    print(N+M+2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
A, B, C = sorted(list(inpl()))
res = 0
res += (C-B)
A += res
B += res
d, m = divmod(B-A, 2)
res += d+2*m
print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    a, b, c = map(int, input().split())
    su = sum([a, b, c])
    ma = max(a, b, c)
    if (ma * 3 - su) % 2 == 0:
        print((ma * 3 - su) // 2)
    else:
        print(((ma + 1) * 3 - su) // 2)

main()

Submission status: Accepted

Solution code:

a, b, c = map(int,input().split())

max = max(a,b,c)

sa = max - a
sa += max - b
sa += max -c

ans = sa // 2

if sa % 2 == 1:
    ans += 2

print(ans)

Submission status: Accepted

Solution code:
lst = map(int, input().split())
lst = sorted(lst)
a, b, c = lst

if (b - a) % 2 == 0:
    ret = (b - a)//2 + (c - b)
else:
    ret = 1 + (b + 1 - a)//2 + (c - b)
print(ret)

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():
    a = LI()
    a.sort()
    r = 0
    while a[0] != a[2]:
        r += 1
        if a[0] < a[1]:
            a[0] += 2
        else:
            a[0] += 1
            a[1] += 1
        a.sort()


    return r


print(main())

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
ret=0
while a+2<=max([a,b,c]):
    a+=2
    ret+=1
while b+2<=max([a,b,c]):
    b+=2
    ret+=1
while c+2<=max([a,b,c]):
    c+=2
    ret+=1
cnt=0
cnt+=1 if a<max([a,b,c]) else 0
cnt+=1 if b<max([a,b,c]) else 0
cnt+=1 if c<max([a,b,c]) else 0
if cnt==0:
    print(ret)
elif cnt==1:
    print(ret+2)
elif cnt==2:
    print(ret+1)

Submission status: Accepted

Solution code:
arr = list(map(int,input().split()))
a = max(arr)*3 - sum(arr)
if a%2 == 1:
    a += 3
print(a//2)

Submission status: Accepted

Solution code:
a,b,c = sorted(map(int,input().split()))

cost = 0
cost += (b-a)//2
a += cost*2
if a < b:
  c += 1
  a += 1
  cost += 1

cost += c-b
print(cost)

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
m = max(a, b, c)
s = sum((m - a, m - b, m - c))
if s % 2 == 1:
    print(s // 2 + 2)
else:
    print(s // 2)

Submission status: Accepted

Solution code:
def solve(a,b,c):
    return a + b + c - 3 * min([a,b,c])

a, b, c = map(int, raw_input().split())

ans = 1 << 30

for i in range(50):
    for j in range(50):
        for k in range(50):
            ans = min(ans, i + j + k + solve(a+i*2,b+j*2,c+k*2))

print ans

Submission status: Runtime Error

Solution code:
lst = list(map(int, input().split())).sort()

mval = lst[-1]
sval = sum(lst)
cn = mval + (sval-mval) % 2
n = (cn * 3 - sval) // 2
print(n)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
B=[]
ans=0
for i in range(n):
	a,b=map(int,input().split())
	ans+=a
	if a>b:
		B.append(b)
if len(B)==0:
	print(0)
else:
	print(ans-min(B))

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
ans=0
min_b=200_000
for i in range(n):
	a,b=map(int,input().split())
	ans+=a
	if a>b:
		min_b=min(min_b,b)
print(max(ans-min_b,0))

Submission status: Runtime Error

Solution code:
a = list(map(int, input().split( )))

a.sort(reverese = True)

ans = 0
ans += a[0]-a[1]
a[1]+=ans
a[2] += ans
ans += (a[0]-a[2]+1)//2
print(ans)

Submission status: Runtime Error

Solution code:
a = list(map(int, input().split( )))

a.sort()

ans = 0
ans += a[0]-b[0]
a[1]+=ans
a[2] += ans
ans += (a[0]-a[2]+1)//2
print(ans)

Submission status: Runtime Error

Solution code:
*a=map(int,open(0))
m=max(a)
t=m*3-sum(a)
if t%2==1:t+=3
print(t//2)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN =

int a, b, c;

int ans = 0;
int mx = 0;

int dif = 0;
void fix (int x) {
    ans += (mx-x)/2;
    dif += (mx-x)%2;
}
/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();

    cin >> a >> b >> c;
    mx = max({a, b, c});


    fix(a);
    fix(b);
    fix(c);

    if (dif == 2) {
        ans++;
    } else if (dif == 1) {
        ans +=2;
    }

    cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN =

int a, b, c;

int ans = 0;
int mx = 0;

int dif = 0;
void fix (int &x) {
    ans += (mx-x)/2;
    dif += (mx-x)%2;
}
/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();

    cin >> a >> b >> c;
    mx = max({a, b, c});


    fix(a);
    fix(b);
    fix(c);

    if (dif == 2) {
        ans++;
    } else if (dif == 1) {
        ans +=2;
    }

    cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
ABC=map(int,input().split())
ABC.sort()
ans=0
ans+=(ABC[2]-ABC[0])//2
if (ABC[2]-ABC[0])%2==1:
  ans+=(ABC[2]-ABC[0])//2
  ABC[0]=ABC[2]-1
  ans+=(ABC[2]-ABC[1])//2
  if (ABC[2]-ABC[1])%2 == 1:
    ans+=1
  else:
    ans+=2  
else:
  ans+=(ABC[2]-ABC[1])//2
  if (ABC[2]-ABC[1])%2 == 1:
    ans+=2
  else:
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))

a = []
b = []

for i in range(n):
    if i % 2 == 0:
        a.append(l[i])
    else:
        b.append(l[i])

def createMyList(li):
    d = {-1:(0,-1)}
    for e in li:
        if e not in d:
            d[e] = (1,e)
        else:
            d[e] = (d[e][0] + 1, d[e][1])
    return list(reversed(sorted(list(d.values()))))

la = createMyList(a)
lb = createMyList(b)
#print(la)
#print(lb)

if la[0][1] == lb[0][1]:
    ans = n- max(lb[0][0] + la[1][0], la[0][0] +lb[1][0])
else:
    ans = n - (la[0][0] + lb[0][0])
print(ans)

Submission status: Runtime Error

Solution code:
s=list(map(int,input().split()))
a=max(s)*3-sum(s)
if a%2==1
    a+=3
print(a//2)

Submission status: Runtime Error

Solution code:
in = [int(i) for i in input().split(' ')]
A,B,C = in[0],in[1],in[2]
if (A+B+C - max(A,B,C)) % 2 == 0:
  print((3*max(A,B,C) - A - B - C)/2)
else:
  print((3*max(A,B,C) - A - B - C - 1)/2) + 2

Submission status: Runtime Error

Solution code:
A = list(map(int, input().split()))
M = max(A)
S = sum(A)
M += M % 2 != S % 2
print((3 * M - sum) // 2)

Submission status: Runtime Error

Solution code:
N = int(input())
c = -1
s = 0
for i in range(N):
    ai,bi = map(int,input().split())
    s += ai
    if ai > bi:
        if c == -1:
            c = bi
        if bi < c:
            c = bi
if c == -1:
    print(0)
else:
    print(s-c)

Submission status: Runtime Error

Solution code:
from math import sqrt 
Q = int(input())
table=[]
for i in range(Q):
    A,B=map(int,input().split())
    if A>B:
        table.append([B,A])
    else:
        table.append([A,B])
def f(a,b):
    if a==b:
        return 2*a-2
    if a+1==b:
        return 2*a-2
    m = int(sqrt(a*b))
    if m**2 ==a*b:
        return 2*m-3
    if m*(m+1) >= a*b:
        return 2*m -2
    return 2*m-1

ans = []
for a,b in table:
    ans.append(f(a,b))
print('\n'.join(map(str,ans)))

Submission status: Runtime Error

Solution code:
# ANSHUL GAUTAM
# IIIT-D

A,B,C = map(int, input().split())
m = max(A,B,C)
s = sum(m-A,m-B,m-C)
if(s%2 == 0):
	print(s//2)
else:
	print(s//2 + 2)

Submission status: Runtime Error

Solution code:
A, B, C = map(int, input().split(" "))
cnt = 0

if (A%2 == B%2) and (B%2 == C%2):
    pass
else:
    if A%2 == B%2:
        A += 1
        B += 1
        cnt += 1
    elif A%2 == C%2:
        A += 1
        C += 1
        cnt += 1
    else:
        B += 1
        C += 1
        cnt += 1

ABC = sorted([A, B, C])
cnt += (ABC[0] - ABC[1]) / 2
cnt += (ABC[0] - ABC[2]) / 2
print cnt

Submission status: Runtime Error

Solution code:
[a, b, c] = map(int, raw_input().split())

ans = 0
if (a - b) % 2 != 0:
     if (b - c) % 2 != 0:
             a+=1
             c+=1
             ans+=1
     else:
             b+=1
             c+=1
             ans+=1
else:
    if (b - c) % 2 != 0:
            a+=1
            b+=1
            ans+=1

d=max(a, b, c)
print(ans + (3 * d - a - b - c) / 2)

Submission status: Runtime Error

Solution code:
from math import sqrt
Q = int(input())
que = []
for i in range(Q):
    que.append(tuple(map(int, input().split())))
for q in que:
    if q[0] == q[1]:
        print(2*q[0]-2)
    else:
        a = q[0]*q[1]-1
        p = int(sqrt(a))
        if a+1 > p*(p+1):
            print(2*p-1)
        else:
            print(2*p-2)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

debug_mode = True if len(sys.argv) > 1 and sys.argv[1] == "-d" else False
if debug_mode:
    import os
    infile = open(os.path.basename(__file__).replace(".py", ".in"))

    def input():
        return infile.readline()


# ==============================================================


def main():
    a, b, c = list(map(int, input().strip().split()))
    s = sum(a, b, c)
    x = min(a, b, c)
    steps = 0
    while True:
        if s + steps * 2 == 3 * x:
            break
        elif s + steps * 2 < 3 * x:
            steps += 1
        elif s + steps * 2 > 3 * x:
            x += 1
    print(steps)


main()

# ==============================================================

if debug_mode:
    infile.close()

Submission status: Runtime Error

Solution code:

a, b, c = map(int, input().split())

odd = []
even = []

max_val = max(a, b, c)
cnt = 0

for x in [a, b, c]:
    if x & 1:
        odd += 1
    else:
        even += 1

if odd == 0 or even == 0:
    for x in [a, b, c]:
        if x != max_val:
            cnt += int((max_val - x) / 2)
else:
    if (odd == 2 and max_val & 1) or (even == 2 and max_val & 0):
        cnt += 3
    else:
        cnt += 1
    for x in [a, b, c]:
        if x != max_val:
            cnt += int((max_val - x) / 2)

print(cnt)

Submission status: Runtime Error

Solution code:
import math

def slv(A, B):
    A, B = (A, B) if A > B else (B, A)
    
    s = A * B
    c = math.floor(math.sqrt(A * B))
    
    if A == B:
        return 2 * c - 2
    elif c * c < s:
        return 2 * c - 2
    elif c * (c - 1) < s:
        return 2 * c - 3

Q = int(input())
for q in range(Q):
    A, B = map(int, input().split())
    print(slv(A, B))

Submission status: Runtime Error

Solution code:
n=int(input())
a=[0 for i in range(n)]
b=[0 for i in range(n)]
c=[0 for i in range(n)]
for i in range(n):
    a[i],b[i]=[int(i) for i in input().split()]
    c[i]=a[i]*b[i]
#print(a,b)

def keisan(d,e,f):
    count=0
    old_value=10**20
    for j in range(int(d)):
        value=min(old_value,int((d-1)/(j+1)))

#        print(value)

        if old_value==value:
            value-=1

        if value>0:
            if e!=j+1 and f!=value:
                count+=1
                old_value=value
            elif e==j+1:
               pass
            elif f==value:
               pass
        else:
            break
    print(count)

for i in range(n):        
    keisan(c[i],a[i],b[i])

Submission status: Runtime Error

Solution code:
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:
# D
import math
Q = int(input())
A_list = []
B_list = []
for _ in range(Q):
    A, B = map(int, input().split())
    A_list.append(min(A, B))
    B_list.append(max(A, B))
    
for i in range(Q):
    A = A_list[i]
    B = B_list[i]
        
    if A == B:
        print(A+B-2)
        continue
        
    R = int(math.sqrt(A*B-1))
    Q = (A*B-1) // R
    
    if Q <= R+1:
        add = min(Q - A - 1, B - R - 1)    
    elif (Q - R)**2 - 4*(A*B-Q*R) > 0:
        add = int(((Q - R) - math.sqrt((Q - R)**2 - 4*(A*B-Q*R))) / 2)
        if (R + add)*(Q-add) == A*B:
            add -= 1
    else:
        add = 0
    print((A-1) + R + add)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from math import sqrt
def inpl(): return map(int, input().split())
Q = int(input())

def check(X, m):
    if X//m > m:
        return True
    else:
        return False

for q in range(Q):
    A, B = inpl()
    if A > B:
        A, B = B, A

    X = A*B
    if X <= 2:
        print(0)
        continue
    elif X == 3:
        print(1)
        continue
    
    L = int(sqrt(X))
    if L*L == X:
        L -= 1

    ok, ng = 1, X+1
    while ng - ok > 1:
        m = (ok+ng)//2
        if check(X-1, m):
            ok = m
        else:
            ng = m
    
    tmp = L + ok
    
    if A == B:
        print(tmp)
    else:
        if A>1 and X-1//(A-1) == B and X-1//A == B-1:
            print(tmp-2)
        elif (X-1)//A == A:
            print(tmp-2)
        else:
            print(tmp-1)

Submission status: Runtime Error

Solution code:
Q = int(input())
for i in range(Q):
	A,B = map(int,input().split())
	if A == 1 and B == 1:
		print(0)
		continue
	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
	print(ans)

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())
c=int(input())
num=[a,b,c]
num.sort()
ans=((num[2]*3)-(num[0]+num[1]+num[2]))/2
print(ans)