import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int m = s.nextInt();

		long k = s.nextInt();

		int a[] = new int[n];
		int b[] = new int[m];
		for(int i=0;i<n;i++) {
			a[i] = s.nextInt();

		}
		for(int i=0;i<m;i++) {
			b[i] = s.nextInt();
		}

		long sum = 0;
		int i=0,j=0;
		while((i<n && sum+a[i]<=k) || (j<m && sum+b[j]<=k)) {

			//System.out.println(i+" "+j);
			if(i<n && j<m) {
				if(a[i]<b[j]) {
					sum+=a[i];
					i++;
				}
				else {
					sum+=b[j];
					j++;
				}
			}
			else if(i<n) {
				sum+=a[i];
				i++;
			}
			else {
				sum+=b[j];
				j++;
			}
		}
		System.out.println(i+j);
	}

}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();

        int[] left = new int[n];
        for (int i = 0; i < n; i++) {
            left[i] = sc.nextInt();
        }
        int[] right = new int[m];
        for (int i = 0; i < m; i++) {
            right[i] = sc.nextInt();
        }

        long[] suml = new long[n+1];
        for (int i = 1; i <= n; i++) {
            suml[i] = suml[i-1] + left[i-1];
        }
        long[] sumr = new long[m+1];
        for (int i = 1; i <= m; i++) {
            sumr[i] = sumr[i-1] + right[i-1];
        }

        long tmpl = 0;
        int tmpi = -1;
        for (int i = 0; i < n; i++) {
            if (tmpl + left[i] <= k) {
                tmpl += left[i];
            } else {
                break;
            }
            tmpi = i;
        }

        long tmpr = 0;
        int tmpj = -1;
        for (int j = 0; j < m; j++) {
            if (tmpl + tmpr + right[j] <= k) {
                tmpr += right[j];
            } else {
                break;
            }
            tmpj = j;
        }

        int max = tmpi + 1 + tmpj + 1;
        tmpl -= left[tmpi];
        tmpi--;
        for (int i = tmpi; i >= 0; i--) {
            max = Math.max(max, i + 1 + tmpj + 1);

            for (int j = tmpj+1; j < m; j++) {
                if (tmpl + tmpr + right[j] <= k) {
                    tmpr += right[j];
                } else {
                    break;
                }
                tmpj = j;
                max = Math.max(max, i + 1 + j + 1);
            }

            tmpl -= left[i];
        }

        System.out.println(max);
    }
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


import java.util.*;
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();

        long[] A = new long[N];
        long[] B = new long[M];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        for (int i = 0; i < M; i++) {
            B[i] =  sc.nextInt();
        }

        long sum=0;
        int bidx = -1;
        int count=0;
        for (int i = 0; i < M ; i++) {
            if(sum+B[i] <=K){
                sum += B[i];
                bidx =i;
                count++;
            }else{
                break;
            }
        }

        int ans = count;//A zero books

        for (int i = 0; i < N; i++) {
            long bookA = A[i];
            sum += bookA;
            count++;
            while(sum>K && bidx>=0){//remvoe books in B
                sum -= B[bidx];
                count--;
                bidx--;
            }
            if(sum>K){
                break;
            }
            ans = Math.max(ans,count);
        }

        System.out.println(ans);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import static java.lang.Integer.parseInt;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter writer = new PrintWriter(System.out);
        foo(reader, writer);
        writer.flush();
    }

    public static void foo(BufferedReader reader, PrintWriter writer) throws IOException {
        int result = 0;
        String[] s = reader.readLine().split(" ");
        int n = parseInt(s[0]), m = parseInt(s[1]), k = parseInt(s[2]);
        String[] a = reader.readLine().split(" ");
        String[] b = reader.readLine().split(" ");
        int l_a = a.length, l_b = b.length;
        int i = 0, j = 0;
        while (result <= k) {
            int x = Integer.MAX_VALUE, y = Integer.MAX_VALUE;
            if (i < l_a) x = Integer.parseInt(a[i]);
            if (j < l_b) y = Integer.parseInt(b[j]);
            if (x < y) {
                result += x;
                if (result > k) {
                    result -= x;
                    break;
                }
                i++;
            }
            else {
                result += y;
                if (result > k) {
                    result -= y;
                    break;
                }
                j++;
            }
        }
        writer.println(result);
    }
}


import java.util.*;
class Main{
    public static void main(String[]args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int K = scanner.nextInt();
        int[] A = new int[N];
        int[] B = new int[M];
        for(int i=0;i<N;i++){
            A[i] = scanner.nextInt();
        }

        for(int i=0;i<M;i++){
            B[i] = scanner.nextInt();
        }
        int ans = 0;
        if(N<=M){
            ans = solve(N,M,K,A,B);
        }
        else{
            ans = solve(M,N, K,A,B);
        }

        System.out.println(ans);
        scanner.close();
    }

    static int solve(int N,int M,int K,int[] A,int[] B){
        int ans = 0;
        int time = 0;
        int temp = 0;
        int[] timecnt = new int[M];

                for(int i=0;i<M;i++){
                    timecnt[i] = 0;
                }

                time =0;
                for(int j=0;j<N;j++){
                    for(int i=0;i<N-j;i++){
                        if(time + A[i] > K){
                            break;
                        }
                        else{
                            time += A[i];
                            timecnt[j] +=1;
                        }
                    }
                    for(int i=0; i<M;i++){
                        if(time + B[i] > K){
                            break;
                        }
                        else{
                            time += B[i];
                            timecnt[j] +=1;
                        }
                    }
                }

                /*
                for(int i=0;i<M;i++){
                    System.out.println(timecnt[i]);
                }
                */

                ans = timecnt[0];
                //System.out.println(ans);
                for(int i=0;i<M;i++){
                    if(timecnt[i] != 0){
                        if(temp > timecnt[i]){
                            ans = timecnt[i];
                        }
                        temp = timecnt[i];
                    }
                }

        return ans;
    }
}


import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		long k = in.nextLong();
		long[] a = new long[n];
		long[] b = new long[m];
		for(int i = 0; i < n; i++) {
			a[i] = in.nextLong();
		}
		for(int i = 0; i < m; i++) {
			b[i] = in.nextLong();
		}
		long add = 0L;
		int i;
		for(i = 0; i < n; i++) {
			if(add + a[i] <= k) {
				add += a[i];
			}else {
				break;
			}
		}
		long ans = i;
		i -= 1;
		main:
		for(int j = 0; j < m; j++) {
			if(add + b[j] <= k) {
				add += b[j];
				ans = Math.max(ans, (i + 1) + (j + 1));
			}else {
				boolean flag = false;
				while(i >= 0) {
					add -= a[i];
					i -= 1;
					if(add + b[j] <= k) {
						ans = Math.max(ans, (i + 1) + (j + 1));
						add += b[j];
						flag = true;
						break;
					}
				}
				if(flag == false) break;
			}
		}
		System.out.println(ans);
	}
}


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

public class Main{
	public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
	    int n=sc.nextInt();
	    int m=sc.nextInt();
	    int k=sc.nextInt();
	    int[] a=new int[n];
	    int[] b=new int[m];

	    int[] ac=new int[n];
	    int[] bc=new int[m];

	    for(int i=0;i<n;i++) {
	    	a[i]=sc.nextInt();
	    	if(i!=0)ac[i]=ac[i-1]+a[i];
	    	else ac[i]=a[i];

	    }
	    int c=0;
	    for(int i=0;i<m;i++) {
	    	b[i]=sc.nextInt();
	    	if(i!=0)bc[i]=bc[i-1]+b[i];
	    	else bc[i]=b[i];
	    }

	    int ans=0;
	    int ind=m-1;
		for(int i=0;i<n;i++) {
			if(ac[i]>k)break;
			int rest=k-ac[i];

			while(bc[ind]>rest && ind>0) {
				ind--;
			}
			if(ind!=0)ind++;
			ans=Math.max(i+ind+1, ans);
		}

		System.out.println(ans);
	}

}


import java.util.Scanner;
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        ArrayList<Double> a = new ArrayList<>();
        ArrayList<Double> b = new ArrayList<>();

        int n = Integer.valueOf(scanner.next());
        int m = Integer.valueOf(scanner.next());
        double k = Double.valueOf(scanner.next());

        System.out.println("\n");

        double aValue = 0;
        for(int i = 0; i < n; i++) {
            aValue = Double.valueOf(scanner.next());
            a.add(aValue);
        }

        System.out.println("\n");

        double bValue = 0;
        for(int j = 0; j < m; j++) {
            bValue = Double.valueOf(scanner.next());
            b.add(bValue);
        }

        double l = 0;
        int z = 0;
        while(true) {

            if(a.isEmpty() && b.isEmpty()) {
                break;
            }

            if(a.isEmpty() && !(b.isEmpty())) {
                l += b.get(0);
                b.remove(0);
            }

            if(b.isEmpty() && !(a.isEmpty())) {
                l += a.get(0);
                a.remove(0);
            }

            if(!(a.isEmpty() || b.isEmpty())) {
                if(a.get(0) < b.get(0)) {
                    l += a.get(0);
                    a.remove(0);
                }else {
                    l += b.get(0);
                    b.remove(0);
                }
            }

            if(l > k) {
                break;
            }

            z++;
        }

        System.out.println(z);
    }
}


import java.util.Scanner;

public class Main {
	//java11

	static int N, M, ans;
	static long K;
	static int[] A, B;
	static long time;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		N = sc.nextInt();
		M = sc.nextInt();
		K = sc.nextLong();

		A = new int[N];
		for(int i=0; i<N; i++) {
			A[i] = sc.nextInt();
		}

		B = new int[M];
		for(int i=0; i<M; i++) {
			B[i] = sc.nextInt();
		}

