Problem p02755 (python)

Fixed submission:
class Fraction_Error(Exception):
    pass

from fractions import gcd
#import math
class Fraction():
    ##入力定義
    def __init__(self,Numerator=0,Denominator=1):
        self.a=Numerator
        self.b=Denominator

    #表示定義
    def __str__(self):
        if self.b==1:
            return str(self.a)
        else:
            return str(self.a)+"/"+str(self.b)

    #四則演算定義
    def __add__(self,other):
        c=Fraction()
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        c.a=self.a*other.b+self.b*other.a
        c.b=self.b*other.b
        return Fraction.__reduce(c)

    def __radd__(self,other):
        c=Fraction()
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        c.a=self.a*other.b+self.b*other.a
        c.b=self.b*other.b
        
        return Fraction.__reduce(c)
    
    def __sub__(self,other):
        return self+(-other)

    def __rsub__(self,other):
        return -self+other

    def __mul__(self,other):
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return Fraction.__reduce(Fraction(self.a*other.a,self.b*other.b))

    def __rmul__(self,other):
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return Fraction.__reduce(Fraction(self.a*other.a,self.b*other.b))

    def __floordiv__(self,other):
        if other==Fraction():
            raise Fraction_Error("0除算です.")
        
        H=self/other
        return H.a//H.b

    def __rfloordiv__(self,other):
        if self==Fraction():
            raise Fraction_Error("0除算です.")

        H=other/self
        return H.a//H.b
    
    def __truediv__(self,other):
        if other==Fraction():
            raise Fraction_Error("0除算です.")
        
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return self*Fraction.__inverse(other)

    def __rtruediv__(self,other):
        if self==Fraction():
            raise Fraction_Error("0除算です.")
        
        if not(isinstance(self,Fraction)):
            self=Fraction.Int_to_Fraction(other)
            
        return Fraction.__inverse(self)*other

    def __pow__(self,other):
        if other==0:
            return 1
        n=abs(other)

        g=1
        k=self
        for i in range(int(math.log(n,2))+1):
            if n%2==1:
                g*=k

            k*=k
            n=n>>1

        if other>0:
            return g
        else:
            return 1/g
        
    #比較演算子
    def __eq__(self,other):
        t=self-other
        if isinstance(t,Fraction):
            return t.a==0
        else:
            return t==0
    
    def __nq(self,other):
        return not(self==other)

    def __lt__(self,other):
        t=self-other
        if isinstance(t,Fraction):
            return t.a<0
        else:
            return t<0

    def __le__(self,other):
        return (self<other) or (self==other)

    def __gt__(self,other):
        return -self<-other

    def __ge__(self,other):
        return (other<self) or (self==other)
    
    #その他
    def ToNumber(self):
        return self.a/self.b

    def sign(self):
        s=self.a*self.b
        if s>0:return 1
        elif s==0:return 0
        else:return -1

    def __reduce(self):
        g=gcd(self.a,self.b)
        self.a//=g
        self.b//=g

        if self.b<0:
            self.a*=-1
            self.b*=-1
        return Fraction(self.a,self.b)

    def Int_to_Fraction(self):
        if not(isinstance(self,Fraction)):
            return Fraction(self,1)
        else:return self
        
    def __inverse(self):
        if self==Fraction():
            raise Fraction_Error("0の逆数は存在しまんせん.")
        
        return Fraction.__reduce(Fraction(self.b,self.a))
    
    def __pos__(self):
        return self

    def __neg__(self):
        return Fraction(-self.a,self.b)

    def __abs__(self):
        return max(self,-self)
#--------------------
import math
A,B=map(int,input().split())
alpha=Fraction(8,100)
beta=Fraction(10,100)

m=max(A/alpha,B/beta)
m=math.ceil(m.a/m.b)

M=min((A+1)/alpha,(B+1)/beta)
M=math.floor(M.a/M.b)

if m<M:
    print(m)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
class Fraction_Error(Exception):
    pass

