import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
int[] arr = new int[x];
sc.nextLine();
long sum =0l;
int count =0;
for(int i =0; i<x ;i++){
    int num =sc.nextInt();
    arr[i]=num;

    }
    for(int i =0;i<arr.length;i++){
    if(arr[i]%2==0){
        sum+=arr[i];
    }else{
        count++;
    }
    }
    if(count%2==0){
    for(int i =0;i<arr.length;i++){
        if(arr[i]%2!=0){
            sum+=arr[i];

        }
    }
    }else{
    int minSoFar =1000000001;
    for (int i =0; i<arr.length;i++){
        if (arr[i]<minSoFar && arr[i]%2!=0){
            minSoFar=arr[i];

        }
    }
    for(int i =0 ;i< arr.length ; i++){
        if(arr[i]%2!=0 ){
            sum+=arr[i];
        }
    }sum-=minSoFar;
    }
        System.out.println(sum);
    }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x=sc.nextInt();
int[] arr = new int[x];
sc.nextLine();
long sum =0l;
long count =0l;
for(int i =0; i<x ;i++){
    int num =sc.nextInt();
    arr[i]=num;

    }
    for(int i =0;i<arr.length;i++){
    if(arr[i]%2==0){
        sum+=arr[i];
    }else{
        count++;
    }
    }
    if(count%2==0){
    for(int i =0;i<arr.length;i++){
        if(arr[i]%2!=0){
            sum+=arr[i];

        }
    }
    }else{
    int minSoFar =1000000000;
    for (int i =0; i<arr.length;i++){
        if (arr[i]<minSoFar){
            minSoFar=arr[i];

        }
    }
    for(int i =0 ;i< arr.length ; i++){
        if(arr[i]%2!=0 ){
            sum+=arr[i];
        }
    }sum-=minSoFar;
    }
        System.out.println(sum);
    }
}


import java.util.*;
public class first{
    public static void main(String args []){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long x[] = new long[n];
        long mi = 10000000011L;
        for (int i = 0 ; i<n ; i++){
            x[i] = sc.nextLong();
            if (x[i]%2 == 1){
                if (x[i]<mi){
                    mi = x[i];
                }
            }
        }
        Arrays.sort(x);
        long se = 0L , so = 0L  ;
        for (int k = x.length-1 ; k>=0;k--){
            if (x[k]%2 == 0)
                se+=x[k];
            else
                so+=x[k];
        }
        if ((se+so)%2 == 1){
            System.out.println(se+so-mi);
        }else
            System.out.println(se+so);
    }
}


import java.util.Scanner ;
public class firstproblem {
    public static void main(String args[]) {
        Scanner xx = new Scanner(System.in);
        int n = xx.nextInt();
        int[] b = new int[n];
        for (int c = 0; c < n; c++) {
            b[c] = xx.nextInt();

        }
        int i ;
        long s , r , m ;
        int c = 0 ;
        s = 0 ;
        r = 0 ;
        m = 0 ;
        i = 0 ;
        while (i < n - 2){
            while (c < n) {
                s += b[c] ;
                if (s%2==0) {
                    r = s ;
                    if (r > m ) {
                        m = r ;
                    }
                }
            ++c ;
            }
        ++i ;
        c = i;
        s = 0 ;
        }
        System.out.println(m) ;

    }
}


import java.util.*;
public class first{
    public static void main(String args []){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long x[] = new long[n];
        long mi = 10000000011L;
        long se = 0L , so = 0L  ;
        for (int i = 0 ; i<n ; i++){
            x[i] = sc.nextLong();
            if (x[i]%2 == 1){
                if (x[i]<mi){
                    mi = x[i];
                }
                if (x[i]%2 == 0)
                    se+=x[i];
                else
                    so+=x[i];
            }
        }
        if ((se+so)%2 == 1){
            System.out.println(se+so-mi);
        }else
            System.out.println(se+so);
    }
}


import java.util.*;
public class first{
    public static void main(String args []){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long x[] = new long[n];
        long mi = 10000000011L;
        long se = 0L , so = 0L  ;
        for (int i = 0 ; i<n ; i++){
            x[i] = sc.nextLong();
            if (x[i]%2 == 1) {
                if (x[i] < mi) {
                    mi = x[i];
                }
            }
            if (x[i]%2 == 0)
                se+=x[i];
            else
                so+=x[i];

        }
        if ((se+so)%2 == 1){
            System.out.println(se+so-mi);
        }else
            System.out.println(se+so);
    }
}


import Samara2013.M;