		ans = 0;
		time = 0;
		int A_index = 0;
		int B_index = 0;
		Outside:
		for(int i=0; i<N+M; i++) {
			if(A_index == N && B_index == M) {
				break;
			}else if(A_index == N){
				if(time + B[B_index] <= K) {
					time += B[B_index];
					B_index++;
					ans++;
				}else {
					break;
				}
			}else if(B_index == M) {
				if(time + A[A_index] <= K) {
					time += A[A_index];
					A_index++;
					ans++;
				}else {
					break;
				}
			}
			else {
			int judge_n = judge(A_index, B_index);

			switch(judge_n) {
			case 1:
				time += A[A_index];
				A_index++;
				ans++;
				break;
			case -1:
				time += B[B_index];
				B_index++;
				ans++;
				break;
			case 0:
				break Outside;
			default:
				break;
			}
			}

		}

		System.out.println(ans);
	}

	//Aを消すべき1, Bを消すべき-1, 消えないは0
	public static int judge(int ai, int bi) {
		if(A[ai] < B[bi]) {
			if(time + A[ai] <= K) {
				return 1;
			}else {
				return 0;
			}
		}
		else if(A[ai] > B[bi]) {
			if(time + B[bi] <= K) {
				return -1;
			}else {
				return 0;
			}
		}else {
			//終了条件
			if(ai == N-1 || bi == M-1) {
				if(time + A[ai] <= K) {
					return 1;
				}else {
					return 0;
				}
			}else {
				return judge(ai+1, bi+1);
			}
		}
	}
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N + 1];
        int[] B = new int[M + 1];
        A[N] = 0;
        B[N] = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        for (int i = 0; i < M; i++) {
            B[i] = sc.nextInt();
        }
        int T = 0;
        int a = A[0];
        int b = B[0];
        int Ca = 0;
        int Cb = 0;
        while ( T <= K ) {
            if ( a > 0 && a > b ) {
                T = T + a;
                Ca = Ca + 1;
                a = A[Ca];
            } else if (b > 0 && b >= a){
                T = T + b;
                Cb = Cb + 1;
                b = B[Cb];
            } else {
                break;
            }
        }
        System.out.println(Ca + Cb);
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, m;
        long k;
        n = sc.nextInt(); m = sc.nextInt(); k = sc.nextLong();
        sc.nextLine();
        int i;
        long N[] = new long[n];
        long M[] = new long[m];
        for(i = 0; i < n; i++) N[i] = sc.nextLong();
        sc.nextLine();
        for(i = 0; i < m; i++) M[i] = sc.nextLong();
        sc.nextLine();

        long limit = 0;
        int ntop = 0, mtop = 0;
        while(limit < k){

            if(N[ntop] > M[mtop] || mtop >= m){
                if((limit + M[mtop]) < k) limit += M[mtop++];
                else break;
            }else{
                if((limit + N[ntop]) < k) limit += N[ntop++];
                else break;
            }

        }

        System.out.println(mtop+ntop);

    }
}


/*
Written by Kabir Kanha Arora
@kabirkanha
 */

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        long K = scanner.nextLong();
        long[] arr_A = new long[N];
        long[] arr_B = new long[M];
        for (int i = 0; i < N; ++i) {
            arr_A[i] = scanner.nextLong();
        }
        for (int i = 0; i < M; ++i) {
            arr_B[i] = scanner.nextLong();
        }
        int cnt = 0;
        long sum = 0;
        for (int i = 0; i < N; ++i) {
            if (sum + arr_A[i] > K)
                break;
            sum += arr_A[i];
            cnt++;
        }
        int max = cnt;
        int marker = cnt - 1;
        for (int i = 0; i < M; ++i) {
            if (sum + arr_B[i] > K)
                break;
            sum += arr_B[i];
            cnt++;
        }
        int j = 0;
        for (int i = marker; i >= 0; --i) {
            sum -= arr_A[i];
            --cnt;
            while (j < M && sum + arr_B[j] <= K) {
                sum += arr_B[j];
                ++j;
                ++cnt;
                max = Math.max(max, cnt);
            }
        }
        System.out.println(max);
    }
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int M = in.Int();
            int K = in.Int();
            int[] A = in.Int(N);
            int[] B = in.Int(M);

            long[] as = new long[N + 1];
            for (int i = 0; i < N; i++) {
                as[i + 1] += as[i] + A[i];
            }
            long[] bs = new long[M + 1];
            for (int i = 0; i < M; i++) {
                bs[i + 1] += bs[i] + B[i];
            }
            int ans = 0;
            int i = 0;
            while (i < N && as[i + 1] <= K) i++;
            int j = 0;
            while (i >= 0) {
                while (j < M && as[i] + bs[j + 1] <= K) j++;
                ans = Math.max(ans, i + j);
                i--;
            }
            out.println(ans);
//        out.println(Arrays.toString(as));
//        out.println(Arrays.toString(bs));
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}


import java.util.*;

public class Main {
	static int max = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        long K = sc.nextLong();
        int[] A = new int[N+1];
        for (int i = 1; i < N+1; i++) {
        	int Ai = sc.nextInt();
        	A[i] = Ai;
        }
        int[] B = new int[M+1];
        for (int i = 1; i < M+1; i++) {
        	int Bi = sc.nextInt();
        	B[i] = Bi;
        }
        calc(0, K, true, A, B, 1, 1);
        calc(0, K, false, A, B, 1, 1);
        System.out.println(max);
    }

    private static void calc(int count, long K, boolean isA, int[] A, int[] B, int indexA, int indexB) {
    	if (isA) {
    		K -= A[indexA];
    		if (K < 0) {
    			if (max < count) {
    				max = count;
    			}
    			return;
    		}
    		indexA++;
    		count++;
    		if (indexA == A.length && indexB == B.length) {
    			if (max < count) {
    				max = count;
    			}
        		return;
    		} else if (indexA == A.length) {
    			calc(count, K, false, A , B, indexA, indexB);
    		} else if (indexB == B.length) {
    			calc(count, K, true, A , B, indexA, indexB);
    		} else {
        		calc(count, K, true, A , B, indexA, indexB);
        		calc(count, K, false, A , B, indexA, indexB);
    		}
    	} else {
    		K -= B[indexB];
    		if (K < 0) {
    			if (max < count) {
    				max = count;
    			}
    			return;
    		}
    		indexB++;
    		count++;
    		if (indexA == A.length && indexB == B.length) {
    			if (max < count) {
    				max = count;
    			}
        		return;
    		} else if (indexA == A.length) {
    			calc(count, K, false, A , B, indexA, indexB);
    		} else if (indexB == B.length) {
    			calc(count, K, true, A , B, indexA, indexB);
    		} else {
        		calc(count, K, true, A , B, indexA, indexB);
        		calc(count, K, false, A , B, indexA, indexB);
    		}
    	}
    }
}


import java.util.*;
import java.io.*;
import java.util.function.*;
// import lib.util.*;
// import lib.graph.*;
// import lib.io.*;
// import lib.math.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[m];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            b[i] = sc.nextInt();
        }
        ArrayDeque<Integer> q = new ArrayDeque<>();
        int c = 0;
        int d = 0;
        for (int i = 0; i < n + m; i++) {
            if (c == n) {
                while (d != m) {
                    q.add(b[d]);
                    d++;
                }
                break;
            }
            if (d == m) {
                while (c != n) {
                    q.add(a[c]);
                    c++;
                }
                break;
            }
            if (a[c] < b[d]) {
                q.add(a[c]);
                c++;
            } else {
                q.add(b[d]);
                d++;
            }
        }
        int res = 0;
        while (q.size() > 0) {
            k -= q.poll();
            if (k >= 0)
                res++;
            else
                break;
        }
        System.out.println(res);
    }

}

class UnionFindTree {
    int[] root;
    int[] rank;
    int[] size;
    int m;

    public UnionFindTree(int n) {
        this.root = new int[n];
        this.rank = new int[n];
        this.size = new int[n];
        this.m = n;
        for (int i = 0; i < n; i++) {
            root[i] = i;
            size[i] = 1;
        }
    }

    public int find(int x) {
        if (root[x] == x)
            return x;
        else {
            return root[x] = find(root[x]);
        }
    }

    public void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (rank[x] < rank[y]) {
            size[find(y)] = size[find(x)];
            root[x] = y;
        } else {
            size[find(x)] = size[find(y)];
            root[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
        m--;
    }

    public boolean same(int x, int y) {
        return find(x) == find(y);
    }

    public int size(int i) {
        return this.size[find(i)];
    }
}

class Dijkstra {
    private static int prev[];
    private static long dist[];

    public Dijkstra(AbstractGraph graph, int s) {
        prev = new int[graph.n];
        dist = new long[graph.n];
        Arrays.fill(prev, -1);
        Arrays.fill(dist, Long.MAX_VALUE);
        PriorityQueue<Integer> searching = new PriorityQueue<>((x, y) -> Long.compare(dist[x], dist[y]));
        dist[s] = 0;
        searching.add(s);
        while (searching.size() > 0) {
            int now = searching.poll();
            for (Edge e : graph.getEdges(now)) {
                int next = e.to;
                long c = e.cost;
                if (dist[now] + c < dist[next]) {
                    dist[next] = dist[now] + c;
                    prev[next] = now;
                    searching.add(next);
                }
            }
        }
    }

    public int[] path(int to) {
        ArrayList<Integer> rev = new ArrayList<>();
        for (int now = to; now != -1; now = this.prev[now]) {
            rev.add(now);
        }
        int[] path = new int[rev.size()];
        for (int i = 0; i < path.length; i++) {
            path[i] = rev.get(path.length - i - 1);
        }
        return path;
    }

    public long getDist(int t) {
        return dist[t];
    }
}

class WF {
    private static long[][] dist;

