using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;

namespace HW1
{

    public class Program
    {

        static void swap(List<int> arr, int i, int j)
        {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());

            for (int z = 0; z < n; z++)
            {
                int[] nk = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);

                double half = Math.Floor((double)nk[1]/2);

                if (nk[0] >= nk[1])
                {
                    int each = nk[0] / nk[1];
                    int r = nk[0] % nk[1];

                    if (r <= 1)
                    {
                        Console.WriteLine(nk[0]);
                        continue;
                    }
                    else
                    {
                        int s = each * nk[1];
                        for (int i = 0; i < half && s <= nk[0]; i++)
                        {
                            s++;
                        }

                        Console.WriteLine(s);
                    }
                }
                else
                {

                    if(nk[1] - nk[0] <= 1)
                        Console.WriteLine(nk[0]);
                    else
                        Console.WriteLine(0);

                }

            }

            return;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;

namespace HW1
{

    public class Program
    {

        static void swap(List<int> arr, int i, int j)
        {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());

            for (int z = 0; z < n; z++)
            {
                int[] nk = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);

                double half = Math.Floor((double)nk[1]/2);

                if (nk[0] >= nk[1])
                {
                    int each = nk[0] / nk[1];
                    int r = nk[0] % nk[1];

                    if (r <= 1)
                    {
                        Console.WriteLine(nk[0]);
                        continue;
                    }
                    else
                    {
                        int s = each * nk[1];
                        for (int i = 0; i < half && s <= nk[0]; i++)
                        {
                            s++;
                        }

                        Console.WriteLine(s);
                    }
                }
                else
                {

                    Console.WriteLine(half <= nk[0] ? half : nk[0]);

                }

            }

            return;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;

namespace HW1
{

    public class Program
    {

        static void swap(List<int> arr, int i, int j)
        {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());

            for (int z = 0; z < n; z++)
            {
                int[] nk = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);

                double half = Math.Floor((double)nk[1]/2);
                int each = nk[0] / nk[1];
                int r = nk[0] % nk[1];

                if (r <= 1)
                {
                    Console.WriteLine(nk[0]);
                    continue;
                }
                else
                {
                    int s = each * nk[1];
                    for (int i = 0; i < half && s <= nk[0]; i++)
                    {
                        s++;
                    }
                    Console.WriteLine(s);
                }

            }

            return;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;

namespace HW1
{

    public class Program
    {

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());

            for (int z = 0; z < n; z++)
            {
                int[] nk = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);

                double half = Math.Floor((double)nk[1]/2);

                if (nk[0] >= nk[1])
                {
                    long each = nk[0] / nk[1];
                    int r = nk[0] % nk[1];

                    if (r <= 1)
                    {
                        Console.WriteLine(nk[0]);
                        continue;
                    }
                    else
                    {
                        long s = each * nk[1];
                        s += (half < nk[0] - s) ? (int)half : nk[0]-s;
                        Console.WriteLine(s);
                    }
                }
                else
                {

                    Console.WriteLine(half <= nk[0] ? half : nk[0]);

                }

            }

            return;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;

namespace HW1
{

    public class Program
    {

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());

            for (int z = 0; z < n; z++)
            {
                int[] nk = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);

                double half = Math.Floor((double)nk[1]/2);

                if (nk[0] >= nk[1])
                {
                    long each = nk[0] / nk[1];
                    int r = nk[0] % nk[1];

                    if (r <= 1)
                    {
                        Console.WriteLine(nk[0]);
                        continue;
                    }
                    else
                    {
                        long s = each * nk[1];
                        for (int i = 0; i < half && s <= nk[0]; i++)
                        {
                            s++;
                        }

                        Console.WriteLine(s);
                    }
                }
                else
                {

                    Console.WriteLine(half <= nk[0] ? half : nk[0]);

                }

            }

            return;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;

namespace HW1
{

    public class Program
    {

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());

            for (int z = 0; z < n; z++)
            {
                int[] nk = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);

                double half = Math.Floor((double)nk[1]/2);

                if (nk[0] >= nk[1])
                {
                    long each = nk[0] / nk[1];
                    int r = nk[0] % nk[1];

                    if (r <= 1)
                    {
                        Console.WriteLine(nk[0]);
                        continue;
                    }
                    else
                    {
                        long s = each * nk[1];
                        s += (half < nk[0] - s) ? (int)half : nk[0];
                        Console.WriteLine(s);
                    }
                }
                else
                {

                    Console.WriteLine(half <= nk[0] ? half : nk[0]);

                }

            }

            return;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            var q = int.Parse(Console.ReadLine());
            while(--q >= 0)
            {
                var nk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                var n = nk[0];
                var k = nk[1];

                var maxDiff = k / 2;

                var modDiff = n % k;
                int maxN = 0;
                if(modDiff > 0 && modDiff <= maxDiff)
                {
                    maxN = n;
                }
                else if(modDiff == 0)
                {
                    maxN = n;
                }
                else if(modDiff > maxDiff)
                {
                    maxN = n - (modDiff - maxDiff);
                }
                Console.WriteLine(maxN);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;

class Program {
    static void Main(string[] args) {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        var solver = new Solver(sw);
        // var t = new Thread(solver.solve, 1 << 26); // 64 MB
        // t.Start();
        // t.Join();
        solver.solve();
        sw.Flush();
    }
}

class Solver {
    StreamWriter sw;
    Scan sc;
    void Prt(string a) => sw.WriteLine(a);
    void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
    void Prt(params object[] a) => Prt(string.Join(" ", a));
    public Solver(StreamWriter sw) {
        this.sw = sw;
        this.sc = new Scan();
    }

    public void solve() {
        int T = sc.Int;
        for (int i = 0; i < T; i++)
        {
            int n, k;
            sc.Multi(out n, out k);
            Prt(n / k * k + Math.Min(n % k, k / 2));
        }
    }
}

class pair<T, U> : IComparable<pair<T, U>> {
    public T v1;
    public U v2;
    public pair() : this(default(T), default(U)) {}
    public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; }
    public int CompareTo(pair<T, U> a) {
        int c = Comparer<T>.Default.Compare(v1, a.v1);
        return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2);
    }
    public override string ToString() => v1 + " " + v2;
    public void Deconstruct(out T a, out U b) { a = v1; b = v2; }
}
static class util {
    public static readonly int M = 1000000007;
    // public static readonly int M = 998244353;
    public static readonly long LM = 1L << 60;
    public static readonly double eps = 1e-11;
    public static void DBG(string a) => Console.Error.WriteLine(a);
    public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
    public static void DBG(params object[] a) => DBG(string.Join(" ", a));
    public static void Assert(bool cond) { if (!cond) throw new Exception(); }
    public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2);
    public static int CompareList<T>(IList<T> a, IList<T> b) where T : IComparable<T> {
        for (int i = 0; i < a.Count && i < b.Count; i++)
            if (a[i].CompareTo(b[i]) != 0) return a[i].CompareTo(b[i]);
        return a.Count.CompareTo(b.Count);
    }
    public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w;
    static readonly int[] dd = { 0, 1, 0, -1 };
    // static readonly string dstring = "RDLU";
    public static P[] adjacents(int i, int j)
        => Enumerable.Range(0, dd.Length).Select(k => new P(i + dd[k], j + dd[k ^ 1])).ToArray();
    public static P[] adjacents(int i, int j, int h, int w)
        => Enumerable.Range(0, dd.Length).Select(k => new P(i + dd[k], j + dd[k ^ 1]))
                                         .Where(p => inside(p.v1, p.v2, h, w)).ToArray();
    public static P[] adjacents(this P p) => adjacents(p.v1, p.v2);
    public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w);
    public static Dictionary<T, int> compress<T>(this IEnumerable<T> a)
        => a.Distinct().OrderBy(v => v).Select((v, i) => new { v, i }).ToDictionary(p => p.v, p => p.i);
    public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union));
    public static T[] inv<T>(this Dictionary<T, int> dic) {
        var res = new T[dic.Count];
        foreach (var item in dic) res[item.Value] = item.Key;
        return res;
    }
    public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; }
    public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; }
    public static T[] copy<T>(this IList<T> a) {
        var ret = new T[a.Count];
        for (int i = 0; i < a.Count; i++) ret[i] = a[i];
        return ret;
    }
}

