import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.*;

public class Code {
    static Scan sc = new Scan();
    static Print print = new Print();

    public static void main(String[] args)throws Exception
    {
        int n = sc.scanInt();
        var map = new HashMap<Integer,Integer>();
        int a[] = new int[n];
        for(int i=0;i<n;i++)
        {
            a[i] = sc.scanInt();
            map.put(a[i],i);
        }
        int m = sc.scanInt();
        long v=0,p=0;
        for(int i=1;i<=m;i++)
        {
            int b = sc.scanInt();
            v = v + map.get(b)+1;
            p = p + (n-map.get(b));
        }
        print.println(v+" "+p);
        print.close();
    }
}

class Scan {
    private byte[] buf = new byte[1024];
    private int index;
    private InputStream in;
    private int total;

    public Scan() {
        in = System.in;
    }

    public int scan() throws IOException {
        if (total < 0)
            throw new InputMismatchException();
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0)
                return -1;
        }
        return buf[index++];
    }

    public int scanInt() throws IOException {
        int integer = 0;
        int n = scan();
        while (isWhiteSpace(n))
            n = scan();
        int neg = 1;
        if (n == '-') {
            neg = -1;
            n = scan();
        }
        while (!isWhiteSpace(n)) {
            if (n >= '0' && n <= '9') {
                integer *= 10;
                integer += n - '0';
                n = scan();
            } else throw new InputMismatchException();
        }
        return neg * integer;
    }

    public long scanLong() throws IOException {
        long integer = 0;
        int n = scan();
        while (isWhiteSpace(n))
            n = scan();
        int neg = 1;
        if (n == '-') {
            neg = -1;
            n = scan();
        }
        while (!isWhiteSpace(n)) {
            if (n >= '0' && n <= '9') {
                integer *= 10;
                integer += (long) (n - '0');
                n = scan();
            } else throw new InputMismatchException();
        }
        return neg * integer;
    }

    public double scanDouble() throws IOException {
        double doub = 0;
        int n = scan();
        while (isWhiteSpace(n))
            n = scan();
        int neg = 1;
        if (n == '-') {
            neg = -1;
            n = scan();
        }
        while (!isWhiteSpace(n) && n != '.') {
            if (n >= '0' && n <= '9') {
                doub *= 10;
                doub += n - '0';
                n = scan();
            } else throw new InputMismatchException();
        }
        if (n == '.') {
            n = scan();
            double temp = 1;
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    temp /= 10;
                    doub += (n - '0') * temp;
                    n = scan();
                } else throw new InputMismatchException();
            }
        }
        return doub * neg;
    }

    public String scanString() throws IOException {
        StringBuilder sb = new StringBuilder();
        int n = scan();
        while (isWhiteSpace(n))
            n = scan();
        while (!isWhiteSpace(n)) {
            sb.append((char) n);
            n = scan();
        }
        return sb.toString();
    }

    private boolean isWhiteSpace(int n) {
        if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
            return true;
        return false;
    }
}

class Print {
    private final BufferedWriter bw;

    public Print() {
        this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
    }

    public void print(Object object) throws IOException {
        bw.append("" + object);
    }

    public void println(Object object) throws IOException {
        print(object);
        bw.append("\n");
    }

    public void close() throws IOException {
        bw.close();
    }
}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.*;

public class Code {
    static Scan sc = new Scan();
    static Print print = new Print();

    public static void main(String[] args)throws Exception
    {
        int n = sc.scanInt();
        var map = new HashMap<Integer,Integer>();
        int a[] = new int[n];
        for(int i=0;i<n;i++)
        {
            a[i] = sc.scanInt();
            map.put(a[i],i);
        }
        int m = sc.scanInt();
        int v=0,p=0;
        for(int i=1;i<=m;i++)
        {
            int b = sc.scanInt();
            v = v + map.get(b)+1;
            p = p + (n-map.get(b));
        }
        print.println(v+" "+p);
        print.close();
    }
}

class Scan {
    private byte[] buf = new byte[1024];
    private int index;
    private InputStream in;
    private int total;

    public Scan() {
        in = System.in;
    }

    public int scan() throws IOException {
        if (total < 0)
            throw new InputMismatchException();
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0)
                return -1;
        }
        return buf[index++];
    }

    public int scanInt() throws IOException {
        int integer = 0;
        int n = scan();
        while (isWhiteSpace(n))
            n = scan();
        int neg = 1;
        if (n == '-') {
            neg = -1;
            n = scan();
        }
        while (!isWhiteSpace(n)) {
            if (n >= '0' && n <= '9') {
                integer *= 10;
                integer += n - '0';
                n = scan();
            } else throw new InputMismatchException();
        }
        return neg * integer;
    }

    public long scanLong() throws IOException {
        long integer = 0;
        int n = scan();
        while (isWhiteSpace(n))
            n = scan();
        int neg = 1;
        if (n == '-') {
            neg = -1;
            n = scan();
        }
        while (!isWhiteSpace(n)) {
            if (n >= '0' && n <= '9') {
                integer *= 10;
                integer += (long) (n - '0');
                n = scan();
            } else throw new InputMismatchException();
        }
        return neg * integer;
    }

    public double scanDouble() throws IOException {
        double doub = 0;
        int n = scan();
        while (isWhiteSpace(n))
            n = scan();
        int neg = 1;
        if (n == '-') {
            neg = -1;
            n = scan();
        }
        while (!isWhiteSpace(n) && n != '.') {
            if (n >= '0' && n <= '9') {
                doub *= 10;
                doub += n - '0';
                n = scan();
            } else throw new InputMismatchException();
        }
        if (n == '.') {
            n = scan();
            double temp = 1;
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    temp /= 10;
                    doub += (n - '0') * temp;
                    n = scan();
                } else throw new InputMismatchException();
            }
        }
        return doub * neg;
    }

    public String scanString() throws IOException {
        StringBuilder sb = new StringBuilder();
        int n = scan();
        while (isWhiteSpace(n))
            n = scan();
        while (!isWhiteSpace(n)) {
            sb.append((char) n);
            n = scan();
        }
        return sb.toString();
    }

    private boolean isWhiteSpace(int n) {
        if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
            return true;
        return false;
    }
}

class Print {
    private final BufferedWriter bw;

    public Print() {
        this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
    }

    public void print(Object object) throws IOException {
        bw.append("" + object);
    }

    public void println(Object object) throws IOException {
        print(object);
        bw.append("\n");
    }

    public void close() throws IOException {
        bw.close();
    }
}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class EffeciveApproach {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastScanner in = new FastScanner(System.in);
		int n = in.nextInt();
		int a[] = new int[100000 + 1];
		for (int i = 0; i < n; i++) {
			a[in.nextInt()] = i;
		}
		int k = in.nextInt();
		long first = 0;
		long second = 0;
		for (int i = 0; i < k; i++) {
			int b = in.nextInt();
			first += a[b] + 1;
			second += n - a[b];
		}
		System.out.println(first + " " + second);
	}
	static class FastScanner{
		BufferedReader br ;
		StringTokenizer st ;
		FastScanner(InputStream stream) {
			try {
				br = new BufferedReader(new InputStreamReader(stream));
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
		String next() {
			while (st==null||!st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
	}

	}
}


import java.util.Scanner;
public class EffeciveApproach {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[100000 + 1];
		for (int i = 0; i < n; i++) {
			a[in.nextInt()] = i;
		}
		int k = in.nextInt();
		long first = 0;
		long second = 0;
		for (int i = 0; i < k; i++) {
			int b = in.nextInt();
			first += a[b] + 1;
			second += n - a[b];
		}
		System.out.println(first + " " + second);
	}

}


import java.util.Scanner;
public class EffeciveApproach {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		int k = in.nextInt();
		int first = 0;
		int second = 0;
		for (int i = 0; i < k; i++) {
			int b = in.nextInt();
			first += first_approach(a, b);
			second += Second_approach(a, b);
		}
		System.out.println(first + " " + second);
	}
	public static int first_approach(int a[], int b) {
		int ans = 0;
		for (int i = 0; i < a.length; i++) {
			ans++;
			if (a[i] == b) {
				return ans;
			}
		}
		return ans;

	}
	public static int Second_approach(int a[], int b) {
		int ans = 0;
		for (int i = a.length -1 ; i >= 0; i--) {
			ans++;
			if (a[i] == b) {
				return ans;
			}
		}

		return ans;
	}
}


import java.util.Scanner;
public class EffeciveApproach {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[100000 + 1];
		for (int i = 0; i < n; i++) {
			a[in.nextInt()] = i;
		}
		int k = in.nextInt();
		int first = 0;
		int second = 0;
		for (int i = 0; i < k; i++) {
			int b = in.nextInt();
			first += a[b] + 1;
			second += n - a[b];
		}
		System.out.println(first + " " + second);
	}

}


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		HashMap<Integer,Integer> map=new HashMap<>();
		for(int i=0;i<n;i++){
			int q=in.nextInt();
			map.put(q,i);
		}
		int sum1=0,sum2=0;
		int m=in.nextInt();
		for(int i=0;i<m;i++){
			int k=in.nextInt();
			int q=map.get(k);
			sum1+=q+1;
			sum2+=(n-q);

		}
		System.out.println(sum1+" "+sum2);
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=in.nextInt();
		}
		int m=in.nextInt();
		long sum1=0;
		long sum2=0;
		for(int j=0;j<m;j++){
			int k=in.nextInt();
			int i=0;
			for(i=0;i<n;i++){
				if(a[i]==k){
					break;
				}
			}
			sum1+=i+1;
			sum2+=n-i;
		//	System.out.println(jj+" "+q);
		}
		System.out.println(sum1+" "+sum2);
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		HashMap<Integer,Integer> map=new HashMap<>();
		for(int i=0;i<n;i++){
			int q=in.nextInt();
			map.put(q,i);
		}
		long sum1=0,sum2=0;
		int m=in.nextInt();
		for(int i=0;i<m;i++){
			int k=in.nextInt();
			int q=map.get(k);
			sum1+=q+1;
			sum2+=(n-q);

		}
		System.out.println(sum1+" "+sum2);
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner in=new Scanner(System.in);
		long n=in.nextLong();
HashMap<Long,Long> map=new HashMap<>();

		for(long i=0;i<n;i++){
			long k=in.nextLong();
			map.put(k,i);
		}
		long a=0,b=0;
		long q=in.nextInt();
		for(long z=0;z<q;z++){
		long m=in.nextLong();
           if(map.containsKey(m)){
           	long u=map.get(m);
           	u=u+1;
           	 a+=u-0;
           	 b+=(n-u)+1;

           }

		}
			System.out.println(a+" "+b);

	}
}


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
HashMap<Integer,Integer> map=new HashMap<>();

		for(int i=0;i<n;i++){
			int k=in.nextInt();
			map.put(k,i);
		}
		int a=0,b=0;
		int q=in.nextInt();
		for(int z=0;z<q;z++){
		int m=in.nextInt();
           if(map.containsKey(m)){
           	int u=map.get(m);
           	u=u+1;
           	 a+=u-0;
           	 b+=(n-u)+1;

           }

		}
			System.out.println(a+" "+b);

	}
}


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=in.nextInt();
		}
		int m=in.nextInt();
		long sum1=0;
		long sum2=0;
		for(int j=0;j<m;j++){
			int k=in.nextInt();
			int i=0;
			for(i=0;i<n;i++){
				if(a[i]==k){
					break;
				}
			}
			sum1+=n-i;
			sum2+=i+1;
		//	System.out.println(jj+" "+q);
		}
		System.out.println(sum1+" "+sum2);
	}
}


import java.util.*;

public class P30 {
    static int N= (int) 1e5+3;
    static int pos[]=new int[N];
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int i;
        for(i=0;i<n;i++)
        {
            int num=sc.nextInt();
            pos[num]=i+1;
        }
        int m=sc.nextInt();
        long vc=0;
        long  pc=0;
        for(i=0;i<m;i++)
        {
           int q=sc.nextInt();
           vc+=pos[q];
            pc+=n-pos[q]+1;
        }