import java.util.Scanner ;
public class firstproblem {
    public static void main(String args[]) {
        Scanner xx = new Scanner(System.in);
        int n = xx.nextInt();
        int[] b = new int[n];
        for (int c = 0; c < n; c++) {
            b[c] = xx.nextInt();

        }
        int i ;
        long s , r , m ;
        int c = 0 ;
        s = 0 ;
        r = 0 ;
        m = 0 ;
        i = 0 ;
        while (i < n - 2){
            while (c < n) {
                s += b[c] ;
                if (s%2==0) {
                    r = s ;
                    if (r > m ) {
                        m = r ;
                    }
                }
            ++c ;
            }
        ++i ;
        c = i;
        s = 0 ;
        }
        System.out.println(m) ;

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class CF341A {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long []a=new long[n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextLong();
		Arrays.sort(a);
		long j=0,sum=0,last=0;
		for(int i=n-1;i>=0;i--){
			if(a[i]%2==0)
				sum+=a[i];
			else{
				sum+=a[i];
				j++;
				last=a[i];
			}
		}
		if(j%2==1)
			sum-=last;
		System.out.println(sum);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class CF341A {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n=sc.nextInt();
		String s=reader.readLine();
		long []a=new long[n];
		int k=0,num=0;
		char []ch=s.toCharArray();
		while(k<s.length()){
			if(ch[k]==' ')
				num++;
			else
				a[num]=a[num]*10+ch[k]-'0';
			k++;
		}
		Arrays.sort(a);
		long j=0,sum=0,last=0;
		for(int i=n-1;i>=0;i--){
			if(a[i]%2==0)
				sum+=a[i];
			else{
				sum+=a[i];
				j++;
				last=a[i];
			}
		}
		if(j%2==1)
			sum-=last;
		System.out.println(sum);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class CF341A {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String s1=reader.readLine();
		int n=0;
		char []ch1=s1.toCharArray();
		int l=0;
		while(l<s1.length()){
			n=n*10+ch1[l++]-'0';
		}
		String s=reader.readLine();
		long []a=new long[n];
		int k=0,num=0;
		char []ch=s.toCharArray();
		while(k<s.length()){
			if(ch[k]==' ')
				num++;
			else
				a[num]=a[num]*10+ch[k]-'0';
			k++;
		}
		Arrays.sort(a);
		long j=0,sum=0,last=0;
		for(int i=n-1;i>=0;i--){
			if(a[i]%2==0)
				sum+=a[i];
			else{
				sum+=a[i];
				j++;
				last=a[i];
			}
		}
		if(j%2==1)
			sum-=last;
		System.out.println(sum);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class CF341A {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String s1=reader.readLine();
		int n=0;
		char []ch1=s1.toCharArray();
		int l=0;
		while(l<s1.length()){
			n=n*10+ch1[l++]-'0';
		}
		String s=reader.readLine();
		long []a=new long[n];
		int k=0,num=0;
		char []ch=s.toCharArray();
		while(k<s.length()){
			if(ch[k]==' ')
				num++;
			else
				a[num]=a[num]*10+ch[k]-'0';
			k++;
		}
		long j=0,sum=0,last=1000000005;
		for(int i=n-1;i>=0;i--){
			if(a[i]%2==0)
				sum+=a[i];
			else{
				sum+=a[i];
				j++;
				if(a[i]<last)
					last=a[i];
			}
		}
		if(j%2==1)
			sum-=last;
		System.out.println(sum);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class CF341A {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String s1=reader.readLine();
		int n=0;
		char []ch1=s1.toCharArray();
		int l=0;
		while(l<s1.length()){
			n=n*10+ch1[l++]-'0';
		}
		String s=reader.readLine();
		long []a=new long[n];
		int k=0,num=0;
		char []ch=s.toCharArray();
		while(k<s.length()){
			if(ch[k]==' ')
				num++;
			else
				a[num]=a[num]*10+ch[k]-'0';
			k++;
		}
		long j=0,sum=0,last=99999999;
		for(int i=n-1;i>=0;i--){
			if(a[i]%2==0)
				sum+=a[i];
			else{
				sum+=a[i];
				j++;
				if(a[i]<last)
					last=a[i];
			}
		}
		if(j%2==1)
			sum-=last;
		System.out.println(sum);
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class cf341A {
	public static void main(String[] args) {
		int n;
		n = in.nextInt();
		int[] ar = new int[n];
		for (int i = 0; i < n; i++)
			ar[i] = in.nextInt();
		Arrays.sort(ar);
		long ans = 0;
		for (int i = n - 1; i >= 0; i--) {
			ans += ar[i];
		}
		if (ans % 2 != 0) {
			int minOdd = 0;
			for (int i = 0; i < n; i++) {
				int x = ar[i];
				if (x % 2 != 0) {
					minOdd = x;
					break;
				}
			}
			ans -= minOdd;
		}
		if(ans % 2 != 0) ans = 0;
		out.println(ans);
		out.close();
	}

	// --------------- ------fast input/ouput---------------------------///

	public static Object returnFirst(Object x, Object y) {
		return x;
	}

	public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	public static FastScanner in = new FastScanner();

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	// -----------------------------fast i/o ends
	// here-------------------------//
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class cf341A {
	public static void main(String[] args) {
		int n;
		long ans = 0;
		n = in.nextInt();
		int[] ar = new int[n];
		for (int i = 0; i < n; i++) {
			ar[i] = in.nextInt();
			ans += ar[i];
		}
		Arrays.sort(ar);

		if (ans % 2 != 0) {
			int minOdd = 0;
			for (int i = 0; i < n; i++) {
				int x = ar[i];
				if (x % 2 != 0) {
					minOdd = x;
					break;
				}
			}
			ans -= minOdd;
		}
		if(ans % 2 != 0) ans = 0;
		out.println(ans);
		out.close();
	}

	// --------------- ------fast input/ouput---------------------------///

	public static Object returnFirst(Object x, Object y) {
		return x;
	}

	public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	public static FastScanner in = new FastScanner();

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	// -----------------------------fast i/o ends
	// here-------------------------//
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class cf341A {
	public static void main(String[] args) {
		int n;
		long ans = 0;
		n = in.nextInt();
		int minOdd = 0;
		int[] ar = new int[n];
		for (int i = 0; i < n; i++) {
			ar[i] = in.nextInt();
			ans += ar[i];
			if(ar[i]%2 == 1) {
				minOdd = Math.min(minOdd, ar[i]);
			}
		}
		if (ans % 2 != 0) {
			ans -= minOdd;
		}
		if(ans % 2 != 0) ans = 0;
		out.println(ans);
		out.close();
	}

	// --------------- ------fast input/ouput---------------------------///

	public static Object returnFirst(Object x, Object y) {
		return x;
	}

	public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	public static FastScanner in = new FastScanner();

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	// -----------------------------fast i/o ends
	// here-------------------------//
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class cf341A {
	public static void main(String[] args) {
		int n;
		n = in.nextInt();
		int[] ar = new int[n];
		for (int i = 0; i < n; i++)
			ar[i] = in.nextInt();
		Arrays.sort(ar);
		long ans = 0;
		for (int i = n - 1; i >= 0; i--) {
			ans += ar[i];
		}
		if (ans % 2 != 0) {
			int minOdd = 0;
			for (int x : ar) {
				if (x % 2 != 0) {
					minOdd = x;
					break;
				}
			}
			ans -= minOdd;
		}
		if(ans % 2 != 0) ans = 0;
		out.println(ans);
		out.close();
	}

	// --------------- ------fast input/ouput---------------------------///

	public static Object returnFirst(Object x, Object y) {
		return x;
	}

	public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	public static FastScanner in = new FastScanner();

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	// -----------------------------fast i/o ends
	// here-------------------------//
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class cf341A {
	public static void main(String[] args) {
		int n;
		long ans = 0;
		n = in.nextInt();
		int minOdd = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			ans += x;
			if(x%2 == 1) {
				minOdd = Math.min(minOdd, x);
			}
		}
		if (ans % 2 != 0 && minOdd != Integer.MAX_VALUE) {
			ans -= minOdd;
		} else ans = 0;
		out.println(ans);
		out.close();
	}

	// --------------- ------fast input/ouput---------------------------///

	public static Object returnFirst(Object x, Object y) {
		return x;
	}

	public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	public static FastScanner in = new FastScanner();

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	// -----------------------------fast i/o ends
	// here-------------------------//
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class cf341A {
	public static void main(String[] args) {
		int n;
		long ans = 0;
		n = in.nextInt();
		int minOdd = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			ans += x;
			if(x%2 == 1) {
				minOdd = Math.min(minOdd, x);
			}
		}
		if (ans % 2 != 0) {
			ans -= minOdd;
		}
		out.println(ans);
		out.close();
	}

	// --------------- ------fast input/ouput---------------------------///

	public static Object returnFirst(Object x, Object y) {
		return x;
	}

	public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	public static FastScanner in = new FastScanner();

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	// -----------------------------fast i/o ends
	// here-------------------------//
}


import java.util.*;

public class Main
{
	public static long[] arregloimpares(long [] arr1)
	{
		int j=0;
		long []arrnew=new long[cuentaimpares(arr1)];
		for(int i=0; i<arr1.length;i++)
		{
			if(arr1[i]%2!=0)
			{
				arrnew[j]=arr1[i];
				j++;
			}
		}
		return arrnew;
	}
	public static long small(long[] arr1)
	{
		long smallest=arr1[0];

		for(int i=0;i<arr1.length;i++)
		{
			if(arr1[i]<smallest)
			{
				smallest=arr1[i];
			}
		}
		return smallest;
	}
	public static int cuentaimpares(long[] arr)
	{
		int impares=0;
		for(int i=0;i<arr.length;i++)
		{
			if(arr[i]%2!=0)
			{
				impares++;
			}
		}
		return impares;
	}

	public static void main(String[]args)
	{
		Scanner read= new Scanner(System.in);
		int n=read.nextInt();
		long sum=0L;

		long []arreglo= new long[n];

		for(int i=0;i<n;i++)
		{
			arreglo[i]=read.nextLong();
			sum=sum+arreglo[i];
		}

		long smallodd=small(arregloimpares(arreglo));

		if ((n-cuentaimpares(arreglo)%2==0)&&(cuentaimpares(arreglo)%2==0))
		{
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2!=0)&&(cuentaimpares(arreglo)%2==0))
		{
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2!=0)&&(cuentaimpares(arreglo)%2!=0))
		{
			sum=sum-smallodd;
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2==0)&&(cuentaimpares(arreglo)%2!=0))
		{
			sum=sum-smallodd;
			System.out.println(sum);
		}

	}

}


import java.util.*;

public class Main
{
	public static long[] arregloimpares(long [] arr1)
	{
		int j=0;
		long []arrnew=new long[cuentaimpares(arr1)];
		for(int i=0; i<arr1.length;i++)
		{
			if(arr1[i]%2!=0)
			{
				arrnew[j]=arr1[i];
				j++;
			}
		}
		return arrnew;
	}
	public static long small(long[] arr1)
	{
		long smallest=arr1[0];

		for(int i=0;i<arr1.length;i++)
		{
			if(arr1[i]<smallest)
			{
				smallest=arr1[i];
			}
		}
		return smallest;
	}
	public static int cuentaimpares(long[] arr)
	{
		int impares=0;
		for(int i=0;i<arr.length;i++)
		{
			if(arr[i]%2!=0)
			{
				impares++;
			}
		}
		return impares;
	}

	public static void main(String[]args)
	{
		Scanner read= new Scanner(System.in);
		int n=read.nextInt();
		long sum=0L;

		long []arreglo= new long[n];

		for(int i=0;i<n;i++)
		{
			arreglo[i]=read.nextLong();
			sum=sum+arreglo[i];
		}

		if(arreglo.length==1)
		{
			if(arreglo[0]%2==0)
			{
				System.out.println(arreglo[0]);
			}
			else
			{
				System.out.println("0");
			}
		}
		else
		{

		if ((n-cuentaimpares(arreglo)%2==0)&&(cuentaimpares(arreglo)%2==0))
		{
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2!=0)&&(cuentaimpares(arreglo)%2==0))
		{
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2!=0)&&(cuentaimpares(arreglo)%2!=0))
		{
			//long smallodd=small(arregloimpares(arreglo));
			sum=sum-small(arregloimpares(arreglo));
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2==0)&&(cuentaimpares(arreglo)%2!=0))
		{
			sum=sum-small(arregloimpares(arreglo));
			System.out.println(sum);
		}
		}

	}

}


import java.util.*;

public class Main
{
	public static long[] arregloimpares(long [] arr1)
	{
		int j=0;
		long []arrnew=new long[cuentaimpares(arr1)];
		for(int i=0; i<arr1.length;i++)
		{
			if(arr1[i]%2!=0)
			{
				arrnew[j]=arr1[i];
				j++;
			}
		}
		return arrnew;
	}
	public static long small(long[] arr1)
	{
		long smallest=arr1[0];

		for(int i=0;i<arr1.length;i++)
		{
			if(arr1[i]<smallest)
			{
				smallest=arr1[i];
			}
		}
		return smallest;
	}
	public static int cuentaimpares(long[] arr)
	{
		int impares=0;
		for(int i=0;i<arr.length;i++)
		{
			if(arr[i]%2!=0)
			{
				impares++;
			}
		}
		return impares;
	}

	public static void main(String[]args)
	{
		Scanner read= new Scanner(System.in);
		int n=read.nextInt();
		long sum=0L;

		long []arreglo= new long[n];

		for(int i=0;i<n;i++)
		{
			arreglo[i]=read.nextLong();
			sum=sum+arreglo[i];
		}

		if(arreglo.length==1)
		{
			if(arreglo[0]%2==0)
			{
				System.out.println(arreglo[0]);
			}
			else
			{
				System.out.println("0");
			}
		}
		else
		{
		long smallodd=small(arregloimpares(arreglo));

		if ((n-cuentaimpares(arreglo)%2==0)&&(cuentaimpares(arreglo)%2==0))
		{
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2!=0)&&(cuentaimpares(arreglo)%2==0))
		{
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2!=0)&&(cuentaimpares(arreglo)%2!=0))
		{
			sum=sum-smallodd;
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2==0)&&(cuentaimpares(arreglo)%2!=0))
		{
			sum=sum-smallodd;
			System.out.println(sum);
		}
		}

	}

}


import java.util.*;

public class Main
{
	public static long small(long[] arr1)
	{
		long smallest=arr1[0];
		for(int i=0;i<arr1.length;i++)
		{
			if(arr1[i]%2!=0)
			{
				if(arr1[i]<smallest)
				{
					smallest=arr1[i];
				}
			}
		}
		return smallest;

	}
	public static long cuentaimpares(long[] arr)
	{
		long impares=0L;
		for(int i=0;i<arr.length;i++)
		{
			if(arr[i]%2!=0)
			{
				impares++;
			}
		}
		return impares;
	}

	public static void main(String[]args)
	{
		Scanner read= new Scanner(System.in);
		int n=read.nextInt();
		long sum=0L;

		long []arreglo= new long[n];

		for(int i=0;i<n;i++)
		{
			arreglo[i]=read.nextLong();
			sum=sum+arreglo[i];
		}

		long smallodd=small(arreglo);

		if ((n-cuentaimpares(arreglo)%2==0)&&(cuentaimpares(arreglo)%2==0))
		{
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2!=0)&&(cuentaimpares(arreglo)%2==0))
		{
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2!=0)&&(cuentaimpares(arreglo)%2!=0))
		{
			sum=sum-smallodd;
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2==0)&&(cuentaimpares(arreglo)%2!=0))
		{
			sum=sum-smallodd;
			System.out.println(sum);
		}

	}

}