class Scan {
    StreamReader sr;
    public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }
    public Scan(string path) { sr = new StreamReader(path); }
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public string Str => sr.ReadLine().Trim();
    public pair<T, U> Pair<T, U>() {
        T a; U b;
        Multi(out a, out b);
        return new pair<T, U>(a, b);
    }
    public P P => Pair<int, int>();
    public int[] IntArr => StrArr.Select(int.Parse).ToArray();
    public long[] LongArr => StrArr.Select(long.Parse).ToArray();
    public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
    public string[] StrArr => Str.Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries);
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    T cv<T>(string s) => eq<T, int>()    ? ct<T, int>(int.Parse(s))
                       : eq<T, long>()   ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, char>()   ? ct<T, char>(s[0])
                                         : ct<T, string>(s);
    public void Multi<T>(out T a) => a = cv<T>(Str);
    public void Multi<T, U>(out T a, out U b)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); }
    public void Multi<T, U, V>(out T a, out U b, out V c)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); }
    public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); }
    public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
    { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> mas = new List<string>();int konf =0;
            for (int i = int.Parse(Console.ReadLine()); i > 0; i--) {
                int[] m = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                konf = 0;
                konf = ((m[0] / m[1]) * m[1]);
                if (m[0] % m[1] > m[1] / 2)
                    konf += m[1] / 2;
                else
                    konf += m[0] % m[1];
                mas.Add(konf.ToString());
            }foreach (string i in mas)
                Console.WriteLine(i);
        }
    }
}


using System;

namespace Codeforces
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            while (t-- > 0)
                Solve();
        }

        static void Solve()
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int a, kidsWithMax, upperBound;

            a = input[0] / input[1];
            kidsWithMax = input[0] % input[1];
            upperBound = input[1] / 2;

            if (kidsWithMax > upperBound)
            {
                Console.WriteLine(a * input[1] + upperBound);
            }
            else
            {
                Console.WriteLine(a * input[1] + kidsWithMax);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace OlimpTask
{
    class MainClass
    {
        public static void Main(string[] args)
        {
#if LOCAL
            TextReader sourceFileReader = new StreamReader(new FileInfo(@"../../input.txt").FullName);
            Console.SetIn(sourceFileReader);
            TextWriter sourceFileWriter = new StreamWriter(new FileInfo(@"../../output.txt").FullName);
            Console.SetOut(sourceFileWriter);
#endif

            new Solution().Solve();

#if LOCAL
            sourceFileReader.Close();
            sourceFileWriter.Close();
#endif
        }
    }

    public static class ClassExtensions
    {
        public static bool IsSorted<T>(this IList<T> list) where T: IComparable
        {
            if (list.Count < 2)
            {
                return true;
            }

            if (list.First().CompareTo(list.Last()) > 0)
            {
                return false;
            }

            for (int i = 0; i + 1 < list.Count; i++)
            {
                if (list[i].CompareTo(list[i + 1]) > 0)
                {
                    return false;
                }
            }

            return true;
        }
    }

    class SolutionBase
    {
        private static T ParseValue<T>(string input)
        {
            if (typeof(T).Name == "String")
            {
                return (T)(object)input;
            }

            var targetParseMethod = typeof(T).GetMethods().FirstOrDefault(method =>
            {
                if (method.Name != "Parse")
                {
                    return false;
                }

                var parameters = method.GetParameters();
                return parameters.Length == 1 && parameters[0].ParameterType.Name == "String";
            });

            if (targetParseMethod == null)
            {
                throw new Exception($"'Parse' method is not found for type '{typeof(T).Name}'");
            }

            object methodResult = targetParseMethod.Invoke(null, new object[] { input });
            return (T)methodResult;
        }

        protected static T ReadValue<T>()
        {
            string input = Console.ReadLine();
            return ParseValue<T>(input);
        }

        protected static T[] ReadArray<T>()
        {
            string input = Console.ReadLine();
            string[] parts = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            return parts.Select(part => ParseValue<T>(part)).ToArray();
        }
    }

    class Solution: SolutionBase
    {
        public void Solve()
        {
            int t = ReadValue<int>();
            for(int i = 0; i < t; i++)
            {
                SolveTestCase();
            }
        }

        private void SolveTestCase()
        {
            int[] nk = ReadArray<int>();
            int mm = (nk[0] / nk[1]) * nk[1];
            int mod = Math.Min(nk[1] / 2, nk[0] % nk[1]);
            Console.WriteLine(mm + mod);
        }
    }
}


using System;
using System.Linq;

class B
{
	static void Main() => Console.WriteLine(string.Join("\n", new int[int.Parse(Console.ReadLine())].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).Select(x => MaxCandies(x[0], x[1]))));
	static int MaxCandies(int n, int k) => Math.Min(n, n / k * k + k / 2);
}


// Problem: 1283B - Candies Division
// Author: Gusztav Szmolik

using System;

class CandiesDivision
    {
    static int Main ()
        {
        string line = Console.ReadLine ();
        if (line == null)
            return -1;
        char[] delims = {' ', '\t'};
        string[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);
        if (words.Length != 1)
            return -1;
        ushort t;
        if (!UInt16.TryParse (words[0], out t))
            return -1;
        if (t < 1 || t > 50000)
            return -1;
        for (ushort i = 0; i < t; i++)
            {
            line = Console.ReadLine ();
            if (line == null)
                return -1;
            words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);
            if (words.Length != 2)
                return -1;
            uint n;
            if (!UInt32.TryParse (words[0], out n))
                return -1;
            if (n < 1 || n > 1000000000)
                return -1;
            uint k;
            if (!UInt32.TryParse (words[1], out k))
                return -1;
            if (k < 1 || k > 1000000000)
                return -1;
            uint candidRemain = n;
            uint ans = k*(n/k);
            candidRemain -= ans;
            uint halfNumKid = k/2;
            ans += (candidRemain < halfNumKid ? candidRemain : halfNumKid);
            Console.WriteLine (ans);
            }
        return 0;
        }
    }


// Problem: 1283B - Candies Division
// Author: Gusztav Szmolik

using System;

class CandiesDivision
    {
    static int Main ()
        {
        string line = Console.ReadLine ();
        if (line == null)
            return -1;
        char[] delims = {' ', '\t'};
        string[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);
        if (words.Length != 1)
            return -1;
        ushort t;
        if (!UInt16.TryParse (words[0], out t))
            return -1;
        if (t < 1 || t > 50000)
            return -1;
        for (ushort i = 0; i < t; i++)
            {
            line = Console.ReadLine ();
            if (line == null)
                return -1;
            words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);
            if (words.Length != 2)
                return -1;
            uint n;
            if (!UInt32.TryParse (words[0], out n))
                return -1;
            if (n < 1 || n > 1000000000)
                return -1;
            uint k;
            if (!UInt32.TryParse (words[1], out k))
                return -1;
            if (k < 1 || k > 1000000000)
                return -1;
            uint candidRemain = n;
            uint ans = k*(n/k);
            candidRemain = ans;
            uint halfNumKid = k/2;
            ans += (candidRemain < halfNumKid ? candidRemain : halfNumKid);
            Console.WriteLine (ans);
            }
        return 0;
        }
    }


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {

            int question = int.Parse(Console.ReadLine());
            string[] input;
            int candy = 0;
            int child = 0;
            int exCandy = 0;
            int sCandy = 0;
            for (int i = 0; i < question; i++)
            {
                input = Console.ReadLine().Split(' ');
                candy = int.Parse(input[0]);
                child = int.Parse(input[1]);

                exCandy = candy % child;

                if (exCandy > (child/2))
                {
                    sCandy = exCandy-( child / 2);
                }
                else
                {
                    sCandy = 0;
                }

                Console.WriteLine(candy - sCandy);
            }

            //Console.ReadKey();
        }
    }
}


using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace ForCodeForces
{
    class Program
    {
        public static void Vish()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            for (int j = 0; j < n; j++)
            {
                var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

                if (a[0] - (a[0] / a[1]) * (a[1]) > (a[1] / 2))
                {
                    Console.WriteLine(a[0] / a[1] * a[1] + a[1] / 2);
                }
                else
                {
                    Console.WriteLine(a[0]);
                }
            }
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Vish();
            Console.Out.Flush();
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace MainProject
{
    class Program
    {
        static void Main(string[] args)
        //{
        //    var watch = System.Diagnostics.Stopwatch.StartNew();
        //    SolveProblem Problem = new New_Year_Garland();
        //    Console.WriteLine(Problem.GetType().Name);
        //    Problem.Solve();
        //    watch.Stop();
        //    Console.WriteLine(((double)watch.ElapsedMilliseconds / 1000) + " Sec");
        //    Console.ReadKey();
        //}
        {
            Solve();
            //Console.ReadKey();
        }

        public static void Solve()
        {
            int TestCases = int.Parse(Console.ReadLine());
            while (TestCases > 0)
            {
                SolveMe();
                TestCases--;
            }
        }

        static void SolveMe()
        {
            List<int> HandM = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToList();

            int equal = HandM[0] / HandM[1];

            int remain = HandM[0] % HandM[1];

            int half = HandM[1] / 2;

            int result = 0;
            if (remain <= half)
                result = (equal * HandM[1]) + remain;
            else
                result = (equal * HandM[1]) + half;

            Console.WriteLine(result);
        }

    }
}


fn main(){
   let mut ncase = String::new();
   std::io::stdin().read_line(&mut ncase).unwrap();
   let ncase: i32 = ncase.trim().parse().unwrap();
   for _ in 0..ncase{
      let mut nk = String::new();
      std::io::stdin().read_line(&mut nk).unwrap();
      let mut it = nk.split_whitespace();
      let n: i32 = it.next().unwrap().parse().unwrap();
      let k: i32 = it.next().unwrap().parse().unwrap();
      let r = n%k;
      println!("{}", n-std::cmp::max(r-k/2, 0));
   }
}


#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(dead_code)]

use std::char::*;
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;

macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::f64;

fn min<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { a }
    else { b }
}

fn max<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { b }
    else { a }
}