        System.out.println(vc+"\t"+pc);

    }

}


import java.util.*;

public class P30 {
    static int N= (int) 1e5+3;
    static int pos[]=new int[N];
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int i;
        for(i=0;i<n;i++)
        {
            int num=sc.nextInt();
            pos[num]=i+1;
        }
        int m=sc.nextInt();
        int vc=0;
        int  pc=0;
        for(i=0;i<m;i++)
        {
           int q=sc.nextInt();
           vc+=pos[q];
            pc+=n-pos[q]+1;
        }

        System.out.println(vc+"\t"+pc);

    }

}


import java.util.*;

public class P30 {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        HashMap<Integer,Integer> hm=new HashMap<>();
        int n=sc.nextInt();
        int ar[]=new int[n];
        int i;
        for(i=0;i<n;i++)
        {
            ar[i]=sc.nextInt();
            hm.put(ar[i],i+1);
        }
        int m=sc.nextInt();
        int q[]=new int[m];
        for(i=0;i<m;i++)
        {
            q[i]=sc.nextInt();
        }
        int vc=0;
       int  pc=0;
        for(i=0;i<m;i++)
        {
           int val=q[i];
           int indx=hm.get(val);
           vc+=indx;
           pc+=n-indx+1;
        }
        System.out.println(vc+" "+pc);

    }

}


import java.util.*;

public class P30 {
public static int findS(int ar[],int ele)
{
   int st=0;
   int end=ar.length-1;
   while(st<=end)
   {
       int mid=st+(end-st)/2;
       if(ar[mid]==ele)
       {
           return  mid+1;
       }else if(ar[mid]>ele)
       {
           end=mid-1;
       }else
       {
           st=mid+1;
       }
   }
   return -1;
}

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int ar[]=new int[n];
        int i;
        for(i=0;i<n;i++)
        {
            ar[i]=sc.nextInt();
        }
        Arrays.sort(ar);
        int m=sc.nextInt();
        int q[]=new int[m];
        for(i=0;i<m;i++)
        {
            q[i]=sc.nextInt();
        }
        int vc=0;
       int  pc=0;
        for(i=0;i<m;i++)
        {
            int no=q[i];
           int val=findS(ar,no);
           vc+=val;
           pc+=(n-val)+1;

        }
        System.out.println(vc+" "+pc);

    }

}


import java.util.*;

public class P30 {
public static int findS(int ar[],int ele)
{
   int i;
   for(i=0;i<ar.length;i++)
   {
       if(ar[i]==ele)
       {
           return  i+1;
       }
   }
   return -1;
}

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int ar[]=new int[n];
        int i;
        for(i=0;i<n;i++)
        {
            ar[i]=sc.nextInt();
        }
        int m=sc.nextInt();
        int q[]=new int[m];
        for(i=0;i<m;i++)
        {
            q[i]=sc.nextInt();
        }
        int vc=0;
       int  pc=0;
        for(i=0;i<m;i++)
        {
            int no=q[i];
            int val=findS(ar,no);
            vc+=val;
            pc+=n-val+1;
        }
        System.out.println(vc+" "+pc);

    }

}


import java.util.*;

public class P30 {
    static int N=10^5+3;
static int pos[]=new int[N];
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        HashMap<Integer,Integer> hm=new HashMap<>();
        int n=sc.nextInt();

        int i;
        for(i=0;i<n;i++)
        {
            int num=sc.nextInt();
            pos[num]=i+1;
        }
        int m=sc.nextInt();
        int vc=0;
        int  pc=0;
        for(i=0;i<m;i++)
        {
           int q=sc.nextInt();
           vc+=pos[q];
            pc+=n-pos[q]+1;
        }

        System.out.println(vc+" "+pc);

    }

}


import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.util.*;

public class P30 {
    static int N=10^5+3;
static int pos[]=new int[N];
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        HashMap<Integer,Integer> hm=new HashMap<>();
        int n=sc.nextInt();

        int i;
        for(i=0;i<n;i++)
        {
            int num=sc.nextInt();
            pos[num]=i+1;
        }
        int m=sc.nextInt();
        int vc=0;
        int  pc=0;
        for(i=0;i<m;i++)
        {
           int q=sc.nextInt();
           vc+=pos[q];
            pc+=n-pos[q]+1;
        }

        System.out.println(vc+" "+pc);

    }

}


import java.util.*;

public class P30 {
    static int N= (int) 1e5+3;
    static int pos[]=new int[N];
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        HashMap<Integer,Integer> hm=new HashMap<>();
        int n=sc.nextInt();

        int i;
        for(i=0;i<n;i++)
        {
            int num=sc.nextInt();
            pos[num]=i+1;
        }
        int m=sc.nextInt();
        int vc=0;
        int  pc=0;
        for(i=0;i<m;i++)
        {
           int q=sc.nextInt();
           vc+=pos[q];
            pc+=n-pos[q]+1;
        }

        System.out.println(vc+" "+pc);

    }

}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	long int n;
	cin>>n;
	map<long long int,long int> pi;
	long int x;
	for(long int i=0;i<n;i++){
		cin>>x;
		pi[x]=i;
	}
	int m;
	cin>>m;
	long int p=0,q=0,v=0;
	for(long int i=0;i<m;i++){
		cin>>q;
		long int j=pi[q];
			v+=j+1;
			p+=n-j;
	}
	cout<<v<<" "<<p;
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	long int n;
	cin>>n;
	long int a[n];
	for(long int i=0;i<n;i++)cin>>a[i];
	int m;
	cin>>m;
	long int q,v=0,p=0;
	long int mid;
	if(n%2==0)mid=n/2;
	else mid=(n+1)/2;
	for(long int i=0;i<m;i++){
		cin>>q;
		for(long int j=0;j<mid;j++){
			if(a[j]==q){
				v+=j+1;
				p+=n-j;
			}
			else if(a[n-j-1]==q){
				v+=n-j;
				p+=j+1;
			}
		}
	}
	cout<<v<<" "<<p;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int m;
	cin>>m;
	int q,v=0,p=0;
	for(int i=0;i<m;i++){
		cin>>q;
		for(int j=0;j<n;j++){
			if(a[j]==q){
				v+=j+1;
				p+=n-j;
			}
		}
	}
	cout<<v<<" "<<p;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int m;
	cin>>m;
	int q,v=0,p=0;
	for(int i=0;i<m;i++){
		cin>>q;
		for(int j=0;j<n;j++){
			if(a[j]==q){
				v+=i+1;
				p+=n-i;
			}
		}
	}
	cout<<v<<" "<<p;
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int m;
	cin>>m;
	int q,v=0,p=0;
	for(int i=0;i<m;i++){
		cin>>q;
		for(int j=0;j<n/2;j++){
			if(a[j]==q){
				v+=j+1;
				p+=n-j;
			}
			else if(a[n-j-1]==q){
				v+=n-j;
				p+=j+1;
			}
		}
	}
	cout<<v<<" "<<p;
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	long int n;
	cin>>n;
	map<long long int,long int> pi;
	long int x;
	for(long int i=0;i<n;i++){
		cin>>x;
		pi[x]=i;
	}
	int m;
	cin>>m;
	long long int p=0,q=0,v=0;
	for(long int i=0;i<m;i++){
		cin>>q;
		long int j=pi[q];
			v+=j+1;
			p+=n-j;
	}
	cout<<v<<" "<<p;
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	long int n;
	cin>>n;
	map<long int,long int> pi;
	long int x;
	for(long int i=0;i<n;i++){
		cin>>x;
		pi[x]=i;
	}
	int m;
	cin>>m;
	long int p=0,q=0,v=0;
	for(long int i=0;i<m;i++){
		cin>>q;
		long int j=pi[q];
			v+=j+1;
			p+=n-j;
	}
	cout<<v<<" "<<p;
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int m;
	cin>>m;
	int q,v=0,p=0;
	int mid;
	if(n%2==0)mid=n/2;
	else mid=(n+1)/2;
	for(int i=0;i<m;i++){
		cin>>q;
		for(int j=0;j<mid;j++){
			if(a[j]==q){
				v+=j+1;
				p+=n-j;
			}
			else if(a[n-j-1]==q){
				v+=n-j;
				p+=j+1;
			}
		}
	}
	cout<<v<<" "<<p;
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int m;
	cin>>m;
	int q,v=0,p=0;
	for(int i=0;i<m;i++){
		cin>>q;
		for(int j=0;j<n;j++){
			if(a[j]==q){
				v+=j+1;
				p+=n-j;
			}
		}
	}
	cout<<v<<" "<<p;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
long int n,x;
cin>>n;
map<long int,long int> a;
map<long int,long int>::iterator it;
for(int i=0;i<n;i++)
    {
        cin>>x;
        a.insert(pair<long int,long int>(x,i+1));
    }
long int m,ca=0,cb=0,b;
cin>>m;
for(int i=0;i<m;i++)
  {
    cin>>b;
    it=a.find(b);
    x=(it->second);
    ca+=x;
    cb=cb+(n-x+1);
  }
  cout<<ca<<"  "<<cb;
  return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
long int n,x;
cin>>n;
map<long int,long int> a;
map<long int,long int>::iterator it;
for(int i=0;i<n;i++)
    {
        cin>>x;
        a.insert(pair<int,int>(x,i+1));
    }
long int m,ca=0,cb=0,b;
cin>>m;
for(int i=0;i<m;i++)
  {
    cin>>b;
    it=a.find(b);
    x=(it->second);
    ca+=x;
    cb=cb+(n-x+1);
  }
  cout<<ca<<"  "<<cb;
  return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
long int n,x;
cin>>n;
map<long int,long int> a;
map<long int,long int>::iterator it;
for(int i=0;i<n;i++)
    {
        cin>>x;
        a[x]=i+1;
    }
long int m,ca=0,cb=0,b;
cin>>m;
for(int i=0;i<m;i++)
  {
    cin>>b;
    x=a[b];
    ca+=x;
    cb=cb+(n-x+1);
  }
  cout<<ca<<"  "<<cb;
  return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
long int n,x;
cin>>n;
map<long int,long int> a;
map<long int,long int>::iterator it;
for(int i=0;i<n;i++)
    {
        cin>>x;
        a.insert(make_pair(x,i+1));
    }
long int m,ca=0,cb=0,b;
cin>>m;
for(int i=0;i<m;i++)
  {
    cin>>b;
    it=a.find(b);
    x=(it->second);
    ca+=x;
    cb=cb+(n-x+1);
  }
  cout<<ca<<"  "<<cb;
  return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,x;
cin>>n;
map<int,int> a;
map<int,int>::iterator it;
for(int i=0;i<n;i++)
    {
        cin>>x;
        a.insert(pair<int,int>(x,i+1));
    }
long int m,ca=0,cb=0,b;
cin>>m;
for(int i=0;i<m;i++)
  {
    cin>>b;
    it=a.find(b);
    x=(it->second);
    ca+=x;
    cb=cb+(n-x+1);
  }
  cout<<ca<<"  "<<cb;
  return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,x;
cin>>n;
map<int,int> a;
map<int,int>::iterator it;
for(int i=0;i<n;i++)
    {
        cin>>x;
        a.insert(pair<int,int>(x,i+1));
    }
int m,ca=0,cb=0,b;
cin>>m;
for(int i=0;i<m;i++)
  {
    cin>>b;
    it=a.find(b);
    x=(it->second);
    ca+=x;
    cb=cb+(n-x+1);
  }
  cout<<ca<<"  "<<cb;
  return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n,x;
cin>>n;
map<long long int,long long int> a;
map<long long int,long long int>::iterator it;
for(int i=0;i<n;i++)
    {
        cin>>x;
        a[x]=i+1;
    }
