#include<stdio.h>
int calculatenjam(int arr1[],int arr2[],int b1jam,int b2jam,int s1jam,int s2jam,int diff)
{
    int i,j,k,l,m,n,flag,cal=0,dummy;

        i=0,j=0;
        while(diff)
        {
            flag=0;
            if(arr1[i]==1)
            {
                --diff;
                i++;
                flag=1;
                cal++;
            }
            else
            {
                if(arr2[j]==1)
                {
                    --diff;
                    j++;
                    flag=1;
                    cal++;
                }
            }
            if(flag==0)
            {
                k=i,l=j,dummy=diff;
                int dummy2=diff;
                while(arr1[k]!=1)
                {
                    ++dummy;
                    k++;
                }
                while(arr2[l]!=1)
                {
                    ++dummy2;
                    l++;
                }
                if(arr1[k]==1&&arr2[l]==1)
                {
                    if((k-i)<=(l-j)&&k<l)
                    {

                        diff=dummy;
                        --diff;
                        cal+=(k-i);
                        cal++;
                        i=k+1;
                    }
                    else
                    {

                        diff=dummy2;
                        --diff;
                        cal+=(l-j);
                        cal++;
                        j=l+1;
                    }
                }
            }
        }
    return(cal);
}
int calculatepjam(int arr1[],int arr2[],int b1jam,int b2jam,int s1jam,int s2jam,int diff)
{
    int i,j,k,l,m,n,flag,cal=0,dummy;
    if(diff>0)
    {
        i=0,j=0;
        while(diff)
        {
            flag=0;
            if(arr1[i]==2)
            {
                --diff;
                i++;
                flag=1;
                cal++;
            }
            else
            {
                if(arr2[j]==2)
                {
                    --diff;
                    j++;
                    flag=1;
                    cal++;
                }
            }
            if(flag==0)
            {
                k=i,l=j,dummy=diff;
                int dummy2=diff;
                while(arr1[k]!=2)
                {
                    ++dummy;
                    k++;
                }
                while(arr2[l]!=2)
                {
                    ++dummy2;
                    l++;
                }
                if(arr1[k]==2&&arr2[l]==2)
                {
                    if((k-i)<=(l-j)&&k<l)
                    {
                        diff=dummy;
                        --diff;
                        cal+=(k-i);
                        cal++;
                        i=k+1;
                    }
                    else
                    {
                        diff=dummy2;
                        --diff;
                        cal+=(l-j);
                        cal++;
                        j=l+1;
                    }
                }
            }
        }
    }
    return(cal);
}
int main()
{
    int i,j,t,n,arr1[100005],arr2[100005],s1jam,b1jam,s2jam,b2jam;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%d",&n);
        s1jam=0,b1jam=0,s2jam=0,b2jam=0;
        for(j=0;j<n;j++)
        {
            scanf("%d",&arr1[n-1-j]);
            if(arr1[n-1-j]==1)
            s1jam++;
            else
            b1jam++;
        }
        for(j=0;j<n;j++)
        {
            scanf("%d",&arr2[j]);
            if(arr2[j]==1)
            s2jam++;
            else
            b2jam++;
        }
        int diff=(b2jam+b1jam)-(s1jam+s2jam);
        if(diff==0)
        printf("0\n");
        else if(diff<0)
        {
            diff=(s1jam+s2jam)-(b2jam+b1jam);
            printf("%d\n",calculatenjam(arr1,arr2,b1jam,b2jam,s1jam,s2jam,diff));
        }
        else
        printf("%d\n",calculatepjam(arr1,arr2,b1jam,b2jam,s1jam,s2jam,diff));
    }
    return 0;
}


#include<stdio.h>
int calculatenjam(int arr1[],int arr2[],int b1jam,int b2jam,int s1jam,int s2jam,int diff)
{
    int i,j,k,l,m,n,flag,cal=0,dummy;

        i=0,j=0;
        while(diff)
        {
            flag=0;
            if(arr1[i]==1)
            {
                --diff;
                i++;
                flag=1;
                cal++;
            }
            else
            {
                if(arr2[j]==1)
                {
                    --diff;
                    j++;
                    flag=1;
                    cal++;
                }
            }
            if(flag==0)
            {
                k=i,l=j,dummy=diff;
                int dummy2=diff;
                while(arr1[k]!=1)
                {
                    ++dummy;
                    k++;
                }
                while(arr2[l]!=1)
                {
                    ++dummy2;
                    l++;
                }
                if(arr1[k]==1&&arr2[l]==1)
                {
                    if((k-i)<=(l-j)&&k<=l)
                    {

                        diff=dummy;
                        --diff;
                        cal+=(k-i);
                        cal++;
                        i=k+1;
                    }
                    else
                    {

                        diff=dummy2;
                        --diff;
                        cal+=(l-j);
                        cal++;
                        j=l+1;
                    }
                }
            }
        }
    return(cal);
}
int calculatepjam(int arr1[],int arr2[],int b1jam,int b2jam,int s1jam,int s2jam,int diff)
{
    int i,j,k,l,m,n,flag,cal=0,dummy;
    if(diff>0)
    {
        i=0,j=0;
        while(diff)
        {
            flag=0;
            if(arr1[i]==2)
            {
                --diff;
                i++;
                flag=1;
                cal++;
            }
            else
            {
                if(arr2[j]==2)
                {
                    --diff;
                    j++;
                    flag=1;
                    cal++;
                }
            }
            if(flag==0)
            {
                k=i,l=j,dummy=diff;
                int dummy2=diff;
                while(arr1[k]!=2)
                {
                    ++dummy;
                    k++;
                }
                while(arr2[l]!=2)
                {
                    ++dummy2;
                    l++;
                }
                if(arr1[k]==2&&arr2[l]==2)
                {
                    if((k-i)<=(l-j)&&k<=l)
                    {
                        diff=dummy;
                        --diff;
                        cal+=(k-i);
                        cal++;
                        i=k+1;
                    }
                    else
                    {
                        diff=dummy2;
                        --diff;
                        cal+=(l-j);
                        cal++;
                        j=l+1;
                    }
                }
            }
        }
    }
    return(cal);
}
int main()
{
    int i,j,t,n,arr1[100005],arr2[100005],s1jam,b1jam,s2jam,b2jam;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%d",&n);
        s1jam=0,b1jam=0,s2jam=0,b2jam=0;
        for(j=0;j<n;j++)
        {
            scanf("%d",&arr1[n-1-j]);
            if(arr1[n-1-j]==1)
            s1jam++;
            else
            b1jam++;
        }
        for(j=0;j<n;j++)
        {
            scanf("%d",&arr2[j]);
            if(arr2[j]==1)
            s2jam++;
            else
            b2jam++;
        }
        int diff=(b2jam+b1jam)-(s1jam+s2jam);
        if(diff==0)
        printf("0\n");
        else if(diff<0)
        {
            diff=(s1jam+s2jam)-(b2jam+b1jam);
            printf("%d\n",calculatenjam(arr1,arr2,b1jam,b2jam,s1jam,s2jam,diff));
        }
        else
        printf("%d\n",calculatepjam(arr1,arr2,b1jam,b2jam,s1jam,s2jam,diff));
    }
    return 0;
}


#include<stdio.h>
int calculatenjam(int arr1[],int arr2[],int b1jam,int b2jam,int s1jam,int s2jam,int diff)
{
    int i,j,k,l,m,n,flag,cal=0;

        i=0,j=0;
        while(diff)
        {
            flag=0;
            if(arr1[i]==1)
            {
                --diff;
                i++;
                flag=1;
                cal++;
            }
            else
            {
                if(arr2[j]==1)
                {
                    --diff;
                    j++;
                    flag=1;
                    cal++;
                }
            }
            if(flag==0)
            {
                k=i,l=j;
                while(arr1[k]!=1&&arr2[l]!=1)
                {
                    ++diff;
                    k++;
                    l++;
                    cal++;
                }
                if(arr1[k]==1)
                {
                    --diff;
                    i=k+1;
                    cal++;
                }
                else if(arr2[l]==1)
                {
                    --diff;
                    j=l+1;
                    cal++;
                }
            }
        }
    return(cal);
}
int calculatepjam(int arr1[],int arr2[],int b1jam,int b2jam,int s1jam,int s2jam,int diff)
{
    int i,j,k,l,m,n,flag,cal=0;
    if(diff>0)
    {
        i=0,j=0;
        while(diff)
        {
            flag=0;
            if(arr1[i]==2)
            {
                --diff;
                i++;
                flag=1;
                cal++;
            }
            else
            {
                if(arr2[j]==2)
                {
                    --diff;
                    j++;
                    flag=1;
                    cal++;
                }
            }
            if(flag==0)
            {
                k=i,l=j;
                while(arr1[k]!=2&&arr2[l]!=2)
                {
                    ++diff;
                    k++;
                    l++;
                    cal++;
                }
                if(arr1[k]==2)
                {
                    --diff;
                    i=k+1;
                    cal++;
                }
                else if(arr2[l]==2)
                {
                    --diff;
                    j=l+1;
                    cal++;
                }
            }
        }
    }
    return(cal);
}
int main()
{
    int i,j,t,n,arr1[100005],arr2[100005],s1jam,b1jam,s2jam,b2jam;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%d",&n);
        s1jam=0,b1jam=0,s2jam=0,b2jam=0;
        for(j=0;j<n;j++)
        {
            scanf("%d",&arr1[n-1-j]);
            if(arr1[n-1-j]==1)
            s1jam++;
            else
            b1jam++;
        }
        for(j=0;j<n;j++)
        {
            scanf("%d",&arr2[j]);
            if(arr2[j]==1)
            s2jam++;
            else
            b2jam++;
        }
        int diff=(b2jam+b1jam)-(s1jam+s2jam);
        if(diff==0)
        printf("0\n");
        else if(diff<0)
        {
            diff=(s1jam+s2jam)-(b2jam+b1jam);
            printf("%d\n",calculatenjam(arr1,arr2,b1jam,b2jam,s1jam,s2jam,diff));
        }
        else
        printf("%d\n",calculatepjam(arr1,arr2,b1jam,b2jam,s1jam,s2jam,diff));
    }
    return 0;
}


#include<stdio.h>
int calculatenjam(int arr1[],int arr2[],int diff)
{
    int i,j,k,l,m,n,flag,cal=0,dummy,bjam,bjam1,sjam,sjam1;
    i=0,j=0;
    while(diff)
    {
        k=i,l=j,dummy=diff,bjam=0,bjam1=0,sjam=0;sjam1=0;
        int dummy2=diff;
        while(arr1[k]!=1)
        {
            ++dummy;
            bjam++;
            k++;
        }
        while(arr2[l]!=1)
        {
            ++dummy2;
            bjam1++;
            l++;
        }
        if(arr1[k]==1&&arr2[l]==1)
        {
            if(bjam<bjam1&&k<l)
            {
                diff=dummy;
                --diff;
                cal+=(k-i);
                cal++;
                i=k+1;
            }
            else if(bjam1<bjam&&l<k)
            {
                diff=dummy2;
                --diff;
                cal+=(l-j);
                cal++;
                j=l+1;
            }
            else if(bjam<bjam1&&l<k)
            {
                 diff=dummy;
                --diff;
                cal+=(k-i);
                cal++;
                i=k+1;
            }
            else if(bjam1<bjam&&k<l)
            {

                diff=dummy2;
                --diff;
                cal+=(l-j);
                cal++;
                j=l+1;
            }
            else if(bjam==bjam1)
            {
                if(k<l)
                {

                    diff=dummy;
                    --diff;
                    cal+=(k-i);
                    cal++;
                    i=k+1;
                }
                else
                {
                    diff=dummy2;
                    --diff;
                    cal+=(l-j);
                    cal++;
                    j=l+1;
                }
            }
            else if(k==l)
            {
                if(bjam<bjam1)
                {
                    diff=dummy;
                    --diff;
                    cal+=(k-i);
                    cal++;
                    i=k+1;
                }
                else
                {
                    diff=dummy2;
                    --diff;
                    cal+=(l-j);
                    cal++;
                    j=l+1;
                }
            }
        }
    }
    return(cal);
}
int calculatepjam(int arr1[],int arr2[],int diff)
{
    int i,j,k,l,m,n,flag,cal=0,dummy,bjam,bjam1,sjam,sjam1;
    if(diff>0)
    {
        i=0,j=0,sjam=0,sjam1=0;
        while(diff)
        {
            k=i,l=j,dummy=diff,sjam=0,sjam1=0;
            int dummy2=diff;
           while(arr1[k]!=2)
            {
                ++dummy;
                sjam++;
                k++;
            }
            while(arr2[l]!=2)
            {
                ++dummy2;
                sjam1++;
                l++;
            }
            if(arr1[k]==2&&arr2[l]==2)
            {
                if(sjam<sjam1&&k<l)
               {
                diff=dummy;
                --diff;
                cal+=(k-i);
                cal++;
                i=k+1;
              }
            else if(sjam1<sjam&&l<k)
            {
                diff=dummy2;
                --diff;
                cal+=(l-j);
                cal++;
                j=l+1;
            }
            else if(sjam<sjam1&&l<k)
            {
                diff=dummy;
                --diff;
                cal+=(k-i);
                cal++;
                i=k+1;
            }
            else if(sjam1<sjam&&k<l)
            {

                diff=dummy2;
                --diff;
                cal+=(l-j);
                cal++;
                j=l+1;
            }
            else if(sjam==sjam1)
            {
                if(k<l)
                {

                    diff=dummy;
                    --diff;
                    cal+=(k-i);
                    cal++;
                    i=k+1;
                }
                else
                {
                    diff=dummy2;
                    --diff;
                    cal+=(l-j);
                    cal++;
                    j=l+1;
                }
            }
            else if(k==l)
            {
                if(sjam<sjam1)
                {
                    diff=dummy;
                    --diff;
                    cal+=(k-i);
                    cal++;
                    i=k+1;
                }
                else
                {
                    diff=dummy2;
                    --diff;
                    cal+=(l-j);
                    cal++;
                    j=l+1;
                }
            }
            }
        }
    }
    return(cal);
}
int main()
{
    int i,j,t,n,arr1[100005],arr2[100005],s1jam,b1jam,s2jam,b2jam;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%d",&n);
        s1jam=0,b1jam=0,s2jam=0,b2jam=0;
        for(j=0;j<n;j++)
        {
            scanf("%d",&arr1[n-1-j]);
            if(arr1[n-1-j]==1)
            s1jam++;
            else
            b1jam++;
        }
        for(j=0;j<n;j++)
        {
            scanf("%d",&arr2[j]);
            if(arr2[j]==1)
            s2jam++;
            else
            b2jam++;
        }
        int diff=(b2jam+b1jam)-(s1jam+s2jam);
        if(diff==0)
        printf("0\n");
        else if(diff<0)
        {
            diff=(s1jam+s2jam)-(b2jam+b1jam);
            printf("%d\n",calculatenjam(arr1,arr2,diff));
        }
        else
        printf("%d\n",calculatepjam(arr1,arr2,diff));
    }
    return 0;
}