use std::hash::Hash;
fn inc<T: Hash+Ord>(map:&mut BTreeMap<T,i64>, key:T) {
    let count = map.entry(key).or_insert(0);
    *count += 1;
}

fn digit(ch: char) -> i64 {
    return (ch as u8 - b'0') as i64
}

const MAX:usize = 30;
const INF:i64 = std::i64::MAX;
const MOD:i64 = 1e9 as i64 + 7;

fn main() {
    let t:usize = read();

    'outer: for _ in 0..t {
        let n:i64 = read();
        let k:i64 = read();

        println!("{}", n/k*k + min(k/2, n%k));
    }

}

/*

*/


//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        t: usize,
        p: [(usize, usize); t],
    }
    for (n, k) in p {
        let mut ans = n / k * k;
        let rem = n % k;
        ans += std::cmp::min(rem, k / 2);
        writeln!(out, "{}", ans).ok();
    }
}

fn main() {
    run();
}


macro_rules! parse_line {
    ($t: ty) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let a_str = a_str.trim();
        a_str.parse::<$t>().expect("parse error")
    });
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

#[allow(unused_macros)]
macro_rules! parse_line_to_vec {
    ($t: ty) => {{
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        (a_str
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<$t>>())
    }};
}

use std::io::Write;

fn solve(writer: &mut std::io::BufWriter<std::io::Stdout>) {
    let (n, k) = parse_line!(u32, u32);
    let a = n / k;
    let result = a * k + std::cmp::min(k / 2, n - a * k);
    writeln!(writer, "{}", result).unwrap();
}

fn main() {
    let mut writer = std::io::BufWriter::new(std::io::stdout());
    let tests = parse_line!(usize);
    for _ in 0..tests {
        solve(&mut writer);
    }
}


use std::io::{self, BufRead};
fn main(){
	let stdin = io::stdin();
	let mut input = stdin.lock();
	let mut line = String::new();
	input.read_line(&mut line).unwrap();
	let mut queries: u16 = line.trim().parse().unwrap();
	while queries > 0{
		line.clear();
		input.read_line(&mut line).unwrap();
		let mut numbers = line.split_whitespace();
		let sweets: i32 = numbers.next().unwrap().parse().unwrap();
		let children: i32 = numbers.next().unwrap().parse().unwrap();
		let mut unused = sweets % children;
		unused -= children / 2;
		if unused < 0{
			unused = 0;
		}
		println!("{}", sweets - unused);
		queries -= 1;
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for i := 1; i <= t; i++ {
		var n, k int
		scanf("%d %d\n", &n, &k)
		printf("%d\n", n/k*k+min(n%k, k/2))
	}
}


package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"
)

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// D: Some formulas in the problem were written with typos. The correct formula is: the sum of values "the distance to the nearest Christmas tree" over all people.
func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024*1024)

	t, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	for ; t > 0; t-- {
		line := strings.Split(readLine(reader), " ")
		n, err := strconv.ParseInt(line[0], 10, 64)
		checkError(err)
		k, err := strconv.ParseInt(line[1], 10, 64)
		checkError(err)
		a := n / k
		fmt.Println(a*k + min(n%k, int64(math.Ceil(float64(k/2)))))
	}
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	t := nextInt(sc)
	ans := make([]int, t)
	for i := 0; i < t; i++ {
		n := nextInt(sc)
		k := nextInt(sc)
		given := (n / k) * k
		given += min(k/2, n-given)
		ans[i] = given
	}
	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < t; i++ {
		fmt.Fprintln(wtr, ans[i])
	}
	wtr.Flush()
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n, k int
		fmt.Scan(&n, &k)
		given := (n / k) * k
		given += min(k/2, n-given)
		fmt.Println(given)
	}
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	var tests int

	fmt.Fscanln(reader, &tests)
	for tests > 0 {
		tests--
		var n, k int
		fmt.Fscanln(reader, &n, &k)
		full := n / k
		ans := full * k + min(k / 2, n % k)
		fmt.Fprintln(writer, ans)
		writer.Flush()
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var tests int

	fmt.Fscanln(reader, &tests)
	for tests > 0 {
		tests--
		var n, k int
		fmt.Fscanln(reader, &n, &k)
		full := n / k
		ans := full * k + min(k / 2, n % k)
		fmt.Fprintln(writer, ans)
	}
}


package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var tests int
	fmt.Scan(&tests)
	for tests > 0 {
		tests--
		var n, k int
		fmt.Scan(&n, &k)
		full := n / k
		ans := full * k + min(k / 2, n % k)
		fmt.Println(ans)
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	var tests int

	fmt.Fscanln(reader, &tests)
	for tests > 0 {
		tests--
		var n, k int
		fmt.Fscanln(reader, &n, &k)
		full := n / k
		ans := full * k + min(k / 2, n % k)
		fmt.Fprintln(writer, ans)
	}
	writer.Flush()
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	writer.Flush()
	var tests int

	fmt.Fscanln(reader, &tests)
	for tests > 0 {
		tests--
		var n, k int
		fmt.Fscanln(reader, &n, &k)
		full := n / k
		ans := full * k + min(k / 2, n % k)
		fmt.Fprintln(writer, ans)
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	var tests int

	fmt.Fscanln(reader, &tests)
	for tests > 0 {
		tests--
		var n, k int
		fmt.Fscanln(reader, &n, &k)
		full := n / k
		ans := full * k + min(k / 2, n % k)
		fmt.Fprintln(writer, ans)
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a, b int64) int64 {
	if a <= b {
		return a
	}
	return b
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t int
	var n, k, candies int64
	fmt.Fscanln(reader, &t)
	for i := 0; i < t; i++ {
		fmt.Fscanln(reader, &n, &k)
		candies = (n / k) * k
		if n%k != 0 {
			candies += min((k / 2), n-candies)
		}
		fmt.Fprintln(writer, candies)
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var diffCandy, k float64

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	input := scanner.Text()

	testCount, _ := strconv.Atoi(input)
	var inputList []string
	var candyCount, childCount int

	for i := 0; i < testCount; i++ {
		scanner.Scan()
		input = scanner.Text()

		inputList = strings.Split(input, " ")
		candyCount, _ = strconv.Atoi(inputList[0])
		childCount, _ = strconv.Atoi(inputList[1])

		for ; ; candyCount-- {
			if calc(candyCount, childCount) {
				fmt.Println(candyCount)
				break
			}
		}
	}
}

func calc(candyCount, childCount int) bool {
	diffCandy = float64(candyCount % childCount);
	if diffCandy == 0 {
		return true
	} else {
		k = float64(childCount) / 2

		if diffCandy <= k {
			return true
		}
	}

	return false
}


package main

import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	input := scanner.Text()

	testCount, _ := strconv.Atoi(input)
	var inputList []string
	var candyCount, childCount int

	for i := 0; i < testCount; i++ {
		scanner.Scan()
		input := scanner.Text()

		inputList = strings.Split(input, " ")
		candyCount, _ = strconv.Atoi(inputList[0])
		childCount, _ = strconv.Atoi(inputList[1])

		diffCount := candyCount % childCount

		if diffCount == 0 {
			fmt.Println(candyCount)
		} else {
			for ; ; candyCount-- {
				if calc(candyCount, childCount) {
					fmt.Println(candyCount)
					break
				}
			}
		}
	}
}

func calc(candyCount, childCount int) bool {
	diffCandy := float64(candyCount % childCount);
	if diffCandy == 0 {
		return true
	} else {
		k := float64(childCount) / 2

		if diffCandy <= k {
			return true
		}
	}

	return false
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	input := scanner.Text()

	testCount, _ := strconv.Atoi(input)
	var inputList []string
	var candyCount, childCount int

	for i := 0; i < testCount; i++ {
		scanner.Scan()
		input = scanner.Text()

		inputList = strings.Split(input, " ")
		candyCount, _ = strconv.Atoi(inputList[0])
		childCount, _ = strconv.Atoi(inputList[1])

		candyDiff := candyCount % childCount;
		if candyDiff == 0 {
			fmt.Println(candyCount)
			continue
		}

		baseCandyCount := candyCount - candyDiff
		prevChildCount := childCount / 2

		fmt.Println(min(candyCount, baseCandyCount+prevChildCount))
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}

	return b
}


package main

import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	input := scanner.Text()

	testCount, _ := strconv.Atoi(input)
	var inputList []string
	var candyCount, childCount int

	for i := 0; i < testCount; i++ {
		scanner.Scan()
		input = scanner.Text()

		inputList = strings.Split(input, " ")
		candyCount, _ = strconv.Atoi(inputList[0])
		childCount, _ = strconv.Atoi(inputList[1])

		candyDiff := candyCount % childCount;
		if candyDiff == 0 {
			fmt.Println(candyCount)
			continue
		}

		baseCandyCount := candyCount - candyDiff
		prevChildCount := childCount / 2

		fmt.Println(baseCandyCount + prevChildCount)
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	input := scanner.Text()

	testCount, _ := strconv.Atoi(input)
	var inputList []string
	var candyCount, childCount int

	for i := 0; i < testCount; i++ {
		scanner.Scan()
		input := scanner.Text()

		inputList = strings.Split(input, " ")
		candyCount, _ = strconv.Atoi(inputList[0])
		childCount, _ = strconv.Atoi(inputList[1])

		for ; ; candyCount-- {
			if calc(candyCount, childCount) {
				fmt.Println(candyCount)
				break
			}
		}
	}
}

func calc(candyCount, childCount int) bool {
	diffCandy := float64(candyCount % childCount);
	if diffCandy == 0 {
		return true
	} else {
		k := float64(childCount) / 2

		if diffCandy <= k {
			return true
		}
	}

	return false
}


package main

import (
	"fmt"
)

func divideTheCandy(candy, kids int) {
	modulus := candy % kids
	if modulus >= 0 && modulus <= kids/2 {
		fmt.Println(candy)
	} else if modulus > kids/2 {
		fmt.Println((candy - (candy % kids)) + (kids / 2))
	}
	return
}

func main() {
	inputLn := 0
	fmt.Scanf("%d\n", &inputLn)
	for i := 0; i < inputLn; i++ {
		candy := 0
		kids := 0
		fmt.Scanf("%d %d\n", &candy, &kids)
		divideTheCandy(candy, kids)
	}
}


package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

func divideTheCandy(cases [][]int) {
	for _, v := range cases {
		candy := v[0]
		kids := v[1]
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (candy % kids)) + (kids / 2))
		}
	}
	return
}