import java.util.*;

public class Main
{
	public static long[] arregloimpares(long [] arr1)
	{
		int j=0;
		long []arrnew=new long[cuentaimpares(arr1)];
		for(int i=0; i<arr1.length;i++)
		{
			if(arr1[i]%2!=0)
			{
				arrnew[j]=arr1[i];
				j++;
			}
		}
		return arrnew;
	}
	public static long small(long[] arr1)
	{
		long smallest=arr1[0];

		for(int i=0;i<arr1.length;i++)
		{
			if(arr1[i]<smallest)
			{
				smallest=arr1[i];
			}
		}
		return smallest;
	}
	public static int cuentaimpares(long[] arr)
	{
		int impares=0;
		for(int i=0;i<arr.length;i++)
		{
			if(arr[i]%2!=0)
			{
				impares++;
			}
		}
		return impares;
	}

	public static void main(String[]args)
	{
		Scanner read= new Scanner(System.in);
		int n=read.nextInt();
		long sum=0L;

		if(n==1)
		{
			System.out.println("0");
		}
		else
		{
			long []arreglo= new long[n];

		for(int i=0;i<n;i++)
		{
			arreglo[i]=read.nextLong();
			sum=sum+arreglo[i];
		}

		long smallodd=small(arregloimpares(arreglo));

		if ((n-cuentaimpares(arreglo)%2==0)&&(cuentaimpares(arreglo)%2==0))
		{
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2!=0)&&(cuentaimpares(arreglo)%2==0))
		{
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2!=0)&&(cuentaimpares(arreglo)%2!=0))
		{
			sum=sum-smallodd;
			System.out.println(sum);
		}
		if((n-cuentaimpares(arreglo)%2==0)&&(cuentaimpares(arreglo)%2!=0))
		{
			sum=sum-smallodd;
			System.out.println(sum);
		}

		}

	}

}


import java.util.* ;

public class WetSharkAndOddAndEven {
	public static void main (String args [] ) {
		Scanner sc = new Scanner (System.in) ;
		int n = sc.nextInt();
		int ws [] = new int [n] ;
		for ( int i = 0 ; i < n ; i++) {
			ws[i] = sc.nextInt();
		}
		long c = 0L ;

		for ( int i = 0 ; i < n ; i ++ ) {
			long sum = ws[i] ;

			for (int j = i+1 ;  j < n ; j ++) {
				sum += ws[j] ;
				long zz = ws[i] + ws[j] ;
				if ((c<sum && sum%2==0))
					c = sum ;
				if (c<zz && zz%2==0 && zz>sum)
					c = zz ;
			}
			if (c<ws[i] && ws[i]%2==0)
				c = ws[i] ;
		}

		System.out.println(c);
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class WetShark {

	public static void main(String[] args) throws IOException , InterruptedException{

		Scanner sc = new Scanner (System.in) ;
		PrintWriter pw = new PrintWriter(System.out) ;
		int n = sc.nextInt() ;
		int a [] = new int [n] ;
		int odd = 0  ;
		long lo = 0L ;
		for (int i = 0 ; i < n ; i ++ ) {
			a[i] = sc.nextInt() ;
			if (a[i]%2==0 )
				lo += a[i] ;
			else
				odd ++ ;
		}

		int b [] = new int [odd] ;
		odd-- ;
		for (int i = 0; i < n ; i ++ ) {
			if (a[i]%2==1) {
				b[odd] = a[i] ;
				odd--;
			}
		}
		Arrays.sort(b);
		for(int i = b.length-1 ; i >= 0 ; i-- ) {
			lo+= b[i] ;
		}
		if (lo%2 != 0 )
			lo-= b[0] ;
		pw.println(lo);
		pw.close();

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


import java.util.* ;

public class WetSharkAndOddAndEven {
	public static void main (String args [] ) {
		Scanner sc = new Scanner (System.in) ;
		int n = sc.nextInt();
		int ws [] = new int [n] ;
		for ( int i = 0 ; i < n ; i++) {
			ws[i] = sc.nextInt();
		}
		long c = 0L ;

		for ( int i = 0 ; i < n ; i ++ ) {
			long sum = ws[i] ;

			for (int j = i+1 ;  j < n ; j ++) {
				sum += ws[j] ;
				long zz = ws[i] + ws[j] ;
				if ((c<sum && sum%2==0))
					c = sum ;
				if (c<zz && zz%2==0 && zz>sum)
					c = zz ;
			}
		}
		for (int i= 0 ; i < n ; i++ ) {
			if (c<ws[i] && ws[i]%2==0)
				c = ws[i] ;
		}
		System.out.println(c);
	}
}


import java.util.* ;

public class WetSharkAndOddAndEven {
	public static void main (String args [] ) {
		Scanner sc = new Scanner (System.in) ;
		int n = sc.nextInt();
		int ws [] = new int [n] ;
		for ( int i = 0 ; i < n ; i++) {
			ws[i] = sc.nextInt();
		}
		long c = -1L ;

		for ( int i = 0 ; i < n ; i ++ ) {
			long sum = ws[i] ;

			for (int j = i+1 ;  j < n ; j ++) {
				sum += ws[j] ;
				long zz = ws[i] + ws[j] ;
				if ((c<sum && sum%2==0))
					c = sum ;
				if (c<zz && zz%2==0 && zz>sum)
					c = zz ;
			}
		}
		for (int i= 0 ; i < n ; i++ ) {
			if (c<ws[i] && ws[i]%2==0)
				c = ws[i] ;
		}
		System.out.println(c);
	}
}


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

namespace Regular_Bracket_Sequence
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int l = 0, r = 0;
            char next1 = '(';
            char next2 = ')';
            int num = 0;
            bool rightLift = false;
            for (int i = 0; i < input.Length; i++)
            {
                if(i==0)
                {
                    if(input[i]==next1)
                    {
                        l++;
                    }
                }
                else
                {
                    if (rightLift == false)
                    {
                        if (input[i] == next1)
                        {
                            l++;

                        }
                        else if (input[i] == next2)
                        {
                            if(l ==0)
                            {
                                continue;
                            }
                            r++;
                            rightLift = true;
                            next1 = ')';
                            next2 = '(';
                        }
                    }
                    else
                    {
                        if (input[i] == next1)
                        {
                            r++;

                        }
                        else if (input[i] == next2)
                        {
                            r = 0;
                            l++;
                            rightLift = false;
                            next1 = '(';
                            next2 = ')';
                        }
                    }

                    if(r !=0 && l !=0)
                    {
                        num+=2;
                        r--;
                        l--;
                    }
                }
            }
            Console.WriteLine(num);
        }
    }
}


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

namespace Regular_Bracket_Sequence
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int l = 0, r = 0;
            char next1 = '(';
            char next2 = ')';
            int num = 0;
            bool rightLift = false;
            for (int i = 0; i < input.Length; i++)
            {
                if(i==0)
                {
                    if(input[i]==next1)
                    {
                        l++;
                    }
                }
                else
                {
                    if (rightLift == false)
                    {
                        if (input[i] == next1)
                        {
                            l++;

                        }
                        else if (input[i] == next2)
                        {
                            r++;
                            rightLift = true;
                            next1 = ')';
                            next2 = '(';
                        }
                    }
                    else
                    {
                        if (input[i] == next1)
                        {
                            l++;

                        }
                        else if (input[i] == next2)
                        {
                            r++;
                            rightLift = false;
                            next1 = '(';
                            next2 = ')';
                        }
                    }
                    if(r !=0 && l !=0)
                    {
                        num+=2;
                        r--;
                        l--;
                    }
                }
            }
            Console.WriteLine(num);
        }
    }
}


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

namespace Regular_Bracket_Sequence
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string s = reader.ReadLine();

            int count = 0;
            var st = new Stack<char>();
            foreach (char c in s)
            {
                if (c == '(')
                    st.Push(c);
                else
                {
                    if (st.Count > 0 && st.Peek() == '(')
                    {
                        st.Pop();
                        count += 2;
                    }
                }
            }

            writer.WriteLine(count);
            writer.Flush();
        }
    }
}


#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

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

namespace _26b
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;

        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
			Console.SetIn(getInput());
#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

            try
            {
                solution();
            }
            finally
            {
                if (_useFileInput)
                {
                    file.Close();
                }
            }
        }

        static void solution()
        {
            #region SOLUTION
            var s = Console.ReadLine();
            var b = 0;
            var rem = 0;
            for (int i = 0; i < s.Length; i++)
            {
                var next = s[i];
                if (next == '(')
                {
                    b++;
                }
                else
                {
                    if (b == 0)
                    {
                        rem++;
                    }
                    else
                    {
                        b--;
                    }
                }
            }

            rem += b;
            Console.WriteLine(s.Length - rem);

            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static int readInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long readLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] readIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] readLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
		static StreamReader getInput()
		{
			var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
			var resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);

			return new StreamReader(resource);
		}
#endif
    }
}


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

class Program{
    static void Main(){
        System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

        string s = readLine();
        int ans = 0;
        Stack<char> st = new Stack<char>();

        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '(') st.Push(s[i]);
            else if (s[i]==')' && st.Count != 0 && st.Peek() == '(') {
                ans += 2;
                st.Pop();
            }
        }

        print(ans);

#if !ONLINE_JUDGE
        fout.Close();