#include<stdio.h>
int calculatenjam(int arr1[],int arr2[],int b1jam,int b2jam,int s1jam,int s2jam,int diff)
{
    int i,j,k,l,m,n,flag,cal=0;

        i=0,j=0;
        while(diff)
        {
            flag=0;
            if(arr1[i]==1)
            {
                --diff;
                i++;
                flag=1;
                cal++;
            }
            else
            {
                if(arr2[j]==1)
                {
                    --diff;
                    j++;
                    flag=1;
                    cal++;
                }
            }
            if(flag==0)
            {
                k=i,l=j;
                while(arr1[k]!=1&&arr2[l]!=1)
                {
                    ++diff;
                    k++;
                    l++;
                    cal++;
                }
                if(arr1[k]==1&&arr2[l]==1)
                {
                    if(k<=l)
                    {
                        --diff;
                        i=k+1;
                        cal++;
                    }
                    else
                    {
                        --diff;
                        j=l+1;
                        cal++;
                    }
                }
                else if(arr1[k]==1)
                {
                    --diff;
                    i=k+1;
                    cal++;
                }
                else if(arr2[l]==1)
                {
                    --diff;
                    j=l+1;
                    cal++;
                }
            }
        }
    return(cal);
}
int calculatepjam(int arr1[],int arr2[],int b1jam,int b2jam,int s1jam,int s2jam,int diff)
{
    int i,j,k,l,m,n,flag,cal=0;
    if(diff>0)
    {
        i=0,j=0;
        while(diff)
        {
            flag=0;
            if(arr1[i]==2)
            {
                --diff;
                i++;
                flag=1;
                cal++;
            }
            else
            {
                if(arr2[j]==2)
                {
                    --diff;
                    j++;
                    flag=1;
                    cal++;
                }
            }
            if(flag==0)
            {
                k=i,l=j;
                while(arr1[k]!=2&&arr2[l]!=2)
                {
                    ++diff;
                    k++;
                    l++;
                    cal++;
                }
                if(arr1[k]==2&&arr2[l]==2)
                {
                    if(k<=l)
                    {
                        --diff;
                        i=k+1;
                        cal++;
                    }
                    else
                    {
                        --diff;
                        j=l+1;
                        cal++;
                    }
                }
                else if(arr1[k]==2)
                {
                    --diff;
                    i=k+1;
                    cal++;
                }
                else if(arr2[l]==2)
                {
                    --diff;
                    j=l+1;
                    cal++;
                }
            }
        }
    }
    return(cal);
}
int main()
{
    int i,j,t,n,arr1[100005],arr2[100005],s1jam,b1jam,s2jam,b2jam;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%d",&n);
        s1jam=0,b1jam=0,s2jam=0,b2jam=0;
        for(j=0;j<n;j++)
        {
            scanf("%d",&arr1[n-1-j]);
            if(arr1[n-1-j]==1)
            s1jam++;
            else
            b1jam++;
        }
        for(j=0;j<n;j++)
        {
            scanf("%d",&arr2[j]);
            if(arr2[j]==1)
            s2jam++;
            else
            b2jam++;
        }
        int diff=(b2jam+b1jam)-(s1jam+s2jam);
        if(diff==0)
        printf("0\n");
        else if(diff<0)
        {
            diff=(s1jam+s2jam)-(b2jam+b1jam);
            printf("%d\n",calculatenjam(arr1,arr2,b1jam,b2jam,s1jam,s2jam,diff));
        }
        else
        printf("%d\n",calculatepjam(arr1,arr2,b1jam,b2jam,s1jam,s2jam,diff));
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

#define N	100000

int min(int a, int b) { return a < b ? a : b; }

int main() {
	int t;

	scanf("%d", &t);
	while (t--) {
		static int aa[N + N], ii[N + 1 + N], jj[N + 1 + N];
		int n, i, j, a, ans;

		scanf("%d", &n);
		for (i = 0; i < n * 2; i++)
			scanf("%d", &aa[i]), aa[i] = aa[i] == 1 ? 1 : -1;
		memset(ii, -1, (n + 1 + n) * sizeof *ii);
		ii[a = n] = 0;
		for (i = 0; i < n; i++)
			ii[a += aa[i]] = i + 1;
		memset(jj, -1, (n + 1 + n) * sizeof *jj);
		jj[a = n] = 0;
		for (j = n * 2 - 1; j >= n; j--)
			jj[a -= aa[j]] = n * 2 - j;
		ans = n + n;
		for (a = 0; a <= n + n; a++)
			if (ii[a] != -1 && jj[a] != -1)
				ans = min(ans, n + n - ii[a] - jj[a]);
		printf("%d\n", ans);
	}
	return 0;
}


/* Coached by rainboy */
#include <stdio.h>
#include <string.h>

#define N 100000

int main() {
	int t;

	scanf("%d", &t);
	while (t--) {
		static int aa[N * 2], pp[N * 2 + 1], qq[N * 2 + 1];
		int n, i, a, x, ans;

		scanf("%d", &n);
		for (i = 0; i < n * 2; i++) {
			scanf("%d", &aa[i]);
			if (aa[i] == 2)
				aa[i] = -1;
		}
		memset(pp, -1, (n * 2 + 1) * sizeof *pp);
		a = n;
		pp[a] = 0;
		for (i = 0; i < n; i++) {
			a += aa[i];
			pp[a] = i + 1;
		}
		memset(qq, -1, (n * 2 + 1) * sizeof *qq);
		a = n;
		qq[a] = 0;
		for (i = n * 2 - 1; i >= n; i--) {
			a += -aa[i];
			qq[a] = n * 2 - i;
		}
		ans = n * 2 + 1;
		for (a = 0; a <= n + n; a++)
			if (pp[a] != -1 && qq[a] != -1) {
				x = n + n - pp[a] - qq[a];
				if (ans > x)
					ans = x;
			}
		printf("%d\n", ans);
	}
	return 0;
}


using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using static System.Math;
using Number = System.Int32;

namespace Program {
	public class Solver {
		Random rnd = new Random();
		public void Solve() {
			var T = ri;
			for (int i = 0; i < T; i++) f();
		}
		const int D = 500000 / 2;
		int[] diff = new int[D * 2];
		void f() {
			var n = ri;
			var a = Enumerate(n, x => ri).Reverse().ToArray();
			var b = Enumerate(n, x => ri);
			var N = a.Count(x => x == 1) + b.Count(x => x == 1);
			var M = 2 * n - N;
			Debug.WriteLine($"{N} {M}");
			for (int i = 0; i <= n + 5; i++) diff[D + i] = diff[D - i] = 1000000000;
			var u = 0;
			diff[D] = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] == 1) u++;
				else u--;
				diff[D + u] = Min(diff[D + u], i + 1);
			}
			u = 0;
			// N - u == M - v
			// N - M == u - v
			var ans = diff[D + N - M];
			Debug.WriteLine(ans);
			for (int i = 0; i < n; i++) {
				if (b[i] == 1) u++;
				else u--;
				var need = N - M - u;
				ans = Min(ans, diff[D + need] + i + 1);
			}
			Console.WriteLine(ans);

		}
		const long INF = 1L << 60;
		static int[] dx = { -1, 0, 1, 0 };
		static int[] dy = { 0, 1, 0, -1 };
		int ri { get { return sc.Integer(); } }
		long rl { get { return sc.Long(); } }
		double rd { get { return sc.Double(); } }
		string rs { get { return sc.Scan(); } }
		public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

		static T[] Enumerate<T>(int n, Func<int, T> f) {
			var a = new T[n];
			for (int i = 0; i < a.Length; ++i) a[i] = f(i);
			return a;
		}
		static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
	}
}

#region main
static class Ex {
	static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
	static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
		return string.Join(st, ie);
	}
	static public void Main() {
		Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = true });
		var solver = new Program.Solver();
		/*
		var t = new System.Threading.Thread(solver.Solve, 50000000);
		t.Start();
		t.Join();
		//*/
		solver.Solve();
		Console.Out.Flush();
	}
}
#endregion
#region Ex
namespace Program.IO {
	using System.IO;
	using System.Text;
	using System.Globalization;

	public class Printer : StreamWriter {
		public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
		public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	}

	public class StreamScanner {
		public StreamScanner(Stream stream) { str = stream; }

		public readonly Stream str;
		private readonly byte[] buf = new byte[1024];
		private int len, ptr;
		public bool isEof = false;
		public bool IsEndOfStream { get { return isEof; } }

		private byte read() {
			if (isEof) return 0;
			if (ptr >= len) {
				ptr = 0;
				if ((len = str.Read(buf, 0, 1024)) <= 0) {
					isEof = true;
					return 0;
				}
			}
			return buf[ptr++];
		}

		public char Char() {
			byte b = 0;
			do b = read(); while ((b < 33 || 126 < b) && !isEof);
			return (char)b;
		}
		public string Scan() {
			var sb = new StringBuilder();
			for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
			return sb.ToString();
		}
		public string ScanLine() {
			var sb = new StringBuilder();
			for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
			return sb.ToString();
		}
		public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
		public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
		public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
	}
}

#endregion


using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using static System.Math;
using Number = System.Int32;

namespace Program {
	public class Solver {
		Random rnd = new Random();
		public void Solve() {
			var T = ri;

			for (int i = 0; i < T; i++) f();
		}
		const int D = 500000 / 2;
		int[] diff = new int[D * 2];
		void f() {
			var n = ri;
			var a = Enumerate(n, x => ri).Reverse().ToArray();
			var b = Enumerate(n, x => ri);
			var N = a.Count(x => x == 1) + b.Count(x => x == 1);
			var M = 2 * n - N;
			Debug.WriteLine($"{N} {M}");
			for (int i = 0; i <= 2 * n + 5; i++) diff[D + i] = diff[D - i] = 1000000000;
			var u = 0;
			diff[D] = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] == 1) u++;
				else u--;
				diff[D + u] = Min(diff[D + u], i + 1);
			}
			u = 0;
			// N - u == M - v
			// N - M == u - v
			var ans = diff[D + N - M];
			Debug.WriteLine(ans);
			for (int i = 0; i < n; i++) {
				if (b[i] == 1) u++;
				else u--;
				var need = N - M - u;
				ans = Min(ans, diff[D + need] + i + 1);
			}
			Console.WriteLine(ans);

		}
		const long INF = 1L << 60;
		static int[] dx = { -1, 0, 1, 0 };
		static int[] dy = { 0, 1, 0, -1 };
		int ri { get { return sc.Integer(); } }
		long rl { get { return sc.Long(); } }
		double rd { get { return sc.Double(); } }
		string rs { get { return sc.Scan(); } }
		public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

		static T[] Enumerate<T>(int n, Func<int, T> f) {
			var a = new T[n];
			for (int i = 0; i < a.Length; ++i) a[i] = f(i);
			return a;
		}
		static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
	}
}

#region main
static class Ex {
	static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
	static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
		return string.Join(st, ie);
	}
	static public void Main() {
		Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = true });
		var solver = new Program.Solver();
		/*
		var t = new System.Threading.Thread(solver.Solve, 50000000);
		t.Start();
		t.Join();
		//*/
		solver.Solve();
		Console.Out.Flush();
	}
}
#endregion
#region Ex
namespace Program.IO {
	using System.IO;
	using System.Text;
	using System.Globalization;

	public class Printer : StreamWriter {
		public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
		public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	}

	public class StreamScanner {
		public StreamScanner(Stream stream) { str = stream; }

		public readonly Stream str;
		private readonly byte[] buf = new byte[1024];
		private int len, ptr;
		public bool isEof = false;
		public bool IsEndOfStream { get { return isEof; } }

		private byte read() {
			if (isEof) return 0;
			if (ptr >= len) {
				ptr = 0;
				if ((len = str.Read(buf, 0, 1024)) <= 0) {
					isEof = true;
					return 0;
				}
			}
			return buf[ptr++];
		}

		public char Char() {
			byte b = 0;
			do b = read(); while ((b < 33 || 126 < b) && !isEof);
			return (char)b;
		}
		public string Scan() {
			var sb = new StringBuilder();
			for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
			return sb.ToString();
		}
		public string ScanLine() {
			var sb = new StringBuilder();
			for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
			return sb.ToString();
		}
		public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
		public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
		public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
	}
}

#endregion