long long int m,ca=0,cb=0,b;
cin>>m;
for(int i=0;i<m;i++)
  {
    cin>>b;
    if(a[b]!=0)
    {
        x=a[b];
        ca=ca+x;
        cb=cb+(n-x+1);
    }

  }
  cout<<ca<<"  "<<cb;
  return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n,x;
cin>>n;
map<long long int,long long int> a;
map<long long int,long long int>::iterator it;
for(int i=0;i<n;i++)
    {
        cin>>x;
        a[x]=i+1;
    }
long long int m,ca=0,cb=0,b;
cin>>m;
for(int i=0;i<m;i++)
  {
    cin>>b;

        x=a[b];
        ca=ca+x;
        cb=cb+(n-x+1);

  }
  cout<<ca<<"  "<<cb;
  return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
long int n,x;
cin>>n;
map<long int,long int> a;
map<long int,long int>::iterator it;
for(int i=0;i<n;i++)
    {
        cin>>x;
        a[x]=i+1;
    }
long int m,ca=0,cb=0,b;
cin>>m;
for(int i=0;i<m;i++)
  {
    cin>>b;
    if(a[b]!=0)
    {
        x=a[b];
        ca+=x;
        cb=cb+(n-x+1);
    }

  }
  cout<<ca<<"  "<<cb;
  return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back

int a[100000],q[100000];

void Solve(){
    int V=0,P=0;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int m;
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> q[i];
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(a[j]==q[i]){
                V=V+(j+1);
                break;
            }
        }
        for(int j=n-1;j>=0;j--){
            if(a[j] == q[i]){
                P=P+(n-j);
                break;
            }
        }
    }
    cout << V << " " << P << endl;
}

int main(){
    fast;

    int t=1;
//    cin >> t;
    while(t--)
        Solve();
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back

int a[100000],q[100000],dp[100000];

void Solve(){
    int V=0,P=0;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int m;
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> q[i];
    }
    for(int i=0;i<m;i++){
        if(dp[i] == 0){
            for(int j=0;j<n;j++){
                if(a[j]==q[i]){
                    V=V+(j+1);
                    P=P+(n-j);
                    break;
                }
                if(a[n-1-j] == q[i]){
                    P=P+(j+1);
                    V=V+(n-j);
                    break;
                }
            }
        }
    }
    cout << V << " " << P << endl;
}

int main(){
    fast;

    int t=1;
//    cin >> t;
    while(t--)
        Solve();
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back

int a[100005],q[100005],dp[100005];

void Solve(){
    ll V=0,P=0;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        dp[a[i]] = i;
    }
    int m;
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> q[i];
        V+=(dp[q[i]] + 1);
        P+=(n-dp[q[i]]);
    }
    cout << V << " " << P << endl;
}

int main(){
    fast;

    int t=1;
//    cin >> t;
    while(t--)
        Solve();
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back

int a[100000],q[100000],dp[100000];

void Solve(){
    int V=0,P=0;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int m;
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> q[i];
    }
    for(int i=0;i<m;i++){
        int j;
        if(dp[q[i]] == 0){
            for(j=0;j<n;j++){
                if(a[j]==q[i]){
                    V=V+(j+1);
                    P=P+(n-j);
                    break;
                }
                else{
                    dp[a[j]] = j;
                }
            }
            dp[q[i]] = j;
        }
        else{
            V = V+(dp[q[i]] + 1);
            P = P+(n - dp[q[i]]);
        }
    }
    cout << V << " " << P << endl;
}

int main(){
    fast;

    int t=1;
//    cin >> t;
    while(t--)
        Solve();
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back

int a[100000],q[100000],dpi[100000],dpj[100000];

void Solve(){
    int V=0,P=0;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int m;
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> q[i];
    }
    for(int i=0;i<m;i++){
        if(dpi[i] == 0){
            for(int j=0;j<n;j++){
                if(a[j]==q[i]){
                    V=V+(j+1);
                    break;
                }
            }
            dpi[i] = V;
        }
        else{
            V = dpi[i];
        }
        if(dpj[i] == 0){
            for(int j=n-1;j>=0;j--){
                if(a[j] == q[i]){
                    P=P+(n-j);
                    break;
                }
            }
            dpj[i] = P;
        }
        else{
            P = dpj[i];
        }
    }
    cout << V << " " << P << endl;
}

int main(){
    fast;

    int t=1;
//    cin >> t;
    while(t--)
        Solve();
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back

int a[100000],q[100000];

void Solve(){
    int V=0,P=0;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int m;
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> q[i];
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(a[j]==q[i]){
                V=V+(j+1);
                P=P+(n-j);
                break;
            }
        }

    }
    cout << V << " " << P << endl;
}

int main(){
    fast;

    int t=1;
//    cin >> t;
    while(t--)
        Solve();
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back

int a[100005],q[100005],dp[100005];

void Solve(){
    ll V=0,P=0;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int m;
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> q[i];
    }
    for(int i=0;i<m;i++){
        int j;
        if(dp[q[i]] == 0){
            for(j=0;j<n;j++){
                if(a[j]==q[i]){
                    V=V+(j+1);
                    P=P+(n-j);
                    break;
                }
                else{
                    dp[a[j]] = j;
                }
            }
            dp[q[i]] = j;
        }
        else{
            V = V+(dp[q[i]] + 1);
            P = P+(n - dp[q[i]]);
        }
    }
    cout << V << " " << P << endl;
}

int main(){
    fast;

    int t=1;
//    cin >> t;
    while(t--)
        Solve();
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back

int a[100000],q[100000],dp[100000];

void Solve(){
    ll V=0,P=0;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int m;
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> q[i];
    }
    for(int i=0;i<m;i++){
        int j;
        if(dp[q[i]] == 0){
            for(j=0;j<n;j++){
                if(a[j]==q[i]){
                    V=V+(j+1);
                    P=P+(n-j);
                    break;
                }
                else{
                    dp[a[j]] = j;
                }
            }
            dp[q[i]] = j;
        }
        else{
            V = V+(dp[q[i]] + 1);
            P = P+(n - dp[q[i]]);
        }
    }
    cout << V << " " << P << endl;
}

int main(){
    fast;

    int t=1;
//    cin >> t;
    while(t--)
        Solve();
}


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

int main()
{
    int n,m,a,countv=0,countp=0;
    vector<int> v1;
    vector<int> v2;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v1.push_back(a);
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a;
        v2.push_back(a);
    }

    for(int i=0;i<v2.size();i++)
    {
        for(int j=0;j<v1.size();j++)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countv++;
            }
            else
            {
                countv++;
                break;
            }
        }

        for(int j=v1.size()-1;j>=0;j--)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countp++;
            }
            else
            {
                countp++;
                break;
            }
        }

    }

    cout<<countv<<" "<<countp<<endl;

    return 0;
}


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

int main()
{
    int n,m,a,countv=0,countp=0;
    vector<int> v1;
    vector<int> v2;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v1.push_back(a);
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a;
        v2.push_back(a);
    }

    for(int i=0;i<v2.size();i++)
    {
        for(int j=0;j<v1.size();j++)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countv++;
            }
            else
            {
                countv++;
                break;
            }
        }
    }

    for(int i=0;i<v2.size();i++)
    {
        for(int j=v1.size()-1;j>=0;j--)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countp++;
            }
            else
            {
                countp++;
                break;
            }
        }
    }

    cout<<countv<<" "<<countp<<endl;

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m,a,countv=0,countp=0;
    vector<int> v1;
    vector<int> v2;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v1.push_back(a);
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a;
        v2.push_back(a);
    }

    for(int i=0;i<v2.size();i++)
    {
        for(int j=0;j<v1.size();j++)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countv++;
            }
            else
            {
                countv++;
                break;
            }
        }

        for(int j=v1.size()-1;j>=0;j--)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countp++;
            }
            else
            {
                countp++;
                break;
            }
        }

    }

   /* for(int i=0;i<v2.size();i++)
    {
        for(int j=v1.size()-1;j>=0;j--)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countp++;
            }
            else
            {
                countp++;
                break;
            }
        }
    }
*/
    cout<<countv<<" "<<countp<<endl;

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n,m,a,countv=0,countp=0;
    vector<int> v1;
    vector<int> v2;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v1.push_back(a);
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a;
        v2.push_back(a);
    }

    for(int i=0;i<v2.size();i++)
    {
        for(int j=0;j<v1.size();j++)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countv++;
            }
            else
            {
                countv++;
                break;
            }
        }
    }

    for(int i=0;i<v2.size();i++)
    {
        for(int j=v1.size()-1;j>=0;j--)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countp++;
            }
            else
            {
                countp++;
                break;
            }
        }
    }

    cout<<countv<<" "<<countp<<endl;

    return 0;
}


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

int main()
{
    long long int n,m,a,countv=0,countp=0;
    vector<int> v1;
    vector<int> v2;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v1.push_back(a);
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a;
        v2.push_back(a);
    }

    for(int i=0;i<v2.size();i++)
    {
        for(int j=0;j<v1.size();j++)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countv++;
            }
            else
            {
                countv++;
                break;
            }
        }

        for(int j=v1.size()-1;j>=0;j--)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countp++;
            }
            else
            {
                countp++;
                break;
            }
        }

    }

   /* for(int i=0;i<v2.size();i++)
    {
        for(int j=v1.size()-1;j>=0;j--)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countp++;
            }
            else
            {
                countp++;
                break;
            }
        }
    }
*/
    cout<<countv<<" "<<countp<<endl;

    return 0;
}


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

int main()
{
    long long int n,a,m,countv=0,countp=0;
    cin>>n;
    long int arr[n];
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        arr[a]=i;
    }
    cin>>m;
    while(m--)
    {
        cin>>a;
        countv=countv+arr[a];
        countp = countp+(n-arr[a]+1);
    }
    cout<<countv<<" "<<countp<<endl;

    return 0;
}


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

int main()
{
    int n,a,m,countv=0,countp=0;
    cin>>n;
    int arr[n];
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        arr[a]=i;
    }
    cin>>m;
    while(m--)
    {
        cin>>a;
        countv=countv+arr[a];
        countp = countp+(n-arr[a]+1);
    }
    cout<<countv<<" "<<countp<<endl;

    return 0;
}


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

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

    long long int n,m,a,countv=0,countp=0;
    vector<int> v1;
    vector<int> v2;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v1.push_back(a);
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a;
        v2.push_back(a);
    }

    for(int i=0;i<v2.size();i++)
    {
        for(int j=0;j<v1.size();j++)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countv++;
            }
            else
            {
                countv++;
                break;
            }
        }

        for(int j=v1.size()-1;j>=0;j--)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countp++;
            }
            else
            {
                countp++;
                break;
            }
        }

    }

   /* for(int i=0;i<v2.size();i++)
    {
        for(int j=v1.size()-1;j>=0;j--)
        {
            if(v2[i]!=v1[j])
            {
                //cout<<v2[i]<<"!="<<v1[j]<<" ";
                countp++;
            }
            else
            {
                countp++;
                break;
            }
        }
    }
*/
    cout<<countv<<" "<<countp<<endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <vector>
#include <cctype>
#include <string>
#include <ctime>
#include <cmath>
#include <set>
#include <map>

typedef long double LD;
typedef long long LL;

using namespace std;

#define sz(A) (int)(A).size()
#define mp make_pair
#define pb push_back

const int N = int(1e5 + 3);

int n, m, pos[N];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int num;
		scanf("%d", &num);
		pos[num] = i + 1;
	}

	LL sum1 = 0, sum2 = 0;

	scanf("%d", &m);
	for (int i = 0; i < m; i++)	{
		int q;
		scanf("%d", &q);
		sum1 += pos[q];
		sum2 += n - pos[q] + 1;
	}

	printf("%I64d %I64d\n", sum1, sum2);

	return 0;
}


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