#endif
    }

    struct quat<T1, T2, T3, T4> { public T1 fst; public T2 snd; public T3 thr; public T4 frt; }
    struct trip<T1, T2, T3> { public T1 fst; public T2 snd; public T3 thr; }
    struct pair<T1, T2> { public T1 fst; public T2 snd; }
    static long LCM(long a, long b) { return a / GCD(a, b) * b; }
    static long GCD(long a, long b) { if (b == 0) return a; else return GCD(b, a % b); }
    static void swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; }
    static double dist(double x1, double y1, double x2, double y2) { return Math.Sqrt(Math.Pow(x1-x2, 2)+Math.Pow(y1-y2, 2)); }
    static void fill<T>(T[] d, T v) { for (int i = 0; i < d.Length; i++) d[i] = v; }
    static void fill<T>(T[,] d, T v) { for (int i = 0; i < d.GetLength(0); i++) { for (int j = 0; j < d.GetLength(1); j++) { d[i, j] = v; } } }

    static void print(double v) { Console.Write(v); }
    static void print(long v) { Console.Write(v); }
    static void print(int v) { Console.Write(v); }
    static void print(string v) { Console.Write(v); }
    static void print(char v) { Console.Write(v); }
    //static void print(BigInteger v) { Console.Write(v); }
    static void print(String f, params object[] o) { Console.Write(f, o); }

    static void println(double v) { Console.WriteLine(v); }
    static void println(long v) { Console.WriteLine(v); }
    static void println(int v) { Console.WriteLine(v); }
    static void println(string v) { Console.WriteLine(v); }
    static void println(char v) { Console.WriteLine(v); }
    //static void println(BigInteger v) { Console.WriteLine(v); }
    static void println() { Console.WriteLine(); }
    static void println(String f, params object[] o) { Console.WriteLine(f, o); }

    static string RL() { return Console.ReadLine(); }
    static int[] readValsI(int n) { int[] t = new int[n]; for (int i = 0; i < n; i++) t[i] = readInt(); return t; }
    static double[] readValsD(int n) { double[] t = new double[n]; for (int i = 0; i < n; i++) t[i] = readDouble(); return t; }

    /*static BigInteger readBigInt()
    {
        BigInteger val = 0;
        bool m = false;
        int c;
        while (((c = Console.Read()) < '0' || c > '9') && c != '-') { }
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m=true : m=false) ? 0 : 0;
        while ((c = Console.Read() - 48) >= 0 && c <= 9) val = val*10 + (m?-c:c);
        return val;
    }*/

    static double readDouble() {
        bool m = false;
        double val = 0;
        int c = 0, r = 1;
        while(((c=Console.Read())<'0' || c>'9') && c!='-') {}
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m=true : m=false) ? 0 : 0;
        while ((c = Console.Read()) >= '0' && c <= '9') val = val * 10 + (m?-(c-48):(c-48));
        if(c=='.') while ((c = Console.Read()) >= '0' && c <= '9'){ val += ((double)(c-48))/(r*=10); }

        return val;
    }

    static long readLong()
    {
        long val = 0;
        bool m = false;
        int c;
        while (((c = Console.Read()) < '0' || c > '9') && c != '-') { }
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m=true : m=false) ? 0 : 0;
        while ((c = Console.Read() - 48) >= 0 && c <= 9) val = val*10 + (m?-c:c);
        return val;
    }

    static int readInt()
    {
        bool m = false;
        int val = 0, c;
        while (((c = Console.Read()) < '0' || c > '9') && c != '-') { }
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m=true : m=false) ? 0 : 0;
        while ((c = Console.Read() - 48) >= 0 && c <= 9) val = val*10 + (m?-c:c);
        return val;
    }

    static string readLine() {
        string s = "";
        int c;
        while((c=Console.Read())!=10 && c!=-1) s+=(char)c;
        return s;
    }

    static string readString() {
        string s = "";
        int c;
        while ((c = Console.Read()) != 10 && c != 32 && c != -1) s += (char)c;
        return s;
    }
}


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

class Program{
    static void Main(){
        System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
#if !ONLINE_JUDGE
        StreamWriter fout;
        Console.SetIn(new StreamReader("input.txt"));
        Console.SetOut(fout=new StreamWriter("output.txt"));
#endif
        string s = readLine();
        int ans = 0;
        Stack<char> st = new Stack<char>();

        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '(') st.Push(s[i]);
            else if (s[i]==')' && st.Count != 0 && st.Peek() == '(') {
                ans += 2;
                st.Pop();
            }
        }

        print(ans);

#if !ONLINE_JUDGE
        fout.Close();
#endif
    }

    struct quat<T1, T2, T3, T4> { public T1 fst; public T2 snd; public T3 thr; public T4 frt; }
    struct trip<T1, T2, T3> { public T1 fst; public T2 snd; public T3 thr; }
    struct pair<T1, T2> { public T1 fst; public T2 snd; }
    static long LCM(long a, long b) { return a / GCD(a, b) * b; }
    static long GCD(long a, long b) { if (b == 0) return a; else return GCD(b, a % b); }
    static void swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; }
    static double dist(double x1, double y1, double x2, double y2) { return Math.Sqrt(Math.Pow(x1-x2, 2)+Math.Pow(y1-y2, 2)); }
    static void fill<T>(T[] d, T v) { for (int i = 0; i < d.Length; i++) d[i] = v; }
    static void fill<T>(T[,] d, T v) { for (int i = 0; i < d.GetLength(0); i++) { for (int j = 0; j < d.GetLength(1); j++) { d[i, j] = v; } } }

    static void print(double v) { Console.Write(v); }
    static void print(long v) { Console.Write(v); }
    static void print(int v) { Console.Write(v); }
    static void print(string v) { Console.Write(v); }
    static void print(char v) { Console.Write(v); }
    //static void print(BigInteger v) { Console.Write(v); }
    static void print(String f, params object[] o) { Console.Write(f, o); }

    static void println(double v) { Console.WriteLine(v); }
    static void println(long v) { Console.WriteLine(v); }
    static void println(int v) { Console.WriteLine(v); }
    static void println(string v) { Console.WriteLine(v); }
    static void println(char v) { Console.WriteLine(v); }
    //static void println(BigInteger v) { Console.WriteLine(v); }
    static void println() { Console.WriteLine(); }
    static void println(String f, params object[] o) { Console.WriteLine(f, o); }

    static string RL() { return Console.ReadLine(); }
    static int[] readValsI(int n) { int[] t = new int[n]; for (int i = 0; i < n; i++) t[i] = readInt(); return t; }
    static double[] readValsD(int n) { double[] t = new double[n]; for (int i = 0; i < n; i++) t[i] = readDouble(); return t; }

    /*static BigInteger readBigInt()
    {
        BigInteger val = 0;
        bool m = false;
        int c;
        while (((c = Console.Read()) < '0' || c > '9') && c != '-') { }
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m=true : m=false) ? 0 : 0;
        while ((c = Console.Read() - 48) >= 0 && c <= 9) val = val*10 + (m?-c:c);
        return val;
    }*/

    static double readDouble() {
        bool m = false;
        double val = 0;
        int c = 0, r = 1;
        while(((c=Console.Read())<'0' || c>'9') && c!='-') {}
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m=true : m=false) ? 0 : 0;
        while ((c = Console.Read()) >= '0' && c <= '9') val = val * 10 + (m?-(c-48):(c-48));
        if(c=='.') while ((c = Console.Read()) >= '0' && c <= '9'){ val += ((double)(c-48))/(r*=10); }

        return val;
    }

    static long readLong()
    {
        long val = 0;
        bool m = false;
        int c;
        while (((c = Console.Read()) < '0' || c > '9') && c != '-') { }
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m=true : m=false) ? 0 : 0;
        while ((c = Console.Read() - 48) >= 0 && c <= 9) val = val*10 + (m?-c:c);
        return val;
    }

    static int readInt()
    {
        bool m = false;
        int val = 0, c;
        while (((c = Console.Read()) < '0' || c > '9') && c != '-') { }
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m=true : m=false) ? 0 : 0;
        while ((c = Console.Read() - 48) >= 0 && c <= 9) val = val*10 + (m?-c:c);
        return val;
    }

    static string readLine() {
        string s = "";
        int c;
        while((c=Console.Read())!=10 && c!=-1) s+=(char)c;
        return s;
    }

    static string readString() {
        string s = "";
        int c;
        while ((c = Console.Read()) != 10 && c != 32 && c != -1) s += (char)c;
        return s;
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        string s = ReadToken();
        int ans = 0;
        Stack<char> st = new Stack<char>();

        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '(') st.Push(s[i]);
            else if (s[i] == ')' && st.Count != 0 && st.Peek() == '(')
            {
                ans += 2;
                st.Pop();
            }
        }

        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


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