using System;
using System.Collections.Generic;
using System.Text;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int t = sc.NextInt();
        var sb = new StringBuilder();
        for (int i = 0; i < t; i++)
        {
            sb.AppendLine(Query(sc.NextInt(), sc.IntArray()));
        }

        Console.Write(sb.ToString());
    }

    private string Query(int n, int[] a)
    {
        // aの真ん中に降りる
        // 左側 右側に連続したジャムを食べる
        // 残っている瓶は2種類とも同じ数になってる
        // 食べたジャムの数 最小

        int diff = 0;

        foreach (int i in a)
        {
            if (i == 1)
            {
                diff++;
            }
            else
            {
                diff--;
            }
        }

        var map = new Dictionary<int, int>();

        int cnt = 0;
        map[0] = 0;
        int o;
        for (int i = 1; i <= n; i++)
        {
            if (a[n - i] == 1)
            {
                cnt++;
            }
            else
            {
                cnt--;
            }

            if (!map.TryGetValue(cnt, out o))
            {
                map[cnt] = i;
            }
        }

        int ans = int.MaxValue;

        cnt = 0;
        if (map.TryGetValue(diff - cnt, out o))
        {
            ans = Math.Min(ans, o);
        }

        for (int i = 1; i <= n; i++)
        {
            if (a[n + i - 1] == 1)
            {
                cnt++;
            }
            else
            {
                cnt--;
            }

            if (map.TryGetValue(diff - cnt, out o))
            {
                ans = Math.Min(ans, o + i);
            }
        }

        return ans.ToString();
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}


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

bool comp(pair<ll,ll>  a, pair<ll,ll> b){
  return a.first > b.first;
}

int main(int argc, char const *argv[]){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,a,b;cin>>n>>a>>b;
    ll fac = pow(2,a);
    vector< pair<ll, ll> > mons, diff;
    vector<pair<ll,pair<ll,ll> > > arr(n);
    ll hp, dm, i;
    ll summ=0;
    for(i=0;i<n;i++){
      cin>>hp>>dm;
      mons.push_back(make_pair(hp,dm));
      diff.push_back(make_pair(hp-dm,i));
      summ += dm;
    }
    if(b==0 ){
      cout<<summ<<endl;
      return 0;
    }
    if(n==1){
      if(b){
        cout<<max(fac*mons[0].first, mons[0].second);
      }
      else
        cout<<mons[0].second<<endl;
      return 0;
    }

    sort(diff.begin(), diff.end());
    reverse(diff.begin(), diff.end());
    ll leftb = b;
    summ = 0;
    for(i=0;i<n;i++){
      if(diff[i].first > 0 && leftb > 0 ){
        leftb--;
        summ += mons[diff[i].second].first;
      }
      else
        summ += mons[diff[i].second].second;
    }
    ll maxScore = summ;

    //cout<<b<<" "<<maxScore<<endl;
    for(i=0;i<b-leftb;i++){
      maxScore =  max(maxScore  , summ - mons[diff[i].second].first + fac*mons[diff[i].second].first );
    }

    for(i=b-leftb;i<n;i++){
        if(leftb || b-leftb==0)
            maxScore =  max(maxScore  , summ - mons[diff[i].second].second + fac*mons[diff[i].second].first);
        else
            maxScore =  max(maxScore  , summ - mons[diff[i].second].second + fac*mons[diff[i].second].first - mons[diff[b-1].second].first + mons[diff[b-1].second].second);
    }
   cout<<maxScore<<endl;

}


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

bool comp(pair<ll,ll>  a, pair<ll,ll> b){
	return a.first > b.first;
}

int main(int argc, char const *argv[]){
    //freopen ("cpp_IO_DIFF/input.txt","r",stdin);
    //freopen ("cpp_IO_DIFF/output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

  	ll n,a,b;cin>>n>>a>>b;
    ll fac = pow(2,a);
  	vector< pair<ll, ll> > mons, diff;
  	vector<pair<ll,pair<ll,ll> > > arr(n);
  	ll hp, dm, i;
  	ll summ=0;
  	for(i=0;i<n;i++){
  		cin>>hp>>dm;
  		mons.push_back(make_pair(hp,dm));
  		diff.push_back(make_pair(hp-dm,i));
  		summ += dm;
  	}
  	if(b==0 ){
  		cout<<summ<<endl;
  		return 0;
  	}
    if(n==1){
      if(b){
        cout<<max(fac*mons[0].first, mons[0].second);
      }
      else
        cout<<mons[0].second<<endl;
      return 0;
    }

  	sort(diff.begin(), diff.end());
    reverse(diff.begin(), diff.end());
    ll tempb = 0;
    summ = 0;
    for(i=0;i<n;i++){
      if(diff[i].first > 0 && tempb < b ){
        tempb++;
        summ += mons[diff[i].second].first;
      }
      else
        summ += mons[diff[i].second].second;
    }
    b=min(b,tempb);
    ll maxScore = summ;

    //cout<<b<<" "<<maxScore<<endl;
    for(i=0;i<b;i++){
      maxScore =  max(maxScore  , summ - mons[diff[i].second].first + fac*mons[diff[i].second].first );
    }

    for(i=b;i<n;i++){
        if(b>0)
            maxScore =  max(maxScore  , summ - mons[diff[i].second].second + fac*mons[diff[i].second].first - mons[diff[b-1].second].first + mons[diff[b-1].second].second );
        else
            maxScore =  max(maxScore  , summ - mons[diff[i].second].second + fac*mons[diff[i].second].first);
    }
   cout<<maxScore<<endl;

}


#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=200000+10;
int n,a,b;
long long hp[maxn],dmg[maxn];
int id[maxn];
long long kq;

bool cmp(int i,int j){
  return hp[i]-dmg[i]>hp[j]-dmg[j];
}

long long max(long long a,long long b){
  if (a<b) return b;
  else return a;
}

int main(){
  //freopen("input.txt","r",stdin);
  scanf("%d%d%d",&n,&a,&b);
  for(int i=1;i<=n;i++) cin>>hp[i]>>dmg[i];
  for(int i=1;i<=n;i++) id[i]=i;
  sort(id+1,id+n+1,cmp);
  long long sum=0;
  for(int i=1;i<=n;i++)
    if (i<=b){
      if (hp[id[i]]>dmg[id[i]]) sum=sum+hp[id[i]];
      else sum=sum+dmg[id[i]];
    }
    else sum=sum+dmg[id[i]];
  kq=sum;
  for(int i=1;i<=b;i++){
    long long tmp=hp[id[i]]<<a;
    long long tsum=sum;
    if (hp[id[i]]>dmg[id[i]]) tsum=tsum-hp[id[i]]+tmp;
    else tsum=tsum-dmg[id[i]]+tmp;
    kq=max(kq,tsum);
  }
  for(int i=b+1;i<=n;i++){
    long long tmp=hp[id[i]]<<a;
    long long tsum=sum;
    tsum=tsum-dmg[id[i]]+tmp;
    if (hp[id[b]]>dmg[id[b]]) tsum=tsum-hp[id[b]]+dmg[id[b]];
    kq=max(kq,tsum);
  }
  cout<<kq;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=200000+10;
int n,a,b;
long long hp[maxn],dmg[maxn];
int id[maxn];
long long kq;

bool cmp(int i,int j){
  return hp[i]-dmg[i]>hp[j]-dmg[j];
}

long long max(long long a,long long b){
  if (a<b) return b;
  else return a;
}

int main(){
  //freopen("input.txt","r",stdin);
  scanf("%d%d%d",&n,&a,&b);
  for(int i=1;i<=n;i++) cin>>hp[i]>>dmg[i];
  for(int i=1;i<=n;i++) id[i]=i;
  sort(id+1,id+n+1,cmp);
  long long sum=0;
  for(int i=1;i<=n;i++)
    if (i<=b){
      if (hp[id[i]]>dmg[id[i]]) sum=sum+hp[id[i]];
      else sum=sum+dmg[id[i]];
    }
    else sum=sum+dmg[id[i]];
  kq=sum;
  for(int i=1;i<=b;i++){
    long long tmp=hp[id[i]]<<a;
    long long tsum=sum;
    if (hp[id[i]]>dmg[id[i]]) tsum=tsum-hp[id[i]]+tmp;
    else tsum=tsum-dmg[id[i]]+tmp;
    kq=max(kq,tsum);
  }
  if (b>0)
    for(int i=b+1;i<=n;i++){
      long long tmp=hp[id[i]]<<a;
      long long tsum=sum;
      tsum=tsum-dmg[id[i]]+tmp;
      if (hp[id[b]]>dmg[id[b]]) tsum=tsum-hp[id[b]]+dmg[id[b]];
      kq=max(kq,tsum);
    }
  cout<<kq;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=200000+10;
int n,a,b;
long long hp[maxn],dmg[maxn];
int id[maxn];
long long kq;

bool cmp(int i,int j){
  return hp[i]-dmg[i]>hp[j]-dmg[j];
}

long long max(long long a,long long b){
  if (a<b) return b;
  else return a;
}

int main(){
  //freopen("input.txt","r",stdin);
  scanf("%d%d%d",&n,&a,&b);
  for(int i=1;i<=n;i++) cin>>hp[i]>>dmg[i];
  for(int i=1;i<=n;i++) id[i]=i;
  sort(id+1,id+n+1,cmp);
  long long sum=0;
  for(int i=1;i<=n;i++)
    if (i<=b){
      if (hp[id[i]]>dmg[id[i]]) sum=sum+hp[id[i]];
      else sum=sum+dmg[id[i]];
    }
    else sum=sum+dmg[id[i]];
  //cout<<sum<<endl;
  //for(int i=1;i<=n;i++) printf("%d ",id[i]);printf("\n");
  kq=sum;
  for(int i=1;i<=b;i++){
    long long tmp=hp[id[i]]<<a;
    long long tsum=sum;
    if (hp[id[i]]>dmg[id[i]]) tsum=tsum-hp[id[i]]+tmp;
    else tsum=tsum-dmg[id[i]]+tmp;
    kq=max(kq,tsum);
  }
  cout<<kq;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct gg{
	ll atk,hp,ha;
}node[300010];
ll n,a,b,tp,ans;
bool cmp(gg x,gg y)
{
	return x.ha==y.ha?x.hp-x.atk<y.hp-y.atk:x.ha>y.ha;
}
bool cmpp(gg x,gg y)
{
	return x.hp-x.atk>y.hp-y.atk;
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>a>>b;tp=pow(2,a);
	for(int i=1;i<=n;i++)
		cin>>node[i].hp>>node[i].atk,node[i].ha=tp*node[i].hp-node[i].atk,ans+=node[i].atk;
	sort(node+1,node+n+1,cmp);
	node[1].hp*=tp;
	sort(node+1,node+n+1,cmpp);
	for(int i=1;i<=min(b,n);i++)
	{
		ans+=max(0LL,node[i].hp-node[i].atk);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct gg{
	ll atk,hp;
}node[300010];
ll n,a,b,tp,ans,res;bool lasb=0;
bool cmp(gg x,gg y)
{return x.hp-x.atk>y.hp-y.atk;}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>a>>b;tp=pow(2,a);
	for(int i=1;i<=n;i++)
		cin>>node[i].hp>>node[i].atk,ans+=node[i].atk;
	sort(node+1,node+n+1,cmp);
	for(int i=1;i<=min(b,n);i++)
	{
		if(node[i].hp-node[i].atk<=0){lasb=1;break;}
		ans+=max(0LL,node[i].hp-node[i].atk);
	}
	if(a==0){cout<<ans;return 0;}
	res=ans;
	for(int i=1;i<=n;i++)
	{
		if(i<=b)
		{
			res=max(res,ans-max(0LL,node[i].hp-node[i].atk)+node[i].hp*tp-node[i].atk);
		}
		else
		{
			if(lasb)
			{
				res=max(res,ans+node[i].hp*tp-node[i].atk);
			}
			else
			{
				res=max(res,ans+node[i].hp*tp-node[i].atk-max(0LL,node[b].hp-node[b].atk));
			}
		}
	}
	cout<<res;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct gg{
	ll atk,hp,ha;
}node[200010];
int n,a,b;ll tp,ans;
ll pow(ll x,int y)
{
	ll res=1;
	while(y)
	{
		if(y&1)res*=x;
		y>>=1;x=x*x;
	}
	return res;
}
bool cmp(gg x,gg y)
{
	return x.ha>y.ha;
}
bool cmpp(gg x,gg y)
{
	return x.hp-x.atk>y.hp-y.atk;
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>a>>b;tp=pow(2,a);
	for(int i=1;i<=n;i++)
		cin>>node[i].hp>>node[i].atk,node[i].ha=tp*node[i].hp-node[i].atk,ans+=node[i].atk;
	sort(node+1,node+n+1,cmp);
	node[1].hp=node[1].hp*tp;
	sort(node+1,node+n+1,cmpp);
	for(int i=1;i<=min(b,n);i++)
	{
		if(node[i].hp-node[i].atk<=0)break;
		ans+=node[i].hp-node[i].atk;
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct gg{
	ll atk,hp;
}node[300010];
ll n,a,b,tp,ans,res;bool lasb=0;
bool cmp(gg x,gg y)
{return x.hp-x.atk>y.hp-y.atk;}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>a>>b;tp=pow(2,a);
	for(int i=1;i<=n;i++)
		cin>>node[i].hp>>node[i].atk,ans+=node[i].atk;
	sort(node+1,node+n+1,cmp);
	for(int i=1;i<=min(b,n);i++)
	{
		if(node[i].hp-node[i].atk<=0){lasb=1;break;}
		ans+=max(0LL,node[i].hp-node[i].atk);
	}
	if(a==0||b==0){cout<<ans;return 0;}
	res=ans;
	for(int i=1;i<=n;i++)
	{
		if(i<=b)
		{
			res=max(res,ans-max(0LL,node[i].hp-node[i].atk)+node[i].hp*tp-node[i].atk);
		}
		else
		{
			if(lasb)
			{
				res=max(res,ans+node[i].hp*tp-node[i].atk);
			}
			else
			{
				res=max(res,ans+node[i].hp*tp-node[i].atk-max(0LL,node[b].hp-node[b].atk));
			}
		}
	}
	cout<<res;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>

using namespace std;
struct node{
	long long hp,dmg;
	bool f;
}a[200010];
int n,A,B;
bool flag;
long long ans,t,sum;
bool cmp(node x,node y)
{
	return x.hp-x.dmg>y.hp-y.dmg;
}
int main()
{
	scanf("%d%d%d",&n,&A,&B);
	t=1;
	int b=B;
	for(int i=1;i<=A;i++)
	{
		t*=2;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i].hp,&a[i].dmg);
		sum+=a[i].dmg;
		if(a[i].dmg<a[i].hp*t) flag=1;
	}
	if(!flag||B==0)
	{
		printf("%lld",sum);
		return 0;
	}
	long long temp=0;
	sort(a+1,a+1+n,cmp);
	if(A==0)
	{
		for(int i=1;i<=n;i++)
		{
			if(a[i].hp>a[i].dmg&&B>0)
			{
				temp+=a[i].hp;
				B--;
			}
			else temp+=a[i].dmg;
		}
		printf("%lld",max(sum,temp));
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i].hp>a[i].dmg&&B>0)
		{
			temp+=a[i].hp;
			a[i].f=1;
			B--;
		}
		else temp+=a[i].dmg;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i].f)
		{
			temp-=a[i].hp;
			temp+=a[i].hp*t;
			ans=max(ans,temp);
			temp-=a[i].hp*t;
			temp+=a[i].hp;
		}
		else if(B>0)
		{
			temp-=a[i].dmg;
			temp+=a[i].hp*t;
			ans=max(ans,temp);
			temp-=a[i].hp*t;
			temp+=a[i].dmg;
		}
		else
		{
			temp-=a[i].dmg;
			temp-=a[b].hp;
			temp+=a[b].dmg;
			temp+=a[i].hp*t;
			ans=max(ans,temp);
			temp-=a[i].hp*t;
			temp-=a[b].dmg;
			temp+=a[i].dmg;
			temp+=a[b].hp;
		}
	}
	ans=max(ans,temp);
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>

using namespace std;
struct node{
	long long hp,dmg;
	bool f;
}a[200010];
int n,A,B;
bool flag;
long long ans,t,sum;
bool cmp(node x,node y)
{
	return x.hp-x.dmg>y.hp-y.dmg;
}
int main()
{
	scanf("%d%d%d",&n,&A,&B);
	t=1;
	for(int i=1;i<=A;i++)
	{
		t*=2;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i].hp,&a[i].dmg);
		sum+=a[i].dmg;
		if(a[i].dmg<a[i].hp*t) flag=1;
	}
	if(!flag||B==0)
	{
		printf("%lld",sum);
		return 0;
	}
	long long temp=0;
	sort(a+1,a+1+n,cmp);
	if(A==0)
	{
		for(int i=1;i<=n;i++)
		{
			if(a[i].hp>a[i].dmg&&B>0)
			{
				temp+=a[i].hp;
				B--;
			}
			else temp+=a[i].dmg;
		}
		printf("%lld",max(sum,temp));
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i].hp>a[i].dmg&&B>0)
		{
			temp+=a[i].hp;
			a[i].f=1;
			B--;
		}
		else temp+=a[i].dmg;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i].f)
		{
			temp-=a[i].hp;
			temp+=a[i].hp*t;
			ans=max(ans,temp);
			temp-=a[i].hp*t;
			temp+=a[i].hp;
		}
		else if(B>0)
		{
			temp-=a[i].dmg;
			temp+=a[i].hp*t;
			ans=max(ans,temp);
			temp-=a[i].hp*t;
			temp+=a[i].dmg;
		}
	}
	ans=max(ans,temp);
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>