int main(){
    string s;
    cin>>s;
    int len=s.size();
    int ans=0;
    for(int i=0;i<len;i++){
        int l=0,r=0;
        for(int j=i;j<len;j++){
            if(s[j]=='(') l++,r++;
            else if(s[j]==')') r--,l--;
            else l--,r++;
            if(r<0) break;
            if(l<0) l=1;
            if(l==0) {
                     ans++;
                }
            else if(l<0){
                if(abs(l)%2==0)
                {
                     ans++;
                }

            }

        }
    }cout<<ans<<endl;
}


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

template<class T> bool amin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool amax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define REP(i, n) for(int i=0;i<n;i++)
#define RREP(i, n) for(int i=n;i>=0;i--)
#define VI vector<int>
#define VL vector<long>
#define PI pair<int, int>
#define VPI vector<PI>
#define VVI vector<VI>
#define VVL vector<VL>
#define VVPI vector<VPI>
#define TCASES int _t; cin>>_t; while(_t-- > 0)
const int32_t MOD = 1e9+7;
#define N 5010
#define MID 2905
#define ll long long
int dp[N][MID];
bool counted[N];

ll dfs(string &s, int i, int open){
	// cout << i+1 << ' ' << open << endl;
	if(i==s.size()){
		if(counted[i]) return 0;
		if(open == 0){
			counted[i]=true;
			return 1;
		}
		return 0;
	}

	if(open < 0) return 0;
	//if(dp[i][open] != -1) return dp[i][open];

	int n=s.size();
	ll ans=0;
	if(open==0 && !counted[i]) { counted[i]=true; ans++; }

	if(s[i]=='?'){
		ans += dfs(s, i+1, open+1);
		ans += dfs(s, i+1, open-1);
	}else if(s[i]=='('){
		ans += dfs(s, i+1, open+1);
	}else{
		ans += dfs(s, i+1, open-1);
	}

	return dp[i][open]=ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef LOCAL_TEST
	freopen("input.txt","r",stdin);
	#endif
	REP(i, N) memset(dp[i], -1, sizeof(dp[i]));

	string s; cin >> s;
	ll ans = 0;
	// ans += (dfs(s, 0, 0)-1);
	for(int i=0;i<(int)s.size()-1;i++){
	 	memset(counted, false, sizeof(counted));
		ans += dfs(s, i, 0)-1;
	}

	cout << ans << '\n';
}


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

template<class T> bool amin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool amax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define REP(i, n) for(int i=0;i<n;i++)
#define RREP(i, n) for(int i=n;i>=0;i--)
#define VI vector<int>
#define VL vector<long>
#define PI pair<int, int>
#define VPI vector<PI>
#define VVI vector<VI>
#define VVL vector<VL>
#define VVPI vector<VPI>
#define TCASES int _t; cin>>_t; while(_t-- > 0)
const int32_t MOD = 1e9+7;
#define N 5010
bool l[N][N], r[N][N];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef LOCAL_TEST
	freopen("input.txt","r",stdin);
	#endif
	string s; cin >> s;
	int n = s.size();
	int res = 0;
	for(int i=0;i<n-1;i++){
		int cnt = 0;
		bool ok = true;
		for(int j=i;j<n;j++){
			if(s[j] == ')') cnt--;
			else cnt ++;

			if(cnt < 0) ok = false;
			l[i][j] = ok;
		}
	}

	for(int i=1;i<n;i++){
		int cnt = 0;
		bool ok = true;
		for(int j=i;j>=0;j--){
			if(s[j] == '(') cnt --;
			else cnt ++;

			if(cnt < 0) ok = false;
			r[j][i] = ok;
		}
	}

	// REP(i, n){ REP(j, n) cout << l[i][j] << ' '; cout << '\n'; }
	// cout << '\n';
	// REP(i, n){ REP(j, n) cout << r[i][j] << ' '; cout << '\n'; }

	int ans = 0;
	for(int i = 0;i < n-1; ++i) for(int j = i+1;j < n; ++j){
		if(l[i][j] && r[i][j] && (j-i+1)%2==0) ++ans;
	}

	cout << ans << '\n';
}


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

template<class T> bool amin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool amax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define REP(i, n) for(int i=0;i<n;i++)
#define RREP(i, n) for(int i=n;i>=0;i--)
#define VI vector<int>
#define VL vector<long>
#define PI pair<int, int>
#define VPI vector<PI>
#define VVI vector<VI>
#define VVL vector<VL>
#define VVPI vector<VPI>
#define TCASES int _t; cin>>_t; while(_t-- > 0)
const int32_t MOD = 1e9+7;
#define N 5010
#define MID 2905
#define ll long long
// int dp[N][MID];
// // bool been_here[N][N];
// bool counted[N][N];
// bool visited[N][N][N];

// ll dfs(string &s,int start, int i, int open){
// 	if(start==0) cout << start+1 << ' ' << i+1 << ' ' << open << endl;
// 	if(i==s.size()){
// 		int ans = 0;
// 		if(open == 0 && !counted[start][i]) { counted[start][i]=true; ans++; }
// 		return ans;
// 	}

// 	if(open < 0) return 0;

// 	if(dp[i][open] != -1){
// 		cout << i << '~' << open << '=' << visited[start][i][open] << endl;
// 		if(!visited[start][i][open]){
// 			visited[start][i][open]=true;
// 			return dp[i][open];
// 		}else return 0;
// 	}

// 	int n=s.size();
// 	ll ans=0;
// 	if(open==0) {
// 		if(!counted[start][i]) ans++;
// 		counted[start][i]=true;
// 	}

// 	if(s[i]=='?'){
// 		ans += dfs(s, start, i+1, open+1);
// 		ans += dfs(s, start, i+1, open-1);
// 	}else if(s[i]=='('){
// 		ans += dfs(s, start, i+1, open+1);

// 	}else{
// 		ans += dfs(s, start, i+1, open-1);
// 	}

// 	visited[start][i][open]=true;
// 	return dp[i][open]=ans;
// }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef LOCAL_TEST
	freopen("input.txt","r",stdin);
	#endif

	// REP(i, N) memset(dp[i], -1, sizeof(dp[i]));

	string s; cin >> s;
	int n = s.size();
	ll ans = 0;
	vector<unordered_set<int>> ends(n), n_ends(n);
	int start=0;
	ends[0].insert(n);
	for(int i=n-1;i>=0;i--){
		if(s[i] == ')'){
			for(int j=1;j<n;j++) n_ends[j]=ends[j-1];
		}else if(s[i]=='('){
			for(int j=0;j<n-1;j++) n_ends[j]=ends[j+1];
		}else{
			for(int j=1;j<n;j++) n_ends[j]=ends[j-1];
			for(int j=0;j<n-1;j++) n_ends[j].insert(ends[j+1].begin(), ends[j+1].end());
		}

		swap(ends, n_ends);
		n_ends[0].clear();
		ans += ends[0].size();
		ends[0].insert(i);
	}

	cout << ans << '\n';
}


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

template<class T> bool amin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool amax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define REP(i, n) for(int i=0;i<n;i++)
#define RREP(i, n) for(int i=n;i>=0;i--)
#define VI vector<int>
#define VL vector<long>
#define PI pair<int, int>
#define VPI vector<PI>
#define VVI vector<VI>
#define VVL vector<VL>
#define VVPI vector<VPI>
#define TCASES int _t; cin>>_t; while(_t-- > 0)
const int32_t MOD = 1e9+7;
#define N 1000
bool l[N][N], r[N][N];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef LOCAL_TEST
	freopen("input.txt","r",stdin);
	#endif
	string s; cin >> s;
	int n = s.size();
	int res = 0;
	for(int i=0;i<n-1;i++){
		int cnt = 0;
		bool ok = true;
		for(int j=i;j<n;j++){
			if(s[j] == ')') cnt--;
			else cnt ++;

			if(cnt < 0) ok = false;
			l[i][j] = ok;
		}
	}

	for(int i=1;i<n;i++){
		int cnt = 0;
		bool ok = true;
		for(int j=i;j>=0;j--){
			if(s[j] == '(') cnt --;
			else cnt ++;

			if(cnt < 0) ok = false;
			r[j][i] = ok;
		}
	}

	// REP(i, n){ REP(j, n) cout << l[i][j] << ' '; cout << '\n'; }
	// cout << '\n';
	// REP(i, n){ REP(j, n) cout << r[i][j] << ' '; cout << '\n'; }

	int ans = 0;
	for(int i = 0;i < n-1; ++i) for(int j = i+1;j < n; ++j){
		if(l[i][j] && r[i][j] && (j-i+1)%2==0) ++ans;
	}

	cout << ans << '\n';
}


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

template<class T> bool amin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool amax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define REP(i, n) for(int i=0;i<n;i++)
#define RREP(i, n) for(int i=n;i>=0;i--)
#define VI vector<int>
#define VL vector<long>
#define PI pair<int, int>
#define VPI vector<PI>
#define VVI vector<VI>
#define VVL vector<VL>
#define VVPI vector<VPI>
#define TCASES int _t; cin>>_t; while(_t-- > 0)
const int32_t MOD = 1e9+7;
#define N 5010
#define MID 2905
#define ll long long
int dp[N][MID];
bool counted[N];

