• + 1 comment
    • Implementation in c#
    • Cheers:)
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    class Solution {
    
        static void Main(String[] args) {
            int n = Convert.ToInt32(Console.ReadLine());
            int p = Convert.ToInt32(Console.ReadLine());
            // your code goes here
            int fromBack;
            int fromFront = (int)Math.Ceiling(((float)(p-1))/2);
            
            if(n%2==1){
                fromBack = (n-p)/2;
            }
            else{
                fromBack = (int)Math.Ceiling(((float)(n-p))/2);
            }
            if(fromFront<=fromBack)Console.WriteLine(fromFront);
            else Console.WriteLine(fromBack);  
        }
    }