using namespace std;
struct node{
	long long hp,dmg;
	bool f;
}a[200010];
int n,A,B;
bool flag;
long long ans,t,sum;
bool cmp(node x,node y)
{
	return x.hp-x.dmg>y.hp-y.dmg;
}
int main()
{
	scanf("%d%d%d",&n,&A,&B);
	t=1;
	for(int i=1;i<=A;i++)
	{
		t*=2;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i].hp,&a[i].dmg);
		sum+=a[i].dmg;
		if(a[i].dmg<a[i].hp*t) flag=1;
	}
	if(!flag||B==0)
	{
		printf("%lld",sum);
		return 0;
	}
	long long temp=0;
	sort(a+1,a+1+n,cmp);
	if(A==0)
	{
		for(int i=1;i<=n;i++)
		{
			if(a[i].hp>a[i].dmg&&B>0)
			{
				temp+=a[i].hp;
				B--;
			}
			else temp+=a[i].dmg;
		}
		printf("%lld",max(sum,temp));
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i].hp>a[i].dmg&&B>0)
		{
			temp+=a[i].hp;
			a[i].f=1;
			B--;
		}
		else temp+=a[i].dmg;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i].f)
		{
			temp-=a[i].hp;
			temp+=a[i].hp*t;
			ans=max(ans,temp);
			temp-=a[i].hp*t;
			temp+=a[i].hp;
		}
	}
	ans=max(ans,temp);
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>

using namespace std;
struct node{
	long long hp,dmg;
}a[200010];
int n,A,B;
bool flag;
long long ans,t,sum;
bool cmp(node x,node y)
{
	return x.hp*t-x.dmg>y.hp*t-y.dmg;
}
int main()
{
	scanf("%d%d%d",&n,&A,&B);
	t=1;
	for(int i=1;i<=A;i++)
	{
		t*=2;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i].hp,&a[i].dmg);
		sum+=a[i].dmg;
		if(a[i].dmg<a[i].hp*t) flag=1;
	}
	if(!flag||B==0)
	{
		printf("%lld",sum);
		return 0;
	}
	long long temp=0;
	sort(a+1,a+1+n,cmp);
	if(A==0)
	{
		for(int i=1;i<=n;i++)
		{
			if(a[i].hp>a[i].dmg&&B>0)
			{
				temp+=a[i].hp;
				B--;
			}
			else temp+=a[i].dmg;
		}
		printf("%lld",max(sum,temp));
		return 0;
	}
	temp+=a[1].hp*t;
	B--;
	t=1;
	sort(a+2,a+1+n,cmp);
	for(int i=2;i<=n;i++)
	{
		if(a[i].hp>a[i].dmg&&B>0)
		{
			temp+=a[i].hp;
			B--;
		}
		else temp+=a[i].dmg;
	}
	printf("%lld",max(sum,temp));
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>

using namespace std;
struct node{
	long long hp,dmg;
}a[200010];
int n,A,B;
bool flag;
long long ans,t,sum;
bool cmp(node x,node y)
{
	return x.hp-x.dmg>y.hp-y.dmg;
}
int main()
{
	scanf("%d%d%d",&n,&A,&B);
	t=1;
	for(int i=1;i<=A;i++)
	{
		t*=2;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i].hp,&a[i].dmg);
		sum+=a[i].dmg;
		if(a[i].dmg<a[i].hp*t) flag=1;
	}
	if(flag||B==0)
	{
		printf("%lld",sum);
		return 0;
	}
	long long temp=0;
	sort(a+1,a+1+n,cmp);
	if(A==0)
	{
		for(int i=1;i<=n;i++)
		{
			if(a[i].hp>a[i].dmg&&B>0)
			{
				temp+=a[i].hp;
				B--;
			}
			else temp+=a[i].dmg;
		}
		printf("%lld",max(sum,temp));
		return 0;
	}
	temp+=a[1].hp*t;
	B--;
	for(int i=2;i<=n;i++)
	{
		if(a[i].hp>a[i].dmg&&B>0)
		{
			temp+=a[i].hp;
			B--;
		}
		else temp+=a[i].dmg;
	}
	printf("%lld",max(sum,temp));
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>

using namespace std;
struct node{
	long long hp,dmg;
}a[200010];
int n,A,B;
long long ans,t;
bool cmp1(node x,node y)
{
	return x.hp-x.dmg>y.hp-y.dmg;
}
bool cmp2(node x,node y)
{
	return x.hp*t-x.dmg>y.hp*t-y.dmg;
}

int main()
{
	scanf("%d%d%d",&n,&A,&B);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i].hp,&a[i].dmg);
	}
	if(B==0)
	{
		for(int i=1;i<=n;i++)
		ans+=a[i].dmg;
		printf("%lld",ans);
		return 0;
	}

	if(A==0)
	{
		sort(a+1,a+1+n,cmp1);
		for(int i=1;i<=n;i++)
		{
			if(a[i].hp>a[i].dmg&&B>0)
			{
				ans+=a[i].hp;
				B--;
			}
			else ans+=a[i].dmg;
		}
		printf("%lld",ans);
		return 0;
	}
	t=1;
	for(int i=1;i<=A;i++)
	{
		t*=2;
	}
	sort(a+1,a+1+n,cmp2);
	ans+=a[1].hp*t;
	B--;
	for(int i=2;i<=n;i++)
	{
		if(a[i].hp>a[i].dmg&&B>0)
		{
			ans+=a[i].hp;
			B--;
		}
		else ans+=a[i].dmg;
	}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>

using namespace std;
struct node{
	long long hp,dmg;
}a[200010];
int n,A,B;
bool flag;
long long ans,t;
bool cmp(node x,node y)
{
	return x.hp*t-x.dmg>y.hp*t-y.dmg;
}
int main()
{
	scanf("%d%d%d",&n,&A,&B);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i].hp,&a[i].dmg);
		if(a[i].dmg<a[i].hp) flag=1;
	}
	if(!flag||B==0)
	{
		for(int i=1;i<=n;i++)
		ans+=a[i].dmg;
		printf("%lld",ans);
		return 0;
	}
	t=1;
	for(int i=1;i<=A;i++)
	{
		t*=2;
	}
	sort(a+1,a+1+n,cmp);
	if(A==0)
	{
		for(int i=1;i<=n;i++)
		{
			if(a[i].hp>a[i].dmg&&B>0)
			{
				ans+=a[i].hp;
				B--;
			}
			else ans+=a[i].dmg;
		}
		printf("%lld",ans);
		return 0;
	}
	ans+=a[1].hp*t;
	B--;
	for(int i=2;i<=n;i++)
	{
		if(a[i].hp>a[i].dmg&&B>0)
		{
			ans+=a[i].hp;
			B--;
		}
		else ans+=a[i].dmg;
	}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>

using namespace std;
struct node{
	long long hp,dmg;
	bool f;
}a[200010];
int n,A,B;
bool flag;
long long ans,t,sum;
bool cmp(node x,node y)
{
	return x.hp-x.dmg>y.hp-y.dmg;
}
int main()
{
	scanf("%d%d%d",&n,&A,&B);
	t=1;
	for(int i=1;i<=A;i++)
	{
		t*=2;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i].hp,&a[i].dmg);
		sum+=a[i].dmg;
		if(a[i].dmg<a[i].hp*t) flag=1;
	}
	if(!flag||B==0)
	{
		printf("%lld",sum);
		return 0;
	}
	long long temp=0;
	sort(a+1,a+1+n,cmp);
	if(A==0)
	{
		for(int i=1;i<=n;i++)
		{
			if(a[i].hp>a[i].dmg&&B>0)
			{
				temp+=a[i].hp;
				B--;
			}
			else temp+=a[i].dmg;
		}
		printf("%lld",max(sum,temp));
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i].hp>a[i].dmg&&B>0)
		{
			temp+=a[i].hp;
			a[i].f=1;
			B--;
		}
		else temp+=a[i].dmg;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i].f)
		{
			temp-=a[i].hp;
			temp+=a[i].hp*t;
			ans=max(ans,temp);
			temp-=a[i].hp*t;
			temp+=a[i].hp;
		}
	}
	printf("%lld",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>

using namespace std;
struct node{
	long long hp,dmg;
}a[200010];
int n,A,B;
long long ans,t;
bool cmp(node x,node y)
{
	return x.hp*t-x.dmg>y.hp*t-y.dmg;
}

int main()
{
	scanf("%d%d%d",&n,&A,&B);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i].hp,&a[i].dmg);
	}
	if(B==0)
	{
		for(int i=1;i<=n;i++)
		ans+=a[i].dmg;
		printf("%lld",ans);
		return 0;
	}
	t=1;
	for(int i=1;i<=A;i++)
	{
		t*=2;
	}
	sort(a+1,a+1+n,cmp);
	if(A==0)
	{

		for(int i=1;i<=n;i++)
		{
			if(a[i].hp>a[i].dmg&&B>0)
			{
				ans+=a[i].hp;
				B--;
			}
			else ans+=a[i].dmg;
		}
		printf("%lld",ans);
		return 0;
	}
	ans+=a[1].hp*t;
	B--;
	for(int i=2;i<=n;i++)
	{
		if(a[i].hp>a[i].dmg&&B>0)
		{
			ans+=a[i].hp;
			B--;
		}
		else ans+=a[i].dmg;
	}
	printf("%lld",ans);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int N,A,B;