    public WF(AbstractGraph graph) {
        dist = new long[graph.n][graph.n];
        for (int i = 0; i < dist.length; i++) {
            Arrays.fill(dist[i], Integer.MAX_VALUE);
        }
        for (int i = 0; i < graph.n; i++) {
            for (Edge e : graph.getEdges(i)) {
                dist[i][e.to] = e.cost;
            }
            dist[i][i] = 0;
        }
        for (int k = 0; k < graph.n; k++) {
            for (int i = 0; i < graph.n; i++) {
                for (int j = 0; j < graph.n; j++) {
                    if (dist[i][k] != Integer.MAX_VALUE && dist[k][j] != Integer.MAX_VALUE) {
                        dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);
                    }
                }
            }
        }
    }

    public static long getShortest(int s, int t) {
        return dist[s][t];
    }

    public static long[][] getAllDist() {
        return dist;
    }

    public static boolean isNegativeLoop() {
        for (int i = 0; i < dist.length; i++) {
            if (dist[i][i] < 0) {
                return true;
            }
        }
        return false;
    }
}

class Edge {
    int from, to;
    long cost;

    public Edge(int from, int to, long cost) {
        this.from = from;
        this.to = to;
        this.cost = cost;
    }

    public Edge(int from, int to) {
        this.from = from;
        this.to = to;
        this.cost = 1;
    }

    public Edge reverse() {
        return new Edge(to, from, cost);
    }
}

@SuppressWarnings("unchecked")
abstract class AbstractGraph {
    int n;
    int m;
    ArrayList<Edge>[] edges;

    public AbstractGraph(int n) {
        this.n = n;
        this.m = 0;
        this.edges = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            this.edges[i] = new ArrayList<Edge>();
        }
    }

    public void addEdge(Edge e) {
        this.m++;
        this.edges[e.from].add(e);
    }

    public int getV() {
        return this.n;
    }

    public int getE() {
        return this.m;
    }

    public ArrayList<Edge> getEdges(int v) {
        return this.edges[v];
    }

    abstract public boolean isBipartite();

    public boolean isTree() {
        // require Modifying.
        return false;
    }
}

class Graph extends AbstractGraph {
    int n;
    int m;
    // array of edges which is connect to the node
    ArrayList<Edge>[] edges;

    public Graph(int n) {
        super(n);
    }

    public void addEdge(int from, int to, int cost) {
        Edge e = new Edge(from, to, cost);
        super.addEdge(e);
        super.addEdge(e.reverse());
        this.m++;
    }

    @Override
    public void addEdge(Edge e) {
        this.edges[e.from].add(e);
        this.edges[e.to].add(e.reverse());
        this.m++;
    }

    public int getV(int v) {
        return n;
    }

    public int getE() {
        return m;
    }

    public boolean isBipartite() {
        int[] color = new int[n];
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        HashSet<Integer> visited = new HashSet<>();
        queue.add(0);
        color[0] = 1;
        while (queue.size() > 0) {
            int now = queue.poll();
            visited.add(now);
            for (Edge e : getEdges(now)) {
                if (visited.contains(e.to)) {
                    continue;
                }
                if (color[e.to] == color[now])
                    return false;
                queue.add(e.to);
                if (color[e.to] == 0)
                    color[e.to] = -1 * color[now];
            }
        }
        return true;
    }
}

class DirectedGraph extends AbstractGraph {
    private int n;
    private int m;
    private int[] ind;
    // array of edges which is connect to the node
    ArrayList<Edge>[] edges;

    public DirectedGraph(int n) {
        super(n);
        this.ind = new int[n];
    }

    public void addEdge(int from, int to, int cost) {
        Edge e = new Edge(from, to, cost);
        super.addEdge(e);
        this.m++;
        this.ind[to]++;
    }

    @Override
    public void addEdge(Edge e) {
        this.edges[e.from].add(e);
        this.m++;
        this.ind[e.to]++;
    }

    public int getV(int v) {
        return this.n;
    }

    public int getE() {
        return this.m;
    }

    public int[] getInDimension() {
        return this.ind;
    }

    public int getInDimension(int v) {
        return this.ind[v];
    }

    public boolean isBipartite() {
        // need to rewrite to work
        return false;
    }

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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

class MyMath {
    public static long gcm(long a, long b) {

        // if (a < b)
        // return gcm(b, a);

        // if (b == 0 || a % b == 0)
        // return b;

        // return gcm(b, a % b);
        if (a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        long r = -1;
        while (r != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    public static long summation(long a, long b) {
        return b * (b + 1) / 2 - a * (a - 1) / 2;
    }

    public static long factorial(long n, long m) {

        if (n <= 1)
            return 1;
        else
            return factorial(n - 1, m) * n % m;
    }

    public static long[][] binomialTable(int a, long m) {
        long[][] table = new long[a + 1][a + 1];
        for (int i = 0; i < a + 1; i++) {
            table[0][a] = 0;
            table[i][0] = 1;
            table[i][i] = 1;
        }
        for (int i = 1; i < a + 1; i++) {
            for (int j = 1; j < a + 1; j++) {
                if (i < j)
                    table[i][j] = 0;
                else {
                    table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % m;
                }
            }
        }
        return table;
    }

    public static long binomial(int n, int k, long m) {
        long res = 1;
        for (int l = n - k + 1; l <= n; l++) {
            res = (res % m) * (l % m) % m;
        }
        for (int r = 1; r <= k; r++) {
            res = (res % m) * modinv(r, m) % m;
        }
        return res;
    }

    public static long binomial(long[] facttable, long[] invtable, int n, int k, long m) {
        if (n < k)
            return 0;
        else
            return (facttable[n] % m * (invtable[n - k] % m) * invtable[k] % m) % m;
    }

    public static long pow(long a, long n, long p) {
        if (n == 0)
            return 1;
        if (n == 1)
            return a % p;
        if (n % 2 == 1)
            return a * pow(a, n - 1, p) % p;
        long tmp = pow(a, n / 2, p) % p;
        return tmp * tmp % p;
    }

    public static long modinv(long a, long p) {
        long b, x, u, q, abs_p, tmp;
        abs_p = Math.abs(p);
        b = p;
        x = 1;
        u = 0;
        while (b > 0) {
            q = a / b;
            tmp = u;
            u = x - q * u;
            x = tmp;
            tmp = b;
            b = a - q * b;
            a = tmp;
        }
        return (x < 0) ? abs_p + x : x;
    }

    public static Long[] eratosthenes(int n) {
        Long[] factor_table = new Long[n];
        for (long i = 1; i <= n; i++) {
            factor_table[(int) (i - 1)] = i;
        }
        for (long i = 1; i <= n; i++) {
            if (factor_table[(int) (i - 1)] == i) {
                int j = 2;
                while (i * j <= n) {
                    factor_table[(int) (i * j - 1)] = i;
                    j++;
                }
            }
        }

        return factor_table;
    }

    public static HashMap<Long, Integer> primeFactorization(long n) {
        HashMap<Long, Integer> primes = new HashMap<>();
        for (long p = 2; p * p <= n; p++) {
            int q = 0;
            while (n % p == 0) {
                n /= p;
                q++;
            }
            if (q > 0)
                primes.put(p, q);
        }
        if (n > 1)
            primes.put(n, 1);
        return primes;
    }

    public static ArrayList<Integer> divisor(int n) {
        ArrayList<Integer> ret = new ArrayList<Integer>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                ret.add(i);
                // n=PQ+0→ PもQも約数. ただし、Q=Pは↑で登録済みなので登録しない
                if (i != n / i)
                    ret.add(n / i);
            }
        }
        return ret;
    }
}

class nextPermutation {
    public static int[] swap(int data[], int left, int right) {

        // Swap the data
        int temp = data[left];
        data[left] = data[right];
        data[right] = temp;

        // Return the updated array
        return data;
    }

    // Function to reverse the sub-array
    // starting from left to the right
    // both inclusive
    public static int[] reverse(int data[], int left, int right) {

        // Reverse the sub-array
        while (left < right) {
            int temp = data[left];
            data[left++] = data[right];
            data[right--] = temp;
        }

        // Return the updated array
        return data;
    }

    // Function to find the next permutation
    // of the given integer array
    public static boolean findNextPermutation(int data[]) {

        // If the given dataset is empty
        // or contains only one element
        // next_permutation is not possible
        if (data.length <= 1)
            return false;

        int last = data.length - 2;

        // find the longest non-increasing suffix
        // and find the pivot
        while (last >= 0) {
            if (data[last] < data[last + 1]) {
                break;
            }
            last--;
        }

        // If there is no increasing pair
        // there is no higher order permutation
        if (last < 0)
            return false;

        int nextGreater = data.length - 1;

        // Find the rightmost successor to the pivot
        for (int i = data.length - 1; i > last; i--) {
            if (data[i] > data[last]) {
                nextGreater = i;
                break;
            }
        }

        // Swap the successor and the pivot
        data = swap(data, nextGreater, last);

        // Reverse the suffix
        data = reverse(data, last + 1, data.length - 1);

        // Return true as the next_permutation is done
        return true;
    }
}

class ArrayUtil {
    private static long INF = 1_000_000_000_0L;

    public static int UpperBound(long[] array, long obj) {
        int l = 0, r = array.length - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj < array[c]) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }

    public static int LowerBound(long[] array, long obj) {
        int l = 0, r = array.length - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj <= array[c]) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }

    // return the length of array's LIS
    public static int LIS(long[] array) {
        long[] dp = new long[array.length + 1];
        Arrays.fill(dp, INF);
        for (int i = 0; i < array.length; i++) {
            int idx = LowerBound(dp, array[i]);
            dp[idx] = array[i];
        }
        return LowerBound(dp, INF - 1);
    }

    public static int StrictLIS(long[] array) {
        long[] dp = new long[array.length + 1];
        Arrays.fill(dp, INF);
        for (int i = 0; i < array.length; i++) {
            int idx = UpperBound(dp, array[i]);
            dp[idx] = array[i];
        }
        return UpperBound(dp, INF - 1);
    }

    public static void debug(int[][] A) {
        for (int i = 0; i < A.length; i++) {
            for (int j = 0; j < A[0].length; j++) {
                System.out.print(A[i][j] + " ");
            }
            System.out.println();
        }
    }
}

