Problem: Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a sa as close as possible to the sum of the elements in the array b sb. So he wants to minimize the value v = |sa - sb|.

In one operation professor can swap some element from the array a and some element from the array b. For example if the array a is [5, 1, 3, 2, 4] and the array b is [3, 3, 2] professor can swap the element 5 from the array a and the element 2 from the array b and get the new array a [2, 1, 3, 2, 4] and the new array b [3, 3, 5].

Professor doesn't want to make more than two swaps. Find the minimal value v and some sequence of no more than two swaps that will lead to the such value v. Professor makes swaps one by one, each new swap he makes with the new arrays a and b.

Input

The first line contains integer n (1 ≤ n ≤ 2000) — the number of elements in the array a.

The second line contains n integers ai ( - 109 ≤ ai ≤ 109) — the elements of the array a.

The third line contains integer m (1 ≤ m ≤ 2000) — the number of elements in the array b.

The fourth line contains m integers bj ( - 109 ≤ bj ≤ 109) — the elements of the array b.

Output

In the first line print the minimal value v = |sa - sb| that can be got with no more than two swaps.

The second line should contain the number of swaps k (0 ≤ k ≤ 2).

Each of the next k lines should contain two integers xp, yp (1 ≤ xp ≤ n, 1 ≤ yp ≤ m) — the index of the element in the array a and the index of the element in the array b in the p-th swap.

If there are several optimal solutions print any of them. Print the swaps in order the professor did them.

Examples

Input

5
5 4 3 2 1
4
1 1 1 1


Output

1
2
1 1
4 2


Input

5
1 2 3 4 5
1
15


Output

0
0


Input

5
1 2 3 4 5
4
1 2 3 4


Output

1
1
3 1

Solution (in JAVA):

Solution:
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.Arrays;

/* Name of the class has to be "Main" only if the class is public. */
public class ValentineProject {

    long neg[] = new long[2001 * 2001];
    long pos[] = new long[2001 * 2001];
    boolean zero ;
    long sa, sb, sbb, saa;
    int tracea[] = new int[3];
    int traceb[] = new int[3];
    int swaps;
    long ans;
    long back;

    private void solve() throws IOException {
        int b[] = new int[2010];
        int a[] = new int[2010];
        sa = sb = 0;
        int n = nextInt();
        for (int i=1;i<=n;++i) {
            a[i] = nextInt();
            sa += a[i];
        }
        int m = nextInt();
        for (int i=1;i<=m ; i++) {
            b[i] = nextInt();
            sb += b[i];
        }
        int ng = 0 , ps = 0;
        zero = false;

        long diff , e;

        for(int i=1;i<=m;++i)
            if( b[i] > 0)                
                pos[++ps] = b[i];
            else if(b[i] == 0)
                    zero = true;
            else
                neg[++ng] = b[i];

        int tt;

        if( ng > 0){
            tt = 1;
            Arrays.sort(neg , 1 , ng + 1);
            for(int i=2;i<=ng;++i)
                if( neg[i] != neg[i-1])
                    neg[++tt] = neg[i];
            ng = tt;
        }
        if(ps > 0){
            tt = 1;
            Arrays.sort(pos , 1 , ps + 1);
            for(int i=2;i<=ps;++i){
                if( pos[i] != pos[i-1])
                    pos[++tt] = pos[i];
            }
            ps = tt;
        }
        
        ans = abs(sa - sb);
        swaps = 0;

        long prev;

        for(int i=1;i<=n;++i){
            saa = sa - a[i];
            sbb = sb + a[i];
            diff = sbb - saa;
            if(ps > 0){
                prev = ans;
                pbinary(1,ps,diff);                
                if(ans < prev){
                    swaps = 1 ;
                    tracea[1] = i;
                }
            }
            if(ng > 0){
                prev = ans;
                nbinary(1,ng,diff);               
                if(ans < prev){
                    swaps = 1;
                    tracea[1] = i;
                }
            }
            if(zero){
                if( ans > abs(diff)){
                    swaps = 1;
                    tracea[1] = i;
                    ans = abs(diff);
                    back = 0;
                }
            }
        }

        ps = ng = 0;

        zero = false ;

        for(int i=1;i<m;++i){
            for( int j = i + 1 ; j <= m; ++j){
                if( b[i] + b[j] > 0){
                    pos[++ps] = b[i] + b[j];
                }
                else if( b[i] + b[j] == 0){
                    zero = true ;
                }
                else{
                    neg[++ng] = b[i] + b[j];
                }
            }
        }
        
        if( ng > 0){
            tt = 1;
            Arrays.sort(neg , 1 , ng + 1);
            for(int i=2;i<=ng;++i)
                if( neg[i] != neg[i-1])
                    neg[++tt] = neg[i];
            ng = tt;
        }
        if(ps > 0){
            tt = 1;
            Arrays.sort(pos , 1 , ps + 1);
            for(int i=2;i<=ps;++i){
                if( pos[i] != pos[i-1])
                    pos[++tt] = pos[i];
            }
            ps = tt;
        }

        for(int i=1;i<n;++i){
            for(int j=i+1;j<=n;++j){
                
                saa = sa - a[i] - a[j];
                sbb = sb + a[i] + a[j];
                diff = sbb - saa;

                if(n==2000 && a[1]==539391558L && i==92 && j==1407){
                    for(int k=1;k<=ng;++k)
                        if( abs(diff - 2 * neg[k]) < ans){
                            ans = abs(diff - 2 * neg[k]);
                            swaps = 2;
                            back = neg[k];
                            tracea[1] = i ; tracea[2] = j;
                        }
                    for(int k=1;k<=ps;++k)
                        if( abs(diff - 2 * pos[k]) < ans){
                            ans = abs(diff - 2 * pos[k]);
                            swaps = 2;
                            back = pos[k];
                            tracea[1] = i ; tracea[2] = j;
                        }

                }

                if(ps > 0){
                    prev = ans;
                    pbinary(1,ps,diff);
                    if(prev > ans){
                        swaps = 2;
                        tracea[1] = i;
                        tracea[2] = j;
                    }
                    

                }
                if(ng > 0){
                    prev = ans;
                    nbinary(1,ng,diff);                    
                    if( prev > ans){
                        swaps = 2;
                        tracea[1] = i;
                        tracea[2] = j;
                    }
                   
                }
                if(zero){
                    
                    if( ans > abs(diff)){
                        swaps = 2;
                        tracea[1] = i;
                        tracea[2] = j;
                        ans = min(ans, abs(diff));
                        back = 0;
                    }
                    
                }

         //       System.out.print("\n");
            //    return ;
            }
        }
        System.out.print(ans);
        System.out.print("\n");
        System.out.print(swaps);
        System.out.print("\n");
        if(swaps == 0){
            return;
        }

        if(swaps == 1){
            for(int i=1;i<=m;++i)
                if( b[i] == back){
                    traceb[1] = i;
                    break;
                }
                System.out.print(tracea[1]);
                System.out.print(" ");
                System.out.print(traceb[1]);
                System.out.print("\n");
                return ;
        }

        for(int i=1;i<m;++i)
            for(int j=i+1;j<=m;++j)
                if( back == b[i] + b[j]){
                    traceb[1] = i;
                    traceb[2] = j;
                }
        System.out.print(tracea[1]);
        System.out.print(" ");
        System.out.print(traceb[1]);
        System.out.print("\n");
        System.out.print(tracea[2]);
        System.out.print(" ");
        System.out.print(traceb[2]);
        System.out.print("\n");

    }

