using System;

public class Test
{

	public static void Main()
	{
		// your code goes here
            Int64 n, c1, c2;
            string s1 = Console.ReadLine();
            string[] s2 = new string[10];
            s2 = s1.Split(' ');
            n = Convert.ToInt64(s2[0]);
            c1 = Convert.ToInt64(s2[1]);
            c2 = Convert.ToInt64(s2[2]);

            //Console.WriteLine(Convert.ToSingle(c2));
            string s3 = Console.ReadLine();

            int i = 0;
            Int64 cnt = 0;
            Int64 ans = 1000000000;
            ans *= ans;
            while (i < n) {
                if (s3[i] == '1'){
                    cnt++;
                }
                ++i;
            }
            i = 1;
            while (i <= cnt)
            {
           		Int64 pepC = n,
					g1C = pepC % i,
					g2C = i - g1C;
				Int64 g1p = pepC / i,
					g2p = pepC / i - 1;
				Int64 res = g1C * (c1 + c2*g1p*g1p) + g2C * (c1 + c2*g2p*g2p);
				if (res<ans) ans = res;
                ++i;
            }
            Console.WriteLine(Convert.ToString(ans));
	}
}

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 n, c1, c2;
            string s = Console.ReadLine();
            string[] ar =  s.Split();
            n = int.Parse(ar[0]);
            c1 = int.Parse(ar[1]);
            c2 = int.Parse(ar[2]);

            s = Console.ReadLine();
            int maxx = 0;

            for (int i = 0; i < n; i++)
                if (s[i] == '1')
                    maxx++;
            Int64 res = 1000000000000000000;

            for (int gr = 1; gr <= maxx; gr++)
            {
                Int64 remain = n - gr;
                Int64 eachit = remain / gr + 1;
                Int64 eachNh = eachit + 1;

                Int64 nhieu = remain % gr;
                Int64 it = gr - nhieu;

                Int64 cur = (c1 + c2 * (eachit - 1) * (eachit - 1)) * it + (c1 + c2 * (eachNh - 1)* (eachNh - 1)) * nhieu;
                if (cur < res)
                    res = cur;
            }

            Console.WriteLine("{0}", res);
        }
    }
}

using System;
using System.Linq;

public static class Program
{
    public static void Main()
    {
        var nn = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int n=nn[0];
        int c1=nn[1];
        int c2=nn[2];

        string s= Console.ReadLine();

        int k=0;
        foreach (char c in s)
            if(c=='1')
                k++;

        long ans=2000000000;
        ans=ans*ans;

        for(int i=1; i<=k; i++)
        {
            long sz1=(n/i);
            long sz2=(n/i)+1;

            long k1=i-(n%i);
            long k2=i-k1;
            //Console.WriteLine(k2);

            long tans=k1*(c1+c2*(sz1-1)*(sz1-1));
            tans+=k2*(c1+c2*(sz2-1)*(sz2-1));
            ans=Math.Min(ans,tans);
        }
        Console.WriteLine(ans);
    }
}

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

class Program
{
    static void Main()
    {
        long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long n = input[0], c1 = input[1], c2 = input[2];
        char[] s = Console.ReadLine().ToCharArray();
        long a = 0, b = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '0') a++;
            else b++;
        }
        long Min = long.MaxValue;
        for (long i = 1; i <= b; i++)//number of groups
        {
            long c = (n - i) / i + 1;
            long cnt = (c1 + c2 * c * c) * ((n - i) % i) + (c1 + c2 * (c - 1) * (c - 1)) * (i - (n - i) % i);
            Min = Math.Min(Min, cnt);
        }
        Console.WriteLine(Min);
    }
}

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

namespace codeforces_charp
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 n, c1, c2;
            string s1 = Console.ReadLine();
            string[] s2 = new string[10];
            s2 = s1.Split(' ');
            n = Convert.ToInt64(s2[0]);
            c1 = Convert.ToInt64(s2[1]);
            c2 = Convert.ToInt64(s2[2]);

            //Console.WriteLine(Convert.ToSingle(c2));
            string s3 = Console.ReadLine();

            int i = 0;
            Int64 cnt = 0;
            Int64 ans = 1000000000;
            ans *= ans;
            while (i < n) {
                if (s3[i] == '1'){
                    cnt++;
                }
                ++i;
            }
            //cnt = n;
            Int64 j = 1;
            while (j <= cnt)
            {
                Int64 res = j * c1;
                Int64 ost = n - j;
                Int64 exist = ost / j;
                Int64 big = ost % j;
                Int64 small = j - big;
                res += c2 * (small * exist * exist + big * (exist + 1) * (exist + 1));
                if (ans > res)
                {
                    ans = res;
                }
                //ans = min(ans, res);
                ++j;
            }
            Console.WriteLine(Convert.ToString(ans));
        }
    }
}