class BinaryIndexedTree {
    int[] data;
    long[] tree;
    int n;

    public BinaryIndexedTree(int[] data) {
        this.data = data;
        this.n = data.length;
        this.tree = new long[n + 1];
        buildTree();
    }

    public void buildTree() {
        for (int i = 0; i < n; i++) {
            add(i + 1, data[i]);
        }
    }

    public void add(int index, int value) {
        for (int i = index; i <= n; i += i & -i) {
            tree[i] += value;
        }
    }

    public long sum(int from, int to) {
        return sum(to) - sum(from - 1);
    }

    public long sum(int index) {
        int sum = 0;
        for (int i = index; i > 0; i -= i & -i) {
            sum += tree[i];
        }
        return sum;
    }
}

class TopologicalSort {
    private DirectedGraph g;
    private int[] in;
    private int n, m;

    public TopologicalSort(DirectedGraph g) {
        this.g = g;
        this.in = g.getInDimension();
        this.n = g.getV();
        this.m = g.getE();
    }

    public int[] sort() {
        int[] ret = new int[this.n];
        ArrayDeque<Integer> q = new ArrayDeque<>();
        for (int i = 0; i < this.n; i++) {
            if (in[i] == 0) {
                q.push(i);
            }
        }
        int k = 0;
        while (q.size() > 0) {
            int v = q.pollFirst();
            ret[k] = v;
            k++;
            for (Edge e : g.getEdges(v)) {
                if (--in[e.to] == 0)
                    q.push(e.to);
            }
        }
        return ret;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		long K = sc.nextLong();

		ArrayList<Long> a_books = new ArrayList<Long>(N);
		for (int i = 0; i < N; i++) {
			a_books.add(sc.nextLong());
		}
		ArrayList<Long> b_books = new ArrayList<Long>(M);
		for (int i = 0; i < M; i++) {
			b_books.add(sc.nextLong());
		}

		int ans = 0;
		long total = 0L;
		while (total <= K) {
			long a_book_time = -1;
			if (!a_books.isEmpty()) {
				a_book_time = a_books.get(0);

			}
			long b_book_time = -1;
			if (!b_books.isEmpty()) {
				b_book_time = b_books.get(0);
			}

			if (a_book_time != -1 && a_book_time != -1) {
				if (a_book_time < b_book_time) {
					if (total + a_book_time <= K) {
						total += a_book_time;
						a_books.remove(0);
						ans++;
					}
					else {
						break;
					}
				}
				else {
					if (total + b_book_time <= K) {
						total += b_book_time;
						b_books.remove(0);
						ans++;
					}
					else {
						break;
					}
				}
			}
			else if (a_book_time != -1) {
				if (total + a_book_time <= K) {
					total += a_book_time;
					a_books.remove(0);
					ans++;
				}
				else {
					break;
				}
			}
			else if (b_book_time != -1) {
				if (total + b_book_time <= K) {
					total += b_book_time;
					b_books.remove(0);
					ans++;
				}
				else {
					break;
				}
			}
			else {
				break;
			}
		}

		System.out.println(ans);
	}

	private static class FastScanner {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;

		public FastScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

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

	}
}


import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();
			int M = scan.nextInt();
			int K = scan.nextInt();
			int[]A = new int[N];
			int[]B = new int[M];
			Deque<Integer>ade = new ArrayDeque<Integer>();
			Deque<Integer>bde = new ArrayDeque<Integer>();
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				ade.addFirst(A[i]);

			}
			for(int i = 0;i<M;i++) {
					B[i] = scan.nextInt();
					bde.addFirst(B[i]);
			}

			long time=0;
			int count = 0;

			while(true) {

				if(ade.isEmpty()&&bde.isEmpty()) {
					break;
				}else if(ade.isEmpty()) {
					time+=(long)bde.pollLast();
					count++;
				}else if(bde.isEmpty()) {
					time+=(long)ade.pollLast();
					count++;
				}else {
					int ase = ade.peekLast();
					int bse = bde.peekLast();
					if(ase<=bse){
						time+=(long)ade.pollLast();
						count++;
					}else{
						time+=(long)bde.pollLast();
						count++;
					}
				}
				System.out.println(time);

				if(time>K) {
					count--;
					break;
				}

			}

			System.out.println(count);

		}

	}

}


import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int k = sc.nextInt();

	int n_nums[] = new int[n];
    int m_nums[] = new int[m];
    for(int i = 0; i < n; i++){
		n_nums[i] = sc.nextInt();
    }

     for(int i = 0; i < m; i++){
		m_nums[i] = sc.nextInt();
    }

    int ns = 0,ms = 0;
    int sum = 0;

    while(true){
      	int tmp = 0;

      	if(n_nums[ns] > m_nums[ms]){
        	if(m_nums.length > ms)
        		tmp = m_nums[ms++];
          	else
            	tmp = n_nums[ns++];
        }else if(n_nums[ns] < m_nums[ms]){
          	if(n_nums.length > ns)
        		tmp = n_nums[ns++];
          	else
              	tmp = m_nums[ms++];
        }

    	if(sum+tmp > k){
        	break;
        }else{
        	sum += tmp;
        }
    }

  }
}


/*
 * Remember a 6.72 student can know more than a 10.0 student.
 * Grades don't determine intelligence, they test obedience.
 * I Never Give Up.
 * I will become Candidate Master.
 * I will defeat Saurabh Anand.
 * Skills are Cheap,Passion is Priceless.
 * Obsession is necessary.
 * Author : Sameer Raj
 */
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.lang.Math.*;
import java.math.BigInteger;