ll dfs(string &s, int i, int open){
	// cout << i+1 << ' ' << open << endl;
	if(i==s.size()){
		if(counted[i]) return 0;
		if(open == 0){
			counted[i]=true;
			return 1;
		}
		return 0;
	}

	if(open < 0) return 0;
	if(dp[i][open] != -1){
		return 0;
	}

	int n=s.size();
	ll ans=0;
	if(open==0 && !counted[i]) { counted[i]=true; ans++; }

	if(s[i]=='?'){
		ans += dfs(s, i+1, open+1);
		ans += dfs(s, i+1, open-1);
	}else if(s[i]=='('){
		ans += dfs(s, i+1, open+1);
	}else{
		ans += dfs(s, i+1, open-1);
	}

	return dp[i][open]=ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef LOCAL_TEST
	freopen("input.txt","r",stdin);
	#endif

	string s; cin >> s;
	ll ans = 0;
	// ans += (dfs(s, 0, 0)-1);
	for(int i=0;i<(int)s.size()-1;i++){
		REP(i, N) memset(dp[i], -1, sizeof(dp[i]));
	 	memset(counted, false, sizeof(counted));
		ans += dfs(s, i, 0)-1;
	}

	cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 5005;
char inp[maxn];
int main()
{
    scanf("%s",inp);
    int len=strlen(inp);
    int ans=0;
    for(int i=0;i<len;i++){
        int wen=0,le=0,ri=0;
        for(int j=i;j<len;j++){
            if(inp[j]=='(') le++;
            else if(inp[j]=='?')    wen++;
            else    ri++;

            if(ri>le+wen)   break;
            if(le>(len-i)/2||ri>(len-i)/2)  break;
            if((j-i+1)%2==0&&ri+wen>=le)    ans++;
   //         printf("i: %d, j: %d, wen: %d, le: %d, ri: %d, ans: %d\n",i,j,wen,le,ri,ans);
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 5005;
char inp[maxn];
int main()
{
    scanf("%s",inp);
    int len=strlen(inp);
    int ans=0;
    for(int i=0;i<len;i++){
        int wen=0,le=0;
        for(int j=i;j<len;j++){
            if(inp[j]=='('){
                le++;
                continue;
            }
            else if(inp[j]=='?'){
                if(le==0)   le++;
                else    wen++;
            }
            else{
                if(le==0)   wen--;
                else    le--;
            }
            if(wen<0)    break;
            if(wen>=le&&(wen-le)%2==0){
                ans++;
            }
      //      printf("i: %d, j: %d, wen: %d, le: %d, ans: %d\n",i,j,wen,le,ans);
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 5005;
char inp[maxn];
int main()
{
    scanf("%s",inp);
    int len=strlen(inp);
    int ans=0;
    for(int i=0;i<len;i++){
        int wen=0,le=0;
        for(int j=i;j<len;j++){
            if(inp[j]=='('){
                le++;
            }
            else if(inp[j]=='?'){
                if(le==0)   le++;
                else    wen++;
            }
            else{
                if(le==0)   wen--;
                else    le--;
            }
            if(wen<0)    break;
            if(le==wen){
                ans++;
            }
//            printf("i: %d, j: %d, wen: %d, le: %d, ri: %d, ans: %d\n",i,j,wen,le,ri,ans);
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 5003;
char inp[maxn];
bool can[maxn][maxn];
int main(){
    scanf("%s",inp);
    int len=strlen(inp);
    int ans=0;
    for(int i=0;i+1<len;i++){
        if((inp[i]=='('||inp[i]=='?')&&(inp[i+1]==')'||inp[i+1]=='?'))  can[i][i+1]=true,ans++;
    }
    for(int i=4;i<=len;i+=2){
        for(int j=0;j+i-1<len;j++){
            if(can[j][j+i/2-1]&&can[j+i/2][j+i-1])  can[j][j+i-1]=true,ans++;
            else{
//                bool can=true;
                for(int k=1;k<=i/2;k++){
                    if(inp[j+k-1]==')'||inp[j+i-k]=='(')    break;
                    if(j+k<j+i-k-1&&can[j+k][j+i-k-1]){
                        can[j][j+i-1]=true,ans++;
                        break;
                    }
                    if(k==i/2)    can[j][j+i-1]=true,ans++;
                }
            }
        }
    }
    printf("%d\n",ans);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 5005;
char inp[maxn];
int main()
{
    scanf("%s",inp);
    int len=strlen(inp);
    int ans=0;
    for(int i=0;i<len;i++){
        int wen=0,le=0;
        for(int j=i;j<len;j++){
            if(inp[j]=='('){
                le++;
            }
            else if(inp[j]=='?'){
                if(le==0)   le++;
                else    wen++;
            }
            else{
                if(le==0)   wen--;
                else    le--;
            }
            if(wen<0)    break;
            if(le==wen){
                ans++;
                le=0,wen=0;
            }
//            printf("i: %d, j: %d, wen: %d, le: %d, ri: %d, ans: %d\n",i,j,wen,le,ri,ans);
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 5005;
char inp[maxn];
int main()
{
    scanf("%s",inp);
    int len=strlen(inp);
    int ans=0;
    for(int i=0;i<len;i++){
        int wen=0,le=0;
        for(int j=i;j<len;j++){
            if(inp[j]=='('){
                le++;
            }
            else if(inp[j]=='?'){
                if(le==0)   le++;
                else    wen++;
            }
            else{
                if(le==0)   wen--;
                else    le--;
            }
            if(wen<0)    break;
            if(wen>=le&&(wen-le)%2==0){
                ans++;
            }
//            printf("i: %d, j: %d, wen: %d, le: %d, ri: %d, ans: %d\n",i,j,wen,le,ri,ans);
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 5003;
char inp[maxn];
bool can[maxn][maxn];
int main(){
    scanf("%s",inp);
    int len=strlen(inp);
    int ans=0;
    for(int i=0;i+1<len;i++){
        if((inp[i]=='('||inp[i]=='?')&&(inp[i+1]==')'||inp[i+1]=='?'))  can[i][i+1]=true,ans++;
    }
    for(int i=4;i<=len;i+=2){
        for(int j=0;j+i-1<len;j++){
            bool ends=false;
            for(int k=2;k<i;k+=2){
                if(can[j][j+k-1]&&can[j+k][j+i-1]){
                    ends=true;
                    can[j][j+i-1]=true,ans++;
                    break;
                }
            }
            if(ends)    continue;
            for(int k=1;k<=i/2;k++){
                if(inp[j+k-1]==')'||inp[j+i-k]=='(')    break;
                if(j+k<j+i-k-1&&can[j+k][j+i-k-1]){
                    can[j][j+i-1]=true,ans++;
                    break;
                }
                if(k==i/2)    can[j][j+i-1]=true,ans++;
            }
//            if(can[j][j+i/2-1]&&can[j+i/2][j+i-1])  can[j][j+i-1]=true,ans++;
//            else{
//                bool can=true;
//                for(int k=1;k<=i/2;k++){
//                    if(inp[j+k-1]==')'||inp[j+i-k]=='(')    break;
//                    if(j+k<j+i-k-1&&can[j+k][j+i-k-1]){
//                        can[j][j+i-1]=true,ans++;
//                        break;
//                    }
//                    if(k==i/2)    can[j][j+i-1]=true,ans++;
//                }
//            }
        }
    }
    printf("%d\n",ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 5003;
char inp[maxn];
bool can[maxn][maxn];
int main(){
    scanf("%s",inp);
    int len=strlen(inp);
    int ans=0;
    for(int i=2;i<=len;i+=2){
        for(int j=0;j+i-1<len;j++){
            int wen=0,le=0,ri=0;
            bool can=true;
            for(int k=j;k<j+i;k++){
                if(inp[k]==')') ri++;
                else if(inp[k]=='(')    le++;
                else    wen++;
                if(wen+le>=i/2) break;
                if(ri>wen+le){
                    can=false;
                    break;
                }
//                if(wen>i/2){
//                    ans++;
//                    break;
//                }
            }
            if(can){
                wen=0,le=0,ri=0;
                for(int k=j+i-1;k>=j;k--){
                    if(inp[k]==')') ri++;
                    else if(inp[k]=='(')    le++;
                    else    wen++;
                    if(wen+ri>=i/2) break;
                    if(le>wen+ri){
                        can=false;
                        break;
                    }
                }
            }
            if(can) ans++;
        }
    }
    //            int k;
//            for(k=j;k<j+i/2;k++){
//                if(inp[k]==')'){
//                    can=false;
//                    break;
//                }
//                if(inp[k]=='?') wen++;
//            }
//            if(!can)    continue;
//            for(k=j+len-1;k>=j+i/2;k--){
//                if(inp[k]=='('){
//                    can=false;
//                    break;
//                }
//                if(inp[k]=='?') wen++;
//                if(wen>i/2) break;
//            }
//            if(can) ans++;
//    for(int i=0;i+1<len;i++){
//        if((inp[i]=='('||inp[i]=='?')&&(inp[i+1]==')'||inp[i+1]=='?'))  can[i][i+1]=true,ans++;
//        if(can[i][i+1]){
//            for(int j=1;i-j>=0&&i+1+j<len;j++){
//                if((inp[i-j]=='('||inp[i-j]=='?')&&(inp[i+j+1]==')'||inp[i+j+1]=='?'))  can[i-j][i+j+1]=true,ans++;
//                else    break;
//            }
//        }
//    }
//    for(int i=4;i<=len;i+=2){
//        for(int j=0;j+i-1<len;j++){
//            if(can[j][j+i-1])   continue;
////            bool ends=false;
//            for(int k=2;k<i;k+=2){
//                if(can[j][j+k-1]&&can[j+k][j+i-1]){
////                    ends=true;
//                    can[j][j+i-1]=true,ans++;
//                    break;
//                }
//            }
//            if(can[j][j+i-1]){
//                for(int k=1;j-k>=0&&j+i-1+k<len;k++){
//                    if((inp[j-k]=='('||inp[j-k]=='?')&&(inp[j+i-1+k]==')'||inp[j+i-1+k]=='?'))  can[j-k][j+i-1+k]=true,ans++;
//                    else    break;
//                }
//            }
//            if(ends)    continue;
//            for(int k=1;k<=i/2;k++){
//                if(inp[j+k-1]==')'||inp[j+i-k]=='(')    break;
//                if(j+k<j+i-k-1&&can[j+k][j+i-k-1]){
//                    can[j][j+i-1]=true,ans++;
//                    break;
//                }
//                if(k==i/2)    can[j][j+i-1]=true,ans++;
//            }
//            if(can[j][j+i/2-1]&&can[j+i/2][j+i-1])  can[j][j+i-1]=true,ans++;
//            else{
//                bool can=true;
//                for(int k=1;k<=i/2;k++){
//                    if(inp[j+k-1]==')'||inp[j+i-k]=='(')    break;
//                    if(j+k<j+i-k-1&&can[j+k][j+i-k-1]){
//                        can[j][j+i-1]=true,ans++;
//                        break;
//                    }
//                    if(k==i/2)    can[j][j+i-1]=true,ans++;
//                }
//            }
//        }
//    }
    printf("%d\n",ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 5003;
char inp[maxn];
bool can[maxn][maxn];
int main(){
    scanf("%s",inp);
    int len=strlen(inp);
    int ans=0;
    for(int i=2;i<=len;i+=2){
        for(int j=0;j+i-1<len;j++){
            int wen=0,le=0,ri=0;
            bool can=true;
            for(int k=j;k<j+i/2;k++){
                if(inp[k]==')') ri++;
                else if(inp[k]=='(')    le++;
                else    wen++;
                if(ri>wen+le){
                    can=false;
                    break;
                }
//                if(wen>i/2){
//                    ans++;
//                    break;
//                }
            }
            if(can){
                int tri=0,tle=0,twen=0;
                for(int k=j+i-1;k>=j+i/2;k--){
                    if(inp[k]==')') ri++,tri++;
                    else if(inp[k]=='(')    le++,tle++;
                    else    wen++,twen++;
                    if(tle>twen+tri||le>i/2||ri>i/2){
                        can=false;
                        break;
                    }
                }
            }
            if(can) ans++;
        }
    }
    printf("%d\n",ans);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 5005;
char inp[maxn];
int main()
{
    scanf("%s",inp);
    int len=strlen(inp);
    int ans=0;
    for(int i=0;i<len;i++){
        if(inp[i]==')') continue;
        int nowmin=0,nowmax=0;
        for(int j=i,l=1;j<len;j++,l++){
            if(inp[j]=='(') nowmax++,nowmin++;
            else if(inp[j]=='?')    nowmax++,nowmin--;
            else    nowmax--,nowmin--;
            if(nowmax<0)    break;
            nowmin=max(0,nowmin);
            if(l%2==0&&nowmin<=0&&nowmax>=0)    ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 5005;
char inp[maxn];
int main()
{
    scanf("%s",inp);
    int len=strlen(inp);
    int ans=0;
    for(int i=0;i<len;i++){
        int wen=0,le=0,ri=0;
        for(int j=i;j<len;j++){
            if(inp[j]=='('){
                le++;
                continue;
            }
            else if(inp[j]=='?')    wen++;
            else    ri++;

            if(ri>le+wen)   break;
            if(le>(len-i)/2||ri>(len-i)/2)  break;
            if((j-i+1)%2==0&&ri+wen>=le)    ans++;
    //        printf("i: %d, j: %d, wen: %d, le: %d, ri: %d, ans: %d\n",i,j,wen,le,ri,ans);
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn = 5005;
char inp[maxn];
int main()
{
    scanf("%s",inp);
    int len=strlen(inp);
    int ans=0;
    for(int i=0;i<len;i++){
        if(inp[i]==')') continue;
        int nowmin=0,nowmax=0;
        for(int j=i,l=1;j<len;j++,l++){
            if(inp[j]=='(') nowmax++,nowmin++;
            else if(inp[j]=='?')    nowmax++,nowmin--;
            else    nowmax--,nowmin--;
            if(nowmax<0)    break;
            nowmin=max(0,nowmin);
            if(l%2==0&&nowmin==0&&nowmax>=0)    ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


/*********************************
Date: Mon Jan 29 23:24:45 CST 2018
Author: ycl
*********************************/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <sstream>
using namespace std;
#define CL(a) memset(a,0,sizeof(a))
#define Cl(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define INF 0x7fffffff
#define LL long long
const int MOD = 1e9 + 7;
const int maxn = 5e3 + 10;
char s[maxn];
bool dp[maxn][maxn];
int ml[maxn];
int mr[maxn];
int main()
{
	CL(dp);
	scanf("%s",s);
	int len = strlen(s);
	for (int i=0;i<len;++i){
		dp[i+1][i]=1;
		ml[i]=mr[i]=i;
	}
	for (int i=2;i<=len;i+=2){
		for (int l=0;i+l-1<len;++l){
			int r = l+i-1;
			if (dp[l+1][r-1] && (s[l]=='(' || s[l]=='?') && (s[r]==')' || s[r]=='?')){
				dp[l][r]=1;
				ml[l]=max(ml[i],r);
				mr[r]=min(mr[r],l);
			}
			else if (dp[l][r]==0){
				for (int j=mr[r]-1;j<ml[l]+1;++j){
					if (dp[l][j] && dp[j+1][r]){
						dp[l][r]=1;
						mr[r]=l;
						ml[l]=r;
						break;
					}
				}
			}
			else
				dp[l][r]=0;
		}
	}
	int ans=0;
	for (int i=0;i<len;++i)
		for (int j=i+1;j<len;++j)
			if (dp[i][j]) ++ans;
	cout<<ans<<endl;
	return 0;
}


/*********************************
Date: Mon Jan 29 23:24:45 CST 2018
Author: ycl
*********************************/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <sstream>
using namespace std;
#define CL(a) memset(a,0,sizeof(a))
#define Cl(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define INF 0x7fffffff
#define LL long long
const int MOD = 1e9 + 7;
const int maxn = 5e3 + 10;
char s[maxn];
bool dp[maxn][maxn];
int ml[maxn];
int mr[maxn];
int main()
{
	CL(dp);
	scanf("%s",s);
	int len = strlen(s);
	for (int i=0;i<len;++i){
		dp[i+1][i]=1;
		ml[i]=mr[i]=i;
	}
	for (int i=2;i<=len;i+=2){
		for (int l=0;i+l-1<len;++l){
			int r = l+i-1;
			if (dp[l+1][r-1] && (s[l]=='(' || s[l]=='?') && (s[r]==')' || s[r]=='?')){
				dp[l][r]=1;
				ml[l]=max(ml[i],r);
				mr[r]=min(mr[r],l);
			}
			else if (dp[l][r]==0){
				for (int j=mr[r]-1;j<ml[l]+1;++j){
					if (dp[l][j] && dp[j+1][r]){
						dp[l][r]=1;
						ml[l]=max(ml[i],r);
						mr[r]=min(mr[r],l);
					}
				}
			}
			else
				dp[l][r]=0;
		}
	}
	int ans=0;
	for (int i=0;i<len;++i)
		for (int j=i+1;j<len;++j)
			if (dp[i][j]) ++ans;
	cout<<ans<<endl;
	return 0;
}


/*********************************
Date: Mon Jan 29 23:24:45 CST 2018
Author: ycl
*********************************/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <sstream>
using namespace std;
#define CL(a) memset(a,0,sizeof(a))
#define Cl(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define INF 0x7fffffff
#define LL long long
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 100;
char s[maxn];
int dp[5010][5010];
int main()
{
	CL(dp);
	scanf("%s",s);
	int len = strlen(s);
	for (int i=0;i<len;++i)
		dp[i+1][i]=1;
	for (int i=2;i<=len;++i){
		for (int l=0;i+l-1<len;++l){
			int r = l+i-1;
			if (dp[l+1][r-1] && (s[l]=='(' || s[l]=='?') && (s[r]==')' || s[r]=='?'))
				dp[l][r]=1;
			else
				dp[l][r]=0;
			if (dp[l][r]==0){
				for (int j=l;j<r;++j){
					if (dp[l][j] && dp[j+1][r]){
						dp[l][r]=1;
						break;
					}
				}
			}
		}
	}
	int ans=0;
	for (int i=0;i<len;++i)
		for (int j=i+1;j<len;++j)
			if (dp[i][j]) ++ans;
	cout<<ans<<endl;
	return 0;
}


/*********************************
Date: Mon Jan 29 23:24:45 CST 2018
Author: ycl
*********************************/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <sstream>
using namespace std;
#define CL(a) memset(a,0,sizeof(a))
#define Cl(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define INF 0x7fffffff
#define LL long long
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 100;
char s[maxn];
int dp[5010][5010];
int ml[5010];
int mr[5010];
int main()
{
	CL(dp);
	scanf("%s",s);
	int len = strlen(s);
	for (int i=0;i<len;++i){
		dp[i+1][i]=1;
		ml[i]=mr[i]=i;
	}
	for (int i=2;i<=len;i+=2){
		for (int l=0;i+l-1<len;++l){
			int r = l+i-1;
			if (dp[l+1][r-1] && (s[l]=='(' || s[l]=='?') && (s[r]==')' || s[r]=='?')){
				dp[l][r]=1;
				ml[l]=max(ml[i],r);
				mr[r]=min(mr[r],l);
			}
			else
				dp[l][r]=0;
			if (dp[l][r]==0){
				for (int j=mr[r]-1;j<ml[l]+1;++j){
					if (dp[l][j] && dp[j+1][r]){
						dp[l][r]=1;
						mr[r]=l;
						ml[l]=r;
						break;
					}
				}
			}
		}
	}
	int ans=0;
	for (int i=0;i<len;++i)
		for (int j=i+1;j<len;++j)
			if (dp[i][j]) ++ans;
	cout<<ans<<endl;
	return 0;
}


/*********************************
Date: Mon Jan 29 23:24:45 CST 2018
Author: ycl
*********************************/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <sstream>
using namespace std;
#define CL(a) memset(a,0,sizeof(a))
#define Cl(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define INF 0x7fffffff
#define LL long long
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 100;
char s[maxn];
int dp[5010][5010];
int ml[5010];
int mr[5010];
int main()
{
	CL(dp);
	Cl(mr,0x7f);
	scanf("%s",s);
	int len = strlen(s);
	for (int i=0;i<len;++i)
		dp[i+1][i]=1;
	for (int i=2;i<=len;i+=2){
		for (int l=0;i+l-1<len;++l){
			int r = l+i-1;
			if (dp[l+1][r-1] && (s[l]=='(' || s[l]=='?') && (s[r]==')' || s[r]=='?')){
				dp[l][r]=1;
				ml[l]=max(ml[i],r);
				mr[r]=min(mr[r],l);
			}
			else
				dp[l][r]=0;
			if (dp[l][r]==0){
				for (int j=mr[r]-1;j>=0 && j<ml[l]+1;++j){
					if (dp[l][j] && dp[j+1][r]){
						dp[l][r]=1;
						break;
					}
				}
			}
		}
	}
	int ans=0;
	for (int i=0;i<len;++i)
		for (int j=i+1;j<len;++j)
			if (dp[i][j]) ++ans;
	cout<<ans<<endl;
	return 0;
}


/*********************************
Date: Mon Jan 29 23:24:45 CST 2018
Author: ycl
*********************************/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <sstream>
using namespace std;
#define CL(a) memset(a,0,sizeof(a))
#define Cl(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define INF 0x7fffffff
#define LL long long
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 100;
char s[maxn];
int dp[5010][5010];
int ml[5010];
int mr[5010];
int main()
{
	CL(dp);
	scanf("%s",s);
	int len = strlen(s);
	for (int i=0;i<len;++i)
		dp[i+1][i]=1;
	for (int i=0;i<len;++i)
		mr[i]=ml[i]=i;
	for (int i=2;i<=len;i+=2){
		for (int l=0;i+l-1<len;++l){
			int r = l+i-1;
			if (dp[l+1][r-1] && (s[l]=='(' || s[l]=='?') && (s[r]==')' || s[r]=='?')){
				dp[l][r]=1;
				ml[l]=max(ml[i],r);
				mr[r]=min(mr[r],l);
			}
			else
				dp[l][r]=0;
			if (dp[l][r]==0 && i>2){
				if (ml[l] != l && mr[r]!=r && mr[r]+1>= ml[l])
					dp[l][r]=1;
			}
		}
	}
	int ans=0;
	for (int i=0;i<len;++i)
		for (int j=i+1;j<len;++j)
			if (dp[i][j]) ++ans;
	cout<<ans<<endl;
	return 0;
}


/*********************************
Date: Mon Jan 29 23:24:45 CST 2018
Author: ycl
*********************************/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <sstream>
using namespace std;
#define CL(a) memset(a,0,sizeof(a))
#define Cl(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define INF 0x7fffffff
#define LL long long
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 100;
char s[maxn];
int dp[5010][5010];
int ml[5010];
int mr[5010];
int main()
{
	CL(dp);
	scanf("%s",s);
	int len = strlen(s);
	for (int i=0;i<len;++i)
		dp[i+1][i]=1;
	for (int i=0;i<len;++i)
		mr[i]=ml[i]=i;
	for (int i=2;i<=len;i+=2){
		for (int l=0;i+l-1<len;++l){
			int r = l+i-1;
			if (dp[l+1][r-1] && (s[l]=='(' || s[l]=='?') && (s[r]==')' || s[r]=='?')){
				dp[l][r]=1;
				ml[l]=max(ml[i],r);
				mr[r]=min(mr[r],l);
			}
			else
				dp[l][r]=0;
			if (dp[l][r]==0){
				int ll,rr;
				ll = mr[r]==r? l:mr[r]-1;
				rr = ml[l]==l? r:ml[l]+1;
				for (int j=ll;j<rr;++j){
					if (dp[l][j] && dp[j+1][r]){
						dp[l][r]=1;
						break;
					}
				}
			}
		}
	}
	int ans=0;
	for (int i=0;i<len;++i)
		for (int j=i+1;j<len;++j)
			if (dp[i][j]) ++ans;
	cout<<ans<<endl;
	return 0;
}


#pragma comment(linker, "/STACK:66777216")
#define _CRT_SECURE_NO_DEPRECATE
#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <utility>
#include <stack>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define E 2.71828182846

const int magicconst = 1e7;

const long long mod = 1e9 + 7;

const int MAXN = 1e3 + 1;

long long gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);
	while (b != 0)
	{
		a %= b;
		swap(a, b);
	}
	return a + b;
}

string s;

long long DFS(int layout, unordered_set<int>& s1)
{
	if (layout >= s.size())
		return 0;
	unordered_set<int> s2;
	for (auto i : s1)
	{
		if (s[layout] == '(' || s[layout] == '?')
			s2.insert(i + 1);
		if ((s[layout] == ')' || s[layout] == '?') && i != 0)
			s2.insert(i - 1);
	}
	return (s2.find(0) != s2.end() ? 1 : 0) + DFS(layout + 1, s2);
}

void Solve()
{
	cin >> s;
	long long answer = 0;
	unordered_set<int>s1;
	s1.insert(1);
	for (int i = 0; i < s.size() - 1; i++)
	{
		if (s[i] == '?' || s[i] == '(')
		{
			answer += DFS(i + 1, s1);
		}
	}
	cout << answer << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	Solve();
}


#pragma comment(linker, "/STACK:66777216")
#define _CRT_SECURE_NO_DEPRECATE
#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <utility>
#include <stack>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define E 2.71828182846

const int magicconst = 1e7;

const long long mod = 1e9 + 7;

const int MAXN = 1e3 + 1;

long long gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);
	while (b != 0)
	{
		a %= b;
		swap(a, b);
	}
	return a + b;
}

vector<vector<int>>a;
vector<vector<int>>b;

void Solve()
{
	string s;
	cin >> s;
	a.resize(s.size(), vector<int>(s.size() + 1));
	b.resize(s.size(), vector<int>(s.size() + 1));
	int k1 = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '(' || s[i] == '?')
		{
			a[i][1] = 1;
			if (i > 0)
			{
				for (int j = 1; j < a[i].size(); j++)
				{
					a[i][j] += a[i - 1][j - 1];
					if (s[i] == '?')
						b[i][j] = a[i - 1][j - 1];
					else
						b[i][j] = b[i - 1][j - 1];
				}
			}
		}
		if (s[i] == ')' || s[i] == '?')
		{
			if (i > 0)
			{
				for (int j = 1; j < a[i].size(); j++)
				{
					a[i][j - 1] += a[i - 1][j];
					if (s[i] != '?' && j - 1 > 1)
					{
						b[i][j - 1] = b[i - 1][j];
					}
				}
			}
		}
		if (s[i] == '?')
		{
			k1++;
			if (k1 > 1)
			{
				for (int j = 1; j < a[i].size() - 1; j++)
				{
					if (b[i - 1][j + 1] > 0)
						a[i][j] -= b[i - 1][j + 1];
				}
			}
		}
		/*for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << " ";
		cout << "  k1 : "<<k1 <<endl;*/
	}
	/*
	for (int i = 0; i < b.size(); i++)
	{
		for (int j = 0; j < b[i].size(); j++)
		{
			cout << b[i][j] << " ";
		}
		cout << endl;
	}*/
	long long answer = 0;
	for (int i = 0; i < s.size(); i++)
		answer += a[i][0];
	cout << answer << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	Solve();
}


#pragma comment(linker, "/STACK:66777216")
#define _CRT_SECURE_NO_DEPRECATE
#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <utility>
#include <stack>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define E 2.71828182846

const int magicconst = 1e7;

const long long mod = 1e9 + 7;

const int MAXN = 1e3 + 1;

long long gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);
	while (b != 0)
	{
		a %= b;
		swap(a, b);
	}
	return a + b;
}

string s;

long long DFS(int layout, unordered_set<int>& s1)
{
	if (layout >= s.size())
		return 0;
	unordered_set<int> s2;
	for (auto i : s1)
	{
		if (i > s.size() - layout + 1)
			continue;
		if (s[layout] == '(' || s[layout] == '?')
			s2.insert(i + 1);
		if ((s[layout] == ')' || s[layout] == '?') && i != 0)
			s2.insert(i - 1);
	}
	return (s2.find(0) != s2.end() ? 1 : 0) + DFS(layout + 1, s2);
}

void Solve()
{
	cin >> s;
	long long answer = 0;
	unordered_set<int>s1;
	s1.insert(1);
	for (int i = 0; i < s.size() - 1; i++)
	{
		if (s[i] == '?' || s[i] == '(')
		{
			answer += DFS(i + 1, s1);
		}
	}
	cout << answer << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	Solve();
}


#pragma comment(linker, "/STACK:66777216")
#define _CRT_SECURE_NO_DEPRECATE
#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <utility>
#include <stack>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define E 2.71828182846

const int magicconst = 1e7;

const long long mod = 1e9 + 7;

const int MAXN = 1e3 + 1;

long long gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);
	while (b != 0)
	{
		a %= b;
		swap(a, b);
	}
	return a + b;
}

vector<vector<long long>>a;
vector<vector<long long>>b;

void Solve()
{
	string s;
	cin >> s;
	a.resize(s.size(), vector<long long>(s.size() + 1));
	b.resize(s.size(), vector<long long>(s.size() + 1));
	int k1 = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '(' || s[i] == '?')
		{
			a[i][1] = 1;
			if (i > 0)
			{
				for (int j = 1; j < a[i].size(); j++)
				{
					a[i][j] += a[i - 1][j - 1];
					if (s[i] == '?')
						b[i][j] = a[i - 1][j - 1];
					else
						b[i][j] = b[i - 1][j - 1];
				}
			}
		}
		if (s[i] == ')' || s[i] == '?')
		{
			if (i > 0)
			{
				for (int j = 1; j < a[i].size(); j++)
				{
					a[i][j - 1] += a[i - 1][j];
					if (s[i] != '?')
					{
						b[i][j - 1] = b[i - 1][j];
					}
				}
			}
		}
		if (s[i] == '?')
		{
			k1++;
			if (k1 > 1)
			{
				for (int j = 1; j < a[i].size() - 1; j++)
				{
					if (a[i - 1][j - 1] > 0 && a[i - 1][j + 1] > 0)
						a[i][j] -= b[i - 1][j + 1];
				}
			}
		}
		/*for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << " ";
		cout << "  k1 : "<<k1 <<endl;*/
	}
	/*
	for (int i = 0; i < b.size(); i++)
	{
		for (int j = 0; j < b[i].size(); j++)
		{
			cout << b[i][j] << " ";
		}
		cout << endl;
	}*/
	long long answer = 0;
	for (int i = 0; i < s.size(); i++)
		answer += a[i][0];
	cout << answer << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	Solve();
}


#pragma comment(linker, "/STACK:66777216")
#define _CRT_SECURE_NO_DEPRECATE
#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <utility>
#include <stack>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define E 2.71828182846

const int magicconst = 1e7;

const long long mod = 1e9 + 7;

const int MAXN = 1e3 + 1;

long long gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);
	while (b != 0)
	{
		a %= b;
		swap(a, b);
	}
	return a + b;
}

vector<vector<int>>a;
vector<vector<int>>b;

void Solve()
{
	string s;
	cin >> s;
	a.resize(s.size(), vector<int>(s.size() + 1));
	b.resize(s.size(), vector<int>(s.size() + 1));
	int k1 = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '(' || s[i] == '?')
		{
			a[i][1] = 1;
			if (i > 0)
			{
				for (int j = 1; j < a[i].size(); j++)
				{
					a[i][j] += a[i - 1][j - 1];
					if (s[i] == '?')
						b[i][j] = a[i - 1][j - 1];
					else
						b[i][j] = b[i - 1][j - 1];
				}
			}
		}
		if (s[i] == ')' || s[i] == '?')
		{
			if (i > 0)
			{
				for (int j = 1; j < a[i].size(); j++)
				{
					a[i][j - 1] += a[i - 1][j];
					if (s[i] != '?' && j - 1 > 0)
					{
						b[i][j - 1] = b[i - 1][j];
					}
				}
			}
		}
		if (s[i] == '?')
		{
			k1++;
			if (k1 > 1)
			{
				for (int j = 1; j < a[i].size() - 1; j++)
				{
					if (b[i - 1][j + 1] > 0)
						a[i][j] -= b[i - 1][j + 1];
				}
			}
		}
		/*for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << " ";
		cout << "  k1 : "<<k1 <<endl;*/
	}
	/*
	for (int i = 0; i < b.size(); i++)
	{
		for (int j = 0; j < b[i].size(); j++)
		{
			cout << b[i][j] << " ";
		}
		cout << endl;
	}*/
	long long answer = 0;
	for (int i = 0; i < s.size(); i++)
		answer += a[i][0];
	cout << answer << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	Solve();
}


#pragma comment(linker, "/STACK:66777216")
#define _CRT_SECURE_NO_DEPRECATE
#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <utility>
#include <stack>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define E 2.71828182846

const int magicconst = 1e7;

const long long mod = 1e9 + 7;

const int MAXN = 1e3 + 1;

long long gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);
	while (b != 0)
	{
		a %= b;
		swap(a, b);
	}
	return a + b;
}

vector<vector<int>>a;
vector<vector<int>>b;

void Solve()
{
	string s;
	cin >> s;
	a.resize(s.size(), vector<int>(s.size() + 1));
	b.resize(s.size(), vector<int>(s.size() + 1));
	int k1 = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '(' || s[i] == '?')
		{
			a[i][1] = 1;
			if (i > 0)
			{
				for (int j = 1; j < a[i].size(); j++)
				{
					a[i][j] += a[i - 1][j - 1];
					if (s[i] == '?')
						b[i][j] = a[i - 1][j - 1];
					else
						b[i][j] = b[i - 1][j - 1];
				}
			}
		}
		if (s[i] == ')' || s[i] == '?')
		{
			if (i > 0)
			{
				for (int j = 1; j < a[i].size(); j++)
				{
					a[i][j - 1] += a[i - 1][j];
					if (s[i] != '?')
					{
						b[i][j - 1] = b[i - 1][j];
					}
				}
			}
		}
		if (s[i] == '?')
		{
			k1++;
			if (k1 > 1)
			{
				for (int j = 1; j < a[i].size() - 1; j++)
				{
					if (a[i - 1][j - 1] > 0 && a[i - 1][j + 1] > 0)
						a[i][j] -= b[i - 1][j + 1];
				}
			}
		}
		/*for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << " ";
		cout << "  k1 : "<<k1 <<endl;*/
	}
	/*
	for (int i = 0; i < b.size(); i++)
	{
		for (int j = 0; j < b[i].size(); j++)
		{
			cout << b[i][j] << " ";
		}
		cout << endl;
	}*/
	long long answer = 0;
	for (int i = 0; i < s.size(); i++)
		answer += a[i][0];
	cout << answer << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	Solve();
}


#pragma comment(linker, "/STACK:66777216")
#define _CRT_SECURE_NO_DEPRECATE
#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <utility>
#include <stack>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define E 2.71828182846

const int magicconst = 1e7;

const long long mod = 1e9 + 7;

const int MAXN = 1e3 + 1;

long long gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);
	while (b != 0)
	{
		a %= b;
		swap(a, b);
	}
	return a + b;
}

vector<vector<int>>a;
vector<vector<int>>b;

void Solve()
{
	string s;
	cin >> s;
	a.resize(s.size(), vector<int>(s.size() + 1));
	b.resize(s.size(), vector<int>(s.size() + 1));
	int k1 = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '(' || s[i] == '?')
		{
			a[i][1] = 1;
			if (i > 0)
			{
				for (int j = 1; j < a[i].size(); j++)
				{
					a[i][j] += a[i - 1][j - 1];
					if (s[i] != '?')
						b[i][j] = b[i - 1][j - 1];
				}
			}
		}
		if (s[i] == ')' || s[i] == '?')
		{
			if (i > 0)
			{
				for (int j = 1; j < a[i].size(); j++)
				{
					a[i][j - 1] += a[i - 1][j];
					if (s[i] != '?')
					{
						b[i][j - 1] = b[i - 1][j];
					}
					else
					{
						b[i][j - 1] = a[i - 1][j];
					}
				}
			}
		}
		if (s[i] == '?')
		{
			k1++;
			if (k1 > 1)
			{
				for (int j = 1; j < a[i].size() - 1; j++)
				{
					if (b[i - 1][j - 1] > 0)
						a[i][j] -= b[i - 1][j - 1];
				}
			}
		}
		/*for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << " ";
		cout << "  k1 : "<<k1 <<endl;*/
	}
	/*
	for (int i = 0; i < b.size(); i++)
	{
		for (int j = 0; j < b[i].size(); j++)
		{
			cout << b[i][j] << " ";
		}
		cout << endl;
	}
	*/
	long long answer = 0;
	for (int i = 0; i < s.size(); i++)
		answer += a[i][0];
	cout << answer << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	Solve();
}


#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;

int len;
char s[5010];
int ans = 0;
int main(void)
{
	scanf("%s", s + 1);

	int len = strlen(s + 1);
	for (int i = 1; i <= len; i++) {
		int cnt1 = 0, cnt2 = 0, cnt3 = 0;
		for (int j = i; j <= len; j++) {
			if (s[j] == '(') cnt1++;
			if (s[j] == ')') {
				if (cnt1) cnt1--;
				else if(cnt3)cnt3--;
				else break;
			}

			if (s[j] == '?') {
				if (cnt1 == 0 && cnt3 == 0) cnt1++;
				else cnt3++;
			}

			if ((j - i) % 2 == 1) {
				if (cnt1 <= cnt3) ans++;
			}
		}
	}

	printf("%d", ans);
	return 0;
}


#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

string s;
int a, b, c;
int ans = 0;
int main(void)
{
	cin >> s;

	int len = s.length();

	for (int i = 0; i < len; i++) {
		a = 0, b = 0, c = 0;
		for (int j = i; j < len; j++) {
			if (s[j] == '(') a++;
			else if (s[j] == '?') b++;
			else {
				c++;
			}

			while (b && a < b + c) a++, b--;
			if (b == 0 && a < c) break;

			if ((j - i) % 2 == 0) continue;
			if (a - c <= b && c - a <= b) ans++;
		}
	}

	printf("%d", ans);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;

int len;
char s[5010];
int ans = 0;
int main(void)
{
	scanf("%s", s + 1);

	int len = strlen(s + 1);
	for (int i = 1; i <= len; i++) {
		int cnt1 = 0, cnt2 = 0, cnt3 = 0;
		for (int j = i; j <= len; j++) {
			if (s[j] == '(') cnt1++;
			if (s[j] == ')') {
				if (cnt1) cnt1--;
				else if(cnt3)cnt3--;
				else break;
			}

			if (s[j] == '?') {
				if (cnt1 == 0 && cnt3 == 0) cnt1++;
				else cnt3++;
			}

			if ((j - i) % 2 == 1) {
				if (cnt2 > cnt1 + cnt3) break;
				if (cnt2 <= cnt1 + cnt3 && cnt1 <= cnt2 + cnt3) ans++;
			}
		}
	}

	printf("%d", ans);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;

int len;
char s[5010];
int ans = 0;
int main(void)
{
	scanf("%s", s + 1);

	int len = strlen(s + 1);
	for (int i = 1; i <= len; i++) {
		int cnt1 = 0, cnt2 = 0, cnt3 = 0;
		for (int j = i; j <= len; j++) {
			if (s[j] == '(') cnt1++;
			if (s[j] == ')') {
				if (cnt1 == 1 && cnt3) cnt3--;
				else if (cnt1) cnt1--;
				else if(cnt3)cnt3--;
				else break;
			}

			if (s[j] == '?') {
				if (cnt1 == 0) cnt1++;
				else cnt3++;
			}

			if ((j - i) % 2 == 1) {
				if (cnt1 <= cnt3) ans++;
			}
		}
	}

	printf("%d", ans);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;

int len;
char s[5010];
int ans = 0;
int main(void)
{
	scanf("%s", s + 1);

	int len = strlen(s + 1);
	for (int i = 1; i <= len; i++) {
		int cnt1 = 0, cnt2 = 0, cnt3 = 0;
		for (int j = i; j <= len; j++) {
			if (s[j] == '(') cnt1++;
			if (s[j] == ')') {
				if (cnt1 == 1 && cnt3) cnt3--;
				if (cnt1) cnt1--;
				else if(cnt3)cnt3--;
				else break;
			}

			if (s[j] == '?') {
				if (cnt1 == 0) cnt1++;
				else cnt3++;
			}

			if ((j - i) % 2 == 1) {
				if (cnt1 <= cnt3) ans++;
			}
		}
	}

	printf("%d", ans);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define all(S) S.begin(), S.end()
#define S(a) scanf("%lld", &a)
using namespace std;
int main(){
	string s;
	cin>>s;
	long ans = 0;
	for(long i=0;i<s.size();i++){
		ll noq, no, nc, mnoq;
		noq = no = nc = mnoq = 0;
		for(long j=i;j<s.size();j++){
			if(s[j] == '('){
				no++;
			} else if(s[j] == ')') {
				nc++;
			} else {
				noq++;
				if(no > mnoq)
					mnoq++;
			}
			if(nc > no + noq) break;
			if(nc > no){
				noq -= nc-no;
				no = nc;
				if(mnoq > noq) mnoq = noq;
			}
			if(nc == no){
				if(noq%2 == 0){
					ans++;
					// cout<<i<<" "<<j<<endl;
				}
			} else if (no > nc){
				if(no <= nc + mnoq){
					if((noq - (no-nc))%2 == 0){
						ans++;
						// cout<<i<<" "<<j<<"in here"<<endl;
						// cout<<no<<" "<<nc<<" "<<noq<<" "<<mnoq<<endl;
					}
				}
			} else break;
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define all(S) S.begin(), S.end()
#define S(a) scanf("%lld", &a)
using namespace std;
int main(){
	string s;
	cin>>s;
	set<pair<long, long> > se;
	for(long i=0;i<s.size();i++){
		long noq, no, nc, mnoq;
		noq = no = nc = mnoq = 0;
		for(long j=i;j<s.size();j++){
			if(s[j] == '('){
				no++;
			} else if(s[j] == ')') {
				nc++;
			} else {
				noq++;
				if(no > mnoq)
					mnoq++;
			}
			if(nc > no + noq) break;
			noq -= max(nc-no, 0L);
			if(mnoq > noq) mnoq = noq;
			no += max(nc-no, 0L);
			if(nc == no){
				if(noq%2 == 0){
					se.insert(mp(i, j));
					// cout<<i<<" "<<j<<endl;
				}
			}
			else if (no > nc){
				if(no <= nc + mnoq){
					if((noq - (no-nc))%2 == 0){
						se.insert(mp(i, j));
						// cout<<i<<" "<<j<<"in here"<<endl;
						// cout<<no<<" "<<nc<<" "<<noq<<" "<<mnoq<<endl;
					}
				}
			} else {
				while(1);
			}
		}
	}
	cout<<se.size()<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define all(S) S.begin(), S.end()
#define S(a) scanf("%lld", &a)
using namespace std;
int main(){
	string s;
	cin>>s;
	long ans = 0;
	for(long i=0;i<s.size();i++){
		ll noq, no, nc, mnoq;
		noq = no = nc = mnoq = 0;
		for(long j=i;j<s.size();j++){
			if(s[j] == '('){
				no++;
			} else if(s[j] == ')') {
				nc++;
			} else {
				noq++;
				if(no > mnoq)
					mnoq++;
			}
			if(nc > no + noq) break;
			j++;
			if(j >= s.size()) break;
			if(s[j] == '('){
				no++;
			} else if(s[j] == ')') {
				nc++;
			} else {
				noq++;
				if(no > mnoq)
					mnoq++;
			}
			if(nc > no + noq) break;
			if(nc > no){
				noq -= nc-no;
				no = nc;
				if(mnoq > noq) mnoq = noq;
			}
			if(nc == no){
				if(noq%2 == 0){
					// cout<<i<<" "<<j<<endl;
					ans++;
				}
			} else if (no > nc){
				if(no <= nc + mnoq){
					if((noq -no+nc)%2 == 0){
						// cout<<i<<" "<<j<<endl;
						ans++;
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define all(S) S.begin(), S.end()
#define S(a) scanf("%lld", &a)
using namespace std;
int main(){
	string s;
	cin>>s;
	long ans = 0;
	for(long i=0;i<s.size();i++){
		long noq, no, nc, mnoq;
		noq = no = nc = mnoq = 0;
		for(long j=i;j<s.size();j++){
			if(s[j] == '('){
				no++;
			} else if(s[j] == ')') {
				nc++;
			} else {
				noq++;
				if(no > mnoq)
					mnoq++;
			}
			if(nc > no + noq) break;
			noq -= max(nc-no, 0L);
			if(mnoq > noq) mnoq = noq;
			no += max(nc-no, 0L);
			if(nc == no){
				if(noq%2 == 0){
					ans++;
					// cout<<i<<" "<<j<<endl;
				}
			}
			else if (no > nc){
				if(no <= nc + mnoq){
					if((noq - (no-nc))%2 == 0){
						ans++;
						// cout<<i<<" "<<j<<"in here"<<endl;
						// cout<<no<<" "<<nc<<" "<<noq<<" "<<mnoq<<endl;
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define all(S) S.begin(), S.end()
#define S(a) scanf("%lld", &a)
using namespace std;
int main(){
	string s;
	cin>>s;
	set<pair<long, long> > se;
	for(long i=0;i<s.size();i++){
		long noq, no, nc;
		noq = no = nc = 0;
		for(long j=i;j<s.size();j++){
			if(s[j] == '('){
				no++;
			} else if(s[j] == ')') {
				nc++;
			} else {
				noq++;
			}
			if(nc > no + noq) break;
			noq -= max(nc-no, 0L);
			no += max(nc-no, 0L);
			if((nc == no) && (noq%2 == 0)){
				se.insert(mp(i, j));
			}
		}
	}
	reverse(all(s));
	for(long i=0;i<s.size();i++){
		long noq, no, nc;
		noq = no = nc = 0;
		for(long j=i;j<s.size();j++){
			if(s[j] == ')'){
				no++;
			} else if(s[j] == '(') {
				nc++;
			} else {
				noq++;
			}
			if(nc > no + noq) break;
			noq -= max(nc-no, 0L);
			no += max(nc-no, 0L);
			if((nc == no) && (noq%2 == 0)){
				se.insert(mp(s.size()-1-j, s.size()-1-i));
			}
		}
	}
	cout<<se.size()<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define all(S) S.begin(), S.end()
#define S(a) scanf("%lld", &a)
using namespace std;
int main(){
	string s;
	cin>>s;
	long ans = 0;
	for(long i=0;i<s.size();i++){
		ll noq, no, nc, mnoq;
		noq = no = nc = mnoq = 0;
		for(long j=i;j<s.size();j++){
			if(s[j] == '('){
				no++;
			} else if(s[j] == ')') {
				nc++;
			} else {
				noq++;
				if(no > mnoq)
					mnoq++;
			}
			if(nc > no + noq) break;
			if(nc > no){
				noq -= nc-no;
				no = nc;
				if(mnoq > noq) mnoq = noq;
			}
			if(nc == no){
				if(noq%2 == 0){
					ans++;
					// cout<<i<<" "<<j<<endl;
				}
			} else if (no > nc){
				if(no <= nc + mnoq){
					if((noq - (no-nc))%2 == 0){
						ans++;
						// cout<<i<<" "<<j<<"in here"<<endl;
						// cout<<no<<" "<<nc<<" "<<noq<<" "<<mnoq<<endl;
					}
				}
			} else if (no < nc) {
				while(1);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define all(S) S.begin(), S.end()
#define S(a) scanf("%lld", &a)
using namespace std;
int main(){
	string s;
	cin>>s;
	long ans = 0;
	for(long i=0;i<s.size();i++){
		ll noq, no, nc, mnoq, ano;
		noq = no = nc = mnoq = ano = 0;
		for(long j=i;j<s.size();j++){
			if(s[j] == '('){
				no++;
				ano++;
			} else if(s[j] == ')') {
				nc++;
			} else {
				noq++;
				if(ano > mnoq)
					mnoq++;
			}
			if(nc > no + noq) break;
			if(nc > no){
				noq -= nc-no;
				no = nc;
				if(mnoq > noq) mnoq = noq;
			}
			if(nc == no){
				if(noq%2 == 0){
					ans++;
				}
			} else if (no > nc){
				if(no <= nc + mnoq){
					if((noq -no+nc)%2 == 0){
						ans++;
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define all(S) S.begin(), S.end()
#define S(a) scanf("%lld", &a)
using namespace std;
int main(){
	string s;
	cin>>s;
	long ans = 0;
	for(long i=0;i<s.size();i++){
		ll noq, no, nc, mnoq;
		noq = no = nc = mnoq = 0;
		for(long j=i;j<s.size();j++){
			if(s[j] == '('){
				no++;
			} else if(s[j] == ')') {
				nc++;
			} else {
				noq++;
				if(no-nc > mnoq)
					mnoq++;
			}
			if(nc > no + noq) break;
			if(nc > no){
				noq -= nc-no;
				no = nc;
				if(mnoq > noq) mnoq = noq;
			}
			if(nc == no){
				if(noq%2 == 0){
					ans++;
				}
			} else if (no > nc){
				if(no <= nc + mnoq){
					if((noq -no+nc)%2 == 0){
						ans++;
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}