import math
class Fraction():
    ##入力定義
    def __init__(self,Numerator=0,Denominator=1):
        self.a=Numerator
        self.b=Denominator

    #表示定義
    def __str__(self):
        if self.b==1:
            return str(self.a)
        else:
            return str(self.a)+"/"+str(self.b)

    #四則演算定義
    def __add__(self,other):
        c=Fraction()
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        c.a=self.a*other.b+self.b*other.a
        c.b=self.b*other.b
        return Fraction.__reduce(c)

    def __radd__(self,other):
        c=Fraction()
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        c.a=self.a*other.b+self.b*other.a
        c.b=self.b*other.b
        
        return Fraction.__reduce(c)
    
    def __sub__(self,other):
        return self+(-other)

    def __rsub__(self,other):
        return -self+other

    def __mul__(self,other):
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return Fraction.__reduce(Fraction(self.a*other.a,self.b*other.b))

    def __rmul__(self,other):
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return Fraction.__reduce(Fraction(self.a*other.a,self.b*other.b))

    def __floordiv__(self,other):
        if other==Fraction():
            raise Fraction_Error("0除算です.")
        
        H=self/other
        return H.a//H.b

    def __rfloordiv__(self,other):
        if self==Fraction():
            raise Fraction_Error("0除算です.")

        H=other/self
        return H.a//H.b
    
    def __truediv__(self,other):
        if other==Fraction():
            raise Fraction_Error("0除算です.")
        
        if not(isinstance(other,Fraction)):
            other=Fraction.Int_to_Fraction(other)
            
        return self*Fraction.__inverse(other)

    def __rtruediv__(self,other):
        if self==Fraction():
            raise Fraction_Error("0除算です.")
        
        if not(isinstance(self,Fraction)):
            self=Fraction.Int_to_Fraction(other)
            
        return Fraction.__inverse(self)*other

    def __pow__(self,other):
        if other==0:
            return 1
        n=abs(other)

        g=1
        k=self
        for i in range(int(math.log(n,2))+1):
            if n%2==1:
                g*=k

            k*=k
            n=n>>1

        if other>0:
            return g
        else:
            return 1/g
        
    #比較演算子
    def __eq__(self,other):
        t=self-other
        if isinstance(t,Fraction):
            return t.a==0
        else:
            return t==0
    
    def __nq(self,other):
        return not(self==other)

    def __lt__(self,other):
        t=self-other
        if isinstance(t,Fraction):
            return t.a<0
        else:
            return t<0

    def __le__(self,other):
        return (self<other) or (self==other)

    def __gt__(self,other):
        return -self<-other

    def __ge__(self,other):
        return (other<self) or (self==other)
    
    #その他
    def ToNumber(self):
        return self.a/self.b

    def sign(self):
        s=self.a*self.b
        if s>0:return 1
        elif s==0:return 0
        else:return -1

    def __reduce(self):
        g=math.gcd(self.a,self.b)
        self.a//=g
        self.b//=g

        if self.b<0:
            self.a*=-1
            self.b*=-1
        return Fraction(self.a,self.b)

    def Int_to_Fraction(self):
        if not(isinstance(self,Fraction)):
            return Fraction(self,1)
        else:return self
        
    def __inverse(self):
        if self==Fraction():
            raise Fraction_Error("0の逆数は存在しまんせん.")
        
        return Fraction.__reduce(Fraction(self.b,self.a))
    
    def __pos__(self):
        return self

    def __neg__(self):
        return Fraction(-self.a,self.b)

    def __abs__(self):
        return max(self,-self)
#--------------------
import math

A,B=map(int,input().split())
alpha=Fraction(8,100)
beta=Fraction(10,100)

m=max(A/alpha,B/beta)
m=math.ceil(m.a/m.b)

M=min((A+1)/alpha,(B+1)/beta)
M=math.floor(M.a/M.b)

if m<=M:
    print(m)
else:
    print(-1)