class Program{
    static void Main(){
        System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

        string s = readLine();
        int ans = 0;
        Stack<char> st = new Stack<char>();

        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '(') st.Push(s[i]);
            else if (s[i]==')' && st.Count != 0 && st.Peek() == '(') {
                ans += 2;
                st.Pop();
            }
        }

        print(ans);

    }

    struct quat<T1, T2, T3, T4> { public T1 fst; public T2 snd; public T3 thr; public T4 frt; }
    struct trip<T1, T2, T3> { public T1 fst; public T2 snd; public T3 thr; }
    struct pair<T1, T2> { public T1 fst; public T2 snd; }
    static long LCM(long a, long b) { return a / GCD(a, b) * b; }
    static long GCD(long a, long b) { if (b == 0) return a; else return GCD(b, a % b); }
    static void swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; }
    static double dist(double x1, double y1, double x2, double y2) { return Math.Sqrt(Math.Pow(x1-x2, 2)+Math.Pow(y1-y2, 2)); }
    static void fill<T>(T[] d, T v) { for (int i = 0; i < d.Length; i++) d[i] = v; }
    static void fill<T>(T[,] d, T v) { for (int i = 0; i < d.GetLength(0); i++) { for (int j = 0; j < d.GetLength(1); j++) { d[i, j] = v; } } }

    static void print(double v) { Console.Write(v); }
    static void print(long v) { Console.Write(v); }
    static void print(int v) { Console.Write(v); }
    static void print(string v) { Console.Write(v); }
    static void print(char v) { Console.Write(v); }
    //static void print(BigInteger v) { Console.Write(v); }
    static void print(String f, params object[] o) { Console.Write(f, o); }

    static void println(double v) { Console.WriteLine(v); }
    static void println(long v) { Console.WriteLine(v); }
    static void println(int v) { Console.WriteLine(v); }
    static void println(string v) { Console.WriteLine(v); }
    static void println(char v) { Console.WriteLine(v); }
    //static void println(BigInteger v) { Console.WriteLine(v); }
    static void println() { Console.WriteLine(); }
    static void println(String f, params object[] o) { Console.WriteLine(f, o); }

    static string RL() { return Console.ReadLine(); }
    static int[] readValsI(int n) { int[] t = new int[n]; for (int i = 0; i < n; i++) t[i] = readInt(); return t; }
    static double[] readValsD(int n) { double[] t = new double[n]; for (int i = 0; i < n; i++) t[i] = readDouble(); return t; }

    /*static BigInteger readBigInt()
    {
        BigInteger val = 0;
        bool m = false;
        int c;
        while (((c = Console.Read()) < '0' || c > '9') && c != '-') { }
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m=true : m=false) ? 0 : 0;
        while ((c = Console.Read() - 48) >= 0 && c <= 9) val = val*10 + (m?-c:c);
        return val;
    }*/

    static double readDouble() {
        bool m = false;
        double val = 0;
        int c = 0, r = 1;
        while(((c=Console.Read())<'0' || c>'9') && c!='-') {}
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m=true : m=false) ? 0 : 0;
        while ((c = Console.Read()) >= '0' && c <= '9') val = val * 10 + (m?-(c-48):(c-48));
        if(c=='.') while ((c = Console.Read()) >= '0' && c <= '9'){ val += ((double)(c-48))/(r*=10); }

        return val;
    }

    static long readLong()
    {
        long val = 0;
        bool m = false;
        int c;
        while (((c = Console.Read()) < '0' || c > '9') && c != '-') { }
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m=true : m=false) ? 0 : 0;
        while ((c = Console.Read() - 48) >= 0 && c <= 9) val = val*10 + (m?-c:c);
        return val;
    }

    static int readInt()
    {
        bool m = false;
        int val = 0, c;
        while (((c = Console.Read()) < '0' || c > '9') && c != '-') { }
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m=true : m=false) ? 0 : 0;
        while ((c = Console.Read() - 48) >= 0 && c <= 9) val = val*10 + (m?-c:c);
        return val;
    }

    static string readLine() {
        string s = "";
        int c;
        while((c=Console.Read())!=10 && c!=-1) s+=(char)c;
        return s;
    }

    static string readString() {
        string s = "";
        int c;
        while ((c = Console.Read()) != 10 && c != 32 && c != -1) s += (char)c;
        return s;
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int ans = 0;
        int b = 0;
        foreach (char c in ReadToken())
            if (c == ')')
            {
                if (b > 0)
                {
                    b--;
                    ans++;
                }
            }
            else
            {
                b++;
                ans++;
            }
        Write(ans - b);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


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

#region ioh

class Scanner
{
    private readonly TextReader reader;
    private string[] buffer;
    private int bufferPos;

    public Scanner()
        : this(null)
    { }

    public Scanner(TextReader reader)
    {
        this.reader = reader ?? Console.In;
        buffer = new string[0];
    }

    public string NextTerm()
    {
        if (bufferPos >= buffer.Length)
        {
            buffer = reader.ReadLine().Split(' ');
            bufferPos = 0;
        }

        return buffer[bufferPos++];
    }

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

    public int[] NextIntArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    }

    public int[][] NextIntMatrix(int rowCount)
    {
        var matrix = new int[rowCount][];

        for (int i = 0; i < matrix.Length; i++)
        {
            matrix[i] = NextIntArray();
        }

        return matrix;
    }
}

#endregion

class Program
{
    private static readonly Scanner s = new Scanner();

    static void Main(string[] args)
    {
        var s = Console.ReadLine();

        var p = new Stack<char>();

        var r = s.Length;

        foreach (var c in s)
        {
            if (c == ')')
            {
                if (p.Count == 0)
                {
                    r--;
                }
                else
                {
                    p.Pop();
                }
            }
            else
            {
                p.Push(c);
            }

        }

        Console.WriteLine(r-p.Count);
    }
}


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

#region ioh

class Scanner
{
    private readonly TextReader reader;
    private string[] buffer;
    private int bufferPos;

    public Scanner()
        : this(null)
    { }

    public Scanner(TextReader reader)
    {
        this.reader = reader ?? Console.In;
        buffer = new string[0];
    }

    public string NextTerm()
    {
        if (bufferPos >= buffer.Length)
        {
            buffer = reader.ReadLine().Split(' ');
            bufferPos = 0;
        }

        return buffer[bufferPos++];
    }

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

    public int[] NextIntArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    }

    public int[][] NextIntMatrix(int rowCount)
    {
        var matrix = new int[rowCount][];

        for (int i = 0; i < matrix.Length; i++)
        {
            matrix[i] = NextIntArray();
        }

        return matrix;
    }
}

#endregion

class Program
{
    private static readonly Scanner s = new Scanner();

    static void Main(string[] args)
    {
        var s = Console.ReadLine();

        var r = s.Length;
        var o = 0;

        foreach (var c in s)
        {
            if (c == ')')
            {
                if (o == 0)
                {
                    r--;
                }
                else
                {
                    o--;
                }
            }
            else
            {
                o++;
            }
        }

        Console.WriteLine(r-o);
    }
}


import java.util.Scanner

fun main(args : Array<String>){

    val strIn = readLine()!!
    var a = 0
    var s = strIn.length

    for(char in strIn) {
        if(char == '(') {
            a++
        }
        else if(char ==')') {
            a--
            if(a<0) {
                s--
                a = 0
            }
        }
    }
        println(s - a)
}


import java.util.*

fun main() {

    var a= readLine();
    var stack:Stack<Int> = Stack()

    var ans:Int=0
    for (i in a?.indices!!){
        if (a[i]=='(')stack.push(1)
        else{
            if (!stack.isEmpty()){
               stack.pop()
                ans+=2
            }
        }
    }
    println(ans)

}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

#define EACH( v, c ) for ( auto &v : c )

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	string str;
	cin >> str;

	int depth = 0, res = 0;

	EACH( ch, str )
	{
		if ( ch == '(' )
		{
			depth++;
		}
		else
		{
			if ( 0 < depth )
			{
				depth--;
			}
			else
			{
				res++;
			}
		}
	}

	cout << ( str.size() - res - depth ) << endl;

	return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

const int INF = INT_MAX / 4;
const double EPS = 1e-12;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	string str;
	cin >> str;

	int depth = 0, res = 0;

	EACH( ch, str )
	{
		if ( ch == '(' )
		{
			depth++;
		}
		else
		{
			if ( 0 < depth )
			{
				depth--;
			}
			else
			{
				res++;
			}
		}
	}

	cout << ( str.size() - res - depth ) << endl;

	return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

#define EACH( v, c ) for ( auto &v : c )

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	int depth = 0, res = 0, count = 0;
	char ch;

	while ( cin >> ch )
	{
		count++;

		if ( ch == '(' )
		{
			depth++;
		}
		else
		{
			if ( 0 < depth )
			{
				depth--;
			}
			else
			{
				res++;
			}
		}
	}

	cout << ( count - res - depth ) << endl;

	return 0;
}


#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <vector>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
#define MM(a,x) memset(a,x,sizeof(a));
#define ALL(x)  (x).begin(), (x).end()
#define P(x)	cerr<<"["#x<<" = "<<x<<"]\n"
#define PP(x,i)	cerr<<"["#x<<i<<" = "<<x[i]<<"]\n"
#define P2(x,y)	cerr<<"["#x" = "<<x<<", "#y" = "<<y<<"]\n"
#define TM(a,b)	cerr<<"["#a" -> "#b": "<<1e3*(b-a)/CLOCKS_PER_SEC<<"ms]\n";
#define FOR(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define mp make_pair
#define pb push_back
#define x first
#define y second
struct _ {_() {ios_base::sync_with_stdio(0);}} _;
template<class T> void PV(T a, T b) {while(a != b)cout << *a++, cout << (a != b ? " " : "\n");}
template<class T> inline bool chmin(T &a, T b) {return a > b ? a = b, 1 : 0;}
template<class T> inline bool chmax(T &a, T b) {return a < b ? a = b, 1 : 0;}
const int inf = 0x3f3f3f3f;
const int mod = int(1e9) + 7;

string s;
int n;
int main() {
	cin >> s;
	int res = 0;
	int cnt = 0;
	for(int i = 0; i < s.length(); i++) {
		if(s[i] == '(') cnt++;
		else if(cnt > 0) {res += 2; cnt--;}
	}

	cout << res << endl;
	return 0;
}


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

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <set>
#include <deque>
#include <utility>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>

#include <math.h>
#include <iomanip>
#include <algorithm>
#include <limits.h>

#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define INPUT "cowjog.in"
#define OUTPUT "cowjog.out"
#define FILE 0

#define MAX 2010
#define MAXN 1000010
#define INF -1
#define EPS 0.0000001
#define PI acos(-1)
#define sbit(a) a&(-a)
#define gauss(a) a*(a+1)/2
#define Node pair<int, long long>

typedef long long ll;

using namespace std;

int ans;
string s;

int main() {

    if(FILE) {
        freopen(INPUT, "r", stdin);
        freopen(OUTPUT, "w", stdout);
    }

    int cur = 0;
    cin >> s;
    for(int i = 0; i < int(s.size()); i++) {
        if(s[i] == '(') cur++;
        else if(cur > 0) cur--, ans+=2;
    }
    cout << ans << "\n";

    return 0;
}


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

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <set>
#include <deque>
#include <utility>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>

#include <math.h>
#include <iomanip>
#include <algorithm>
#include <limits.h>

#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define INPUT "cowjog.in"
#define OUTPUT "cowjog.out"
#define FILE 0

#define MAX 2010
#define MAXN 1000010
#define INF -1
#define EPS 0.0000001
#define PI acos(-1)
#define sbit(a) a&(-a)
#define gauss(a) a*(a+1)/2
#define Node pair<int, long long>

typedef long long ll;

using namespace std;

int ans;
char s[MAXN];

int main() {

    if(FILE) {
        freopen(INPUT, "r", stdin);
        freopen(OUTPUT, "w", stdout);
    }

    int cur = 0;
    scanf("%s", s);
    for(int i = 0; i < strlen(s); i++) {
        if(s[i] == '(') cur++;
        else if(cur > 0) cur--, ans+=2;
    }
    printf("%d\n", ans);

    return 0;
}


