Barrel#7375

Barrel (Editorial)

Written By : MathModel

Since is small then we can brute force choices for and and we choose

\min_{-100 \le x,y \le 100}(|x|+|y|)

Complexity \mathcal{O}(201^2).

n=int(input())
ans=10**18
for x in range(-100,100):
    for y in range(-100,100):
        if(5*x+3*y==n):
            ans=min(ans,abs(x)+abs(y))
print(ans)