import static java.lang.System.*;
import static java.util.Arrays.fill;
import static java.lang.Math.log;
import static java.lang.Math.abs;
import static java.lang.Math.pow;
import static java.lang.Math.sqrt;
import static java.lang.Math.floor;
import static java.lang.Math.ceil;
import static java.lang.Math.sin;
import static java.lang.Math.cos;
import static java.lang.Math.tan;
import static java.util.Arrays.spliterator;
public class Main implements Runnable{
	private static Reader in=new Reader();
	private static StringBuilder ans=new StringBuilder();
	private static long MOD=(long)1e9+7;
	private static final int N=(int) (2e5+7); // 2e5+7
	private static ArrayList<Integer> v[]=new ArrayList[N];
	private static HashMap<String,Integer> cmap=new HashMap();
	private static boolean mark[]=new boolean[N];
	//    private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	/*Not try to hack the sort function*/
	public static void sort(long arr[]){
		for(int i=arr.length-1;i>=2;i--){
			int x=new Random().nextInt(i-1);
			long temp=arr[x];
			arr[x]=arr[i];
			arr[i]=temp;
		}
		Arrays.sort(arr);
	}
	public static void sort(int arr[]){
		for(int i=arr.length-1;i>=2;i--){
			int x=new Random().nextInt(i-1);
			int temp=arr[x];
			arr[x]=arr[i];
			arr[i]=temp;
		}
		Arrays.sort(arr);
	}
	public static void sort(String arr[]){
		for(int i=arr.length-1;i>=2;i--){
			int x=new Random().nextInt(i-1);
			String temp=arr[x];
			arr[x]=arr[i];
			arr[i]=temp;
		}
		Arrays.sort(arr);
	}
	public static void sort(Pair arr[]){
		for(int i=arr.length-1;i>=2;i--){
			int x=new Random().nextInt(i-1);
			Pair temp=arr[x];
			arr[x]=arr[i];
			arr[i]=temp;
		}
		Arrays.sort(arr);
	}
	private static long gcd(long a, long b){
		if(b==0)return a;
		return gcd(b,a%b);
	}
	public static long lcm(long a,long b){
		return min(a,b)*(max(a,b)/gcd(a,b));
	}
	/*--------------------------------------------------------------------------------------------------------------*/
	/*Code lies here*/
	public static int solve(long a[],long b[],long k){
		long rem;
		int l=0,r=0,mid,res=0;
		for(int i=0;i<a.length&&a[i]<=k;i++){
			rem=k-a[i];
			res=max(res,i+1);
			l=0;r=b.length-1;
			while(l<r&&l+1!=r){
				mid=(l+r)/2;
				if(b[mid]<=rem)l=mid;
				else r=mid;
			}
			if(b[r]<=rem){res=max(res,i+1+r+1);}
			else if(b[l]<=rem){res=max(res,i+1+l+1);}
		}
		return res;
	}
	@Override
	public void run(){
		int n=in.nextInt();
		int m=in.nextInt();
		int k=in.nextInt();
		long ar[]=new long[n];
		long br[]=new long[m];
		for(int i=0;i<n;i++){
			if(i==0)ar[i]=in.nextLong();
			else ar[i]=ar[i-1]+in.nextLong();
		}
		for(int i=0;i<m;i++){
			if(i==0)br[i]=in.nextLong();
			else br[i]=br[i-1]+in.nextLong();
		}
		pn(max(solve(ar,br,k),solve(br,ar,k)));
	}
	public static void main(String[] args) throws IOException{
		new Thread(null,new Main(),"Accepted",1<<26).start();
		/* 0_0 I am watching you 0_0 */
	}
	static class Pair<T> implements Comparable<Pair>{
		long l;
		long r;
		Pair(){
			l=0;
			r=0;
		}
		Pair(long k,long v){
			l=k;
			r=v;
		}
		@Override
		public int compareTo(Pair o){
			if(l!=o.l)return (int)(l-o.l);
			return (int)(r-o.r);
		}
	}
	/* BINARY SEARCH FUNCTIONS */
	public static int ceilSearch(int l,int r,int val,int ar[]){
		int mid;
		while(l+1!=r&&l<r){
			mid=(l+r)/2;
			if(ar[mid]<val)l=mid;
			else r=mid;
		}
		if(ar[l]>=val)return l;
		else if(ar[r]>=val)return r;
		else return -1;
	}
	public static int ceilSearch(int l,int r,long val,long ar[]){
		int mid;
		while(l+1!=r&&l<r){
			mid=(l+r)/2;
			if(ar[mid]<val)l=mid;
			else r=mid;
		}
		if(ar[l]>=val)return l;
		else if(ar[r]>=val)return r;
		else return -1;
	}
	public static int floorSearch(int l,int r,int val,int ar[]){
		int mid;
		while(l+1!=r&&l<r){
			mid=(l+r)/2;
			if(ar[mid]>val)r=mid;
			else l=mid;
		}
		if(ar[r]<=val)return r;
		else if(ar[l]<=val)return l;
		else return -1;
	}
	public static int floorSearch(int l,int r,long val,long ar[]){
		int mid;
		while(l+1!=r&&l<r){
			mid=(l+r)/2;
			if(ar[mid]>val)r=mid;
			else l=mid;
		}
		if(ar[r]<=val)return r;
		else if(ar[l]<=val)return l;
		else return -1;
	}
	/* MODULAR OPERATIONS */
	private static long mod(long a,long b){ //a%b
		return (b+a%b)%b;
	}
	private static long modInv(long a){
		return powmod(a,MOD-2);
	}
	private static long powmod(long x,long n){
		if(n==0||x==0)return 1;
		else if(n%2==0)return(powmod((x*x)%MOD,n/2));
		else return (x*(powmod((x*x)%MOD,(n-1)/2)))%MOD;
	}
	public static long mult(long a,long b){
		return mod(mod(a,MOD)*mod(b,MOD),MOD);
	}
	public static long add(long a,long b){
		return mod(mod(a,MOD)+mod(b,MOD),MOD);
	}
	public static long sub(long a,long b){
		return mod(mod(a,MOD)-mod(b,MOD),MOD);
	}
	/* MAX-MIN FUNCTIONS */
	public static long min(long a,long b){
		return Math.min(a, b);
	}
	public static int min(int a,int b){
		return Math.min(a, b);
	}
	public static long max(long a,long b){
		return Math.max(a, b);
	}
	public static int max(int a,int b){
		return Math.max(a, b);
	}
	public static long min(long ar[]){
		return Arrays.stream(ar).min().getAsLong();
	}
	public static int min(int ar[]){
		return Arrays.stream(ar).min().getAsInt();
	}
	public static long max(long ar[]){ return Arrays.stream(ar).max().getAsLong();}
	public static int max(int ar[]){ return Arrays.stream(ar).max().getAsInt(); }
	//Reader Class
	static class Reader{
		BufferedReader br;
		StringTokenizer st;
		public Reader(){br=new BufferedReader(new InputStreamReader(System.in));}
		String next(){
			while(st==null||!st.hasMoreElements()){
				try{st=new StringTokenizer(br.readLine());
				}catch(IOException e){e.printStackTrace();}
			}
			return st.nextToken();
		}
		int nextInt(){return Integer.parseInt(next());}
		long nextLong(){return Long.parseLong(next());}
		double nextDouble(){return Double.parseDouble(next());}
		String nextLine(){
			String str="";
			try{
				str=br.readLine();
			}catch(IOException e){
				e.printStackTrace();
			}
			return str;
		}
	}
	//Looping methods
	static void rep(int ar[],int start,int end){
		for(int i=start;i<end;i++)
			ar[i]=in.nextInt();

	}
	static void rep(long ar[],int start,int end){
		for(int i=start;i<end;i++)
			ar[i]=in.nextLong();
	}
	static void rep(String ar[],int start,int end){
		for(int i=start;i<end;i++)
			ar[i]=in.next();
	}
	static void rep(int ar[][],int n,int m){
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++)
				ar[i][j]=in.nextInt();
		}
	}
	static void rep(long ar[][],int n,int m){
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++)
				ar[i][j]=in.nextLong();
		}
	}
	//Printer Methods
	static void pn(Object o){out.print(o);}
	static void pln(Object o){out.println(o);}
	static void pln(){out.println();}
	static void pf(String format,Object o){out.printf(format,o);}
	//Appenders
	static void app(Object o){ans.append(o);}
	static void appn(Object o){ans.append(o+"\n");}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) throws Exception {

		MyScanner sc = new MyScanner();
		PrintWriter pr = new PrintWriter(System.out);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();

		long a[] = new long[n];
		long b[] = new long[m];

		for (int i = 0; i < n; i++)
			a[i] = sc.nextLong();

		for (int i = 0; i < m; i++)
			b[i] = sc.nextLong();

		int count = 0;
		long cost = 0;

		Stack<Long> s1 = new Stack<>();
		Stack<Long> s2 = new Stack<>();

		for (int i = n - 1; i >= 0; i--)
			s1.push(a[i]);

		for (int i = m - 1; i >= 0; i--)
			s2.push(b[i]);

		while (cost < k && !s1.isEmpty() && !s2.isEmpty()) {

			long x = s1.peek();
			long y = s2.peek();
			// System.out.println(x + " " + y + " " + cost);
			if (x <= y) {

				cost += x;

				if (cost > k)
					break;

				count++;
				s1.pop();
			} else {

				cost += y;

				if (cost > k)
					break;

				count++;
				s2.pop();
			}
		}

		if (s1.isEmpty() && !s2.isEmpty()) {

			while (cost < k) {

				cost += s2.pop();
				count++;
			}
		}

		else if (s2.isEmpty() && !s1.isEmpty()) {

			while (cost < k) {

				cost += s1.pop();
				count++;
			}
		}
		pr.print(count);
		pr.close();
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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


import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int k = sc.nextInt();

	int n_nums[] = new int[n];
    int m_nums[] = new int[m];
    for(int i = 0; i < n; i++){
		n_nums[i] = sc.nextInt();
    }

     for(int i = 0; i < m; i++){
		m_nums[i] = sc.nextInt();
    }

    int ns = 0,ms = 0;
    int sum = 0;
    int count = 0;

    while(true){
      	int tmp = 0;

      	if(n_nums[ns] > m_nums[ms]){
        	tmp = m_nums[ms++];
        }else if(n_nums[ns] < m_nums[ms]){
        	tmp = n_nums[ns++];
        }else{
        	if(n_nums[ns] > m_nums[ms]){
        		tmp = m_nums[ms++];
        	}else if(n_nums[ns] < m_nums[ms]){
        		tmp = n_nums[ns++];
            }else{
            	tmp = n_nums[ns++];
            }
        }
    	if(sum+tmp > k){
        	break;
        }else{
        	sum += tmp;
        	count++;
        }
    }

    System.out.println(count);

  }
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long M = sc.nextLong();
        long k = sc.nextLong();
        long[] arr = new long[(int)(N+M)];
        for(int i = 0; i < (M+N); i++) {
            arr[i] = sc.nextLong();
        }
        Arrays.sort(arr);

        long res = 0;
        long total = 0;
        for(int i = 0; i < (M+N); i++) {
            total += arr[i];
            if(total > k) break;
            res++;
        }
        System.out.println(res);
    }
}


import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int m = sc.nextInt();
      	long k = sc.nextLong();
      	long[] a = new long[n];
      	long[] b = new long[m];
      	boolean bFlag = true;
      	long ans = 0;
      	long tmp = 0;
      	for(int i=0;i<n;i++){
          a[i] = sc.nextLong();
        }
      	for(int i=0;i<m;i++){
          b[i] = sc.nextLong();
        }
      	for(int i=0;(i<n)||(i<m);i++){
          if( i < n ){
            tmp += a[i];
            ans++;
          }
          if( tmp > k ){
            ans--;
            break;
          }
          if( i < m ){
            tmp += b[i];
            ans++;
          }
          if( tmp > k ){
            ans--;
            break;
          }
        }
      	System.out.println(ans);
	}
}


import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = (int)1e9 + 7;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int len = (int)1e7;

	void doIt() {
		int N = sc.nextInt();
		long[] num = new long[N + 1];
		Arrays.fill(num, 2);
		num[1] = 1;
		for(int i = 2; i <= N; i++) {
			for(int j = i * 2; j <= N; j += i) {
				num[j]++;
			}
		}
		long sum = 0;
		for(int i = 1; i <= N; i++) {
			sum += i * num[i];
		}
		System.out.println(sum);
		//System.out.println(Arrays.toString(num));
	}

	public static void main(String[] args) {
		new Main().doIt();
	}

}

Score : 400 points

Problem Statement

For a positive integer X, let f(X) be the number of positive divisors of X.

Given a positive integer N, find \sum_{K=1}^N K\times f(K).

Constraints

1 \leq N \leq 10^7

Input

Input is given from Standard Input in the following format:

N

Output

Print the value \sum_{K=1}^N K\times f(K).

Sample Input 1

4

Sample Output 1

23

We have f(1)=1, f(2)=2, f(3)=2, and f(4)=3, so the answer is 1\times 1 + 2\times 2 + 3\times 2 + 4\times 3 =23.

Sample Input 2

100

Sample Output 2

26879

Sample Input 3

10000000

Sample Output 3

838627288460105

Watch out for overflows.


import java.io.*;
import java.util.*;
//import javafx.util.*;
import java.math.*;
//import java.lang.*;
public class Main
{

   // static int n;
//  static HashSet<Integer> adj[];

   // static int dist[];
   // static int remove[];
//    static boolean isLeaf[];
  //   static Long dp[][];
   // static int arr[];
  //  static boolean ok;
    // static long arr[];
    // static long sum[];
  //  static boolean ok;
    static long mod=1000000007;
 //   static HashSet<Integer> adjacency[];
    static final long oo=(long)1e18;
    public static void main(String[] args) throws IOException {
    //    Scanner sc=new Scanner(System.in);
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        br = new BufferedReader(new InputStreamReader(System.in));
      //  int test=nextInt();
       int test=1;

        outer: while(test--!=0){

           // String s=next();
            long n=nextLong();
            boolean prime[]=new boolean[(int)n+1];
            long ans=(n*(n+1))/2;
            for(int i=2;i<=n;i++){
                for(int j=i;j<=n;j+=i){

                    ans+=j;
                }

            }
            pw.println(ans);

        }

        pw.close();
    }