func main() {
	stdin, err := os.OpenFile("input.txt",
		os.O_RDONLY|os.O_CREATE, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdin = stdin

	stdout, err := os.OpenFile("output.txt",
		os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdout = stdout
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	var cases [][]int
	for i := 0; i < inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil && err != io.EOF {
			log.Fatalln("Can't read input case!", err)
		}
		var caseStr []string
		caseStr = strings.Split(strings.TrimSuffix(string(input), "\n"), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = append(cases, []int{caseArg1, caseArg2})
	}
	divideTheCandy(cases)
}


package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

func divideTheCandy(cases [][]int) {
	for _, v := range cases {
		candy := v[0]
		kids := v[1]
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (candy % kids)) + (kids / 2))
		}
	}
	return
}

func main() {
	/*stdin, err := os.OpenFile("input.txt",
		os.O_RDONLY, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdin = stdin

	stdout, err := os.OpenFile("output.txt",
		os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdout = stdout*/
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	var cases [][]int
	for i := 0; i < inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil && err != io.EOF {
			log.Fatalln("Can't read input case!", err)
		}
		var caseStr []string
		caseStr = strings.Split(strings.TrimSuffix(string(input), "\n"), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = append(cases, []int{caseArg1, caseArg2})
	}
	divideTheCandy(cases)
}


package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

func divideTheCandy(cases [][]int) {
	fmt.Println(cases)
	for _, v := range cases {
		candy := v[0]
		kids := v[1]
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (candy % kids)) + (kids / 2))
		}
	}
	return
}

func main() {
	/*stdin, err := os.OpenFile("input.txt",
		os.O_RDONLY, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdin = stdin

	stdout, err := os.OpenFile("output.txt",
		os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdout = stdout*/
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	var cases [][]int
	for i := 0; i < inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil && err != io.EOF {
			log.Fatalln("Can't read input case!", err)
		}
		var caseStr []string
		caseStr = strings.Split(strings.TrimSuffix(string(input), "\n"), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = append(cases, []int{caseArg1, caseArg2})
	}
	divideTheCandy(cases)
}


package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func divideTheCandy(cases [][]int) {
	for _, v := range cases {
		candy := v[0]
		kids := v[1]
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Fprintf(os.Stdin, "%d\n", candy)
		} else if modulus > kids/2 {
			fmt.Fprintf(os.Stdin, "%d\n", (candy-(candy%kids))+(kids/2))
		}
	}
	return
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	var cases [][]int
	for i := 0; i < inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil {
			log.Fatalln("Can't read input case!", err)
		}
		caseStr := strings.Split(string(input[:len(input)-1]), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = append(cases, []int{caseArg1, caseArg2})
	}
	divideTheCandy(cases)
}


package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func divideTheCandy(kids, candy int) {
	modulus := candy % kids
	if modulus >= 0 && modulus <= kids/2 {
		fmt.Println(candy)
		return
	} else if modulus > kids/2 {
		fmt.Println((candy - (candy % kids)) + (kids / 2))
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	cases := make([]int, 2)
	for i := 1; i <= inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil {
			log.Fatalln("Can't read input case!", err)
		}
		caseStr := strings.Split(string(input[:len(input)-1]), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = []int{caseArg1, caseArg2}
		divideTheCandy(cases[1], cases[0])
	}
}


package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

func divideTheCandy(cases [][]int) {
	for _, v := range cases {
		candy := v[0]
		kids := v[1]
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (candy % kids)) + (kids / 2))
		}
	}
	return
}

func main() {
	stdin, err := os.OpenFile("input.txt",
		os.O_RDONLY, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdin = stdin

	stdout, err := os.OpenFile("output.txt",
		os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdout = stdout
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	var cases [][]int
	for i := 0; i < inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil && err != io.EOF {
			log.Fatalln("Can't read input case!", err)
		}
		var caseStr []string
		caseStr = strings.Split(strings.TrimSuffix(string(input), "\n"), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = append(cases, []int{caseArg1, caseArg2})
	}
	divideTheCandy(cases)
}


package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func divideTheCandy(cases [][]int) {
	for _, v := range cases {
		candy := v[0]
		kids := v[1]
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (candy % kids)) + (kids / 2))
		}
	}
	return
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	var cases [][]int
	for i := 1; i <= inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil {
			log.Fatalln("Can't read input case!", err)
		}
		caseStr := strings.Split(string(input[:len(input)-1]), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = append(cases, []int{caseArg1, caseArg2})
	}
	divideTheCandy(cases)
}


package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func divideTheCandy(cases [][]int) {
	for _, v := range cases {
		candy := v[0]
		kids := v[1]
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (candy % kids)) + (kids / 2))
		}
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	var cases [][]int
	for i := 1; i <= inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil {
			log.Fatalln("Can't read input case!", err)
		}
		caseStr := strings.Split(string(input[:len(input)-1]), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = append(cases, []int{caseArg1, caseArg2})
	}
	divideTheCandy(cases)
}


package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var inputLn int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d\n", &inputLn)
	candy := 0
	kids := 0
	newline := []byte{'\n'}
	for i := 0; i < inputLn; i++ {
		scanner.Scan()
		inputCase := scanner.Bytes()
		candy, kids = toInt(bytes.Split(inputCase, newline)[0])
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (modulus)) + (kids / 2))
		}
	}
}

func toInt(buf []byte) (int, int) {
	nn := bytes.Split(buf, []byte{' '})
	n, _ := strconv.Atoi(string(nn[0]))
	i, _ := strconv.Atoi(string(nn[1]))
	return n, i
}


package main

import (
	"fmt"
)