long long Sum;
struct ad{
	long long hp,dmg;
	bool operator < (const ad b) const{
		return (hp*(1<<A)-dmg>b.hp*(1<<A)-b.dmg);
	}
}S[200005];
inline int read(){
	int Res=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') Res=Res*10+ch-'0',ch=getchar();
	return Res;
}
bool cmp(ad x,ad y){
	return x.hp-x.dmg>y.hp-y.dmg;
}
int main()
{
	N=read();A=read();B=read();
	for (int i=1;i<=N;i++) S[i].hp=read(),S[i].dmg=read(),Sum+=S[i].dmg;
	if (!B){
		cout<<Sum<<endl;
		return 0;
	}
	sort(S+1,S+1+N);
	if (S[1].hp*(1<<A)>S[1].dmg) Sum-=S[1].dmg,Sum+=S[1].hp*(1<<A);
	sort(S+2,S+1+N,cmp);B--;
	for (int i=2;i<=1+B;i++){
		if (S[i].hp-S[i].dmg>0) Sum-=S[i].dmg,Sum+=S[i].hp;
		else break;
	}
	cout<<Sum<<endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int N,A,B;
long long Sum;
struct ad{
	long long hp,dmg;
	bool operator < (const ad b) const{
		return (hp*(1<<A)-dmg>b.hp*(1<<A)-b.dmg);
	}
}S[200005];
inline int read(){
	int Res=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') Res=Res*10+ch-'0',ch=getchar();
	return Res;
}
bool cmp(ad &x,ad &y){
	return x.hp-x.dmg>y.hp-y.dmg;
}
int main()
{
	N=read();A=read();B=read();
	for (int i=1;i<=N;i++) S[i].hp=read(),S[i].dmg=read(),Sum+=S[i].dmg;
	if (!B){
		cout<<Sum<<endl;
		return 0;
	}
	sort(S+1,S+1+N);
	if (S[1].hp*(1<<A)>S[1].dmg) Sum-=S[1].dmg,Sum+=S[1].hp*(1<<A);
	sort(S+2,S+1+N,cmp);B--;
	for (int i=2;i<=1+B;i++){
		if (S[i].hp-S[i].dmg>0) Sum-=S[i].dmg,Sum+=S[i].hp;
		else break;
	}
	cout<<Sum<<endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int N,A,B;
long long Sum,P;
struct ad{
	long long hp,dmg;
	bool operator < (const ad b) const{
		return -(hp-dmg)+hp*(1<<A)-dmg>-(b.hp-b.dmg)+b.hp*(1<<A)-b.dmg;
	}
}S[200005];
inline int read(){
	int Res=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') Res=Res*10+ch-'0',ch=getchar();
	return Res;
}
bool cmp(ad x,ad y){
	return x.hp-x.dmg>y.hp-y.dmg;
}
int main()
{
	N=read();A=read();B=read();
	for (int i=1;i<=N;i++) S[i].hp=read(),S[i].dmg=read(),Sum+=S[i].dmg,P+=S[i].hp-S[i].dmg;
	if (!B){
		cout<<Sum<<endl;
		return 0;
	}
	sort(S+1,S+1+N);
	if (S[1].hp*(1<<A)>S[1].dmg) Sum-=S[1].dmg,Sum+=S[1].hp*(1<<A);
	sort(S+2,S+1+N,cmp);B--;
	for (int i=2;i<=min(1+B,N);i++){
		if (S[i].hp-S[i].dmg>0) Sum-=S[i].dmg,Sum+=S[i].hp;
		else break;
	}
	cout<<Sum<<endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int N,A,B;
long long Sum,P,Ans;
struct ad{
	long long hp,dmg;
	bool operator < (const ad b) const{
		return hp-dmg>b.hp-b.dmg;
	}
}S[200005];
inline int read(){
	int Res=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') Res=Res*10+ch-'0',ch=getchar();
	return Res;
}
int main()
{
	N=read();A=read();B=read();
	for (int i=1;i<=N;i++) S[i].hp=read(),S[i].dmg=read(),Sum+=S[i].dmg;
	if (!B){
		cout<<Sum<<endl;
		return 0;
	}
	sort(S+1,S+1+N);
	for (int i=1;i<=B;i++) P+=max(0LL,S[i].hp-S[i].dmg);
	for (int i=1;i<=B;i++) Ans=max(Ans,P-max(0LL,S[i].hp-S[i].dmg)-S[i].dmg+(S[i].hp*(1<<A)));
	for (int i=B+1;i<=N;i++) Ans=max(Ans,P-max(0LL,S[B].hp-S[B].dmg)-S[i].dmg+(S[i].hp*(1<<A)));
	cout<<Sum+Ans<<endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int N,A,B;
long long Sum;
struct ad{
	long long hp,dmg;
	bool operator < (const ad b) const{
		return (hp*(1<<A)-dmg>b.hp*(1<<A)-b.dmg);
	}
}S[200005];
inline int read(){
	int Res=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') Res=Res*10+ch-'0',ch=getchar();
	return Res;
}
bool cmp(ad x,ad y){
	return x.hp-x.dmg>y.hp-y.dmg;
}
int main()
{
	N=read();A=read();B=read();
	for (int i=1;i<=N;i++) S[i].hp=read(),S[i].dmg=read(),Sum+=S[i].dmg;
	if (!B){
		cout<<Sum<<endl;
		return 0;
	}
	sort(S+1,S+1+N);
	if (S[1].hp*(1<<A)>S[1].dmg) Sum-=S[1].dmg,Sum+=S[1].hp*(1<<A);
	sort(S+2,S+1+N,cmp);B--;
	for (int i=2;i<=min(1+B,N);i++){
		if (S[i].hp-S[i].dmg>0) Sum-=S[i].dmg,Sum+=S[i].hp;
		else break;
	}
	cout<<Sum<<endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int N,A,B;
long long Sum;
struct ad{
	long long hp,dmg;
	bool operator < (const ad b) const{
		return (hp*(1<<A)-dmg>b.hp*(1<<A)-b.dmg);
	}
}S[200005];
inline int read(){
	int Res=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') Res=Res*10+ch-'0',ch=getchar();
	return Res;
}
bool cmp(ad &x,ad &y){
	return x.hp-x.dmg>y.hp-y.dmg;
}
int main()
{
	N=read();A=read();B=read();
	for (int i=1;i<=N;i++) S[i].hp=read(),S[i].dmg=read(),Sum+=S[i].dmg;
	if (!B){
		cout<<Sum<<endl;
		return 0;
	}
	sort(S+1,S+1+N);
	if (S[1].hp*(1<<A)>S[1].dmg) Sum-=S[1].dmg,Sum+=S[1].hp*(1<<A);
	sort(S+2,S+1+N,cmp);B--;
	for (int i=2;i<=min(1+B,N);i++){
		if (S[i].hp-S[i].dmg>0) Sum-=S[i].dmg,Sum+=S[i].hp;
		else break;
	}
	cout<<Sum<<endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int N,A,B;
long long Sum=0;
struct ad{
	int hp,dmg;
	bool operator < (const ad b) const{
		return ((long long)hp*(1<<A)-dmg>(long long)b.hp*(1<<A)-b.dmg);
	}
}S[200005];
inline int read(){
	int Res=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') Res=Res*10+ch-'0',ch=getchar();
	return Res;
}
bool cmp(ad x,ad y){
	return x.hp-x.dmg>y.hp-y.dmg;
}
int main()
{
	N=read();A=read();B=read();
	for (int i=1;i<=N;i++) S[i].hp=read(),S[i].dmg=read(),Sum+=S[i].dmg;
	if (!B){
		cout<<Sum<<endl;
		return 0;
	}
	sort(S+1,S+1+N);
	if ((long long)S[1].hp*(1<<A)>S[1].dmg) Sum-=S[1].dmg,Sum+=(long long)S[1].hp*(1<<A);
	sort(S+2,S+1+N,cmp);B--;
	for (int i=2;i<=1+B;i++){
		if (S[i].hp-S[i].dmg>0) Sum-=S[i].dmg,Sum+=S[i].hp;
		else break;
	}
	cout<<Sum<<endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int N,A,B;
long long Sum;
struct ad{
	long long hp;int dmg;
	bool operator < (const ad b) const{
		return (hp*(1<<A)-dmg>b.hp*(1<<A)-b.dmg);
	}
}S[200005];
inline int read(){
	int Res=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') Res=Res*10+ch-'0',ch=getchar();
	return Res;
}
bool cmp(ad x,ad y){
	return x.hp-x.dmg>y.hp-y.dmg;
}
int main()
{
	N=read();A=read();B=read();
	for (int i=1;i<=N;i++) S[i].hp=read(),S[i].dmg=read(),Sum+=S[i].dmg;
	if (!B){
		cout<<Sum<<endl;
		return 0;
	}
	sort(S+1,S+1+N);
	if (S[1].hp*(1<<A)>S[1].dmg) Sum-=S[1].dmg,Sum+=S[1].hp*(1<<A);
	sort(S+2,S+1+N,cmp);B--;
	for (int i=2;i<=1+B;i++){
		if (S[i].hp-S[i].dmg>0) Sum-=S[i].dmg,Sum+=S[i].hp;
		else break;
	}
	cout<<Sum<<endl;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n;long long tpa,tpb;
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return x.first-x.second>y.first-y.second;
}
long long dp[2][21][21];
long long po2[22];
long long ui=-1;
long long ans;
int main()
{
	po2[0]=1;
	for(long long i=1;i<=21;i++) po2[i]=po2[i-1]*2;
	 cin>>n>>tpa>>tpb;
	 for(long long i=0;i<n;i++) scanf("%I64d %I64d",&p[i].first,&p[i].second),ans+=p[i].second;
	 sort(p,p+n,cmp);
	 while(tpb>tpa)
	 {
	 	tpb--,ui++;
	 	if(p[ui].first<p[ui].second) tpb=tpa,ui--;else ans+=-p[ui].second+p[ui].first;
	 }
	 for(long long i=0;i<2;i++)
	 {
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			dp[i][j][k]=0;
	 		}
	 	}
	 }
	 long long now=0;
	 for(long long i=0;i<n;i++)
	 {
	 	for(long long j=tpa;j>=0;j--)
	 	{
	 		for(long long k=tpb;k>=0;k--)
	 		{
	 			if(i<=ui and k!=tpb) break;
	 			dp[!now][j][k]=max(dp[now][j][k],dp[!now][j][k]);
	 			dp[now][j][k-1]=max(dp[now][j][k-1],dp[now][j][k]);
	 			dp[now][j-1][k]=max(dp[now][j-1][k],dp[now][j][k]);
	 			dp[now][j-1][k-1]=max(dp[now][j-1][k-1],dp[now][j][k]);

	 			if(i>ui)dp[!now][j][k-1]=max(dp[now][j][k]+p[i].first-p[i].second,dp[!now][j][k-1]);

	 			if(k>0 or i<=ui) for(long long z=0;z<j;z++)
	 			{
	 				if(i<=ui)dp[!now][z][k]=max(dp[now][j][k]-p[i].first+p[i].first*po2[j-z],dp[!now][z][k]);
	 				if(i>ui) dp[!now][z][k-1]=max(dp[now][j][k]-p[i].second+p[i].first*po2[j-z],dp[!now][z][k-1]);
	 			}
	 			if(n==7 and i==3 and 0)
	 			{
	 					for(long long j=0;j<=tpa;j++)
	 				{
	 			for(long long k=0;k<=tpb;k++)
		 		{
	 			cout<<dp[!now][j][k]<<" ";
	 			}
	 				}cout<<"\n";
	 			}

	 		}
	 	}
	 	now=!now;
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			if(n==7) cout<<dp[now][j][k]<<" ";
	 			dp[!now][j][k]=0;
	 		}
	 	}if(n==7 and i>2) cout<<"\n";
	 }
	 long long aaa=ans;
	for(long long j=0;j<=tpa;j++)
	{
	 	for(long long k=0;k<=tpb;k++)
	 	{//cout<<" "<<dp[n][j][k]<<" "<<ans<<"\n";
	 		aaa=max(aaa,ans+dp[now][j][k]);	if(n==7) cout<<dp[now][j][k]<<" ";
	 	}
	}if(n==7) cout<<"\n";

	cout<<aaa;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n;long long tpa,tpb;
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return x.first-x.second>y.first-y.second;
}
long long dp[2][21][21];
long long po2[22];
long long ui=-1;
long long ans;
int main()
{
	po2[0]=1;
	for(long long i=1;i<=21;i++) po2[i]=po2[i-1]*2;
	 cin>>n>>tpa>>tpb;//
	 for(long long i=0;i<n;i++) scanf("%I64d %I64d",&p[i].first,&p[i].second),ans+=p[i].second;
	 sort(p,p+n,cmp);
	 while(tpb>tpa)
	 {
	 	tpb--,ui++;
	 	if(p[ui].first<p[ui].second) tpb=tpa,ui--;else ans+=-p[ui].second+p[ui].first;
	 }
	 for(long long i=0;i<2;i++)
	 {
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			dp[i][j][k]=0;
	 		}
	 	}
	 }
	 long long now=0;
	 for(long long i=0;i<n;i++)
	 {
	 	for(long long j=tpa;j>=0;j--)
	 	{
	 		for(long long k=tpb;k>=0;k--)
	 		{
	 			if(i<=ui and k!=tpb) break;
	 			dp[!now][j][k]=max(dp[now][j][k],dp[!now][j][k]);
	 			dp[now][j][k-1]=max(dp[now][j][k-1],dp[now][j][k]);
	 			dp[now][j-1][k]=max(dp[now][j-1][k],dp[now][j][k]);
	 			dp[now][j-1][k-1]=max(dp[now][j-1][k-1],dp[now][j][k]);

	 			if(i>ui)dp[!now][j][k-1]=max(dp[now][j][k]+p[i].first-p[i].second,dp[!now][j][k-1]);

	 			if(k>0 or i<=ui) for(long long z=0;z<j;z++)
	 			{
	 				if(i<=ui)dp[!now][z][k]=max(dp[now][j][k]-p[i].first+p[i].first*po2[j-z],dp[!now][z][k]);
	 				if(i>ui) dp[!now][z][k-1]=max(dp[now][j][k]-p[i].second+p[i].first*po2[j-z],dp[!now][z][k-1]);
	 			}

	 		}
	 	}
	 	now=!now;
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			dp[!now][j][k]=0;
	 		}
	 	}
	 }
	 long long aaa=ans;
	for(long long j=0;j<=tpa;j++)
	{
	 	for(long long k=0;k<=tpb;k++)
	 	{//cout<<" "<<dp[n][j][k]<<" "<<ans<<"\n";
	 		aaa=max(aaa,ans+dp[now][j][k]);
	 	}
	}
	cout<<aaa;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n;long long tpa,tpb;
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return x.first-x.second>y.first-y.second;
}
long long dp[200008][21][21];
long long po2[22];
long long ui=-1;
long long ans;
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	po2[0]=1;
	for(long long i=1;i<=21;i++) po2[i]=po2[i-1]*2;
	 cin>>n>>tpa>>tpb;
	 for(long long i=0;i<n;i++) scanf("%d %d",&p[i].first,&p[i].second),ans+=p[i].second;
	 sort(p,p+n,cmp);
	 while(tpb>tpa)
	 {
	 	tpb--,ui++;
	 	if(p[ui].first<p[ui].second) tpb=tpa;else ans-=p[ui].second-p[ui].first;
	 }
	 for(long long i=0;i<n+1;i++)
	 {
	 	for(long long j=0;j<tpa;j++)
	 	{
	 		for(long long k=0;k<tpb;k++)
	 		{
	 			dp[i][j][k]=-1e18;
	 		}
	 	}
	 }
	 dp[0][tpa][tpb]=0;

	 for(long long i=0;i<n;i++)
	 {
	 	for(long long j=tpa;j>=0;j--)
	 	{
	 		for(long long k=tpb;k>=0;k--)
	 		{
	 			dp[i+1][j][k]=max(dp[i][j][k],dp[i+1][j][k]);
	 			dp[i][j][k-1]=max(dp[i][j][k-1],dp[i][j][k]);
	 			dp[i][j-1][k]=max(dp[i][j-1][k],dp[i][j][k]);
	 			dp[i][j-1][k-1]=max(dp[i][j-1][k-1],dp[i][j][k]);
	 			if(i>ui)dp[i+1][j][k-1]=max(dp[i][j][k]+p[ui].first-p[ui].second,dp[i+1][j][k-1]);
	 			if(k>0 or i<=ui) for(long long z=0;z<j;z++)
	 			{
	 				if(i<=ui)dp[i+1][z][k]=max(dp[i][j][k]-p[i].first+p[i].first*po2[j-z],dp[i+1][z][k]);
	 				if(i>ui) dp[i+1][z][k-1]=max(dp[i][j][k]-p[i].second+p[i].first*po2[j-z],dp[i+1][z][k-1]);
	 			}
	 		}
	 	}
	 }
	 long long aaa=ans;
	for(long long j=0;j<=tpa;j++)
	{
	 	for(long long k=0;k<=tpb;k++)
	 	{//cout<<" "<<dp[n][j][k]<<" "<<ans<<"\n";
	 		aaa=max(aaa,ans+dp[n][j][k]);
	 	}
	}
	cout<<aaa;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n;long long tpa,tpb;
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return x.first-x.second>y.first-y.second;
}
long long dp[2][21][21];
long long po2[22];
long long ui=-1;
long long ans;
int main()
{
	po2[0]=1;
	for(long long i=1;i<=21;i++) po2[i]=po2[i-1]*2;
	 cin>>n>>tpa>>tpb;//
	 for(long long i=0;i<n;i++) scanf("%I64d %I64d",&p[i].first,&p[i].second),ans+=p[i].second;
	 sort(p,p+n,cmp);
	 while(tpb>tpa)
	 {
	 	tpb--,ui++;
	 	if(p[ui].first<p[ui].second) tpb=tpa,ui--;else ans+=-p[ui].second+p[ui].first;
	 }
	 for(long long i=0;i<2;i++)
	 {
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			dp[i][j][k]=0;
	 		}
	 	}
	 }
	 long long now=0;
	 for(long long i=0;i<n;i++)
	 {
	 	for(long long j=tpa;j>=0;j--)
	 	{
	 		for(long long k=tpb;k>=0;k--)
	 		{
	 			if(i<=ui and k!=tpb) break;
	 			dp[!now][j][k]=max(dp[now][j][k],dp[!now][j][k]);
	 			dp[now][j][k-1]=max(dp[now][j][k-1],dp[now][j][k]);
	 			dp[now][j-1][k]=max(dp[now][j-1][k],dp[now][j][k]);
	 			dp[now][j-1][k-1]=max(dp[now][j-1][k-1],dp[now][j][k]);

	 			if(i>ui)dp[!now][j][k-1]=max(dp[now][j][k]+p[i].first-p[i].second,dp[!now][j][k-1]);

	 			if(k>0 or i<=ui) for(long long z=0;z<j;z++)
	 			{
	 				if(i<=ui)dp[!now][z][k]=max(dp[now][j][k]-p[i].first+p[i].first*po2[j-z],dp[!now][z][k]);
	 				if(i>ui) dp[!now][z][k-1]=max(dp[now][j][k]-p[i].second+p[i].first*po2[j-z],dp[!now][z][k-1]);
	 			}

	 		}
	 	}
	 	now=!now;
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			if(n==7) cout<<dp[!now][j][k]<<" ";
	 			dp[!now][j][k]=0;
	 		}
	 	}if(n==7) cout<<"\n";
	 }
	 long long aaa=ans;
	for(long long j=0;j<=tpa;j++)
	{
	 	for(long long k=0;k<=tpb;k++)
	 	{//cout<<" "<<dp[n][j][k]<<" "<<ans<<"\n";
	 		aaa=max(aaa,ans+dp[now][j][k]);	if(n==7) cout<<dp[now][j][k]<<" ";
	 	}
	}if(n==7) cout<<"\n";

	cout<<aaa;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n;long long tpa,tpb;
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return x.first-x.second>y.first-y.second;
}
long long dp[2][21][21];
long long po2[22];
long long ui=-1;
long long ans;
int main()
{
	po2[0]=1;
	for(long long i=1;i<=21;i++) po2[i]=po2[i-1]*2;
	 cin>>n>>tpa>>tpb;
	 for(long long i=0;i<n;i++) scanf("%d %d",&p[i].first,&p[i].second),ans+=p[i].second;
	 sort(p,p+n,cmp);
	 while(tpb>tpa)
	 {
	 	tpb--,ui++;
	 	if(p[ui].first<p[ui].second) tpb=tpa;else ans+=-p[ui].second+p[ui].first;
	 }
	 for(long long i=0;i<2;i++)
	 {
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			dp[i][j][k]=-1e18;
	 		}
	 	}
	 }
	 dp[0][tpa][tpb]=0;
	 long long now=0;
	 for(long long i=0;i<n;i++)
	 {
	 	for(long long j=tpa;j>=0;j--)
	 	{
	 		for(long long k=tpb;k>=0;k--)
	 		{
	 			dp[!now][j][k]=max(dp[now][j][k],dp[!now][j][k]);
	 			dp[now][j][k-1]=max(dp[now][j][k-1],dp[now][j][k]);
	 			dp[now][j-1][k]=max(dp[now][j-1][k],dp[now][j][k]);
	 			dp[now][j-1][k-1]=max(dp[now][j-1][k-1],dp[now][j][k]);

	 			if(i>ui)dp[!now][j][k-1]=max(dp[now][j][k]+p[i].first-p[i].second,dp[!now][j][k-1]);

	 			if(k>0 or i<=ui) for(long long z=0;z<j;z++)
	 			{
	 				if(i<=ui)dp[!now][z][k]=max(dp[now][j][k]-p[i].first+p[i].first*po2[j-z],dp[!now][z][k]);
	 				if(i>ui) dp[!now][z][k-1]=max(dp[now][j][k]-p[i].second+p[i].first*po2[j-z],dp[!now][z][k-1]);
	 			}

	 		}
	 	}
	 	now=!now;
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			dp[!now][j][k]=-1e18;
	 		}
	 	}
	 }
	 long long aaa=ans;
	for(long long j=0;j<=tpa;j++)
	{
	 	for(long long k=0;k<=tpb;k++)
	 	{//cout<<" "<<dp[n][j][k]<<" "<<ans<<"\n";
	 		aaa=max(aaa,ans+dp[now][j][k]);
	 	}
	}
	cout<<aaa;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n,a,b;