    static class Pair implements Comparable<Pair>{
        double g,ai,bi,sa,sb;
        Pair(double g,double ai,double bi){
          //  this.index=index;
            this.g=g;
            this.ai=ai;
            this.bi=bi;
            sa=g/ai;
            sb=g/bi;
            //this.z=z;
        }
        public int compareTo(Pair p){
            double a=Math.abs(sa-sb);
            double b=Math.abs(p.sa-p.sb);
            if(a>b){
                return 1;
            }
            else if(a==b){
                return 0;

            }
            else{
                return -1;
            }
        }
    }
   static void update(long tree[],int idx,long val){
        //println(idx);
        while(idx<1000006){

            tree[idx]+=val;
            idx+=(idx)&(-idx);
        }
    }
    static long sum(long tree[],int idx){
        long sum=0;
        while(idx>0){

            sum+=tree[idx];
            idx-=(idx)&(-idx);
        }
        return sum;
    }
    public static BufferedReader br;
    public static StringTokenizer st;
    public static String next() {
        while (st == null || !st.hasMoreTokens()) {
       try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

    public static Integer nextInt() {
        return Integer.parseInt(next());
    }
    public static Long nextLong() {
        return Long.parseLong(next());
    }

    public static Double nextDouble() {
        return Double.parseDouble(next());
    }
    // static class Pair{
    //     int x;int y;
    //     Pair(int x,int y,int z){
    //         this.x=x;
    //         this.y=y;
    //        // this.z=z;
    //      //   this.z=z;
    //       //  this.i=i;
    //     }
    // }
    // static class sorting implements Comparator<Pair>{
    //     public int compare(Pair a,Pair b){
    //         //return (a.y)-(b.y);
    //         if(a.y==b.y){
    //             return -1*(a.z-b.z);
    //         }
    //         return (a.y-b.y);
    //     }
   // }

    static long ncr(long n,long r){

        if(r==0)
            return 1l;
        long val=ncr(n-1,r-1);
        val=(n*val);
        val=(val/r);
        return val;
    }

    public static int[] na(int n)throws IOException{
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = nextInt();
        return a;
    }
    static class query implements Comparable<query>{
        int l,r,idx,block;
        static int len;
        query(int l,int r,int i){
            this.l=l;
            this.r=r;
            this.idx=i;
            this.block=l/len;
        }
        public int compareTo(query a){
            return block==a.block?r-a.r:block-a.block;
        }
    }

    // static class sorting implements Comparator<Pair>{
    //     public int compare(Pair a1,Pair a2){
    //         if(o1.a==o2.a)
    //             return (o1.b>o2.b)?1:-1;
    //         else if(o1.a>o2.a)
    //             return 1;
    //         else
    //             return -1;
    //     }
    // }
    static boolean isPrime(int n) {
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;
        if (n % 2 == 0 ||
            n % 3 == 0)
            return false;

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

        return true;
    }
    static int gcd(int a, int b) {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
    // To compute x^y under modulo m
    static long power(long x, long y, long m){
        if (y == 0)
            return 1;
        long p = power(x, y / 2, m) % m;
        p = (p * p) % m;

        if (y % 2 == 0)
            return p;
        else
            return (x * p) % m;
    }
    static long fast_pow(long base,long n,long M){
        if(n==0)
           return 1;
        if(n==1)
        return base;
        long halfn=fast_pow(base,n/2,M);
        if(n%2==0)
            return ( halfn * halfn ) % M;
        else
            return ( ( ( halfn * halfn ) % M ) * base ) % M;
    }
       static long modInverse(long n,long M){
        return fast_pow(n,M-2,M);
    }
    // (1,1)

    //     (3,2)   (3,5)

}


import java.util.*;

public class Main {

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		long n = new Integer(Integer.parseInt(sc.next()));

		long result = 0;
		for (long i = 1; i <= n; i++) {
			long kosuu = n / i;
			result += (i + (i * kosuu)) * kosuu / 2;
		}

		System.out.println(result);

	}
}


import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int  n = Integer.parseInt(scanner.nextLine());
		int i = 1;
		long ans = 0;

		long[] list = divisor(n);
		while(i <= n) {

			ans += list[i] * i;
			i++;
		}
		System.out.println(ans);
	}

	private static long[] divisor(long num) {
		int MAX   = (int)num;
		long[] cnt = new long[(MAX + 2)];

		int i = 0;
        int j = 0;
		cnt[1] = 1;
		for(i = 2; i <= MAX; i++) cnt[i] = 2;
		for(i=2; i<=MAX/2; i++) {
			for(j = 2*i; j <= MAX; j += i) { cnt[j]++;}
		}

		return cnt;

	}
}


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

public class Main {
	static int n;
	static int[] primes;
	static int div2[];
	static void solve() {
		n = ni();
		if(n == 1) {
			out.println(1);
			return;
		}
		primes = eratos(n);
		div2 = new int[n+1];
		div2[2] = 1;
		for(int i=3;i<=n;i++) {
			if(i % 2 == 0) {
				div2[i] = div2[i/2] + 1;
			}
		}
		long dp[] = new long[n+1];
		dp[1] = 1;
		for(int i=2;i<=n;i++) {
			if(dp[i] != 0)continue;
			if(primes[i] == 0) {
				dp[i] = 2;
				continue;
			}
			int x = i;
			if(x % 2 == 0) {
				x /= pow(2, div2[i]);
				dp[i] = dp[x] * (div2[i]+1);
				continue;
			}

			int cnt = 0;
			while(x % primes[i] == 0) {
				x /= primes[i];
				cnt++;
			}
			dp[i] = dp[x] * (cnt + 1);
		}
		long ans = 0;
		for(int i=1;i<=n;i++) {
			ans += i * dp[i];
		}
		out.println(ans);
	}

	static int[] eratos(int x) {
		int[] era = new int[x+1];
		fill(era, -1);
		for(int i=2;i<=n;i++) {
			if(era[i]!=-1)continue;
			era[i] = 0;//0が素数
			for(int j=i+i;j<=n;j+=i) {
				era[j] = i;//自分を割れる素数
			}
		}
		return era;
	}

	static int factCnt(int x) {
		Set<Integer> set = new HashSet<>();
		for(int i=1;i*i<=x;i++) {
			if(x % i == 0) {
				set.add(i);
				set.add(x / i);
			}
		}
		return set.size();
	}

	//constant
	static final int inf = Integer.MAX_VALUE / 2;
	static final long linf = Long.MAX_VALUE / 3;
	static final double dinf = Double.MAX_VALUE / 3;
	static final long mod = (long) 1e9 + 7;
	static final int[] dx = { -1, 0, 1, 0 }, dy = { 0, -1, 0, 1 }, dx8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy8 = { -1, 0, 1, -1, 1, -1, 0, 1 };
	static final double eps = 1e-10, pi = Math.PI;
	static StringBuilder sb = new StringBuilder();