func divideTheCandy(cases []int32) {
	v := cases
	candy := v[0]
	kids := v[1]
	modulus := candy % kids
	if modulus >= 0 && modulus <= kids/2 {
		fmt.Println(candy)
	} else if modulus > kids/2 {
		fmt.Println((candy - (candy % kids)) + (kids / 2))
	}
	return
}

func main() {
	/*stdin, err := os.OpenFile("input.txt",
		os.O_RDONLY, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdin = stdin

	stdout, err := os.OpenFile("output.txt",
		os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdout = stdout*/
	inputLn := 0
	fmt.Scanf("%d\n", &inputLn)
	for i := 0; i < inputLn; i++ {
		cases := make([]int32, 2)
		fmt.Scanf("%d %d\n", &cases[0], &cases[1])
		divideTheCandy(cases)
	}
}


package main

import (
	"fmt"
)

func main() {
	inputLn := 0
	fmt.Scanf("%d\n", &inputLn)
	candy := 0
	kids := 0
	for i := 0; i < inputLn; i++ {
		fmt.Scanf("%d %d\n", &candy, &kids)
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (modulus)) + (kids / 2))
		}
	}
}


/************************************/
/* Date		: 2020-01-17 10:17:27	*/
/* Author	: MiohitoKiri5474		*/
/* Email	: lltzpp@gmail.com		*/
/************************************/

// by. MiohitoKiri5474

package main

import (
	"fmt"
	"os"
	"bufio"
)

func min ( a int, b int ) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader ( os.Stdin )
	var t, n, m int
	fmt.Fscan ( in, &t )
	for t > 0 {
		t--
		fmt.Fscan ( in, &n, &m )
		ans := ( n / m )
		ans *= m
		ans += min ( n % m, m / 2 )
		fmt.Println ( ans )
	}
}


package main

import (
    "fmt"
)

func min(a, b int) int {
    if a <= b {
        return a
    }
    return b
}

func solve() (ans int) {
    var n, k int
    fmt.Scanf("%d %d\n", &n, &k)
    var a = n / k
    ans = a * k
    if n % k > 0 {
        ans += min(k / 2, n % k)
    }
    return
}

func main() {
    var t int
    fmt.Scanf("%d\n", &t)
    for i := 0; i < t; i++ {
        fmt.Printf("%d\n", solve())
    }
}


package main

import (
    "bufio"
    "fmt"
    "os"
)

func min(a, b int) int {
    if a <= b {
        return a
    }
    return b
}

func main() {
    reader := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    defer writer.Flush()
    var t, ans int
    fmt.Fscanln(reader, &t)
    for i := 0; i < t; i++ {
        var n, k int
        fmt.Fscanln(reader, &n, &k)
        var a = n / k
        ans = a * k
        if n % k > 0 {
            ans += min(k / 2, n % k)
        }
        fmt.Fprintln(writer, ans)
    }
}


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = floor($b / $c);
     $e = $b % $c;
     if($b < $c)
     {
          print $b . "\n";
     }
     elseif($e == 0)
     {
          print $b . "\n";
     }
     else
     {
          $f = $b - ($e - floor($c / 2));
          print $f . "\n";
     }
}
?>


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = floor($b / $c);
     $e = $b % $c;
     if($e == 0)
     {
          print $b . "\n";
     }
     else
     {
          $f = $b - ($e - floor($c / 2));
          print $f . "\n";
     }
}
?>


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = floor($b / $c);
     $e = $b % $c;
     if($b < $c)
     {
          print min($b, floor($c / 2));
     }
     elseif($e == 0)
     {
          print $b . "\n";
     }
     else
     {
          $f = $b - ($e - floor($c / 2));
          print $f . "\n";
     }
}
?>


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = floor($b / $c);
     $e = $b % $c;
     if($b < $c)
     {
          print min($b, floor($c / 2)) . "\n";
     }
     elseif($e == 0)
     {
          print $b . "\n";
     }
     else
     {
          $f = $b - ($e - floor($c / 2));
          print $f . "\n";
     }
}
?>


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     $d = floor($b / $c);
     $e = $b % $c;
     if($b < $c)
     {
          print min($b, floor($c / 2)) . "\n";
     }
     elseif($e == 0)
     {
          print $b . "\n";
     }
     elseif($b > $c)
     {
          if($e <= floor($c / 2))
          {
               print $b . "\n";
          }
          else
          {
               print $b - ($e - floor($c / 2)) . "\n";
          }
     }
}
?>


<?php
// $stdin = fopen('input.txt', 'r');

$t = intval(trim(fgets(STDIN)));

for ($i = 0; $i<=$t-1; $i++){

	list($n, $k) = explode(' ', trim(fgets(STDIN)));
	$n = intval($n);
	$k = intval($k);

	$ost = $n % $k;

	echo $n - $ost + min($ost, ceil($k/2));

	echo "\n";
}


<?php
$stdin = fopen('input.txt', 'r');

$t = intval(trim(fgets($stdin)));

for ($i = 0; $i<=$t-1; $i++){

	list($n, $k) = explode(' ', trim(fgets(STDIN)));
	$n = intval($n);
	$k = intval($k);

	$ost = $n % $k;

	echo $n - $ost + min($ost, floor($k/2));

	echo "\n";
}


<?php
// $stdin = fopen('input.txt', 'r');

$t = intval(trim(fgets(STDIN)));

for ($i = 0; $i<=$t-1; $i++){

	list($n, $k) = explode(' ', trim(fgets(STDIN)));
	$n = intval($n);
	$k = intval($k);

	$ost = $n % $k;

	echo $n - $ost + min($ost, floor($k/2));

	echo "\n";
}


<?php

declare(strict_types = 1);

function main() {
	$tests = (int) fgets(STDIN);
	while (($tests--) > 0) {
		[$n, $k] = array_map( 'intval', explode( " ", fgets(STDIN) ) );
		$answer = $n - ($n % $k);
		$answer += min((int)($n % $k), (int)($k / 2));
		echo "$answer";
	}
}

main();


<?php

declare(strict_types = 1);

function main() {
	$tests = (int) fgets(STDIN);
	while (($tests--) > 0) {
		[$n, $k] = array_map( 'intval', explode( " ", fgets(STDIN) ) );
		$answer = $n - ($n % $k);
		$answer += min((int)($n % $k), (int)($k / 2));
		echo "$answer\n";
	}
}

main();


<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

function foo($n, $k)
{
    $a = floor($n / $k);

    $od = $n % $k;

    if ($od === 0 || $od === 1) {
        return $n;
    }

    if (($k > $n) && (($k - $n) > (int)($n / 2))) {
        return 0;
    }

    $c = $a * $k;
    $c += floor($k / 2);

    return $c > $n ? $n : $c;
}

$r = 0;

list($t) = fscanf($input, "%d\n");