#include <iostream>
#include<string>

using namespace std;

int main()
{
    string s;
    int c = 0, ans = 0;
    getline(cin, s);

    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == '(')
            c++;
        if (c > 0 && s[i] == ')')
            ans++, c--;
    }
    cout << ans * 2 << endl;

    return 0;
}


#include<iostream>
#include <string>
#include<algorithm>

using namespace std;

int main()
{
   string s;
   cin>>s;
   long long x=0,z=0;
   for(int i=0;i<=s.size()/2;)
   {

       if(s[i]=='('&&s[s.size()-i-1]!=')')
       {
           s.erase(s.size()-i-1,1);
       }
       if(s[i]=='('&&s[i+1]==')'&&i==0)
        i+=2;
       else if(s[i]==')'&&s[s.size()-i-1]==')')
       {
           if(i==s.size()-i-1)
             s.erase(i,1);
             else
             {
                s.erase(s.size()-i-1,1);
                s.erase(i,1);
             }
       }
       else if(s[i]=='('&&s[s.size()-i-1]=='(')
                        s.erase(s.size()-i-1,1);
        else
            i++;
   }
   if(s.size()==1)
   {
       cout<<0;
   }
else
   cout<<s.size();

    return 0;
}


#include<iostream>
#include <string>
#include<algorithm>

using namespace std;

int main()
{
   string s;
   cin>>s;
   long long x=0,z=0;
   for(int i=0;i<=s.size()/2;)
   {

       if(s[i]=='('&&s[s.size()-i-1]!=')')
       {
           s.erase(s.size()-i-1,1);
       }
       if(s[i]=='('&&s[i+1]==')')
        i+=2;
       else if(s[i]==')'&&s[s.size()-i-1]==')')
       {
           if(i==s.size()-i-1)
             s.erase(i,1);
             else
             {
                s.erase(s.size()-i-1,1);
                s.erase(i,1);
             }
       }
       else if(s[i]=='('&&s[s.size()-i-1]=='(')
                        s.erase(s.size()-i-1,1);
        else
            i++;
   }
   if(s.size()==1)
   {
       cout<<0;
   }
else
   cout<<s.size();

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <cstring>
#define SIZE 1000005

using namespace std;

stack <int> st;
char str[SIZE];

int main()
{
	scanf("%s",&str);
	int s=0,sum=0;
	int sz=strlen(str);
	int ret=sz;
	for(int i=0;i<sz;i++)
	{
		if(str[i]=='(') sum++;
		else
		{
			if(sum!=0) sum--;
			else ret--;
		}
	}
	printf("%d\n",ret-sum);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#define pb push_back
#define ll long long
#define mp make_pair
#define ff first
#define sc second
#define pii pair<int,int>
#define pis pair<int, string>
#define psi pair<string, int>
using namespace std;
int main () {
    string s;
    cin >> s;
    int n = s.length(), t=0, k=0, m = 0;
    for(int i = 0; i<n; i++)
        if(s[i]=='(') k++;
        else {
            if(k){
                k--;
                t+=2;
            }
            else {
                if(m<t) m = t;
                t = 0;
                k = 0;
            }
        }
    cout << max(m, t);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#define pb push_back
#define ll long long
#define mp make_pair
#define ff first
#define sc second
#define pii pair<int,int>
#define pis pair<int, string>
#define psi pair<string, int>
using namespace std;
int main () {
    string s;
    cin >> s;
    int n = s.length(), t=0, k=0, m = 0;
    for(int i = 0; i<n; i++)
        if(s[i]=='(') k++;
        else {
            if(k){
                k--;
                t+=2;
            }
            else {
                m+=t;
                t = 0;
                k = 0;
            }
        }
    cout << m+=t;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#define pb push_back
#define ll long long
#define mp make_pair
#define ff first
#define sc second
#define pii pair<int,int>
#define pis pair<int, string>
#define psi pair<string, int>
using namespace std;
int main () {
    string s;
    cin >> s;
    int n = s.length(), t=0, k=0, m = 0;
    for(int i = 0; i<n; i++)
        if(s[i]=='(') k++;
        else {
            if(k){
                k--;
                t+=2;
            }
            else {
                m+=t;
                t = 0;
                k = 0;
            }
        }
    cout << m+t;
    return 0;
}


#include <iostream>
using namespace std;
char c;
int n=0,t=0;
int main () {
	while (cin.get(c)){
		if (c=='(') n++;
		if (c==')' && n>0) {
				t++;
				n--;
			}
	}
	cout<<t*2;
}


#include <iostream>
using namespace std;
char c;
int n=0,t=0;
int main () {
	while (cin.get(c)){
		if (c=='(') n++;
		else if (n>0) {
				t++;
				n--;
			}
	}
	cout<<t*2;
}


#include <cstdio>
#include <iostream>
#include <cmath>
#include <stack>
#include <string>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int t  = 0, R = 0;
	for (int i = 0; i < s.length(); ++i)
		if (s[i] == '(')
			++t;
		else if (t)
		{
			--t;
			R += 2;
		}
	cout << R;
	return 0;
}


                          ///Rabby (corei5)///
                        ///Daffodil International University///

#include<bits/stdc++.h>
#define pi acos(-1)
#define rabby 100000

using namespace std;

int main()
{
    char a[rabby];
    int i,j,k,len,sum,c1,c2;
    while(gets(a))
    {
        sum =0;
        c1 = 0;
        c2 = 0;
        len = strlen(a);
        for(i=0;i<len;i++)
        {
            if(a[i]=='(') c1++;
            else c2++;
            if(c2>c1) c2--;
        }
        printf("%d\n",min(c1,c2)*2);

    }

    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char str[1000003];
int main()
{
    int len,sum,c1,c2,i;
    scanf("%s",str);
    len=strlen(str);
    sum=c1=c2=0;
    for (i=0;i<len;i++)
    {
        if (str[i]=='(')
        {
            c1++;
        }
        else
        {
            c2++;
            if (c2>c1) c2--;
        }
    }
    printf("%d\n",min(c1,c2)*2);
    return 0;
}


                          ///Rabby (corei5)///
                        ///Daffodil International University///

#include<bits/stdc++.h>
#define pi acos(-1)
#define rabby 10000000

using namespace std;

char a[rabby];
int main()
{

    int i,j,k,len,sum,c1,c2;
    while(gets(a))
    {
        sum =0;
        c1 = 0;
        c2 = 0;
        len = strlen(a);
        for(i=0;i<len;i++)
        {
            if(a[i]=='(') c1++;
            else c2++;
            if(c2>c1) c2--;
        }
        printf("%d\n",min(c1,c2)*2);

    }

    return 0;
}


                          ///Rabby (corei5)///
                        ///Daffodil International University///

#include<bits/stdc++.h>
#define pi acos(-1)
#define rabby 100000

using namespace std;

char a[rabby];
int main()
{

    int i,j,k,len,sum,c1,c2;
    while(gets(a))
    {
        sum =0;
        c1 = 0;
        c2 = 0;
        len = strlen(a);
        for(i=0;i<len;i++)
        {
            if(a[i]=='(') c1++;
            else c2++;
            if(c2>c1) c2--;
        }
        printf("%d\n",min(c1,c2)*2);

    }

    return 0;
}


#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int) n; ++i)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; ++i)
#define For(i, st, en) for(int i = (int)st; i <= (int)en; ++i)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
#define mp make_pair

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

/**
 * The code starts here.
 */

int main()
{
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    int bal = 0;
    for (int i = 0; i < (int)s.length(); ++i)
    {
        if (s[i] == ')')
        {
            if (bal)
            {
                --bal;
                ans += 2;
            }
        } else
        {
            ++bal;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main ()
{
  long  n;
  cin>> n;
  int* x= new int [n] ;
  int in,m=0 ;
  long i=0 ;
  for ( i=0 ; i<n;i++)
  {
      cin>>in;
     if (in==' ')
         continue;
         x[m]=in;
         m++;
  }

  long k ,failEqu=0,failSma=0;
  int out=0,empty;
  bool many=true;
  for(i=0;i<n;i++)
  {
      if(x[i]==-1)
          continue;
      out++;
      empty=4-x[i];

            if (failEqu<200)
          {
          for(k=i+1;(k<n)&&(empty);k++)
          {

              if ((empty==x[k])&&(x[k]!=-1))
              {

                  empty-=x[k];
                  x[k]=-1;
                  failEqu=0;
                  break;
              }
              else
                  failEqu++;
          }
            }

          if(failSma<200)
          {
          for(k=i+1;(k<n)&&(empty);k++)
          {

              if ((empty>=x[k])&&(x[k]!=-1))
              {
                  empty-=x[k];
                  x[k]=-1;
                  failSma=0;
                  continue;
              }
              else
                  failSma++;
          }
          }
          else
              x[i]=-1;

  }

  cout<< out << endl;

return 0 ;
}


#include <iostream>

using namespace std;

int main ()
{
  long  n;
  cin>> n;
  int* x= new int [n] ;
  int in,m=0 ;
  long i=0 ;
  for ( i=0 ; i<n;i++)
  {
      cin>>in;
     if (in==' ')
         continue;
         x[m]=in;
         m++;
  }

  long k;
  int out=0,empty,real_emp,num=0,equ=0,min=x[0];
  int queue[4]={0, 0 ,0, 0};
  bool check=false,miss=false;

  for(i=0;i<n;i++)
  {
      if(min>x[k])
         {
           min=x[k];
         }
  }

  for(i=0;i<n;i++)
  {
      if(x[i]==-1)
          continue;
      out++;
      empty=4-x[i];
      real_emp=empty;
      if((min<real_emp))
              miss=true;
      k=i+1;
      num=0;
      while((empty||(!miss))&&(k<n)&&(!check))
      {

          if(real_emp==x[k])
          {
              x[k]=-1;
              break;
          }

           if ( (x[k]<=empty)&&(x[k]!=-1)&&(empty!=0))
          {
              empty-=x[k];
              queue[num]=k;
              num++;
          }
          if ((x[i]==x[k])&&(i==0))
              equ++;
          k++;
      }

        if((!empty)||(k>=n))
        {
            for(int n=0;n<num;n++)
                x[queue[n]]=-1;

        }
        else if(empty&&(k>=n))
            {
                x[i]=-1;
            }
        check= (equ+1)==n;
        if (check)
        {
            if(x[i]==1)
                out=ceil((double)n/4.0);
            if(x[i]==2)
                out=ceil((double)n/2.0);
            if(x[i]==3)
                out=n;
            if(x[i]==4)
                out=n;
            break;
        }

  }

  cout<< out << endl;

return 0 ;
}


#include <iostream>

using namespace std;

int main ()
{
  long  n;
  cin>> n;
  int* x= new int [n] ;
  int in,m=0 ;
  long i=0 ;
  for ( i=0 ; i<n;i++)
  {
      cin>>in;
     if (in==' ')
         continue;
         x[m]=in;
         m++;
  }

  long k;
  int out=0,empty,real_emp,num=0,equ=0,min=x[0];
  int queue[4]={0, 0 ,0, 0};
  bool check=false,miss=false;

  for(i=0;i<n;i++)
  {
      if(min>x[i])
         {
           min=x[i];
         }
  }

  for(i=0;i<n;i++)
  {
      if(x[i]==-1)
          continue;
      out++;
      empty=4-x[i];
      real_emp=empty;
      if((min=<real_emp))
              miss=true;
      k=i+1;
      num=0;
      while((empty||(!miss))&&(k<n)&&(!check))
      {

          if(real_emp==x[k])
          {
              x[k]=-1;
              break;
          }

           if ( (x[k]<=empty)&&(x[k]!=-1)&&(empty!=0))
          {
              empty-=x[k];
              queue[num]=k;
              num++;
          }
          if ((x[i]==x[k])&&(i==0))
              equ++;
          k++;
      }

        if((!empty)||(k>=n))
        {
            for(int n=0;n<num;n++)
                x[queue[n]]=-1;

        }
        else if(empty&&(k>=n))
            {
                x[i]=-1;
            }
        check= (equ+1)==n;
        if (check)
        {
            if(x[i]==1)
                out=ceil((double)n/4.0);
            if(x[i]==2)
                out=ceil((double)n/2.0);
            if(x[i]==3)
                out=n;
            if(x[i]==4)
                out=n;
            break;
        }

  }

  cout<< out << endl;

return 0 ;
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int n,a,sum1=0,sum2=0,sum3=0,sum4=0;
 cin>>n;
for(int i=1; i<=n;i++)
{
    cin>>a;
    if(a==1)
    {
        sum1++;
    }
    else if(a==2)
    {
        sum2++;
    }
    else if(a==3)
    {
        sum3++;
    }
    else if(a==4)
    {
        sum4++;
    }
}
int d;
d=0;
int temp1,temp2,temp3,temp4;
d=sum4+sum3;
if(sum2||sum3)
{
if(sum1<=sum3)
{
    d=d+ceil(sum2/2.0);
}
else
{
    if(sum2)
    {
    temp1= sum1-sum3;
    temp2= ceil(temp1/2.0);
    if(temp2>=sum2)
    {
        d=d+temp2;

    }
        else
        {
            d=d+ceil(sum2/2.0);
        }
    }
else
{
    d=d+ceil(sum1/4.0);
}
}
}
else
{
d=d+ceil(sum1/4.0);
}
    cout<<d;

}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int n,a,sum=0;
 cin>>n;

for(int i=1;i<=n;i++)
{
    cin>>a;
    sum=sum+a;
}
double f=sum/4.0;
int d;
if(f>0)
{
    d=(sum/4)+1;
}
else
{
d=(sum/4);

}
cout<<d;
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int n,a,sum1=0,sum2=0,sum3=0,sum4=0;
 cin>>n;
for(int i=1; i<=n;i++)
{
    cin>>a;
    if(a==1)
    {
        sum1++;
    }
    else if(a==2)
    {
        sum2++;
    }
    else if(a==3)
    {
        sum3++;
    }
    else if(a==4)
    {
        sum4++;
    }
}
int d,b=0,f=0;
d=0;
int temp1=0,temp2=0,temp3=0,temp4=0;
d=sum4+sum3;
if(sum3)
{
    if(sum1<=sum3)
        {
             d=d+ceil(sum2/2.0);
        }
    else
        {
            temp1=sum1-sum3;
            temp2= ceil(sum2/2.0);
            temp3= ceil(sum1/4.0);
            if(temp2>(sum2/2))
            {
                b=1;
            }
            if(temp3>(sum1/4))
            {
                f=1;
            }
            d=d+(sum2/2)+(sum1/4);
        }
        if(b||f)
        {
            d=d+1;
        }
}
else if(sum1&&sum2)
{
d=d+ceil(sum2/(sum1/2.0));
}
else if(sum2)
{
    d=d+ceil(sum2/2.0);

}
else if(sum1)
{
    d=ceil(sum1/4.0);
}

    cout<<d;

}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int n,a,sum1=0,sum2=0,sum3=0,sum4=0,temp1=0,temp2=0,temp3=0,temp4=0;
 cin>>n;
for(int i=1; i<=n;i++)
{
    cin>>a;
    if(a==1)
    {
        sum1++;
    }
    else if(a==2)
    {
        sum2++;
    }
    else if(a==3)
    {
        sum3++;
    }
    else if(a==4)
    {
        sum4++;
    }
}
int sumt;
sumt= sum4;
if(sum1&&sum3==0&&sum2==0)
{
    if(sum1>=4)
    { if(sum1%4==0)
    {
        sumt=sumt+(sum1/4);
    }
    else if(sum1%4==1)
    {
        sumt=sumt+((sum1-1)/4)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }
}
else if(sum2&&sum3==0&&sum1==0)
{

    if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }
}

else if(sum3&&sum2==0&&sum1==0)
{
    sumt=sumt+sum3;
}
else if(sum3&&sum2&&sum1==0)
{

    sumt=sumt+sum3;

    if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }

}
else if(sum3&&sum1&&sum2==0)
{
    if(sum3>=sum1)
      {sumt=sumt+sum3;}
    else
    {
      sumt=sumt+sum3;
      temp1=sum1-sum3;

    if(temp1>=4)
    { if(temp1%4==0)
    {
        sumt=sumt+(temp1/4);
    }
    else if(temp1%4==1)
    {
        sumt=sumt+((temp1-1)/4)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }
    }
}
else if(sum2&&sum1&&sum3==0)
{
     if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2);
        temp2=1;
    }
    }
    else
    {
        temp2=sum2;
    }
   // cout<<temp2<<endl;
    if(sum1>=4)
    {
        if(sum1%4==0)
    {
        sumt=sumt+(sum1/4);
    }
    else if(sum1%4==1)
    {
        sumt=sumt+((sum1-1)/4);
        temp3=1;
    }
    }
    else
    {
        temp3=sum1;
    }

    if((temp3==1&&temp2==1)||(temp3==2&&temp2==1))
    {
        sumt=sumt+1;

    }
    else if(temp3>2)
    {
        sumt=sumt+2;
    }

}
else if(sum3&&sum1&&sum2)
{
 if(sum3>=sum1)
 {
     sumt = sumt+sum3;

    if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }
 }
 else /*if sum3<sum1*/
    {

        sumt=sumt+sum3;
        temp4=sum1-sum3;

     if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2);
        temp2=1;
    }
    }
    else
    {
        temp2=sum2;
    }
    if(temp4>=4)
    {
        if(temp4%4==0)
    {
        sumt=sumt+(temp4/4);
    }
    else if(temp4%4==1)
    {
        sumt=sumt+((temp4-1)/4);
        temp3=1;
    }
    else
    {
        temp3=temp4;
    }
    }
    if((temp3==1&&temp2==1)||(temp3==2&&temp2==1))
    {
        sumt=sumt+1;
    }
    else if(temp3>2)
    {
        sumt=sumt+2;
    }

    }
}
cout<<sumt;
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 long int n,a,sum1=0,sum2=0,sum3=0,sum4=0,temp1=0,temp2=0,temp3=0,temp4=0;
 cin>>n;