	//libraries
	static void reverse(int ar[]) {
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			int t = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = t;
		}
	}
	static void reverse(long ar[]) {
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			long t = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = t;
		}
	}
	static void reverse(double ar[]) {
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			double t = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = t;
		}
	}
	static void reverse(char ar[]) {
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			char t = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = t;
		}
	}
	static String getReverse(String s) {
		char c[] = s.toCharArray();
		reverse(c);
		s = String.valueOf(c);
		return s;
	}
	static <T> void reverse(List<T> ls) {
		int sz = ls.size();
		for (int i = 0; i < sz / 2; i++) {
			T t = ls.get(i);
			ls.set(i, ls.get(sz - 1 - i));
			ls.set(sz - 1 - i, t);
		}
	}
	static <T> void reverse(T[] ar) {
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			T t = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = t;
		}
	}
	static void sbnl() {//StringBuilderに改行文字をappendする
		sb.append("\n");
	}
	static int lowerBound(int[] a, int x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] < x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int upperBound(int[] a, int x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] <= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int rlowerBound(int[] a, int x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] > x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int rupperBound(int[] a, int x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] >= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int lowerBound(long[] a, long x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] < x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int upperBound(long[] a, long x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] <= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int rlowerBound(long[] a, long x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] > x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int rupperBound(long[] a, long x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] >= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int lowerBound(double[] a, double x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] < x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int upperBound(double[] a, double x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] <= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int rlowerBound(double[] a, double x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] > x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int rupperBound(double[] a, double x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] >= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int lowerBound(char[] a, char x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] < x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int upperBound(char[] a, char x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] <= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int rlowerBound(char[] a, char x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] > x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static int rupperBound(char[] a, char x) {
		int l = -1, r = a.length;
		while (r - l > 1) {
			int c = (l + r) / 2;
			if (a[c] >= x) {
				l = c;
			} else {
				r = c;
			}
		}
		return r;
	}
	static <T> int lowerBound(List<T> ls, T x) throws RuntimeException {
		if (ls.size() == 0)
			return -1;
		if (ls.get(0) instanceof Integer) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) >= 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Long) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) >= 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Double) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) >= 0 ? 1 : -1);
		} else {
			System.err.println(
					String.format("%s:数値でないリストを二分探索しています。", Thread.currentThread().getStackTrace()[1].getMethodName()));
			throw new RuntimeException();
		}
	}
	static <T> int upperBound(List<T> ls, T x) throws RuntimeException {
		if (ls.size() == 0)
			return -1;
		if (ls.get(0) instanceof Integer) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) > 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Long) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) > 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Double) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) > 0 ? 1 : -1);
		} else {
			System.err.println(
					String.format("%s:数値でないリストを二分探索しています。", Thread.currentThread().getStackTrace()[1].getMethodName()));
			throw new RuntimeException();
		}
	}
	static <T> int rupperBound(List<T> ls, T x) throws RuntimeException {
		if (ls.size() == 0)
			return -1;
		if (ls.get(0) instanceof Integer) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) < 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Long) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) < 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Double) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) < 0 ? 1 : -1);
		} else {
			System.err.println(
					String.format("%s:数値でないリストを二分探索しています。", Thread.currentThread().getStackTrace()[1].getMethodName()));
			throw new RuntimeException();
		}
	}
	static <T> int rlowerBound(List<T> ls, T x) {
		if (ls.size() == 0)
			return -1;
		if (ls.get(0) instanceof Integer) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) <= 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Long) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) <= 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Double) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) <= 0 ? 1 : -1);
		} else {
			System.err.println(
					String.format("%s:数値でないリストを二分探索しています。", Thread.currentThread().getStackTrace()[1].getMethodName()));
			throw new RuntimeException();
		}
	}
	static int[] concat(int x, int arr[]) {
		int ret[] = new int[arr.length + 1];
		System.arraycopy(arr, 0, ret, 1, ret.length - 1);
		ret[0] = x;
		return ret;
	}
	static int[] concat(int arr[], int x) {
		int ret[] = new int[arr.length + 1];
		System.arraycopy(arr, 0, ret, 0, ret.length - 1);
		ret[ret.length - 1] = x;
		return ret;
	}
	static long[] concat(long x, long arr[]) {
		long ret[] = new long[arr.length + 1];
		System.arraycopy(arr, 0, ret, 1, ret.length - 1);
		ret[0] = x;
		return ret;
	}
	static long[] concat(long arr[], long x) {
		long ret[] = new long[arr.length + 1];
		System.arraycopy(arr, 0, ret, 0, ret.length - 1);
		ret[ret.length - 1] = x;
		return ret;
	}
	static char[] concat(char x, char arr[]) {
		char ret[] = new char[arr.length + 1];
		System.arraycopy(arr, 0, ret, 0, ret.length - 1);
		ret[ret.length - 1] = x;
		return ret;
	}
	static char[] concat(char arr[], char x) {
		char ret[] = new char[arr.length + 1];
		System.arraycopy(arr, 0, ret, 0, ret.length - 1);
		ret[ret.length - 1] = x;
		return ret;
	}
	static int max(int x, int y) {
		return Math.max(x, y);
	}
	static int min(int x, int y) {
		return Math.min(x, y);
	}
	static int max(int x, int y, int z) {
		x = Math.max(x, y);
		x = Math.max(x, z);
		return x;
	}
	static int min(int x, int y, int z) {
		x = Math.min(x, y);
		x = Math.min(x, z);
		return x;
	}
	static long max(long x, long y) {
		return Math.max(x, y);
	}
	static long min(long x, long y) {
		return Math.min(x, y);
	}
	static long max(long x, long y, long z) {
		x = Math.max(x, y);
		x = Math.max(x, z);
		return x;
	}
	static long min(long x, long y, long z) {
		x = Math.min(x, y);
		x = Math.min(x, z);
		return x;
	}
	static double max(double x, double y) {
		return Math.max(x, y);
	}
	static double min(double x, double y) {
		return Math.min(x, y);
	}
	static double max(double x, double y, double z) {
		x = Math.max(x, y);
		x = Math.max(x, z);
		return x;
	}
	static double min(double x, double y, double z) {
		x = Math.min(x, y);
		x = Math.min(x, z);
		return x;
	}
	static void sort(int[] ar) {
		Arrays.sort(ar);
	}
	static void sort(long[] ar) {
		Arrays.sort(ar);
	}
	static void sort(double[] ar) {
		Arrays.sort(ar);
	}
	static void sort(char[] ar) {
		Arrays.sort(ar);
	}
	static void rsort(int[] ar) {
		Arrays.sort(ar);
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			int tmp = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = tmp;
		}
	}
	static void rsort(long[] ar) {
		Arrays.sort(ar);
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			long tmp = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = tmp;
		}
	}
	static void rsort(double[] ar) {
		Arrays.sort(ar);
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			double tmp = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = tmp;
		}
	}
	static void rsort(char[] ar) {
		Arrays.sort(ar);
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			char tmp = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = tmp;
		}
	}
	static void fill(int arr[], int x) {
		Arrays.fill(arr, x);
	}
	static void fill(long arr[], long x) {
		Arrays.fill(arr, x);
	}
	static void fill(boolean arr[], boolean x) {
		Arrays.fill(arr, x);
	}
	static void fill(double arr[], double x) {
		Arrays.fill(arr, x);
	}
	static void fill(int arr[][], int x) {
		for (int i = 0; i < arr.length; i++)
			Arrays.fill(arr[i], x);
	}
	static void fill(long arr[][], long x) {
		for (int i = 0; i < arr.length; i++)
			Arrays.fill(arr[i], x);
	}
	static void fill(double arr[][], double x) {
		for (int i = 0; i < arr.length; i++)
			Arrays.fill(arr[i], x);
	}
	static void fill(boolean arr[][], boolean x) {
		for (int i = 0; i < arr.length; i++)
			Arrays.fill(arr[i], x);
	}
	//MOD culc
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}
	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}
	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}
	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}
	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
	public static void main(String[] args) throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}
	//input
	static InputStream is;
	static PrintWriter out;
	static String INPUT = "";
	private static byte[] inbuf = new byte[1024];
	static int lenbuf = 0, ptrbuf = 0;
	private static int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}
	private static boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}
	private static int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}
	@SuppressWarnings("unused")
	private static double nd() {
		return Double.parseDouble(ns());
	}
	@SuppressWarnings("unused")
	private static char nc() {
		return (char) skip();
	}
	private static String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	private static char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	@SuppressWarnings("unused")
	private static char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}
	@SuppressWarnings("unused")
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	@SuppressWarnings("unused")
	private static long[] nla(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
	private static int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	@SuppressWarnings("unused")
	private static long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
}


import java.io.*;
import java.util.*;
public class Main{
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(br.readLine().trim());
        long a[] = new long[n+1];
        Arrays.fill(a, 1);
        a[0]=0;
        for(int i=2;i<=n;i++){
            for(int j=i;j<=n;j+=i){
                a[j]++;
            }
        }
        for(int i=1;i<=n;i++){
            a[i] *= i;
            a[i] += a[i-1];
        }
        out.println(a[n]);
        out.flush();
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    if(n == 1) {
      System.out.println(1);
    }else {
      sc.nextLine();
      String[] str = sc.nextLine().split(" ");

      ArrayList<Integer> aList = new ArrayList<Integer>();
      for(int i = 0;i < n;i++) {
        aList.add(Integer.parseInt(str[i]));
      }
      Collections.sort(aList);

      if(aList.contains(1)) {
        if(aList.get(1) != 1) {
          System.out.println(1);
        }else {
          System.out.println(0);
        }
      }else {
        int max = Collections.max(aList);
        boolean[] bArray = new boolean[max+1];
        int cnt = 0;

        for(int i = 0;i < max+1 ; i++) {
          if(aList.contains(i)) {
            bArray[i] = true;
            cnt++;
          }else {
            bArray[i] = false;
          }
        }

        for(int i = 1;i < n;i++) {
          if(bArray[aList.get(i)]) {
            for(int j = 0;j < i;j++) {
              if(aList.get(i) % aList.get(j) == 0) {
                int c = 1;
                for(int k = aList.get(i);k <= max; k = c * aList.get(i)) {
                  if(aList.contains(k)) {
                    bArray[k] = false;
                    cnt--;
                  }
                  c++;
                }
                break;
              }
              if(aList.get(i) / aList.get(j) <= 2) {
                break;
              }
            }
          }
        }
        System.out.println(cnt);
        }
      }

  }
}

Score : 400 points

Problem Statement

Given is a number sequence A of length N.

Find the number of integers i \left(1 \leq i \leq N\right) with the following property:

For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the answer.

Sample Input 1

5
24 11 8 3 16

Sample Output 1

3

The integers with the property are 2, 3, and 4.

Sample Input 2

4
5 5 5 5

Sample Output 2

0

Note that there can be multiple equal numbers.

Sample Input 3

10
33 18 45 28 8 19 89 86 2 4

Sample Output 3

5