for ($i = 0; $i < $t; ++$i) {
    list($n, $k) = fscanf($input, "%d %d\n");

    $r = foo($n, $k);

    fwrite($output, $r . PHP_EOL);
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define pb push_back
ll mod=1e9;
ll MOD=1e18+0LL;
int f_div(int n)
{
    for(int i=2;i*i<=n;i++)
        if(n%i==0) return i;
    return -1;
}
int main()
{
    int n;scanf("%d",&n);
    int a[n],b[n],i;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    int mn=1000,id=-1;
    for(i=0;i<n;i++) {b[i]=f_div(a[i]);if(b[i]!=-1&&b[i]<mn) {mn=min(b[i],mn);id=i;} }
    int j;
    if(id!=-1)
    {
        for(i=0;i<n;i++)
        {
            if(i!=id)
            {
                if((a[i]*b[id])<a[id])
                {
                    a[i]=a[i]*b[id];
                    a[id]=b[id];
                    break;
                }
            }
        }
    }int sum=0;
    for(i=0;i<n;i++) sum+=a[i];
    printf("%d",sum);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int prefix[n];
        map<int,int> m;
        prefix[0]=a[0];
        m[prefix[0]]=i;
         int ans=0;
        for(int i=1;i<n;i++)
        {
            prefix[i]=prefix[i-1]^a[i];
              if(m.find(prefix[i])==m.end())
              {
                  m[prefix[i]]=i;
              }
              else{
                  if((i-m[prefix[i]])%2==0)
                  {
                      ans++;
                      m[prefix[i]]=i;
                  }
              }

        }

        cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool isprime(int x)
{
    if(x==2 || x==3 || x==1)
    {
        return true;
    }
    else{
        for(int i=2;i<=sqrt(x);i++)
        {
            if((x%i)==0)
            {
                return false;
            }
        }
        return true;
    }
}
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int w=INT_MIN;
        for(int i=0;i<n;i++)
        {
            if(isprime(a[i])==false)
            {
                w=max(w,a[i]);
            }
        }
        if(w==INT_MIN)
        {
            cout<<sum<<endl;
        }
        else{
        int r=(w/(sqrt(w)));
        sum-=(w-r);
        int e=*min_element(a,a+n);
        int y=(e*sqrt(w));
        sum+=(y-e);
        cout<<sum<<endl;
        }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int p=sum;
        sort(a,a+n);
        int ans=INT_MAX;
        for(int i=1;i<n;i++)
        {
            int x=a[i];
            for(int j=1;j<=sqrt(x);j++)
            {
                if((x%j)==0)
                {
                    int y=(x/j);
                    int g=0;
                    g-=(x-y);
                    int e=(a[0]*j);
                    g+=e-a[0];
                    ans=min(ans,p+g);
                }
            }
        }
        cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int p=sum;
        sort(a,a+n);
        int ans=INT_MAX;
        for(int i=1;i<n;i++)
        {
            int x=a[i];
            for(int j=1;j<=x;j++)
            {
                if((x%j)==0)
                {
                    int y=(x/j);
                    int g=0;
                    g-=(x-y);
                    int e=(a[0]*j);
                    g+=e-a[0];
                    ans=min(ans,p+g);
                    if(ans<sum)
                    {
                        break;
                    }
                }
            }
        }
        cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int p=sum;
        sort(a,a+n);
        int ans=INT_MAX;
        for(int i=1;i<n;i++)
        {
            int x=a[i];
            for(int j=1;j<=x;j++)
            {
                if((x%j)==0)
                {
                    int y=(x/j);
                    int g=0;
                    g-=(x-y);
                    int e=(a[0]*j);
                    g+=e-a[0];
                    ans=min(ans,p+g);
                }
            }
        }
        cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int p=sum;
        sort(a,a+n);
        for(int i=n-1;i>0;i--)
        {
            int x=a[i];
            for(int j=2;j<=sqrt(x);j++)
            {
                if(x%j==0)
                {
                    int y=(x/j);
                    p-=(x-y);
                    int e=(a[0]*j);
                    p+=e-a[0];
                    if(p<sum)
                    {
                        sum=p;
                    }
                }
            }
        }
        cout<<sum<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int p=sum;
        sort(a,a+n);
        int ans=INT_MAX;
        for(int i=1;i<n;i++)
        {
            int x=a[i];
            for(int j=1;j<=x;j++)
            {
                if((x%j)==0)
                {
                    int y=(x/j);
                    p-=(x-y);
                    int e=(a[0]*j);
                    p+=e-a[0];
                    ans=min(ans,p);
                }
            }
        }
        cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int p=sum;
        sort(a,a+n);
        for(int i=n-1;i>0;i--)
        {
            int x=a[i];
            for(int j=2;j<x;j++)
            {
                if(x%j==0)
                {
                    int y=(x/j);
                    p-=(x-y);
                    int e=(a[0]*(j-1));
                    p+=e-a[0];
                    if(p<sum)
                    {
                        sum=p;
                    }
                }
            }
        }
        cout<<sum<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int p=sum;
        sort(a,a+n);
        for(int i=n-1;i>0;i--)
        {
            int x=a[i];
            for(int j=2;j<x;j++)
            {
                if((x%j)==0)
                {
                    int y=(x/j);
                    p-=(x-y);
                    int e=(a[0]*j);
                    p+=e-a[0];
                    if(p<sum && p>0)
                    {
                        sum=p;
                    }
                }
            }
        }
        cout<<sum<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int p=sum;
        sort(a,a+n);
        int ans=INT_MAX;
        for(int i=1;i<n;i++)
        {
            int x=a[i];
            for(int j=1;j<x;j++)
            {
                if(x%j==0)
                {
                    int y=(x/j);
                    p-=(x-y);
                    int e=(a[0]*j);
                    p+=e-a[0];
                    ans=min(ans,p);
                }
            }
        }
        cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int p=sum;
        sort(a,a+n);
        for(int i=n-1;i>0;i--)
        {
            int x=a[i];
            for(int j=1;j<=x;j++)
            {
                if(x%j==0)
                {
                    int y=(x/j);
                    p-=(x-y);
                    int e=(a[0]*j);
                    p+=e-a[0];
                    if(p<sum)
                    {
                        sum=p;
                    }
                }
            }
        }
        cout<<sum<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int p=sum;
        sort(a,a+n);
        int ans=INT_MAX;
        for(int i=1;i<n;i++)
        {
            int x=a[i];
            for(int j=2;j<=sqrt(x);j++)
            {
                if((x%j)==0)
                {
                    int y=(x/j);
                    int g=0;
                    g-=(x-y);
                    int e=(a[0]*j);
                    g+=e-a[0];
                    ans=min(ans,p+g);
                }
            }
        }
        cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int p=sum;
        sort(a,a+n);
        for(int i=n-1;i>0;i--)
        {
            int x=a[i];
            for(int j=2;j<x;j++)
            {
                if(x%j==0)
                {
                    int y=(x/j);
                    p-=(x-y);
                    int e=(a[0]*j);
                    p+=e-a[0];
                    if(p<sum)
                    {
                        sum=p;
                    }
                }
            }
        }
        cout<<sum<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool isprime(int x)
{
    if(x==2 || x==3 || x==1)
    {
        return true;
    }
    else{
        for(int i=2;i<=sqrt(x);i++)
        {
            if((x%i)==0)
            {
                return false;
            }
        }
        return true;
    }
}
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int w=INT_MIN;
        for(int i=0;i<n;i++)
        {
            if(isprime(a[i])==false)
            {
                w=max(w,a[i]);
            }
        }
        if(w==INT_MIN)
        {
            cout<<sum<<endl;
        }
        else{
            int j=0;
            int p=sum;
          for(int i=2;i<=sqrt(w);i++)
          {
              if((w%i)==0)
              {
                  j=i;
              }
          }
          int e=(w/j);
          p-=(w-e);
          int g=*min_element(a,a+n);
          int l=(g*j);
          p+=(l-g);
          if(p>=sum)
          {
              cout<<sum<<endl;
          }
          else{
              cout<<p<<endl;
          }
        }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool isprime(int x)
{
    if(x==2 || x==3 || x==1)
    {
        return true;
    }
    else{
        for(int i=2;i<=sqrt(x);i++)
        {
            if((x%i)==0)
            {
                return false;
            }
        }
        return true;
    }
}
int main()
{

        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
        }
        int w=INT_MIN;
        for(int i=0;i<n;i++)
        {
            if(isprime(a[i])==false)
            {
                w=max(w,a[i]);
            }
        }
        if(w==INT_MIN)
        {
            cout<<sum<<endl;
        }
        else{
            int j=0;
            int p=sum;
          for(int i=2;i<=w;i++)
          {
              if((w%i)==0)
              {
                  j=i;
              }
          }
          int e=(w/j);
          p-=(w-e);
          int g=*min_element(a,a+n);
          int l=(g*j);
          p+=(l-g);
          if(p>=sum)
          {
              cout<<sum<<endl;
          }
          else{
              cout<<p<<endl;
          }
        }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    int sum=0,x=1000;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        x=min(x,a[i]);
    }
    for(int i=0;i<n;i++)
    {
        int y,z=sum-x-a[i];
        if(x==a[i])
        {
            continue;
        }
        for(int j=2;j*j<=a[i];j++)
        {
            if(a[i]%j==0)
            {
                y=j;
                sum=min(sum,z+(a[i]/y)+(x*y));
                if(j*j!=a[i])
                {
                    y=a[i]/j;
                    sum=min(sum,z+(a[i]/y)+(x*y));
                }
            }
        }
    }
    cout<<sum<<"\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    int sum=0,x=1000;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        x=min(a,a[i]);
    }
    for(int i=0;i<n;i++)
    {
        int y=0,z=sum-x-a[i];
        if(x==a[i])
        {
            continue;
        }
        for(int j=2;j*j<=a[i];j++)
        {
            if(a[i]%j==0)
            {
                y=max(y,j);
                if(j*j!=a[i])
                {
                    y=max(y,a[i]/j);
                }
            }
        }
        if(y!=0)
        {
            z+=(a[i]/y)+(x*y);
            sum=min(sum,z);
        }
    }
    cout<<sum<<"\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    int sum=0,x=1e9;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        x=min(x,a[i]);
    }
    for(int i=0;i<n;i++)
    {
        int z=sum-x-a[i];
        for(int j=1;j<=a[i];j++)
        {
            if(a[i]%j==0)
            {
                sum=min(sum,z+(a[i]/j)+(x*j));
            }
        }
    }
    cout<<sum<<"\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    int sum=0,x=1000;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        x=min(x,a[i]);
    }
    for(int i=0;i<n;i++)
    {
        int y=0,z=sum-x-a[i];
        if(x==a[i])
        {
            continue;
        }
        for(int j=2;j*j<=a[i];j++)
        {
            if(a[i]%j==0)
            {
                y=max(y,j);
                if(j*j!=a[i])
                {
                    y=max(y,a[i]/j);
                }
            }
        }
        if(y!=0)
        {
            z+=(a[i]/y)+(x*y);
            sum=min(sum,z);
        }
    }
    cout<<sum<<"\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for(int i=n-1;i>=1;i--)
    {
        int x=0;
        for(int j=2;j*j<=a[i];j++)
        {
            if(a[i]%j==0)
            {
                x=max(x,j);
                if(j*j!=a[i])
                {
                    x=max(x,a[i]/j);
                }
            }
        }
        if(x!=0)
        {
            int y=a[i]+a[0];
            a[i]/=x;
            a[0]*=x;
            if((a[i]+a[0])>y)
            {
                a[0]/=x;
                a[i]*=x;
            }
            else
            {
                break;
            }
        }
    }
    for(int i=1;i<n;i++)
    {
        a[i]+=a[i-1];
    }
    cout<<a[n-1]<<"\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    int sum=0,x=1e9;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        x=min(x,a[i]);
    }
    for(int i=0;i<n;i++)
    {
        int z=sum-x-a[i];
        for(int j=1;j<=a[i];j++)
        {
            if(a[i]%j==0)
            {
                z+=a[i]/j+x*j;
                sum=min(sum,z);
            }
        }
    }
    cout<<sum<<"\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    int sum=0,x=1000;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        x=min(x,a[i]);
    }
    for(int i=0;i<n;i++)
    {
        int y,z=sum-x-a[i];
        if(x==a[i])
        {
            continue;
        }
        for(int j=1;j*j<=a[i];j++)
        {
            if(a[i]%j==0)
            {
                y=j;
                sum=min(sum,z+(a[i]/y)+(x*y));
                if(j*j!=a[i])
                {
                    y=a[i]/j;
                    sum=min(sum,z+(a[i]/y)+(x*y));
                }
            }
        }
    }
    cout<<sum<<"\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    int sum=0,x=1e9;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        x=min(x,a[i]);
    }
    int best=sum;
    for(int i=0;i<n;i++)
    {
        if(x==a[i])
        {
            continue;
        }
        for(int j=1;j*j<=a[i];j++)
        {
            if(a[i]%j==0)
            {
                int z=sum-x-a[i];
                best=min(best,z+(a[i]/j)+(x*j));
                if(j*j!=a[i])
                {
                    int y=a[i]/j;
                    best=min(best,z+(a[i]/y)+(x*y));
                }
            }
        }
    }
    cout<<best<<"\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    int sum=0,x=1000;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        x=min(x,a[i]);
    }
    for(int i=0;i<n;i++)
    {
        int y,z=sum-x-a[i];
        for(int j=1;j*j<=a[i];j++)
        {
            if(a[i]%j==0)
            {
                y=j;
                sum=min(sum,(z+(a[i]/y)+(x*y)));
                if(j*j!=a[i])
                {
                    y=a[i]/j;
                    sum=min(sum,(z+(a[i]/y)+(x*y)));
                }
            }
        }
    }
    cout<<sum<<"\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    int sum=0,x=1000;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        x=min(x,a[i]);
    }
    for(int i=0;i<n;i++)
    {
        int y,z=sum-x-a[i];
        if(x==a[i])
        {
            continue;
        }
        for(int j=1;j*j<=a[i];j++)
        {
            if(a[i]%j==0)
            {
                y=j;
                sum=min(sum,(z+(a[i]/y)+(x*y)));
                if(j*j!=a[i])
                {
                    y=a[i]/j;
                    sum=min(sum,(z+(a[i]/y)+(x*y)));
                }
            }
        }
    }
    cout<<sum<<"\n";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for(int i=n-1;i>=1;i--)
    {
        int x=0;
        for(int j=2;j*j<=a[i];j++)
        {
            if(a[i]%j==0)
            {
                x=max(x,j);
                if(j*j!=a[i])
                {
                    x=max(x,a[i]/j);
                }
            }
        }
        if(x!=0)
        {
            a[i]/=x;
            a[0]*=x;
            break;
        }
    }
    for(int i=1;i<n;i++)
    {
        a[i]+=a[i-1];
    }
    cout<<a[n-1]<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define fr(a,b) for(int i=a;i<b;i++)