using System;
using System.Collections.Generic;
using System.Collections;
using System.Numerics;

class Solution
{
	static void Main() {
		int n,c1,c2;
		string[] inp=Console.ReadLine().Split(' ');
		n=int.Parse(inp[0]);
		c1=int.Parse(inp[1]);
		c2=int.Parse(inp[2]);
		long res=4611686018427387903L;
		string s=Console.ReadLine();
		int pcnt=0;
		for(int i=0;i<n;i++)
			if(s[i]=='1')
				pcnt++;
		for(int i=1;i<=pcnt;i++)
		{
			long largecnt=n%i;
			long smallcnt=i-largecnt;
			long largesz=(n+i-1)/i;
			long smallsz=n/i;
			long cost=(long)c1*i+
					c2*(largecnt*(largesz-1)*(largesz-1)+
							smallcnt*(smallsz-1)*(smallsz-1));
			res=Math.Min(res,cost);
		}
		Console.Out.WriteLine(res);
		Console.Out.Close();
	}
}

using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var nn = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        var n = nn[0];
        var c1 = nn[1];
        var c2 = nn[2];

        string str = Console.ReadLine();
        int k = 0;
        for (var i = 0; i < n; ++i)
        {
            if (str[i] == '1')
            {
                ++k;
            }
        }

        long ans = 9223372036854775807, d;
        for (var i = 1; i <= k; ++i)
        {
            d = i * (c1 + c2) - 2 * n * c2;
            d += c2 * ((n / i) * (n / i) * (i - n % i) + (n / i + 1) * (n / i + 1) * (n % i));
            ans = Math.Min(ans, d);
        }
        Console.WriteLine(ans);
    }
}

using System;
using System.Numerics;

public class Test
{
	public static void Main()
	{
		int[] nk = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        BigInteger n = nk[0];
        BigInteger c1 = nk[1];
        BigInteger c2 = nk[2];
        BigInteger ad = 0, ch = 0;
        string s = Console.ReadLine();
        for (int i = 0; i < n; i++) {
            if (s[i] == '0')
                ch++;
            else
                ad++;
        }
        BigInteger mn = 1000000000000000000;
        mn = mn * mn * mn;
        for (BigInteger i = 1; i <= ad; i++) {
        	BigInteger small = (ch + ad - i) / i;
        	BigInteger big = small + 1;
        	BigInteger cn_big = (ch + ad - i) % i;
        	BigInteger cn_small = i - cn_big;
        	BigInteger x = cn_big * (c1 + c2 * big * big) + cn_small * (c1 + c2 * small * small);
        	if (x < mn)
        		mn = x;
        }
        Console.WriteLine(mn);
	}
}

using System;
using System.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var terms = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long n = terms[0], c1 = terms[1], c2 = terms[2], adults = Console.ReadLine().Count(_ => _ == '1'), min = long.MaxValue;
            for (long count = 1; count <= adults; ++count)
            {
                long sum = n % count * Price(n / count + 1, c1, c2) + (count - n % count) * Price(n / count, c1, c2);
                if (min > sum) min = sum;
            }

            Console.WriteLine(min);
        }

        private static long Price(long x, long c1, long c2)
        {
            return c1 + c2 * (x - 1) * (x - 1);
        }
    }
}

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

namespace ForAll
{
    class Program
    {

        static void Main(string[] args)
        {
            long[] keys = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt64);

            long n = keys[0];
            long c1 = keys[1];
            long c2 = keys[2];

            long Parents = 0;

            foreach (char i in Console.ReadLine())
                if (i == '1')
                    Parents++;
            long minPrice = Int64.MaxValue;
            for (long i = Parents; i > 0; i--)
            {
                long ost = n % i;
                long group = i;
                long sizeOfGroup = n/i;
                if (ost != 0)
                {
                    ost = n - sizeOfGroup * group;

                    long presum = 0;

                    presum += F(sizeOfGroup + 1, c1, c2)*ost;
                    presum += F(sizeOfGroup, c1, c2)*(group-ost);
                    if (minPrice > presum) minPrice = presum;
                }
                else
                {
                    long sum = 0;
                    sum += F(sizeOfGroup, c1, c2)*group;
                    if (minPrice > sum) minPrice = sum;
                }

            }