for(int i=1; i<=n;i++)
{
    cin>>a;
    if(a==1)
    {
        sum1++;
    }
    else if(a==2)
    {
        sum2++;
    }
    else if(a==3)
    {
        sum3++;
    }
    else if(a==4)
    {
        sum4++;
    }
}
int sumt;
sumt= sum4;
if(sum1&&sum3==0&&sum2==0)
{
    if(sum1>=4)
    { if(sum1%4==0)
    {
        sumt=sumt+(sum1/4);
    }
    else if(sum1%4==1)
    {
        sumt=sumt+((sum1-1)/4)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }
}
else if(sum2&&sum3==0&&sum1==0)
{

    if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }
}

else if(sum3&&sum2==0&&sum1==0)
{
    sumt=sumt+sum3;
}
else if(sum3&&sum2&&sum1==0)
{

    sumt=sumt+sum3;

    if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }

}
else if(sum3&&sum1&&sum2==0)
{
    if(sum3>=sum1)
      {sumt=sumt+sum3;}
    else
    {
      sumt=sumt+sum3;
      temp1=sum1-sum3;

    if(temp1>=4)
    { if(temp1%4==0)
    {
        sumt=sumt+(temp1/4);
    }
    else if(temp1%4==1)
    {
        sumt=sumt+((temp1-1)/4)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }
    }
}
else if(sum2&&sum1&&sum3==0)
{
    sumt = ceil(((sum2*2)+sumt)/2.0);

}
else if(sum3&&sum1&&sum2)
{
 if(sum3>=sum1)
 {
     sumt = sumt+sum3;

    if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }
 }
 else /*if sum3<sum1*/
    {

        sumt=sumt+sum3;
        temp4=sum1-sum3;

     if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2);
        temp2=1;
    }
    }
    else
    {
        temp2=sum2;
    }
    if(temp4>=4)
    {
        if(temp4%4==0)
    {
        sumt=sumt+(temp4/4);
    }
    else if(temp4%4==1)
    {
        sumt=sumt+((temp4-1)/4);
        temp3=1;
    }
    else
    {
        temp3=temp4;
    }
    }
   if((temp3==1&&temp2==1)||(temp3==2&&temp2==1)||(temp3==2&&temp2==0)||(temp3==0&&temp2==1)||(temp3==1&&temp2==0))
    {
        sumt=sumt+1;

    }
    else if(temp3>2)
    {
        sumt=sumt+2;
    }

    }
}
cout<<sumt;
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int n,a,sum=0;
 cin>>n;