#define len  length

const int maxn = (int) 1e9 + 7;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int)1e9 + 7;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,sum=0,f=-1;
    cin>>n;
    vector<int> v(n),loda;
    for(int i=0;i<n;i++) {
        cin>>v[i];
        sum+=v[i];
        for(int j=2;j<=sqrt(v[i]);j++){
            if(v[i]%j==0) {
                f=max(f,v[i]);
                loda.push_back(i);
                break;
            }
        }
    }
    if(f==-1){
        cout<<sum<<endl;return 0;
    }
    sort(v.begin(),v.end());
    sort(loda.begin(),loda.end(),greater<int>());
    int b=v[0];
    int lo=-1,flag=0;
    for(int j=0;j<loda.size();j++)

    {   f=v[loda[j]];
        for(int i=2;i<f;i++){
        if(f%i==0){
            int l= v[0] + f;
            int r= f/i + b*i;
            if(l>r){
                lo=max(lo,(l-r)); flag=1;
            }
        }
    }}

    if(flag) cout<< sum-lo<<endl ;
    else cout<<sum<<endl;

}


#include <bits/stdc++.h>
using namespace std;

#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define fr(a,b) for(int i=a;i<b;i++)
#define len  length

const int maxn = (int) 1e9 + 7;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int)1e9 + 7;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,sum=0,f=-1;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) {
        cin>>v[i];
        sum+=v[i];
        for(int j=2;j<=sqrt(v[i]);j++){
            if(v[i]%j==0) {
                f=max(f,v[i]);
                break;
            }
        }
    }
    if(f==-1){
        cout<<sum<<endl;return 0;
    }
    sort(v.begin(),v.end());
    int b=v[0],a=f;
    int lo=INF,flag=0;
    for(int i=2;i<f;i++){
        if(a%i==0){
            int l= v[0] + a;
            int r= a/i + b*i;
            if(l>r){
                lo=min(lo,(l-r)); flag=1;
            }
        }
    }

    if(flag) cout<< sum-lo<<endl ;
    else cout<<sum<<endl;

}


#include <bits/stdc++.h>
using namespace std;

#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define fr(a,b) for(int i=a;i<b;i++)
#define len  length

const int maxn = (int) 1e9 + 7;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int)1e9 + 7;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,sum=0;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) {
        cin>>v[i];
        sum+=v[i];
    }
    sort(v.begin(),v.end());
    int flag=0;
    int lo=-1;
    for(int j=n-1;j>0;j--){
        int f=v[j];
        int b=v[0];
        for(int i=2;i<f;i++){
            if(f%i==0){
                int l= v[0] + f;
                int r= f/i + b*i;
                if(l>r){
                    lo=max(lo,(l-r)); flag=1;
                }
            }
        }
    }

    if(flag) cout<< sum-lo<<endl ;
    else cout<<sum<<endl;

}


#include <bits/stdc++.h>
using namespace std;

#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define fr(a,b) for(int i=a;i<b;i++)
#define len  length

const int maxn = (int) 1e9 + 7;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int)1e9 + 7;

bool prime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,sum=0;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin>>v[i],sum+=v[i];
    sort(v.begin(),v.end());
    int ops=n-1;
    while(prime(v[ops]) && ops>0) ops--;
    int a=v[ops];
    int b=v[0];
    int lo=INF,flag=0;
    for(int i=2;i<v[ops];i++){
        if(a%i==0){
            int l= v[0] + v[ops];
            int r= a/i + b*i;
            if(l>r){
                lo=min(lo,(l-r)); flag=1;
            }
        }
    }

    if(flag) cout<< sum-lo<<endl ;
    else cout<<sum<<endl;

}


#include <bits/stdc++.h>
using namespace std;

#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define fr(a,b) for(int i=a;i<b;i++)
#define len  length