            Console.WriteLine(minPrice);
        }

        public static long F(long x, long c1, long c2)
        {
            return c1 + c2 * (x - 1) * (x - 1);
        }

    }
}

using System;
using System.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var terms = Console.ReadLine().Split(new[] { ' ' }).Select(long.Parse).ToArray();
            var n = terms[0];
            var c1 = terms[1];
            var c2 = terms[2];

            long adults = Console.ReadLine().Count(_ => _ == '1');
            long children = n - adults;
            var min = long.MaxValue;
            for (long count = children > 0 ? children : 1; count <= adults; ++count)
            {
                long size = n / count;
                long sum = count * Price(size, c1, c2);
                if (n % count != 0) sum += Price(n % count, c1, c2);
                if (sum < min) min = sum;
            }
            Console.WriteLine(min);
        }

        private static long Price(long x, long c1, long c2)
        {
            return c1 + c2 * (x - 1) * (x - 1);
        }
    }
}

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

namespace codeforces_charp
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 n, c1, c2;
            string s1 = Console.ReadLine();
            string[] s2 = new string[10];
            s2 = s1.Split(' ');
            n = Convert.ToInt64(s2[0]);
            c1 = Convert.ToInt64(s2[1]);
            c2 = Convert.ToInt64(s2[2]);

            //Console.WriteLine(Convert.ToSingle(c2));
            string s3 = Console.ReadLine();

            int i = 0;
            Int64 cnt = 0;
            Int64 ans = 1000000000;
            ans *= ans;
            while (i < n) {
                if (s3[i] == '1'){
                    cnt++;
                }
                ++i;
            }
            i = 1;
            while (i < n)
            {
                Int64 res = i * c1;
                Int64 ost = n - i;
                Int64 exist = ost / i;
                Int64 big = ost % i;
                Int64 small = i - big;
                res += c2 * (small * exist * exist + big * (exist + 1) * (exist + 1));
                if (ans > res)
                {
                    ans = res;
                }
                //ans = min(ans, res);
                ++i;
            }
            Console.WriteLine(Convert.ToSingle(ans));
        }
    }
}

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

namespace codeforces_charp
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 n, c1, c2;
            string s1 = Console.ReadLine();
            string[] s2 = new string[10];
            s2 = s1.Split(' ');
            n = Convert.ToInt64(s2[0]);
            c1 = Convert.ToInt64(s2[1]);
            c2 = Convert.ToInt64(s2[2]);

            //Console.WriteLine(Convert.ToSingle(c2));
            string s3 = Console.ReadLine();

            int i = 0;
            Int64 cnt = 0;
            Int64 ans = 1000000000;
            ans *= ans;
            while (i < n) {
                if (s3[i] == '1'){
                    cnt++;
                }
                ++i;
            }
            i = 1;
            while (i <= cnt)
            {
                Int64 res = i * c1;
                Int64 ost = n - i;
                Int64 exist = ost / i;
                Int64 big = ost % i;
                Int64 small = i - big;
                res += c2 * (small * exist * exist + big * (exist + 1) * (exist + 1));
                if (ans > res)
                {
                    ans = res;
                }
                //ans = min(ans, res);
                ++i;
            }
            Console.WriteLine(Convert.ToSingle(ans));
        }
    }
}

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

namespace ForAll
{
    class Program
    {

        static void Main(string[] args)
        {
            int[] keys = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);

            int n = keys[0];
            int c1 = keys[1];
            int c2 = keys[2];

            int Parents = 0;

            foreach (char i in Console.ReadLine())
                if (i == '1')
                    Parents++;
            int minPrice = Int32.MaxValue;
            for (int i = Parents; i > 0; i--)
            {
                int ost = n % i;
                int group = i; int sizeOfGroup = (int)Math.Round((double)n / (double)i);
                if (ost != 0)
                {
                    group--;
                    int j = 0;

                    ost = n - sizeOfGroup * group;

                    int presum = 0;
                    for (; j < ost; j++)
                    {
                        presum += F(sizeOfGroup + 1, c1, c2);
                    }

                    int ostsum = 0;
                    ostsum += F((ost), c1, c2);

                    for (int k = 1; k <= group; k++)
                    {
                        ostsum += F(sizeOfGroup, c1, c2);
                    }

                    for (int k = 1; k <= group - j; k++)
                    {
                        presum += F(sizeOfGroup, c1, c2);
                    }

                    if (minPrice > presum) minPrice = presum;
                    else if (minPrice > ostsum) minPrice = ostsum;
                }
                else
                {
                    int sum = 0;
                    for (int k = 1; k <= group; k++)
                    {
                        sum += F(sizeOfGroup, c1, c2);
                    }

                    if (minPrice > sum) minPrice = sum;
                }

            }