import java.util.*;
import java.io.*;
public class Main{
	static int[] a;
	static ArrayList<Integer> x = new ArrayList<Integer>();
   public static void main(String[] main) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
      PrintWriter out = new PrintWriter(System.out);
      int n = Integer.parseInt(st.nextToken());
      st = new StringTokenizer(br.readLine());
      a = new int[n];
      for(int i = 0; i < n; i++)
          a[i] = Integer.parseInt(st.nextToken());
      Arrays.sort(a);
      sieve();
      out.println(x.size());
      out.close();
   }
   static void sieve() {
	   boolean[] dp = new boolean[1000001];
	   for(int i = 0; i < dp.length; i++)
		   dp[i] = true;
	   for(int i = 0; i < a.length; i++) {
		   if(dp[a[i]] && a[i] <= 500000) {
			   for(int j = a[i]*2; j < 1000001; j += a[i]) {
				   dp[j] = false;
			   }
		   }
	   }
	   HashSet<Integer> elements = new HashSet<Integer>();
	   HashSet<Integer> dup = new HashSet<Integer>();
	   for(int i = 0; i < a.length; i++) {
		   if(elements.contains(a[i]))
			   dup.add(a[i]);
		   elements.add(a[i]);
	   }
	   for(int i = 0; i < a.length; i++)
		   if(dp[a[i]] && !dup.contains(a[i]))
			   x.add(a[i]);
   }
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] input = new int[n];
		for (int i = 0; i < n; i++) {
			input[i] = sc.nextInt();
		}
		Arrays.sort(input);

		boolean[] dp = new boolean[n];
		Arrays.fill(dp, true);

		int count = 0;
		for (int i = 0; i < n; i++) {

			if (dp[i]) {
				for (int j = i + 1; j < n; j++) {
					if (dp[j]) {
						if (input[i] == input[j])
							dp[i] = dp[j] = false;

						else if (input[j] % input[i] == 0)
							dp[j] = false;
					}
				}
			}

			if (dp[i])
				count++;
		}

		System.out.println(count);
	}
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        var N = scanner.nextInt();
        var A = new int[N];
        var isP = new boolean[N];

        for(int i=0; i<N; i++) {
            A[i] = scanner.nextInt();
            isP[i] = true;
        }

        Arrays.sort(A);
        int numP = 0;
        for(int i=0; i<N-1; i++) {
            if(!isP[i]) continue;

            for(int j=i+1; j<N; j++) {
                if(!isP[j]) continue;
                if(A[i] == A[j]) isP[i] = false;
                if(A[j] % A[i] == 0) isP[j] = false;
                numP++;
            }
        }
        System.out.println(numP);
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        var N = scanner.nextInt();
        var A = new LinkedList<Integer>();
        for(int i=0; i<N; i++)
            A.add(scanner.nextInt());

        A.sort(Comparator.naturalOrder());
        var numP = 0;
        while(A.size()!=0) {
            int p = A.getFirst();
            A.remove(0);
            System.out.println("p: " + p);
            System.out.println("A: " + A);

            boolean isPExistInRemains = false;
            for(Iterator<Integer> ite = A.iterator(); ite.hasNext(); ) {
                int next = ite.next();
                if(next % p == 0) ite.remove();
                if(next == p) isPExistInRemains = true;
            }
            if(!isPExistInRemains) numP++;
        }
        System.out.println(numP);
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();

			int[] aArray = new int[n];
			HashMap<Integer, Integer> dupMap = new HashMap<>();

			for(int i = 0 ; i < n ; i++ ) {
				aArray[i] = sc.nextInt();
				if ( dupMap.containsKey(aArray[i]) ) {
					int current = dupMap.get(aArray[i]);
					dupMap.put(aArray[i], current+1);
				}
				else {
					dupMap.put(aArray[i], 1);
				}

			}

			long ans = 0;

			List<Integer> uniqList = new ArrayList<>(dupMap.keySet());
			Collections.sort(uniqList);

			for(int i = 0 ; i < uniqList.size() ; i++ ) {
				int ai = uniqList.get(i);

				if (dupMap.get(ai) > 1) {
					//duplicate itself
					continue;
				}

				int rootAi = ai / 2 + 1;

				boolean isOK = true;
				for(int j = 0 ; j < i ; j++ ) {
					int aj = uniqList.get(j);

					if ( ai % aj == 0 ) {
						isOK = false;
						break;
					}

					if ( aj > rootAi) {
						break;
					}
				}

				if ( isOK ) {
//					System.out.println(ai);
					ans++;
				}
			}

			System.out.println(ans);

		}
	}

}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] as = new int[n];
		int[] count = new int[1000001];
		boolean[] hantei = new boolean[1000001];
		for(int i=0; i<n; i++){
			as[i] = sc.nextInt();
			count[as[i]]++;
		}
		for(int i=0; i<n; i++){
			if(count[as[i]] >= 2){
				int j = 2;
				int tmp = as[i];
				while(tmp <= 1000000){
					hantei[tmp] = true;
					tmp = as[i]*j;
					j++;
				}
			} else if(count[as[i]] >= 1){
				int j = 2;
				int tmp = as[i]*j;
				while(tmp <= 1000000){
					hantei[tmp] = true;
					j++;
					tmp = as[i]*j;
				}
			}
		}
		int ans = 0;
		for(int a: as){
			if(!hantei[a]) ans++;
		}
		System.out.println(ans);

	}
}


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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i =0; i<N; i++) {
      A[i] = sc.nextInt();
    }
    Arrays.sort(A);
    boolean[] dp = new boolean[1000001];
    int count =0;
    for (int i =0; i<N; i++) {
      dp[A[i]] = true;
    }
    for (int i =0; i<N; i++) {
      int j = A[i] * 2;
      while (j < 1000001) {
        dp[j] = false;
        j+= A[i];
      }
    }
    for (int i =0; i<N; i++) {
      if (i <N-1 && A[i] == A[i+1]) {
        dp[A[i]] = false;
      }
      if (dp[A[i]] == true) {
        count++;
      }
    }
    System.out.println(count);
  }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {

		slover();
		out.flush();
	}
	static FastScanner sc = new FastScanner();
	static PrintWriter out = new PrintWriter(System.out);
	//StringBuffer S = new StringBuffer(sc.next());
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)
	//Map<Integer, Integer> map = new HashMap<Integer, Integer>(N);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );

		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek BFSは前から実行される
	//Deque<String> dd=new ArrayDeque<>();//push後ろに入れる,poll(pop)後ろからとる,peek addは先頭に入るからバグ注意
	//stackdfsは後ろから実行される
	//ArrayList<Integer> cc = new ArrayList<>(N);
	//cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5

	private static void slover() {

		int N=sc.nextInt();
		int A[]=sc.nextIntArray(N, false);
		int ans=0;

		Arrays.sort(A);
		if(N==1) {
			p(1);
		}else
		if(A[0]==A[N-1]) {
			p(0);
		}
		else {
			t:for(int i=0;i<N;i++) {
				if((i-1>=0&&A[i-1]==A[i])||(i+1<N&&A[i+1]==A[i]))continue t;
				for(int a=2;a<=125;a++) {
					if((A[i]/a)>0&&A[i]%(A[i]/a)==0&&Arrays.binarySearch(A,(A[i]/a))>=0)continue t;
				}
				for(int a=0;a<i;a++) {
					if(A[a]*125>A[i])break;
					if(A[i]%A[a]==0)continue t;
				}

				ans++;
			}
			p(ans);
		}
	}

	static long Nsin(long t) {
		long sum=0;
		long v=1;
		long tt=1;
		for(long k=0;k<(t+"").length();k++) {
			sum+=(t%(tt*10)-t%tt)/tt*v;
			v*=t;
			tt*=10;
		}
		return sum;
	}

	static long so(long n) {
		for(long i=2;i*i<=n;i++) {
			if(n%i==0) {
				return i;
			}
		}
		return 0;

	}

	     static void nibun(int a,int b,int target) {

	    	 int ok=a;
	    	 int ng=b;

	    	 int t=2;

	    	 while(a<b) {
	    		 int G=(ok+ng)/2;
	    		 if(t==target) {
	    			 break;
	    		 }
	    		 if(t>ok) {

	    		 }
	    		 if(t>ng) {

	    		 }

	    	 }

	     }

		//StringBuffer str = new StringBuffer(sc.nextInt());
		//for(int i=0;i<N;i++) {}

			//	p("===================");
				//for(int f:gyo.keySet()){
				    //p(gyo.get(f));
			//	}
			//	p("===================");

	static void p(String ans) {out.println(ans);};
	static void p(int ans) {out.println(ans);};
	static void p() {out.println();};
	static void p(long ans) {out.println(ans);};
	static void p(double ans) {out.println(ans);};

	static void pn(String ans) {out.print(ans);};
	static void pn(int ans) {out.print(ans);};
	static void pn() {out.print("");};
	static void pn(long ans) {out.print(ans);};
	static void pn(double ans) {out.print(ans);};

	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;

	    private boolean hasNextByte() {
	      if (ptr < buflen) {
	        return true;
	      } else {
	        ptr = 0;
	        try {
	          buflen = in.read(buffer);
	        } catch (IOException e) {
	          e.printStackTrace();
	        }
	        if (buflen <= 0) {
	          return false;
	        }
	      }
	      return true;
	    }

	    private int readByte() {
	      if (hasNextByte()) return buffer[ptr++];
	      else return -1;
	    }

	    private static boolean isPrintableChar(int c) {
	      return 33 <= c && c <= 126;
	    }

	    private void skipUnprintable() {
	      while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
	    }

	    public boolean hasNext() {
	      skipUnprintable();
	      return hasNextByte();
	    }

	    public String next() {
	      if (!hasNext()) throw new NoSuchElementException();
	      StringBuilder sb = new StringBuilder();
	      int b = readByte();
	      while (isPrintableChar(b)) {
	        sb.appendCodePoint(b);
	        b = readByte();
	      }
	      return sb.toString();
	    }

	    public long nextLong() {
	      if (!hasNext()) throw new NoSuchElementException();
	      long n = 0;
	      boolean minus = false;
	      int b = readByte();
	      if (b == '-') {
	        minus = true;
	        b = readByte();
	      }
	      if (b < '0' || '9' < b) {
	        throw new NumberFormatException();
	      }
	      while (true) {
	        if ('0' <= b && b <= '9') {
	          n *= 10;
	          n += b - '0';
	        } else if (b == -1 || !isPrintableChar(b)) {
	          return minus ? -n : n;
	        } else {
	          throw new NumberFormatException();
	        }
	        b = readByte();
	      }
	    }

	    public int nextInt() {
	      return (int) nextLong();
	    }

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

	    public int[] nextIntArray(int N, boolean oneBased) {
	      if (oneBased) {
	        int[] array = new int[N + 1];
	        for (int i = 1; i <= N; i++) {
	          array[i] = sc.nextInt();
	        }
	        return array;
	      } else {
	        int[] array = new int[N];
	        for (int i = 0; i < N; i++) {
	          array[i] = sc.nextInt();
	        }
	        return array;
	      }
	    }

	    public long[] nextLongArray(int N, boolean oneBased) {
	      if (oneBased) {
	        long[] array = new long[N + 1];
	        for (int i = 1; i <= N; i++) {
	          array[i] = sc.nextLong();
	        }
	        return array;
	      } else {
	        long[] array = new long[N];
	        for (int i = 0; i < N; i++) {
	          array[i] = sc.nextLong();
	        }
	        return array;
	      }
	    }
	  }
}