const int maxn = (int) 1e9 + 7;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int)1e9 + 7;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,sum=0,f=-1;
    cin>>n;
    vector<int> v(n),loda;
    for(int i=0;i<n;i++) {
        cin>>v[i];
        sum+=v[i];
        for(int j=2;j<=sqrt(v[i]);j++){
            if(v[i]%j==0) {
                f=max(f,v[i]);
                loda.push_back(i);
                break;
            }
        }
    }
    if(f==-1){
        cout<<sum<<endl;return 0;
    }
    sort(v.begin(),v.end());
    sort(loda.begin(),loda.end(),greater<int>());
    int b=v[0];
    int lo=INF,flag=0;
    for(int j=0;j<loda.size();j++)

    {   f=v[loda[j]];
        for(int i=2;i<f;i++){
        if(f%i==0){
            int l= v[0] + f;
            int r= f/i + b*i;
            if(l>r){
                lo=min(lo,(l-r)); flag=1;
            }
        }
    }}

    if(flag) cout<< sum-lo<<endl ;
    else cout<<sum<<endl;

}


#include <bits/stdc++.h>
using namespace std;

#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define fr(a,b) for(int i=a;i<b;i++)
#define len  length

const int maxn = (int) 1e9 + 7;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int)1e9 + 7;

bool prime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,sum=0;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin>>v[i],sum+=v[i];
    sort(v.begin(),v.end());
    int ops=n-1;
    while(prime(v[ops]) && ops>=0) ops--;
    int a=v[ops];
    int b=v[0];
    int lo=INF,flag=0;
    for(int i=2;i<v[ops];i++){
        if(a%i==0){
            int l= v[0] + v[ops];
            int r= a/i + b*i;
            if(l>r){
                lo=min(lo,(l-r)); flag=1;
            }
        }
    }

    if(flag) cout<< sum-lo<<endl ;
    else cout<<sum<<endl;

}


#include <bits/stdc++.h>
using namespace std;

#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define fr(a,b) for(int i=a;i<b;i++)
#define len  length

const int maxn = (int) 1e9 + 7;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int)1e9 + 7;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,sum=0;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) {
        cin>>v[i];
        sum+=v[i];
    }
    sort(v.begin(),v.end());
    int flag=0;
    int lo=INF;
    for(int j=n-1;j>0;j--){
        int f=v[j];
        int b=v[0];
        for(int i=2;i<f;i++){
            if(f%i==0){
                int l= v[0] + f;
                int r= f/i + b*i;
                if(l>r){
                    lo=min(lo,(l-r)); flag=1;
                }
            }
        }
    }

    if(flag) cout<< sum-lo<<endl ;
    else cout<<sum<<endl;

}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
vector<int> getDivisors(int n)
{  vector<int>divisors;
    // Note that this loop runs till square root
    for (int i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            divisors.push_back(i);
        }
    }
    return divisors;
}

int main() {

	int n;
	cin>>n;
	int arr[n];
	int acumsum=0;
	int cnt_one=0;
	int ans=INT_MAX;
	for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	acumsum+=arr[i];
	  	///if(arr[i]==1)cnt_one++;
	  }
	 //int result = arr[0];
    //for (int i = 1; i < n; i++)
      //  result = gcd(arr[i], result);
        //cout<<result;
   //if(result!=1)
    {
    //	cout<<acumsum;
    }
   //else
    {
    	//if(cnt_one==0)cout<<acumsum;
    	//else
    	{  //cout<<1;
    		sort(arr,arr+n);

    		for(int i=0,j=n-1;i<n&&j>=0&&i!=j;)
    		{

    				if(isPrime(arr[j]))
    				  j--;
    				else
    				{  //cout<<arr[j];
    					vector<int>divisors =getDivisors(arr[j]);
    					int previ=arr[i];
    					int prevj=arr[j];

    					for(int k=0;k<divisors.size();k++)
    					{arr[i]=previ;
    					 arr[j]=prevj;

    					arr[i]*=divisors[k];
    					arr[j]=arr[j]/divisors[k];
    					//cout<<arr[i]<<" "<<arr[j];

    					int  sum=0;

			    		for(int l=0;l<n;l++)
			    		   sum+=arr[l];
			    		   //cout<<sum;
			    		   ans=min(ans,sum);
    					}
    					arr[i]=previ;
    				    arr[j]=prevj;

    				}
    				if(ans>acumsum)
    					  ans=acumsum;
    					cout<<ans;
    					return 0;

    		}

    	}
    }
    cout<<acumsum;

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
vector<int> getDivisors(int n)
{  vector<int>divisors;
    // Note that this loop runs till square root
    for (int i=2; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            divisors.push_back(i);
        }
    }
    return divisors;
}

int main() {

	int n;
	cin>>n;
	int arr[n];
	int acumsum=0;
	int cnt_one=0;
	for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	acumsum+=arr[i];
	  	///if(arr[i]==1)cnt_one++;
	  }
	 //int result = arr[0];
    //for (int i = 1; i < n; i++)
      //  result = gcd(arr[i], result);
        //cout<<result;
   //if(result!=1)
    {
    //	cout<<acumsum;
    }
   //else
    {
    	//if(cnt_one==0)cout<<acumsum;
    	//else
    	{  //cout<<1;
    		sort(arr,arr+n);
    		int ans=INT_MAX;
    		for(int i=0,j=n-1;i<n&&j>=0&&i!=j;)
    		{

    				if(isPrime(arr[j]))
    				  j--;
    				else
    				{  //cout<<arr[j];
    					vector<int>divisors =getDivisors(arr[j]);
    					int previ=arr[i];
    					int prevj=arr[j];

    					for(int k=0;k<divisors.size();k++)
    					{arr[i]=previ;
    					 //cout<<min(divisors[k],arr[j]/divisors[k])<<" "<<max(divisors[k],arr[j]/divisors[k])<<endl;
    					arr[i]*=min(divisors[k],arr[j]/divisors[k]);
    					arr[j]=max(divisors[k],arr[j]/divisors[k]);
    					//cout<<arr[i]<<" "<<arr[j];

    					int  sum=0;

			    		for(int l=0;l<n;l++)
			    		   sum+=arr[l];
			    		   //cout<<sum;
			    		   ans=min(ans,sum);
    					}
    					if(ans>acumsum)
    					  ans=acumsum;
    					cout<<ans;
    					return 0;
    				}

    		}

    	}
    }
    cout<<acumsum;

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
vector<int> getDivisors(int n)
{  vector<int>divisors;
    // Note that this loop runs till square root
    for (int i=2; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            divisors.push_back(i);
        }
    }
    return divisors;
}

int main() {

	int n;
	cin>>n;
	int arr[n];
	int acumsum=0;
	int cnt_one=0;
	for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	acumsum+=arr[i];
	  	if(arr[i]==1)cnt_one++;
	  }
	 int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
        //cout<<result;
    if(result!=1)
    {
    	cout<<acumsum;
    }
     else
    {
    	if(cnt_one==0)cout<<acumsum;
    	else
    	{  //cout<<1;
    		sort(arr,arr+n);
    		for(int i=0,j=n-1;i<n&&j>=0&&i!=j;)
    		{

    				if(isPrime(arr[j]))
    				  j--;
    				else
    				{
    					vector<int>divisors =getDivisors(arr[j]);
    					int previ=arr[i];
    					int prevj=arr[j];
    					int ans=INT_MAX;
    					for(int k=0;k<divisors.size();k++)
    					{arr[i]=previ;

    					arr[i]*=min(divisors[k],arr[j]/divisors[k]);
    					arr[j]=max(divisors[k],arr[j]/divisors[k]);

    					int  sum=0;

			    		for(int l=0;l<n;l++)
			    		   sum+=arr[l];
			    		   //cout<<sum;
			    		   ans=min(ans,sum);
    					}
    					if(ans>acumsum)
    					  ans=acumsum;
    					cout<<ans;
    					break;
    				}

    		}

    	}
    }

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int getDivisors(int n)
{
    // Note that this loop runs till square root
    for (int i=2; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            return i;
        }
    }
}

int main() {

	int n;
	cin>>n;
	int arr[n];
	int acumsum=0;
	int cnt_one=0;
	for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	acumsum+=arr[i];
	  	if(arr[i]==1)cnt_one++;
	  }
	 int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
        //cout<<result;
    if(result!=1)
    {
    	cout<<acumsum;
    }
     else
    {
    	if(cnt_one==0)cout<<acumsum;
    	else
    	{  //cout<<1;
    		sort(arr,arr+n);
    		for(int i=0,j=n-1;i<n&&j>=0&&i!=j;)
    		{

    				if(isPrime(arr[j]))
    				  j--;
    				else
    				{
    					int divisor=getDivisors(arr[j]);
    					//cout<<divisor;
    					arr[i]*=min(divisor,arr[j]/divisor);
    					arr[j]=max(divisor,arr[j]/divisor);
    					break;
    				}

    		}
    		int sum=0;
    		for(int i=0;i<n;i++)
    		   sum+=arr[i];
    		   cout<<sum;
    	}
    }

	return 0;
}