    public void nbinary(int it,int f, long diff)
    {
        int fo = f;
        if(diff >= 0){
            if( ans > abs(diff - 2 * neg[f])){
                ans = abs(diff - 2 * neg[f]);
                back = neg[f];                
            }
            return ;
        }
        if( diff >= 2 * neg[f]){
            if( ans > abs(diff - 2 * neg[f])){
                ans = abs (diff - 2 * neg[f]);
                back = neg[f];                
            }
            return ;
        }
        int mid ;
        while ( it != f){
            mid = ( it + f)/2;
            if(diff - 2 * neg[mid+1] >= 0)
                it = mid + 1;
            else 
                f = mid;
        }
        if( f < fo){
            if( abs(diff - 2 * neg[f + 1]) < ans){
                ans = abs(diff - 2 * neg[f + 1]);
                back = neg[f+1];
            }
        }
        if(f > 1){
        if( abs(diff - 2 * neg[f-1] ) < ans){
            ans = abs(diff - 2 * neg[f-1] );
            back = neg[f-1];
        }
        }
        if(abs(diff - 2 * neg[f]) < ans){
            ans = abs(diff - 2 * neg[f]);
            back = neg[f];
        }
    }

    public void pbinary(int it,int f,long diff )
    {
        int fo = f;
        if( diff <= 0){
            if(abs(diff - 2 * pos[it]) < ans){
                ans = abs(diff - 2 * pos[it]);
                back = pos[it];
            }
            return ;

        }
            
        if( diff >= 2 * pos[f]){
            if( abs(diff - 2 * pos[f]) < ans){
                ans = abs(diff - 2 * pos[f]);
                back = pos[f];            
            }
            return ;
        }
        
        int mid;
        while( it != f){
            mid = (it + f)/2;
            if( diff >= pos[mid + 1])
                it = mid + 1;
            else f = mid;
        }        

        if( abs(2 * pos[f] - diff) < ans){
                ans = abs(2 * pos[f] - diff);
                back = pos[f];
        }
        if( f > 1){
        if( abs(diff - 2 * pos[f-1]) < ans){
                ans = abs(diff - 2 * pos[f - 1] );
                back = pos[f - 1];
        } 
        }
        if( f < fo){
            if( abs(diff - 2 * pos[f+1]) < ans){
                ans = abs(diff - 2 * pos[f+1]);
                back = pos[f+1];
            }
        }
    }

    public static void main(String[] args) {
        // TODO code application logic here
        new ValentineProject().run();
    }
    
    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;
    
    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
    
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

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

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
    
}