            Console.WriteLine(minPrice);
        }

        public static int F(int x, int c1, int c2)
        {
            return c1 + c2 * (x - 1) * (x - 1);
        }

    }
}

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

namespace ForAll
{
    class Program
    {

        static void Main(string[] args)
        {
            int[] keys = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);

            int n = keys[0];
            int c1 = keys[1];
            int c2 = keys[2];

            int Parents = 0;

            foreach (char i in Console.ReadLine())
                if (i == '1')
                    Parents++;
            int minPrice = Int32.MaxValue;
            for (int i = Parents; i > 0; i--)
            {
                int ost = n % i;
                int group = i;
                int sizeOfGroup = n/i;
                if (ost != 0)
                {
                    //group--;
                    int j = 0;

                    ost = n - sizeOfGroup * group;

                    int presum = 0;
                    for (; j < ost; j++)
                    {
                        presum += F(sizeOfGroup + 1, c1, c2);
                    }

                    for (int k = 1; k <= group - j; k++)
                    {
                        presum += F(sizeOfGroup, c1, c2);
                    }

                    if (minPrice > presum) minPrice = presum;
                }
                else
                {
                    int sum = 0;
                    for (int k = 1; k <= group; k++)
                    {
                        sum += F(sizeOfGroup, c1, c2);
                    }

                    if (minPrice > sum) minPrice = sum;
                }

            }

            Console.WriteLine(minPrice);
        }

        public static int F(int x, int c1, int c2)
        {
            return c1 + c2 * (x - 1) * (x - 1);
        }

    }
}

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

namespace ForAll
{
    class Program
    {

        static void Main(string[] args)
        {
            long[] keys = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt64);

            long n = keys[0];
            long c1 = keys[1];
            long c2 = keys[2];

            long Parents = 0;

            foreach (char i in Console.ReadLine())
                if (i == '1')
                    Parents++;
            long minPrice = Int64.MaxValue;
            for (long i = Parents; i > 0; i--)
            {
                long ost = n % i;
                long group = i;
                long sizeOfGroup = n/i;
                if (ost != 0)
                {
                    //group--;
                    long j = 0;

                    ost = n - sizeOfGroup * group;

                    long presum = 0;
                    presum += F(sizeOfGroup + 1, c1, c2) * ost;
                    presum+= F(sizeOfGroup, c1, c2)*(group-j);

                    if (minPrice > presum) minPrice = presum;
                }
                else
                {
                    long sum = 0;
                    sum+= F(sizeOfGroup, c1, c2)*group;
                    if (minPrice > sum) minPrice = sum;
                }

            }

            Console.WriteLine(minPrice);
        }

        public static long F(long x, long c1, long c2)
        {
            return c1 + c2 * (x - 1) * (x - 1);
        }

    }
}

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

namespace ForAll
{
    class Program
    {

        static void Main(string[] args)
        {
            long[] keys = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt64);

            long n = keys[0];
            long c1 = keys[1];
            long c2 = keys[2];

            long Parents = 0;

            foreach (char i in Console.ReadLine())
                if (i == '1')
                    Parents++;
            long minPrice = Int64.MaxValue;
            for (long i = Parents; i > 0; i--)
            {
                long ost = n % i;
                long group = i;
                long sizeOfGroup = n/i;
                if (ost != 0)
                {
                    //group--;
                    long j = 0;

                    ost = n - sizeOfGroup * group;

                    long presum = 0;
                    presum += F(sizeOfGroup + 1, c1, c2) * ost;
                    presum+= F(sizeOfGroup, c1, c2)*(group-j-1);

                    if (minPrice > presum) minPrice = presum;
                }
                else
                {
                    long sum = 0;
                    sum+= F(sizeOfGroup, c1, c2)*group;
                    if (minPrice > sum) minPrice = sum;
                }

            }

            Console.WriteLine(minPrice);
        }

        public static long F(long x, long c1, long c2)
        {
            return c1 + c2 * (x - 1) * (x - 1);
        }

    }
}