long long dp[200008];
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return (x.first-x.second)>(y.first-y.second);
}
int main()
{
	cin>>n>>a>>b;	long long ans=0;long long tot=-1;
	for(long long i=0;i<n;i++)
	{
		cin>>p[i].first>>p[i].second;ans+=p[i].second;
	}
	sort(p,p+n,cmp);
	for(long long i=0;i<b;i++)
	{
		long long t=p[i].first-p[i].second;
		if(t>0) ans+=t;
	}tot=ans;
	for(long long i=0;i<n;i++)
	{
		if(i<b)
		{
			long long t=p[i].first-p[i].second;
			long long sum=ans-p[i].second;
			if(t>0) sum-=t;sum+=(p[i].first<<a);
			tot=max(tot,sum);
		}
		else
		{
			long long t=p[b-1].first-p[b-1].second;
			long long sum=ans-p[i].second;
			if(t>0) sum-=t;sum+=(p[i].first<<a);
			tot=max(tot,sum);
		}
	}cout<<tot;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n;long long tpa,tpb;
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return x.first-x.second>y.first-y.second;
}
long long dp[2][21][21];
long long po2[22];
long long ui=-1;
long long ans;
int main()
{
	po2[0]=1;
	for(long long i=1;i<=21;i++) po2[i]=po2[i-1]*2;
	 cin>>n>>tpa>>tpb;//
	 for(long long i=0;i<n;i++) scanf("%I64d %I64d",&p[i].first,&p[i].second),ans+=p[i].second;
	 sort(p,p+n,cmp);
	 while(tpb>tpa)
	 {
	 	tpb--,ui++;
	 	if(p[ui].first<p[ui].second) tpb=tpa,ui--;else ans+=-p[ui].second+p[ui].first;
	 }
	 for(long long i=0;i<2;i++)
	 {
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			dp[i][j][k]=0;
	 		}
	 	}
	 }
	 long long now=0;
	 for(long long i=0;i<n;i++)
	 {
	 	for(long long j=tpa;j>=0;j--)
	 	{
	 		for(long long k=tpb;k>=0;k--)
	 		{
	 			if(i<=ui and k!=tpb) break;
	 			dp[!now][j][k]=max(dp[now][j][k],dp[!now][j][k]);
	 			dp[now][j][k-1]=max(dp[now][j][k-1],dp[now][j][k]);
	 			dp[now][j-1][k]=max(dp[now][j-1][k],dp[now][j][k]);
	 			dp[now][j-1][k-1]=max(dp[now][j-1][k-1],dp[now][j][k]);

	 			if(i>ui)dp[!now][j][k-1]=max(dp[now][j][k]+p[i].first-p[i].second,dp[!now][j][k-1]);

	 			if(k>0 or i<=ui) for(long long z=0;z<j;z++)
	 			{
	 				if(i<=ui)dp[!now][z][k]=max(dp[now][j][k]-p[i].first+p[i].first*po2[j-z],dp[!now][z][k]);
	 				if(i>ui) dp[!now][z][k-1]=max(dp[now][j][k]-p[i].second+p[i].first*po2[j-z],dp[!now][z][k-1]);
	 			}

	 		}
	 	}
	 	now=!now;
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			if(n==7 and i>3) cout<<dp[!now][j][k]<<" ";
	 			dp[!now][j][k]=0;
	 		}
	 	}if(n==7) cout<<"\n";
	 }
	 long long aaa=ans;
	for(long long j=0;j<=tpa;j++)
	{
	 	for(long long k=0;k<=tpb;k++)
	 	{//cout<<" "<<dp[n][j][k]<<" "<<ans<<"\n";
	 		aaa=max(aaa,ans+dp[now][j][k]);	if(n==7) cout<<dp[now][j][k]<<" ";
	 	}
	}if(n==7) cout<<"\n";

	cout<<aaa;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n;long long tpa,tpb;
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return x.first-x.second>y.first-y.second;
}
long long dp[2][21][21];
long long po2[22];
long long ui=-1;
long long ans;
int main()
{
	po2[0]=1;
	for(long long i=1;i<=21;i++) po2[i]=po2[i-1]*2;
	 cin>>n>>tpa>>tpb;
	 for(long long i=0;i<n;i++) scanf("%I64d %I64d",&p[i].first,&p[i].second),ans+=p[i].second;
	 sort(p,p+n,cmp);
	 while(tpb>tpa)
	 {
	 	tpb--,ui++;
	 	if(p[ui].first<p[ui].second) tpb=tpa,ui--;else ans+=-p[ui].second+p[ui].first;
	 }
	 for(long long i=0;i<2;i++)
	 {
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			dp[i][j][k]=0;
	 		}
	 	}
	 }
	 long long now=0;
	 for(long long i=0;i<n;i++)
	 {
	 	for(long long j=tpa;j>=0;j--)
	 	{
	 		for(long long k=tpb;k>=0;k--)
	 		{
	 			if(i<=ui and k!=tpb) break;
	 			dp[!now][j][k]=max(dp[now][j][k],dp[!now][j][k]);
	 			dp[now][j][k-1]=max(dp[now][j][k-1],dp[now][j][k]);
	 			dp[now][j-1][k]=max(dp[now][j-1][k],dp[now][j][k]);
	 			dp[now][j-1][k-1]=max(dp[now][j-1][k-1],dp[now][j][k]);

	 			if(i>ui)dp[!now][j][k-1]=max(dp[now][j][k]+p[i].first-p[i].second,dp[!now][j][k-1]);

	 			if(k>0 or i<=ui) for(long long z=0;z<j;z++)
	 			{
	 				if(i<=ui)dp[!now][z][k]=max(dp[now][j][k]-p[i].first+p[i].first*po2[j-z],dp[!now][z][k]);
	 				if(i>ui) dp[!now][z][k-1]=max(dp[now][j][k]-p[i].second+p[i].first*po2[j-z],dp[!now][z][k-1]);
	 			}
	 			if(n==7 and i==3)
	 			{
	 					for(long long j=0;j<=tpa;j++)
	 				{
	 			for(long long k=0;k<=tpb;k++)
		 		{
	 			cout<<dp[!now][j][k]<<" ";
	 			}
	 				}cout<<"\n";
	 			}

	 		}
	 	}
	 	now=!now;
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			if(n==7 and i>2) cout<<dp[!now][j][k]<<" ";
	 			dp[!now][j][k]=0;
	 		}
	 	}if(n==7 and i>2) cout<<"\n";
	 }
	 long long aaa=ans;
	for(long long j=0;j<=tpa;j++)
	{
	 	for(long long k=0;k<=tpb;k++)
	 	{//cout<<" "<<dp[n][j][k]<<" "<<ans<<"\n";
	 		aaa=max(aaa,ans+dp[now][j][k]);	if(n==7) cout<<dp[now][j][k]<<" ";
	 	}
	}if(n==7) cout<<"\n";

	cout<<aaa;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n,a,b;