for(int i=1;i<=n;i++)
{
    cin>>a;
    sum=sum+a;
}
double f=sum/4.0;
int s = sum/4;
int d;
if(f>s)
{
    d=(sum/4)+1;
}
else
{
d=(sum/4);

}
cout<<d;
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int n,a,sum1=0,sum2=0,sum3=0,sum4=0;
 cin>>n;
for(int i=1; i<=n;i++)
{
    cin>>a;
    if(a==1)
    {
        sum1++;
    }
    else if(a==2)
    {
        sum2++;
    }
    else if(a==3)
    {
        sum3++;
    }
    else if(a==4)
    {
        sum4++;
    }
}
int d;
d=0;
int temp1,temp2,temp3,temp4;
d=sum4+sum3;
if(sum2||sum3)
{
if(sum1<=sum3)
{
    d=d+ceil(sum2/2.0);
}
else
{
    if(sum2)
    {
    temp1= sum1-sum3;
    temp2= ceil(temp1/2.0);
    if(temp2>=sum2)
    {
        d=d+temp2;

    }
        else
        {
            d=d+sum2;
        }
    }
else
{
    d=d+ceil(sum1/4.0);
}
}
}
else
{
d=d+ceil(sum1/4.0);
}
    cout<<d;

}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int n,a,sum1=0,sum2=0,sum3=0,sum4=0;
 cin>>n;
for(int i=1; i<=n;i++)
{
    cin>>a;
    if(a==1)
    {
        sum1++;
    }
    else if(a==2)
    {
        sum2++;
    }
    else if(a==3)
    {
        sum3++;
    }
    else if(a==4)
    {
        sum4++;
    }
}
int d;
d=0;
int temp1,temp2,temp3,temp4;
d=sum4+sum3;
if(sum2)
{
if(sum1<sum3)
{
    d=d+ceil(sum2/2.0);
}
else
{
    temp1= sum1-sum3;
    temp2= ceil(temp1/2.0);
    if(temp2>=sum2)
    {
        d=d+temp2;

    }
        else
        {
            d=d+sum2;
        }
    }
}
else
{
d=d+ceil(sum1/4.0);
}
    cout<<d;

}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int n,a,sum1=0,sum2=0,sum3=0,sum4=0;
 cin>>n;
for(int i=1; i<=n;i++)
{
    cin>>a;
    if(a==1)
    {
        sum1++;
    }
    else if(a==2)
    {
        sum2=sum2+2;
    }
    else if(a==3)
    {
        sum3++;
    }
    else if(a==4)
    {
        sum4++;
    }
}
int d;
int temp1,temp2,temp3,temp4;
double f= sum2/4.0;
double m;
if(f>(sum2/4))
{
    temp2=(sum2/4)+1;
}
else
{
    temp2=sum2/4;
}
int l=((sum4*4)+(sum3*3)+sum2+sum1);
if(sum1==0)
{
    d=sum4+sum3+temp2;
}
else
{
    if(sum3>=sum1)
    {
d=sum4+sum3+temp2;
}
else
{
    d=sum4+sum3+(ceil(abs(sum1-sum3)/4.0))+temp2;
}

}

cout<<d;

}


#include <iostream>
#include <string>
using namespace std;
int main()
{
int sumt=0,n,m,sum1=0,sum2=0,sum3=0;
cin>>n;
for(int i=1;i<=n;i++)
{
    cin>>m;
    if(m==4)
    {
        sumt++;
    }
    else if(m==3)
    { sum3++;

    }
    else if(m==2)
    {
        sum2++;
    }
    else if(m==1)
    {

     sum1++;
    }
}

if(sum1==sum3)
{
    sumt=sumt+sum1;
    sum3=0;
    sum1=0;

}
else if(sum1<sum3)
{ sumt=sumt+sum1;
sum3=sum3-sum1;
sum1=0;
}
else if(sum1>sum3)
{
    sumt=sumt+sum3;
    sum1=sum1-sum3;
    sum3=0;

}

if(sum2%2==0)
{
    sumt=sumt+(sum2/2);
    sum2=0;

}
else if(sum2%2==1)
{
    sumt=sumt+((sum2-1)/2);
    sum2=1;

}
if(sum1==0&&sum3==0&&sum2==1)
{
    sumt=sumt+1;
    sum2=0;

}
else if(sum1==0&&sum3==0&&sum2==0)
{
    sumt=sumt;
    sum2=0;

}
else if(sum1==0)
{
sumt=sumt+sum2+sum3;
sum2=0;
sum3=0;
}
else if(sum3==0&&sum2==1&&sum1==1)
{
    sum1=sum1-1;
sumt=sumt+1;
sum2=0;

}
else if(sum3==0&&sum2==1&&sum1>=2)
{
    sum1=sum1-2;
    sumt=sumt+1;
    sum2=0;

}
if(sum1%4>0)
{
    sumt=sumt+1;
    sum1=sum1-(sum1%4);
}
sum1=sum1/4;
sumt=sumt+sum1;
cout<<sumt;
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int n,a,sum1=0,sum2=0,sum3=0,sum4=0,temp1=0,temp2=0,temp3=0,temp4=0;
 cin>>n;
for(int i=1; i<=n;i++)
{
    cin>>a;
    if(a==1)
    {
        sum1++;
    }
    else if(a==2)
    {
        sum2++;
    }
    else if(a==3)
    {
        sum3++;
    }
    else if(a==4)
    {
        sum4++;
    }
}
int sumt;
sumt= sum4;
if(sum1&&sum3==0&&sum2==0)
{
    if(sum1>=4)
    { if(sum1%4==0)
    {
        sumt=sumt+(sum1/4);
    }
    else if(sum1%4==1)
    {
        sumt=sumt+((sum1-1)/4)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }
}
else if(sum2&&sum3==0&&sum1==0)
{

    if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }
}

else if(sum3&&sum2==0&&sum1==0)
{
    sumt=sumt+sum3;
}
else if(sum3&&sum2&&sum1==0)
{

    sumt=sumt+sum3;

    if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }

}
else if(sum3&&sum1&&sum2==0)
{
    if(sum3>=sum1)
      {sumt=sumt+sum3;}
    else
    {
      sumt=sumt+sum3;
      temp1=sum1-sum3;

    if(temp1>=4)
    { if(temp1%4==0)
    {
        sumt=sumt+(temp1/4);
    }
    else if(temp1%4==1)
    {
        sumt=sumt+((temp1-1)/4)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }
    }
}
else if(sum2&&sum1&&sum3==0)
{
     if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2);
        temp2=1;
    }
    }
    else
    {
        temp2=sum2;
    }
    if(sum1>=4)
    {
        if(sum1%4==0)
    {
        sumt=sumt+(sum1/4);
    }
    else if(sum1%4==1)
    {
        sumt=sumt+((sum1-1)/4);
        temp3=1;
    }
    else
    {
        temp3=sum1;
    }
    }
    if((temp3==1&&temp2==1)||(temp3==2&&temp2==1))
    {
        sumt=sumt+1;
    }
    else if(temp3>2)
    {
        sumt=sumt+2;
    }

}
else if(sum3&&sum1&&sum2)
{
 if(sum3>=sum1)
 {
     sumt = sumt+sum3;

    if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2)+1;
    }
    }
    else
    {
        sumt=sumt+1;
    }
 }
 else /*if sum3<sum1*/
    {

        sumt=sumt+sum3;
        temp4=sum1-sum3;

     if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2);
        temp2=1;
    }
    }
    else
    {
        temp2=sum2;
    }
    if(temp4>=4)
    {
        if(temp4%4==0)
    {
        sumt=sumt+(temp4/4);
    }
    else if(temp4%4==1)
    {
        sumt=sumt+((temp4-1)/4);
        temp3=1;
    }
    else
    {
        temp3=temp4;
    }
    }
    if((temp3==1&&temp2==1)||(temp3==2&&temp2==1))
    {
        sumt=sumt+1;
    }
    else if(temp3>2)
    {
        sumt=sumt+2;
    }

    }
}
cout<<sumt;
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 long int n,a,sum1=0,sum2=0,sum3=0,sum4=0,temp1=0,temp2=0,temp3=0,temp4=0;
 cin>>n;
for(int i=1; i<=n;i++)
{
    cin>>a;
    if(a==1)
    {
        sum1++;
    }
    else if(a==2)
    {
        sum2++;
    }
    else if(a==3)
    {
        sum3++;
    }
    else if(a==4)
    {
        sum4++;
    }
}
int sumt;
sumt= sum4;
if(sum3)
{
    sumt=sum3+sumt;
    if(sum1>sum3)
    {
        temp1= sum1-sum3;
    }

    else
    {
        temp1=sum1;
    }
}

else
{
    temp1=sum1;
}

if(temp1>=4)
{ if(temp1%4==0)
{
    sumt=sumt+temp1/4;
}
else
{
    sumt = sumt+ (temp1-1/4)+1;
}
}
else
{
    temp2=sum1;
}

    if(sum2>=2)
    { if(sum2%2==0)
    {
        sumt=sumt+(sum2/2);
    }
    else if(sum2%2==1)
    {
        sumt=sumt+((sum2-1)/2)+1;
    }
    }
    else
    {
        temp3=1;
    }
    if((temp3==1&&temp2==1)||(temp3==2&&temp2==1)||(temp3==2&&temp2==0)||(temp3==0&&temp2==1)||(temp3==1&&temp2==0))
    {
        sumt=sumt+1;

    }
    else if(temp3>2)
    {
        sumt=sumt+2;
    }

cout<<sumt;
}