long long dp[200008];
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return (x.first-x.second)>(y.first-y.second);
}
int main()
{
	cin>>n>>a>>b;	long long ans=0;long long tot=-1;
	for(long long i=0;i<n;i++)
	{
		cin>>p[i].first>>p[i].second;ans+=p[i].second;
	}
	sort(p,p+n,cmp);
	for(long long i=0;i<b;i++)
	{
		long long t=p[i].first-p[i].second;
		if(t>0) ans+=t;
	}tot=ans;
	if(b>0)for(long long i=0;i<n;i++)
	{
		if(i<b)
		{
			long long t=p[i].first-p[i].second;
			long long sum=ans-p[i].second;
			if(t>0) sum-=t;sum+=(p[i].first<<a);
			tot=max(tot,sum);
		}
		else
		{
			long long t=p[b-1].first-p[b-1].second;
			long long sum=ans-p[i].second;
			if(t>0) sum-=t;sum+=(p[i].first<<a);
			tot=max(tot,sum);
		}
	}cout<<tot;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n;long long tpa,tpb;
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return x.first-x.second>y.first-y.second;
}
long long dp[2][21][21];
long long po2[22];
long long ui=-1;
long long ans;
int main()
{
	po2[0]=1;
	for(long long i=1;i<=21;i++) po2[i]=po2[i-1]*2;
	 cin>>n>>tpa>>tpb;
	 for(long long i=0;i<n;i++) scanf("%d %d",&p[i].first,&p[i].second),ans+=p[i].second;
	 sort(p,p+n,cmp);
	 while(tpb>tpa)
	 {
	 	tpb--,ui++;
	 	if(p[ui].first<p[ui].second) tpb=tpa;else ans-=p[ui].second-p[ui].first;
	 }
	 for(long long i=0;i<2;i++)
	 {
	 	for(long long j=0;j<tpa;j++)
	 	{
	 		for(long long k=0;k<tpb;k++)
	 		{
	 			dp[i][j][k]=-1e18;
	 		}
	 	}
	 }
	 dp[0][tpa][tpb]=0;
	 long long now=0;
	 for(long long i=0;i<n;i++)
	 {
	 	for(long long j=tpa;j>=0;j--)
	 	{
	 		for(long long k=tpb;k>=0;k--)
	 		{
	 			dp[!now][j][k]=max(dp[now][j][k],dp[!now][j][k]);
	 			dp[now][j][k-1]=max(dp[now][j][k-1],dp[now][j][k]);
	 			dp[now][j-1][k]=max(dp[now][j-1][k],dp[now][j][k]);
	 			dp[now][j-1][k-1]=max(dp[now][j-1][k-1],dp[now][j][k]);
	 			if(i>ui)dp[!now][j][k-1]=max(dp[now][j][k]+p[i].first-p[i].second,dp[!now][j][k-1]);
	 			if(k>0 or i<=ui) for(long long z=0;z<j;z++)
	 			{
	 				if(i<=ui)dp[!now][z][k]=max(dp[now][j][k]-p[i].first+p[i].first*po2[j-z],dp[!now][z][k]);
	 				if(i>ui) dp[!now][z][k-1]=max(dp[now][j][k]-p[i].second+p[i].first*po2[j-z],dp[!now][z][k-1]);
	 			}
	 		}
	 	}
	 	now=!now;
	 	for(long long j=0;j<tpa;j++)
	 	{
	 		for(long long k=0;k<tpb;k++)
	 		{
	 			dp[!now][j][k]=-1e18;
	 		}
	 	}
	 }
	 long long aaa=ans;
	for(long long j=0;j<=tpa;j++)
	{
	 	for(long long k=0;k<=tpb;k++)
	 	{//cout<<" "<<dp[n][j][k]<<" "<<ans<<"\n";
	 		aaa=max(aaa,ans+dp[now][j][k]);
	 	}
	}
	cout<<aaa;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n;long long tpa,tpb;
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return x.first-x.second>y.first-y.second;
}
long long dp[2][21][21];
long long po2[22];
long long ui=-1;
long long ans;
int main()
{
	po2[0]=1;
	for(long long i=1;i<=21;i++) po2[i]=po2[i-1]*2;
	 cin>>n>>tpa>>tpb;
	 for(long long i=0;i<n;i++) scanf("%I64d %I64d",&p[i].first,&p[i].second),ans+=p[i].second;
	 sort(p,p+n,cmp);
	 while(tpb>tpa)
	 {
	 	tpb--,ui++;
	 	if(p[ui].first<p[ui].second) tpb=tpa,ui--;else ans+=-p[ui].second+p[ui].first;
	 }
	 for(long long i=0;i<2;i++)
	 {
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			dp[i][j][k]=0;
	 		}
	 	}
	 }if(n==7)for(long long i=0;i<n;i++) cout<<p[i].first<<p[i].second<<"    ";cout<<"\n";
	 long long now=0;
	 for(long long i=0;i<n;i++)
	 {
	 	for(long long j=tpa;j>=0;j--)
	 	{
	 		for(long long k=tpb;k>=0;k--)
	 		{
	 			if(i<=ui and k!=tpb) break;
	 			dp[!now][j][k]=max(dp[now][j][k],dp[!now][j][k]);
	 			dp[now][j][k-1]=max(dp[now][j][k-1],dp[now][j][k]);
	 			dp[now][j-1][k]=max(dp[now][j-1][k],dp[now][j][k]);
	 			dp[now][j-1][k-1]=max(dp[now][j-1][k-1],dp[now][j][k]);

	 			if(i>ui)dp[!now][j][k-1]=max(dp[now][j][k]+p[i].first-p[i].second,dp[!now][j][k-1]);

	 			if(k>0 or i<=ui) for(long long z=0;z<j;z++)
	 			{
	 				if(i<=ui)dp[!now][z][k]=max(dp[now][j][k]-p[i].first+p[i].first*po2[j-z],dp[!now][z][k]);
	 				if(i>ui) dp[!now][z][k-1]=max(dp[now][j][k]-p[i].second+p[i].first*po2[j-z],dp[!now][z][k-1]);
	 			}
	 			if(n==7 and i==3)
	 			{
	 					for(long long j=0;j<=tpa;j++)
	 				{
	 			for(long long k=0;k<=tpb;k++)
		 		{
	 			cout<<dp[!now][j][k]<<" ";
	 			}
	 				}cout<<"\n";
	 			}

	 		}
	 	}
	 	now=!now;
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			if(n==7 and i==2) cout<<dp[now][j][k]<<" ";
	 			dp[!now][j][k]=0;
	 		}
	 	}if(n==7 and i>2) cout<<"\n";
	 }
	 long long aaa=ans;
	for(long long j=0;j<=tpa;j++)
	{
	 	for(long long k=0;k<=tpb;k++)
	 	{//cout<<" "<<dp[n][j][k]<<" "<<ans<<"\n";
	 		aaa=max(aaa,ans+dp[now][j][k]);	if(n==7) cout<<dp[now][j][k]<<" ";
	 	}
	}if(n==7) cout<<"\n";

	cout<<aaa;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n;long long tpa,tpb;
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return x.first-x.second>y.first-y.second;
}
long long dp[2][21][21];
long long po2[22];
long long ui=-1;
long long ans;
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	po2[0]=1;
	for(long long i=1;i<=21;i++) po2[i]=po2[i-1]*2;
	 cin>>n>>tpa>>tpb;
	 for(long long i=0;i<n;i++) scanf("%d %d",&p[i].first,&p[i].second),ans+=p[i].second;
	 sort(p,p+n,cmp);
	 while(tpb>tpa)
	 {
	 	tpb--,ui++;
	 	if(p[ui].first<p[ui].second) tpb=tpa;else ans-=p[ui].second-p[ui].first;
	 }
	 for(long long i=0;i<2;i++)
	 {
	 	for(long long j=0;j<tpa;j++)
	 	{
	 		for(long long k=0;k<tpb;k++)
	 		{
	 			dp[i][j][k]=-1e18;
	 		}
	 	}
	 }
	 dp[0][tpa][tpb]=0;
	 long long now=0;
	 for(long long i=0;i<n;i++)
	 {
	 	for(long long j=tpa;j>=0;j--)
	 	{
	 		for(long long k=tpb;k>=0;k--)
	 		{
	 			dp[!now][j][k]=max(dp[now][j][k],dp[!now][j][k]);
	 			dp[now][j][k-1]=max(dp[now][j][k-1],dp[now][j][k]);
	 			dp[now][j-1][k]=max(dp[now][j-1][k],dp[now][j][k]);
	 			dp[now][j-1][k-1]=max(dp[now][j-1][k-1],dp[now][j][k]);
	 			if(i>ui)dp[!now][j][k-1]=max(dp[now][j][k]+p[ui].first-p[ui].second,dp[!now][j][k-1]);
	 			if(k>0 or i<=ui) for(long long z=0;z<j;z++)
	 			{
	 				if(i<=ui)dp[!now][z][k]=max(dp[now][j][k]-p[i].first+p[i].first*po2[j-z],dp[!now][z][k]);
	 				if(i>ui) dp[!now][z][k-1]=max(dp[now][j][k]-p[i].second+p[i].first*po2[j-z],dp[!now][z][k-1]);
	 			}
	 		}
	 	}
	 	now=!now;
	 	for(long long j=0;j<tpa;j++)
	 	{
	 		for(long long k=0;k<tpb;k++)
	 		{
	 			dp[!now][j][k]=-1e18;
	 		}
	 	}
	 }
	 long long aaa=ans;
	for(long long j=0;j<=tpa;j++)
	{
	 	for(long long k=0;k<=tpb;k++)
	 	{//cout<<" "<<dp[n][j][k]<<" "<<ans<<"\n";
	 		aaa=max(aaa,ans+dp[now][j][k]);
	 	}
	}
	cout<<aaa;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n,a,b;
long long dp[200008];
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return (x.first-x.second)>(y.first-y.second);
}
int main()
{
	cin>>n>>a>>b;	long long ans=0;long long tot=-1;
	for(long long i=0;i<n;i++)
	{
		scanf("%I64d %I64d",&p[i].first,&p[i].second);
	ans+=p[i].second;
	}
	sort(p,p+n,cmp);
	for(long long i=0;i<b;i++)
	{
		long long t=p[i].first-p[i].second;
		if(t>0) ans+=t;
	}tot=ans;
	if(b>0)for(long long i=0;i<n;i++)
	{
		if(i<b)
		{
			long long t=p[i].first-p[i].second;
			long long sum=ans-p[i].second;
			if(t>0) sum-=t;sum+=(p[i].first<<a);
			tot=max(tot,sum);
		}
		else
		{
			long long t=p[b-1].first-p[b-1].second;
			long long sum=ans-p[i].second;
			if(t>0) sum-=t;sum+=(p[i].first<<a);
			tot=max(tot,sum);
		}
	}cout<<tot;
	return 0;
}


//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
long long n;long long tpa,tpb;
pair<long long,long long> p[200008];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return x.first-x.second>y.first-y.second;
}
long long dp[2][21][21];
long long po2[22];
long long ui=-1;
long long ans;
int main()
{
	po2[0]=1;
	for(long long i=1;i<=21;i++) po2[i]=po2[i-1]*2;
	 cin>>n>>tpa>>tpb;//
	 for(long long i=0;i<n;i++) scanf("%I64d %I64d",&p[i].first,&p[i].second),ans+=p[i].second;
	 if(n==7)for(long long i=0;i<n;i++) cout<<p[i].first<<p[i].second<<" ";
	if(n==7) for(int i=0;i<20;i++) cout<<po2[i]<<" ";
	 sort(p,p+n,cmp);
	 while(tpb>tpa)
	 {
	 	tpb--,ui++;
	 	if(p[ui].first<p[ui].second) tpb=tpa,ui--;else ans+=-p[ui].second+p[ui].first;
	 }
	 for(long long i=0;i<2;i++)
	 {
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			dp[i][j][k]=0;
	 		}
	 	}
	 }
	 long long now=0;
	 for(long long i=0;i<n;i++)
	 {
	 	for(long long j=tpa;j>=0;j--)
	 	{
	 		for(long long k=tpb;k>=0;k--)
	 		{
	 			if(i<=ui and k!=tpb) break;
	 			dp[!now][j][k]=max(dp[now][j][k],dp[!now][j][k]);
	 			dp[now][j][k-1]=max(dp[now][j][k-1],dp[now][j][k]);
	 			dp[now][j-1][k]=max(dp[now][j-1][k],dp[now][j][k]);
	 			dp[now][j-1][k-1]=max(dp[now][j-1][k-1],dp[now][j][k]);

	 			if(i>ui)dp[!now][j][k-1]=max(dp[now][j][k]+p[i].first-p[i].second,dp[!now][j][k-1]);

	 			if(k>0 or i<=ui) for(long long z=0;z<j;z++)
	 			{
	 				if(i<=ui)dp[!now][z][k]=max(dp[now][j][k]-p[i].first+p[i].first*po2[j-z],dp[!now][z][k]);
	 				if(i>ui) dp[!now][z][k-1]=max(dp[now][j][k]-p[i].second+p[i].first*po2[j-z],dp[!now][z][k-1]);
	 			}

	 		}
	 	}
	 	now=!now;
	 	for(long long j=0;j<=tpa;j++)
	 	{
	 		for(long long k=0;k<=tpb;k++)
	 		{
	 			if(n==7 and i>3) cout<<dp[!now][j][k]<<" ";
	 			dp[!now][j][k]=0;
	 		}
	 	}if(n==7 and i>3) cout<<"\n";
	 }
	 long long aaa=ans;
	for(long long j=0;j<=tpa;j++)
	{
	 	for(long long k=0;k<=tpb;k++)
	 	{//cout<<" "<<dp[n][j][k]<<" "<<ans<<"\n";
	 		aaa=max(aaa,ans+dp[now][j][k]);	if(n==7) cout<<dp[now][j][k]<<" ";
	 	}
	}if(n==7) cout<<"\n";

	cout<<aaa;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <string>
// DON'T DIVIDE
// Try different approaches
using namespace std;

int n, a, b;
const int MAXN = 200005;
long long power[MAXN], hp[MAXN], dmg[MAXN];
pair<long long, long long> diff[MAXN];

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> a >> b;

	power[0] = 1;
	for(int i = 1; i < 22; i++)
		power[i] = power[i - 1] * 2;

	for(int i = 0; i < n; i++)
	{
		cin >> hp[i] >> dmg[i];
		diff[i] = make_pair(hp[i] - dmg[i], i);
	}

	long long big = 0, idx = -1;
	for(int i = 0; i < n; i++)
		if(power[a] * hp[i] - dmg[i] > big)
		{
			big = power[a] * hp[i] - dmg[i];
			idx = i;
		}

	if(idx != -1)
	{
		diff[idx] = make_pair(big, idx);
		hp[idx] = big + dmg[idx];
	}

	sort(diff, diff + n);

	for(int i = n - 1; i >= 0; i--)
		if(b > 0)
		{
			if(dmg[diff[i].second] < hp[diff[i].second])
				dmg[diff[i].second] = hp[diff[i].second];
			b--;
		}

	long long ans = 0;
	for(int i = 0; i < n; i++)
		ans += dmg[i];

	cout << ans << "\n";

	return 0;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <string>
// DON'T DIVIDE
// Try different approaches
using namespace std;

long long n, a, b;
const int MAXN = 200005;
long long power[MAXN], hp[MAXN], dmg[MAXN];
pair<long long, long long> diff[MAXN];

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> a >> b;

	power[0] = 1;
	for(int i = 1; i < 23; i++)
		power[i] = power[i - 1] * 2;

	for(int i = 0; i < n; i++)
	{
		cin >> hp[i] >> dmg[i];
		diff[i] = make_pair(hp[i] - dmg[i], i);
	}

	long long big = 0, idx = -1;
	for(int i = 0; i < n; i++)
		if(power[a] * hp[i] - dmg[i] >= big)
		{
			big = power[a] * hp[i] - dmg[i];
			idx = i;
		}

	if(idx != -1)
	{
		diff[idx] = make_pair(big, idx);
		hp[idx] = max(big + dmg[idx], hp[idx]);
	}

	sort(diff, diff + n);

	for(int i = n - 1; i >= 0; i--)
		if(b > 0)
		{
			if(dmg[diff[i].second] < hp[diff[i].second])
				dmg[diff[i].second] = hp[diff[i].second];
			b--;
		}

	long long ans = 0;
	for(int i = 0; i < n; i++)
		ans += dmg[i];

	cout << ans << "\n";

	return 0;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <string>
// DON'T DIVIDE
// Try different approaches
using namespace std;

long long n, a, b;
const int MAXN = 200005;
long long power[MAXN], hp[MAXN], dmg[MAXN];
pair<long long, long long> diff[MAXN];

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> a >> b;

	power[0] = 1;
	for(int i = 1; i < 22; i++)
		power[i] = power[i - 1] * 2;

	for(int i = 0; i < n; i++)
	{
		cin >> hp[i] >> dmg[i];
		diff[i] = make_pair(hp[i] - dmg[i], i);
	}

	long long big = 0, idx = -1;
	for(int i = 0; i < n; i++)
		if(power[a] * hp[i] - dmg[i] > big)
		{
			big = power[a] * hp[i] - dmg[i];
			idx = i;
		}

	if(idx != -1)
	{
		diff[idx] = make_pair(big, idx);
		hp[idx] = max(big + dmg[idx], hp[idx]);
	}

	sort(diff, diff + n);

	for(int i = n - 1; i >= 0; i--)
		if(b > 0)
		{
			if(dmg[diff[i].second] < hp[diff[i].second])
				dmg[diff[i].second] = hp[diff[i].second];
			b--;
		}

	long long ans = 0;
	for(int i = 0; i < n; i++)
		ans += dmg[i];

	cout << ans << "\n";

	return 0;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <string>
// DON'T DIVIDE
// Try different approaches
using namespace std;

long long n, a, b;
const int MAXN = 200005;
long long power[MAXN], hp[MAXN], dmg[MAXN];
pair<long long, long long> diff[MAXN];

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> a >> b;

	power[0] = 1;
	for(int i = 1; i < 23; i++)
		power[i] = power[i - 1] * 2;

	for(int i = 0; i < n; i++)
	{
		cin >> hp[i] >> dmg[i];
		diff[i] = make_pair(hp[i] - dmg[i], i);
	}

	sort(diff, diff + n);
	reverse(diff, diff + n);

	long long temp = 0, sum = 0, last = 0;
	for(int i = 0; i < n; i++)
	{
		if(i < b && diff[i].first > 0)
		{
			sum += diff[i].first;
			last = diff[i].first;
			temp++;
		}
		sum += dmg[diff[i].second];
	}

	long long ans = sum;

	if(temp < b)
		last = 0;
	if(b > 0)
	{
		for(int i = 0; i < n; i++)
		{
			if(i < b && diff[i].first > 0)
				ans = max(ans, sum - hp[diff[i].second] + hp[diff[i].second] * power[a]);
			else
				ans = max(ans, sum - dmg[diff[i].second] - last + hp[diff[i].second] * power[a]);
		}
	}

	cout << ans << "\n";
	return 0;
}


#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-8;
const int MAX=2e5+10;
const ll mod=1e9;
struct node
{
	ll h,d;
	friend bool operator <(node a,node b)
	{
		return a.h-a.d<b.h-b.d;
	}
	void input()
	{
		scanf("%lld%lld",&h,&d);
	}
}a[MAX];
int n,x;
ll gao1(int y)
{
	ll maxx=-1,p,i,res=0;
	node t;
	priority_queue<node> q;
	for(i=0;i<n;i++)
	{
		if(a[i].h>maxx)
		{
			maxx=a[i].h;
			p=i;
		}
	}
	for(i=0;i<n;i++)
	{
		if(p!=i) q.push(a[i]);
	}
	if(y)
	{
		y--;
		res+=a[p].h*(1LL<<x);
	}
	while(!q.empty())
	{
		t=q.top();
		q.pop();
		if(t.h>t.d&&y)
		{
			y--;
			res+=t.h;
		}
		else res+=t.d;
	}
	return res;
}
ll gao2(int y)
{
	ll i,res=0,maxx=-1;
	node t;
	priority_queue<node> q;
	for(i=0;i<n;i++)
	{
		q.push(a[i]);
	}
	while(!q.empty())
	{
		t=q.top();
		q.pop();
		if(t.h>t.d&&y)
		{
			maxx=max(maxx,t.h);
			y--;
			res+=t.h;
		}
		else res+=t.d;
	}
	return res+maxx*((1LL<<x)-1);
}
int main()
{
	int i,y;
	while(~scanf("%d%d%d",&n,&x,&y))
	{
		for(i=0;i<n;i++) a[i].input();
		printf("%lld\n",max(gao1(y),gao2(y)));
	}
	return 0;
}


#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-8;
const int MAX=2e5+10;
const ll mod=1e9;
struct node
{
	ll h,d;
	friend bool operator <(node a,node b)
	{
		return a.h-a.d<b.h-b.d;
	}
	void input()
	{
		scanf("%lld%lld",&h,&d);
	}
}a[MAX];
int n,x,y;
ll gao1()
{
	ll maxx=-1,p,i,res=0;
	node t;
	priority_queue<node> q;
	for(i=0;i<n;i++)
	{
		if(a[i].h>maxx)
		{
			maxx=a[i].h;
			p=i;
		}
	}
	for(int i=0;i<n;i++)
	{
		if(p!=i) q.push(a[i]);
	}
	if(y)
	{
		y--;
		res+=a[p].h*(1LL<<x);
	}
	while(!q.empty())
	{
		t=q.top();
		q.pop();
		if(t.h>t.d&&y)
		{
			y--;
			res+=t.h;
		}
		else res+=t.d;
	}
	return res;
}
ll gao2()
{
	ll i,res=0,maxx=-1;
	node t;
	priority_queue<node> q;
	for(i=0;i<n;i++)
	{
		q.push(a[i]);
	}
	while(!q.empty())
	{
		t=q.top();
		q.pop();
		if(t.h>t.d&&y)
		{
			maxx=max(maxx,t.h);
			y--;
			res+=t.h;
		}
		else res+=t.d;
	}
	return res+maxx*((1LL<<x)-1);
}
int main()
{
	int i;
	while(~scanf("%d%d%d",&n,&x,&y))
	{
		for(i=0;i<n;i++) a[i].input();
		printf("%lld\n",max(gao1(),gao2()));
	}
	return 0;
}


#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-8;
const int MAX=2e5+10;
const ll mod=1e9;
struct node
{
	ll h,d;
	friend bool operator <(node a,node b)
	{
		return a.h-a.d<b.h-b.d;
	}
	void input()
	{
		scanf("%lld%lld",&h,&d);
	}
}a[MAX];
int n,x;
ll gao1(int y)
{
	ll maxx=0,p,i,res=0;
	node t;
	priority_queue<node> q;
	for(i=0;i<n;i++)
	{
		if(a[i].h>maxx)
		{
			maxx=a[i].h;
			p=i;
		}
	}
	for(i=0;i<n;i++)
	{
		if(p!=i) q.push(a[i]);
	}
	if(y)
	{
		y--;
		res+=a[p].h*(1LL<<x);
	}
	while(!q.empty())
	{
		t=q.top();
		q.pop();
		if(t.h>t.d&&y)
		{
			y--;
			res+=t.h;
		}
		else res+=t.d;
	}
	return res;
}
ll gao2(int y)
{
	ll i,res=0,maxx=0;
	node t;
	priority_queue<node> q;
	for(i=0;i<n;i++)
	{
		q.push(a[i]);
	}
	while(!q.empty())
	{
		t=q.top();
		q.pop();
		if(t.h>t.d&&y)
		{
			maxx=max(maxx,t.h);
			y--;
			res+=t.h;
		}
		else res+=t.d;
	}
	return res+maxx*((1LL<<x)-1);
}
int main()
{
	int i,y;
	while(~scanf("%d%d%d",&n,&x,&y))
	{
		for(i=0;i<n;i++) a[i].input();
		printf("%lld\n",max(gao1(y),gao2(y)));
	}
	return 0;
}


#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-8;
const int MAX=2e5+10;
const ll mod=1e9;
struct node
{
	ll h,d;
	friend bool operator <(node a,node b)
	{
		return a.h-a.d<b.h-b.d;
	}
	void input()
	{
		scanf("%lld%lld",&h,&d);
	}
}a[MAX];
int main()
{
	int i,n,x,y;
	ll ans,now,tmp;
	while(~scanf("%d%d%d",&n,&x,&y))
	{
		for(i=0;i<n;i++) a[i].input();
		sort(a,a+n);
		ans=0;
		for(i=0;i<n;i++) ans+=a[i].d;
		if(y==0) goto end;
		y--;
		tmp=0;
		for(i=0;i<n;i++)
		{
			if(i<y&&a[i].h>a[i].d) ans+=a[i].h-a[i].d;
			if(i==y&&a[i].h>a[i].d) tmp=a[i].h-a[i].d;
		}
		now=ans;
		for(i=0;i<n;i++)
		{
			if(i<y&&a[i].h>a[i].d) ans=max(ans,now+((1LL<<x)-1)*a[i].h);
			else ans=max(ans,now+(1LL<<x)*a[i].h-a[i].d+tmp*(i!=y));
		}
		end:;
		printf("%lld\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-8;
const int MAX=2e5+10;
const ll mod=1e9;
struct node
{
	ll h,d;
	friend bool operator <(node a,node b)
	{
		return a.h-a.d<b.h-b.d;
	}
	void input()
	{
		scanf("%lld%lld",&h,&d);
	}
}a[MAX];
int main()
{
	int i,n,x,y;
	ll ans,now,tmp;
	while(~scanf("%d%d%d",&n,&x,&y))
	{
		for(i=0;i<n;i++) a[i].input();
		sort(a,a+n);
		ans=0;
		for(i=0;i<n;i++) ans+=a[i].d;
		if(y==0) goto end;
		y--;
		tmp=0;
		for(i=0;i<n;i++)
		{
			if(i<y&&a[i].h>a[i].d) ans+=a[i].h-a[i].d;
			if(i==y&&a[i].h>a[i].d) tmp=a[i].h-a[i].d;
		}
		now=ans;
		for(i=0;i<n;i++)
		{
			if(i<y&&a[i].h>a[i].d) ans=max(ans,now+((1LL<<x)-1)*a[i].h+tmp);
			else ans=max(ans,now+(1LL<<x)*a[i].h-a[i].d);
		}
		end:;
		printf("%lld\n",ans);
	}
	return 0;
}